简体   繁体   中英

Magento custom attribute filter

I am a Magento developer. In my project I have added a custom attribute 'featured_product' to the table catalog_product, so that when clicking on any product from catalog/manage product , there will be an option for making the current product as a 'featured product'. Those featured products are displayed on the front end. Now in the product management grid, I want to develop a filter in terms of this 'featured product'. ie, There will be a check box or select box, and when we select 'featured product' from the select box and click on search, it will display all the featured products. How can I achieve this?

You have to override product grid in admin and add the column featured_product there. In that column you can sort all featured products.

  1. need add ypur custom attribute to grid collection.You can use observer event like this eav_collection_abstract_load_before or just rewrite this block Mage_Adminhtml_Block_Catalog_Product_Grid and update this method _prepareCollection().
  2. add to method _prepareColumns next code like this

    $this->addColumn('featured_product', array( 'header'=> Mage::helper('your_modile')->__('Featured Product'), 'width' => '60px', 'index' => 'featured_product', 'type' => 'options', 'options' => array('1' => 'Yes', '0' => 'No'), ));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM