Skip to main content
changed formatting and corrected spellings
Source Link
Mohit Kumar Arora
  • 10.2k
  • 7
  • 28
  • 56

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

Custom\Outofstock\etc\di.xml

Custom\Outofstock\etc\di.xml

Custom\Outofstock\Pricing\Render\FinalPriceBox.php

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;
    }
}

}

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

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;
}

}

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

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;
    }
}

Custom\Outofstock\etc\di.xml

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;}

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;
}

}

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;}}

Custom\Outofstock\etc\di.xml

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;
}

}

added 1496 characters in body
Source Link
imtia
  • 67
  • 8

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

<preference for="Magento\Catalog\Pricing\Render\FinalPriceBox" type="Custom\Outofstock\Pricing\Render\FinalPriceBox" />
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; } }

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

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

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

<preference for="Magento\Catalog\Pricing\Render\FinalPriceBox" type="Custom\Outofstock\Pricing\Render\FinalPriceBox" />
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; } }
Source Link
imtia
  • 67
  • 8
Loading