In a custom module we extend \Magento\Catalog\Block\Product\ListProduct, so we need \Magento\Catalog\Block\Product\Context in our constructor.

But as I can see, it has now been marked as deprecated in MAGETWO-71174.

namespace Magento\Catalog\Block\Product;

 * Constructor modification point for Magento\Catalog\Block\Product\AbstractProduct.
 * All context classes were introduced to allow for backwards compatible constructor modifications
 * of classes that were supposed to be extended by extension developers.
 * Do not call methods of this class directly.
 * As Magento moves from inheritance-based APIs all such classes will be deprecated together with
 * the classes they were introduced for.
 * @deprecated 101.1.0
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Here is our constructor:

public function __construct(
    \Magento\Catalog\Block\Product\Context $context,
    \Magento\Framework\Data\Helper\PostHelper $postDataHelper,
    \Magento\Catalog\Model\Layer\Resolver $layerResolver,
    CategoryRepositoryInterface $categoryRepository,
    \Magento\Framework\Url\Helper\Data $urlHelper,
    array $data = [],

    PriceCurrencyInterface $priceCurrency,
    ProductRepositoryInterface $productRepository
) {

    $this->priceCurrency = $priceCurrency;
    $this->productRepository = $productRepository;

How do we replace it and with what?


Try this:

\Magento\Framework\View\Element\Template\Context $context


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.