需要在产品页面上显示特定类别产品的通知

时间:2014-02-11 08:51:00

标签: php magento

当产品属于某个类别时,我正试图在产品页面上显示通知。丹麦语版本停止并仅加载半页。瑞典版似乎完美无缺?!我的Magento安装在日志中也没有显示任何内容。

有没有更好的方法来实现这一目标?

www.alldo.dk / stylish-angle-white /不起作用!

www.alldo.se / stylish-angle-white /工作!

<!-- SHOW NOTICE -->    
<?php

### GET THE FIRST CATEGORY ID FOR THIS PRODUCT ###

$categoryIds = $_product->getCategoryIds();

if(count($categoryIds) ){
    $firstCategoryId = $categoryIds[0];
    $_category = Mage::getModel('catalog/category')->load($firstCategoryId);
}

### ONLY RUN ON PRODUCT PAGES ###
if($this->getRequest()->getModuleName() == 'catalog' && $this->getRequest()->getControllerName() == 'product'){

    ### SHOW CORRECT NOTICE FOR EACH STORE ###
    if ( Mage::app() -> getStore() -> getCode() == 'domain_com' && $_category -> getId() == 5 ){ 
            echo 'An important notice ...';
    }

    if ( Mage::app() -> getStore() -> getCode() == 'domain_org' && $_category -> getId() == 5 ){ 
            echo 'An important notice ...';
    }

}
?>
<!-- SHOW NOTICE -->

提前致谢!

1 个答案:

答案 0 :(得分:1)

如果您在“产品”页面上,则可以更轻松地查看。看到这段代码:

    <?php

$isProductPage = Mage::registry("current_product");
if ($isProductPage) {
    $categoryIds = Mage::registry("current_product")->getCategoryIds();
    $_categoryId = 5;
    $showNotice = false;
    if (count($categoryIds)) {
        $showNotice = in_array($_categoryId, $categoryIds);
    }

    $isProductPage = Mage::registry("current_product");
    if ($isProductPage && $showNotice) {
        echo $this->__('An important notice ...'); //With this you utilize the standard magento translator, so you don't need two separate row.
    }
}
?>

然后,您可以为每个商店视图添加带有自定义消息的translate.csv文件。当然,如果每个商店视图都有不同的主题,您也可以使用它。

相关问题