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_Promo_Widget_Chooser_Sku extends Mage_Adminhtml_Block_Widget_Grid
00035 {
00036
00037 public function __construct($arguments=array())
00038 {
00039 parent::__construct($arguments);
00040
00041 if ($this->getRequest()->getParam('current_grid_id')) {
00042 $this->setId($this->getRequest()->getParam('current_grid_id'));
00043 } else {
00044 $this->setId('skuChooserGrid_'.$this->getId());
00045 }
00046
00047 $form = $this->getJsFormObject();
00048 $this->setRowClickCallback("$form.chooserGridRowClick.bind($form)");
00049 $this->setCheckboxCheckCallback("$form.chooserGridCheckboxCheck.bind($form)");
00050 $this->setRowInitCallback("$form.chooserGridRowInit.bind($form)");
00051 $this->setDefaultSort('sku');
00052 $this->setUseAjax(true);
00053 if ($this->getRequest()->getParam('collapse')) {
00054 $this->setIsCollapsed(true);
00055 }
00056 }
00057
00058
00059
00060
00061
00062 public function getStore()
00063 {
00064 return Mage::app()->getStore();
00065 }
00066
00067 protected function _addColumnFilterToCollection($column)
00068 {
00069
00070 if ($column->getId() == 'in_products') {
00071 $selected = $this->_getSelectedProducts();
00072 if (empty($selected)) {
00073 $selected = '';
00074 }
00075 if ($column->getFilter()->getValue()) {
00076 $this->getCollection()->addFieldToFilter('sku', array('in'=>$selected));
00077 } else {
00078 $this->getCollection()->addFieldToFilter('sku', array('nin'=>$selected));
00079 }
00080 } else {
00081 parent::_addColumnFilterToCollection($column);
00082 }
00083 return $this;
00084 }
00085
00086 protected function _prepareCollection()
00087 {
00088 $collection = Mage::getResourceModel('catalog/product_collection')
00089 ->setStoreId(0)
00090 ->addAttributeToSelect('name')
00091 ->addAttributeToFilter('type_id', array('in'=>array(
00092 Mage_Catalog_Model_Product_Type::TYPE_SIMPLE,
00093 Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE,
00094 Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE
00095 )));
00096
00097 $this->setCollection($collection);
00098
00099 return parent::_prepareCollection();
00100 }
00101
00102 protected function _prepareColumns()
00103 {
00104 $this->addColumn('in_products', array(
00105 'header_css_class' => 'a-center',
00106 'type' => 'checkbox',
00107 'name' => 'in_products',
00108 'values' => $this->_getSelectedProducts(),
00109 'align' => 'center',
00110 'index' => 'sku',
00111 'use_index' => true,
00112 ));
00113
00114 $this->addColumn('entity_id', array(
00115 'header' => Mage::helper('sales')->__('ID'),
00116 'sortable' => true,
00117 'width' => '60px',
00118 'index' => 'entity_id'
00119 ));
00120
00121 $this->addColumn('chooser_sku', array(
00122 'header' => Mage::helper('sales')->__('SKU'),
00123 'name' => 'chooser_sku',
00124 'width' => '80px',
00125 'index' => 'sku'
00126 ));
00127 $this->addColumn('chooser_name', array(
00128 'header' => Mage::helper('sales')->__('Product Name'),
00129 'name' => 'chooser_name',
00130 'index' => 'name'
00131 ));
00132
00133 return parent::_prepareColumns();
00134 }
00135
00136 public function getGridUrl()
00137 {
00138 return $this->getUrl('*/*/chooser', array(
00139 '_current' => true,
00140 'current_grid_id' => $this->getId(),
00141 'collapse' => null
00142 ));
00143 }
00144
00145 protected function _getSelectedProducts()
00146 {
00147 $products = $this->getRequest()->getPost('selected', array());
00148
00149 return $products;
00150 }
00151
00152 }
00153