Tuesday, February 7, 2017

How to get Tier Price of product magento2?

<?php
use \Magento\Framework\App\Bootstrap;
include('/www/magento2.1/app/bootstrap.php');

$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();

$state = $objectManager->get('\Magento\Framework\App\State');
$state->setAreaCode('frontend');

$productId = 1;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product_obj = $objectManager->create('Magento\Catalog\Model\Product')->load($productId);

getAnyGroup($product_obj);

function getAnyGroup($product_obj) {
    $tier_price = $product_obj->getTierPrices();

    if(count($tier_price) > 0){
        echo "price_qty\tprice\tCustomerGroupId\n";

        foreach($tier_price as $price){
            echo $price->getQty();
            echo "\t";
            echo $price->getValue();
            echo "\t";
            echo $price->getCustomerGroupId();
            echo "\t";
            echo "\n";
            print_r($price->getData());
            echo "\t";
            echo "\n";
        }
    }
}

No comments: