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>
答案 0 :(得分:1)
您需要覆盖Mage_Catalog_Block_Widget_Link
阻止。按照以下步骤在Widget中获取类别图像:
app\code\core\Mage\Catalog\Block\Widget\Link.php
app\code\local\Mage\Catalog\Block\Widget\Link.php
将以下代码添加到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;
}
更新了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>
希望它会有所帮助!