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

                    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?