Comment créer un nouveau type de lien produits, ce n’est pas exactement la demande, mais c’est ce qui m’a permis de trouver la solution à la demande initiale. Entrons dans le vif du sujet, nous allons créer la colonne en base qui contiendra les données de ce nouveau champ. app\code\local\Adfab\Associatedproductlink\sql\associatedproductlink_setup\mysql4-install-0.0.1.php
Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED, 'product_link_attribute_code' => 'reco', 'data_type' => 'int' ) ); $installer->getConnection()->insertMultiple($installer->getTable('catalog/product_link_attribute'), $data);
J’ajoute ensuite le champ dans le back-office en surchargeant la classe Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Group comme suit app\code\local\Adfab\Associatedproductlink\Block\Adminhtml\Catalog\Product\Edit\Tab\Super\Group.php
addColumn('in_products', array( 'header_css_class' => 'a-center', 'type' => 'checkbox', 'name' => 'in_products', 'values' => $this->_getSelectedProducts(), 'align' => 'center', 'index' => 'entity_id' )); $this->addColumn('entity_id', array( 'header' => Mage::helper('catalog')->__('ID'), 'sortable' => true, 'width' => '60px', 'index' => 'entity_id' )); $this->addColumn('name', array( 'header' => Mage::helper('catalog')->__('Name'), 'index' => 'name' )); $this->addColumn('sku', array( 'header' => Mage::helper('catalog')->__('SKU'), 'width' => '80px', 'index' => 'sku' )); $this->addColumn('price', array( 'header' => Mage::helper('catalog')->__('Price'), 'type' => 'currency', 'currency_code' => (string) Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE), 'index' => 'price' )); $this->addColumn('qty', array( 'header' => Mage::helper('catalog')->__('Default Qty'), 'name' => 'qty', 'type' => 'number', 'validate_class' => 'validate-number', 'index' => 'qty', 'width' => '1', 'editable' => true )); $this->addColumn('reco', array( 'header' => Mage::helper('catalog')->__('Reco Qty'), 'name' => 'reco', 'type' => 'number', 'validate_class' => 'validate-number', 'index' => 'reco', 'width' => '1', 'editable' => true )); $this->addColumn('position', array( 'header' => Mage::helper('catalog')->__('Position'), 'name' => 'position', 'type' => 'number', 'validate_class' => 'validate-number', 'index' => 'position', 'width' => '1', 'editable' => true, 'edit_only' => !$this->_getProduct()->getId() )); return parent::_prepareColumns(); } }
On va ensuite modifier le fichier app\design\adminhtml\default\default\layout\catalog.xml il faut modifier le noeud « adminhtml_catalog_product_supergroup » pour lui indiquer l’arrivée d’un nouveau champ.
<adminhtml_catalog_product_supergroup> <grid_block_name>catalog.product.edit.tab.super.group <data_callback>getSelectedGroupedProducts <hidden_input_name>links[grouped] <reload_param_name>products_grouped <input_name>qty <input_name>reco <input_name>position
Il ne nous reste plus qu’à créer les fichier xml de config et du module : app\code\local\Adfab\Associatedproductlink\etc\config.xml
<adfab_associatedproductlink> 0.0.1 Adfab_Associatedproductlink_Block <catalog_product_edit_tab_super_group>Adfab_Associatedproductlink_Block_Adminhtml_Catalog_Product_Edit_Tab_Super_Group <associatedproductlink_setup> Adfab_Associatedproductlink Mage_Eav_Model_Entity_Setup core_setup
app\etc\modules\Adfab_Associatedproductlink.xml
<adfab_associatedproductlink> true local