0

I want to update the product price using plugin and I tried the afterGetPrice() plugin its working fine in normal case but showing wrong price calculation when catalog price rule applied, I want to apply catalog price rule before the plugin execution. I tired the below code :

di.xml :

 <?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Catalog\Model\Product">
        <plugin name="change_product" type="Vendor\Module\Plugin\Product" sortOrder="1" disabled="false"/>
    </type>
</config>

Product.php

public function afterGetPrice($product, $proceed) : float
    {
        return $proceed+111.55;
    }

I want to apply catalog price rule before the plugin execution.

  • in frontend or backend? – Mohit Rane Jul 25 '19 at 12:21
  • Can you talk us through the outcome you are trying to achieve? – Dominic Xigen Jul 25 '19 at 12:22
  • I just want to update the price on frontend via some condition – MagentoDev Jul 25 '19 at 12:23
  • post your di.xml and module.xml, also mention the file for this code afterGetPrice() you have mentioned. – Mohit Rane Jul 25 '19 at 12:27
  • @MohitRane question edited – MagentoDev Jul 25 '19 at 12:30
0

You should use afterGetFinalPrice instead of afterGetPrice, that way all calculations of prices will be done.

| improve this answer | |

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.