0

when bundled products are out of stock(the individual items) the price on the frontend shows:0.00 in Magento 2.3.4

I poked around in: vendor/magento/module-bundle/Pricing/Price/FinalPrice.php

public function getAmount()

  public function getAmount()
{
    if (!$this->minimalPrice) {
        $price = parent::getValue();
        if ($this->product->getPriceType() == Price::PRICE_TYPE_FIXED) {
            $this->loadProductCustomOptions();
            /** @var \Magento\Catalog\Pricing\Price\CustomOptionPrice $customOptionPrice */
            $customOptionPrice = $this->priceInfo->getPrice(CustomOptionPrice::PRICE_CODE);
            $price += $customOptionPrice->getCustomOptionRange(true);
        }
        $this->minimalPrice = $this->calculator->getAmount($price, $this->product);
    }
    return $this->minimalPrice;
}

$price returns 0.

Anyone has an idea how to get the regular price to show on frontend instead of 0 for out of bundled products with out of stock items?

Thanks!

3
  • i think you apply the condition like if bundle is out of stock . so showing price May 1, 2020 at 19:06
  • Hello, what do you mean by that? Please clarify. May 1, 2020 at 19:30
  • has someone found a solution for this issue? i tried module above on 2.3.5 but it doesnt work :(
    – Kaines
    Sep 4, 2020 at 21:12

1 Answer 1

0

For that you need to create new extension with this functionality.

Create file

Vendor/Module/etc/frontend/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Catalog\Pricing\Render\FinalPriceBox" type="Vendor\Module\Pricing\Render\FinalPriceBox" />
</config>

Vendor/Module/Pricing/Render/FinalPriceBox.php

namespace Vendor\Module\Pricing\Render;

use Magento\Msrp\Pricing\Price\MsrpPrice;
use Magento\Framework\Pricing\Render\PriceBox as BasePriceBox;

class FinalPriceBox extends \Magento\Catalog\Pricing\Render\FinalPriceBox
{
    protected function _toHtml()
    {
        $result = parent::_toHtml();

        if(!$result) {
            $result = BasePriceBox::_toHtml();
            try {
                /** @var MsrpPrice $msrpPriceType */
                $msrpPriceType = $this->getSaleableItem()->getPriceInfo()->getPrice('msrp_price');
            } catch (\InvalidArgumentException $e) {
                $this->_logger->critical($e);
                return $this->wrapResult($result);
            }

            //Renders MSRP in case it is enabled
            $product = $this->getSaleableItem();
            if ($msrpPriceType->canApplyMsrp($product) && $msrpPriceType->isMinimalPriceLessMsrp($product)) {
                /** @var BasePriceBox $msrpBlock */
                $msrpBlock = $this->rendererPool->createPriceRender(
                    MsrpPrice::PRICE_CODE,
                    $this->getSaleableItem(),
                    [
                        'real_price_html' => $result,
                        'zone' => $this->getZone(),
                    ]
                );
                $result = $msrpBlock->toHtml();
            }

            return $this->wrapResult($result);
        }

        return $result;
    }
}

With this you can do the things you want.

Thanks and Happy Coding.

1
  • Hello, thanks, but that doesnt work. The out of stock bundled product still shows 0,00 as price. Magento 2.3.4 May 1, 2020 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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