Configure Magento Use Default Value Product Attribute with updateAttributes

I have a setting with several repositories, and I set the product attribute for a particular store to use the "Use default value" parameter - (that is, use the value in the repository view) as follows:

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

This sets the Name attribute for storeId for $ productId to use "Use default value"

Given that I have a lot of attributes that I'm trying to use:

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

But this does not mean that the "Use default value" checkbox is true.

How can I use -> updateAttributes to set the repository value to use the "Use default value" parameter?

Screenshot:

enter image description here

+6
source share
2 answers

The "Use default value" flag is not saved anywhere in the database.

The Magento kernel uses this 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); } } 

Before doing something else.

I would look at Mage_Adminhtml_Catalog_ProductController (app / code / core / Mage / Adminhtml / controllerlers / Catalog / ProductController.php) and find out how the Magento core does it.

In particular, saveAction() and _initProductSave()

Hope this indicates that you are in the right direction.

+4
source

Just use 0 as the store identifier (admin store), which is the same as the default values ​​in Magento Admin.

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

If you have already set up the repository viewing areas, you will need to go in and re-check the default values, or redefine the attribute in the corresponding area.

There may be a way to install them programmatically. I'm not sure.

0
source

Source: https://habr.com/ru/post/908560/


All Articles