0

I am adding configurable products in to cart using the below code.

$product_id = 123; 
$qty        = 1; 
$product    = Mage::getModel('catalog/product')->load($product_id);
$cart       = Mage::getModel('checkout/cart'); 
$cart->init();

$superAttributeArray = array('151' => '3');

$params = array(
        'product' => $product_id,
        'qty'     => $qty,
        'super_attribute' => $superAttributeArray
     );
$cart->addProduct($product, $params);
$cart->save();

this code works well and I can able to add the product in to cart. Tested the same in Database.

I want to map user id for the quote that was created. products will be added only after loggging in. When I add products with above code, customer_id field in 'sales_flat_quote' table is NULL. I want current logged in user id need to be set to this quote.

Can any one help me with this?

0

Try

....
$cart->addProduct($product, $params);
$cart->save();

$customer_id = Mage::getSingleton('customer/session')->getCustomerId();
$quote = $cart->getQuote();
$quote->setCustomerId($customer_id);
$quote->save();
  • its not working ..!! anyhow thanks for your support – Mugunthan Aug 18 '15 at 15:38
  • Please explain more, is the customer_id field still blank? – Renon Stewart Aug 18 '15 at 15:44
  • Yes, after adding the code you have given, still customer_id field is empty. – Mugunthan Aug 19 '15 at 6:57
  • Can you add some debugging code .... Try to get the quote id before and after you save. $quote->getId() and the $quote->setCustomerId() – Renon Stewart Aug 19 '15 at 13:09

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.