Magento:当产品图像不可用时显示类别图像

时间:2011-12-01 12:44:13

标签: magento

当产品没有图像(占位符)时,我想显示Catagory图像而不是一般的占位符,而不是显示枯燥的图像。我一直在@SO搜索,但没有查看任何解决方案。

以下是media.phtml中显示图片的片段。

    $_img = '<img src="'.$this->helper('catalog/image')->init($_product, 'small_image')->resize(265).'" alt="'.$this->htmlEscape($this->getImageLabel()).'" title="'.$this->htmlEscape($this->getImageLabel()).'" />';
    echo '<a class="' . $borderClass . '" title="' . $this->htmlEscape($this->getImageLabel()) . '" onclick="return hs.expand(this);" href="' . $this->helper('catalog/image')->init($_product, 'image') . '">' . $_helper->productAttribute($_product, $_img, 'image') . '</a>';

//--> $this->helper('catalog/image')->init($_product, 'small_image')->resize(265)

有人有想法/解决方案吗? Magento 1.5,顺便说一句: - )

1 个答案:

答案 0 :(得分:0)

对于magento配置中没有图像,您可以使用另一张“无聊图片”。这个“无聊的图片”被称为占位符。

另一个选择是:

1. Load first of product categories.
2. Get category image
3. Put category image instead of default "boring picture"

更新1

在类别页面上加载产品类别:

$currentCat = $_product->getCategory();
$_product->getCategoryCollection();
$_product->getCategoryIds();
    $category = Mage::getModel('catalog/category')->load($categoryId);

获取类别图像:

$_imgUrl = $_category->getImageUrl();

因此检查产品是否没有图像,如果没有用产品图像替换类别图像。

相关问题