Пример #1
0
 /**
  * @magentoDataFixture Magento/Sales/_files/invoice.php
  */
 public function testOrderTotalItemCount()
 {
     $expectedResult = [['total_item_count' => 1]];
     $actualResult = [];
     /** @var \Magento\Sales\Model\Order $order */
     foreach ($this->_collection->getItems() as $order) {
         $actualResult[] = ['total_item_count' => $order->getData('total_item_count')];
     }
     $this->assertEquals($expectedResult, $actualResult);
 }
 /**
  * Set base grand total of order to registry
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return \Magento\GoogleAdwords\Observer\SetConversionValueObserver
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if (!($this->_helper->isGoogleAdwordsActive() && $this->_helper->isDynamicConversionValue())) {
         return $this;
     }
     $orderIds = $observer->getEvent()->getOrderIds();
     if (!$orderIds || !is_array($orderIds)) {
         return $this;
     }
     $this->_collection->addFieldToFilter('entity_id', ['in' => $orderIds]);
     $conversionValue = 0;
     /** @var $order \Magento\Sales\Model\Order */
     foreach ($this->_collection as $order) {
         $conversionValue += $order->getBaseGrandTotal();
     }
     $this->_registry->register(\Magento\GoogleAdwords\Helper\Data::CONVERSION_VALUE_REGISTRY_NAME, $conversionValue);
     return $this;
 }
Пример #3
0
 /**
  * Constructor
  *
  * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
  * @param \Psr\Log\LoggerInterface $logger
  * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
  * @param \Magento\Framework\Event\ManagerInterface $eventManager
  * @param \Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot $entitySnapshot
  * @param \Magento\Framework\DB\Helper $coreResourceHelper
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
  * @param \Magento\Sales\Model\Order\Config $orderConfig
  * @param \Magento\Sales\Model\ResourceModel\Report\OrderFactory $reportOrderFactory
  * @param null $connection
  * @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource
  *
  * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  */
 public function __construct(\Magento\Framework\Data\Collection\EntityFactory $entityFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot $entitySnapshot, \Magento\Framework\DB\Helper $coreResourceHelper, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Sales\Model\Order\Config $orderConfig, \Magento\Sales\Model\ResourceModel\Report\OrderFactory $reportOrderFactory, \Magento\Framework\DB\Adapter\AdapterInterface $connection = null, \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null)
 {
     parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $entitySnapshot, $coreResourceHelper, $connection, $resource);
     $this->_scopeConfig = $scopeConfig;
     $this->_storeManager = $storeManager;
     $this->_localeDate = $localeDate;
     $this->_orderConfig = $orderConfig;
     $this->_reportOrderFactory = $reportOrderFactory;
 }
Пример #4
0
 public function testLoadByIncrementIdAndStoreId()
 {
     $incrementId = '000000001';
     $storeId = '2';
     $this->salesOrderCollectionFactoryMock->expects($this->once())->method('create')->willReturn($this->salesOrderCollectionMock);
     $this->salesOrderCollectionMock->expects($this->any())->method('addFieldToFilter')->willReturnSelf();
     $this->salesOrderCollectionMock->expects($this->once())->method('load')->willReturnSelf();
     $this->salesOrderCollectionMock->expects($this->once())->method('getFirstItem')->willReturn($this->order);
     $this->assertSame($this->order, $this->order->loadByIncrementIdAndStoreId($incrementId, $storeId));
 }
Пример #5
0
 /**
  * Order throws exception while canceling
  */
 public function testException()
 {
     $exception = new \Exception('Can not cancel');
     $order1 = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock();
     $this->orderCollectionMock->expects($this->any())->method('getItems')->willReturn([$order1]);
     $order1->expects($this->once())->method('canCancel')->willReturn(true);
     $order1->expects($this->once())->method('cancel')->willThrowException($exception);
     $this->messageManagerMock->expects($this->once())->method('addError')->with('Can not cancel');
     $this->massAction->execute();
 }
Пример #6
0
 public function testExecuteNoReleasedOrderFromHold()
 {
     $order1 = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock();
     $order2 = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock();
     $orders = [$order1, $order2];
     $this->orderCollectionMock->expects($this->any())->method('getItems')->willReturn($orders);
     $order1->expects($this->once())->method('canUnhold')->willReturn(false);
     $this->orderCollectionMock->expects($this->once())->method('count')->willReturn(count($orders));
     $order2->expects($this->once())->method('canUnhold')->willReturn(false);
     $this->messageManagerMock->expects($this->once())->method('addError')->with('No order(s) were released from on hold status.');
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('sales/*/')->willReturnSelf();
     $this->massAction->execute();
 }
Пример #7
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());
 }
Пример #8
0
 /**
  * Add orders statistics to collection items
  *
  * @return $this
  */
 protected function _addOrdersStatistics()
 {
     $customerIds = $this->getColumnValues($this->getResource()->getIdFieldName());
     if ($this->_addOrderStatistics && !empty($customerIds)) {
         $connection = $this->orderResource->getConnection();
         $baseSubtotalRefunded = $connection->getIfNullSql('orders.base_subtotal_refunded', 0);
         $baseSubtotalCanceled = $connection->getIfNullSql('orders.base_subtotal_canceled', 0);
         $totalExpr = $this->_addOrderStatFilter ? "(orders.base_subtotal-{$baseSubtotalCanceled}-{$baseSubtotalRefunded})*orders.base_to_global_rate" : "orders.base_subtotal-{$baseSubtotalCanceled}-{$baseSubtotalRefunded}";
         $select = $this->orderResource->getConnection()->select();
         $select->from(['orders' => $this->orderResource->getTable('sales_order')], ['orders_avg_amount' => "AVG({$totalExpr})", 'orders_sum_amount' => "SUM({$totalExpr})", 'orders_count' => 'COUNT(orders.entity_id)', 'customer_id'])->where('orders.state <> ?', \Magento\Sales\Model\Order::STATE_CANCELED)->where('orders.customer_id IN(?)', $customerIds)->group('orders.customer_id');
         foreach ($this->orderResource->getConnection()->fetchAll($select) as $ordersInfo) {
             $this->getItemById($ordersInfo['customer_id'])->addData($ordersInfo);
         }
     }
     return $this;
 }
Пример #9
0
    public function testExecuteNoOrdersPutOnHold()
    {
        $order1 = $this->getMockBuilder('Magento\Sales\Model\Order')
            ->disableOriginalConstructor()
            ->getMock();
        $order2 = $this->getMockBuilder('Magento\Sales\Model\Order')
            ->disableOriginalConstructor()
            ->getMock();

        $orders = [$order1, $order2];
        $countOrders = count($orders);

        $this->orderCollectionMock->expects($this->any())
            ->method('getItems')
            ->willReturn($orders);

        $order1->expects($this->once())
            ->method('canHold')
            ->willReturn(false);

        $this->orderCollectionMock->expects($this->once())
            ->method('count')
            ->willReturn($countOrders);

        $order2->expects($this->once())
            ->method('canHold')
            ->willReturn(false);

        $this->messageManagerMock->expects($this->once())
            ->method('addError')
            ->with('No order(s) were put on hold.');

        $this->resultRedirectMock->expects($this->once())
            ->method('setPath')
            ->with('sales/*/')
            ->willReturnSelf();

        $this->massAction->executeInternal();
    }
Пример #10
0
 /**
  * Orders quantity data
  *
  * @param array $productIds
  * @return array
  */
 protected function getOrdersData(array $productIds)
 {
     $ordersSubSelect = clone $this->orderResource->getSelect();
     $ordersSubSelect->reset()->from(['oi' => $this->getTable('sales_order_item')], ['product_id', 'orders' => new \Zend_Db_Expr('COUNT(1)')])->where('oi.product_id IN (?)', $productIds)->group('oi.product_id');
     return $this->orderResource->getConnection()->fetchAssoc($ordersSubSelect);
 }
Пример #11
0
 /**
  * @param \Magento\Sales\Api\OrderRepositoryInterface $subject
  * @param \Magento\Sales\Model\ResourceModel\Order\Collection $resultOrder
  * @return \Magento\Sales\Model\ResourceModel\Order\Collection
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterGetList(\Magento\Sales\Api\OrderRepositoryInterface $subject, \Magento\Sales\Model\ResourceModel\Order\Collection $resultOrder)
 {
     /** @var  $order */
     foreach ($resultOrder->getItems() as $order) {
         $this->afterGet($subject, $order);
     }
     return $resultOrder;
 }
Пример #12
0
 /**
  * Add billing agreement filter on orders collection
  *
  * @param \Magento\Sales\Model\ResourceModel\Order\Collection $orderCollection
  * @param string|int|array $agreementIds
  * @return $this
  */
 public function addOrdersFilter(\Magento\Sales\Model\ResourceModel\Order\Collection $orderCollection, $agreementIds)
 {
     $agreementIds = is_array($agreementIds) ? $agreementIds : [$agreementIds];
     $orderCollection->getSelect()->joinInner(['pbao' => $this->getTable('paypal_billing_agreement_order')], 'main_table.entity_id = pbao.order_id', [])->where('pbao.agreement_id IN(?)', $agreementIds);
     return $this;
 }