如何防止Magento以编程方式更新产品时覆盖其他网站/商店中的属性值

Kov*_*NET 13 php magento magento-1.8

我已经实现了自定义Magento模块,该模块循环来自外部服务的数据,并在Magento多语言,多商店网站中更新价格,重量,名称和一些其他产品属性.

我的解决方案很简单(在我的模型中每天由Cron调用),如下所示:

/* THIS IS CODE SNIPPET INSIDE FOREACH LOOP */
$storeId = (string)$jobConfig->store; //cron for each store
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$extistingProduct = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
$extistingProduct->setPrice($newPrice); //update price
//some code here dealing with Associated products of Configurable product probably not relevant
//...
$extistingProduct->setCanSaveConfigurableAttributes(true);
$extistingProduct->setCanSaveCustomOptions(true);

$extistingProduct->setConfigurableAttributesData($configurableAttributesData);
// This tells Magento to associate the given simple products to this configurable product..
$extistingProduct->setConfigurableProductsData($configurableProductsData);

$extistingProduct->setStoreId($storeId);

$extistingProduct->save();
Run Code Online (Sandbox Code Playgroud)

我在每天运行cron,每个商店分别运行.它通常可以正常工作,只改变每个商店的每个产品的价格,但有时会发生奇怪的事情(比如每2个月一次) - 除了价格之外的所有其他属性都会从商店X覆盖到当前商店$storeId.这意味着我所有受影响的产品的所有英文产品描述都成为德语(例如).

我不知道怎么会发生这种情况,因为每次我调试它都正常工作,只改变我明确设置的当前范围的价格,但保留所有其他产品属性.它似乎从Store X加载所有产品数据,设置价格,然后将所有这些值存储到我在通过调用保存产品之前设置的存储$extistingProduct->setStoreId($storeId).

在发生这种情况的情况下,所有属性都会被同一个商店覆盖(例如,所有英文文本都会变成德语,但在其他情况下,所有文本都将成为西班牙语 - 它们都来自一个随机商店).

有没有人知道这怎么可能发生?我究竟做错了什么?

小智 -1

我遇到了类似的问题,但我找不到使用 Magento 的本机功能来解决它​​的方法。我最终使用Magmi (更具体地说是Magmi 的API )来正确创建/更新我的产品。

PS我知道这不是“Magento 的方式”,但这是我花了很多时间研究后发现的唯一方法。所以我将其作为替代解决方案发布。