2012-08-14 45 views
0

我试图在父类别的页面上显示子类别网格。 我已经按照this教程和一切工作正常,除了即使我已经分配图像到每个子类别,页面仍然显示占位符图像,而不是实际的。无法检索magento子类别图像

我认为在phtml代码的某处存在问题。

// Retrieve the current category and it's children 
<?php 
$_maincategorylisting=$this->getCurrentCategory(); 
$_categories=$this->getCurrentChildCategories(); 
if($_categories->count()): 
    foreach ($_categories as $_category): 
     if($_category->getIsActive()): 
      $cur_category=Mage::getModel('catalog/category')->load($_category->getId()); 
      $layer = Mage::getSingleton('catalog/layer'); 
      $layer->setCurrentCategory($cur_category); 
      $catName = $this->getCurrentCategory()->getName(); 
      $_imageUrl=$cur_category->getImageUrl(); 
      if (!$_imageUrl) : //if the image url is false set it to the placeholder 
       $_imageUrl = $this->getSkinUrl('images/catalog/product/placeholder/thumbnail.jpg'); 
      endif; 
      /* output */ ?> 
       <div class="category-box"> 
        <a href="<?php echo $this->getCategoryUrl($_category)?>"> 
         <img src="<?php echo $_imageUrl?>" height="80"> 
        </a> 
        <p><a href="<?php echo $this->getCategoryUrl($_category)?>"> <?php echo $_category->getName()?></a></p> 
       </div> 
     <?php endif; 
    endforeach; 
    $layer->setCurrentCategory($_maincategorylisting); 
endif; ?> 

注:

我跑Magento的v 1.6.0.0

This是我测试的分类页面。

回答

1

我注意到,在foreach循环中使用$ this-> getCurrentCategory(),它总是返回“Filtrare”类别。

基本上在foreach循环中,你需要更换到处 $这个 - > getCurrentCategory()与$ cur_category

+0

我跟着你的建议,但没有与子类别的图像 – Bogdan 2012-08-15 10:37:23

+0

改变@Bogdan我和我的队友尝试来自教程的代码,你已经提到并为我们工作。我们注意到一些不良的PHP风格,如使用<?一些PHP代码?>而不是<?php ome php code?>。你能告诉我们,你在Magento安装中有多少商店视图? – ceckoslab 2012-08-15 11:54:58

+0

另外这里的代码是格式良好的一些版本的PHP不会抛出错误,因为这个脚本样式“”https://gist.github.com/3359512 – ceckoslab 2012-08-15 12:00:54