Magento – Magento 2: How to display all Customer Group Price on Product Detail Page

customer-groupmagento2priceproduct

I would like to display all customer group price for that product on product detail page.

May be need to work on vendor\magento\module-catalog\view\base\templates\product\price\final_price.phtml

So when user is not logged in they are able to see for this Group we have this prices.

$productId = $block->getSaleableItem()->getId();

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

$groupPrices = $ProductObject->getData('group_price');

echo "<pre>";
print_r($groupPrices);
exit;

After that, need to set Customer Group wise Promotion Price, then also display that.

Best Answer

Below is the way to get

/** @var \Magento\Catalog\Pricing\Render\FinalPriceBox $block */
$productId = $block->getSaleableItem()->getId();

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

$productAllTierPrices = $_product->getData('tier_price');

$allTierPrices = array();
foreach($productAllTierPrices as $tierPrices){
    $groupname = $objectManager->create('Magento\Customer\Model\Group')->load($tierPrices['cust_group'])->getCustomerGroupCode();
    $allTierPrices[$groupname] = $tierPrices['price'];
}

echo "<pre>";
print_r($allTierPrices);
exit;
// END

How to avoid ObjectManager in above code? If you know then can update the answer or post own.

Thanks

Related Topic