Magento将最新产品添加到购物车 [英] Magento get last product added to cart

查看:50
本文介绍了Magento将最新产品添加到购物车的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果产品是可配置的,我需要将最后一个添加到购物车的产品与所有信息一起使用:图像,名称,sku和自定义选项.我尝试使用此代码,但无法正常工作.我的Magento版本是1.9.1

i need to get the last product added to cart, with all informations: image, name, sku and custom options if product is configurable. I try with this code but is not working. My Magento version is 1.9.1

                 $xitems = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
    $max = 0;
    $lastItem = null;
    foreach ($xitems as $xitem){
        if ($xitem->getId() > $max) {
            $max = $xitem->getId();
            $lastItem = $xitem;
        }
    }
    if ($lastItem){
        $_xproduct = $lastItem->getProduct();
        $xproductsku = $_xproduct->getSku();
       $xproductname = $_xproduct->getName();               
       $xproductqty = $_xproduct->getQty();  
       $xproductprice = $_xproduct->getPrice();   
       $xproducturl = $_xproduct->getUrl();
    }

                $xhtml .='<a href="'.$lastItem->getUrl().'" title="'.$lastItem->getName().'" class="product-image"><img src="'. Mage::helper('catalog/image')->init($lastItem->getProduct(), 'thumbnail').'" width="50" height="50" alt="" /></a>';
                $xhtml .='<a class="item-name" href="'.$lastItem->getUrl().'">'.$lastItem->getName().'</a> <span class="item-price"><span class="price">$'.$lastItem->getPrice().'</span></span>';

        $_response = Mage::getModel('ajaxminicart/response')                                         
                ->setMessage($xhtml);
        //append updated blocks
        $_response->addUpdatedBlocks($_response);
        $_response->send();
    }

谢谢.

推荐答案

        $items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
        $max = 0;
        $lastItem = null;
        foreach ($items as $item){
            if ($item->getId() > $max) {
                $max = $item->getId();
                $lastItem = $item;
            }
        }
        if ($lastItem){
            $_product = $lastItem->getProduct();
            $xproductsku = $_product->getSku();
           $xproductname = $_product->getName();               
           $xproductqty = $_product->getQty();  
           $xproductprice = $_product->getPrice();   
           $xproducturl = $_product->getUrl();
        }

这有效..对 Marius

参考- MAGENTO-将上次创建的产品加载到购物车

这篇关于Magento将最新产品添加到购物车的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆