Magento也想编辑"catalog category link"小部件以显示特定类别的图像



magento想要编辑"目录类别链接"小部件以显示特定类别的图像。我尝试编辑"类别/小部件/链接/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>
您需要

覆盖Mage_Catalog_Block_Widget_Link块。按照以下步骤在小部件中获取类别图像:

  1. 复制此文件:appcodecoreMageCatalogBlockWidgetLink.php
  2. 过去此文件:appcodelocalMageCatalogBlockWidgetLink.php
  3. 将以下代码添加到appcodelocalMageCatalogBlockWidgetLink.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>
    

希望它能有所帮助!

最新更新