0

Magento\Catalog\Pricing\Render\FinalPriceBox I want to rewrite this file and I have done this code but not working

Custom\Outofstock\etc\di.xml

<preference for="Magento\Catalog\Pricing\Render\FinalPriceBox" type="Custom\Outofstock\Pricing\Render\FinalPriceBox" />

Custom\Outofstock\Pricing\Render\FinalPriceBox.php

    <?php
     namespace Ec\Outofstock\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;
    }
}
  • Please post the code for Custom\Outofstock\Pricing\Render\FinalPriceBox file also. – Mohit Kumar Arora Jul 16 '18 at 11:22
0

As I can see by the first review, that you have used

namespace Ec\Outofstock\Pricing\Render;

instead of

namespace Custom\Outofstock\Pricing\Render;

Please check and change it and let me know if still, you have the issue same.

  • i have change that but not working – imtia Jul 16 '18 at 11:34
0

Use the below code for your FinalPriceBox.php file:

<?php
namespace Custom\Outofstock\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;
    }
}
  • i already change Custom to Ec – imtia Jul 16 '18 at 12:03
  • On which file? Everywhere? – Sukumar Gorai Jul 16 '18 at 12:07
  • yes everywhere event if i put exit here my fornt page distrub – imtia Jul 16 '18 at 12:08
  • Can you try to return static value and check if its showing on frontend? Otherwise you need to use Plugin for that. – Sukumar Gorai Jul 16 '18 at 12:12
  • already done that both – imtia Jul 16 '18 at 12:23
0

Check in your registration.php module name is similar like in module.xml(No typo there)

And check after removing generated folder

rm -rf generated/*

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.