{"id":381,"date":"2013-04-11T08:24:33","date_gmt":"2013-04-11T06:24:33","guid":{"rendered":"http:\/\/www.h-hennes.fr\/blog\/?p=381"},"modified":"2013-07-24T21:08:47","modified_gmt":"2013-07-24T19:08:47","slug":"magento-ajouter-un-attribut-produit-via-un-module","status":"publish","type":"post","link":"https:\/\/www.h-hennes.fr\/blog\/2013\/04\/11\/magento-ajouter-un-attribut-produit-via-un-module\/","title":{"rendered":"Magento : Ajouter un attribut produit via un module"},"content":{"rendered":"<p>Petit script pratique aujourd&rsquo;hui pour ajouter rapidement un attribut produit via un module personnalis\u00e9.<br \/>\nDans notre cas nous allons \u00e9galement cr\u00e9er un groupe d&rsquo;attribut sp\u00e9cifique qui sera ajout\u00e9 \u00e0 tous les jeux d&rsquo;attributs produits.<br \/>\nPuis pour finir nous ajouterons l&rsquo;attribut directement dans ce groupe d&rsquo;attributs.<\/p>\n<p>Le code suivant est \u00e0 placer dans le fichier d&rsquo;install ou d&rsquo;upgrade de votre module.<\/p>\n<p>&nbsp;<\/p>\n<pre lang=\"php\">$installer = $this;\r\n$setup = new Mage_Eav_Model_Entity_Setup('core_setup');\r\n$installer->startSetup();\r\n\r\n\/**\r\n * Cr\u00e9ation du nouvel Attribut produit \"product_picto\"\r\n * Creation of the new product attribute \"product_picto\"\r\n *\/\r\n$setup->addAttribute('catalog_product', 'product_picto', array(\r\n    'label' => 'product_picto',\r\n    'type' => 'varchar',\r\n    'input' => 'select',\r\n    'backend' => '',\r\n    'frontend' => '',\r\n    'global' => 0,\r\n    'visible' => true,\r\n    'required' => false,\r\n    'user_defined' => 1,\r\n    'option' => array(\r\n        'value' => array(\r\n            'none' => array('none'),\r\n            'exclu-web' => array('exclu-web'),\r\n            'nouveaute' => array('nouveaute'),\r\n            'top-ventes' => array('top-ventes'),\r\n        )\r\n    ),\r\n    'used_in_product_listing' => 1,\r\n    'default' => 'none',\r\n));\r\n\r\n\r\n\/**\r\n * Cr\u00e9ation d'un groupe d'attribut \"V2\" et ajout du nouvel attribut \"product_picto\" dans ce groupe pour tous les jeux d'attributs\r\n * Creation of an attribute group \"V2\" and add of the new attribute \"product_picto\" in this attribute group  for all attributes sets\r\n *\/\r\n$attributesSetIds = $setup->getAllAttributeSetIds('catalog_product');\r\n\r\nforeach ($attributesSetIds as $attributesSetId) {\r\n   \r\n    $setup->addAttributeGroup('catalog_product', $attributesSetId, 'V2');\r\n    $setup->addAttributeToGroup('catalog_product', $attributesSetId, 'V2', 'product_picto');\r\n    \r\n}\r\n\r\n$installer->endSetup();<\/pre>\n<p>Apr\u00e8s l&rsquo;installation ou la mise \u00e0 jour de votre module voici le r\u00e9sultat obtenu \ud83d\ude42<\/p>\n<p><a href=\"https:\/\/www.h-hennes.fr\/blog\/wp-content\/uploads\/2013\/04\/product-attribute1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-383 alignleft\" title=\"Attribut produit Magento\" src=\"https:\/\/www.h-hennes.fr\/blog\/wp-content\/uploads\/2013\/04\/product-attribute1.jpg\" alt=\"\" width=\"800\" height=\"271\" srcset=\"https:\/\/www.h-hennes.fr\/blog\/wp-content\/uploads\/2013\/04\/product-attribute1.jpg 800w, https:\/\/www.h-hennes.fr\/blog\/wp-content\/uploads\/2013\/04\/product-attribute1-300x101.jpg 300w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Petit script pratique aujourd&rsquo;hui pour ajouter rapidement un attribut produit via un module personnalis\u00e9. Dans notre cas nous allons \u00e9galement cr\u00e9er un groupe d&rsquo;attribut sp\u00e9cifique qui sera ajout\u00e9 \u00e0 tous les jeux d&rsquo;attributs produits. Puis pour finir nous ajouterons l&rsquo;attribut directement dans ce groupe d&rsquo;attributs. Le code suivant est \u00e0 placer dans le fichier d&rsquo;install [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[246,6],"tags":[231,150,212],"class_list":["post-381","post","type-post","status-publish","format-standard","hentry","category-magento-2","category-trucs-et-astuces","tag-attribut-produit-magento","tag-magento","tag-module-magento"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/posts\/381","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/comments?post=381"}],"version-history":[{"count":4,"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/posts\/381\/revisions"}],"predecessor-version":[{"id":478,"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/posts\/381\/revisions\/478"}],"wp:attachment":[{"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/media?parent=381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/categories?post=381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/tags?post=381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}