1

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.

2

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.

1

As a suggestion,it will be better to merge you quote to current logged in user quote .Then it may be resolved the problem.

$quote = Mage::getModel('sales/quote')->load($quoteId));
// Change  the mode  of your code to active
$quote->setISActive(1);
$quote->save();
get the current quote id from session

$session        = Mage::getSingleton('checkout/session');
$Current_quote_id       = $session->getQuoteId();
$CurrentQuote = Mage::getModel('sales/quote')->load($Current_quote_id);
// Now merge your quote to current quote
$CurrentQuote->merge($quote);

// Also related the cart total after merge
$CurrentQuote->collectTotals()->save();

Zend_Debug::dump($CurrentQuote->getAllItems());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.