2

I want to get the original price of a Bundle product (Minimal/Maximal one). This needs to replicate what Magento is grabbing for the WAS price below so I can add a percentage off to product pages.

Offer / Bundlke Price

I can get the Special Price like below:

$bundleObj=$product->getPriceInfo()->getPrice('final_price');
echo $bundleObj->getMinimalPrice();// For min price
echo $bundleObj->getMaximalPrice(); // for max price

I've tried using the below but this just returns 0:

$_product->getPrice();

This also only has both with and without tax and the standalone tax:

print_r($_product->getPriceInfo()->getPrice('final_price')->getMinimalPrice());

Have also looked at:

$_product->getPriceModel()->getTotalPrices($_product,'min',1)

This seems to just be pulling similar data cannot get the original price.

2
  • you want to get price of assigned children products? Jan 15, 2018 at 17:00
  • I guess so, whatever Magento is doing for the WAS price pictured above?
    – harri
    Jan 15, 2018 at 17:54

2 Answers 2

10

After studying a lot of files containing the old-price tag similar to that used in the markup for the WAS price, I found the below:

$finalPriceModel = $block->getPriceType('regular_price');
echo priceModel->getAmount();

vendor/magento/module-catalog/view/base/templates/product/price/final_price.phtml

I figured it made sense to use regular_price instead of final_price and so used similar code in my block to get the original price:

$bundleRegularPrice = $_product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue();

So after playing a little bit I can confirm how to get the following prices:

Regular Minimal Price:

$_product->getPriceInfo()->getPrice('regular_price')->getMinimalPrice()->getValue();

Regular Maximal Price:

$_product->getPriceInfo()->getPrice('regular_price')->getMaximalPrice()->getValue();

Special Minimal Price:

$_product->getPriceInfo()->getPrice('final_price')->getMinimalPrice()->getValue();

Special Maximal Price:

$_product->getPriceInfo()->getPrice('final_price')->getMaximalPrice()->getValue();

These are all including the tax to get the value excluding tax change getValue() to getBaseAmount();.

e.g:

$_product->getPriceInfo()->getPrice('regular_price')->getMinimalPrice()->getBaseAmount();
1

if tax enable

list($minimalPrice, $maximalPrice) = $item->getPriceModel()->getTotalPrices($item, null, true, false);

if tax is not there

list($minimalPrice, $maximalPrice) = $item->getPriceModel()->getTotalPrices($item, null, false, false);

You will get the Minimum price as $minimalPrice and the Maximum price as $maximalPrice.Please let me know if you still face the issue.

6
  • Tried this one unfoortunately this allowed me to get every price under the sun but the regular price. I think i've found a solution now however.
    – harri
    Jan 16, 2018 at 11:40
  • Did that solution work for you? Can you please explain?
    – Tejas Vyas
    Jan 16, 2018 at 11:42
  • No sorry, this was something i tried originally but would just return the special prices. Special prices with and without tax / minimal maximal version from everything i tried.
    – harri
    Jan 16, 2018 at 11:45
  • Thank you for the info. Can you please share the function that you used for getting prices?
    – Tejas Vyas
    Jan 16, 2018 at 11:48
  • Yeah will do just checking it as at moment returning the object and just want the number.
    – harri
    Jan 16, 2018 at 12:13

Your Answer

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

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