Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Recent.php
Go to the documentation of this file.
1 <?php
7 
14 
22 {
26  const ORDER_LIMIT = 5;
27 
32 
36  protected $_customerSession;
37 
41  protected $_orderConfig;
42 
46  private $storeManager;
47 
56  public function __construct(
57  Context $context,
58  CollectionFactory $orderCollectionFactory,
59  Session $customerSession,
60  Config $orderConfig,
61  array $data = [],
62  StoreManagerInterface $storeManager = null
63  ) {
64  $this->_orderCollectionFactory = $orderCollectionFactory;
65  $this->_customerSession = $customerSession;
66  $this->_orderConfig = $orderConfig;
67  $this->_isScopePrivate = true;
68  $this->storeManager = $storeManager ?: ObjectManager::getInstance()
69  ->get(StoreManagerInterface::class);
70  parent::__construct($context, $data);
71  }
72 
76  protected function _construct()
77  {
78  parent::_construct();
79  $this->getRecentOrders();
80  }
81 
86  private function getRecentOrders()
87  {
88  $orders = $this->_orderCollectionFactory->create()->addAttributeToSelect(
89  '*'
90  )->addAttributeToFilter(
91  'customer_id',
92  $this->_customerSession->getCustomerId()
93  )->addAttributeToFilter(
94  'store_id',
95  $this->storeManager->getStore()->getId()
96  )->addAttributeToFilter(
97  'status',
98  ['in' => $this->_orderConfig->getVisibleOnFrontStatuses()]
99  )->addAttributeToSort(
100  'created_at',
101  'desc'
102  )->setPageSize(
103  self::ORDER_LIMIT
104  )->load();
105  $this->setOrders($orders);
106  }
107 
112  public function getViewUrl($order)
113  {
114  return $this->getUrl('sales/order/view', ['order_id' => $order->getId()]);
115  }
116 
121  public function getTrackUrl($order)
122  {
123  return $this->getUrl('sales/order/track', ['order_id' => $order->getId()]);
124  }
125 
129  protected function _toHtml()
130  {
131  if ($this->getOrders()->getSize() > 0) {
132  return parent::_toHtml();
133  }
134  return '';
135  }
136 
141  public function getReorderUrl($order)
142  {
143  return $this->getUrl('sales/order/reorder', ['order_id' => $order->getId()]);
144  }
145 }
$order
Definition: order.php:55
__construct(Context $context, CollectionFactory $orderCollectionFactory, Session $customerSession, Config $orderConfig, array $data=[], StoreManagerInterface $storeManager=null)
Definition: Recent.php:56