Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Related Class Reference

Inheritance diagram for Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Related:

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 ()
 getGridUrl ()

Protected Member Functions

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


Detailed Description

Definition at line 34 of file Related.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 36 of file Related.php.

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


Member Function Documentation

_addColumnFilterToCollection ( column  )  [protected]

Reimplemented from Mage_Adminhtml_Block_Widget_Grid.

Definition at line 57 of file Related.php.

00058     {
00059         // Set custom filter for in product flag
00060         if ($column->getId() == 'in_products') {
00061             $productIds = $this->_getSelectedProducts();
00062             if (empty($productIds)) {
00063                 $productIds = 0;
00064             }
00065             if ($column->getFilter()->getValue()) {
00066                 $this->getCollection()->addFieldToFilter('entity_id', array('in'=>$productIds));
00067             }
00068             else {
00069                 if($productIds) {
00070                     $this->getCollection()->addFieldToFilter('entity_id', array('nin'=>$productIds));
00071                 }
00072             }
00073         }
00074         else {
00075             parent::_addColumnFilterToCollection($column);
00076         }
00077         return $this;
00078     }

_getProduct (  )  [protected]

Retirve currently edited product model

Returns:
Mage_Catalog_Model_Product

Definition at line 52 of file Related.php.

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

_getSelectedProducts (  )  [protected]

Definition at line 217 of file Related.php.

00218     {
00219         $products = $this->getRequest()->getPost('products', null);
00220         if (!is_array($products)) {
00221             $products = $this->_getProduct()->getRelatedProductIds();
00222         }
00223         return $products;
00224     }

_prepareCollection (  )  [protected]

Prepare grid collection object

Returns:
this

Reimplemented from Mage_Adminhtml_Block_Widget_Grid.

Definition at line 80 of file Related.php.

00081     {
00082         $collection = Mage::getModel('catalog/product_link')->useRelatedLinks()
00083             ->getProductCollection()
00084             ->setProduct($this->_getProduct())
00085             ->addAttributeToSelect('*');
00086 
00087         if ($this->isReadonly()) {
00088             $productIds = $this->_getSelectedProducts();
00089             if (empty($productIds)) {
00090                 $productIds = array(0);
00091             }
00092             $collection->addFieldToFilter('entity_id', array('in'=>$productIds));
00093         }
00094 
00095         $this->setCollection($collection);
00096         return parent::_prepareCollection();
00097     }

_prepareColumns (  )  [protected]

Reimplemented from Mage_Adminhtml_Block_Widget_Grid.

Definition at line 110 of file Related.php.

00111     {
00112         if (!$this->isReadonly()) {
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('qty', array(
00188             'header'    => Mage::helper('catalog')->__('Default Qty'),
00189             'name'      => 'qty',
00190             'align'     => 'center',
00191             'type'      => 'number',
00192             'validate_class' => 'validate-number',
00193             'index'     => 'qty',
00194             'width'     => '60px',
00195             'editable'  => true
00196         ));*/
00197 
00198         $this->addColumn('position', array(
00199             'header'    => Mage::helper('catalog')->__('Position'),
00200             'name'      => 'position',
00201             'type'      => 'number',
00202             'validate_class' => 'validate-number',
00203             'index'     => 'position',
00204             'width'     => '60px',
00205             'editable'  => !$this->isReadonly(),
00206             'edit_only' => !$this->_getProduct()->getId()
00207         ));
00208 
00209         return parent::_prepareColumns();
00210     }

getGridUrl (  ) 

Reimplemented from Mage_Adminhtml_Block_Widget_Grid.

Definition at line 212 of file Related.php.

00213     {
00214         return $this->getData('grid_url') ? $this->getData('grid_url') : $this->getUrl('*/*/related', array('_current'=>true));
00215     }

isReadonly (  ) 

Checks when this block is readonly

Returns:
boolean

Definition at line 104 of file Related.php.

00105     {
00106         return $this->_getProduct()->getRelatedReadonly();
00107     }


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