magento Filter Google Base based on product status [SOLVED]

piaoling  2011-11-01 11:05:47
class Mage_GoogleBase_Block_Adminhtml_Items_Product extends Mage_Adminhtml_Block_Widget_Grid
{

    
public function __construct()
    
{
        parent
::__construct();
        
$this->setId('googlebase_selection_search_grid');
        
$this->setDefaultSort('id');
        
$this->setUseAjax(true);
    
}

    
protected function _beforeToHtml()
    
{
        $this
->setId($this->getId().'_'.$this->getIndex());
        
$this->getChild('reset_filter_button')->setData('onclick'$this->getJsObjectName().'.resetFilter()');
        
$this->getChild('search_button')->setData('onclick'$this->getJsObjectName().'.doFilter()');
        return 
parent::_beforeToHtml();
    
}

    
protected function _prepareCollection()
    
{
        $collection 
Mage::getModel('catalog/product')->getCollection()
            ->
setStore($this->_getStore())
            ->
addAttributeToSelect('name')
            ->
addAttributeToSelect('sku')
            ->
addAttributeToSelect('price')
            ->
addAttributeToSelect('attribute_set_id');
//            ->addFilterByRequiredOptions();

        
$store $this->_getStore();
        if (
$store->getId()) {
            $collection
->addStoreFilter($store);
            
$collection->joinAttribute('visibility''catalog_product/visibility''entity_id'null'inner'$store->getId()); 
        
}

        
if ($excludeIds $this->_getGoogleBaseProductIds()) {
            $collection
->addIdFilter($excludeIdstrue);
        
}

        Mage
::getSingleton('catalog/product_status')->addSaleableFilterToCollection($collection);

        
$this->setCollection($collection);

        return 
parent::_prepareCollection();
    
}

    
protected function _prepareColumns()
    
{
        $this
->addColumn('id', array(
            
'header'    => Mage::helper('sales')->__('ID'),
            
'sortable'  => true,
            
'width'     => '60px',
            
'index'     => 'entity_id'
        
));
        
$this->addColumn('name', array(
            
'header'    => Mage::helper('sales')->__('Product Name'),
            
'index'     => 'name',
            
'column_css_class'=> 'name'
        
));

        
$sets Mage::getResourceModel('eav/entity_attribute_set_collection')
            ->
setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId())
            ->
load()
            ->
toOptionHash();

        
$this->addColumn('type',
            array(
                
'header'=> Mage::helper('catalog')->__('Type'),
                
'width' => '60px',
                
'index' => 'type_id',
                
'type'  => 'options',
                
'options' => Mage::getSingleton('catalog/product_type')->getOptionArray(),
        ));

        
$this->addColumn('visibility',
            array(
                
'header'=> Mage::helper('catalog')->__('Visibility'),
                
'width' => '70px',
                
'index' => 'visibility',
                
'type'  => 'options',
                
'options' => Mage::getSingleton('catalog/product_visibility')->getOptionArray(),
        ));
        
        
$this->addColumn('set_name',
            array(
                
'header'=> Mage::helper('catalog')->__('Attrib. Set Name'),
                
'width' => '100px',
                
'index' => 'attribute_set_id',
                
'type'  => 'options',
                
'options' => $sets,
        ));

        
$this->addColumn('sku', array(
            
'header'    => Mage::helper('sales')->__('SKU'),
            
'width'     => '80px',
            
'index'     => 'sku',
            
'column_css_class'=> 'sku'
        
));
        
$this->addColumn('price', array(
            
'header'    => Mage::helper('sales')->__('Price'),
            
'align'     => 'center',
            
'type'      => 'currency',
            
'currency_code' => $this->_getStore()->getCurrentCurrencyCode(),
            
'rate'      => $this->_getStore()->getBaseCurrency()->getRate($this->_getStore()->getCurrentCurrencyCode()),
            
'index'     => 'price'
        
));

        return 
parent::_prepareColumns();
    
}

    
protected function _prepareMassaction()
    
{
        $this
->setMassactionIdField('product_id');
        
$this->getMassactionBlock()->setFormFieldName('product');

        
$this->getMassactionBlock()->addItem('add', array(
             
'label'    => $this->__('Add to Google Base'),
             
'url'      => $this->getUrl('*/*/massAdd', array('_current'=>true)),
        ));
        return 
$this;
    
}

    
public function getGridUrl()
    
{
        
return $this->getUrl('googlebase/selection/grid', array('index' => $this->getIndex(),'_current'=>true));
    
}

    
protected function _getGoogleBaseProductIds()
    
{
        $collection 
Mage::getResourceModel('googlebase/item_collection')
            ->
addStoreFilterId($this->_getStore()->getId())
            ->
load();
        
$productIds = array();
        foreach (
$collection as $item{
            $productIds[] 
$item->getProductId();
        
}
        
return $productIds;
    
}

    
protected function _getStore()
    
{
        
return Mage::app()->getStore($this->getRequest()->getParam('store'));
    
}
}
 
 
 
 
http://www.magentocommerce.com/boards/viewthread/213315/
类别 :  magento(258)  |  浏览(4005)  |  评论(2)
发表评论(评论将通过邮件发给作者):

Email:
userhead
侯会亮
2012-10-08 14:05:47
0.0
userhead
侯会亮
2012-09-26 15:38:20
Magento