1

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

4

1 回答 1

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

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

于 2013-09-29T19:12:30.490 回答