Esempio n. 1
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);
 }
Esempio n. 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'));
 }
 /**
  * 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;
 }
Esempio n. 4
0
 /**
  * Decorate status column values
  *
  * @param string $value
  * @param \Magento\Sales\Model\Order\Status $row
  * @param \Magento\Backend\Block\Widget\Grid\Column $column
  * @param bool $isExport
  * @return string
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function decorateState($value, $row, $column, $isExport)
 {
     if ($value) {
         $cell = $value . '[' . $this->_config->getStateLabel($value) . ']';
     } else {
         $cell = $value;
     }
     return $cell;
 }
 /**
  * {@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;
 }
Esempio n. 6
0
 /**
  * @return array
  */
 public function toOptionArray()
 {
     $statuses = $this->_stateStatuses ? $this->_orderConfig->getStateStatuses($this->_stateStatuses) : $this->_orderConfig->getStatuses();
     $options = [['value' => '', 'label' => __('-- Please Select --')]];
     foreach ($statuses as $code => $label) {
         $options[] = ['value' => $code, 'label' => $label];
     }
     return $options;
 }
Esempio n. 7
0
 /**
  * @return array
  */
 public function toOptionArray()
 {
     $statuses = $this->_stateStatuses ? $this->_orderConfig->getStateStatuses($this->_stateStatuses) : $this->_orderConfig->getStatuses();
     $options = [['value' => '', 'label' => __(self::UNDEFINED_OPTION_LABEL)]];
     foreach ($statuses as $code => $label) {
         $options[] = ['value' => $code, 'label' => $label];
     }
     return $options;
 }
Esempio n. 8
0
 public function testGetInvisibleOnFrontStatuses()
 {
     $statuses = [new \Magento\Framework\Object(['status' => 'canceled', 'is_default' => 1, 'visible_on_front' => 1]), new \Magento\Framework\Object(['status' => 'complete', 'is_default' => 1, 'visible_on_front' => 0]), new \Magento\Framework\Object(['status' => 'processing', 'is_default' => 1, 'visible_on_front' => 1]), new \Magento\Framework\Object(['status' => 'pending_payment', 'is_default' => 1, 'visible_on_front' => 0])];
     $expectedResult = ['complete', 'pending_payment'];
     $collectionMock = $this->getMock('Magento\\Sales\\Model\\Resource\\Order\\Status\\Collection', ['create', 'joinStates'], [], '', false, false);
     $this->orderStatusCollectionFactoryMock->expects($this->once())->method('create')->will($this->returnValue($collectionMock));
     $collectionMock->expects($this->once())->method('joinStates')->will($this->returnValue($statuses));
     $result = $this->salesConfig->getInvisibleOnFrontStatuses();
     $this->assertSame($expectedResult, $result);
 }
Esempio n. 9
0
 /**
  * @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;
 }
 public function testUpdateOrderStatusForPaymentMethodsNewState()
 {
     $this->_prepareEventMockWithMethods(['getState', 'getStatus']);
     $this->eventMock->expects($this->once())->method('getState')->will($this->returnValue(\Magento\Sales\Model\Order::STATE_NEW));
     $this->eventMock->expects($this->once())->method('getStatus')->will($this->returnValue(self::ORDER_STATUS));
     $defaultStatus = 'defaultStatus';
     $this->orderConfigMock->expects($this->once())->method('getStateDefaultStatus')->with(\Magento\Sales\Model\Order::STATE_NEW)->will($this->returnValue($defaultStatus));
     $this->paymentConfigMock->expects($this->once())->method('getActiveMethods')->will($this->returnValue($this->_getPreparedActiveMethods()));
     $this->coreResourceConfigMock->expects($this->once())->method('saveConfig')->with('payment/' . self::METHOD_CODE . '/order_status', $defaultStatus, 'default', 0);
     $this->updateOrderStatusForPaymentMethodsObserver->execute($this->observerMock);
 }
 /**
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if ($observer->getEvent()->getState() != \Magento\Sales\Model\Order::STATE_NEW) {
         return;
     }
     $status = $observer->getEvent()->getStatus();
     $defaultStatus = $this->_salesOrderConfig->getStateDefaultStatus(\Magento\Sales\Model\Order::STATE_NEW);
     $methods = $this->_paymentConfig->getActiveMethods();
     foreach ($methods as $method) {
         if ($method->getConfigData('order_status') == $status) {
             $this->_resourceConfig->saveConfig('payment/' . $method->getCode() . '/order_status', $defaultStatus, 'default', 0);
         }
     }
 }
Esempio n. 12
0
 /**
  * Calculate lifitime sales
  *
  * @param int $isFilter
  * @return $this
  */
 public function calculateSales($isFilter = 0)
 {
     $statuses = $this->_orderConfig->getStateStatuses(\Magento\Sales\Model\Order::STATE_CANCELED);
     if (empty($statuses)) {
         $statuses = [0];
     }
     $adapter = $this->getConnection();
     if ($this->_scopeConfig->getValue('sales/dashboard/use_aggregated_data', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) {
         $this->setMainTable('sales_order_aggregated_created');
         $this->removeAllFieldsFromSelect();
         $averageExpr = $adapter->getCheckSql('SUM(main_table.orders_count) > 0', 'SUM(main_table.total_revenue_amount)/SUM(main_table.orders_count)', 0);
         $this->getSelect()->columns(['lifetime' => 'SUM(main_table.total_revenue_amount)', 'average' => $averageExpr]);
         if (!$isFilter) {
             $this->addFieldToFilter('store_id', ['eq' => $this->_storeManager->getStore(\Magento\Store\Model\Store::ADMIN_CODE)->getId()]);
         }
         $this->getSelect()->where('main_table.order_status NOT IN(?)', $statuses);
     } else {
         $this->setMainTable('sales_order');
         $this->removeAllFieldsFromSelect();
         $expr = $this->_getSalesAmountExpression();
         if ($isFilter == 0) {
             $expr = '(' . $expr . ') * main_table.base_to_global_rate';
         }
         $this->getSelect()->columns(['lifetime' => "SUM({$expr})", 'average' => "AVG({$expr})"])->where('main_table.status NOT IN(?)', $statuses)->where('main_table.state NOT IN(?)', [\Magento\Sales\Model\Order::STATE_NEW, \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT]);
     }
     return $this;
 }
Esempio n. 13
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());
 }
Esempio n. 14
0
 /**
  * Prepare form fields
  *
  * @return $this
  */
 protected function _prepareForm()
 {
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create(['data' => ['id' => 'edit_form', 'method' => 'post']]);
     $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Assignment Information')]);
     $statuses = $this->_collectionFactory->create()->toOptionArray();
     array_unshift($statuses, ['value' => '', 'label' => '']);
     $states = $this->_orderConfig->getStates();
     $states = array_merge(['' => ''], $states);
     $fieldset->addField('status', 'select', ['name' => 'status', 'label' => __('Order Status'), 'class' => 'required-entry', 'values' => $statuses, 'required' => true]);
     $fieldset->addField('state', 'select', ['name' => 'state', 'label' => __('Order State'), 'class' => 'required-entry', 'values' => $states, 'required' => true]);
     $fieldset->addField('is_default', 'checkbox', ['name' => 'is_default', 'label' => __('Use Order Status As Default'), 'value' => 1]);
     $fieldset->addField('visible_on_front', 'checkbox', ['name' => 'visible_on_front', 'label' => __('Visible On Frontend'), 'value' => 1]);
     $form->setAction($this->getUrl('sales/order_status/assignPost'));
     $form->setUseContainer(true);
     $this->setForm($form);
     return parent::_prepareForm();
 }
Esempio n. 15
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;
 }
Esempio n. 16
0
 /**
  * Gets Payu.pl-specific default status for state.
  *
  * @param string $state
  * @return string
  */
 public function getStateDefaultStatus($state)
 {
     switch ($state) {
         case Order::STATE_PENDING_PAYMENT:
             return $this->scopeConfig->getValue(self::XML_PATH_ORDER_STATUS_NEW, 'store');
         case Order::STATE_HOLDED:
             return $this->scopeConfig->getValue(self::XML_PATH_ORDER_STATUS_HOLDED, 'store');
         case Order::STATE_PROCESSING:
             return $this->scopeConfig->getValue(self::XML_PATH_ORDER_STATUS_PROCESSING, 'store');
     }
     return parent::getStateDefaultStatus($state);
 }
Esempio n. 17
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\\ResourceModel\\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());
 }
Esempio n. 18
0
 /**
  * Get last order ID from session, fetch it and check whether it can be viewed, printed etc
  *
  * @return void
  */
 protected function _prepareLastOrder()
 {
     $orderId = $this->_checkoutSession->getLastOrderId();
     if ($orderId) {
         $order = $this->_orderFactory->create()->load($orderId);
         if ($order->getId()) {
             $isVisible = !in_array($order->getStatus(), $this->_orderConfig->getInvisibleOnFrontStatuses());
             $canView = $this->httpContext->getValue(Context::CONTEXT_AUTH) && $isVisible;
             $this->addData(['is_order_visible' => $isVisible, 'view_order_url' => $this->getUrl('sales/order/view/', ['order_id' => $orderId]), 'print_url' => $this->getUrl('sales/order/print', ['order_id' => $orderId]), 'can_print_order' => $isVisible, 'can_view_order' => $canView, 'order_id' => $order->getIncrementId()]);
         }
     }
 }
Esempio n. 19
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());
 }
Esempio n. 20
0
 /**
  * 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);
     }
 }
Esempio n. 21
0
 public function testToOptionArray()
 {
     $this->config->expects($this->once())->method('getStateStatuses')->will($this->returnValue(['status1', 'status2']));
     $this->assertEquals([['value' => '', 'label' => '-- Please Select --'], ['value' => 0, 'label' => 'status1'], ['value' => 1, 'label' => 'status2']], $this->object->toOptionArray());
 }
Esempio n. 22
0
 public function testToOptionArray()
 {
     $this->config->expects($this->once())->method('getStateStatuses')->with(['pending_payment'])->will($this->returnValue(['pending_payment' => 'Pending Payment']));
     $this->assertEquals([['value' => '', 'label' => '-- Please Select --'], ['value' => 'pending_payment', 'label' => 'Pending Payment']], $this->object->toOptionArray());
 }
Esempio n. 23
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);
 }
Esempio n. 24
0
 /**
  * Is order visible
  *
  * @param Order $order
  * @return bool
  */
 protected function isVisible(Order $order)
 {
     return !in_array($order->getStatus(), $this->_orderConfig->getInvisibleOnFrontStatuses());
 }