I'm trying to replace a class method "wrapResult" from:


Never enter into this method. Try to stop the execution with die () or with xdebug, enter directly to the parent method.

What I can be doing wrong?


<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <preference for="Magento\Catalog\Pricing\Render\FinalPriceBox"

Class FinalPriceBox:

namespace Mod\RepSales\Pricing\Render;    

use Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolverInterface;
use Magento\Catalog\Pricing\Price\MinimalPriceCalculatorInterface;
use Magento\Framework\Pricing\Price\PriceInterface;
use Magento\Framework\Pricing\Render\RendererPool;
use Magento\Framework\Pricing\SaleableInterface;
use Magento\Framework\View\Element\Template\Context;

class FinalPriceBox extends \Magento\Catalog\Pricing\Render\FinalPriceBox
    const ATTR_PVP = 'sgi_pvp';

    protected $helperPrice;
    protected $helperRepSalesPrices;

    public function __construct(
        Context $context,
        SaleableInterface $saleableItem,
        PriceInterface $price,
        RendererPool $rendererPool,
        array $data = [],
        SalableResolverInterface $salableResolver = null,
        MinimalPriceCalculatorInterface $minimalPriceCalculator = null,
        \Mod\RepSales\Helper\RepSalesPrices $helperRepSalesPrices,
        \Magento\Framework\Pricing\Helper\Data $helperPrice
        $this->helperRepSalesPrices = $helperRepSalesPrices;
        $this->helperPrice = $helperPrice;
        parent::__construct($context, $saleableItem, $price, $rendererPool, $data, $salableResolver, $minimalPriceCalculator);

    protected function wrapResult($html)

        if ($this->helperRepSalesPrices->changePrices()) {
            $price = $this->getSaleableItem()->getData(self::ATTR_PVP);
            $price = floatval(str_replace(',', '.', $price));
            $priceFormat = $this->helperPrice->currency(number_format($price, 2), true, false);

            $html = '<span class="price-container price-final_price tax weee">' .
                '<span id="product-price-' . $this->getSaleableItem()->getId() . '" data-price-amount="' . $price . '" data-price-type="finalPrice" class="price-wrapper ">' .
                '<span class="price">' . $priceFormat . '</span>' .
                '</span>' .

        return '<div class="price-box ' . $this->getData('css_classes') . '" ' .
            'data-role="priceBox" ' .
            'data-product-id="' . $this->getSaleableItem()->getId() . '"' .
            '>' . $html . '</div>';
  • Have you run setup:di:compile command? – Matthias_CompactCode Mar 21 at 15:00
  • @Matthias_CompactCode yes... all deploy:( – chdzma Mar 21 at 15:14

There might be several causes for this. There might be another module with a preference on this class. If this module is loaded after yours, your preference will be overwritten. Try debugging it by switching Magento\Catalog\Pricing\Render\FinalPriceBox to another class.

  • I have searched and only found VirtualType with this class. Is it possible to replace a function with VirtualType? – chdzma Mar 21 at 15:36
  • You cannot replace a function with VirtualType. Make sure your di.xml is located in the right area directory. – Matthias_CompactCode Mar 21 at 15:48

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.