How to add custom option price when product is adding add to cart using controllerUpdate product custom option price in observerAdd custom options while adding grouped product to cartForcing a certain custom option value when customer adding product to cartMake custom option price to be added to bundle product price in cartadd new custom option in cart not work while adding configurable product using observerWhen Adding a product to cart programatically ,the price of the product becomes zero ($0.00)custom option when product add to cart in magento 2.2.5How to add custom option before adding to cart by code in Magento 2?How to set custom tax price during add to cart in Magento 2Add existing custom option to cart item if the option was not included initially

Why the lack of hesitance to wear pads on the sabbath?

Could IPv6 make NAT / port numbers redundant?

Can a non-EU citizen travel within the Schengen area without identity documents?

Is there an evolutionary advantage to having two heads?

If a massive object like Jupiter flew past the Earth how close would it need to come to pull people off of the surface?

Draw a checker pattern with a black X in the center

What are the slash markings on Gatwick's 08R/26L?

What is the intuition behind uniform continuity?

Adding strings in lists together

Thousands and thousands of words

Windows 10 Programs start without visual Interface

Understanding STM32 datasheet regarding decoupling capacitors

Do creatures all have the same statistics upon being reanimated via the Animate Dead spell?

How to make the POV character sit on the sidelines without the reader getting bored

Is having a hidden directory under /etc safe?

How crucial is a waifu game storyline?

The deliberate use of misleading terminology

My player wants to cast multiple charges of magic missile from a wand

Could I be denied entry into Ireland due to medical and police situations during a previous UK visit?

How can I grammatically understand "Wir über uns"?

What does "Marchentalender" on the front of a postcard mean?

How were these pictures of spacecraft wind tunnel testing taken?

How should I push back against my job assigning "homework"?

Rotated Position of Integers



How to add custom option price when product is adding add to cart using controller


Update product custom option price in observerAdd custom options while adding grouped product to cartForcing a certain custom option value when customer adding product to cartMake custom option price to be added to bundle product price in cartadd new custom option in cart not work while adding configurable product using observerWhen Adding a product to cart programatically ,the price of the product becomes zero ($0.00)custom option when product add to cart in magento 2.2.5How to add custom option before adding to cart by code in Magento 2?How to set custom tax price during add to cart in Magento 2Add existing custom option to cart item if the option was not included initially






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








0















I have to add the custom option price when product is adding add to cart using controller










share|improve this question






























    0















    I have to add the custom option price when product is adding add to cart using controller










    share|improve this question


























      0












      0








      0








      I have to add the custom option price when product is adding add to cart using controller










      share|improve this question
















      I have to add the custom option price when product is adding add to cart using controller







      magento2 price custom-options addtocart controllers






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 24 at 8:49









      Muhammad Anas

      1,2233526




      1,2233526










      asked May 23 at 10:46









      Divya Divya

      875




      875




















          1 Answer
          1






          active

          oldest

          votes


















          0














          If you have a product with custom options like this -



          enter image description here



          and you want to add it to cart with the option Zip Type = Metal, use the following code:



           <?php
          namespace MyVendorMyModule;

          use MagentoFrameworkExceptionNoSuchEntityException;
          use MagentoCatalogApiProductRepositoryInterface;

          class AddToCart

          private $cart;
          private $productRepository;
          private $storeManager;

          public function __construct(
          MagentoCheckoutModelCart $cart,
          ProductRepositoryInterface $productRepository,
          MagentoStoreModelStoreManagerInterface $storeManager,
          )
          $this->cart = $cart;
          $this->productRepository = $productRepository;
          $this->storeManager = $storeManager;



          protected function _initProduct($productId)

          $storeId = $this->storeManager->getStore()->getId();
          try
          return $this->productRepository->getById($productId, false, $storeId);
          catch (NoSuchEntityException $e)
          return false;




          public function addToCart()

          $product = $this->_initProduct("8");
          $this->cart->addProduct($product, ['options' => [1 => 2]] );
          $this->cart->save();







          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%2f275843%2fhow-to-add-custom-option-price-when-product-is-adding-add-to-cart-using-controll%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














            If you have a product with custom options like this -



            enter image description here



            and you want to add it to cart with the option Zip Type = Metal, use the following code:



             <?php
            namespace MyVendorMyModule;

            use MagentoFrameworkExceptionNoSuchEntityException;
            use MagentoCatalogApiProductRepositoryInterface;

            class AddToCart

            private $cart;
            private $productRepository;
            private $storeManager;

            public function __construct(
            MagentoCheckoutModelCart $cart,
            ProductRepositoryInterface $productRepository,
            MagentoStoreModelStoreManagerInterface $storeManager,
            )
            $this->cart = $cart;
            $this->productRepository = $productRepository;
            $this->storeManager = $storeManager;



            protected function _initProduct($productId)

            $storeId = $this->storeManager->getStore()->getId();
            try
            return $this->productRepository->getById($productId, false, $storeId);
            catch (NoSuchEntityException $e)
            return false;




            public function addToCart()

            $product = $this->_initProduct("8");
            $this->cart->addProduct($product, ['options' => [1 => 2]] );
            $this->cart->save();







            share|improve this answer



























              0














              If you have a product with custom options like this -



              enter image description here



              and you want to add it to cart with the option Zip Type = Metal, use the following code:



               <?php
              namespace MyVendorMyModule;

              use MagentoFrameworkExceptionNoSuchEntityException;
              use MagentoCatalogApiProductRepositoryInterface;

              class AddToCart

              private $cart;
              private $productRepository;
              private $storeManager;

              public function __construct(
              MagentoCheckoutModelCart $cart,
              ProductRepositoryInterface $productRepository,
              MagentoStoreModelStoreManagerInterface $storeManager,
              )
              $this->cart = $cart;
              $this->productRepository = $productRepository;
              $this->storeManager = $storeManager;



              protected function _initProduct($productId)

              $storeId = $this->storeManager->getStore()->getId();
              try
              return $this->productRepository->getById($productId, false, $storeId);
              catch (NoSuchEntityException $e)
              return false;




              public function addToCart()

              $product = $this->_initProduct("8");
              $this->cart->addProduct($product, ['options' => [1 => 2]] );
              $this->cart->save();







              share|improve this answer

























                0












                0








                0







                If you have a product with custom options like this -



                enter image description here



                and you want to add it to cart with the option Zip Type = Metal, use the following code:



                 <?php
                namespace MyVendorMyModule;

                use MagentoFrameworkExceptionNoSuchEntityException;
                use MagentoCatalogApiProductRepositoryInterface;

                class AddToCart

                private $cart;
                private $productRepository;
                private $storeManager;

                public function __construct(
                MagentoCheckoutModelCart $cart,
                ProductRepositoryInterface $productRepository,
                MagentoStoreModelStoreManagerInterface $storeManager,
                )
                $this->cart = $cart;
                $this->productRepository = $productRepository;
                $this->storeManager = $storeManager;



                protected function _initProduct($productId)

                $storeId = $this->storeManager->getStore()->getId();
                try
                return $this->productRepository->getById($productId, false, $storeId);
                catch (NoSuchEntityException $e)
                return false;




                public function addToCart()

                $product = $this->_initProduct("8");
                $this->cart->addProduct($product, ['options' => [1 => 2]] );
                $this->cart->save();







                share|improve this answer













                If you have a product with custom options like this -



                enter image description here



                and you want to add it to cart with the option Zip Type = Metal, use the following code:



                 <?php
                namespace MyVendorMyModule;

                use MagentoFrameworkExceptionNoSuchEntityException;
                use MagentoCatalogApiProductRepositoryInterface;

                class AddToCart

                private $cart;
                private $productRepository;
                private $storeManager;

                public function __construct(
                MagentoCheckoutModelCart $cart,
                ProductRepositoryInterface $productRepository,
                MagentoStoreModelStoreManagerInterface $storeManager,
                )
                $this->cart = $cart;
                $this->productRepository = $productRepository;
                $this->storeManager = $storeManager;



                protected function _initProduct($productId)

                $storeId = $this->storeManager->getStore()->getId();
                try
                return $this->productRepository->getById($productId, false, $storeId);
                catch (NoSuchEntityException $e)
                return false;




                public function addToCart()

                $product = $this->_initProduct("8");
                $this->cart->addProduct($product, ['options' => [1 => 2]] );
                $this->cart->save();








                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered May 23 at 12:20









                NoamNNoamN

                18816




                18816



























                    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%2f275843%2fhow-to-add-custom-option-price-when-product-is-adding-add-to-cart-using-controll%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