Adding custom column into product grid





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







4















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,
)
);









share|improve this question
















bumped to the homepage by Community 9 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • have you checked that your observer is working ? check by printing query in your observer.echo $collection->getSelect();

    – Minesh Patel
    Dec 7 '15 at 5:17











  • @MineshPatel, Yes, the observer is working. I was already sure about it but still checked it by printing the query.

    – Capri82
    Dec 7 '15 at 12:44


















4















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,
)
);









share|improve this question
















bumped to the homepage by Community 9 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • have you checked that your observer is working ? check by printing query in your observer.echo $collection->getSelect();

    – Minesh Patel
    Dec 7 '15 at 5:17











  • @MineshPatel, Yes, the observer is working. I was already sure about it but still checked it by printing the query.

    – Capri82
    Dec 7 '15 at 12:44














4












4








4








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,
)
);









share|improve this question
















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,
)
);






magento-1.9 product configurable-product event-observer grid






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 4 '16 at 7:13









Siarhey Uchukhlebau

10.2k93058




10.2k93058










asked Dec 6 '15 at 19:23









Capri82Capri82

486




486





bumped to the homepage by Community 9 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 9 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • have you checked that your observer is working ? check by printing query in your observer.echo $collection->getSelect();

    – Minesh Patel
    Dec 7 '15 at 5:17











  • @MineshPatel, Yes, the observer is working. I was already sure about it but still checked it by printing the query.

    – Capri82
    Dec 7 '15 at 12:44



















  • have you checked that your observer is working ? check by printing query in your observer.echo $collection->getSelect();

    – Minesh Patel
    Dec 7 '15 at 5:17











  • @MineshPatel, Yes, the observer is working. I was already sure about it but still checked it by printing the query.

    – Capri82
    Dec 7 '15 at 12:44

















have you checked that your observer is working ? check by printing query in your observer.echo $collection->getSelect();

– Minesh Patel
Dec 7 '15 at 5:17





have you checked that your observer is working ? check by printing query in your observer.echo $collection->getSelect();

– Minesh Patel
Dec 7 '15 at 5:17













@MineshPatel, Yes, the observer is working. I was already sure about it but still checked it by printing the query.

– Capri82
Dec 7 '15 at 12:44





@MineshPatel, Yes, the observer is working. I was already sure about it but still checked it by printing the query.

– Capri82
Dec 7 '15 at 12:44










1 Answer
1






active

oldest

votes


















0















  1. change 'index' => 'position_simple' to 'index' => 'entity_id' in your Observer.php (function addPositionColumn)

  2. you need to get value of your position_simple attribute from configurable product and use it in added column - one way to do that:


create function in Observer.php



protected function _getDefaultConfigurationId() {
/** @var Mage_Catalog_Model_Product $product */
$product = Mage::registry('current_product');
if ($product) {
return array($product->getData('position_simple'));
}
return '';
}


and use that in your addPositionColumn function like that:



...    
'values' => $this->_getDefaultConfigurationId(),
...


After that, there is no need of observer type eav_collection_abstract_load_befor at all.






share|improve this answer
























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "479"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f92789%2fadding-custom-column-into-product-grid%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0















    1. change 'index' => 'position_simple' to 'index' => 'entity_id' in your Observer.php (function addPositionColumn)

    2. you need to get value of your position_simple attribute from configurable product and use it in added column - one way to do that:


    create function in Observer.php



    protected function _getDefaultConfigurationId() {
    /** @var Mage_Catalog_Model_Product $product */
    $product = Mage::registry('current_product');
    if ($product) {
    return array($product->getData('position_simple'));
    }
    return '';
    }


    and use that in your addPositionColumn function like that:



    ...    
    'values' => $this->_getDefaultConfigurationId(),
    ...


    After that, there is no need of observer type eav_collection_abstract_load_befor at all.






    share|improve this answer




























      0















      1. change 'index' => 'position_simple' to 'index' => 'entity_id' in your Observer.php (function addPositionColumn)

      2. you need to get value of your position_simple attribute from configurable product and use it in added column - one way to do that:


      create function in Observer.php



      protected function _getDefaultConfigurationId() {
      /** @var Mage_Catalog_Model_Product $product */
      $product = Mage::registry('current_product');
      if ($product) {
      return array($product->getData('position_simple'));
      }
      return '';
      }


      and use that in your addPositionColumn function like that:



      ...    
      'values' => $this->_getDefaultConfigurationId(),
      ...


      After that, there is no need of observer type eav_collection_abstract_load_befor at all.






      share|improve this answer


























        0












        0








        0








        1. change 'index' => 'position_simple' to 'index' => 'entity_id' in your Observer.php (function addPositionColumn)

        2. you need to get value of your position_simple attribute from configurable product and use it in added column - one way to do that:


        create function in Observer.php



        protected function _getDefaultConfigurationId() {
        /** @var Mage_Catalog_Model_Product $product */
        $product = Mage::registry('current_product');
        if ($product) {
        return array($product->getData('position_simple'));
        }
        return '';
        }


        and use that in your addPositionColumn function like that:



        ...    
        'values' => $this->_getDefaultConfigurationId(),
        ...


        After that, there is no need of observer type eav_collection_abstract_load_befor at all.






        share|improve this answer














        1. change 'index' => 'position_simple' to 'index' => 'entity_id' in your Observer.php (function addPositionColumn)

        2. you need to get value of your position_simple attribute from configurable product and use it in added column - one way to do that:


        create function in Observer.php



        protected function _getDefaultConfigurationId() {
        /** @var Mage_Catalog_Model_Product $product */
        $product = Mage::registry('current_product');
        if ($product) {
        return array($product->getData('position_simple'));
        }
        return '';
        }


        and use that in your addPositionColumn function like that:



        ...    
        'values' => $this->_getDefaultConfigurationId(),
        ...


        After that, there is no need of observer type eav_collection_abstract_load_befor at all.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 20 '16 at 7:40









        tesar.hktesar.hk

        306




        306






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f92789%2fadding-custom-column-into-product-grid%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Alcázar de San Juan

            Griza ansero

            Heinkel He 51