1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_GoogleBase_Block_Adminhtml_Items_Product extends Mage_Adminhtml_Block_Widget_Grid
35: {
36:
37: public function __construct()
38: {
39: parent::__construct();
40: $this->setId('googlebase_selection_search_grid');
41: $this->setDefaultSort('id');
42: $this->setUseAjax(true);
43: }
44:
45: protected function _beforeToHtml()
46: {
47: $this->setId($this->getId() . '_' . $this->getIndex());
48: $this->getChild('reset_filter_button')->setData('onclick', $this->getJsObjectName() . '.resetFilter()');
49: $this->getChild('search_button')->setData('onclick', $this->getJsObjectName() . '.doFilter()');
50: return parent::_beforeToHtml();
51: }
52:
53: protected function _prepareCollection()
54: {
55: $collection = Mage::getModel('catalog/product')->getCollection()
56: ->setStore($this->_getStore())
57: ->addAttributeToSelect('name')
58: ->addAttributeToSelect('sku')
59: ->addAttributeToSelect('price')
60: ->addAttributeToSelect('attribute_set_id');
61:
62:
63: $store = $this->_getStore();
64: if ($store->getId()) {
65: $collection->addStoreFilter($store);
66: }
67:
68: if ($excludeIds = $this->_getGoogleBaseProductIds()) {
69: $collection->addIdFilter($excludeIds, true);
70: }
71:
72: Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($collection);
73:
74: $this->setCollection($collection);
75:
76: return parent::_prepareCollection();
77: }
78:
79: protected function _prepareColumns()
80: {
81: $this->addColumn('id', array(
82: 'header' => Mage::helper('sales')->__('ID'),
83: 'sortable' => true,
84: 'width' => '60px',
85: 'index' => 'entity_id'
86: ));
87: $this->addColumn('name', array(
88: 'header' => Mage::helper('sales')->__('Product Name'),
89: 'index' => 'name',
90: 'column_css_class'=> 'name'
91: ));
92:
93: $sets = Mage::getResourceModel('eav/entity_attribute_set_collection')
94: ->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId())
95: ->load()
96: ->toOptionHash();
97:
98: $this->addColumn('type',
99: array(
100: 'header'=> Mage::helper('catalog')->__('Type'),
101: 'width' => '60px',
102: 'index' => 'type_id',
103: 'type' => 'options',
104: 'options' => Mage::getSingleton('catalog/product_type')->getOptionArray(),
105: ));
106:
107: $this->addColumn('set_name',
108: array(
109: 'header'=> Mage::helper('catalog')->__('Attrib. Set Name'),
110: 'width' => '100px',
111: 'index' => 'attribute_set_id',
112: 'type' => 'options',
113: 'options' => $sets,
114: ));
115:
116: $this->addColumn('sku', array(
117: 'header' => Mage::helper('sales')->__('SKU'),
118: 'width' => '80px',
119: 'index' => 'sku',
120: 'column_css_class'=> 'sku'
121: ));
122: $this->addColumn('price', array(
123: 'header' => Mage::helper('sales')->__('Price'),
124: 'align' => 'center',
125: 'type' => 'currency',
126: 'currency_code' => $this->_getStore()->getCurrentCurrencyCode(),
127: 'rate' => $this->_getStore()->getBaseCurrency()->getRate($this->_getStore()->getCurrentCurrencyCode()),
128: 'index' => 'price'
129: ));
130:
131: return parent::_prepareColumns();
132: }
133:
134: protected function _prepareMassaction()
135: {
136: $this->setMassactionIdField('product_id');
137: $this->getMassactionBlock()->setFormFieldName('product');
138:
139: $this->getMassactionBlock()->addItem('add', array(
140: 'label' => $this->__('Add to Google Base'),
141: 'url' => $this->getUrl('*/*/massAdd', array('_current' => true)),
142: ));
143: return $this;
144: }
145:
146: public function getGridUrl()
147: {
148: return $this->getUrl('*/googlebase_selection/grid', array('index' => $this->getIndex(), '_current' => true));
149: }
150:
151: protected function _getGoogleBaseProductIds()
152: {
153: $collection = Mage::getResourceModel('googlebase/item_collection')
154: ->addStoreFilterId($this->_getStore()->getId())
155: ->load();
156: $productIds = array();
157: foreach ($collection as $item) {
158: $productIds[] = $item->getProductId();
159: }
160: return $productIds;
161: }
162:
163: protected function _getStore()
164: {
165: return Mage::app()->getStore($this->getRequest()->getParam('store'));
166: }
167: }
168: