/** * {@inheritdoc} */ public function getList(\Magento\Framework\Api\SearchCriteria $searchCriteria) { $quoteCollection = $this->quoteCollectionFactory->create(); $this->extensionAttributesJoinProcessor->process($quoteCollection); $searchData = $this->searchResultsDataFactory->create(); $searchData->setSearchCriteria($searchCriteria); $searchData->setItems($quoteCollection->getItems()); return $searchData; }
/** * @param array $lifetimes * @param array $additionalFilterFields * @dataProvider cleanExpiredQuotesDataProvider */ public function testExecute($lifetimes, $additionalFilterFields) { $this->storesConfigMock->expects($this->once())->method('getStoresConfigByPath')->with($this->equalTo('checkout/cart/delete_quote_after'))->will($this->returnValue($lifetimes)); $quotesMock = $this->getMockBuilder('Magento\\Quote\\Model\\Resource\\Quote\\Collection')->disableOriginalConstructor()->getMock(); $this->quoteFactoryMock->expects($this->exactly(count($lifetimes)))->method('create')->will($this->returnValue($quotesMock)); $quotesMock->expects($this->exactly((3 + count($additionalFilterFields)) * count($lifetimes)))->method('addFieldToFilter'); if (!empty($lifetimes)) { $quotesMock->expects($this->exactly(count($lifetimes)))->method('walk')->with('delete'); } $this->observer->setExpireQuotesAdditionalFilterFields($additionalFilterFields); $this->observer->execute(); }
/** * Clean expired quotes (cron process) * * @return void */ public function execute() { $lifetimes = $this->storesConfig->getStoresConfigByPath('checkout/cart/delete_quote_after'); foreach ($lifetimes as $storeId => $lifetime) { $lifetime *= self::LIFETIME; /** @var $quotes \Magento\Quote\Model\Resource\Quote\Collection */ $quotes = $this->quoteCollectionFactory->create(); $quotes->addFieldToFilter('store_id', $storeId); $quotes->addFieldToFilter('updated_at', ['to' => date("Y-m-d", time() - $lifetime)]); $quotes->addFieldToFilter('is_active', 0); foreach ($this->getExpireQuotesAdditionalFilterFields() as $field => $condition) { $quotes->addFieldToFilter($field, $condition); } $quotes->walk('delete'); } }