2つの異なるストアと2つの言語の間で説明をどのように割り当てますか?

magento.stackexchange https://magento.stackexchange.com//questions/49016

  •  12-12-2019
  •  | 
  •  

質問

シナリオ:

  • マジェント店を設立 (店舗A) 英語とフランス語の2つのストアビュー言語で。

  • 多数の製品(10k+)

  • 新店舗 (店舗B) (同じMagentoのインストール)が作成され、すべての同じ製品を運ぶされています 店舗A

問題:

から既存のすべての製品を割り当てる場合 店舗A店舗B, 、デフォルトの情報がどこから来るのかを入力するように求められます。 これは1つのストアビューのみをカバーします(英語)。

望ましい結果: enter image description here

どのようにしてすべての説明を入力しますか 店舗A(フランス語)店舗B(フレンチ)

役に立ちましたか?

解決

たぶんオブザーバーが仕事をするでしょうか?

E.g:

class My_Awesome_Model_Observer 
{
    public function syncDescriptions($observer)
    {
        $productId = $observer->getProduct()->getId();

        $storeAEnId = 1; //store view Id for English store A 
        $storeBEnId = 2; //as above for store B
        $storeAFrId = 2; //store A French view's id
        $storeBFrId = 4; //French store B
        //of course replace above with real store Ids

        $descAEn = Mage::getModel('catalog/product')->setStore($storeAEnId)->load($productId)->getData('description');

// Now we check if description in store B is up-to-date with store A's, if not, if yes, we leave, if not, it is updated
        if ($descAEn != Mage::getModel('catalog/product')->setStore($storeBEnId)->load($productId)->getData('description'))
            {
                Mage::getModel('catalog/product')->setStore($storeBEnId)
                    ->load($productId)
                    ->getData('description', $descAEn)
                    ->save();
            }

        $shortDescAEn = Mage::getModel('catalog/product')->setStore($storeAEnId)->load($productId)->getData('short_description');

// Same check for short description
        if ($shortDescAEn != Mage::getModel('catalog/product')->setStore($storeBEnId)->load($productId)->getData('short_description'))
            {
                Mage::getModel('catalog/product')->setStore($storeBEnId)
                    ->load($productId)
                    ->getData('short_description', $shortDescAEn)
                    ->save();
            }

        $descAFr = Mage::getModel('catalog/product')->setStore($storeAFrId)->load($productId)->getData('description');


// same for French view
        if ($descAFr != Mage::getModel('catalog/product')->setStore($storeBFrId)->load($productId)->getData('description'))
            {
                Mage::getModel('catalog/product')->setStore($storeBFrId)
                    ->load($productId)
                    ->getData('description', $descAFr)
                    ->save();
            }

        $shortDescAFr = Mage::getModel('catalog/product')->setStore($storeAFrId)->load($productId)->getData('short_description');


// same for French short description
        if ($shortDescAFr != Mage::getModel('catalog/product')->setStore($storeBFrId)->load($productId)->getData('short_description'))
            {
                Mage::getModel('catalog/product')->setStore($storeBFrId)
                    ->load($productId)
                    ->getData('short_description', $shortDescAFr)
                    ->save();
            }
    }
}

もちろん、オブザーバーを宣言する必要があります catalog_product_save_after モジュール内のオブザーバクラスとメソッドを選択するイベント config.xml.E.g:

<global>
    <events>
        <catalog_product_save_after>
            <observers>
                <awesome_observer>
                    <type>singleton</type>
                    <class>My_Awesome_Model_Observer</class>
                    <method>syncDescriptions</method>
                </awesome_observer>
            </observers>
        </catalog_product_save_after>
    </events>
</global>

それは問題を解決するための非常に基本的な考え方です, 、私はあなたが使用する説明がわからないので(あなたも入れたいかもしれません short_description あり), しかし、私はそれがあなた自身の解決策を作成するのに役立つことを願っています。:)

追伸:オブザーバーのループに注意してください。

他のヒント

私はあなた自身の同期モジュールを書く必要があると思います。

製品の「updated_at」フィールドを使用して、必要な作業量を最小限に抑えます。

疑似コード

  • 毎晩実行するようにクルンジョブをスケジュールする
  • 各製品をスキャンする
  • 最後にジョブが走行してから更新された各製品の場合は、Store A(フランス語)からB(フランス語)を保存しています。
  • ジョブがran の時間を記録します。

    これはあなたが製品の即時同期を必要としないと仮定しています。

    ヒントは、インデックスモデルが「保存時に更新」に設定されていないことを確認することです。

'mass属性更新'機能は、論理制限のために、あるストアビューから別のストアビューへの値を適用することを可能にしません。Magentoは、新しく割り当てられたストアビューにデフォルト値のみを適用します。

純粋なSQL回避策を使用してみてください。

INSERT INTO `catalog_product_entity_text` (`entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `value`) 
SELECT `entity_type_id`, `attribute_id`, '<target_store_id>' as `store_id`, `entity_id`, `value` 
FROM `catalog_product_entity_text` as `source`
WHERE `attribute_id` IN (
    SELECT  `attribute_id` 
    FROM  `eav_attribute` 
    WHERE  `entity_type_id` = 10 /* catalog_product */
    AND  `attribute_code` IN ( 'description', 'short_description' )
)  
AND store_id = '<source_store_id>'
ON DUPLICATE KEY UPDATE `value` = `source`.`value`;
.

スクリプトは '<source_store_id>'ストアビューから '<target_store_id>' Store Viewに 'description'と 'short_description'属性の値をコピーします。

<target_store_id> 'と' <source_store_id> '定数を置き換え、各ストアビューごとにこのスクリプトを別々に実行します。

既に存在する値を保持したい場合は、 'insert key update'の代わりに 'Insert Internore ...'構文を使用します。

他の属性値をコピーしたい場合は、それに応じてスクリプトを変更する必要があります。

ライセンス: CC-BY-SA帰属
所属していません magento.stackexchange
scroll top