2010-08-19 17 views
5

está mal, es posible añadir un nuevo conjunto de atributos en Magento usando algo como lo siguiente:Añadir attributeSet pero en base a un conjunto existente - Magento

$entitySetup = new Mage_Eav_Model_Entity_Setup; 
$entitySetup->addAttributeSet('catalog_product', $setName); 

Pero cómo puedo basar el conjunto en un conjunto existente como el valor por defecto. Esta opción está disponible en la sección de administración para que sea posible.

Respuesta

3

Lo hice hace 6 meses, ya no tengo el código, pero sé que tiene que usar el método initFromSkeleton() en su conjunto de atributos. Puede buscar el código de Magento para las llamadas a esta función, hay muy pocas llamadas (solo una tal vez). Le mostrará su uso.

EDIT: Recuerdo que tenía el mismo problema del que está hablando, y lo envié por correo. Aquí está el uso que se me aconsejó:

$attrSet = Mage::getModel('eav/entity_attribute_set'); 
$attrSet->setAttributeSetName('MyAttributeSet'); 
$attrSet->setEntityTypeId(4);//You can look into the db what '4' corresponds to, I think it is for products. 
$attrSet->initFromSkeleton($attrSetId); 
$attrSet->save(); 

La inicialización se realiza antes de guardar.

+0

Aquí está la cosa, sin embargo, en la sección de administración cuando se pasa sobre el enlace para el atributo predeterminado, el id como muestra 4. Cuando llamo Mago :: getModel ('EAV/entity_attribute_set ') \t \t \t \t -> load ($ setName,' attribute_set_name '); el id. de atributo se devuelve como 1. Por lo tanto, al llamar a initFromSkeleton, el grupo predeterminado es 4 y no 1, por lo que no hay atributos asociados – Bill

3
  // create attribute set 
      $entityTypeId = Mage::getModel('eav/entity') 
       ->setType('catalog_product') 
       ->getTypeId(); // 4 - Default 

      $newSet = Mage::getModel('eav/entity_attribute_set'); 
      $newSet->setEntityTypeId($entityTypeId); 
      $newSet->setAttributeSetName(self::ATTRIBUTE_SET_NAME); 
      $newSet->save(); 

      $newSet->initFromSkeleton($entityTypeId); 
      $newSet->save(); 
0

aquí:

$entityTypeId = Mage::getModel('eav/entity') 
    ->setType('catalog_product') // This can be any eav_entity_type code 
    ->getTypeId(); 
$attrSet = Mage::getModel('eav/entity_attribute_set'); 

$attrSetCollection = $attrSet->getCollection(); 
$attrSetCollection 
    ->addFieldToFilter('entity_type_id', array('eq' => $entityTypeId)) 
    ->addFieldToFilter('attribute_set_name', array('eq' => 'Default')); // This can be any attribute set you might want to clone 

$defaultAttrSet = $attrSetCollection->getFirstItem(); 
$defaultAttrSetId = $defaultAttrSet->getAttributeSetId(); 

$attrSet->setAttributeSetName('Assinaturas'); // This is the new attribute set name 
$attrSet->setEntityTypeId($entityTypeId); 
$attrSet->initFromSkeleton($defaultAttrSetId); 
$attrSet->save(); 
1

Esto es lo que funcionó para mí.

$i_duplicate_attribut_set_id = 10; // ID of Attribut-Set you want to duplicate 
$object = new Mage_Catalog_Model_Product_Attribute_Set_Api(); 
$object->create('YOUR_ATTRIBUT_SET_NAME', $i_duplicate_attribut_set_id); 

Alex

+0

La mejor respuesta es imo –

Cuestiones relacionadas