Magento - 如何将可配置产品图像链接到简单产品图像?

情况就是这样: 我有一个可配置的产品,有几个简单的产品。 这些简单的产品需要与可配置产品具有相同的产品图像。 目前,我必须一遍又一遍地将相同的图像上传到每个简单的产品。 有没有办法将可配置产品的产品图像链接到简单产品? 我的一些产品在一个可配置产品中有30个简单的产品,上传相同的图像30次是太过分/烦人。 我希望有人可以帮我解决这个问题! 提前致谢!     
已邀请:
$_product = $this->getProduct();
之后将其插入
DOCROOTappdesignfrontend<pachage><theme>templatecatalogproductviewmedia.phtml
$_parentIdArray = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($_product->getId());
if(sizeof($_parentIdArray)==1 && Mage::getModel('catalog/product')->load($_parentIdArray[0])->getTypeId() == 'configurable'){
  $_product = Mage::getModel('catalog/product')->load($_parentIdArray[0]);
}
如果简单产品具有可配置类型的单个父级,则将使用属于父可配置产品的图像。 编辑 要在列表视图中使用它,请打开
DOCROOTappdesignfrontend<pachage><theme>templatecatalogproductlist.phtml
并在2个位置插入相同的代码块:
<?php foreach ($_productCollection as $_product): ?>
之后的第45行(在
<?php ?>
包装内) 在
<?php $i=0; foreach ($_productCollection as $_product): ?>
之后的第106行(大约,你的主题可能会有所不同) 这两个位置都需要处理页面的网格视图和列表视图版本。 HTH, JD     
我认为正确的方法是覆盖图像助手(app / core / Mage / Catalog / Helper / Image.php),这样在init函数中,你可以检查你是否有一个简单的产品,如果你做,用可配置的产品替换它。这应该会影响所有模板的更改。     
快速解决方法可能是导出产品列表(管理员>系统>导入/导出>配置文件),将图像文件名放在所有简单产品的相应列中,将文件复制到
media/import/
目录然后导入修改后的产品列表。将为您制作各种关联,并将图像文件复制到他们需要的任何位置。     
我认为最好的方法是覆盖目录图像助手(如@stew所说)。为避免性能问题,我们可以使用原始SQL查询来获取父级的图像值:
class Wfs_Catalog_Helper_Image extends Mage_Catalog_Helper_Image
{
    public function init(Mage_Catalog_Model_Product $product, $attributeName, $imageFile=null)
    {
        parent::init($product, $attributeName, $imageFile);
        if (!$product->getId() || $imageFile || $product->isConfigurable()) {
            return $this;
        }

        $productImage = $product->getData($attributeName);
        if (!$productImage || $productImage == 'no_selection') {
            // Get parent product's attribute
            $value = $this->getParentProductAttribute($product->getId(), $attributeName);
            if ($value) {
                $this->_getModel()->setBaseFile($value);
            }
        }
        return $this;
    }

    public function getParentProductAttribute($productId, $attributeName)
    {
        $coreResource = Mage::getSingleton('core/resource');
        $conn = $coreResource->getConnection('core_read');

        $attrId = Mage::getSingleton('eav/config')
            ->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeName)
            ->getId();

        $select = $conn->select()
            ->from(array('rel'  => $coreResource->getTableName('catalog/product_relation')), array())
            ->join(
                array('var' => $coreResource->getTableName('catalog_product_entity_varchar')),
                'var.entity_id = rel.parent_id',
                array('value')
            )
            ->where('rel.child_id = ?', $productId)
            ->where('var.attribute_id = ?', $attrId);

        return $conn->fetchOne($select);
    }
}
    

要回复问题请先登录注册