在Magento中设置商店级别的属性

时间:2012-03-15 20:05:14

标签: magento

我试图让Magento将商店视图上的产品属性值设置为与默认值相同。

我有一个观察者在

上调用的以下代码
catalog_product_save_before

public function translateProduct($observer)
{
    Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
    $product = Mage::getModel('catalog/product')->load($observer->getEvent()->getProduct()->getId());

    foreach (Mage::app()->getWebsites() as $website) {
        foreach ($website->getGroups() as $group) {
            foreach ($group->getStores() as $store) {
                $config = $store->getConfig('myconfig');
                if($config['enabled']) {
                    foreach($product->getAttributes() as $attribute) {
                        if($attribute->getBackendType() == 'text' && $attribute->getFrontend()->getValue($product) != '') {
                            $product->setStoreId($store->getId())->setData($attribute->getAttributeCode(), $attribute->getFrontend()->getValue($product));
                        }
                    }
                }                
            }
        }
    }
    return $this;
}

我知道我的代码和循环正在调用

echo 'Here'; die(); 

通过循环来测试它。

这是在多个商店视图中为Magento产品设置数据的正确方法,还是我在某处出错?

提前感谢任何帮助/提示/指示: - )

3 个答案:

答案 0 :(得分:4)

哇那里有家伙。

您只需将数据设置为默认级别即可。如果没有为商店上下文设置属性值,则将从默认值推断出它。

: - )

答案 1 :(得分:3)

以编程方式“使用默认值”,将属性的数据设置为FALSE。

$product->setStoreId($store->getId())->setData($attribute->getAttributeCode(), FALSE);

答案 2 :(得分:0)

在上面的示例中,您在“storeview”-level上设置属性,而不是真正在“store”上设置......在magento中有点令人困惑......

相关问题