Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Orders.php
Go to the documentation of this file.
1 <?php
7 
9 
16 class Orders extends \Magento\Backend\Block\Widget\Grid\Extended
17 {
23  protected $_salesReorder = null;
24 
30  protected $_coreRegistry = null;
31 
35  protected $collectionFactory;
36 
45  public function __construct(
46  \Magento\Backend\Block\Template\Context $context,
47  \Magento\Backend\Helper\Data $backendHelper,
48  \Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory $collectionFactory,
49  \Magento\Sales\Helper\Reorder $salesReorder,
50  \Magento\Framework\Registry $coreRegistry,
51  array $data = []
52  ) {
53  $this->_coreRegistry = $coreRegistry;
54  $this->_salesReorder = $salesReorder;
55  $this->_collectionFactory = $collectionFactory;
56  parent::__construct($context, $backendHelper, $data);
57  }
58 
62  protected function _construct()
63  {
64  parent::_construct();
65  $this->setId('customer_orders_grid');
66  $this->setDefaultSort('created_at', 'desc');
67  $this->setUseAjax(true);
68  }
69 
75  protected function _prepareCollection()
76  {
77  $collection = $this->_collectionFactory->getReport('sales_order_grid_data_source')->addFieldToSelect(
78  'entity_id'
79  )->addFieldToSelect(
80  'increment_id'
81  )->addFieldToSelect(
82  'customer_id'
83  )->addFieldToSelect(
84  'created_at'
85  )->addFieldToSelect(
86  'grand_total'
87  )->addFieldToSelect(
88  'order_currency_code'
89  )->addFieldToSelect(
90  'store_id'
91  )->addFieldToSelect(
92  'billing_name'
93  )->addFieldToSelect(
94  'shipping_name'
95  )->addFieldToFilter(
96  'customer_id',
97  $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID)
98  );
99 
100  $this->setCollection($collection);
101  return parent::_prepareCollection();
102  }
103 
107  protected function _prepareColumns()
108  {
109  $this->addColumn('increment_id', ['header' => __('Order'), 'width' => '100', 'index' => 'increment_id']);
110 
111  $this->addColumn(
112  'created_at',
113  ['header' => __('Purchased'), 'index' => 'created_at', 'type' => 'datetime']
114  );
115 
116  $this->addColumn('billing_name', ['header' => __('Bill-to Name'), 'index' => 'billing_name']);
117 
118  $this->addColumn('shipping_name', ['header' => __('Ship-to Name'), 'index' => 'shipping_name']);
119 
120  $this->addColumn(
121  'grand_total',
122  [
123  'header' => __('Order Total'),
124  'index' => 'grand_total',
125  'type' => 'currency',
126  'currency' => 'order_currency_code'
127  ]
128  );
129 
130  if (!$this->_storeManager->isSingleStoreMode()) {
131  $this->addColumn(
132  'store_id',
133  ['header' => __('Purchase Point'), 'index' => 'store_id', 'type' => 'store', 'store_view' => true]
134  );
135  }
136 
137  if ($this->_salesReorder->isAllow()) {
138  $this->addColumn(
139  'action',
140  [
141  'header' => ' ',
142  'filter' => false,
143  'sortable' => false,
144  'width' => '100px',
145  'renderer' => \Magento\Sales\Block\Adminhtml\Reorder\Renderer\Action::class
146  ]
147  );
148  }
149 
150  return parent::_prepareColumns();
151  }
152 
159  public function getRowUrl($row)
160  {
161  return $this->getUrl('sales/order/view', ['order_id' => $row->getId()]);
162  }
163 
167  public function getGridUrl()
168  {
169  return $this->getUrl('customer/*/orders', ['_current' => true]);
170  }
171 }
__()
Definition: __.php:13
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Backend\Helper\Data $backendHelper, \Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory $collectionFactory, \Magento\Sales\Helper\Reorder $salesReorder, \Magento\Framework\Registry $coreRegistry, array $data=[])
Definition: Orders.php:45