Magento-设置产品属性以使用默认值 [英] Magento - Set product attribute to use default values

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

问题描述

这个问题已经被问过很多次了,但是没有有效的答案.

This has been asked many times before but with no working answer.

我有多个商店,并且某些属性已被覆盖.我想通过脚本将这些属性更改为使用默认值".

I have multiple stores and some attributes have been overridden. I want to change these attributes to 'use default value' with a script.

这是显示商店视图和使用默认值"复选框的图像 http://dl.dropbox.com/u/3209649/storeviews-and -defaultvalues.png (尚未发布图片)

Here is an image showing store views and 'use default value' checkboxes http://dl.dropbox.com/u/3209649/storeviews-and-defaultvalues.png (not allowed to post images yet)

app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php 中,setData()与 false 一起用作使用默认值"时的第二个参数已为所有属性选择值".

In app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php setData() is used with false for the second argument when 'Use Default Value' has been selected for any attributes.

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

以下代码尝试使用相同的方法将商店3中产品1的名称"属性设置为使用默认值".

The following code attempts to set the 'name' attribute to 'use default values' for product 1 in store 3 using the same method.

require_once '../app/Mage.php';
Mage::app(3);

$product = Mage::getModel('catalog/product')->load(1);

$product->setData('name', false); # as used in ProductController.php
$product->save();

使用

$product->setData('name', 'anything');

正确地将'name'属性设置为'anything',但 false 并未将其设置为'use default value'

correctly sets the 'name' attribute to 'anything' but false does not set it to 'use default value'

使用默认值"未存储在数据库中的任何位置,因此在管理界面的控制器中,必须存在另一个删除属性行的过程吗?

'Use Default Value' is not stored anywhere in the database so within the controller for the admin interface there must be another procedure that deletes the attribute row?

此处的相关链接-> http://pastebin.com/raw.php?i=j7fwu9H6 (也不允许发布链接)

Related Links here -> http://pastebin.com/raw.php?i=j7fwu9H6 (not allowed to post links yet either)

推荐答案

这不起作用,因为您需要当前存储为 admin存储来进行这种操作.

This doesn't work because you need the current store being the admin store for this kind of operation.

要创建特定的商店视图,请使用给定属性的默认值:

To make a specific store view use the default value for a given attribute:

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$product = Mage::getModel('catalog/product')
    ->load($product_id)         // in your case: 1
    ->setStoreId($store_id)     // in your case: 3
    ->setData($attr, false)     // in your case: 'name'
    ->save();

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

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