Exemplo n.º 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));
 }
 /**
  * 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');
     }
 }
Exemplo n.º 3
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());
         }
     }
 }
Exemplo n.º 5
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;
 }