Aggiungi gli attributi personalizzati all'attributo personalizzato impostato a livello programmatico
-
12-12-2019 - |
Domanda
ciao potrebbe qualcuno aiutarmi con questo?
Ho creato un set di attributi personalizzato e attributo personalizzato come
$installer = $this;
/* @var $installer Mage_Eav_Model_Entity_Setup */
$installer->startSetup();
//Create Attribute set with Based on Default attribute set
//$installer->removeAttributeSet(Mage_Catalog_Model_Product::ENTITY, 'New Attr Set');
/*
$skeletonID=$installer->getAttributeSetId('catalog_product','Default');
$entityTypeId = Mage::getModel('catalog/product')
->getResource()
->getEntityType()
->getId(); //product entity type
$attributeSet = Mage::getModel('eav/entity_attribute_set')
->setEntityTypeId($entityTypeId)
->setAttributeSetName("New Attr Set");
$attributeSet->validate();
$attributeSet->save();
$attributeSet->initFromSkeleton($skeletonID)->save();
//Create attribute new_attr
//$installer->removeAttribute('catalog_product', 'new_attr');
$data= array (
'attribute_set' => 'New Attr Set',
'group' => 'General',
'label' => 'New Attr',
'visible' => true,
'type' => 'int', // multiselect uses comma-sep storage
'input' => 'boolean',
'system' => false,
'required' => false,
'user_defined' => 1,//defaults to false; if true, define a group
'source' => 'eav/entity_attribute_source_boolean',
'default' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
);
$installer->addAttribute('catalog_product','new_attr',$data);
*/
.
Questo codice aggiunge il "New_ATTR" Attivimenti al gruppo "Generale" e quindi l'attributo personalizzato viene visualizzato in tutti i set di attributi come "predefinito".
Voglio aggiungere l'Atteggiamento personalizzato 'New_ATTR' solo al set di attributi personalizzato 'Nuovo attr insieme' sotto il gruppo 'Generale'.È possibile?
Soluzione
Sì, questo è possibile.
Innanzitutto, impostare questi tasti nell'array $ Data $ ai seguenti valori per evitare di aggiungere attributo a tutti i set di attributi:
'user_defined' => true,
'group' => ''
.
Quindi aggiungi attributo al set di attributi:
$attributeSetId = $this->getAttributeSetId($entityTypeId, 'New Attr Set');
$this->addAttributeToSet($entityTypeId, $attributeSetId, 'General', 'new_attr', 10);
. Altri suggerimenti
My Function per Aggiungi attributo (tramite codice) al set di attributo
public function addToAttributeSet($code, $attributeSetName = 'Default', $groupName = 'Details')
{
try {
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$attributeSetId = $setup->getAttributeSetId('catalog_product', $attributeSetName);
$attributeGroupId = $setup->getAttributeGroupId('catalog_product', $attributeSetId, $groupName);
$attributeId = $setup->getAttributeId('catalog_product', $code);
$setup->addAttributeToSet($entityTypeId = 'catalog_product', $attributeSetId, $attributeGroupId, $attributeId);
$this->_success[] = 'Added Attribute to SET ' . $attributeSetName . ' (' . $code . ')';
return true;
} catch (Exception $e) {
$this->_errors[] = 'ERROR when added Attribute to SET ' . $attributeSetName . ' (' . $code . ')';
$this->_errors[] = $e->getMessage();
return false;
}
}
.