1

magento 也想编辑“目录类别链接”小部件以显示特定类别的图像。我尝试编辑'category/widget/link/link_block.phtml'

<?php
$_category  = $this->getCurrentCategory();
?>
<span class="widget widget-category-link">
  <a <?php echo $this->getLinkAttributes() ?>>
    <span><?php echo $this->htmlEscape($this->getAnchorText()) ?></span>
    <img src="<?php echo $_category->getImageUrl();?>" />
  </a>
  <br/>
</span>
4

1 回答 1

2

您需要覆盖Mage_Catalog_Block_Widget_Link块。按照以下步骤在 Widget 中获取类别图像:

  1. 复制此文件:app\code\core\Mage\Catalog\Block\Widget\Link.php
  2. 过去这个文件:app\code\local\Mage\Catalog\Block\Widget\Link.php
  3. 将以下代码添加到app\code\local\Mage\Catalog\Block\Widget\Link.php文件中

    public function getImage(){
    $imgPath = '';
    if ($this->_entityResource) {
    
        $idPath = explode('/', $this->_getData('id_path'));
        if (isset($idPath[1])) {
            $id = $idPath[1];
            if ($id) {
    
                $imgPath = Mage::getBaseUrl('media').'catalog/category/'.$this->_entityResource->getAttributeRawValue($id, 'image', Mage::app()->getStore());
    
            }
        }
    
    }
    
    return $imgPath;
    }
    
  4. 更新了以下代码category/widget/link/link_block.phtml

    <?php
    $_category  = $this->getCurrentCategory();
    ?>
    <span class="widget widget-category-link">
      <a <?php echo $this->getLinkAttributes() ?>>
    <span><?php echo $this->htmlEscape($this->getAnchorText()) ?></span>
    <img src="<?php echo $this->getImage();?>" />
     </a>
    <br/>
    </span>
    

希望它会有所帮助!

于 2013-10-23T12:58:20.590 回答