设想:

  • 成立Magento商店 (A店) 有 2 种商店视图语言:英语和法语。

  • 大量产品(10k+)

  • 新店 (B店) 已创建(相同的 Magento 安装),并带有与 A店

问题:

当分配所有现有产品时 A店B店, ,系统会提示您默认信息的来源。 这仅涵盖一种商店视图(英文)。

期望的结果: enter image description here

如何填充来自的所有描述 A店(法国)B店(法国)

有帮助吗?

解决方案

也许观察员可以完成这项工作?

例如:

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 在模块中选择 Observers 类和方法的事件 config.xml. 。例如:

<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 那里), ,但我希望它能帮助您创建自己的解决方案。:)

附:谨防观察者循环。

其他提示

我想你必须编写自己的同步模块,该模块安排一夜从商店储存法语来存储B法语的信息。

使用“更新_AT”字段进行产品以最大限度地减少您需要执行的工作量。

伪代码

  • 时间表cron作业跑到夜间 通过每个产品扫描
  • 自上次工作以来已经更新的每种产品,从商店a(法语)复制信息以存储b(法语)
  • 记录作业ran 的时间

    这是假设您不需要立即同步产品。

    提示是为了确保您的索引模型未设置为“保存”的更新

'质量属性更新'功能不允许由于逻辑限制而从一个商店视图应用值。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`;
.

脚本将“short_description”属性从“<source_store_id>”存储视图中的“描述”和“short_description”属性复制到“<target_store_id>”存储视图。

替换'<target_store_id>'和'<source_store_id>'常量,并单独运行每个商店视图的脚本。

使用'插入忽略...'语法而不是'insert ..在重复的键更新'如果您想要保留已存在的值。

如果您想复制一些其他属性值,则只需要相应地修改脚本。

许可以下: CC-BY-SA归因
scroll top