0

需要获取最后的商品名称、图片、网址和价格。

$session= Mage::getSingleton('checkout/session');
foreach($session->getQuote()->getAllItems() as $item)
{
$productid = $item->getProductId();
$productname = $item->getName();
$productqty = $item->getQty();
}

这是有效的,但我无法获取图像和网址。

4

1 回答 1

2

集合通常不会加载整个对象,您需要重新加载对象以获取所需的其他数据:

$session= Mage::getSingleton('checkout/session');
// Get all items, including child / hidden items
foreach($session->getQuote()->getAllItems() as $item) {
    $_prod = Mage::getModel('catalog/product')->load($item->getProductId());
    $productname = $_prod->getName();
    $productqty = $_prod->getQty();
    // Now you have a full loaded Product Object.
}
// Visible items only
foreach($session->getQuote()->getAllVisibleItems() as $item) {
    $_prod = Mage::getModel('catalog/product')->load($item->getProductId());
    $productname = $_prod->getName();
    $productqty = $_prod->getQty();
    // Now you have a full loaded Product Object.
}
于 2013-02-26T13:58:38.493 回答