Pergunta

I'm working on a site where we have two types of customers, agents and sites. A customer logs on as an agent then chooses a site that they can order for (these are in a custom customer attribute). The agent customer adds items to the site customer basket and can check out (the site user selection actually changes the customer session from being the agent customer to the site customer).

Now, if the agent customer has items in their basket and then changes the site customer we want to keep the basket contents intact but because they are in reality changing the logged on customer from one site customer to another the basket contents are lost. Anyone have any ideas on how I can keep the basket contents intact between site customers?

Foi útil?

Solução

Changing the customer_id of the quote:

Mage::getModel('checkout/quote')->load($quoteId)->setCustomerId($customerId)->save();

Outras dicas

No experience with this what so ever and this code is far from tested OR complete but you can probably use an event observer (not checkout_cart_product_add_after or you'll have yourself an infinite add loop) that is triggered when adding the product and then execute something like this

$customer_session = Mage::getSingleton('customer/session')->setCustomer([customerid]);
$cart_session = Mage::getSingleton('checkout/session')->loadCustomerQuote();

$cart = Mage::getSingleton('checkout/cart’'); 
$cart->init(); 

$product = Mage::getSingleton('catalog/product')->load($productId); 

$cart->addProduct($product, array('qty' => $qty)); 
$cart->save(); 

$cart_session->setCartWasUpdated(true);

@'Fabian Blechschmidt' for the answer for Sharing the shopping cart. I have tried your code, but need some modifications in it, it should use 'sales/quote' instead of 'checkout/quote', after that it is working fine for me. I have used below code:

Mage::getModel('sales/quote')->load($quoteId)->setCustomerId($customerId)->save();
Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange
scroll top