I have created a custom column for associated products (basically every simple product will have that column under "associated products" tab of configurable product). I store information of this field/column into an attribute which belong to configurable product instead of each simple product.
Below is the code for adding a column;
config.xml
<core_block_abstract_to_html_before>
<observers>
<something>
<class>namespace_JsonProductInfo_Model_Observer</class>
<method>addPositionColumn</method>
</something>
</observers>
</core_block_abstract_to_html_before>
Oberver.php
public function addPositionColumn(Varien_Event_Observer $observer)
{
$block = $observer->getEvent()->getBlock();
if ($block instanceof Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Config_Grid) {
if (!$block->isReadonly()) {
$block->addColumnAfter(
'position_simple',
array(
'header' => Mage::helper('jsonproductinfo')->__('Position'),
'type' => 'input',
'name' => 'position_simple',
'index' => 'position_simple',
'sortable' => false,
),
'name'
);
}
}
}
With above code I am able to add the column into a require grid. And I am also able to save the information which I put inside that column (which is basically an attribute). The only problem I am facing is, I am unable to display the stored information into that column again (If I edit the product). I have also created another observer of type eav_collection_abstract_load_befor
but no luck so far.
Below is the code for it:
config.xml
<eav_collection_abstract_load_before>
<observers>
<jsonproductinfo>
<class>namespace_JsonProductInfo_Model_Observer</class>
<method>addPositionToCatalogProductCollection</method>
</jsonproductinfo>
</observers>
</eav_collection_abstract_load_before>
Observer.php
public function addPositionToCatalogProductCollection($observer)
{
$collection = $observer->getEvent()->getCollection();
if (!isset($collection)) {
return;
}
$collection->addAttributeToSelect('position_simple');
}
I would be grateful if someone can point to the mistake or guide me how can I display back that information again into that column.
EDIT
And here is the code which creates the "postion_simple".
$this->addAttribute(
'catalog_product',
'position_simple',
array(
'group' => 'General',
'type' => 'varchar',
'input' => 'hidden',
'backend' => '',
'frontend' => '',
'label' => 'Simple Position',
'class' => '',
'source' => '',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'visible_in_advanced_search' => false,
'unique' => false,
'apply_to' => Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE,
'is_configurable' => false,
)
);