Example #1
0
 public function testGetStoresConfigByPath()
 {
     $path = 'config/path';
     $this->_storeOne->expects($this->at(0))->method('getCode')->will($this->returnValue('code_0'));
     $this->_storeOne->expects($this->at(1))->method('getId')->will($this->returnValue(0));
     $this->_storeTwo->expects($this->at(0))->method('getCode')->will($this->returnValue('code_1'));
     $this->_storeTwo->expects($this->at(1))->method('getId')->will($this->returnValue(1));
     $this->_storeManager->expects($this->once())->method('getStores')->with(true)->will($this->returnValue([0 => $this->_storeOne, 1 => $this->_storeTwo]));
     $this->_config->expects($this->at(0))->method('getValue')->with($path, 'store', 'code_0')->will($this->returnValue(0));
     $this->_config->expects($this->at(1))->method('getValue')->with($path, 'store', 'code_1')->will($this->returnValue(1));
     $this->assertEquals([0 => 0, 1 => 1], $this->_model->getStoresConfigByPath($path));
 }
Example #2
0
 /**
  * @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\ResourceModel\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');
     }
 }
Example #4
0
 /**
  * Determine if this group is used as the create account default group
  *
  * @return bool
  */
 public function usesAsDefault()
 {
     $data = $this->_storesConfig->getStoresConfigByPath(GroupManagement::XML_PATH_DEFAULT_ID);
     if (in_array($this->getId(), $data)) {
         return true;
     }
     return false;
 }
 /**
  * Clean expired quotes (cron process)
  *
  * @return void
  */
 public function execute()
 {
     $lifetimes = $this->storesConfig->getStoresConfigByPath('sales/orders/delete_pending_after');
     foreach ($lifetimes as $storeId => $lifetime) {
         /** @var $orders \Magento\Sales\Model\ResourceModel\Order\Collection */
         $orders = $this->orderCollectionFactory->create();
         $orders->addFieldToFilter('store_id', $storeId);
         $orders->addFieldToFilter('status', Order::STATE_PENDING_PAYMENT);
         $orders->getSelect()->where(new \Zend_Db_Expr('TIME_TO_SEC(TIMEDIFF(CURRENT_TIMESTAMP, `updated_at`)) >= ' . $lifetime * 60));
         try {
             $orders->walk('cancel');
             $orders->walk('save');
         } catch (\Exception $e) {
             $this->logger->error('Error cancelling deprecated orders: ' . $e->getMessage());
         }
     }
 }
Example #6
0
 /**
  * Clean expired quotes (cron process)
  *
  * @param \Magento\Cron\Model\Schedule $schedule
  * @return $this
  */
 public function cleanExpiredQuotes($schedule)
 {
     $this->_eventManager->dispatch('clear_expired_quotes_before', array('sales_observer' => $this));
     $lifetimes = $this->_storesConfig->getStoresConfigByPath('checkout/cart/delete_quote_after');
     foreach ($lifetimes as $storeId => $lifetime) {
         $lifetime *= 86400;
         /** @var $quotes \Magento\Sales\Model\Resource\Quote\Collection */
         $quotes = $this->_quoteCollectionFactory->create();
         $quotes->addFieldToFilter('store_id', $storeId);
         $quotes->addFieldToFilter('updated_at', array('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');
     }
     return $this;
 }