PageRenderTime 50ms CodeModel.GetById 7ms RepoModel.GetById 1ms app.codeStats 0ms

/app/code/local/Magiccart/Shopbrand/Block/Adminhtml/Brand/Grid.php

https://gitlab.com/blingbang2016/shop
PHP | 154 lines | 135 code | 19 blank | 0 comment | 5 complexity | ad40e028707d23f5a56741273bfbd690 MD5 | raw file
  1. <?php
  2. class Magiccart_Shopbrand_Block_Adminhtml_Brand_Grid extends Mage_Adminhtml_Block_Widget_Grid
  3. {
  4. public function __construct()
  5. {
  6. parent::__construct();
  7. $this->setId('brandGrid');
  8. $this->setDefaultSort('brand_id');
  9. $this->setDefaultDir('ASC');
  10. $this->setSaveParametersInSession(true);
  11. }
  12. public function _prepareCollection() // Convert string stores id
  13. {
  14. $collection = Mage::getModel('shopbrand/brand')->getCollection();
  15. foreach($collection as $link) {
  16. if($link->getStores() && $link->getStores() != 0 ){
  17. $link->setStores(explode(',',$link->getStores()));
  18. }
  19. else{
  20. $link->setStores(array('0'));
  21. }
  22. }
  23. $this->setCollection($collection);
  24. return parent::_prepareCollection();
  25. }
  26. protected function _filterStoreCondition($collection, $column){
  27. if (!$value = $column->getFilter()->getValue()) {
  28. return;
  29. }
  30. $this->getCollection()->addStoreFilter($value);
  31. }
  32. public function _prepareColumns()
  33. {
  34. $this->addColumn('brand_id', array(
  35. 'header' => Mage::helper('shopbrand')->__('ID'),
  36. 'align' => 'right',
  37. 'width' => '50px',
  38. 'index' =>'brand_id',
  39. ));
  40. $this->addColumn('title', array(
  41. 'header' => Mage::helper('shopbrand')->__('Title'),
  42. 'align' => 'left',
  43. 'index' => 'title',
  44. ));
  45. $this->addColumn('urlkey', array(
  46. 'header' => Mage::helper('shopbrand')->__('URL Key'),
  47. 'align' => 'left',
  48. 'index' => 'urlkey',
  49. ));
  50. $this->addColumn('image', array(
  51. 'header' => Mage::helper('shopbrand')->__('Brand Image'),
  52. 'align' => 'left',
  53. 'type' => 'image',
  54. 'renderer' => 'Magiccart_Shopbrand_Block_Adminhtml_Brand_Render_Image',
  55. 'widht' => 64,
  56. 'index' => 'image',
  57. ));
  58. if (!Mage::app()->isSingleStoreMode()) {
  59. $this->addColumn('stores', array(
  60. 'header' => Mage::helper('shopbrand')->__('Store View'),
  61. 'index' => 'stores',
  62. 'type' => 'store',
  63. 'store_all' => true,
  64. 'store_view' => true,
  65. 'sortable' => true,
  66. 'filter_condition_callback' => array($this,'_filterStoreCondition'),
  67. ));
  68. }
  69. $this->addColumn('porder', array(
  70. 'header' => Mage::helper('shopbrand')->__('Order'),
  71. 'width' => '50px',
  72. 'index' => 'order',
  73. ));
  74. $this->addColumn('status', array(
  75. 'header' => Mage::helper('shopbrand')->__('Status'),
  76. 'align' => '80px',
  77. 'index' => 'status',
  78. 'type' => 'options',
  79. 'options' => array(
  80. 1 => 'Enabled',
  81. 2 => 'Disable',
  82. ),
  83. ));
  84. $this->addColumn('action', array(
  85. 'header' => Mage::helper('shopbrand')->__('Action'),
  86. 'width' => '100px',
  87. 'type' => 'action',
  88. 'getter' => 'getId',
  89. 'actions' => array(
  90. array(
  91. 'caption' => Mage::helper('shopbrand')->__('Edit'),
  92. 'url' => array('base' => '*/*/edit'),
  93. 'field' => 'id'
  94. )
  95. ),
  96. 'filter' => false,
  97. 'sortable' => false,
  98. 'index' => 'stores',
  99. 'is_system' => true,
  100. ));
  101. $this->addExportType('*/*/exportCsv', Mage::helper('shopbrand')->__('CSV'));
  102. $this->addExportType('*/*/exportXml', Mage::helper('shopbrand')->__('XML'));
  103. return parent::_prepareColumns();
  104. }
  105. public function _prepareMassaction()
  106. {
  107. $this->setMassactionIdField('brand_id');
  108. $this->getMassactionBlock()->setFormFieldName('shopbrand');
  109. $this->getMassactionBlock()->addItem('delete', array(
  110. 'label' => Mage::helper('shopbrand')->__('Delete'),
  111. 'url' => $this->getUrl('*/*/massDelete'),
  112. 'confirm' => Mage::helper('shopbrand')->__('Are you sure?')
  113. ));
  114. $statuses = Mage::getSingleton('shopbrand/status')->getOptionArray(); // option Action for change status
  115. array_unshift($statuses, array('label' => '', 'value' => ''));
  116. $this->getMassactionBlock()->addItem('status', array(
  117. 'label' => Mage::helper('shopbrand')->__('Change status'),
  118. 'url' => $this->getUrl('*/*/massStatus', array('_current' => true)),
  119. 'additional'=> array(
  120. 'visibility' => array(
  121. 'name' => 'status',
  122. 'type' => 'select',
  123. 'class' => 'required-entry',
  124. 'label' => Mage::helper('shopbrand')->__('Status'),
  125. 'values'=> $statuses
  126. )
  127. )
  128. ));
  129. return $this;
  130. }
  131. public function getRowUrl($row)
  132. {
  133. return $this->getUrl('*/*/edit', array('id' => $row->getId()));
  134. }
  135. }