2014-02-11 41 views
0

我試圖在產品屬於某個類別時在產品頁面上顯示通知。丹麥語版本停止並僅加載半頁。瑞典版本似乎工作完美?!我的Magento安裝不會在日誌中顯示任何內容。需要在產品頁面上顯示通知,針對特定類別的產品

有沒有更好的方法來實現這一目標?

www.alldo.dk /時尚角度白/不工作!

www.alldo.se /時尚角度白/工作!

<!-- 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 --> 

在此先感謝!

回答

0

如果您在產品頁面上,您可以更容易地檢查。請參閱此代碼:

<?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文件。當然,如果你對每個商店視圖有不同的主題,你也可以使用它。

相關問題