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

                    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?