10

これは状況です:

いくつかの単純な製品で構成可能な製品があります。これらの単純な製品は、構成可能な製品と同じ製品イメージを持っている必要があります。現在、同じ画像を各シンプルな製品に何度もアップロードする必要があります。

構成可能な製品の製品イメージを単純な製品にリンクする方法はありますか?

私の製品の中には、1つの構成可能な製品に30の単純な製品があり、同じ画像を30回アップロードするのはやり過ぎ/煩わしいものです。

誰かがこの問題で私を助けてくれることを願っています!

前もって感謝します!

4

4 に答える 4

11

DOCROOT\app\design\frontend\<pachage>\<theme>\template\catalog\product\view\media.phtmlこれをあなたの後に挿入してください$_product = $this->getProduct();

$_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]);
}

単純な製品に構成可能なタイプの単一の親がある場合、親構成可能な製品に属するイメージが使用されます。

編集

これをリストビューで使用するにはDOCROOT\app\design\frontend\<pachage>\<theme>\template\catalog\product\list.phtml、同じコードブロックを開いて2つの場所に挿入します。

  • 45行目<?php foreach ($_productCollection as $_product): ?><?php ?>ラッパー内)
  • 106行目(約、テーマによって異なる場合があります)<?php $i=0; foreach ($_productCollection as $_product): ?>

ページのグリッドビューとリストビューのバージョンを処理するには、両方の場所が必要です。

HTH、
JD

于 2011-02-21T00:06:41.243 に答える
4

これを行う正しい方法は、画像ヘルパー(app / core / Mage / Catalog / Helper / Image.php)をオーバーライドすることです。これにより、init関数で、単純な製品があるかどうかを確認します。構成可能な製品に置き換えてください。これは、すべてのテンプレートの変更に影響するはずです。

于 2011-03-23T19:55:02.687 に答える
2

簡単な回避策として、製品リストをエクスポートし ( [管理] > [システム] > [インポート/エクスポート] > [プロファイル])、すべての単純な製品の適切な列にイメージ ファイル名を入力し、ファイルをmedia/import/ディレクトリにコピーしてからインポートします。変更された製品リスト。さまざまな関連付けが作成され、イメージ ファイルが必要な場所にコピーされます。

于 2011-02-20T23:36:31.623 に答える
2

最良の方法は、カタログ画像ヘルパーをオーバーライドすることだと思います(@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);
    }
}
于 2012-05-11T15:47:17.547 に答える