MAGENTO-将最后创建的产品加载到购物车 [英] MAGENTO - Load last created Product to Cart
本文介绍了MAGENTO-将最后创建的产品加载到购物车的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在购物车中加载最近注册(创建)的产品? 怎么样?
is it possible to load the last registered (created) Product in my Cart? How?
我知道这听起来很疯狂,但是我的一个项目需要这个.
I know it sounds crazy but i need this for one of my project.
我认为这是产品装载的部分:
I think this is the part where the Product gets loaded:
cartcontroller.php
cartcontroller.php
/**
* Initialize product instance from request data
*
* @return Mage_Catalog_Model_Product || false
*/
protected function _initProduct()
{
$productId = (int) $this->getRequest()->getParam('product');
if ($productId) {
$product = Mage::getSingelton('checkout/session')->getQuote()->getAllItems()
->setStoreId(Mage::app()->getStore()->getId())
->load($productId);
if ($product->getId()) {
return $product;
}
}
return false;
}
这个(如果我是对的)我需要替换为商店中创建的最后一个产品-听起来很奇怪,但是我需要这个....
This (if I´m right) i need to be replaced with the last in shop created Product - sound weired but i need this....
推荐答案
您可以像这样在购物车中获取商品:
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
}
这篇关于MAGENTO-将最后创建的产品加载到购物车的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文