Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

[SOLVED]Admin Product Grid filter problem
 
freshwebs
Sr. Member
 
Total Posts:  153
Joined:  2008-05-27
Leicestershire, UK
 

Hi,
I’ve done an override of the default ‘Manage Products’ grid within admin, so that it includes some custom attributes. However, I have a problem in that the number of products returned is being filtered/reduced by the (non) presence of one particular attribute.

Perhaps I need to explain this a little better! I have a custom, non mandatory drop down (single select) attribute called Signed. As its non mandatory, admin can leave it as blank when creating a product - so the available options are blank/null, signed, in plate, etc. Now, when I include this attribute in my product grid, only those products that have a value (signed or in plate) for Signed are returned - its is excluding or filtering out those with a blank/null value for Signed.

I suspect it might have something to do with the way I select the attribute but I’m not sure. Here’s the code where I get the attributes in Block_Catalog_Product_Grid:

class Fws_Adminhtml_Block_Catalog_Product_Grid extends Mage_Adminhtml_Block_Catalog_Product_Grid {
 
protected function _prepareCollection()
    
{
        $store 
$this->_getStore();
        
$collection Mage::getModel('catalog/product')->getCollection()
        ->
addAttributeToSelect('sku')
       ->
joinAttribute('signed','catalog_product/signed''entity_id'null,'inner'$store->getId())
......
}

I then render the attributes like so:

protected function _prepareColumns()  {
......
 
/** Signed */
        
$signed_items Mage::getModel('eav/entity_attribute_option')
            ->
getCollection()
            ->
setStoreFilter()
            ->
join('attribute','attribute.attribute_id=main_table.attribute_id''attribute_code');
        foreach (
$signed_items as $signed_item) :
            if (
$signed_item->getAttributeCode() == 'signed')
                
$signed_options[$signed_item->getOptionId()$signed_item->getValue();
        endforeach;

      
$this->addColumn('signed',
            array(
                
'header'=> Mage::helper('catalog')->__('Signed'),
                
'width' => '80px',
                
'index' => 'signed',
                 
'type'  => 'options',
                
'options' => $signed_options,
        ));

.......
}

So, this is pretty much how I get other custom attributes that are drop downs - the only difference is that these other ones don’t have a ‘blank’ option. If I include the signed attribute in the grid, I get fewer products returned (50%!) than without it.

Now, I know I could add ‘unsigned’ as an option to my signed drop down but I don’t want to show that a product is unsigned - only that it is signed. At the moment, Mage will not display a null attribute - if possible I want to avoid having to do a check on the front end to see if a product is signed before displaying that attribute.

I suspect, like I said above, that the issue may be in the joinAttribute syntax - am I missing something here, something that will tell Zend to include nulls?

Any help gratefully received!

EDIT

I resolved this issue - as suspected it was the join that was causing the issue - the join isn’t in fact necessary in this instance, as this attribute is one of the product’s custom attribute.

So instead of the join just use: ->addAttributeToSelect(’signed’)
Then render the column like so:

** Signed  */
       
$attribute Mage::getModel('eav/config')->getAttribute('catalog_product''signed');
         
$options = array();
        foreach( 
$attribute->getSource()->getAllOptions(truetrue) as $option {
           $options[$option[
'value']] $option['label'];
        
}
        $this
->addColumn('signed',
            array(
                
'header'=> Mage::helper('catalog')->__('Signed?'),
                
'width' => '80px',
                
'index' => 'signed',
                
'type'  => 'options',
                
'options' => $options,
        ));

Cheers,
Eddie

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top