-
Notifications
You must be signed in to change notification settings - Fork 9.3k
/
Orders.php
176 lines (158 loc) · 5.03 KB
/
Orders.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Customer\Block\Adminhtml\Edit\Tab;
use Magento\Customer\Controller\RegistryConstants;
/**
* Adminhtml customer orders grid block
*
* @api
* @since 100.0.2
*/
class Orders extends \Magento\Backend\Block\Widget\Grid\Extended
{
/**
* Sales reorder
*
* @var \Magento\Sales\Helper\Reorder
*/
protected $_salesReorder = null;
/**
* Core registry
*
* @var \Magento\Framework\Registry
*/
protected $_coreRegistry = null;
/**
* @var \Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory
*/
protected $collectionFactory;
/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Backend\Helper\Data $backendHelper
* @param \Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory $collectionFactory
* @param \Magento\Sales\Helper\Reorder $salesReorder
* @param \Magento\Framework\Registry $coreRegistry
* @param array $data
*/
public function __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 = []
) {
$this->_coreRegistry = $coreRegistry;
$this->_salesReorder = $salesReorder;
$this->_collectionFactory = $collectionFactory;
parent::__construct($context, $backendHelper, $data);
}
/**
* @inheritdoc
*/
protected function _construct()
{
parent::_construct();
$this->setId('customer_orders_grid');
$this->setDefaultSort('created_at');
$this->setDefaultDir('desc');
$this->setUseAjax(true);
}
/**
* Apply various selection filters to prepare the sales order grid collection.
*
* @return $this
*/
protected function _prepareCollection()
{
$collection = $this->_collectionFactory->getReport('sales_order_grid_data_source')->addFieldToSelect(
'entity_id'
)->addFieldToSelect(
'increment_id'
)->addFieldToSelect(
'customer_id'
)->addFieldToSelect(
'created_at'
)->addFieldToSelect(
'grand_total'
)->addFieldToSelect(
'order_currency_code'
)->addFieldToSelect(
'store_id'
)->addFieldToSelect(
'billing_name'
)->addFieldToSelect(
'shipping_name'
)->addFieldToFilter(
'customer_id',
$this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID)
);
$this->setCollection($collection);
return parent::_prepareCollection();
}
/**
* @inheritdoc
*/
protected function _prepareColumns()
{
$this->addColumn('increment_id', ['header' => __('Order #'), 'width' => '100', 'index' => 'increment_id']);
$this->addColumn(
'created_at',
['header' => __('Purchased'), 'index' => 'created_at', 'type' => 'datetime']
);
$this->addColumn('billing_name', ['header' => __('Bill-to Name'), 'index' => 'billing_name']);
$this->addColumn('shipping_name', ['header' => __('Ship-to Name'), 'index' => 'shipping_name']);
$this->addColumn(
'grand_total',
[
'header' => __('Order Total'),
'index' => 'grand_total',
'type' => 'currency',
'currency' => 'order_currency_code',
'rate' => 1
]
);
if (!$this->_storeManager->isSingleStoreMode()) {
$this->addColumn(
'store_id',
['header' => __('Purchase Point'), 'index' => 'store_id', 'type' => 'store', 'store_view' => true]
);
}
if ($this->_salesReorder->isAllow()) {
$this->addColumn(
'action',
[
'header' => 'Action',
'filter' => false,
'sortable' => false,
'width' => '100px',
'renderer' => \Magento\Sales\Block\Adminhtml\Reorder\Renderer\Action::class
]
);
}
return parent::_prepareColumns();
}
/**
* Retrieve the Url for a specified sales order row.
*
* @param \Magento\Sales\Model\Order|\Magento\Framework\DataObject $row
* @return string
*/
public function getRowUrl($row)
{
return $this->getUrl(
'sales/order/view',
['order_id' => $row->getId(), 'customer_id' => $this->getRequest()->getParam('id')]
);
}
/**
* @inheritdoc
*/
public function getGridUrl()
{
return $this->getUrl('customer/*/orders', ['_current' => true]);
}
}