1

Since the upgrade from 2.2.x to 2.3.3 we have the problem that a customized tier price box is cached across all product pages.

I found a fix for this, by just changing the variable name.

This is the same in both versions:

use Magenerds\BasePrice\Helper\Data as MagenerdsBasePriceHelperData;
use Magento\Catalog\Model\Product;
use Magento\Framework\Json\Helper\Data;
use Magento\Framework\Math\Random;
use Magento\Framework\Pricing\Price\PriceInterface;
use Magento\Framework\Pricing\Render\RendererPool;
use Magento\Framework\View\Element\Template\Context;

class TierPricesWithBase extends \Magento\Catalog\Pricing\Render\PriceBox

This works:

public function __construct(
    Context $context,
    Product $saleableItem,
    PriceInterface $price,
    RendererPool $rendererPool,
    Data $jsonHelper,
    Random $mathRandom,
    MagenerdsBasePriceHelperData $basePriceHelper,
    array $data = []
) {
    parent::__construct($context, $saleableItem, $price, $rendererPool, $jsonHelper, $mathRandom, $data);

    $this->_basepriceHelper = $basePriceHelper;
}

This does not:

public function __construct(
    Context $context,
    Product $product,
    PriceInterface $price,
    RendererPool $rendererPool,
    Data $jsonHelper,
    Random $mathRandom,
    MagenerdsBasePriceHelperData $basePriceHelper,
    array $data = []
) {
    parent::__construct($context, $product, $price, $rendererPool, $jsonHelper, $mathRandom, $data);

    $this->_basepriceHelper = $basePriceHelper;
}

Only difference is the variable name $product.

How can the behavior differ? Is the object manager doing some reflection here based on variable names here and mess with the caching?

We are using PHP 7.2

Alex
  • 13,817
  • 19
  • 82
  • 163

2 Answers2

1

Between Magento version, the core code will have changed constructor dependency. Now, although the variables are identical, you have spotted the type is different.

I suggest to adjust your code so that it matches the constructor for the parent class.

Once you have done your adjustment, please clear the generated folder as it would otherwise lead you to think the adjustment have not resolved anything

In your case, I'd say likely the generated folder was the culprit or your permissions need tuning. I had a play changing on my local a class and its constructor parameters (see screenshot) and the code works a treat. enter image description here

Herve Tribouilloy
  • 7,668
  • 2
  • 13
  • 28
  • The type is the same, just the name differs. I have the fix already, but want to understand deeper why that happens. – Alex Dec 18 '19 at 16:05
1

in your new class argument signature must be same as extend class (parent) both in docblock type hint and constructor method type, variable

mrtuvn
  • 3,273
  • 5
  • 28
  • 39