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_Catalog_Product_Edit_Tab_Upsell extends Mage_Adminhtml_Block_Widget_Grid
00035 {
00036
00037 public function __construct()
00038 {
00039 parent::__construct();
00040 $this->setId('up_sell_product_grid');
00041 $this->setDefaultSort('entity_id');
00042 $this->setUseAjax(true);
00043 if ($this->_getProduct()->getId()) {
00044 $this->setDefaultFilter(array('in_products'=>1));
00045 }
00046 }
00047
00048
00049
00050
00051
00052
00053 protected function _getProduct()
00054 {
00055 return Mage::registry('current_product');
00056 }
00057
00058 protected function _addColumnFilterToCollection($column)
00059 {
00060
00061 if ($column->getId() == 'in_products') {
00062 $productIds = $this->_getSelectedProducts();
00063 if (empty($productIds)) {
00064 $productIds = 0;
00065 }
00066 if ($column->getFilter()->getValue()) {
00067 $this->getCollection()->addFieldToFilter('entity_id', array('in'=>$productIds));
00068 }
00069 else {
00070 if($productIds) {
00071 $this->getCollection()->addFieldToFilter('entity_id', array('nin'=>$productIds));
00072 }
00073 }
00074 }
00075 else {
00076 parent::_addColumnFilterToCollection($column);
00077 }
00078 return $this;
00079 }
00080
00081
00082
00083
00084
00085
00086 public function isReadonly()
00087 {
00088 return $this->_getProduct()->getUpsellReadonly();
00089 }
00090
00091 protected function _prepareCollection()
00092 {
00093 $collection = Mage::getModel('catalog/product_link')->useUpSellLinks()
00094 ->getProductCollection()
00095 ->setProduct($this->_getProduct())
00096 ->addAttributeToSelect('*');
00097
00098 if ($this->isReadonly()) {
00099 $productIds = $this->_getSelectedProducts();
00100 if (empty($productIds)) {
00101 $productIds = array(0);
00102 }
00103 $collection->addFieldToFilter('entity_id', array('in'=>$productIds));
00104 }
00105
00106 $this->setCollection($collection);
00107 return parent::_prepareCollection();
00108 }
00109
00110 protected function _prepareColumns()
00111 {
00112 if (!$this->_getProduct()->getUpsellReadonly()) {
00113 $this->addColumn('in_products', array(
00114 'header_css_class' => 'a-center',
00115 'type' => 'checkbox',
00116 'name' => 'in_products',
00117 'values' => $this->_getSelectedProducts(),
00118 'align' => 'center',
00119 'index' => 'entity_id'
00120 ));
00121 }
00122
00123 $this->addColumn('entity_id', array(
00124 'header' => Mage::helper('catalog')->__('ID'),
00125 'sortable' => true,
00126 'width' => '60px',
00127 'index' => 'entity_id'
00128 ));
00129 $this->addColumn('name', array(
00130 'header' => Mage::helper('catalog')->__('Name'),
00131 'index' => 'name'
00132 ));
00133
00134 $this->addColumn('type',
00135 array(
00136 'header'=> Mage::helper('catalog')->__('Type'),
00137 'width' => '100px',
00138 'index' => 'type_id',
00139 'type' => 'options',
00140 'options' => Mage::getSingleton('catalog/product_type')->getOptionArray(),
00141 ));
00142
00143 $sets = Mage::getResourceModel('eav/entity_attribute_set_collection')
00144 ->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId())
00145 ->load()
00146 ->toOptionHash();
00147
00148 $this->addColumn('set_name',
00149 array(
00150 'header'=> Mage::helper('catalog')->__('Attrib. Set Name'),
00151 'width' => '130px',
00152 'index' => 'attribute_set_id',
00153 'type' => 'options',
00154 'options' => $sets,
00155 ));
00156
00157 $this->addColumn('status',
00158 array(
00159 'header'=> Mage::helper('catalog')->__('Status'),
00160 'width' => '90px',
00161 'index' => 'status',
00162 'type' => 'options',
00163 'options' => Mage::getSingleton('catalog/product_status')->getOptionArray(),
00164 ));
00165
00166 $this->addColumn('visibility',
00167 array(
00168 'header'=> Mage::helper('catalog')->__('Visibility'),
00169 'width' => '90px',
00170 'index' => 'visibility',
00171 'type' => 'options',
00172 'options' => Mage::getSingleton('catalog/product_visibility')->getOptionArray(),
00173 ));
00174
00175 $this->addColumn('sku', array(
00176 'header' => Mage::helper('catalog')->__('SKU'),
00177 'width' => '80px',
00178 'index' => 'sku'
00179 ));
00180 $this->addColumn('price', array(
00181 'header' => Mage::helper('catalog')->__('Price'),
00182 'type' => 'currency',
00183 'currency_code' => (string) Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE),
00184 'index' => 'price'
00185 ));
00186
00187 $this->addColumn('position', array(
00188 'header' => Mage::helper('catalog')->__('Position'),
00189 'name' => 'position',
00190 'type' => 'number',
00191 'width' => '60px',
00192 'validate_class' => 'validate-number',
00193 'index' => 'position',
00194 'editable' => !$this->_getProduct()->getUpsellReadonly(),
00195 'edit_only' => !$this->_getProduct()->getId()
00196 ));
00197
00198 return parent::_prepareColumns();
00199 }
00200
00201 public function getGridUrl()
00202 {
00203 return $this->_getData('grid_url') ? $this->_getData('grid_url') : $this->getUrl('*/*/upsell', array('_current'=>true));
00204 }
00205
00206 protected function _getSelectedProducts()
00207 {
00208 $products = $this->getRequest()->getPost('products', null);
00209 if (!is_array($products)) {
00210 $products = $this->_getProduct()->getUpSellProductIds();
00211 }
00212 return $products;
00213 }
00214
00215 }