1

Specifically, in my adminhtml Grid.php I created a $collection in _prepareCollection() by using the getSelect()->join() and it works great. I've merged several tables.

Now I want to create a custom column that includes a value based on sku. Lets call it product type. I would like to do something like this:

    foreach($collection as $item):
        if($item->getSku() == 'fresh')     
            $item->setData('product_material','Fresh');
        else
            $item->setData('product_material','Not Fresh');
        $item->save();
    endforeach;

I have more complex logic to build the product material, but you should get the point. The fact I found no clue on how to do this also tells me I'm probably approaching this incorrectly. Is there a better way to do this or a place to handle this?

I don't want to store this in a table yet because we are still defining what inputs generate the material type.

1

You'll want to create this computed column on-the-fly (saving objects don't make sense). Check out this post (link). It shows you how to add a calculated column and how to fully functionalize it.

  • Thank you, that forum post was great. One note, the specific case required his index => 'created_at' which is rather unique. If it's text like mine, just use the variable name – kevando May 7 '14 at 2:05

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.