0

So I am dealing with a group of products that have around 30+ different attributes. When I import the CSV file of the products magento doesn't create the attributes automatically. From there, it seems I would have to manually create each attribute one at a time? Is there a way to mass create say around 30 different attributes all at once?

Thanks!

0

Create a new file in the root of your Magento install. Paste the following code:

require_once('app/Mage.php');

umask(0);
Mage::app('default');
Mage::app ()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$productCollection = Mage::getModel('catalog/product')->getCollection();

foreach($productCollection as $_product) 
{
    echo "\n".'updating '.$_product->getSku()."...\n";
    $product = Mage::getModel('catalog/product')->load($_product->getEntityId());
    $product->setData('your_attribute_to_update_here', 1)->getResource()->saveAttribute($product, 'your_attribute_to_update_here');
}

Goto yourstore.com/script-aboves-name.php

Keep in mind, the 1 in ('your_attribute_to_update_here', 1) can also be a string: "string"

  • I copied and pasted your code in a new file and placed it in the root folder. When I go to mystore.com/your-php-code.php it will stay on a screen with updating 123... – John R. May 26 '15 at 21:06
  • Did you update your attribute and value in the code first? – Tim Hallman May 26 '15 at 21:07
  • Here is what I had added to your code: <?php require_once('app/Mage.php'); umask(0); Mage::app('default'); Mage::app ()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); $productCollection = Mage::getModel('catalog/product')->getCollection(); foreach($productCollection as $_product) { echo "\n".'updating '.$_product->getSku()."...\n"; $product = Mage::getModel('catalog/product')->load($_product->getEntityId()); $product->setData('MassAttributeTest', 1)->getResource()->saveAttribute($product, 'MassAttributeTest'); } ?> – John R. May 26 '15 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.