Magento设置产品属性的“使用默认值"使用updateAttributes [英] Magento setting Product Attribute's "Use Default Value" using updateAttributes

查看:76
本文介绍了Magento设置产品属性的“使用默认值"使用updateAttributes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多商店设置,我正在为特定商店设置产品属性,以使用使用默认值"选项-(即在商店视图中使用该值),如下所示:

I have a multi-store setup and I am setting a Product's Attribute for a particular store to use the "Use Default Value" option - (ie to use the value in the Store View), as follows:

$_product = Mage::getModel('catalog/product');
$_product->load($productId);
$_product->setStoreId($storeId)->setName(false)->save();

这会将$ productId的storeId的Name属性设置为使用使用默认值"

This sets the Name attribute of storeId for $productId to use "Use Default Value"

鉴于我要设置的属性很多,

Given that I have a lot of attributes to set I am trying to use:

Mage::getSingleton('catalog/product_action')->updateAttributes(array($productId), array('name' => false), $storeId);

但是,这并未将使用默认值"复选框设置为true.

But this is not setting the "Use Default Value" checkbox to true.

如何使用-> updateAttributes设置存储值以使用使用默认值"选项?

How can I use ->updateAttributes to set a store value to use the "Use Default Value" option?

屏幕截图:

推荐答案

使用默认值"标志未存储在数据库中的任何位置.

The "Use Default Value" flag isn't stored in the database anywhere.

Magento核心在保存产品时使用该标志来执行此操作:

Magento core uses that flag to do this when saving products:

   /**
     * Check "Use Default Value" checkboxes values
     */
    if ($useDefaults = $this->getRequest()->getPost('use_default')) {
        foreach ($useDefaults as $attributeCode) {
            $product->setData($attributeCode, false);
        }
    }

在做其他事情之前.

我将研究Mage_Adminhtml_Catalog_ProductController(app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php),并了解Magento核心是如何做到的.

I would look at Mage_Adminhtml_Catalog_ProductController (app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php) and learn how Magento core does it.

特别是saveAction()_initProductSave()

我希望这可以为您指明正确的方向.

I hope this points you in the right direction.

这篇关于Magento设置产品属性的“使用默认值"使用updateAttributes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆