magento想要编辑“目录类别链接”小部件以显示特定类别的图像

时间:2013-10-23 11:03:31

标签: magento widget edit

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>

1 个答案:

答案 0 :(得分:1)

您需要覆盖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>
    
  5. 希望它会有所帮助!