123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Sales\Block\Order;
- use \Magento\Framework\App\ObjectManager;
- use \Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface;
- /**
- * Sales order history block
- *
- * @api
- * @since 100.0.2
- */
- class History extends \Magento\Framework\View\Element\Template
- {
- /**
- * @var string
- */
- protected $_template = 'Magento_Sales::order/history.phtml';
- /**
- * @var \Magento\Sales\Model\ResourceModel\Order\CollectionFactory
- */
- protected $_orderCollectionFactory;
- /**
- * @var \Magento\Customer\Model\Session
- */
- protected $_customerSession;
- /**
- * @var \Magento\Sales\Model\Order\Config
- */
- protected $_orderConfig;
- /**
- * @var \Magento\Sales\Model\ResourceModel\Order\Collection
- */
- protected $orders;
- /**
- * @var CollectionFactoryInterface
- */
- private $orderCollectionFactory;
- /**
- * @param \Magento\Framework\View\Element\Template\Context $context
- * @param \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory
- * @param \Magento\Customer\Model\Session $customerSession
- * @param \Magento\Sales\Model\Order\Config $orderConfig
- * @param array $data
- */
- public function __construct(
- \Magento\Framework\View\Element\Template\Context $context,
- \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory,
- \Magento\Customer\Model\Session $customerSession,
- \Magento\Sales\Model\Order\Config $orderConfig,
- array $data = []
- ) {
- $this->_orderCollectionFactory = $orderCollectionFactory;
- $this->_customerSession = $customerSession;
- $this->_orderConfig = $orderConfig;
- parent::__construct($context, $data);
- }
- /**
- * @return void
- */
- protected function _construct()
- {
- parent::_construct();
- $this->pageConfig->getTitle()->set(__('My Orders'));
- }
- /**
- * @return CollectionFactoryInterface
- *
- * @deprecated 100.1.1
- */
- private function getOrderCollectionFactory()
- {
- if ($this->orderCollectionFactory === null) {
- $this->orderCollectionFactory = ObjectManager::getInstance()->get(CollectionFactoryInterface::class);
- }
- return $this->orderCollectionFactory;
- }
- /**
- * @return bool|\Magento\Sales\Model\ResourceModel\Order\Collection
- */
- public function getOrders()
- {
- if (!($customerId = $this->_customerSession->getCustomerId())) {
- return false;
- }
- if (!$this->orders) {
- $this->orders = $this->getOrderCollectionFactory()->create($customerId)->addFieldToSelect(
- '*'
- )->addFieldToFilter(
- 'status',
- ['in' => $this->_orderConfig->getVisibleOnFrontStatuses()]
- )->setOrder(
- 'created_at',
- 'desc'
- );
- }
- return $this->orders;
- }
- /**
- * @return $this
- */
- protected function _prepareLayout()
- {
- parent::_prepareLayout();
- if ($this->getOrders()) {
- $pager = $this->getLayout()->createBlock(
- \Magento\Theme\Block\Html\Pager::class,
- 'sales.order.history.pager'
- )->setCollection(
- $this->getOrders()
- );
- $this->setChild('pager', $pager);
- $this->getOrders()->load();
- }
- return $this;
- }
- /**
- * @return string
- */
- public function getPagerHtml()
- {
- return $this->getChildHtml('pager');
- }
- /**
- * @param object $order
- * @return string
- */
- public function getViewUrl($order)
- {
- return $this->getUrl('sales/order/view', ['order_id' => $order->getId()]);
- }
- /**
- * @param object $order
- * @return string
- */
- public function getTrackUrl($order)
- {
- return $this->getUrl('sales/order/track', ['order_id' => $order->getId()]);
- }
- /**
- * @param object $order
- * @return string
- */
- public function getReorderUrl($order)
- {
- return $this->getUrl('sales/order/reorder', ['order_id' => $order->getId()]);
- }
- /**
- * @return string
- */
- public function getBackUrl()
- {
- return $this->getUrl('customer/account/');
- }
- }
|