123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <?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', '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' => ' ',
- '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()]);
- }
- /**
- * @inheritdoc
- */
- public function getGridUrl()
- {
- return $this->getUrl('customer/*/orders', ['_current' => true]);
- }
- }
|