Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

adding product attributes via php
 
alierdem
Jr. Member
 
Total Posts:  2
Joined:  2012-11-19
 

hello
im trying to use this plugin to import my products: http://erfanimani.github.com/Ezimport/
my xml file contains atributes for products, its something like this:
<products>
<product>
<name>prod name</name>
<options>
<option>
<name>size</name>
<value>6</value>
</option>
<option>
<name>color</name>
<value>red</value>
</option>
</options>

so how can i create these attributes with Mage_Catalog_Model_Product class?
i think i need to check if this attribute exists then add it to product.but im new to magento and i dont know how to do it

any suggestions?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Siggi_Schmitz
Enthusiast
 
Avatar
Total Posts:  811
Joined:  2011-07-03
 

For existing attributes:

$product Mage::getModel('catalog/product')->load(1); //example for loading the model from the product with the id 1
$product->setData('color','red')->save(); //saving 'red' as value in the attribute with the code 'color', then saving the model.
 
Magento Community Magento Community
Magento Community
Magento Community
 
alierdem
Jr. Member
 
Total Posts:  2
Joined:  2012-11-19
 
Siggi_Schmitz - 25 February 2013 12:32 PM

For existing attributes:

$product Mage::getModel('catalog/product')->load(1); //example for loading the model from the product with the id 1
$product->setData('color','red')->save(); //saving 'red' as value in the attribute with the code 'color', then saving the model.

thank you buddy, that should do the trick smile

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top