1

Recently I create two after plugins, one that point to Magento\Catalog\Pricing\Price\FinalPrice::getValue() and other that point to Magento\Catalog\Model\Product::getPrice() and Magento\Catalog\Model\Product::getFinalPrice()

etc/frontend/di.xml

<?xml version="1.0" encoding="utf-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
  <type name="Magento\Catalog\Pricing\Price\FinalPrice">
      <plugin disabled="false" name="morwifinalprice" sortOrder="99" type="Morwi\PrecioRegional\Plugin\FinalPrice"/>
  </type>
  <type name="Magento\Catalog\Model\Product">
      <plugin disabled="false" name="morwifinalprice" sortOrder="99" type="Morwi\PrecioRegional\Plugin\Price"/>
  </type>
</config>

Plugin/FinalPrice.php

<?php
namespace Morwi\PrecioRegional\Plugin;

class FinalPrice
{
    ...

    /**
     * @param \Magento\Catalog\Pricing\Price\FinalPrice $subject
     * @param float $result
     * @return float
     */
    public function afterGetValue(\Magento\Catalog\Pricing\Price\FinalPrice $subject, $result){

      ...

      return $result;
    }
}
?>

Plugin/Price.php

<?php
namespace Morwi\PrecioRegional\Plugin;

class Price
{
    ...

    /**
     * @param \Magento\Catalog\Model\Product $subject
     * @param float $result
     * @return float
     */
    public function afterGetPrice(\Magento\Catalog\Model\Product $subject, $result){
      ...

      return $result;
    }


    /**
     * @param \Magento\Catalog\Model\Product $subject
     * @param float $result
     * @return float
     */
    public function afterGetFinalPrice(\Magento\Catalog\Model\Product $subject, $result){

      ...

      return $result;
    }
}
?>

The plugins work fine and are executed without problem on all the site. Except on checkout. When I pass from cart to checkout, my plugins are ignored. I debugged and detected that the original methods are executed:

Magento\Catalog\Pricing\Price\FinalPrice::getValue()

Magento\Catalog\Model\Product::getPrice()

Magento\Catalog\Model\Product::getFinalPrice()

But the plugins not. Why is it? How can I run my plugins on checkout?

Thanks.

1 Answer 1

1

I got the problem. The plugin was defined only to frontend area. But, during the checkout process, the page made some request defined on webapi_rest. So, I copied etc/frontend/di.xml to etc/webapi_rest/di.xml, and it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.