getValue($query) == 0) { die; } $carts = ReminderController::getAbandonedCart($wich_remind, $id_shop); $templates = TemplateController::getActiveTemplate($id_shop); if (!$templates) { die('No active template ...'); } $x = 0; $sent = array(); $first = true; $mails = ''; if (!isset(Context::getContext()->link)) { Context::getContext()->link = new Link(); } foreach ($carts as $arr_cart) { Context::getContext()->cart = new Cart($arr_cart['id_cart']); $iso = Language::getIsoById($arr_cart['id_lang']); $id_lang = $arr_cart['id_lang']; if (!isset($templates[$arr_cart['id_shop']][$arr_cart['id_lang']][$wich_remind])) { $id_lang = Configuration::get('PS_LANG_DEFAULT'); $iso = Language::getIsoById($id_lang); } $content = Tools::file_get_contents(_PS_MODULE_DIR_.'cartabandonmentpro/mails/'.$iso.'/'.$templates[$arr_cart['id_shop']][$id_lang][$wich_remind]['id'].'.html'); $content = CartAbandonmentProTemplate::editTemplate($content, $wich_remind, $arr_cart['id_cart'], $id_lang, $id_shop); if (!$content) { continue; } $discounts = DiscountsController::getDiscounts($wich_remind, $id_shop); $cart2 = new Cart($arr_cart['id_cart']); if (!isset(Context::getContext()->currency->id)) { Context::getContext()->currency = new Currency($cart2->id_currency, null, $id_shop); } $id_address = Address::getFirstCustomerAddressId($arr_cart['id_customer']); if ($cart2->id_address_delivery != $id_address) { $cart2->id_address_delivery = $id_address; $cart2->id_address_invoice = $id_address; $cart2->save(); } $total_cart = $cart2->getOrderTotal(); $i = 0; $disc = false; $disc_valid = false; $type = false; $min = false; $max = false; $value = false; if (is_array($discounts) && count($discounts) > 0) { foreach ($discounts as $discount) { if ($total_cart >= $discount['min_amount']) { $disc = $i; $disc_valid = $discount['valid_value']; $type = $discount['type']; $min = $discount['min_amount']; $max = $discount['max_amount']; $value = $discount['value']; } $i++; } if ($value > 0 || $type == 'shipping') { $with_taxes = Configuration::get('CARTABAND_DISCOUNT_WITH_TAXES_'.$wich_remind); $voucher = DiscountsController::createDiscount($arr_cart['id_customer'], $value, $disc_valid, $type, $min, $with_taxes); $content = CartAbandonmentProTemplate::editDiscount($voucher, $content, $id_lang, $id_shop); } else { $content = str_replace('%DISCOUNT_TXT%', "", $content); } } else { $content = str_replace('%DISCOUNT_TXT%', "", $content); } $title = strip_tags(CartAbandonmentProTemplate::editTitleBeforeSending($templates[$arr_cart['id_shop']][$id_lang][$wich_remind]['name'], $arr_cart['id_cart'], $id_lang)); $fp = fopen(_PS_MODULE_DIR_.'cartabandonmentpro/mails/' . $iso . '/send.html', 'w+'); fwrite($fp, $content); fclose($fp); $fp = fopen(_PS_MODULE_DIR_.'cartabandonmentpro/mails/' . $iso . '/send.txt', 'w+'); $content = preg_replace("/(\s){2,}/", "\r\n\r\n", trim(strip_tags($content))); fwrite($fp, $content); fclose($fp); $mail = Mail::Send($id_lang, 'send', $title, array(), $arr_cart['email'], null, null, null, null, null, _PS_MODULE_DIR_.'cartabandonmentpro/mails/'); unlink(_PS_MODULE_DIR_.'cartabandonmentpro/mails/' . $iso . '/send.html'); unlink(_PS_MODULE_DIR_.'cartabandonmentpro/mails/' . $iso . '/send.txt'); if ($mail) { if (!$first) { $mails .= ';'; } $mails .= $arr_cart['email']; $first = false; $justSent = array('id_customer'=> $arr_cart['id_customer'], 'id_cart'=> $arr_cart['id_cart'], 'firstname' => $arr_cart['firstname'], 'lastname' => $arr_cart['lastname'], 'email' => $arr_cart['email']); $sent[] = $justSent; Db::getInstance()->Execute("INSERT INTO "._DB_PREFIX_."cartabandonment_remind VALUES (NULL, " . (int) $wich_remind . ", " . (int) $arr_cart['id_cart'] . ", NOW(), 0, 0, 0)"); $x++; } } unset($justSent, $carts, $content, $title, $templates); $str = ''; $str .= '

'.$x.' mails have been sent.



'; $str .= ''; foreach ($sent as $s) { $str .= ''; } $str .= '
ID CUSTOMERID CARTFIRSTNAMELASTNAMEEMAIL
'.$s['id_customer'].''.$s['id_cart'].''.$s['firstname'].''.$s['lastname'].''.$s['email'].'
'; die($str); } public static function visualize() { $wichRemind = Tools::getValue('wichRemind'); $id_cart = Tools::getValue('id_cart'); $token = Tools::getValue('token_cart'); if ($token == md5(_COOKIE_KEY_.'recover_cart_'.$id_cart)) { $query = "UPDATE "._DB_PREFIX_."cartabandonment_remind SET visualize = 1 WHERE wich_remind = ".(int)$wichRemind." AND id_cart = ".(int)$id_cart; Db::getInstance()->Execute($query); } header('Content-Type: image/png'); echo base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII='); } public static function redirectLink() { $id_cart = Tools::getValue('id_cart'); $token = Tools::getValue('token_cart'); $wichRemind = Tools::getValue('wichRemind'); $link = Tools::getValue('link'); if (!$id_cart || !$wichRemind) { Tools::redirect(__PS_BASE_URI__.'order.php?step=0'); } if ($token != md5(_COOKIE_KEY_.'recover_cart_'.(int)$id_cart)) { Tools::redirect(__PS_BASE_URI__.'order.php?step=0'); } // Get GAnalytics tags if needed $params = array(); if (Tools::getValue('utm_source')) { $params['utm_source'] = Tools::getValue('utm_source'); } if (Tools::getValue('utm_medium')) { $params['utm_medium'] = Tools::getValue('utm_medium'); } if (Tools::getValue('utm_campaign')) { $params['utm_campaign'] = Tools::getValue('utm_campaign'); } switch ($link) { case 'cart': $query = ' SELECT `lastname`, `firstname`, `passwd`, `email`, `id_currency`, `id_cart`, ca.id_customer, cu.secure_key FROM `'._DB_PREFIX_.'customer` `cu` LEFT JOIN `'._DB_PREFIX_.'cart` `ca` ON `ca`.`id_customer` = `cu`.`id_customer` AND `ca`.`secure_key` = `cu`.`secure_key` WHERE `ca`.`id_cart`='.(int)$id_cart; $result = DB::getInstance()->getRow($query); if (!empty($result)) { $customer = new Customer($result['id_customer']); $context = Context::getContext(); $context->cookie->id_cart = $id_cart; $context->cookie->id_customer = (int)$customer->id; $context->cookie->customer_lastname = $customer->lastname; $context->cookie->customer_firstname = $customer->firstname; $context->cookie->logged = 1; $context->cookie->is_guest = $customer->is_guest; $context->cookie->passwd = $customer->passwd; $context->cookie->email = $customer->email; //$this->context = $context; $query = "UPDATE "._DB_PREFIX_."cartabandonment_remind SET click_cart = 1 WHERE wich_remind = ".(int)$wichRemind." AND id_cart = ".(int)$id_cart; Db::getInstance()->Execute($query); } Tools::redirect(__PS_BASE_URI__.'order.php?step=0&'.http_build_query($params)); case 'shop': if ($id_cart && $wichRemind) { $query = " UPDATE "._DB_PREFIX_."cartabandonment_remind SET click = 1 WHERE wich_remind = ".(int)$wichRemind." AND id_cart = ".(int)$id_cart; Db::getInstance()->Execute($query); } Tools::redirect(__PS_BASE_URI__.'index.php?'.http_build_query($params)); case 'unsubscribe': $id_customer = Db::getInstance()->getValue(' SELECT c.id_customer FROM `' . _DB_PREFIX_ . 'cart` ca JOIN ' . _DB_PREFIX_ . 'customer c ON ca.id_customer = c.id_customer WHERE ca.id_cart = ' . (int)$id_cart); if (!$id_customer) { die('Error'); } $query = "INSERT INTO "._DB_PREFIX_."cartabandonment_unsubscribe VALUES (".(int) $id_customer.");"; if (Db::getInstance()->Execute($query)) { die('OK'); } else { die('Error'); } default: Tools::redirect(__PS_BASE_URI__.'order.php?step=0&'.http_build_query($params)); } } }