magento 2 add to cart observer modify priceSet custom price of product when adding to cart code not workingMagento 2 - custom price can not add to subtotal and grand total after add to cartChange product price in cart each page loaded with observerHow to get quote item id in checkout_cart_product_add_after observer in magento2Set item price added to cartMagento-2 : How to set product custom price after add to cartMagento 2: I Want to add multiple product using checkboxRemoving Cart items - ObserverI have created one field using product form field for my price i want save my field value at product creation time from backend magento2Magento 2.2.5: Add, Update and Delete existing products Custom Options

Schwa-less Polysyllabic German Noun Stems of Germanic Origin

Gambler's Fallacy Dice

Farthing / Riding

How could the B-29 bomber back up under its own power?

Requirement for splicing neutrals in a switch

Do seaplanes need to get clearance for takeoff?

How did Jean Parisot de Valette, 49th Grand Master of the Order of Malta, die?

Separate the element after every 2nd ',' and push into next row in bash

Simple Arithmetic Puzzle 7. Or is it?

Germany rejected my entry to Schengen countries

If you attack a Tarrasque while swallowed, what AC do you need to beat to hit it?

Why is this python script running in background consuming 100 % CPU?

Are there historical examples of audiences drawn to a work that was "so bad it's good"?

US F1 Visa grace period attending a conference

Removing Doubles Destroy Topology

Which one of these Isp's for the Dawn spacecraft is wrong?

Vehemently against code formatting

Is it wise to pay off mortgage with 401k?

What Species of Trees are These?

Does science define life as "beginning at conception"?

How do we properly manage transitions within a descriptive section?

Does a windmilling propeller create more drag than a stopped propeller in an engine out scenario?

How to tease a romance without a cat and mouse chase?

Ribbon Cable Cross Talk - Is there a fix after the fact?



magento 2 add to cart observer modify price


Set custom price of product when adding to cart code not workingMagento 2 - custom price can not add to subtotal and grand total after add to cartChange product price in cart each page loaded with observerHow to get quote item id in checkout_cart_product_add_after observer in magento2Set item price added to cartMagento-2 : How to set product custom price after add to cartMagento 2: I Want to add multiple product using checkboxRemoving Cart items - ObserverI have created one field using product form field for my price i want save my field value at product creation time from backend magento2Magento 2.2.5: Add, Update and Delete existing products Custom Options






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








0















Wel i have plugin which shows price in frontend from custom attribute.



public function afterGetPrice(MagentoCatalogModelProduct $product, $price) 
if($product->getData('price_per_area')) $price = $product->getData('price_per_area');
return $price;



Now i need to revert price to original price when product is added to cart, made an observer with event: checkout_cart_product_add_before



public function execute(
MagentoFrameworkEventObserver $observer
)
$item = $observer->getEvent()->getData('product');
if($item->getData('price_per_area'))
$item->setPrice(($item->getSpecialPrice() ? $item->getSpecialPrice() : $item->getPrice()));




and here i have issue:
product is added to cart but the price is still the one from custom attribute, when i click on update cart button then it shows the correct price



before cart updateafter cart update
as you can see from screenshots the price which is shown in summary is correct in both cases.



also tried my observer with checkout_cart_product_add_after result was same. tried with custom theme and luma



is it magento/template bug or there is some work around ?










share|improve this question




























    0















    Wel i have plugin which shows price in frontend from custom attribute.



    public function afterGetPrice(MagentoCatalogModelProduct $product, $price) 
    if($product->getData('price_per_area')) $price = $product->getData('price_per_area');
    return $price;



    Now i need to revert price to original price when product is added to cart, made an observer with event: checkout_cart_product_add_before



    public function execute(
    MagentoFrameworkEventObserver $observer
    )
    $item = $observer->getEvent()->getData('product');
    if($item->getData('price_per_area'))
    $item->setPrice(($item->getSpecialPrice() ? $item->getSpecialPrice() : $item->getPrice()));




    and here i have issue:
    product is added to cart but the price is still the one from custom attribute, when i click on update cart button then it shows the correct price



    before cart updateafter cart update
    as you can see from screenshots the price which is shown in summary is correct in both cases.



    also tried my observer with checkout_cart_product_add_after result was same. tried with custom theme and luma



    is it magento/template bug or there is some work around ?










    share|improve this question
























      0












      0








      0








      Wel i have plugin which shows price in frontend from custom attribute.



      public function afterGetPrice(MagentoCatalogModelProduct $product, $price) 
      if($product->getData('price_per_area')) $price = $product->getData('price_per_area');
      return $price;



      Now i need to revert price to original price when product is added to cart, made an observer with event: checkout_cart_product_add_before



      public function execute(
      MagentoFrameworkEventObserver $observer
      )
      $item = $observer->getEvent()->getData('product');
      if($item->getData('price_per_area'))
      $item->setPrice(($item->getSpecialPrice() ? $item->getSpecialPrice() : $item->getPrice()));




      and here i have issue:
      product is added to cart but the price is still the one from custom attribute, when i click on update cart button then it shows the correct price



      before cart updateafter cart update
      as you can see from screenshots the price which is shown in summary is correct in both cases.



      also tried my observer with checkout_cart_product_add_after result was same. tried with custom theme and luma



      is it magento/template bug or there is some work around ?










      share|improve this question














      Wel i have plugin which shows price in frontend from custom attribute.



      public function afterGetPrice(MagentoCatalogModelProduct $product, $price) 
      if($product->getData('price_per_area')) $price = $product->getData('price_per_area');
      return $price;



      Now i need to revert price to original price when product is added to cart, made an observer with event: checkout_cart_product_add_before



      public function execute(
      MagentoFrameworkEventObserver $observer
      )
      $item = $observer->getEvent()->getData('product');
      if($item->getData('price_per_area'))
      $item->setPrice(($item->getSpecialPrice() ? $item->getSpecialPrice() : $item->getPrice()));




      and here i have issue:
      product is added to cart but the price is still the one from custom attribute, when i click on update cart button then it shows the correct price



      before cart updateafter cart update
      as you can see from screenshots the price which is shown in summary is correct in both cases.



      also tried my observer with checkout_cart_product_add_after result was same. tried with custom theme and luma



      is it magento/template bug or there is some work around ?







      magento2 magento2.3.1






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked May 14 at 11:49









      Naberd ZendiNaberd Zendi

      626




      626




















          1 Answer
          1






          active

          oldest

          votes


















          0














          Found out what caused this bug.



          it seem plugin function afterGetPrice influenced checkout price too, also didn't need an observer.



          modified my plugin code so it will not affect checkout prices.



          public function afterGetPrice(MagentoCatalogModelProduct $product, $price) 
          if($product->getData('price_per_area')) //per meter
          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $requestInterface = $objectManager->get('MagentoFrameworkAppRequestInterface');
          $moduleName = $requestInterface->getModuleName();
          if($product->getData('price_per_area'))
          if($moduleName != 'checkout')
          $price = $product->getData('price_per_area');



          return $price;






          share|improve this answer























            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%2f274537%2fmagento-2-add-to-cart-observer-modify-price%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Found out what caused this bug.



            it seem plugin function afterGetPrice influenced checkout price too, also didn't need an observer.



            modified my plugin code so it will not affect checkout prices.



            public function afterGetPrice(MagentoCatalogModelProduct $product, $price) 
            if($product->getData('price_per_area')) //per meter
            $objectManager = MagentoFrameworkAppObjectManager::getInstance();
            $requestInterface = $objectManager->get('MagentoFrameworkAppRequestInterface');
            $moduleName = $requestInterface->getModuleName();
            if($product->getData('price_per_area'))
            if($moduleName != 'checkout')
            $price = $product->getData('price_per_area');



            return $price;






            share|improve this answer



























              0














              Found out what caused this bug.



              it seem plugin function afterGetPrice influenced checkout price too, also didn't need an observer.



              modified my plugin code so it will not affect checkout prices.



              public function afterGetPrice(MagentoCatalogModelProduct $product, $price) 
              if($product->getData('price_per_area')) //per meter
              $objectManager = MagentoFrameworkAppObjectManager::getInstance();
              $requestInterface = $objectManager->get('MagentoFrameworkAppRequestInterface');
              $moduleName = $requestInterface->getModuleName();
              if($product->getData('price_per_area'))
              if($moduleName != 'checkout')
              $price = $product->getData('price_per_area');



              return $price;






              share|improve this answer

























                0












                0








                0







                Found out what caused this bug.



                it seem plugin function afterGetPrice influenced checkout price too, also didn't need an observer.



                modified my plugin code so it will not affect checkout prices.



                public function afterGetPrice(MagentoCatalogModelProduct $product, $price) 
                if($product->getData('price_per_area')) //per meter
                $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                $requestInterface = $objectManager->get('MagentoFrameworkAppRequestInterface');
                $moduleName = $requestInterface->getModuleName();
                if($product->getData('price_per_area'))
                if($moduleName != 'checkout')
                $price = $product->getData('price_per_area');



                return $price;






                share|improve this answer













                Found out what caused this bug.



                it seem plugin function afterGetPrice influenced checkout price too, also didn't need an observer.



                modified my plugin code so it will not affect checkout prices.



                public function afterGetPrice(MagentoCatalogModelProduct $product, $price) 
                if($product->getData('price_per_area')) //per meter
                $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                $requestInterface = $objectManager->get('MagentoFrameworkAppRequestInterface');
                $moduleName = $requestInterface->getModuleName();
                if($product->getData('price_per_area'))
                if($moduleName != 'checkout')
                $price = $product->getData('price_per_area');



                return $price;







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered May 14 at 13:32









                Naberd ZendiNaberd Zendi

                626




                626



























                    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%2f274537%2fmagento-2-add-to-cart-observer-modify-price%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

                    Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

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

                    Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form