Magento – Programmatically assign customer to a quote

addtocartcustomermagento-1.9sales-quote

I have created a custom api for login and addtocart operations.
When the user is not logged in and add products to a cart that quote id is saved and when a user logged in using the my api then i want to assign this customer to the quote that i have saved before.The code ihave used to assign the customer to the quote is below.

$quoteId = '1720';
$customer = Mage::getModel('customer/customer');
$customer->loadByEmail($email);
$quote          =    Mage::getModel('sales/quote')->load($quoteId);
$quote->assignCustomer($customer);

But when this not working.When the customer is get logged in then a new quote is created against the user.But i want the customer to be assigned to the above quote that he has added before logged in.

Best Answer

A quote is actually a 'cart' object. A customer can have many quotes. One for each website. the quote object is not created when the customer is created. It is created when the customer adds the first product to the cart. Also a quote is not necessarily assigned to a customer. You can have a quote when browsing the website as guest. In that case the quote remains in the db after the session expires.

check bellow links for more help

How quotes work in Magento

https://stackoverflow.com/questions/20034568/create-quote-programmatically-doesnt-work

I hope this will help you.

Related Topic