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_Adminhtml_Block_Sales_Order_Create_Search_Grid extends Mage_Adminhtml_Block_Widget_Grid
00035 {
00036
00037 public function __construct()
00038 {
00039 parent::__construct();
00040 $this->setId('sales_order_create_search_grid');
00041 $this->setRowClickCallback('order.productGridRowClick.bind(order)');
00042 $this->setCheckboxCheckCallback('order.productGridCheckboxCheck.bind(order)');
00043 $this->setRowInitCallback('order.productGridRowInit.bind(order)');
00044 $this->setDefaultSort('entity_id');
00045 $this->setUseAjax(true);
00046 if ($this->getRequest()->getParam('collapse')) {
00047 $this->setIsCollapsed(true);
00048 }
00049 }
00050
00051
00052
00053
00054
00055 public function getStore()
00056 {
00057 return Mage::getSingleton('adminhtml/session_quote')->getStore();
00058 }
00059
00060
00061
00062
00063
00064 public function getQuote()
00065 {
00066 return Mage::getSingleton('adminhtml/session_quote')->getQuote();
00067 }
00068
00069 protected function _addColumnFilterToCollection($column)
00070 {
00071
00072 if ($column->getId() == 'in_products') {
00073 $productIds = $this->_getSelectedProducts();
00074 if (empty($productIds)) {
00075 $productIds = 0;
00076 }
00077 if ($column->getFilter()->getValue()) {
00078 $this->getCollection()->addFieldToFilter('entity_id', array('in'=>$productIds));
00079 } else {
00080 if($productIds) {
00081 $this->getCollection()->addFieldToFilter('entity_id', array('nin'=>$productIds));
00082 }
00083 }
00084 } else {
00085 parent::_addColumnFilterToCollection($column);
00086 }
00087 return $this;
00088 }
00089
00090 protected function _prepareCollection()
00091 {
00092 $collection = Mage::getModel('catalog/product')->getCollection()
00093 ->setStore($this->getStore())
00094 ->addAttributeToSelect('name')
00095 ->addAttributeToSelect('sku')
00096 ->addAttributeToSelect('price')
00097 ->addAttributeToFilter('type_id', array_keys(
00098 Mage::getConfig()->getNode('adminhtml/sales/order/create/available_product_types')->asArray()
00099 ))
00100 ->addStoreFilter();
00101
00102 if($this->helper('giftmessage/message')->getIsMessagesAvailable(
00103 'main', $this->getQuote(), $this->getStore()
00104 )) {
00105 $collection->addAttributeToSelect('gift_message_available');
00106 }
00107
00108 Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($collection);
00109
00110
00111
00112
00113
00114 $this->setCollection($collection);
00115
00116 return parent::_prepareCollection();
00117 }
00118
00119 protected function _prepareColumns()
00120 {
00121 $this->addColumn('entity_id', array(
00122 'header' => Mage::helper('sales')->__('ID'),
00123 'sortable' => true,
00124 'width' => '60',
00125 'index' => 'entity_id'
00126 ));
00127 $this->addColumn('name', array(
00128 'header' => Mage::helper('sales')->__('Product Name'),
00129 'index' => 'name'
00130 ));
00131 $this->addColumn('sku', array(
00132 'header' => Mage::helper('sales')->__('SKU'),
00133 'width' => '80',
00134 'index' => 'sku'
00135 ));
00136 $this->addColumn('price', array(
00137 'header' => Mage::helper('sales')->__('Price'),
00138 'align' => 'center',
00139 'type' => 'currency',
00140 'currency_code' => $this->getStore()->getCurrentCurrencyCode(),
00141 'rate' => $this->getStore()->getBaseCurrency()->getRate($this->getStore()->getCurrentCurrencyCode()),
00142 'index' => 'price'
00143 ));
00144
00145 $this->addColumn('in_products', array(
00146 'header_css_class' => 'a-center',
00147 'type' => 'checkbox',
00148 'name' => 'in_products',
00149 'values' => $this->_getSelectedProducts(),
00150 'align' => 'center',
00151 'index' => 'entity_id',
00152 ));
00153
00154 if($this->helper('giftmessage/message')->getIsMessagesAvailable(
00155 'items', $this->getQuote(), $this->getStore()
00156 )) {
00157 $this->addColumn('giftmessage', array(
00158 'filter' => false,
00159 'sortable' => false,
00160 'header' => Mage::helper('sales')->__('Gift'),
00161 'renderer' => 'adminhtml/sales_order_create_search_grid_renderer_giftmessage',
00162 'field_name'=> 'giftmessage',
00163 'inline_css'=> 'checkbox input-text',
00164 'align' => 'center',
00165 'index' => 'entity_id',
00166 'values' => $this->_getGiftmessageSaveModel()->getAllowQuoteItemsProducts(),
00167 'width' => '1',
00168 ));
00169 }
00170
00171 $this->addColumn('qty', array(
00172 'filter' => false,
00173 'sortable' => false,
00174 'header' => Mage::helper('sales')->__('Qty To Add'),
00175 'name' => 'qty',
00176 'inline_css'=> 'qty',
00177 'align' => 'right',
00178 'type' => 'input',
00179 'validate_class' => 'validate-number',
00180 'index' => 'qty',
00181 'width' => '1',
00182 ));
00183
00184 return parent::_prepareColumns();
00185 }
00186
00187 public function getGridUrl()
00188 {
00189 return $this->getUrl('*/*/loadBlock', array('block'=>'search_grid', '_current' => true, 'collapse' => null));
00190 }
00191
00192 protected function _getSelectedProducts()
00193 {
00194 $products = $this->getRequest()->getPost('products', array());
00195
00196 return $products;
00197 }
00198
00199
00200
00201
00202
00203
00204 protected function _getGiftmessageSaveModel()
00205 {
00206 return Mage::getSingleton('adminhtml/giftmessage_save');
00207 }
00208
00209 }
00210