0

how to get the bundle product prices (Maximum & Minimum) in the Magento 2 for customer group and tax as well?

I tried various functions in the Magento's default code but did not get the exact output with functions.

3
  • FYI, I tried this function: list($minimalPrice, $maximalPrice) = $item->getPriceModel()->getTotalPrices($item, null, false, false);
    – Tejas Vyas
    Commented Jul 9, 2019 at 19:24
  • Is it for current customer's group or some other specified group? Commented Jul 10, 2019 at 0:31
  • Have you find solution? Commented Jul 10, 2019 at 12:51

1 Answer 1

0

You can try this code in order to fetch the bundle product price range (maximum and minimum price)

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Catalog\Model\Product')->load(your_product_Id);
$bundleObj=$product->getPriceInfo()->getPrice('final_price');
echo $bundleObj->getMinimalPrice();// For min price
echo $bundleObj->getMaximalPrice(); // for max price

For Tier price for specific customer group, try following way:


public function __construct(
    \Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
    \Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory $priceFactory,
    \Magento\Framework\App\Config\ScopeConfigInterface $config,
    \Magento\Customer\Api\GroupManagementInterface $groupManagement
) {
    $this->productRepository = $productRepository;
    $this->priceFactory = $priceFactory;
    $this->config = $config;
    $this->groupManagement = $groupManagement;

}

And then:


$sku = '24-MB01';
$customerGroupId = 1;
$product = $this->productRepository->get($sku, ['edit_mode' => true]);

$priceKey = 'website_price';
$value = $this->config->getValue('catalog/price/scope', \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE);
if ($value == 0) {
    $priceKey = 'price';
}

$cgi = ($customerGroupId === 'all'
    ? $this->groupManagement->getAllCustomersGroup()->getId()
    : $customerGroupId);

$prices = [];
foreach ($product->getData('tier_price') as $price) {
    if ((is_numeric($customerGroupId) && intval($price['cust_group']) === intval($customerGroupId))
        || ($customerGroupId === 'all' && $price['all_groups'])
    ) {
        /** @var \Magento\Catalog\Api\Data\ProductTierPriceInterface $tierPrice */
        $tierPrice = $this->priceFactory->create();
        $tierPrice->setValue($price[$priceKey])
            ->setQty($price['price_qty'])
            ->setCustomerGroupId($cgi);
        $prices[] = $tierPrice->getValue();
    }
}
echo '<pre>';print_r($prices);

I hope this will help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.