0

Is it possible to add a php file in root directory of magento?

$attribute_set_name = 'your attribute set name here';
$group_name = 'your attribute group here';
$attribute_code = 'your attribute code here';

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

//-------------- add attribute to set and group
$attribute_set_id = $setup->getAttributeSetId('catalog_product', $attribute_set_name);
$attribute_group_id = $setup->getAttributeGroupId('catalog_product', $attribute_set_id, $group_name);
$attribute_id = $setup->getAttributeId('catalog_product', $attribute_code);

$setup->addAttributeToSet($entityTypeId='catalog_product',$attribute_set_id, $attribute_group_id, $attribute_id);

I ran this code, but there is an error:

Fatal error: Call to a member function getResourceConfig() on a non-object in C:\xampp\htdocs\magento\app\code\core\Mage\Core\Model\Resource\Setup.php on line 131

2

1 Answer 1

1

I would always suggest doing this sort of thing via a module's set-up scripts. For full details on set-up script see, but for what you need something like the following should work.

<?php
/* @var $this Mage_Customer_Model_Entity_Setup */
$this->startSetup();

$attribute_set_name = 'your attribute set name here';
$group_name = 'your attribute group here';
$attribute_code = 'your attribute code here';

//-------------- add attribute to set and group
$attribute_set_id=$this->getAttributeSetId('catalog_product', $attribute_set_name);
$attribute_group_id=$this->getAttributeGroupId('catalog_product', $attribute_set_id, $group_name);
$attribute_id=$this->getAttributeId('catalog_product', $attribute_code);

$this->addAttributeToSet($entityTypeId='catalog_product',$attribute_set_id, $attribute_group_id, $attribute_id);

$this->endSetup();
1
  • 1
    How to do it for bulk update
    – zus
    Commented Nov 17, 2017 at 6:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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