/** * @return void */ protected function _construct() { parent::_construct(); $orders = $this->_orderCollectionFactory->create()->addFieldToSelect('*')->addFieldToFilter('customer_id', $this->_customerSession->getCustomerId())->addFieldToFilter('status', array('in' => $this->_orderConfig->getVisibleOnFrontStatuses()))->setOrder('created_at', 'desc'); $this->setOrders($orders); $this->pageConfig->setTitle(__('My Orders')); }
/** * Init customer order for display on front * * @return void */ protected function initOrders() { $customerId = $this->_customerSession->getCustomerId(); $orders = $this->_orderCollectionFactory->create()->addAttributeToFilter('customer_id', $customerId)->addAttributeToFilter('status', ['in' => $this->_orderConfig->getVisibleOnFrontStatuses()])->addAttributeToSort('created_at', 'desc')->setPage(1, 1); //TODO: add filter by current website $this->orders = $orders; }
/** * @return void */ protected function _construct() { parent::_construct(); //TODO: add full name logic $orders = $this->_orderCollectionFactory->create()->addAttributeToSelect('*')->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left')->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left')->addAttributeToFilter('customer_id', $this->_customerSession->getCustomerId())->addAttributeToFilter('status', array('in' => $this->_orderConfig->getVisibleOnFrontStatuses()))->addAttributeToSort('created_at', 'desc')->setPageSize('5')->load(); $this->setOrders($orders); }
/** * {@inheritdoc} */ public function canView(\Magento\Sales\Model\Order $order) { $customerId = $this->customerSession->getCustomerId(); $availableStatuses = $this->orderConfig->getVisibleOnFrontStatuses(); if ($order->getId() && $order->getCustomerId() && $order->getCustomerId() == $customerId && in_array($order->getStatus(), $availableStatuses, true)) { return true; } return false; }
/** * @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; }
/** * Retrieve related orders collection * * @return \Magento\Sales\Model\Resource\Order\Collection */ public function getRelatedOrders() { if ($this->_relatedOrders === null) { $billingAgreement = $this->_getBillingAgreementInstance(); $billingAgreementId = $billingAgreement ? $billingAgreement->getAgreementId() : 0; $this->_relatedOrders = $this->_orderCollectionFactory->create()->addFieldToSelect('*')->addFieldToFilter('customer_id', (int) $this->_customerSession->getCustomerId())->addFieldToFilter('status', ['in' => $this->_orderConfig->getVisibleOnFrontStatuses()])->setOrder('created_at', 'desc'); $this->_agreementResource->addOrdersFilter($this->_relatedOrders, $billingAgreementId); } return $this->_relatedOrders; }
/** * Prepare related grid data * * @return void */ protected function _prepareLayout() { parent::_prepareLayout(); $this->_prepareRelatedOrders(array('increment_id', 'created_at', 'customer_firstname', 'customer_lastname', 'base_grand_total', 'status')); $this->_relatedOrders->addFieldToFilter('status', array('in' => $this->_config->getVisibleOnFrontStatuses())); $pager = $this->getLayout()->createBlock('Magento\\Theme\\Block\\Html\\Pager')->setCollection($this->_relatedOrders)->setIsOutputRequired(false); $this->setChild('pager', $pager); $this->setGridColumns(array(new \Magento\Framework\Object(array('index' => 'increment_id', 'title' => __('Order #'), 'is_nobr' => true, 'width' => 1)), new \Magento\Framework\Object(array('index' => 'created_at', 'title' => __('Date'), 'is_nobr' => true, 'width' => 1)), new \Magento\Framework\Object(array('index' => 'customer_name', 'title' => __('Customer Name'))), new \Magento\Framework\Object(array('index' => 'base_grand_total', 'title' => __('Order Total'), 'is_nobr' => true, 'width' => 1, 'is_amount' => true)), new \Magento\Framework\Object(array('index' => 'status', 'title' => __('Order Status'), 'is_nobr' => true, 'width' => 1)))); $orders = array(); foreach ($this->_relatedOrders as $order) { $orders[] = new \Magento\Framework\Object(array('increment_id' => $order->getIncrementId(), 'created_at' => $this->formatDate($order->getCreatedAt()), 'customer_name' => $order->getCustomerName(), 'base_grand_total' => $this->_coreHelper->formatCurrency($order->getBaseGrandTotal(), false), 'status' => $order->getStatusLabel(), 'increment_id_link_url' => $this->getUrl('sales/order/view/', array('order_id' => $order->getId())))); } if ($orders) { $this->setGridElements($orders); } }
/** * @return void */ protected function _construct() { parent::_construct(); $orders = $this->_orderCollectionFactory->create()->addAttributeToSelect('*')->addAttributeToFilter('customer_id', $this->_customerSession->getCustomerId())->addAttributeToFilter('status', ['in' => $this->_orderConfig->getVisibleOnFrontStatuses()])->addAttributeToSort('created_at', 'desc')->setPageSize('5')->load(); $this->setOrders($orders); }