コード例 #1
0
ファイル: Grid.php プロジェクト: aiesh/magento2
 /**
  * Prepare related orders collection
  *
  * @param array|string $fieldsToSelect
  * @return void
  */
 protected function _prepareRelatedOrders($fieldsToSelect = '*')
 {
     if (null === $this->_relatedOrders) {
         $this->_orderCollection->addFieldToSelect($fieldsToSelect)->addFieldToFilter('customer_id', $this->_registry->registry(RegistryConstants::CURRENT_CUSTOMER_ID))->setOrder('entity_id', 'desc');
         $this->_relatedOrders = $this->_recurringCollectionFilter->byIds($this->_orderCollection, $this->_recurringPayment->getId());
     }
 }
コード例 #2
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);
 }
コード例 #3
0
ファイル: Collection.php プロジェクト: shazal/magento2
 /**
  * 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\Sales\Model\Resource\EntitySnapshot $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\Resource\Report\OrderFactory $reportOrderFactory
  * @param null $connection
  * @param \Magento\Framework\Model\Resource\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\Sales\Model\Resource\EntitySnapshot $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\Resource\Report\OrderFactory $reportOrderFactory, $connection = null, \Magento\Framework\Model\Resource\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
ファイル: Observer.php プロジェクト: shabbirvividads/magento2
 /**
  * Set base grand total of order to registry
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return \Magento\GoogleAdwords\Model\Observer
  */
 public function setConversionValue(\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;
 }
コード例 #5
0
ファイル: SidebarTest.php プロジェクト: nja78/magento2
 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());
 }
コード例 #6
0
ファイル: Collection.php プロジェクト: nja78/magento2
 /**
  * Add orders statistics to collection items
  *
  * @return $this
  */
 protected function _addOrdersStatistics()
 {
     $customerIds = $this->getColumnValues($this->getResource()->getIdFieldName());
     if ($this->_addOrderStatistics && !empty($customerIds)) {
         $adapter = $this->orderResource->getConnection();
         $baseSubtotalRefunded = $adapter->getIfNullSql('orders.base_subtotal_refunded', 0);
         $baseSubtotalCanceled = $adapter->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;
 }
コード例 #7
0
ファイル: Collection.php プロジェクト: aiesh/magento2
 /**
  * Get SQL for get record count
  *
  * @return \Magento\Framework\DB\Select
  */
 public function getSelectCountSql()
 {
     if ($this->getIsCustomerMode()) {
         $this->_renderFilters();
         $unionSelect = clone $this->getSelect();
         $unionSelect->reset(\Zend_Db_Select::ORDER);
         $unionSelect->reset(\Zend_Db_Select::LIMIT_COUNT);
         $unionSelect->reset(\Zend_Db_Select::LIMIT_OFFSET);
         $countSelect = clone $this->getSelect();
         $countSelect->reset();
         $countSelect->from(array('a' => $unionSelect), 'COUNT(*)');
     } else {
         $countSelect = parent::getSelectCountSql();
     }
     return $countSelect;
 }
コード例 #8
0
ファイル: Agreement.php プロジェクト: aiesh/magento2
 /**
  * Add billing agreement filter on orders collection
  *
  * @param \Magento\Sales\Model\Resource\Order\Collection $orderCollection
  * @param string|int|array $agreementIds
  * @return $this
  */
 public function addOrdersFilter(\Magento\Sales\Model\Resource\Order\Collection $orderCollection, $agreementIds)
 {
     $agreementIds = is_array($agreementIds) ? $agreementIds : array($agreementIds);
     $orderCollection->getSelect()->joinInner(array('pbao' => $this->getTable('paypal_billing_agreement_order')), 'main_table.entity_id = pbao.order_id', array())->where('pbao.agreement_id IN(?)', $agreementIds);
     return $this;
 }
コード例 #9
0
ファイル: Collection.php プロジェクト: nja78/magento2
 /**
  * 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);
 }