public function toOptionArray()
 {
     //        $code = Mage::getSingleton('adminhtml/config_data')->getStore();
     //        $storeId = Mage::getModel('core/store')->load($code)->getId();
     $storeId = null;
     $hasCoupon = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::SEND_COUPON);
     if ($hasCoupon) {
         $active = -$this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::MAXTIMES);
     } else {
         $active = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::MAXTIMES);
     }
     $options = array(array('value' => 0, 'label' => __('No')), array('value' => $active + ($hasCoupon ? -1 : 1), 'label' => __('Yes')));
     return $options;
 }
 public function execute()
 {
     $this->_logger->info(__METHOD__);
     $quoteId = (int) $this->getRequest()->getParam('id', false);
     $this->_logger->info("quoteid {$quoteId}");
     if ($quoteId) {
         $quote = $this->_objectManager->create('\\Magento\\Quote\\Model\\Quote')->load($quoteId);
         $storeId = $quote->getStoreId();
         $url = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::PAGE, $storeId);
         $this->_logger->info("url {$url}");
         $token = (int) $this->getRequest()->getParam('token', false);
         if (!$token || $token != $quote->getEbizmartsAbandonedcartToken()) {
             $this->messageManager->addNotice("Invalid token");
             $this->_redirect($url);
         } else {
             $coupon = $this->getRequest()->getParam('coupon', false);
             if ($coupon) {
                 $quote->setCouponCode($coupon);
             }
             $quote->setEbizmartsAbandonedcartFlag(1);
             $quote->save();
             if (!$quote->getCustomerId()) {
                 $this->_getCheckoutSession()->setQuoteId($quote->getId());
             }
             if ($this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::AUTOLOGIN, $storeId)) {
                 if ($quote->getCustomerId()) {
                     $customerSession = $this->_getCustomerSession();
                     if (!$customerSession->isLoggedIn()) {
                         $customerSession->loginById($quote->getCustomerId());
                     }
                     $this->_redirect('customer/account');
                 }
             }
             $this->_redirect($url);
         }
     }
 }
 /**
  * @param $currentCount
  * @return mixed
  */
 protected function _getTemplateId($currentCount, $abTesting = false, $store)
 {
     $ret = NULL;
     switch ($currentCount) {
         case 0:
             if ($abTesting) {
                 $ret = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::AB_TESTING_FIRST_EMAIL, $store);
             } else {
                 $ret = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::FIRST_EMAIL_TEMPLATE_XML_PATH, $store);
             }
             break;
         case 1:
             if ($abTesting) {
                 $ret = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::AB_TESTING_SECOND_EMAIL, $store);
             } else {
                 $ret = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::SECOND_EMAIL_TEMPLATE_XML_PATH, $store);
             }
             break;
         case 2:
             if ($abTesting) {
                 $ret = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::AB_TESTING_THIRD_EMAIL, $store);
             } else {
                 $ret = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::THIRD_EMAIL_TEMPLATE_XML_PATH, $store);
             }
             break;
         case 3:
             if ($abTesting) {
                 $ret = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::AB_TESTING_FOURTH_EMAIL, $store);
             } else {
                 $ret = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::FOURTH_EMAIL_TEMPLATE_XML_PATH, $store);
             }
             break;
         case 4:
             if ($abTesting) {
                 $ret = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::AB_TESTING_FIFTH_EMAIL, $store);
             } else {
                 $ret = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::FIFTH_EMAIL_TEMPLATE_XML_PATH, $store);
             }
             break;
     }
     return $ret;
 }