Create attribute set in Magento script setting

Creating attributes and assigning them to existing attribute sets is a problem, but we are facing a problem trying to create an attribute set and populate it by default, and certain attributes do not work. This is the code used:

$setup->addAttributeSet('catalog_product', 'women_sizing_denim');

$oAttributeSetModel = Mage::getModel("eav/entity_attribute_set")
        ->load($setup->getAttributeSetId('catalog_product', 'women_sizing_denim'))
        ->initFromSkeleton($setup->getAttributeSetId('catalog_product', 'default'))
        ->save();

I can verify by debugging that the method initfromSkeletonloads the attributes from the default_set attribute as advertised, however after the save()new set is empty.

Adding new attributes to the set is possible, therefore it exists and is created correctly, but the missing attributes by default make it unusable, since SKU, price, name, etc. are required.

+5
source share
3 answers

, , , initSkeleton() .

, . , :

// Mage_Eav_Model_Entity_Setup
$oEntitySetup = $this;
$oEntitySetup->startSetup();

$sNewSetName = 'myset';
$iCatalogProductEntityTypeId = (int) $oEntitySetup->getEntityTypeId('catalog_product');

$oAttributeset = Mage::getModel('eav/entity_attribute_set')
    ->setEntityTypeId($iCatalogProductEntityTypeId)
    ->setAttributeSetName($sNewSetName);

if ($oAttributeset->validate()) {
    $oAttributeset
        ->save()
        ->initFromSkeleton($iCatalogProductEntityTypeId)
        ->save();
}
else {
    die('Attributeset with name ' . $sNewSetName . ' already exists.');
}

$oEntitySetup->endSetup();
+5

,

Mage_Catalog_Model_Resource_Eav_Mysql4_Setup

$oEntitySetup->getEntityTypeId('catalog_product');

.

0

, .

, , - ..

, , $installer- > getAttributeSetId ('catalog_product', 'default') initFromSkeleton()

if($attributeSet->validate()) {
$attributeSet
    ->save()
    ->initFromSkeleton($installer->getAttributeSetId('catalog_product', 'default'))
    ->save();
} else {
die('Attributeset with name ' . $setName . ' already exists.');
}
0

All Articles