Esempio n. 1
0
 /**
  * @param int $direction
  * @param string $expectedDirection
  * @dataProvider getListSuccessDataProvider
  */
 public function testGetListSuccess($direction, $expectedDirection)
 {
     $searchResult = $this->getMock('\\Magento\\Quote\\Api\\Data\\CartSearchResultsInterface', [], [], '', false);
     $searchCriteriaMock = $this->getMock('\\Magento\\Framework\\Api\\SearchCriteria', [], [], '', false);
     $cartMock = $this->getMock('Magento\\Payment\\Model\\Cart', [], [], '', false);
     $filterMock = $this->getMock('\\Magento\\Framework\\Api\\Filter', [], [], '', false);
     $pageSize = 10;
     $this->searchResultsDataFactory->expects($this->once())->method('create')->will($this->returnValue($searchResult));
     $searchResult->expects($this->once())->method('setSearchCriteria');
     $filterGroupMock = $this->getMock('\\Magento\\Framework\\Api\\Search\\FilterGroup', [], [], '', false);
     $searchCriteriaMock->expects($this->any())->method('getFilterGroups')->will($this->returnValue([$filterGroupMock]));
     //addFilterGroupToCollection() checks
     $filterGroupMock->expects($this->any())->method('getFilters')->will($this->returnValue([$filterMock]));
     $filterMock->expects($this->once())->method('getField')->will($this->returnValue('store_id'));
     $filterMock->expects($this->any())->method('getConditionType')->will($this->returnValue('eq'));
     $filterMock->expects($this->once())->method('getValue')->will($this->returnValue('filter_value'));
     //back in getList()
     $this->quoteCollectionMock->expects($this->once())->method('getSize')->willReturn($pageSize);
     $searchResult->expects($this->once())->method('setTotalCount')->with($pageSize);
     $sortOrderMock = $this->getMockBuilder('Magento\\Framework\\Api\\SortOrder')->setMethods(['getField', 'getDirection'])->disableOriginalConstructor()->getMock();
     //foreach cycle
     $searchCriteriaMock->expects($this->once())->method('getSortOrders')->will($this->returnValue([$sortOrderMock]));
     $sortOrderMock->expects($this->once())->method('getField')->will($this->returnValue('id'));
     $sortOrderMock->expects($this->once())->method('getDirection')->will($this->returnValue($direction));
     $this->quoteCollectionMock->expects($this->once())->method('addOrder')->with('id', $expectedDirection);
     $searchCriteriaMock->expects($this->once())->method('getCurrentPage')->will($this->returnValue(1));
     $searchCriteriaMock->expects($this->once())->method('getPageSize')->will($this->returnValue(10));
     $this->quoteCollectionMock->expects($this->once())->method('setCurPage')->with(1);
     $this->quoteCollectionMock->expects($this->once())->method('setPageSize')->with(10);
     $this->extensionAttributesJoinProcessorMock->expects($this->once())->method('process')->with($this->isInstanceOf('\\Magento\\Quote\\Model\\Resource\\Quote\\Collection'));
     $this->quoteCollectionMock->expects($this->once())->method('getItems')->willReturn([$cartMock]);
     $searchResult->expects($this->once())->method('setItems')->with([$cartMock]);
     $this->assertEquals($searchResult, $this->model->getList($searchCriteriaMock));
 }
Esempio n. 2
0
 /**
  * Get select count sql
  *
  * @return \Zend_Db_Select
  */
 public function getSelectCountSql()
 {
     if ($this->_selectCountSqlType == self::SELECT_COUNT_SQL_TYPE_CART) {
         $countSelect = clone $this->quoteResource->getSelect();
         $countSelect->reset()->from(['quote_item_table' => $this->getTable('quote_item')], ['COUNT(DISTINCT quote_item_table.product_id)'])->join(['quote_table' => $this->getTable('quote')], 'quote_table.entity_id = quote_item_table.quote_id AND quote_table.is_active = 1', []);
         return $countSelect;
     }
     $countSelect = clone $this->getSelect();
     $countSelect->reset(\Zend_Db_Select::ORDER);
     $countSelect->reset(\Zend_Db_Select::LIMIT_COUNT);
     $countSelect->reset(\Zend_Db_Select::LIMIT_OFFSET);
     $countSelect->reset(\Zend_Db_Select::COLUMNS);
     $countSelect->reset(\Zend_Db_Select::GROUP);
     $countSelect->reset(\Zend_Db_Select::HAVING);
     $countSelect->columns("count(DISTINCT e.entity_id)");
     return $countSelect;
 }
 /**
  * Adds a specified filter group to the specified quote collection.
  *
  * @param FilterGroup $filterGroup The filter group.
  * @param QuoteCollection $collection The quote collection.
  * @return void
  * @throws InputException The specified filter group or quote collection does not exist.
  */
 protected function addFilterGroupToCollection(FilterGroup $filterGroup, QuoteCollection $collection)
 {
     $fields = [];
     $conditions = [];
     foreach ($filterGroup->getFilters() as $filter) {
         $fields[] = $filter->getField();
         $condition = $filter->getConditionType() ? $filter->getConditionType() : 'eq';
         $conditions[] = [$condition => $filter->getValue()];
     }
     if ($fields) {
         $collection->addFieldToFilter($fields, $conditions);
     }
 }
Esempio n. 4
0
 /**
  * @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory
  * @param \Psr\Log\LoggerInterface $logger
  * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
  * @param \Magento\Framework\Event\ManagerInterface $eventManager
  * @param \Magento\Framework\Model\Resource\Db\VersionControl\Snapshot $entitySnapshot
  * @param \Magento\Customer\Model\Resource\Customer $customerResource
  * @param \Zend_Db_Adapter_Abstract $connection
  * @param \Magento\Framework\Model\Resource\Db\AbstractDb $resource
  */
 public function __construct(\Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Framework\Model\Resource\Db\VersionControl\Snapshot $entitySnapshot, \Magento\Customer\Model\Resource\Customer $customerResource, $connection = null, \Magento\Framework\Model\Resource\Db\AbstractDb $resource = null)
 {
     parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $entitySnapshot, $connection, $resource);
     $this->customerResource = $customerResource;
 }
Esempio n. 5
0
 /**
  * @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\Catalog\Model\Resource\Product\Collection $productResource
  * @param \Magento\Customer\Model\Resource\Customer $customerResource
  * @param null $connection
  * @param \Magento\Framework\Model\Resource\Db\AbstractDb $resource
  */
 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\Catalog\Model\Resource\Product\Collection $productResource, \Magento\Customer\Model\Resource\Customer $customerResource, $connection = null, \Magento\Framework\Model\Resource\Db\AbstractDb $resource = null)
 {
     parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
     $this->_productResource = $productResource;
     $this->_customerResource = $customerResource;
 }
Esempio n. 6
0
 /**
  * Add data fetched from another database
  *
  * @return $this
  */
 protected function _afterLoad()
 {
     parent::_afterLoad();
     $items = $this->getItems();
     $productIds = [];
     foreach ($items as $item) {
         $productIds[] = $item->getProductId();
     }
     $productData = $this->getProductData($productIds);
     $orderData = $this->getOrdersData($productIds);
     foreach ($items as $item) {
         $item->setId($item->getProductId());
         $item->setPrice($productData[$item->getProductId()]['price'] * $item->getBaseToGlobalRate());
         $item->setName($productData[$item->getProductId()]['name']);
         $item->setOrders(0);
         if (isset($orderData[$item->getProductId()])) {
             $item->setOrders($orderData[$item->getProductId()]['orders']);
         }
     }
     return $this;
 }