_orderCollectionFactory = $orderCollectionFactory; $this->_customerSession = $customerSession; $this->_orderConfig = $orderConfig; $this->_isScopePrivate = true; $this->storeManager = $storeManager ?: ObjectManager::getInstance() ->get(StoreManagerInterface::class); parent::__construct($context, $data); } /** * @return void */ protected function _construct() { parent::_construct(); $this->getRecentOrders(); } /** * Get recently placed orders. By default they will be limited by 5. */ private function getRecentOrders() { $orders = $this->_orderCollectionFactory->create()->addAttributeToSelect( '*' )->addAttributeToFilter( 'customer_id', $this->_customerSession->getCustomerId() )->addAttributeToFilter( 'store_id', $this->storeManager->getStore()->getId() )->addAttributeToFilter( 'status', ['in' => $this->_orderConfig->getVisibleOnFrontStatuses()] )->addAttributeToSort( 'created_at', 'desc' )->setPageSize( self::ORDER_LIMIT )->load(); $this->setOrders($orders); } /** * @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()]); } /** * @return string */ protected function _toHtml() { if ($this->getOrders()->getSize() > 0) { return parent::_toHtml(); } return ''; } /** * @param object $order * @return string */ public function getReorderUrl($order) { return $this->getUrl('sales/order/reorder', ['order_id' => $order->getId()]); } }