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.
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.
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