cart - How to set custmer id for an quote in magento? -
i adding product cart , tried map customer id,email quote using 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(); $currenquoteid = mage::getsingleton('checkout/session')->getquoteid(); $store = mage::getsingleton('core/store')->load(mage::app()->getstore()->getid()); $quote = mage::getmodel('sales/quote')->setstore($store)->load($currenquoteid); $quote->setcustomerid('1')->setcustomeremail('test@gmail.com')->setcustomerfirstname('firstname')->setcustomerlastname('lastname'); $quote->save();
when try set customerid,email,fname,lname getting error "mage registry key "controller" exists".
can me in fixing issue?
something might work
$customerobj = mage::getmodel('customer/customer')->load($customerid); $quoteobj = mage::getmodel('sales/quote')->assigncustomer($customerobj); $storeid = mage::app()->getstore()->getid(); $quoteobj->setstore(mage::getsingleton('core/store')->load($storeid); $productobj = mage::getmodel('catalog/product')->load($productid); $quoteitem = mage::getmodel('sales/quote_item')->setproduct($productobj); $quoteitem->setquote($quoteobj); $quoteitem->setqty('1'); $quoteitem->setstoreid($storeid); $quoteobj->additem($quoteitem); $quoteobj->setstoreid($storeid); $quoteobj->collecttotals(); $quoteobj->save();
Comments
Post a Comment