-1

I added a product into the cart and tried to map customer id, email to that quote using the code below

$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 I try to set customerid,email,fname,lname am getting the error

"Mage registry key "controller" already exists".

Can anyone help me in fixing this issue?

  • 1
    Could you post the full stack trace for that error from exceptions.log? Something is calling Mage::register('controller', ...), but it's not clear what from your code. – Ryan Hoerr Aug 19 '15 at 15:09
  • Take a look at stackoverflow.com/questions/9737069/… – Renon Stewart Aug 19 '15 at 16:08
  • Is there a reason for manually loading the quote and not using Mage::getSingleton('checkout/session')->getQuote();? – Renon Stewart Aug 19 '15 at 16:12
0

Due to setStore it will throw error.remove setstore. load your quote using below code

Mage::getSingleton('checkout/session')->getQuote()->setCustomer(Mage::getSingleton('customer/session')->getCustomer())

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.