2

I have created one custom module for slider. I want to add product to the slider manually. so i have decided to show product grid under select products tab. I got product grid. But i can't get product id value.

I got following value,when i use var_dump()

array(14) { ["form_key"]=> string(16) "mdfqCbKxuebW87wT" ["title"]=> string(4) "TEST"
["status"]=> string(0) "" ["c_id"]=> string(2) "12" ["store"]=> string(1) "5" 
["page"]=> string(1) "1" ["limit"]=> string(3) "100" ["in_category"]=> string(0) ""
["entity_id"]=> string(1) "," ["name"]=> string(0) "" ["type"]=> string(0) "" ["sku"]=> 
string(0) "" ["websites"]=> string(0) "" ["links"]=> string(0) "" }

product grid returns an empty value

enter image description here

its describe, product grid under select products tab.

https://docs.google.com/file/d/0B9pmknBzwZOuQ3k2M1BLQmhzMFE/edit

Here is my complete code

I can't understand where is problem arise! If you found any thing wrong here, please save me guys!

Thank you

4
  • Hi, can you clarify when you are trying to get the product id? Is this in a controller action? thus posted data?, or are you trying to get the id after the checkbox is selected to use via javascript? Additionally, I tried your code posted, and it fails when changing to the grid tab: Warning: array_keys() expects parameter 1 to be array, null given in /home/lucas/workspace/personal/proxiblue/app/code/local/Chilly/Imageslide/Block/Adminhtml/Imageslide/Edit/Tab/Product.php on line 148
    – ProxiBlue
    Commented Jan 8, 2014 at 9:50
  • to get product id of selected products in saveAction in controller file
    – DRAJI
    Commented Jan 8, 2014 at 10:33
  • ["links"]=> string(0) "" has empty value @ProxiBlue
    – DRAJI
    Commented Jan 8, 2014 at 11:51
  • I M Use This Module. SO, How We can save selected product record in creating another table ? as per id Commented Dec 21, 2016 at 11:37

2 Answers 2

4

The normal behaviour for the grid checkbox is to bind a js event to it, and action the checkbox check/uncheck. Normally this would be to populate a hidden field with the selected values, and then that field is what gets posted to your controller action.

See varienGrid.prototype /js/mage/adminhtml/grid.js : (this.checkboxCheckCallback) and also setCheckboxChecked method in that class.

For this reason the checkbox element generally do not get a name assigned to it, which you can see if you view your element properties.

enter image description here

This is thus the reason why you cannot get the selected options in your post action, since elements with no name will not post in the form, and you most likely do not have the required callback set to deal with the check/uncheck of the box. Using the callback js, you could also effect other actions in your gui, to enhance the user experience.

However, looking at your usage requirements, you may just get away with setting a name for the checkbox element, which will then post the data to your action.

Thus if you adjust your element definition to this (adding in the 'field_name' property), you will get your data in an array called 'selectedproducts'

$this->addColumn('in_category', array(
                'header_css_class' => 'a-center',
                'type'      => 'checkbox',
                'values'    => $this->_getSelectedProducts(),
                'align'     => 'center',
                'index'     => 'entity_id',
        'name'      => 'in_category',
                'field_name' => 'selectedproducts[]'
            ));

Hope that helps.

1
  • 3
    @DRAJI - accepted behaviour is to credit people if their answers worked for you, or at least comment if not :) - thats how stackexchange works ;)
    – ProxiBlue
    Commented Jan 21, 2014 at 10:00
3

Add the below line in your Grid.php

'field_name' => 'selectedproducts[]',

in the "in_category" column.

I hope then you will definetly get the Ids of Selected Product.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.