Domanda

Sono di fronte a un problema per quanto riguarda la creazione di attributi e set di attributi utilizzando set di installazione script.attribute e l'attributo viene creato ma il problema è attributi vengono assegnati a tutti i set di attributi invece di solo uno personalizzato creando con script di installazione.

che segue è il mio script di installazione:

<?php
$installer = $this;
$installer->startSetup();
try{
$sNewSetName = 'Product Bundler Package';
$iCatalogProductEntityTypeId = (int) $installer->getEntityTypeId('catalog_product');

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

if ($oAttributeset->validate()) {
    $oAttributeset
        ->save()
        ->initFromSkeleton($installer->getAttributeSetId('catalog_product', 'Default'))
        ->save();
}
else {
    Mage::log('Attributeset with name ' . $sNewSetName . ' already exists.');
    }
}
catch(Exception $ex){
Mage::log('Attributeset with name ' . $sNewSetName . ' already exists.');

}


    $installer->addAttributeGroup('catalog_product', 'Product Bundler Package', 'Bundled Package Data', 1000);

    $data1= array (
        'attribute_set' =>  'Product Bundler Package',
        'group' => 'Bundled Package Data',
        'label'    => 'Preset1 name',
        'visible'     => true,
        'type'     => 'varchar', 
        'input'    => 'text',
        'system'   => true,
        'required' => false,
        'user_defined' => 1, 
    );

    $installer->addAttribute('catalog_product','bundle_preset1_name',$data1);

      $data2= array (
        'attribute_set' =>  'Product Bundler Package',
        'group'    => 'Bundled Package Data',
        'label'    => 'Preset2 name',
        'visible'  => true,
        'type'     => 'varchar', 
        'input'    => 'text',
        'system'   => true,
        'required' => false,
        'user_defined' => 1, 
    );
    $installer->addAttribute('catalog_product','bundle_preset2_name',$data2);

    $data3= array (
        'attribute_set' =>  'Product Bundler Package',
        'group' => 'Bundled Package Data',
        'label'    => 'Preset3 name',
        'visible'     => true,
        'type'     => 'varchar', 
        'input'    => 'text',
        'system'   => true,
        'required' => false,
        'user_defined' => 1, 
    );
    $installer->addAttribute('catalog_product','bundle_preset3_name',$data3);

    $data4 = array (
        'attribute_set' =>  'Product Bundler Package',
        'group' => 'Bundled Package Data',
        'label'    => 'Preset4 name',
        'visible'     => true,
        'type'     => 'varchar', 
        'input'    => 'text',
        'system'   => true,
        'required' => false,
        'user_defined' => 1, 
    );
   $attribute =  $installer->addAttribute('catalog_product','bundle_preset4_name',$data4);


$installer->endSetup();
?>

Voglio creare attributi personalizzati con il nome attributo impostato "Prodotto Bundler Package" e assegnare tutto attributo che solo set di attributi.

mi aiuto Gentilmente risolverlo.

È stato utile?

Soluzione

Non molto chiaro cosa si vuole fare veramente. In ogni caso questo è lo script per creare un attributo di prodotto dopo è stato creato il set di attributi.

<?php

$th =  new Mage_Catalog_Model_Resource_Setup();  
$th->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'your_custom_attribute_code', array(
            'group' => 'Prices', 
            'type' => 'text',
                        'attribute_set' =>  'Default', // Your custom Attribute set
            'backend' => '',
            'frontend' => '',
            'label' => 'My Custom Attribute',
            'input' => 'text',
            'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
            'visible' => true,
            'required' => false,
            'user_defined' => true,
            'default' => '1',
            'searchable' => false,
            'filterable' => true,
            'comparable' => false,
            'visible_on_front' => true,
            'visible_in_advanced_search' => true,
            'used_in_product_listing' => true,
            'unique' => false,
            'apply_to' => 'simple',  // Apply to simple product type
        ) );

Nota: Per ulteriori informazioni si prega di fare riferimento http://www.magentocommerce.com/wiki/5_- _modules_and_development / catalogo / programmatically_adding_attributes_and_attribute_sets

Altri suggerimenti

In sostanza, proprio come risposta da @Sukeshini ma è necessario lasciare group indefinito nei dati di attributi e specificare user_defined come true.

Quindi non sarà aggiunto al qualsiasi set di attributi. Per quanto ne so, non è possibile definire il set di attributi quando si crea l'attributo in questo metodo. È possibile aggiungere l'attributo a un set di attributi dopo averla creata nello script di aggiornamento o di installazione.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top