/**
  * {@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('.');
         }
     }
 }
Exemple #2
0
 /**
  * @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'));
 }
Exemple #3
0
 /**
  * @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);
 }
Exemple #4
0
 /**
  * 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);
 }
Exemple #5
0
 /**
  * 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;
 }
Exemple #6
0
 /**
  * @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;
 }
Exemple #7
0
 /**
  * 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;
 }
Exemple #8
0
 public function testConstructMethod()
 {
     $data = [];
     $customerId = 25;
     $this->customerSession->expects($this->once())->method('getCustomerId')->will($this->returnValue($customerId));
     $statuses = ['pending', 'processing', 'comlete'];
     $this->orderConfig->expects($this->once())->method('getVisibleOnFrontStatuses')->will($this->returnValue($statuses));
     $orderCollection = $this->getMock('Magento\\Sales\\Model\\Resource\\Order\\Collection', ['addFieldToSelect', 'addFieldToFilter', 'setOrder'], [], '', false, false);
     $orderCollection->expects($this->at(0))->method('addFieldToSelect')->with($this->equalTo('*'))->will($this->returnSelf());
     $orderCollection->expects($this->at(1))->method('addFieldToFilter')->with('customer_id', $this->equalTo($customerId))->will($this->returnSelf());
     $orderCollection->expects($this->at(2))->method('addFieldToFilter')->with('status', $this->equalTo(['in' => $statuses]))->will($this->returnSelf());
     $orderCollection->expects($this->at(3))->method('setOrder')->with('created_at', 'desc')->will($this->returnSelf());
     $this->orderCollectionFactory->expects($this->atLeastOnce())->method('create')->will($this->returnValue($orderCollection));
     $this->model = new \Magento\Sales\Block\Order\History($this->context, $this->orderCollectionFactory, $this->customerSession, $this->orderConfig, $this->pageConfig, $data);
     $this->assertEquals($orderCollection, $this->model->getOrders());
 }
Exemple #9
0
 /**
  * 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;
 }
Exemple #10
0
 public function testConstructMethod()
 {
     $data = [];
     $attribute = ['customer_id', 'status'];
     $customerId = 25;
     $layout = $this->getMock('Magento\\Framework\\View\\Layout', ['getBlock'], [], '', false, false);
     $this->context->expects($this->once())->method('getLayout')->will($this->returnValue($layout));
     $this->customerSession->expects($this->once())->method('getCustomerId')->will($this->returnValue($customerId));
     $statuses = ['pending', 'processing', 'complete'];
     $this->orderConfig->expects($this->once())->method('getVisibleOnFrontStatuses')->will($this->returnValue($statuses));
     $orderCollection = $this->getMock('Magento\\Sales\\Model\\Resource\\Order\\Collection', ['addAttributeToSelect', 'addFieldToFilter', 'addAttributeToFilter', 'addAttributeToSort', 'setPageSize', 'load'], [], '', false, false);
     $this->orderCollectionFactory->expects($this->once())->method('create')->will($this->returnValue($orderCollection));
     $orderCollection->expects($this->at(0))->method('addAttributeToSelect')->with($this->equalTo('*'))->will($this->returnSelf());
     $orderCollection->expects($this->at(1))->method('addAttributeToFilter')->with($attribute[0], $this->equalTo($customerId))->willReturnSelf();
     $orderCollection->expects($this->at(2))->method('addAttributeToFilter')->with($attribute[1], $this->equalTo(['in' => $statuses]))->will($this->returnSelf());
     $orderCollection->expects($this->at(3))->method('addAttributeToSort')->with('created_at', 'desc')->will($this->returnSelf());
     $orderCollection->expects($this->at(4))->method('setPageSize')->with('5')->will($this->returnSelf());
     $orderCollection->expects($this->at(5))->method('load')->will($this->returnSelf());
     $this->block = new \Magento\Sales\Block\Order\Recent($this->context, $this->orderCollectionFactory, $this->customerSession, $this->orderConfig, $data);
     $this->assertEquals($orderCollection, $this->block->getOrders());
 }
Exemple #11
0
 public function testInitOrders()
 {
     $customerId = 25;
     $attribute = ['customer_id', 'status'];
     $this->httpContext->expects($this->once())->method('getValue')->with($this->equalTo(Context::CONTEXT_AUTH))->will($this->returnValue(true));
     $this->customerSession->expects($this->once())->method('getCustomerId')->will($this->returnValue($customerId));
     $statuses = ['pending', 'processing', 'complete'];
     $this->orderConfig->expects($this->once())->method('getVisibleOnFrontStatuses')->will($this->returnValue($statuses));
     $this->orderCollection->expects($this->at(0))->method('addAttributeToFilter')->with($attribute[0], $this->equalTo($customerId))->will($this->returnSelf());
     $this->orderCollection->expects($this->at(1))->method('addAttributeToFilter')->with($attribute[1], $this->equalTo(['in' => $statuses]))->will($this->returnSelf());
     $this->orderCollection->expects($this->at(2))->method('addAttributeToSort')->with('created_at', 'desc')->will($this->returnSelf());
     $this->orderCollection->expects($this->at(3))->method('setPage')->with($this->equalTo(1), $this->equalTo(1))->will($this->returnSelf());
     $this->orderCollectionFactory->expects($this->atLeastOnce())->method('create')->will($this->returnValue($this->orderCollection));
     $this->createBlockObject();
     $this->assertEquals($this->orderCollection, $this->block->getOrders());
 }
Exemple #12
0
 /**
  * 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);
 }
Exemple #13
0
 /**
  * @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);
 }
Exemple #14
0
 /**
  * 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();
 }