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'); 

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

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

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?

1 Answer 1



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

$customer_id = Mage::getSingleton('customer/session')->getCustomerId();
$quote = $cart->getQuote();
  • its not working ..!! anyhow thanks for your support
    – Mugunthan
    Aug 18, 2015 at 15:38
  • Please explain more, is the customer_id field still blank? Aug 18, 2015 at 15:44
  • Yes, after adding the code you have given, still customer_id field is empty.
    – Mugunthan
    Aug 19, 2015 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() Aug 19, 2015 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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