以下是我的代码: -
try
{
$store = $this->_getStore();
Mage::app()->setCurrentStore($store->getId());
$customer_ID = 3;
$customer = Mage::getModel('customer/customer')->load($customer_ID);
// load quote by customer
$quote = Mage::getModel('sales/quote')->loadByCustomer($customer_ID);
$quote->assignCustomer($customer);
$product = Mage::getModel('catalog/product')
// set the current store ID
->setStoreId(Mage::app()->getStore()->getId())
// load the product object
->load(3);
// Add Product to Quote
$quote->addProduct($product,1);
// Calculate the new Cart total and Save Quote
$quote->collectTotals()->save();
return json_encode(array("", $quote->getId()));
}catch(Exception $e)
{
return $e->getMessage();;
}
使用此产品已成功添加到购物车并返回quote_id,但使用此ID我想获取当前登录用户的当前购物车商品详情。
答案 0 :(得分:2)
获取购物车商品详情:
$quote = Mage::helper('checkout/cart')->getCart()->getQuote();
$value = [];
foreach ($quote->getAllItems() as $item) {
$value[]= array (
'id' => $item->getSku(),
'quantity' => $item->getQty(),
'price' => $item->getParentItemId()? $item->getParentItem()->getPrice(): $item->getPrice()
);
}