Grid.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Review\Block\Adminhtml\Product;
  7. /**
  8. * Adminhtml product grid block
  9. *
  10. * @author Magento Core Team <core@magentocommerce.com>
  11. * @SuppressWarnings(PHPMD.DepthOfInheritance)
  12. */
  13. class Grid extends \Magento\Catalog\Block\Adminhtml\Product\Grid
  14. {
  15. /**
  16. * Website collection
  17. *
  18. * @var \Magento\Store\Model\ResourceModel\Website\CollectionFactory
  19. */
  20. protected $_websitesFactory;
  21. /**
  22. * @param \Magento\Backend\Block\Template\Context $context
  23. * @param \Magento\Backend\Helper\Data $backendHelper
  24. * @param \Magento\Store\Model\WebsiteFactory $websiteFactory
  25. * @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory $setsFactory
  26. * @param \Magento\Catalog\Model\ProductFactory $productFactory
  27. * @param \Magento\Catalog\Model\Product\Type $type
  28. * @param \Magento\Catalog\Model\Product\Attribute\Source\Status $status
  29. * @param \Magento\Catalog\Model\Product\Visibility $visibility
  30. * @param \Magento\Framework\Module\Manager $moduleManager
  31. * @param \Magento\Store\Model\ResourceModel\Website\CollectionFactory $websitesFactory
  32. * @param array $data
  33. *
  34. * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  35. */
  36. public function __construct(
  37. \Magento\Backend\Block\Template\Context $context,
  38. \Magento\Backend\Helper\Data $backendHelper,
  39. \Magento\Store\Model\WebsiteFactory $websiteFactory,
  40. \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory $setsFactory,
  41. \Magento\Catalog\Model\ProductFactory $productFactory,
  42. \Magento\Catalog\Model\Product\Type $type,
  43. \Magento\Catalog\Model\Product\Attribute\Source\Status $status,
  44. \Magento\Catalog\Model\Product\Visibility $visibility,
  45. \Magento\Framework\Module\Manager $moduleManager,
  46. \Magento\Store\Model\ResourceModel\Website\CollectionFactory $websitesFactory,
  47. array $data = []
  48. ) {
  49. $this->_websitesFactory = $websitesFactory;
  50. parent::__construct(
  51. $context,
  52. $backendHelper,
  53. $websiteFactory,
  54. $setsFactory,
  55. $productFactory,
  56. $type,
  57. $status,
  58. $visibility,
  59. $moduleManager,
  60. $data
  61. );
  62. }
  63. /**
  64. * Initialize review
  65. *
  66. * @return void
  67. */
  68. protected function _construct()
  69. {
  70. parent::_construct();
  71. $this->setRowClickCallback('review.gridRowClick');
  72. $this->setUseAjax(true);
  73. }
  74. /**
  75. * Prepare product review grid
  76. *
  77. * @return void
  78. */
  79. protected function _prepareColumns()
  80. {
  81. $this->addColumn(
  82. 'entity_id',
  83. [
  84. 'header' => __('ID'),
  85. 'index' => 'entity_id',
  86. 'header_css_class' => 'col-id',
  87. 'column_css_class' => 'col-id'
  88. ]
  89. );
  90. $this->addColumn('name', ['header' => __('Name'), 'index' => 'name']);
  91. if ((int)$this->getRequest()->getParam('store', 0)) {
  92. $this->addColumn('custom_name', ['header' => __('Product Store Name'), 'index' => 'custom_name']);
  93. }
  94. $this->addColumn('sku', ['header' => __('SKU'), 'index' => 'sku']);
  95. $this->addColumn('price', ['header' => __('Price'), 'type' => 'currency', 'index' => 'price']);
  96. $this->addColumn(
  97. 'qty',
  98. ['header' => __('Quantity'), 'type' => 'number', 'index' => 'qty']
  99. );
  100. $this->addColumn(
  101. 'status',
  102. [
  103. 'header' => __('Status'),
  104. 'index' => 'status',
  105. 'type' => 'options',
  106. 'source' => \Magento\Catalog\Model\Product\Attribute\Source\Status::class,
  107. 'options' => $this->_status->getOptionArray()
  108. ]
  109. );
  110. /**
  111. * Check is single store mode
  112. */
  113. if (!$this->_storeManager->isSingleStoreMode()) {
  114. $this->addColumn(
  115. 'websites',
  116. [
  117. 'header' => __('Websites'),
  118. 'sortable' => false,
  119. 'index' => 'websites',
  120. 'type' => 'options',
  121. 'options' => $this->_websitesFactory->create()->toOptionHash()
  122. ]
  123. );
  124. }
  125. }
  126. /**
  127. * Get catalog product grid url
  128. *
  129. * @return string
  130. */
  131. public function getGridUrl()
  132. {
  133. return $this->getUrl('review/product/productGrid', ['_current' => true]);
  134. }
  135. /**
  136. * Get catalog product row url
  137. *
  138. * @param \Magento\Framework\DataObject $row
  139. * @return string
  140. */
  141. public function getRowUrl($row)
  142. {
  143. return $this->getUrl('review/product/jsonProductInfo', ['id' => $row->getId()]);
  144. }
  145. /**
  146. * Prepare mass action
  147. *
  148. * @return $this
  149. */
  150. protected function _prepareMassaction()
  151. {
  152. return $this;
  153. }
  154. }