00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_GoogleBase_Block_Adminhtml_Items_Product extends Mage_Adminhtml_Block_Widget_Grid
00035 {
00036
00037 public function __construct()
00038 {
00039 parent::__construct();
00040 $this->setId('googlebase_selection_search_grid');
00041 $this->setDefaultSort('id');
00042 $this->setUseAjax(true);
00043 }
00044
00045 protected function _beforeToHtml()
00046 {
00047 $this->setId($this->getId().'_'.$this->getIndex());
00048 $this->getChild('reset_filter_button')->setData('onclick', $this->getJsObjectName().'.resetFilter()');
00049 $this->getChild('search_button')->setData('onclick', $this->getJsObjectName().'.doFilter()');
00050 return parent::_beforeToHtml();
00051 }
00052
00053 protected function _prepareCollection()
00054 {
00055 $collection = Mage::getModel('catalog/product')->getCollection()
00056 ->setStore($this->_getStore())
00057 ->addAttributeToSelect('name')
00058 ->addAttributeToSelect('sku')
00059 ->addAttributeToSelect('price')
00060 ->addAttributeToSelect('attribute_set_id');
00061
00062
00063 $store = $this->_getStore();
00064 if ($store->getId()) {
00065 $collection->addStoreFilter($store);
00066 }
00067
00068 if ($excludeIds = $this->_getGoogleBaseProductIds()) {
00069 $collection->addIdFilter($excludeIds, true);
00070 }
00071
00072 Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($collection);
00073
00074 $this->setCollection($collection);
00075
00076 return parent::_prepareCollection();
00077 }
00078
00079 protected function _prepareColumns()
00080 {
00081 $this->addColumn('id', array(
00082 'header' => Mage::helper('sales')->__('ID'),
00083 'sortable' => true,
00084 'width' => '60px',
00085 'index' => 'entity_id'
00086 ));
00087 $this->addColumn('name', array(
00088 'header' => Mage::helper('sales')->__('Product Name'),
00089 'index' => 'name',
00090 'column_css_class'=> 'name'
00091 ));
00092
00093 $sets = Mage::getResourceModel('eav/entity_attribute_set_collection')
00094 ->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId())
00095 ->load()
00096 ->toOptionHash();
00097
00098 $this->addColumn('set_name',
00099 array(
00100 'header'=> Mage::helper('catalog')->__('Attrib. Set Name'),
00101 'width' => '100px',
00102 'index' => 'attribute_set_id',
00103 'type' => 'options',
00104 'options' => $sets,
00105 ));
00106
00107 $this->addColumn('sku', array(
00108 'header' => Mage::helper('sales')->__('SKU'),
00109 'width' => '80px',
00110 'index' => 'sku',
00111 'column_css_class'=> 'sku'
00112 ));
00113 $this->addColumn('price', array(
00114 'header' => Mage::helper('sales')->__('Price'),
00115 'align' => 'center',
00116 'type' => 'currency',
00117 'currency_code' => $this->_getStore()->getCurrentCurrencyCode(),
00118 'rate' => $this->_getStore()->getBaseCurrency()->getRate($this->_getStore()->getCurrentCurrencyCode()),
00119 'index' => 'price'
00120 ));
00121
00122 return parent::_prepareColumns();
00123 }
00124
00125 protected function _prepareMassaction()
00126 {
00127 $this->setMassactionIdField('product_id');
00128 $this->getMassactionBlock()->setFormFieldName('product');
00129
00130 $this->getMassactionBlock()->addItem('add', array(
00131 'label' => $this->__('Add to Google Base'),
00132 'url' => $this->getUrl('*/*/massAdd', array('_current'=>true)),
00133 ));
00134 return $this;
00135 }
00136
00137 public function getGridUrl()
00138 {
00139 return $this->getUrl('googlebase/selection/grid', array('index' => $this->getIndex(),'_current'=>true));
00140 }
00141
00142 protected function _getGoogleBaseProductIds()
00143 {
00144 $collection = Mage::getResourceModel('googlebase/item_collection')
00145 ->addStoreFilterId($this->_getStore()->getId())
00146 ->load();
00147 $productIds = array();
00148 foreach ($collection as $item) {
00149 $productIds[] = $item->getProductId();
00150 }
00151 return $productIds;
00152 }
00153
00154 protected function _getStore()
00155 {
00156 return Mage::app()->getStore($this->getRequest()->getParam('store'));
00157 }
00158 }