问题: 如何根据特定产品属性自定义Magento为产品使用不同的占位符图像?
更多信息:
例如:
注释
提前谢谢
答案 0 :(得分:0)
你可以得到产品' parent category_id
使用以下代码
$_product = Mage::getModel('catalog/product')->load($_item->getId());
$ids = $_product->getCategoryIds();
$categoryId = (isset($ids[0]) ? $ids[0] : null);
您可以使用自定义if/else
条件来显示占位符图片...
应该有一个问题。 如果某个产品的父类别多于您想要的那个?
<强>更新强>
$attribute = $_product->getResource()->getAttribute('custom_attribute_code');
if ($attribute)
{
echo $attribute_value = $attribute ->getFrontend()->getValue($_product);
}
您现在可以对属性使用相同的类别逻辑...
答案 1 :(得分:0)
基于@Rob的信息,我创建了一个工作原型。以下是感兴趣的补丁:
第一个文件
diff --git a/magento/app/code/local/Mage/Catalog/Helper/Image.php b/magento/app/code/local/Mage/Catalog/Helper/Image.php
--- a/magento/app/code/local/Mage/Catalog/Helper/Image.php
+++ b/magento/app/code/local/Mage/Catalog/Helper/Image.php
@@ -349,7 +349,14 @@ class Mage_Catalog_Helper_Image extends Mage_Core_Helper_Abstract
if ($this->getImageFile()) {
$model->setBaseFile($this->getImageFile());
} else {
- $model->setBaseFile($this->getProduct()->getData($model->getDestinationSubdir()));
+ // if part type is in the passed product then use it otherwise get it
+ if ($this->getProduct()->getPartType()) {
+ $productPartType = $this->getProduct()->getPartType();
+ } else {
+ $productPartType = Mage::getModel('catalog/product')->load($this->getProduct()->getId())->getPartType();
+ }
+
+ $model->setBaseFile($this->getProduct()->getData($model->getDestinationSubdir()), $productPartType);
}
if ($model->isCached()) {
第二档
diff --git a/magento/app/code/local/Mage/Catalog/Model/Product/Image.php b/magento/app/code/local/Mage/Catalog/Model/Product/Image.php
--- a/magento/app/code/local/Mage/Catalog/Model/Product/Image.php
+++ b/magento/app/code/local/Mage/Catalog/Model/Product/Image.php
@@ -260,7 +260,7 @@ class Mage_Catalog_Model_Product_Image extends Mage_Core_Model_Abstract
* @param string $file
* @return Mage_Catalog_Model_Product_Image
*/
- public function setBaseFile($file)
+ public function setBaseFile($file, $partType=Null)
{
$this->_isBaseFilePlaceholder = false;
@@ -278,10 +278,23 @@ class Mage_Catalog_Model_Product_Image extends Mage_Core_Model_Abstract
}
}
if (!$file) {
+ // check if part type placeholder file exists
+ if ($partType) {
+ $skinPartTypeBaseDir = Mage::getDesign()->getSkinBaseDir();
+ $skinPartTypePlaceholder = "/images/catalog/product/placeholder/{$partType}.jpg";
+ $PartTypefile = $skinPartTypePlaceholder;
+ }
+
// check if placeholder defined in config
$isConfigPlaceholder = Mage::getStoreConfig("catalog/placeholder/{$this->getDestinationSubdir()}_placeholder");
$configPlaceholder = '/placeholder/' . $isConfigPlaceholder;
- if ($isConfigPlaceholder && $this->_fileExists($baseDir . $configPlaceholder)) {
+
+ // Use part type placeholder image if it exists
+ if ($partType && file_exists($skinPartTypeBaseDir . $PartTypefile)) {
+ $baseDir = $skinPartTypeBaseDir;
+ $file = $PartTypefile;
+ }
+ elseif ($isConfigPlaceholder && $this->_fileExists($baseDir . $configPlaceholder)) {
$file = $configPlaceholder;
}
else {