Grid.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Reports\Block\Adminhtml\Sales\Bestsellers;
  7. /**
  8. * Adminhtml bestsellers report grid block
  9. *
  10. * @author Magento Core Team <core@magentocommerce.com>
  11. * @SuppressWarnings(PHPMD.DepthOfInheritance)
  12. */
  13. class Grid extends \Magento\Reports\Block\Adminhtml\Grid\AbstractGrid
  14. {
  15. /**
  16. * GROUP BY criteria
  17. *
  18. * @var string
  19. */
  20. protected $_columnGroupBy = 'period';
  21. /**
  22. * {@inheritdoc}
  23. * @codeCoverageIgnore
  24. */
  25. protected function _construct()
  26. {
  27. parent::_construct();
  28. $this->setCountTotals(true);
  29. }
  30. /**
  31. * {@inheritdoc}
  32. * @codeCoverageIgnore
  33. */
  34. public function getResourceCollectionName()
  35. {
  36. return \Magento\Sales\Model\ResourceModel\Report\Bestsellers\Collection::class;
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. protected function _prepareColumns()
  42. {
  43. $this->addColumn(
  44. 'period',
  45. [
  46. 'header' => __('Interval'),
  47. 'index' => 'period',
  48. 'sortable' => false,
  49. 'period_type' => $this->getPeriodType(),
  50. 'renderer' => \Magento\Reports\Block\Adminhtml\Sales\Grid\Column\Renderer\Date::class,
  51. 'totals_label' => __('Total'),
  52. 'html_decorators' => ['nobr'],
  53. 'header_css_class' => 'col-period',
  54. 'column_css_class' => 'col-period'
  55. ]
  56. );
  57. $this->addColumn(
  58. 'product_name',
  59. [
  60. 'header' => __('Product'),
  61. 'index' => 'product_name',
  62. 'type' => 'string',
  63. 'sortable' => false,
  64. 'header_css_class' => 'col-product',
  65. 'column_css_class' => 'col-product'
  66. ]
  67. );
  68. if ($this->getFilterData()->getStoreIds()) {
  69. $this->setStoreIds(explode(',', $this->getFilterData()->getStoreIds()));
  70. }
  71. $currencyCode = $this->getCurrentCurrencyCode();
  72. $this->addColumn(
  73. 'product_price',
  74. [
  75. 'header' => __('Price'),
  76. 'type' => 'currency',
  77. 'currency_code' => $currencyCode,
  78. 'index' => 'product_price',
  79. 'sortable' => false,
  80. 'rate' => $this->getRate($currencyCode),
  81. 'header_css_class' => 'col-price',
  82. 'column_css_class' => 'col-price'
  83. ]
  84. );
  85. $this->addColumn(
  86. 'qty_ordered',
  87. [
  88. 'header' => __('Order Quantity'),
  89. 'index' => 'qty_ordered',
  90. 'type' => 'number',
  91. 'total' => 'sum',
  92. 'sortable' => false,
  93. 'header_css_class' => 'col-qty',
  94. 'column_css_class' => 'col-qty'
  95. ]
  96. );
  97. $this->addExportType('*/*/exportBestsellersCsv', __('CSV'));
  98. $this->addExportType('*/*/exportBestsellersExcel', __('Excel XML'));
  99. return parent::_prepareColumns();
  100. }
  101. }