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;
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
add a comment |
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
add a comment |
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
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
magento2 customer addtocart
asked May 14 at 10:15
Robinio TorRobinio Tor
32811
32811
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered May 14 at 10:17
Sunil PatelSunil Patel
1,5231612
1,5231612
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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