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_Super_Group extends Mage_Adminhtml_Block_Widget_Grid implements Mage_Adminhtml_Block_Widget_Tab_Interface
00035 {
00036 public function __construct()
00037 {
00038 parent::__construct();
00039 $this->setId('super_product_grid');
00040 $this->setDefaultSort('entity_id');
00041 $this->setSkipGenerateContent(true);
00042 $this->setUseAjax(true);
00043 if ($this->_getProduct()->getId()) {
00044 $this->setDefaultFilter(array('in_products'=>1));
00045 }
00046 }
00047
00048 public function getTabUrl()
00049 {
00050 return $this->getUrl('*/*/superGroup', array('_current'=>true));
00051 }
00052
00053 public function getTabClass()
00054 {
00055 return 'ajax';
00056 }
00057
00058
00059
00060
00061
00062
00063 protected function _getProduct()
00064 {
00065 return Mage::registry('current_product');
00066 }
00067
00068 protected function _addColumnFilterToCollection($column)
00069 {
00070
00071 if ($column->getId() == 'in_products') {
00072 $productIds = $this->_getSelectedProducts();
00073 if (empty($productIds)) {
00074 $productIds = 0;
00075 }
00076 if ($column->getFilter()->getValue()) {
00077 $this->getCollection()->addFieldToFilter('entity_id', array('in'=>$productIds));
00078 }
00079 else {
00080 $this->getCollection()->addFieldToFilter('entity_id', array('nin'=>$productIds));
00081 }
00082 }
00083 else {
00084 parent::_addColumnFilterToCollection($column);
00085 }
00086
00087 return $this;
00088 }
00089
00090 protected function _prepareCollection()
00091 {
00092 $allowProductTypes = array();
00093 foreach (Mage::getConfig()->getNode('global/catalog/product/type/grouped/allow_product_types')->children() as $type) {
00094 $allowProductTypes[] = $type->getName();
00095 }
00096
00097 $collection = Mage::getModel('catalog/product_link')->useGroupedLinks()
00098 ->getProductCollection()
00099 ->setProduct($this->_getProduct())
00100 ->addAttributeToSelect('*')
00101 ->addFilterByRequiredOptions()
00102 ->addAttributeToFilter('type_id', $allowProductTypes);
00103
00104 $this->setCollection($collection);
00105 return parent::_prepareCollection();
00106 }
00107
00108 protected function _prepareColumns()
00109 {
00110 $this->addColumn('in_products', array(
00111 'header_css_class' => 'a-center',
00112 'type' => 'checkbox',
00113 'name' => 'in_products',
00114 'values' => $this->_getSelectedProducts(),
00115 'align' => 'center',
00116 'index' => 'entity_id'
00117 ));
00118
00119 $this->addColumn('entity_id', array(
00120 'header' => Mage::helper('catalog')->__('ID'),
00121 'sortable' => true,
00122 'width' => '60px',
00123 'index' => 'entity_id'
00124 ));
00125 $this->addColumn('name', array(
00126 'header' => Mage::helper('catalog')->__('Name'),
00127 'index' => 'name'
00128 ));
00129 $this->addColumn('sku', array(
00130 'header' => Mage::helper('catalog')->__('SKU'),
00131 'width' => '80px',
00132 'index' => 'sku'
00133 ));
00134 $this->addColumn('price', array(
00135 'header' => Mage::helper('catalog')->__('Price'),
00136 'type' => 'currency',
00137 'currency_code' => (string) Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE),
00138 'index' => 'price'
00139 ));
00140
00141 $this->addColumn('qty', array(
00142 'header' => Mage::helper('catalog')->__('Default Qty'),
00143 'name' => 'qty',
00144 'type' => 'number',
00145 'validate_class' => 'validate-number',
00146 'index' => 'qty',
00147 'width' => '1',
00148 'editable' => true
00149 ));
00150
00151 $this->addColumn('position', array(
00152 'header' => Mage::helper('catalog')->__('Position'),
00153 'name' => 'position',
00154 'type' => 'number',
00155 'validate_class' => 'validate-number',
00156 'index' => 'position',
00157 'width' => '1',
00158 'editable' => true,
00159 'edit_only' => !$this->_getProduct()->getId()
00160 ));
00161
00162 return parent::_prepareColumns();
00163 }
00164
00165 public function getGridUrl()
00166 {
00167 return $this->_getData('grid_url') ? $this->_getData('grid_url') : $this->getUrl('*/*/superGroup', array('_current'=>true));
00168 }
00169
00170 protected function _getSelectedProducts()
00171 {
00172 $products = $this->getRequest()->getPost('products', null);
00173 if (!is_array($products)) {
00174 $products = $this->_getProduct()->getTypeInstance(true)->getAssociatedProductIds($this->_getProduct());
00175 }
00176 return $products;
00177 }
00178
00179 public function getTabLabel()
00180 {
00181 return Mage::helper('catalog')->__('Associated Products');
00182 }
00183 public function getTabTitle()
00184 {
00185 return Mage::helper('catalog')->__('Associated Products');
00186 }
00187 public function canShowTab()
00188 {
00189 return true;
00190 }
00191 public function isHidden()
00192 {
00193 return false;
00194 }
00195 }