MAGENTO - 获取最后一个购物车类别的儿童类别

时间:2013-09-03 13:52:37

标签: magento categories shopping-cart children

我已将此代码添加到.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.

1 个答案:

答案 0 :(得分:1)

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

   $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;
   }}}

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

相关问题