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_Adminhtml_Block_Sales_Order_Create_Search_Grid extends Mage_Adminhtml_Block_Widget_Grid
35: {
36:
37: public function __construct()
38: {
39: parent::__construct();
40: $this->setId('sales_order_create_search_grid');
41: $this->setRowClickCallback('order.productGridRowClick.bind(order)');
42: $this->setCheckboxCheckCallback('order.productGridCheckboxCheck.bind(order)');
43: $this->setRowInitCallback('order.productGridRowInit.bind(order)');
44: $this->setDefaultSort('entity_id');
45: $this->setUseAjax(true);
46: if ($this->getRequest()->getParam('collapse')) {
47: $this->setIsCollapsed(true);
48: }
49: }
50:
51: 52: 53: 54:
55: public function getStore()
56: {
57: return Mage::getSingleton('adminhtml/session_quote')->getStore();
58: }
59:
60: 61: 62: 63:
64: public function getQuote()
65: {
66: return Mage::getSingleton('adminhtml/session_quote')->getQuote();
67: }
68:
69: protected function _addColumnFilterToCollection($column)
70: {
71:
72: if ($column->getId() == 'in_products') {
73: $productIds = $this->_getSelectedProducts();
74: if (empty($productIds)) {
75: $productIds = 0;
76: }
77: if ($column->getFilter()->getValue()) {
78: $this->getCollection()->addFieldToFilter('entity_id', array('in'=>$productIds));
79: } else {
80: if($productIds) {
81: $this->getCollection()->addFieldToFilter('entity_id', array('nin'=>$productIds));
82: }
83: }
84: } else {
85: parent::_addColumnFilterToCollection($column);
86: }
87: return $this;
88: }
89:
90: 91: 92: 93: 94:
95: protected function _prepareCollection()
96: {
97: $attributes = Mage::getSingleton('catalog/config')->getProductAttributes();
98:
99: $collection = Mage::getModel('catalog/product')->getCollection();
100: $collection
101: ->setStore($this->getStore())
102: ->addAttributeToSelect($attributes)
103: ->addAttributeToSelect('sku')
104: ->addStoreFilter()
105: ->addAttributeToFilter('type_id', array_keys(
106: Mage::getConfig()->getNode('adminhtml/sales/order/create/available_product_types')->asArray()
107: ))
108: ->addAttributeToSelect('gift_message_available');
109:
110: Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($collection);
111:
112: $this->setCollection($collection);
113: return parent::_prepareCollection();
114: }
115:
116: 117: 118: 119: 120:
121: protected function _prepareColumns()
122: {
123: $this->addColumn('entity_id', array(
124: 'header' => Mage::helper('sales')->__('ID'),
125: 'sortable' => true,
126: 'width' => '60',
127: 'index' => 'entity_id'
128: ));
129: $this->addColumn('name', array(
130: 'header' => Mage::helper('sales')->__('Product Name'),
131: 'renderer' => 'adminhtml/sales_order_create_search_grid_renderer_product',
132: 'index' => 'name'
133: ));
134: $this->addColumn('sku', array(
135: 'header' => Mage::helper('sales')->__('SKU'),
136: 'width' => '80',
137: 'index' => 'sku'
138: ));
139: $this->addColumn('price', array(
140: 'header' => Mage::helper('sales')->__('Price'),
141: 'column_css_class' => 'price',
142: 'align' => 'center',
143: 'type' => 'currency',
144: 'currency_code' => $this->getStore()->getCurrentCurrencyCode(),
145: 'rate' => $this->getStore()->getBaseCurrency()->getRate($this->getStore()->getCurrentCurrencyCode()),
146: 'index' => 'price',
147: 'renderer' => 'adminhtml/sales_order_create_search_grid_renderer_price',
148: ));
149:
150: $this->addColumn('in_products', array(
151: 'header' => Mage::helper('sales')->__('Select'),
152: 'header_css_class' => 'a-center',
153: 'type' => 'checkbox',
154: 'name' => 'in_products',
155: 'values' => $this->_getSelectedProducts(),
156: 'align' => 'center',
157: 'index' => 'entity_id',
158: 'sortable' => false,
159: ));
160:
161: $this->addColumn('qty', array(
162: 'filter' => false,
163: 'sortable' => false,
164: 'header' => Mage::helper('sales')->__('Qty To Add'),
165: 'renderer' => 'adminhtml/sales_order_create_search_grid_renderer_qty',
166: 'name' => 'qty',
167: 'inline_css'=> 'qty',
168: 'align' => 'center',
169: 'type' => 'input',
170: 'validate_class' => 'validate-number',
171: 'index' => 'qty',
172: 'width' => '1',
173: ));
174:
175: return parent::_prepareColumns();
176: }
177:
178: public function getGridUrl()
179: {
180: return $this->getUrl('*/*/loadBlock', array('block'=>'search_grid', '_current' => true, 'collapse' => null));
181: }
182:
183: protected function _getSelectedProducts()
184: {
185: $products = $this->getRequest()->getPost('products', array());
186:
187: return $products;
188: }
189:
190: 191: 192: 193: 194: 195:
196: protected function _getGiftmessageSaveModel()
197: {
198: return Mage::getSingleton('adminhtml/giftmessage_save');
199: }
200:
201: 202: 203: 204: 205:
206: protected function _afterLoadCollection() {
207: $this->getCollection()->addOptionsToResult();
208: return parent::_afterLoadCollection();
209: }
210: }
211: