/** * @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')); }
/** * @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 run() { $this->logger->log('Installing orders:'); foreach ($this->fixtures as $file) { $fileName = $this->fixtureHelper->getPath($file); $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']); $isFirst = true; foreach ($csvReader as $row) { if ($isFirst) { $customer = $this->customerRepository->get($row['customer_email']); if (!$customer->getId()) { continue; } /** @var \Magento\Sales\Model\Resource\Collection $orderCollection */ $orderCollection = $this->orderCollectionFactory->create(); $orderCollection->addFilter('customer_id', $customer->getId()); if ($orderCollection->count() > 0) { break; } } $isFirst = false; $orderData = $this->converter->convertRow($row); $this->orderProcessor->createOrder($orderData); $this->logger->logInline('.'); } } }
/** * Init customer order for display on front * * @return void */ public function initOrders() { $customerId = $this->getCustomerId() ? $this->getCustomerId() : $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->setOrders($orders); }
/** * Retrieve last order on current website * * @return \Magento\Sales\Model\Order|false */ public function getLastOrder() { $storeIds = $this->getQuote()->getStore()->getWebsite()->getStoreIds(); $collection = $this->_ordersFactory->create()->addFieldToFilter('customer_id', $this->getCustomerId())->addFieldToFilter('store_id', ['in' => $storeIds])->setOrder('created_at', 'desc')->setPageSize(1)->load(); foreach ($collection as $order) { return $order; } return false; }
/** * @return bool|\Magento\Sales\Model\Resource\Order\Collection */ public function getOrders() { if (!($customerId = $this->_customerSession->getCustomerId())) { return false; } if (!$this->orders) { $this->orders = $this->_orderCollectionFactory->create()->addFieldToSelect('*')->addFieldToFilter('customer_id', $customerId)->addFieldToFilter('status', ['in' => $this->_orderConfig->getVisibleOnFrontStatuses()])->setOrder('created_at', 'desc'); } return $this->orders; }
/** * Load search results * * @return $this */ public function load() { $result = array(); if (!$this->hasStart() || !$this->hasLimit() || !$this->hasQuery()) { $this->setResults($result); return $this; } $query = $this->getQuery(); //TODO: add full name logic $collection = $this->_collectionFactory->create()->addAttributeToSelect('*')->addAttributeToSearchFilter(array(array('attribute' => 'increment_id', 'like' => $query . '%'), array('attribute' => 'billing_firstname', 'like' => $query . '%'), array('attribute' => 'billing_lastname', 'like' => $query . '%'), array('attribute' => 'billing_telephone', 'like' => $query . '%'), array('attribute' => 'billing_postcode', 'like' => $query . '%'), array('attribute' => 'shipping_firstname', 'like' => $query . '%'), array('attribute' => 'shipping_lastname', 'like' => $query . '%'), array('attribute' => 'shipping_telephone', 'like' => $query . '%'), array('attribute' => 'shipping_postcode', 'like' => $query . '%')))->setCurPage($this->getStart())->setPageSize($this->getLimit())->load(); foreach ($collection as $order) { $result[] = array('id' => 'order/1/' . $order->getId(), 'type' => __('Order'), 'name' => __('Order #%1', $order->getIncrementId()), 'description' => $order->getBillingFirstname() . ' ' . $order->getBillingLastname(), 'form_panel_title' => __('Order #%1 (%2)', $order->getIncrementId(), $order->getBillingFirstname() . ' ' . $order->getBillingLastname()), 'url' => $this->_adminhtmlData->getUrl('sales/order/view', array('order_id' => $order->getId()))); } $this->setResults($result); return $this; }
/** * 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; }
/** * Render information about specified orders and their items * * @link https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#checkout-options * @link https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#measuring-transactions * @link https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#transaction * * @return string|void */ public function getOrdersTrackingCode() { $orderIds = $this->getOrderIds(); if (empty($orderIds) || !is_array($orderIds)) { return; } $collection = $this->_salesOrderCollection->create(); $collection->addFieldToFilter('entity_id', array('in' => $orderIds)); $result = []; $result[] = "ga('require', 'ec', 'ec.js');"; foreach ($collection as $order) { if ($order->getIsVirtual()) { $address = $order->getBillingAddress(); } else { $address = $order->getShippingAddress(); } foreach ($order->getAllVisibleItems() as $item) { $result[] = sprintf("ga('ec:addProduct', {\n 'id': '%s',\n 'name': '%s',\n 'price': '%s',\n 'quantity': %s\n });", $this->escapeJsQuote($item->getSku()), $this->escapeJsQuote($item->getName()), $item->getBasePrice(), $item->getQtyOrdered()); } $result[] = sprintf("ga('ec:setAction', 'purchase', {\n 'id': '%s',\n 'affiliation': '%s',\n 'revenue': '%s',\n 'tax': '%s',\n 'shipping': '%s'\n });", $order->getIncrementId(), $this->escapeJsQuote($this->_storeManager->getStore()->getFrontendName()), $order->getBaseGrandTotal(), $order->getBaseTaxAmount(), $order->getBaseShippingAmount()); $result[] = "ga('send', 'pageview');"; } return implode("\n", $result); }
/** * @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); }
/** * Prepare grid collection object * * @return $this */ protected function _prepareCollection() { $collection = $this->_recurringCollectionFilter->byIds($this->_orderCollection->create(), $this->_coreRegistry->registry('current_recurring_payment')->getId()); $this->setCollection($collection); return parent::_prepareCollection(); }