The default attribute value for the entire product in magento

I want to set a default attribute value for the entire product.

+3
source share
4 answers

I had the same problem before when I added product 11096 (downloadable products) to my store, then the client told me to add new attributes to the product, so I create 1 attribute (Type is Yes / No) and set a set of attributes. Now my problem is how can I edit the whole product and set this attribute to yes or not.if I do not set, then the value is null, so I wrote a few lines of code.

Please check this code, maybe it will help you.

$ProductId = Mage::getResourceModel('catalog/product_collection')
    ->addAttributeToFilter('type_id', Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE)
    ->getAllIds();
//Now create an array of attribute_code => values

$attributeData = array("my_attribute_code" =>"my_attribute_value");

//Set the store to affect. I used admin to change all default values

$storeId = 0; 

//Now Update the attribute for the given products.

Mage::getSingleton('catalog/product_action')
    ->updateAttributes($ProductId, $attributeData, $storeId);
+5
source

: - http://www.magentocommerce.com/knowledge-base/entry/tutorial-creating-attributes-custom-fields

:. , .

, , , . , , .

, : -

$attributeCode = 'YOUR_ATTRIBUTE_CODE';
$attribute = Mage::getResourceModel('eav/entity_attribute_collection')
            ->setCodeFilter($attributeCode)
            ->getFirstItem();
echo $attribute->getDefaultValue();
+2

Admin Panel - Directory - Attributes - Attribute Management

Select Attribute - Properties - Attribute Properties - Default

enter image description here

0
source

enter image description here

You can also solve the problem by following the mass schedule for all products. Go to the "Product Management" folder and select "All" and then "Update Attributes".

0
source

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


All Articles