且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MAGENTO-将最后创建的产品加载到购物车

更新时间:2023-11-30 13:46:34

您可以像这样在购物车中获取商品:

You can get the items in the cart like this:

$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();

然后遍历所有项目,看看哪个ID最大.

Then loop through the items and see which one has the biggest id.

$max = 0;
$lastItem = null;
foreach ($items as $item){
    if ($item->getId() > $max) {
        $max = $item->getId();
        $lastItem = $item;
    }
}
if ($lastItem){
    //do something with $lastItem
}