MAGENTO-获取购物车项目的最后一个子类别

MAGENTO-获取购物车项目的最后一个子类别,magento,categories,shopping-cart,children,Magento,Categories,Shopping Cart,Children,我已在.phtml文件中添加了此代码,在该文件中,我有已创建的其他签出步骤的信息,并且我希望根据为每个项目选择的最后一个子类别,设置类别过滤器触发的某些逻辑: $items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems(); foreach($items as $item) { $productId = $item->getProduct()->getCategoryIds();

我已在.phtml文件中添加了此代码,在该文件中,我有已创建的其他签出步骤的信息,并且我希望根据为每个项目选择的最后一个子类别,设置类别过滤器触发的某些逻辑:

$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();  
foreach($items as $item) {  
$productId = $item->getProduct()->getCategoryIds(); 
$_category = Mage::getSingleton('catalog/category')->load($value);
$cartProductCatId = $_category->getChildrenCategory();

echo 'Category ID: '.$cartProductCatId.; 
但是,不可能

我拥有的类别的层次结构树是:

1) Parent_categ_ID=1 
1.1) Child_categ_ID=3 
1.2) Child_categ_ID=4 

2) Parent_categ_ID=2 
2.1) Child_categ_ID=5 
2.2) Child_categ_ID=6 

我想筛选的类别是:ID=3和ID=5。

我最终以这种方式解决了它:

   $items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();  
   $filter_cats = array(3,5);
   $found_cat = false;
   foreach($items as $item){  
   $categories_array = $item->getProduct()->getCategoryIds(); 
   foreach($categories_array as $cat){
   if( in_array($cat, $filter_cats) ){
   $found_cat = true;
   break;
   }}}

我希望这对某人有帮助。谢谢

我最终以这种方式解决了这个问题:

   $items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();  
   $filter_cats = array(3,5);
   $found_cat = false;
   foreach($items as $item){  
   $categories_array = $item->getProduct()->getCategoryIds(); 
   foreach($categories_array as $cat){
   if( in_array($cat, $filter_cats) ){
   $found_cat = true;
   break;
   }}}

我希望这对某人有帮助。谢谢

西蒙,我已经相应地更新了我的答案。你现在明白了吗?谢谢这就是我需要的逻辑托马斯:如果购物车中的任何物品属于类别3或5,那么就这样做。第五和第三类是最深层次的。西蒙,我相应地更新了我的答案。你现在明白了吗?谢谢这就是我需要的逻辑托马斯:如果购物车中的任何物品属于类别3或5,那么就这样做。第5类和第3类为最深层次。