/**
  * Search for orders to review per website.
  */
 public function searchOrdersForReview()
 {
     $websites = $this->helper->getwebsites(true);
     foreach ($websites as $website) {
         $apiEnabled = $this->helper->isEnabled($website);
         if ($apiEnabled && $this->helper->getWebsiteConfig(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_SYNC_ORDER_ENABLED, $website) && $this->helper->getOrderStatus($website) && $this->helper->getDelay($website)) {
             $storeIds = $website->getStoreIds();
             if (empty($storeIds)) {
                 continue;
             }
             $orderStatusFromConfig = $this->helper->getOrderStatus($website);
             $delayInDays = $this->helper->getDelay($website);
             $campaignCollection = $this->campaignCollection->create()->addFieldToFilter('event_name', 'Order Review');
             $campaignOrderIds = $campaignCollection->getColumnValues('order_increment_id');
             $fromTime = $this->date;
             $fromTime->subDay($delayInDays);
             $toTime = clone $fromTime;
             $to = $toTime->toString('YYYY-MM-dd HH:mm:ss');
             $from = $fromTime->subHour(2)->toString('YYYY-MM-dd HH:mm:ss');
             $created = ['from' => $from, 'to' => $to, 'date' => true];
             $collection = $this->orderCollection->create()->addFieldToFilter('main_table.status', $orderStatusFromConfig)->addFieldToFilter('main_table.created_at', $created)->addFieldToFilter('main_table.store_id', ['in' => $storeIds]);
             if (!empty($campaignOrderIds)) {
                 $collection->addFieldToFilter('main_table.increment_id', ['nin' => $campaignOrderIds]);
             }
             //process rules on collection
             $collection = $this->rulesFactory->create()->process($collection, \Dotdigitalgroup\Email\Model\Rules::REVIEW, $website->getId());
             if ($collection->getSize()) {
                 $this->reviewCollection[$website->getId()] = $collection;
             }
         }
     }
 }
 /**
  * Execute method.
  *
  * @return $this
  */
 public function execute()
 {
     $id = $this->getRequest()->getParam('ruleid');
     $attribute = $this->getRequest()->getParam('attribute');
     $arrayKey = $this->getRequest()->getParam('arraykey');
     $conditionName = $this->getRequest()->getParam('condition');
     $valueName = $this->getRequest()->getParam('value');
     if ($arrayKey && $id && $attribute && $conditionName && $valueName) {
         $rule = $this->rulesFactory->create()->load($id);
         //rule not found
         if (!$rule->getId()) {
             $this->http->getHeaders()->clearHeaders();
             return $this->http->setHeader('Content-Type', 'application/json')->setBody('Rule not found!');
         }
         $conditions = $rule->getCondition();
         $condition = $conditions[$arrayKey];
         $selectedConditions = $condition['conditions'];
         $selectedValues = $condition['cvalue'];
         $type = $this->ruleType->getInputType($attribute);
         $conditionOptions = $this->ruleCondition->getInputTypeOptions($type);
         $response['condition'] = str_replace('value="' . $selectedConditions . '"', 'value="' . $selectedConditions . '"' . 'selected="selected"', $this->getOptionHtml('conditions', $conditionName, $conditionOptions));
         $elmType = $this->ruleValue->getValueElementType($attribute);
         if ($elmType == 'select' or $selectedConditions == 'null') {
             $isEmpty = false;
             if ($selectedConditions == 'null') {
                 $isEmpty = true;
             }
             $valueOptions = $this->ruleValue->getValueSelectOptions($attribute, $isEmpty);
             $response['cvalue'] = str_replace('value="' . $selectedValues . '"', 'value="' . $selectedValues . '"' . 'selected="selected"', $this->getOptionHtml('cvalue', $valueName, $valueOptions));
         } elseif ($elmType == 'text') {
             $html = "<input style='width:160px' title='cvalue' name='{$valueName}' value='{$selectedValues}'/>";
             $response['cvalue'] = $html;
         }
         $this->http->getHeaders()->clearHeaders();
         $this->http->setHeader('Content-Type', 'application/json')->setBody($this->jsonEncoder->encode($response));
     }
 }
 /**
  * @param null $from
  * @param null $to
  * @param bool|false $guest
  * @param int $storeId
  *
  * @return $this
  */
 protected function _getStoreQuotes($from = null, $to = null, $guest = false, $storeId = 0)
 {
     $updated = ['from' => $from, 'to' => $to, 'date' => true];
     $salesCollection = $this->_quoteCollection->create()->addFieldToFilter('is_active', 1)->addFieldToFilter('items_count', ['gt' => 0])->addFieldToFilter('customer_email', ['neq' => ''])->addFieldToFilter('store_id', $storeId)->addFieldToFilter('main_table.updated_at', $updated);
     //guests
     if ($guest) {
         $salesCollection->addFieldToFilter('main_table.customer_id', ['null' => true]);
     } else {
         //customers
         $salesCollection->addFieldToFilter('main_table.customer_id', ['notnull' => true]);
     }
     //process rules on collection
     $ruleModel = $this->_rulesFactory->create();
     $websiteId = $this->_storeManager->getStore($storeId)->getWebsiteId();
     $salesCollection = $ruleModel->process($salesCollection, \Dotdigitalgroup\Email\Model\Rules::ABANDONED, $websiteId);
     return $salesCollection;
 }