How to change the product price with a plugin in Magento 2.1?Magento 2 override associated product price (configurable and it's child)How to add extra price on configurable product and it's child (Simple Product) magento 2xIn magento which price or price rule has the highest priority?best practice to connect Magento 2 to price/product serviceMagento 2.1 proxy with di preferenceHow to change the price in checkout page in magento2Magento 2: How to get the price of a product?Magento 2 - Product price plugin does not work on promotionMagento 2 - how to set final price for product on view pageMagento 2 plugin change price of products that have a custom attribute withAfter Plugin does not run at checkoutMagento 2.1 - How to set shipping method at Checkout page programmatically

find not returning expected files

Is the homebrew weapon attack cantrip 'Arcane Strike' balanced?

What are some possible reasons that a father's name is missing from a birth certificate - England?

Why does a C.D.F need to be right-continuous?

Does the 500 feet falling cap apply per fall, or per turn?

Make all the squares explode

How do I compare the result of "1d20+x, with advantage" to "1d20+y, without advantage", assuming x < y?

51% attack - apparently very easy? refering to CZ's "rollback btc chain" - How to make sure such corruptible scenario can never happen so easily?

Cropping a message using array splits

Why do unstable nuclei form?

What did Rocket give Hawkeye in "Avengers: Endgame"?

International Code of Ethics for order of co-authors in research papers

Is there enough time to Planar Bind a creature conjured by a 1-hour-duration spell?

Would an 8% reduction in drag outweigh the weight addition from this custom CFD-tested winglet?

Is there a need for better software for writers?

Help decide course of action for rotting windows

Increase height of laser cut design file for enclosure

What does i386 mean on macOS Mojave?

Was this a power play by Daenerys?

Why was this sacrifice sufficient?

How do I get past a 3-year ban from overstay with VWP?

Was the Highlands Ranch shooting the 115th mass shooting in the US in 2019

Control variables and other independent variables

How can this pool heater gas line be disconnected?



How to change the product price with a plugin in Magento 2.1?


Magento 2 override associated product price (configurable and it's child)How to add extra price on configurable product and it's child (Simple Product) magento 2xIn magento which price or price rule has the highest priority?best practice to connect Magento 2 to price/product serviceMagento 2.1 proxy with di preferenceHow to change the price in checkout page in magento2Magento 2: How to get the price of a product?Magento 2 - Product price plugin does not work on promotionMagento 2 - how to set final price for product on view pageMagento 2 plugin change price of products that have a custom attribute withAfter Plugin does not run at checkoutMagento 2.1 - How to set shipping method at Checkout page programmatically






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















UPDATE



After a lot of debugging I found out that the plugin is loaded on the product detail page but not in the checkout.
It seems that the checkout gets the values from somewhere before so that is why the price is correct initially. But if Javascript is triggered it goes through the module loading process again and there the plugin is not loaded. Thus the original magento database price is loaded.



The problem seems to be in var/generation/Magento/Catalog/Model/Product/Interceptor.php
in function getPrice.
There they fetch $pluginInfo and this contains an array with my plugin. But only on the product detail page. In the checkout this array is always null and therefor it only calls parent::getPrice().



I wonder why my plugin is not loaded in the checkout?



Here is how I setup the plugin:



registration.php



<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'<vendor>_<plugin>',
__DIR__
);


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="MagentoCatalogModelProduct" shared="false">
<plugin
name="<vendor>_<plugin>_productplugin"
type="<vendor><plugin>PluginProductProductPlugin"
disabled="false"
sortOrder="999" />
</type>
</config>


app/code/<vendor>/<plugin>/Plugin/Product/ProductPlugin.php



<?php

namespace <vendor><plugin>PluginProduct;

class ProductPlugin

public function afterGetPrice($product, $proceed) : float

return 111.55;





OLD INFO



I already build a mage2-module with a plugin for MagentoCatalogModelProduct and created an afterGetPrice() method. This works fine for:



  • product detail page

  • checkout/cart product listing on the left

But the problem is that the widget/sidebar summary component at the checkout on the right side of the e.g. Luma theme shows the right prices for a short moment, than an ajax request to the Magento REST-API changes all prices to the normal Magento product prices so the plugin does not work here.



Before everything is ok and can be checkt via console:



window.checkoutConfig;


quoteData and totalsData have got the proper prices. Later they will be updated by the response of totals-information.



I think these endpoints could be used for this action depending on the situation:



POST /V1/carts/:cartId/totals-information
POST /V1/guest-carts/:cartId/totals-information
POST /V1/carts/mine/totals-information

<preference for="MagentoCheckoutApiDataTotalsInformationInterface" type="MagentoCheckoutModelTotalsInformation" />
<preference for="MagentoCheckoutApiGuestTotalsInformationManagementInterface" type="MagentoCheckoutModelGuestTotalsInformationManagement" />
<preference for="MagentoCheckoutApiTotalsInformationManagementInterface" type="MagentoCheckoutModelTotalsInformationManagement" />


In my own theme no such reloading takes place but in step 2 of the onepage checkout the prices are also wrong.




How can I achieve to overwrite the prices in the frontend with my own
prices and in case of no data with the original price, like the
afterGetPrice() function does?




Here you can see the process in screenshots:



  1. first it loads the page with the correct price (sorry it's german language)
    enter image description here


  2. then it reloads the summary box
    enter image description here


  3. after the refresh the price is the magento price without the afterGetPrice() method being runenter image description here










share|improve this question






























    1















    UPDATE



    After a lot of debugging I found out that the plugin is loaded on the product detail page but not in the checkout.
    It seems that the checkout gets the values from somewhere before so that is why the price is correct initially. But if Javascript is triggered it goes through the module loading process again and there the plugin is not loaded. Thus the original magento database price is loaded.



    The problem seems to be in var/generation/Magento/Catalog/Model/Product/Interceptor.php
    in function getPrice.
    There they fetch $pluginInfo and this contains an array with my plugin. But only on the product detail page. In the checkout this array is always null and therefor it only calls parent::getPrice().



    I wonder why my plugin is not loaded in the checkout?



    Here is how I setup the plugin:



    registration.php



    <?php
    MagentoFrameworkComponentComponentRegistrar::register(
    MagentoFrameworkComponentComponentRegistrar::MODULE,
    '<vendor>_<plugin>',
    __DIR__
    );


    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="MagentoCatalogModelProduct" shared="false">
    <plugin
    name="<vendor>_<plugin>_productplugin"
    type="<vendor><plugin>PluginProductProductPlugin"
    disabled="false"
    sortOrder="999" />
    </type>
    </config>


    app/code/<vendor>/<plugin>/Plugin/Product/ProductPlugin.php



    <?php

    namespace <vendor><plugin>PluginProduct;

    class ProductPlugin

    public function afterGetPrice($product, $proceed) : float

    return 111.55;





    OLD INFO



    I already build a mage2-module with a plugin for MagentoCatalogModelProduct and created an afterGetPrice() method. This works fine for:



    • product detail page

    • checkout/cart product listing on the left

    But the problem is that the widget/sidebar summary component at the checkout on the right side of the e.g. Luma theme shows the right prices for a short moment, than an ajax request to the Magento REST-API changes all prices to the normal Magento product prices so the plugin does not work here.



    Before everything is ok and can be checkt via console:



    window.checkoutConfig;


    quoteData and totalsData have got the proper prices. Later they will be updated by the response of totals-information.



    I think these endpoints could be used for this action depending on the situation:



    POST /V1/carts/:cartId/totals-information
    POST /V1/guest-carts/:cartId/totals-information
    POST /V1/carts/mine/totals-information

    <preference for="MagentoCheckoutApiDataTotalsInformationInterface" type="MagentoCheckoutModelTotalsInformation" />
    <preference for="MagentoCheckoutApiGuestTotalsInformationManagementInterface" type="MagentoCheckoutModelGuestTotalsInformationManagement" />
    <preference for="MagentoCheckoutApiTotalsInformationManagementInterface" type="MagentoCheckoutModelTotalsInformationManagement" />


    In my own theme no such reloading takes place but in step 2 of the onepage checkout the prices are also wrong.




    How can I achieve to overwrite the prices in the frontend with my own
    prices and in case of no data with the original price, like the
    afterGetPrice() function does?




    Here you can see the process in screenshots:



    1. first it loads the page with the correct price (sorry it's german language)
      enter image description here


    2. then it reloads the summary box
      enter image description here


    3. after the refresh the price is the magento price without the afterGetPrice() method being runenter image description here










    share|improve this question


























      1












      1








      1


      3






      UPDATE



      After a lot of debugging I found out that the plugin is loaded on the product detail page but not in the checkout.
      It seems that the checkout gets the values from somewhere before so that is why the price is correct initially. But if Javascript is triggered it goes through the module loading process again and there the plugin is not loaded. Thus the original magento database price is loaded.



      The problem seems to be in var/generation/Magento/Catalog/Model/Product/Interceptor.php
      in function getPrice.
      There they fetch $pluginInfo and this contains an array with my plugin. But only on the product detail page. In the checkout this array is always null and therefor it only calls parent::getPrice().



      I wonder why my plugin is not loaded in the checkout?



      Here is how I setup the plugin:



      registration.php



      <?php
      MagentoFrameworkComponentComponentRegistrar::register(
      MagentoFrameworkComponentComponentRegistrar::MODULE,
      '<vendor>_<plugin>',
      __DIR__
      );


      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="MagentoCatalogModelProduct" shared="false">
      <plugin
      name="<vendor>_<plugin>_productplugin"
      type="<vendor><plugin>PluginProductProductPlugin"
      disabled="false"
      sortOrder="999" />
      </type>
      </config>


      app/code/<vendor>/<plugin>/Plugin/Product/ProductPlugin.php



      <?php

      namespace <vendor><plugin>PluginProduct;

      class ProductPlugin

      public function afterGetPrice($product, $proceed) : float

      return 111.55;





      OLD INFO



      I already build a mage2-module with a plugin for MagentoCatalogModelProduct and created an afterGetPrice() method. This works fine for:



      • product detail page

      • checkout/cart product listing on the left

      But the problem is that the widget/sidebar summary component at the checkout on the right side of the e.g. Luma theme shows the right prices for a short moment, than an ajax request to the Magento REST-API changes all prices to the normal Magento product prices so the plugin does not work here.



      Before everything is ok and can be checkt via console:



      window.checkoutConfig;


      quoteData and totalsData have got the proper prices. Later they will be updated by the response of totals-information.



      I think these endpoints could be used for this action depending on the situation:



      POST /V1/carts/:cartId/totals-information
      POST /V1/guest-carts/:cartId/totals-information
      POST /V1/carts/mine/totals-information

      <preference for="MagentoCheckoutApiDataTotalsInformationInterface" type="MagentoCheckoutModelTotalsInformation" />
      <preference for="MagentoCheckoutApiGuestTotalsInformationManagementInterface" type="MagentoCheckoutModelGuestTotalsInformationManagement" />
      <preference for="MagentoCheckoutApiTotalsInformationManagementInterface" type="MagentoCheckoutModelTotalsInformationManagement" />


      In my own theme no such reloading takes place but in step 2 of the onepage checkout the prices are also wrong.




      How can I achieve to overwrite the prices in the frontend with my own
      prices and in case of no data with the original price, like the
      afterGetPrice() function does?




      Here you can see the process in screenshots:



      1. first it loads the page with the correct price (sorry it's german language)
        enter image description here


      2. then it reloads the summary box
        enter image description here


      3. after the refresh the price is the magento price without the afterGetPrice() method being runenter image description here










      share|improve this question
















      UPDATE



      After a lot of debugging I found out that the plugin is loaded on the product detail page but not in the checkout.
      It seems that the checkout gets the values from somewhere before so that is why the price is correct initially. But if Javascript is triggered it goes through the module loading process again and there the plugin is not loaded. Thus the original magento database price is loaded.



      The problem seems to be in var/generation/Magento/Catalog/Model/Product/Interceptor.php
      in function getPrice.
      There they fetch $pluginInfo and this contains an array with my plugin. But only on the product detail page. In the checkout this array is always null and therefor it only calls parent::getPrice().



      I wonder why my plugin is not loaded in the checkout?



      Here is how I setup the plugin:



      registration.php



      <?php
      MagentoFrameworkComponentComponentRegistrar::register(
      MagentoFrameworkComponentComponentRegistrar::MODULE,
      '<vendor>_<plugin>',
      __DIR__
      );


      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="MagentoCatalogModelProduct" shared="false">
      <plugin
      name="<vendor>_<plugin>_productplugin"
      type="<vendor><plugin>PluginProductProductPlugin"
      disabled="false"
      sortOrder="999" />
      </type>
      </config>


      app/code/<vendor>/<plugin>/Plugin/Product/ProductPlugin.php



      <?php

      namespace <vendor><plugin>PluginProduct;

      class ProductPlugin

      public function afterGetPrice($product, $proceed) : float

      return 111.55;





      OLD INFO



      I already build a mage2-module with a plugin for MagentoCatalogModelProduct and created an afterGetPrice() method. This works fine for:



      • product detail page

      • checkout/cart product listing on the left

      But the problem is that the widget/sidebar summary component at the checkout on the right side of the e.g. Luma theme shows the right prices for a short moment, than an ajax request to the Magento REST-API changes all prices to the normal Magento product prices so the plugin does not work here.



      Before everything is ok and can be checkt via console:



      window.checkoutConfig;


      quoteData and totalsData have got the proper prices. Later they will be updated by the response of totals-information.



      I think these endpoints could be used for this action depending on the situation:



      POST /V1/carts/:cartId/totals-information
      POST /V1/guest-carts/:cartId/totals-information
      POST /V1/carts/mine/totals-information

      <preference for="MagentoCheckoutApiDataTotalsInformationInterface" type="MagentoCheckoutModelTotalsInformation" />
      <preference for="MagentoCheckoutApiGuestTotalsInformationManagementInterface" type="MagentoCheckoutModelGuestTotalsInformationManagement" />
      <preference for="MagentoCheckoutApiTotalsInformationManagementInterface" type="MagentoCheckoutModelTotalsInformationManagement" />


      In my own theme no such reloading takes place but in step 2 of the onepage checkout the prices are also wrong.




      How can I achieve to overwrite the prices in the frontend with my own
      prices and in case of no data with the original price, like the
      afterGetPrice() function does?




      Here you can see the process in screenshots:



      1. first it loads the page with the correct price (sorry it's german language)
        enter image description here


      2. then it reloads the summary box
        enter image description here


      3. after the refresh the price is the magento price without the afterGetPrice() method being runenter image description here







      magento2 product magento-2.1 checkout price






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 11 '17 at 16:57







      steros

















      asked May 11 '17 at 9:42









      sterossteros

      867730




      867730




















          4 Answers
          4






          active

          oldest

          votes


















          2














          The problem is that I placed the di.xml into the frontend subfolder, thinking that this defines the area the plugin applies to.
          But reading the docu ( http://devdocs.magento.com/guides/v2.1/architecture/archi_perspectives/components/modules/mod_and_areas.html )




          Magento area types



          Magento is organized into these main areas:



          Magento Admin (adminhtml): entry point for this area is index.php or
          pub/index.php. The Admin panel area includes the code needed for store
          management. The /app/design/adminhtml directory contains all the code
          for components you’ll see while working in the Admin panel.



          Storefront (frontend): entry point for this area is index.php or
          pub/index.php. The storefront (or frontend) contains template and
          layout files that define the appearance of your storefront.



          Basic (base): used as a fallback for files absent in adminhtml and
          frontend areas.




          again it seems that frontend refers only to display purposes but not saving or anything.






          share|improve this answer




















          • 1





            Hi. How did you solve this in the end? I have my di.xml in etc/adminhtml, etc/frontend & the base folder (etc). But the side column in the cart is still getting the price from the DB, and not my dynamic price. Price is displaying correctly in catalog. It's just the side bar and checkout!

            – sulman
            Sep 14 '17 at 15:02











          • Nice man you saved lots of time for me

            – Vaibhav Ahalpara
            Nov 8 '17 at 10:50


















          0














          Perhaps it's too late, but in magento 2, you can use event named : "controller_action_catalog_product_save_entity_after" in order to do action after product saved



          Will






          share|improve this answer























          • That will not work for the usecase I think as it works on the catalog which is not expected.

            – steros
            May 7 at 22:24


















          -1














          After a lot of debugging I found out that the plugin is loaded on the product detail page but not in the checkout.
          It seems that the checkout gets the values from somewhere before so that is why the price is correct initially. But if Javascript is triggered it goes through the module loading process again and there the plugin is not loaded. Thus the original magento database price is loaded.



          The problem seems to be in var/generation/Magento/Catalog/Model/Product/Interceptor.php
          in function getPrice.
          There they fetch $pluginInfo and this contains an array with my plugin. But only on the product detail page. In the checkout this array is always null and therefor it only calls parent::getPrice().



          I wonder why my plugin is not loaded in the checkout?



          Here is how I setup the plugin:



          registration.php



          <?php
          MagentoFrameworkComponentComponentRegistrar::register(
          MagentoFrameworkComponentComponentRegistrar::MODULE,
          '<vendor>_<plugin>',
          __DIR__
          );


          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="MagentoCatalogModelProduct" shared="false">
          <plugin
          name="<vendor>_<plugin>_productplugin"
          type="<vendor><plugin>PluginProductProductPlugin"
          disabled="false"
          sortOrder="999" />
          </type>
          </config>


          app/code/<vendor>/<plugin>/Plugin/Product/ProductPlugin.php



          <?php

          namespace <vendor><plugin>PluginProduct;

          class ProductPlugin

          public function afterGetPrice($product, $proceed) : float

          return 111.55;








          share|improve this answer























          • sorry what is the idea behind "copying" my findings?

            – steros
            May 11 '17 at 17:03


















          -1














          a litte late, but if anyone has the same problem, you also need to add an afterGetFinalPrice() method. This is what get called here. You can add that to your Product Plugin.






          share|improve this answer








          New contributor



          Chris is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.



















          • What version are you working with? I can't recall the need for this.

            – steros
            May 7 at 22:26











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "479"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f173979%2fhow-to-change-the-product-price-with-a-plugin-in-magento-2-1%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          4 Answers
          4






          active

          oldest

          votes








          4 Answers
          4






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          The problem is that I placed the di.xml into the frontend subfolder, thinking that this defines the area the plugin applies to.
          But reading the docu ( http://devdocs.magento.com/guides/v2.1/architecture/archi_perspectives/components/modules/mod_and_areas.html )




          Magento area types



          Magento is organized into these main areas:



          Magento Admin (adminhtml): entry point for this area is index.php or
          pub/index.php. The Admin panel area includes the code needed for store
          management. The /app/design/adminhtml directory contains all the code
          for components you’ll see while working in the Admin panel.



          Storefront (frontend): entry point for this area is index.php or
          pub/index.php. The storefront (or frontend) contains template and
          layout files that define the appearance of your storefront.



          Basic (base): used as a fallback for files absent in adminhtml and
          frontend areas.




          again it seems that frontend refers only to display purposes but not saving or anything.






          share|improve this answer




















          • 1





            Hi. How did you solve this in the end? I have my di.xml in etc/adminhtml, etc/frontend & the base folder (etc). But the side column in the cart is still getting the price from the DB, and not my dynamic price. Price is displaying correctly in catalog. It's just the side bar and checkout!

            – sulman
            Sep 14 '17 at 15:02











          • Nice man you saved lots of time for me

            – Vaibhav Ahalpara
            Nov 8 '17 at 10:50















          2














          The problem is that I placed the di.xml into the frontend subfolder, thinking that this defines the area the plugin applies to.
          But reading the docu ( http://devdocs.magento.com/guides/v2.1/architecture/archi_perspectives/components/modules/mod_and_areas.html )




          Magento area types



          Magento is organized into these main areas:



          Magento Admin (adminhtml): entry point for this area is index.php or
          pub/index.php. The Admin panel area includes the code needed for store
          management. The /app/design/adminhtml directory contains all the code
          for components you’ll see while working in the Admin panel.



          Storefront (frontend): entry point for this area is index.php or
          pub/index.php. The storefront (or frontend) contains template and
          layout files that define the appearance of your storefront.



          Basic (base): used as a fallback for files absent in adminhtml and
          frontend areas.




          again it seems that frontend refers only to display purposes but not saving or anything.






          share|improve this answer




















          • 1





            Hi. How did you solve this in the end? I have my di.xml in etc/adminhtml, etc/frontend & the base folder (etc). But the side column in the cart is still getting the price from the DB, and not my dynamic price. Price is displaying correctly in catalog. It's just the side bar and checkout!

            – sulman
            Sep 14 '17 at 15:02











          • Nice man you saved lots of time for me

            – Vaibhav Ahalpara
            Nov 8 '17 at 10:50













          2












          2








          2







          The problem is that I placed the di.xml into the frontend subfolder, thinking that this defines the area the plugin applies to.
          But reading the docu ( http://devdocs.magento.com/guides/v2.1/architecture/archi_perspectives/components/modules/mod_and_areas.html )




          Magento area types



          Magento is organized into these main areas:



          Magento Admin (adminhtml): entry point for this area is index.php or
          pub/index.php. The Admin panel area includes the code needed for store
          management. The /app/design/adminhtml directory contains all the code
          for components you’ll see while working in the Admin panel.



          Storefront (frontend): entry point for this area is index.php or
          pub/index.php. The storefront (or frontend) contains template and
          layout files that define the appearance of your storefront.



          Basic (base): used as a fallback for files absent in adminhtml and
          frontend areas.




          again it seems that frontend refers only to display purposes but not saving or anything.






          share|improve this answer















          The problem is that I placed the di.xml into the frontend subfolder, thinking that this defines the area the plugin applies to.
          But reading the docu ( http://devdocs.magento.com/guides/v2.1/architecture/archi_perspectives/components/modules/mod_and_areas.html )




          Magento area types



          Magento is organized into these main areas:



          Magento Admin (adminhtml): entry point for this area is index.php or
          pub/index.php. The Admin panel area includes the code needed for store
          management. The /app/design/adminhtml directory contains all the code
          for components you’ll see while working in the Admin panel.



          Storefront (frontend): entry point for this area is index.php or
          pub/index.php. The storefront (or frontend) contains template and
          layout files that define the appearance of your storefront.



          Basic (base): used as a fallback for files absent in adminhtml and
          frontend areas.




          again it seems that frontend refers only to display purposes but not saving or anything.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited May 12 '17 at 10:00

























          answered May 12 '17 at 9:23









          sterossteros

          867730




          867730







          • 1





            Hi. How did you solve this in the end? I have my di.xml in etc/adminhtml, etc/frontend & the base folder (etc). But the side column in the cart is still getting the price from the DB, and not my dynamic price. Price is displaying correctly in catalog. It's just the side bar and checkout!

            – sulman
            Sep 14 '17 at 15:02











          • Nice man you saved lots of time for me

            – Vaibhav Ahalpara
            Nov 8 '17 at 10:50












          • 1





            Hi. How did you solve this in the end? I have my di.xml in etc/adminhtml, etc/frontend & the base folder (etc). But the side column in the cart is still getting the price from the DB, and not my dynamic price. Price is displaying correctly in catalog. It's just the side bar and checkout!

            – sulman
            Sep 14 '17 at 15:02











          • Nice man you saved lots of time for me

            – Vaibhav Ahalpara
            Nov 8 '17 at 10:50







          1




          1





          Hi. How did you solve this in the end? I have my di.xml in etc/adminhtml, etc/frontend & the base folder (etc). But the side column in the cart is still getting the price from the DB, and not my dynamic price. Price is displaying correctly in catalog. It's just the side bar and checkout!

          – sulman
          Sep 14 '17 at 15:02





          Hi. How did you solve this in the end? I have my di.xml in etc/adminhtml, etc/frontend & the base folder (etc). But the side column in the cart is still getting the price from the DB, and not my dynamic price. Price is displaying correctly in catalog. It's just the side bar and checkout!

          – sulman
          Sep 14 '17 at 15:02













          Nice man you saved lots of time for me

          – Vaibhav Ahalpara
          Nov 8 '17 at 10:50





          Nice man you saved lots of time for me

          – Vaibhav Ahalpara
          Nov 8 '17 at 10:50













          0














          Perhaps it's too late, but in magento 2, you can use event named : "controller_action_catalog_product_save_entity_after" in order to do action after product saved



          Will






          share|improve this answer























          • That will not work for the usecase I think as it works on the catalog which is not expected.

            – steros
            May 7 at 22:24















          0














          Perhaps it's too late, but in magento 2, you can use event named : "controller_action_catalog_product_save_entity_after" in order to do action after product saved



          Will






          share|improve this answer























          • That will not work for the usecase I think as it works on the catalog which is not expected.

            – steros
            May 7 at 22:24













          0












          0








          0







          Perhaps it's too late, but in magento 2, you can use event named : "controller_action_catalog_product_save_entity_after" in order to do action after product saved



          Will






          share|improve this answer













          Perhaps it's too late, but in magento 2, you can use event named : "controller_action_catalog_product_save_entity_after" in order to do action after product saved



          Will







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 4 at 11:55









          William RossierWilliam Rossier

          1093




          1093












          • That will not work for the usecase I think as it works on the catalog which is not expected.

            – steros
            May 7 at 22:24

















          • That will not work for the usecase I think as it works on the catalog which is not expected.

            – steros
            May 7 at 22:24
















          That will not work for the usecase I think as it works on the catalog which is not expected.

          – steros
          May 7 at 22:24





          That will not work for the usecase I think as it works on the catalog which is not expected.

          – steros
          May 7 at 22:24











          -1














          After a lot of debugging I found out that the plugin is loaded on the product detail page but not in the checkout.
          It seems that the checkout gets the values from somewhere before so that is why the price is correct initially. But if Javascript is triggered it goes through the module loading process again and there the plugin is not loaded. Thus the original magento database price is loaded.



          The problem seems to be in var/generation/Magento/Catalog/Model/Product/Interceptor.php
          in function getPrice.
          There they fetch $pluginInfo and this contains an array with my plugin. But only on the product detail page. In the checkout this array is always null and therefor it only calls parent::getPrice().



          I wonder why my plugin is not loaded in the checkout?



          Here is how I setup the plugin:



          registration.php



          <?php
          MagentoFrameworkComponentComponentRegistrar::register(
          MagentoFrameworkComponentComponentRegistrar::MODULE,
          '<vendor>_<plugin>',
          __DIR__
          );


          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="MagentoCatalogModelProduct" shared="false">
          <plugin
          name="<vendor>_<plugin>_productplugin"
          type="<vendor><plugin>PluginProductProductPlugin"
          disabled="false"
          sortOrder="999" />
          </type>
          </config>


          app/code/<vendor>/<plugin>/Plugin/Product/ProductPlugin.php



          <?php

          namespace <vendor><plugin>PluginProduct;

          class ProductPlugin

          public function afterGetPrice($product, $proceed) : float

          return 111.55;








          share|improve this answer























          • sorry what is the idea behind "copying" my findings?

            – steros
            May 11 '17 at 17:03















          -1














          After a lot of debugging I found out that the plugin is loaded on the product detail page but not in the checkout.
          It seems that the checkout gets the values from somewhere before so that is why the price is correct initially. But if Javascript is triggered it goes through the module loading process again and there the plugin is not loaded. Thus the original magento database price is loaded.



          The problem seems to be in var/generation/Magento/Catalog/Model/Product/Interceptor.php
          in function getPrice.
          There they fetch $pluginInfo and this contains an array with my plugin. But only on the product detail page. In the checkout this array is always null and therefor it only calls parent::getPrice().



          I wonder why my plugin is not loaded in the checkout?



          Here is how I setup the plugin:



          registration.php



          <?php
          MagentoFrameworkComponentComponentRegistrar::register(
          MagentoFrameworkComponentComponentRegistrar::MODULE,
          '<vendor>_<plugin>',
          __DIR__
          );


          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="MagentoCatalogModelProduct" shared="false">
          <plugin
          name="<vendor>_<plugin>_productplugin"
          type="<vendor><plugin>PluginProductProductPlugin"
          disabled="false"
          sortOrder="999" />
          </type>
          </config>


          app/code/<vendor>/<plugin>/Plugin/Product/ProductPlugin.php



          <?php

          namespace <vendor><plugin>PluginProduct;

          class ProductPlugin

          public function afterGetPrice($product, $proceed) : float

          return 111.55;








          share|improve this answer























          • sorry what is the idea behind "copying" my findings?

            – steros
            May 11 '17 at 17:03













          -1












          -1








          -1







          After a lot of debugging I found out that the plugin is loaded on the product detail page but not in the checkout.
          It seems that the checkout gets the values from somewhere before so that is why the price is correct initially. But if Javascript is triggered it goes through the module loading process again and there the plugin is not loaded. Thus the original magento database price is loaded.



          The problem seems to be in var/generation/Magento/Catalog/Model/Product/Interceptor.php
          in function getPrice.
          There they fetch $pluginInfo and this contains an array with my plugin. But only on the product detail page. In the checkout this array is always null and therefor it only calls parent::getPrice().



          I wonder why my plugin is not loaded in the checkout?



          Here is how I setup the plugin:



          registration.php



          <?php
          MagentoFrameworkComponentComponentRegistrar::register(
          MagentoFrameworkComponentComponentRegistrar::MODULE,
          '<vendor>_<plugin>',
          __DIR__
          );


          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="MagentoCatalogModelProduct" shared="false">
          <plugin
          name="<vendor>_<plugin>_productplugin"
          type="<vendor><plugin>PluginProductProductPlugin"
          disabled="false"
          sortOrder="999" />
          </type>
          </config>


          app/code/<vendor>/<plugin>/Plugin/Product/ProductPlugin.php



          <?php

          namespace <vendor><plugin>PluginProduct;

          class ProductPlugin

          public function afterGetPrice($product, $proceed) : float

          return 111.55;








          share|improve this answer













          After a lot of debugging I found out that the plugin is loaded on the product detail page but not in the checkout.
          It seems that the checkout gets the values from somewhere before so that is why the price is correct initially. But if Javascript is triggered it goes through the module loading process again and there the plugin is not loaded. Thus the original magento database price is loaded.



          The problem seems to be in var/generation/Magento/Catalog/Model/Product/Interceptor.php
          in function getPrice.
          There they fetch $pluginInfo and this contains an array with my plugin. But only on the product detail page. In the checkout this array is always null and therefor it only calls parent::getPrice().



          I wonder why my plugin is not loaded in the checkout?



          Here is how I setup the plugin:



          registration.php



          <?php
          MagentoFrameworkComponentComponentRegistrar::register(
          MagentoFrameworkComponentComponentRegistrar::MODULE,
          '<vendor>_<plugin>',
          __DIR__
          );


          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="MagentoCatalogModelProduct" shared="false">
          <plugin
          name="<vendor>_<plugin>_productplugin"
          type="<vendor><plugin>PluginProductProductPlugin"
          disabled="false"
          sortOrder="999" />
          </type>
          </config>


          app/code/<vendor>/<plugin>/Plugin/Product/ProductPlugin.php



          <?php

          namespace <vendor><plugin>PluginProduct;

          class ProductPlugin

          public function afterGetPrice($product, $proceed) : float

          return 111.55;









          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 11 '17 at 17:00









          Rafael Corrêa GomesRafael Corrêa Gomes

          4,81023366




          4,81023366












          • sorry what is the idea behind "copying" my findings?

            – steros
            May 11 '17 at 17:03

















          • sorry what is the idea behind "copying" my findings?

            – steros
            May 11 '17 at 17:03
















          sorry what is the idea behind "copying" my findings?

          – steros
          May 11 '17 at 17:03





          sorry what is the idea behind "copying" my findings?

          – steros
          May 11 '17 at 17:03











          -1














          a litte late, but if anyone has the same problem, you also need to add an afterGetFinalPrice() method. This is what get called here. You can add that to your Product Plugin.






          share|improve this answer








          New contributor



          Chris is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.



















          • What version are you working with? I can't recall the need for this.

            – steros
            May 7 at 22:26















          -1














          a litte late, but if anyone has the same problem, you also need to add an afterGetFinalPrice() method. This is what get called here. You can add that to your Product Plugin.






          share|improve this answer








          New contributor



          Chris is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.



















          • What version are you working with? I can't recall the need for this.

            – steros
            May 7 at 22:26













          -1












          -1








          -1







          a litte late, but if anyone has the same problem, you also need to add an afterGetFinalPrice() method. This is what get called here. You can add that to your Product Plugin.






          share|improve this answer








          New contributor



          Chris is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          a litte late, but if anyone has the same problem, you also need to add an afterGetFinalPrice() method. This is what get called here. You can add that to your Product Plugin.







          share|improve this answer








          New contributor



          Chris is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.








          share|improve this answer



          share|improve this answer






          New contributor



          Chris is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.








          answered May 7 at 13:15









          ChrisChris

          12




          12




          New contributor



          Chris is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.




          New contributor




          Chris is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.














          • What version are you working with? I can't recall the need for this.

            – steros
            May 7 at 22:26

















          • What version are you working with? I can't recall the need for this.

            – steros
            May 7 at 22:26
















          What version are you working with? I can't recall the need for this.

          – steros
          May 7 at 22:26





          What version are you working with? I can't recall the need for this.

          – steros
          May 7 at 22:26

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f173979%2fhow-to-change-the-product-price-with-a-plugin-in-magento-2-1%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

          Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

          Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?