Domanda

E 'possibile aggiungere un file php nella directory principale di Magento?

$attribute_set_name = 'your attribute set name here';
$group_name = 'your attribute group here';
$attribute_code = 'your attribute code here';

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

//-------------- add attribute to set and group
$attribute_set_id = $setup->getAttributeSetId('catalog_product', $attribute_set_name);
$attribute_group_id = $setup->getAttributeGroupId('catalog_product', $attribute_set_id, $group_name);
$attribute_id = $setup->getAttributeId('catalog_product', $attribute_code);

$setup->addAttributeToSet($entityTypeId='catalog_product',$attribute_set_id, $attribute_group_id, $attribute_id);

mi sono imbattuto questo codice, ma c'è un errore:

Fatal error: chiamata a una funzione membro getResourceConfig () su un non-oggetto in C: \ xampp \ htdocs \ Magento \ app \ code \ Core \ Mage \ Core \ modello \ Resource \ setup.php on line 131

È stato utile?

Soluzione

Ho sempre suggerire facendo questo tipo di cose tramite script di set-up di un modulo. Per tutti i dettagli sul set-up di script vedi , ma per quello che avete bisogno di qualcosa come il seguente dovrebbe funzionare.

<?php
/* @var $this Mage_Customer_Model_Entity_Setup */
$this->startSetup();

$attribute_set_name = 'your attribute set name here';
$group_name = 'your attribute group here';
$attribute_code = 'your attribute code here';

//-------------- add attribute to set and group
$attribute_set_id=$this->getAttributeSetId('catalog_product', $attribute_set_name);
$attribute_group_id=$this->getAttributeGroupId('catalog_product', $attribute_set_id, $group_name);
$attribute_id=$this->getAttributeId('catalog_product', $attribute_code);

$this->addAttributeToSet($entityTypeId='catalog_product',$attribute_set_id, $attribute_group_id, $attribute_id);

$this->endSetup();
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top