Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Config_Grid Class Reference

Inheritance diagram for Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Config_Grid:

Mage_Adminhtml_Block_Widget_Grid Mage_Adminhtml_Block_Widget Mage_Adminhtml_Block_Template Mage_Core_Block_Template Mage_Core_Block_Abstract Varien_Object

List of all members.

Public Member Functions

 __construct ()
 isReadonly ()
 getEditParamsForAssociated ()
 getOptions ($attribute)
 getGridUrl ()

Protected Member Functions

 _getProduct ()
 _addColumnFilterToCollection ($column)
 _getCreatedProducts ()
 _prepareCollection ()
 _getSelectedProducts ()
 _prepareColumns ()
 _getRequiredAttributesIds ()


Detailed Description

Definition at line 34 of file Grid.php.


Constructor & Destructor Documentation

__construct (  ) 

Constructor

By default is looking for first argument as array and assignes it as object attributes This behaviour may change in child classes

Reimplemented from Varien_Object.

Definition at line 37 of file Grid.php.

00038     {
00039         parent::__construct();
00040         $this->setUseAjax(true);
00041         $this->setId('super_product_links');
00042 
00043         if ($this->_getProduct()->getId()) {
00044             $this->setDefaultFilter(array('in_products'=>1));
00045         }
00046     }


Member Function Documentation

_addColumnFilterToCollection ( column  )  [protected]

Reimplemented from Mage_Adminhtml_Block_Widget_Grid.

Definition at line 58 of file Grid.php.

00059     {
00060         // Set custom filter for in product flag
00061         if ($column->getId() == 'in_products') {
00062             $productIds = $this->_getSelectedProducts();
00063 
00064             if (empty($productIds)) {
00065                 $productIds = 0;
00066             }
00067 
00068             $createdProducts = $this->_getCreatedProducts();
00069 
00070             $existsProducts = $productIds; // Only for "Yes" Filter we will add created products
00071 
00072             if(count($createdProducts)>0) {
00073                 if(!is_array($existsProducts)) {
00074                     $existsProducts = $createdProducts;
00075                 } else {
00076                     $existsProducts = array_merge($createdProducts);
00077                 }
00078             }
00079 
00080             if ($column->getFilter()->getValue()) {
00081                 $this->getCollection()->addFieldToFilter('entity_id', array('in'=>$existsProducts));
00082             }
00083             else {
00084                 if($productIds) {
00085                     $this->getCollection()->addFieldToFilter('entity_id', array('nin'=>$productIds));
00086                 }
00087             }
00088         }
00089         else {
00090             parent::_addColumnFilterToCollection($column);
00091         }
00092         return $this;
00093     }

_getCreatedProducts (  )  [protected]

Definition at line 95 of file Grid.php.

00096     {
00097         $products = $this->getRequest()->getPost('new_products', null);
00098         if (!is_array($products)) {
00099             $products = array();
00100         }
00101 
00102         return $products;
00103     }

_getProduct (  )  [protected]

Retrieve currently edited product object

Returns:
Mage_Catalog_Model_Product

Definition at line 53 of file Grid.php.

00054     {
00055         return Mage::registry('current_product');
00056     }

_getRequiredAttributesIds (  )  [protected]

Definition at line 266 of file Grid.php.

00267     {
00268         $attributesIds = array();
00269         foreach ($this->_getProduct()->getTypeInstance(true)->getConfigurableAttributes($this->_getProduct()) as $attribute) {
00270             $attributesIds[] = $attribute->getProductAttribute()->getId();
00271         }
00272 
00273         return implode(',', $attributesIds);
00274     }

_getSelectedProducts (  )  [protected]

Definition at line 140 of file Grid.php.

00141     {
00142         $products = $this->getRequest()->getPost('products', null);
00143         if (!is_array($products)) {
00144             $products = $this->_getProduct()->getTypeInstance(true)->getUsedProductIds($this->_getProduct());
00145         }
00146         return $products;
00147     }

_prepareCollection (  )  [protected]

Prepare grid collection object

Returns:
this

Reimplemented from Mage_Adminhtml_Block_Widget_Grid.

Definition at line 105 of file Grid.php.

00106     {
00107         $allowProductTypes = array();
00108         foreach (Mage::getConfig()->getNode('global/catalog/product/type/configurable/allow_product_types')->children() as $type) {
00109             $allowProductTypes[] = $type->getName();
00110         }
00111 
00112         $product = $this->_getProduct();
00113         $collection = $product->getCollection()
00114             ->addAttributeToSelect('name')
00115             ->addAttributeToSelect('sku')
00116             ->addAttributeToSelect('attribute_set_id')
00117             ->addAttributeToSelect('type_id')
00118             ->addAttributeToSelect('price')
00119             ->addFieldToFilter('attribute_set_id',$product->getAttributeSetId())
00120             ->addFieldToFilter('type_id', $allowProductTypes)
00121             ->addFilterByRequiredOptions();
00122 
00123         Mage::getModel('cataloginventory/stock_item')->addCatalogInventoryToProductCollection($collection);
00124 
00125         foreach ($product->getTypeInstance(true)->getUsedProductAttributes($product) as $attribute) {
00126             $collection->addAttributeToSelect($attribute->getAttributeCode());
00127             $collection->addAttributeToFilter($attribute->getAttributeCode(), array('nin'=>array(null)));
00128         }
00129 
00130         $this->setCollection($collection);
00131 
00132         if ($this->isReadonly()) {
00133             $collection->addFieldToFilter('entity_id', array('in' => $this->_getSelectedProducts()));
00134         }
00135 
00136         parent::_prepareCollection();
00137         return $this;
00138     }

_prepareColumns (  )  [protected]

Reimplemented from Mage_Adminhtml_Block_Widget_Grid.

Definition at line 159 of file Grid.php.

00160     {
00161         $product = $this->_getProduct();
00162         $attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);
00163 
00164         if (!$this->isReadonly()) {
00165             $this->addColumn('in_products', array(
00166                 'header_css_class' => 'a-center',
00167                 'type'      => 'checkbox',
00168                 'name'      => 'in_products',
00169                 'values'    => $this->_getSelectedProducts(),
00170                 'align'     => 'center',
00171                 'index'     => 'entity_id',
00172                 'renderer'  => 'adminhtml/catalog_product_edit_tab_super_config_grid_renderer_checkbox',
00173                 'attributes' => $attributes
00174             ));
00175         }
00176 
00177         $this->addColumn('entity_id', array(
00178             'header'    => Mage::helper('catalog')->__('ID'),
00179             'sortable'  => true,
00180             'width'     => '60px',
00181             'index'     => 'entity_id'
00182         ));
00183         $this->addColumn('name', array(
00184             'header'    => Mage::helper('catalog')->__('Name'),
00185             'index'     => 'name'
00186         ));
00187 
00188 
00189         $sets = Mage::getModel('eav/entity_attribute_set')->getCollection()
00190             ->setEntityTypeFilter($this->_getProduct()->getResource()->getTypeId())
00191             ->load()
00192             ->toOptionHash();
00193 
00194         $this->addColumn('set_name',
00195             array(
00196                 'header'=> Mage::helper('catalog')->__('Attrib. Set Name'),
00197                 'width' => '130px',
00198                 'index' => 'attribute_set_id',
00199                 'type'  => 'options',
00200                 'options' => $sets,
00201         ));
00202 
00203         $this->addColumn('sku', array(
00204             'header'    => Mage::helper('catalog')->__('SKU'),
00205             'width'     => '80px',
00206             'index'     => 'sku'
00207         ));
00208 
00209         $this->addColumn('price', array(
00210             'header'    => Mage::helper('catalog')->__('Price'),
00211             'type'      => 'currency',
00212             'currency_code' => (string) Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE),
00213             'index'     => 'price'
00214         ));
00215 
00216         $this->addColumn('is_saleable', array(
00217             'header'    => Mage::helper('catalog')->__('Inventory'),
00218             'renderer'  => 'adminhtml/catalog_product_edit_tab_super_config_grid_renderer_inventory',
00219             'filter'    => 'adminhtml/catalog_product_edit_tab_super_config_grid_filter_inventory',
00220             'index'     => 'is_saleable'
00221         ));
00222 
00223         foreach ($attributes as $attribute) {
00224             $productAttribute = $attribute->getProductAttribute();
00225             $productAttribute->getSource();
00226             $this->addColumn($productAttribute->getAttributeCode(), array(
00227                 'header'    => $productAttribute->getFrontend()->getLabel(),
00228                 'index'     => $productAttribute->getAttributeCode(),
00229                 'type'      => $productAttribute->getSourceModel() ? 'options' : 'number',
00230                 'options'   => $productAttribute->getSourceModel() ? $this->getOptions($attribute) : ''
00231             ));
00232         }
00233 
00234          $this->addColumn('action',
00235             array(
00236                 'header'    => Mage::helper('catalog')->__('Action'),
00237                 'type'      => 'action',
00238                 'getter'     => 'getId',
00239                 'actions'   => array(
00240                     array(
00241                         'caption' => Mage::helper('catalog')->__('Edit'),
00242                         'url'     => $this->getEditParamsForAssociated(),
00243                         'field'   => 'id',
00244                         'onclick'  => 'superProduct.createPopup(this.href);return false;'
00245                     )
00246                 ),
00247                 'filter'    => false,
00248                 'sortable'  => false
00249         ));
00250 
00251         return parent::_prepareColumns();
00252     }

getEditParamsForAssociated (  ) 

Definition at line 254 of file Grid.php.

00255     {
00256         return array(
00257             'base'      =>  '*/*/edit',
00258             'params'    =>  array(
00259                 'required' => $this->_getRequiredAttributesIds(),
00260                 'popup'    => 1,
00261                 'product'  => $this->_getProduct()->getId()
00262             )
00263         );
00264     }

getGridUrl (  ) 

Reimplemented from Mage_Adminhtml_Block_Widget_Grid.

Definition at line 287 of file Grid.php.

00288     {
00289         return $this->getUrl('*/*/superConfig', array('_current'=>true));
00290     }

getOptions ( attribute  ) 

Definition at line 276 of file Grid.php.

00276                                            {
00277         $result = array();
00278         foreach ($attribute->getProductAttribute()->getSource()->getAllOptions() as $option) {
00279             if($option['value']!='') {
00280                 $result[$option['value']] = $option['label'];
00281             }
00282         }
00283 
00284         return $result;
00285     }

isReadonly (  ) 

Check block is readonly

Returns:
boolean

Definition at line 154 of file Grid.php.

00155     {
00156          return $this->_getProduct()->getCompositeReadonly();
00157     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:22:45 2009 for Magento by  doxygen 1.5.8