Magento 2 Add discount on bundle product on add to cart timeCan Catalog Price Rules be applied to Bundles...

Does a paladin have to announce that they're using Divine Smite before attacking?

What can I do to encourage my players to use their consumables?

Does an Eldritch Knight's Weapon Bond protect him from losing his weapon to a Telekinesis spell?

The No-Straight Maze

Potential client has a problematic employee I can't work with

Why is one not obligated to give up his life rather than violate Lashon Hara?

How to politely refuse in-office gym instructor for steroids and protein

Current across a wire with zero potential difference

What senses are available to a corpse subjected to a Speak with Dead spell?

A starship is travelling at 0.9c and collides with a small rock. Will it leave a clean hole through, or will more happen?

Why do all the books in Game of Thrones library have their covers facing the back of the shelf?

Is there a way to not have to poll the UART of an AVR?

Non-Cancer terminal illness that can affect young (age 10-13) girls?

A Missing Symbol for This Logo

Can a magnetic field be induced without an electric field?

Is there a file that always exists and a 'normal' user can't lstat it?

Does Skippy chunky peanut butter contain trans fat?

Website seeing my Facebook data?

Is there a verb that means to inject with poison?

What makes papers publishable in top-tier journals?

Subsurf on a crown. How can I smooth some edges and keep others sharp?

Translation needed for 130 years old church document

How much mayhem could I cause as a fish?

Cat is tipping over bed-side lamps during the night



Magento 2 Add discount on bundle product on add to cart time


Can Catalog Price Rules be applied to Bundles with dynamic pricing?Bug in bundle children product price calculationMagento individual discount for inner product of bundle productGet Bundle Product to display its “base” simple product with Special and Regular PricesMake custom option price to be added to bundle product price in cartHow to Update Custom Product Total Price with DiscountMagento 2 : Add discount amount to applied discount in cartMagento2 : Add Simple Products to bundle product selectionHow to prevent cart price rules from applying to bundle products?Fails to add bundle product













1















I have to add some discount programmatically on the time of bundle product add to cart.



So far I have developed the catalog product plugin MagentoCatalogModelProduct function afterGetFinalPrice this plugin is worked on the basis of their child product prices so I have used another bundle price plugin MagentoBundleModelProductPrice function afterGetFinalPrice but it won't return desired output.



As per the Magento default flow, Magento is applying a discount on its child product but I like to apply the discount on bundle product total price.










share|improve this question





























    1















    I have to add some discount programmatically on the time of bundle product add to cart.



    So far I have developed the catalog product plugin MagentoCatalogModelProduct function afterGetFinalPrice this plugin is worked on the basis of their child product prices so I have used another bundle price plugin MagentoBundleModelProductPrice function afterGetFinalPrice but it won't return desired output.



    As per the Magento default flow, Magento is applying a discount on its child product but I like to apply the discount on bundle product total price.










    share|improve this question



























      1












      1








      1








      I have to add some discount programmatically on the time of bundle product add to cart.



      So far I have developed the catalog product plugin MagentoCatalogModelProduct function afterGetFinalPrice this plugin is worked on the basis of their child product prices so I have used another bundle price plugin MagentoBundleModelProductPrice function afterGetFinalPrice but it won't return desired output.



      As per the Magento default flow, Magento is applying a discount on its child product but I like to apply the discount on bundle product total price.










      share|improve this question
















      I have to add some discount programmatically on the time of bundle product add to cart.



      So far I have developed the catalog product plugin MagentoCatalogModelProduct function afterGetFinalPrice this plugin is worked on the basis of their child product prices so I have used another bundle price plugin MagentoBundleModelProductPrice function afterGetFinalPrice but it won't return desired output.



      As per the Magento default flow, Magento is applying a discount on its child product but I like to apply the discount on bundle product total price.







      magento2 cart price catalog bundle-product






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 4 hours ago







      Himanshu

















      asked 5 hours ago









      HimanshuHimanshu

      960622




      960622






















          1 Answer
          1






          active

          oldest

          votes


















          0














          You can create following files in your custom extension.




          etc/frontend/events.xml




          <?xml version="1.0" encoding="UTF-8"  ?>

          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
          <event name="sales_quote_item_set_product">
          <observer name="bundle_addto_cart_before" instance="[Vendor][Module]ObserverSetProduct" />
          </event>
          </config>


          File:




          Observer/SetProduct.php




          <?php

          namespace [Vendor][Module]Observer;

          use MagentoFrameworkEventObserver as EventObserver;
          use MagentoFrameworkEventObserverInterface;

          class SetProduct implements ObserverInterface
          {
          public function execute(EventObserver $observer)
          {
          $quoteItem = $observer->getEvent()->getQuoteItem();
          $product = $quoteItem->getProduct();
          if(!$quoteItem->getId() && $product->getTypeId() == MagentoCatalogModelProductType::TYPE_BUNDLE)
          {
          $originalPrice = $product->getFinalPrice();
          $customPrice = 22.5;
          $quoteItem->setPrice($customPrice);
          $quoteItem->setBasePrice($customPrice);
          $quoteItem->setCustomePrice(null);
          $quoteItem->setOriginalCustomPrice(null);
          $quoteItem->getProduct()->setIsSuperMode(false);
          }

          return $this;
          }
          }


          This should work.






          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%2f263384%2fmagento-2-add-discount-on-bundle-product-on-add-to-cart-time%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














            You can create following files in your custom extension.




            etc/frontend/events.xml




            <?xml version="1.0" encoding="UTF-8"  ?>

            <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
            <event name="sales_quote_item_set_product">
            <observer name="bundle_addto_cart_before" instance="[Vendor][Module]ObserverSetProduct" />
            </event>
            </config>


            File:




            Observer/SetProduct.php




            <?php

            namespace [Vendor][Module]Observer;

            use MagentoFrameworkEventObserver as EventObserver;
            use MagentoFrameworkEventObserverInterface;

            class SetProduct implements ObserverInterface
            {
            public function execute(EventObserver $observer)
            {
            $quoteItem = $observer->getEvent()->getQuoteItem();
            $product = $quoteItem->getProduct();
            if(!$quoteItem->getId() && $product->getTypeId() == MagentoCatalogModelProductType::TYPE_BUNDLE)
            {
            $originalPrice = $product->getFinalPrice();
            $customPrice = 22.5;
            $quoteItem->setPrice($customPrice);
            $quoteItem->setBasePrice($customPrice);
            $quoteItem->setCustomePrice(null);
            $quoteItem->setOriginalCustomPrice(null);
            $quoteItem->getProduct()->setIsSuperMode(false);
            }

            return $this;
            }
            }


            This should work.






            share|improve this answer






























              0














              You can create following files in your custom extension.




              etc/frontend/events.xml




              <?xml version="1.0" encoding="UTF-8"  ?>

              <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
              <event name="sales_quote_item_set_product">
              <observer name="bundle_addto_cart_before" instance="[Vendor][Module]ObserverSetProduct" />
              </event>
              </config>


              File:




              Observer/SetProduct.php




              <?php

              namespace [Vendor][Module]Observer;

              use MagentoFrameworkEventObserver as EventObserver;
              use MagentoFrameworkEventObserverInterface;

              class SetProduct implements ObserverInterface
              {
              public function execute(EventObserver $observer)
              {
              $quoteItem = $observer->getEvent()->getQuoteItem();
              $product = $quoteItem->getProduct();
              if(!$quoteItem->getId() && $product->getTypeId() == MagentoCatalogModelProductType::TYPE_BUNDLE)
              {
              $originalPrice = $product->getFinalPrice();
              $customPrice = 22.5;
              $quoteItem->setPrice($customPrice);
              $quoteItem->setBasePrice($customPrice);
              $quoteItem->setCustomePrice(null);
              $quoteItem->setOriginalCustomPrice(null);
              $quoteItem->getProduct()->setIsSuperMode(false);
              }

              return $this;
              }
              }


              This should work.






              share|improve this answer




























                0












                0








                0







                You can create following files in your custom extension.




                etc/frontend/events.xml




                <?xml version="1.0" encoding="UTF-8"  ?>

                <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
                <event name="sales_quote_item_set_product">
                <observer name="bundle_addto_cart_before" instance="[Vendor][Module]ObserverSetProduct" />
                </event>
                </config>


                File:




                Observer/SetProduct.php




                <?php

                namespace [Vendor][Module]Observer;

                use MagentoFrameworkEventObserver as EventObserver;
                use MagentoFrameworkEventObserverInterface;

                class SetProduct implements ObserverInterface
                {
                public function execute(EventObserver $observer)
                {
                $quoteItem = $observer->getEvent()->getQuoteItem();
                $product = $quoteItem->getProduct();
                if(!$quoteItem->getId() && $product->getTypeId() == MagentoCatalogModelProductType::TYPE_BUNDLE)
                {
                $originalPrice = $product->getFinalPrice();
                $customPrice = 22.5;
                $quoteItem->setPrice($customPrice);
                $quoteItem->setBasePrice($customPrice);
                $quoteItem->setCustomePrice(null);
                $quoteItem->setOriginalCustomPrice(null);
                $quoteItem->getProduct()->setIsSuperMode(false);
                }

                return $this;
                }
                }


                This should work.






                share|improve this answer















                You can create following files in your custom extension.




                etc/frontend/events.xml




                <?xml version="1.0" encoding="UTF-8"  ?>

                <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
                <event name="sales_quote_item_set_product">
                <observer name="bundle_addto_cart_before" instance="[Vendor][Module]ObserverSetProduct" />
                </event>
                </config>


                File:




                Observer/SetProduct.php




                <?php

                namespace [Vendor][Module]Observer;

                use MagentoFrameworkEventObserver as EventObserver;
                use MagentoFrameworkEventObserverInterface;

                class SetProduct implements ObserverInterface
                {
                public function execute(EventObserver $observer)
                {
                $quoteItem = $observer->getEvent()->getQuoteItem();
                $product = $quoteItem->getProduct();
                if(!$quoteItem->getId() && $product->getTypeId() == MagentoCatalogModelProductType::TYPE_BUNDLE)
                {
                $originalPrice = $product->getFinalPrice();
                $customPrice = 22.5;
                $quoteItem->setPrice($customPrice);
                $quoteItem->setBasePrice($customPrice);
                $quoteItem->setCustomePrice(null);
                $quoteItem->setOriginalCustomPrice(null);
                $quoteItem->getProduct()->setIsSuperMode(false);
                }

                return $this;
                }
                }


                This should work.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 4 hours ago









                Rakesh Donga

                1,225314




                1,225314










                answered 4 hours ago









                Yash ShahYash Shah

                5167




                5167






























                    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%2f263384%2fmagento-2-add-discount-on-bundle-product-on-add-to-cart-time%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

                    迭戈·戈丁...

                    A phrase ”follow into" in a context The 2019 Stack Overflow Developer Survey Results Are...

                    1960s short story making fun of James Bond-style spy fiction The 2019 Stack Overflow Developer...