Petit script pratique aujourd’hui pour ajouter rapidement un attribut produit via un module personnalisé.
Dans notre cas nous allons également créer un groupe d’attribut spécifique qui sera ajouté à tous les jeux d’attributs produits.
Puis pour finir nous ajouterons l’attribut directement dans ce groupe d’attributs.
Le code suivant est à placer dans le fichier d’install ou d’upgrade de votre module.
$installer = $this; $setup = new Mage_Eav_Model_Entity_Setup('core_setup'); $installer->startSetup(); /** * Création du nouvel Attribut produit "product_picto" * Creation of the new product attribute "product_picto" */ $setup->addAttribute('catalog_product', 'product_picto', array( 'label' => 'product_picto', 'type' => 'varchar', 'input' => 'select', 'backend' => '', 'frontend' => '', 'global' => 0, 'visible' => true, 'required' => false, 'user_defined' => 1, 'option' => array( 'value' => array( 'none' => array('none'), 'exclu-web' => array('exclu-web'), 'nouveaute' => array('nouveaute'), 'top-ventes' => array('top-ventes'), ) ), 'used_in_product_listing' => 1, 'default' => 'none', )); /** * Création d'un groupe d'attribut "V2" et ajout du nouvel attribut "product_picto" dans ce groupe pour tous les jeux d'attributs * Creation of an attribute group "V2" and add of the new attribute "product_picto" in this attribute group for all attributes sets */ $attributesSetIds = $setup->getAllAttributeSetIds('catalog_product'); foreach ($attributesSetIds as $attributesSetId) { $setup->addAttributeGroup('catalog_product', $attributesSetId, 'V2'); $setup->addAttributeToGroup('catalog_product', $attributesSetId, 'V2', 'product_picto'); } $installer->endSetup(); |
Après l’installation ou la mise à jour de votre module voici le résultat obtenu 🙂
0 commentaires actuellement.
Commentez!