How to add product to customer cart in magento2 programmaticallyMagento2 add custom address attributeMagento 2: How to override newsletter Subscriber modelMagento2 how to add configurable product to cart programmaticallyAdd to cart configurable product programatically magento2Add Product to Customer CartMagento 2: Add a product to the cart programmaticallyUpdate Product programmatically - Invalid method MagentoEavModelEntityAttribute::isScopeGlobalMagento 2 : Add product to cart as per customer with custom price programmaticallyadd to cart programmatically doesn't workHow to add product to the cart with customer id and product id magento 2.3?

How to become an Editorial board member?

Was Tyrion always a poor strategist?

why "American-born", not "America-born"?

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

Best practice for printing and evaluating formulas with the minimal coding

Circuit construction for execution of conditional statements using least significant bit

How should I mix small caps with digits or symbols?

Why does an injection from a set to a countable set imply that set is countable?

Difference in 1 user doing 1000 iterations and 1000 users doing 1 iteration in Load testing

Is there a way to generate a mapping graph like this?

Why did Nick Fury not hesitate in blowing up the plane he thought was carrying a nuke?

Does the fact that we can only measure the two-way speed of light undermine the axiom of invariance?

Bash - Execute two commands and get exit status 1 if first fails

On a piano, are the effects of holding notes and the sustain pedal the same for a single chord?

Is there a realtime, uncut video of Saturn V ignition through tower clear?

How could Dwarves prevent sand from filling up their settlements

What quantum phenomena violate the superposition principle in electromagnetism?

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

How does the +1 Keen Composite Longbow (+2 Str) work?

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

Are CTRL+C and <esc> the same?

If the Charles SSL Proxy shows me sensitive data, is that data insecure/exposed?

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

Mikrokosmos, BB 105, Vol. 1: No. 17 Contrary Motion (1) - Can't understand the structure



How to add product to customer cart in magento2 programmatically


Magento2 add custom address attributeMagento 2: How to override newsletter Subscriber modelMagento2 how to add configurable product to cart programmaticallyAdd to cart configurable product programatically magento2Add Product to Customer CartMagento 2: Add a product to the cart programmaticallyUpdate Product programmatically - Invalid method MagentoEavModelEntityAttribute::isScopeGlobalMagento 2 : Add product to cart as per customer with custom price programmaticallyadd to cart programmatically doesn't workHow to add product to the cart with customer id and product id magento 2.3?






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








0















Everything works well, but it adds for all by default, but I need it added for a specific customer, regardless of whether it’s active at the moment or not, I have a customer ID, but how can i add product to his card ?



 ...
MagentoCheckoutModelCart $cart,
MagentoCatalogModelProductRepository $productRepository,
MagentoQuoteModelQuoteRepository $quoteRepository,

...
$this->_cart = $cart;
$this->_productRepository = $productRepository;
$this->_quoteRepository = $quoteRepository;

...

public function autoAddToCart(){

....

try
$data = [
'qty' => $products_count,
'product' => $products_id,
'bundle_option' => $selectionProds
];
$this->_cart->addProduct($_product,$data);
$this->_cart->save();
$cartId = $this->_cart->getQuote()->getId();
$quote = $this->_quoteRepository->getActive($cartId);
$this->_quoteRepository->save($quote);
$quote->collectTotals();

catch(Exception $e)
echo $e->getMessage();










share|improve this question




























    0















    Everything works well, but it adds for all by default, but I need it added for a specific customer, regardless of whether it’s active at the moment or not, I have a customer ID, but how can i add product to his card ?



     ...
    MagentoCheckoutModelCart $cart,
    MagentoCatalogModelProductRepository $productRepository,
    MagentoQuoteModelQuoteRepository $quoteRepository,

    ...
    $this->_cart = $cart;
    $this->_productRepository = $productRepository;
    $this->_quoteRepository = $quoteRepository;

    ...

    public function autoAddToCart(){

    ....

    try
    $data = [
    'qty' => $products_count,
    'product' => $products_id,
    'bundle_option' => $selectionProds
    ];
    $this->_cart->addProduct($_product,$data);
    $this->_cart->save();
    $cartId = $this->_cart->getQuote()->getId();
    $quote = $this->_quoteRepository->getActive($cartId);
    $this->_quoteRepository->save($quote);
    $quote->collectTotals();

    catch(Exception $e)
    echo $e->getMessage();










    share|improve this question
























      0












      0








      0








      Everything works well, but it adds for all by default, but I need it added for a specific customer, regardless of whether it’s active at the moment or not, I have a customer ID, but how can i add product to his card ?



       ...
      MagentoCheckoutModelCart $cart,
      MagentoCatalogModelProductRepository $productRepository,
      MagentoQuoteModelQuoteRepository $quoteRepository,

      ...
      $this->_cart = $cart;
      $this->_productRepository = $productRepository;
      $this->_quoteRepository = $quoteRepository;

      ...

      public function autoAddToCart(){

      ....

      try
      $data = [
      'qty' => $products_count,
      'product' => $products_id,
      'bundle_option' => $selectionProds
      ];
      $this->_cart->addProduct($_product,$data);
      $this->_cart->save();
      $cartId = $this->_cart->getQuote()->getId();
      $quote = $this->_quoteRepository->getActive($cartId);
      $this->_quoteRepository->save($quote);
      $quote->collectTotals();

      catch(Exception $e)
      echo $e->getMessage();










      share|improve this question














      Everything works well, but it adds for all by default, but I need it added for a specific customer, regardless of whether it’s active at the moment or not, I have a customer ID, but how can i add product to his card ?



       ...
      MagentoCheckoutModelCart $cart,
      MagentoCatalogModelProductRepository $productRepository,
      MagentoQuoteModelQuoteRepository $quoteRepository,

      ...
      $this->_cart = $cart;
      $this->_productRepository = $productRepository;
      $this->_quoteRepository = $quoteRepository;

      ...

      public function autoAddToCart(){

      ....

      try
      $data = [
      'qty' => $products_count,
      'product' => $products_id,
      'bundle_option' => $selectionProds
      ];
      $this->_cart->addProduct($_product,$data);
      $this->_cart->save();
      $cartId = $this->_cart->getQuote()->getId();
      $quote = $this->_quoteRepository->getActive($cartId);
      $this->_quoteRepository->save($quote);
      $quote->collectTotals();

      catch(Exception $e)
      echo $e->getMessage();







      magento2 customer addtocart






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked May 14 at 10:15









      Robinio TorRobinio Tor

      32811




      32811




















          1 Answer
          1






          active

          oldest

          votes


















          0














          you need to assign customer to quote



          $quote->assignCustomer($customer);


          more info you can found
          https://webkul.com/blog/create-quote-and-order-programmatically-in-magento2/



          hope it will help you






          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%2f274515%2fhow-to-add-product-to-customer-cart-in-magento2-programmatically%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 need to assign customer to quote



            $quote->assignCustomer($customer);


            more info you can found
            https://webkul.com/blog/create-quote-and-order-programmatically-in-magento2/



            hope it will help you






            share|improve this answer



























              0














              you need to assign customer to quote



              $quote->assignCustomer($customer);


              more info you can found
              https://webkul.com/blog/create-quote-and-order-programmatically-in-magento2/



              hope it will help you






              share|improve this answer

























                0












                0








                0







                you need to assign customer to quote



                $quote->assignCustomer($customer);


                more info you can found
                https://webkul.com/blog/create-quote-and-order-programmatically-in-magento2/



                hope it will help you






                share|improve this answer













                you need to assign customer to quote



                $quote->assignCustomer($customer);


                more info you can found
                https://webkul.com/blog/create-quote-and-order-programmatically-in-magento2/



                hope it will help you







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered May 14 at 10:17









                Sunil PatelSunil Patel

                1,5231612




                1,5231612



























                    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%2f274515%2fhow-to-add-product-to-customer-cart-in-magento2-programmatically%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