MAGENTO:如果产品属于A类、B类或C类,那么就这样做I


MAGENTO: if product is in category A or in category B or in category C, then do this I

我正在使用magento 1.6。当当前显示的产品属于特定类别时,我正在尝试在产品页面视图上显示图片。如果产品属于 A 类、B 类或 C 类...然后回显图像。

我怎样才能做到这一点?

您问题的措辞使我认为,即使在查看不在列表中的类别中的产品时,您也需要显示此图像。使用 catalog/product 模型有几个选项可用。我认为最理想的是 getAvailableInCategories() ,所以:

$yourCatIds = array(1,2,3...);
$productCats = $_product->getAvailableInCategories();
if (count(array_intersect($yourCatIds,$productCats))) {
    //show the image
}

这样的事情应该这样做:

$currentCategory = Mage::registry('current_category');
$curID = $currentCategory->getId();
$showOn = array(4, 12, 88, 99); // array of category ids to show image on
foreach($showOn as $show){
    if($show == $curId){
        echo '<img src="yourimage" alt="" />';
    }
}

未经测试,但应该可以工作。