2

I have added a store selection field in one of my custom modules for testimonials. In which I want to show testimonials store wise specific to that store only. I have added the field and the filter is also working alright. The problem is that in the backend in admin grid where all the testimonials are listed out, there is one column that shows stores as well. Now if there is only one store then it shows up in the field, but if a testimonial is active for more than one stores then the field is blank. The values are set in database table but on the grid it doesn't show up multiple store. Can anyone tell me what am i missing here?

  • Do you store the link between testimonials and store views in a separate table (testimonial_id, store_id), or in field on the testimonial table separated by commas? – Marius Jul 8 '13 at 12:03
  • I am storing the ids in a comma separated list in the testimonial table field. – jdhaar Jul 8 '13 at 12:52
  • 1
    In this case it's normal not to work. Here is how a 'dropdown' column works in the grid. For each row it checks if there is a value in the dropdwon for the specific column. If there is, then it prints the text of the option. So when you have your testimonial in only on store (let's say store id 1) the label of the store id is shown. But when you have a value like '1,2' there is no store with the id '1,2'. I recommend you to look how the cms pages grid and models look like and try to replicate them for your testimonials. This involves storing the store id in a separate table. – Marius Jul 8 '13 at 12:56
  • 3
    Look specially at these methods :Mage_Cms_Model_Resource_Page_Collection::_afterLoad() and _renderFiltersBefore() – Marius Jul 8 '13 at 12:59
1

To add a store_id field to a standard magento grid, you can use the following snippet:

$this->addColumn(
    'store_id',
    array(
        'header'   => 'Store',
        'index'    => 'store_id',
        'type'     => 'store'
    )
);

This will then use the class Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Store to render this column.

Note: I know this is not the exact answer that they are looking for but this is how Magento does this by standard

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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