0

I have a trouble with adding new attribute. So, it's my config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <attributes_new>
            <version>0.1.0</version>
        </attributes_new>
    </modules>
    <resources>
        <attributes_new_setup>
            <setup>
                <module>attributes_new</module>
            </setup>
        </attributes_new_setup>
    </resources>
</config>

my folder location: enter image description here

And my code, where I add my attributes.

<?php
/**
 * Created by PhpStorm.
 * User: p.kushnerevich
 * Date: 19.12.17
 * Time: 14.30
 */
$installer = $this;

$productAttributesSetup = new Mage_Eav_Model_Entity_Setup('core_setup');

$installer->startSetup();

$setId=1;

$productAttributesSetup->addAttributeSet('catalog_product', 'NewAttributeSet');

$groups = Mage::getModel('eav/entity_attribute_group')
    ->getResourceCollection()
    ->addAttributeToFilter('attribute_group_name','Clothing')
    ->setSortOrder()
    ->load();

$attributeCodes = array();
$numberGroupOnPage=0;

foreach ($groups as $group) {
    $groupName          = $group->getAttributeGroupName();
    $groupId            = $group->getAttributeGroupId();
    $productAttributesSetup->addAttributeGroup('catalog_product', 'NewAttributeSet',$groupName,$numberGroupOnPage++);
    $attributes = Mage::getResourceModel('catalog/product_attribute_collection')
        ->setAttributeGroupFilter($group->getId())
        ->addVisibleFilter()
        ->checkConfigurableProducts()
        ->load();
    $numberAttributeOnPage=0;
    if ($attributes->getSize() > 0) {
        foreach ($attributes->getItems() as $attribute) {
            $attributeName=$attribute->getAttributeCode();;
            $productAttributesSetup->addAttributeToGroup('catalog_product','NewAttributeSet',$groupName,$attributeName,$numberAttributeOnPage++);
        }
    }

}
$installer->endSetup();

I think, that my error in config.xml.

1
  • Please add any errors that you encounter. Please add what you expect to happen and what instead is happening.
    – 7ochem
    Dec 19, 2017 at 15:10

2 Answers 2

2

The Module declaration should be in capitalise <Attributes_New> and not <attributes_new>

config.xml

<config>
    <modules>
        <Attributes_New>
            <version>1.0.0</version>
        </Attributes_New>
    </modules>
    <global>
        <helpers>
            <attributes_new>
                <class>Attributes_New_Helper</class>
            </attributes_new>
        </helpers>
        <resources>
            <attributes_new_setup>
                <setup>
                    <module>Attributes_New</module>
                    <class>Mage_Catalog_Model_Resource_Setup</class>
                </setup>
            </attributes_new_setup>
        </resources>
    </global>
</config>
2
0

If your code to add your new attribute is in the mysql4-upgrade-0.1.0-0.1.1.php file, so you have to change your config.xml's version like that :

<attributes_new>
    <version>0.1.1</version>
</attributes_new>

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.