/** * Transform loyalty point to a voucher */ public function processTransformPoints() { $customer_points = (int) LoyaltyModule::getPointsByCustomer((int) $this->context->customer->id); if ($customer_points > 0) { /* Generate a voucher code */ $voucher_code = null; do { $voucher_code = 'FID' . rand(1000, 100000); } while (CartRule::cartRuleExists($voucher_code)); // Voucher creation and affectation to the customer $cart_rule = new CartRule(); $cart_rule->code = $voucher_code; $cart_rule->id_customer = (int) $this->context->customer->id; $cart_rule->reduction_currency = (int) $this->context->currency->id; $cart_rule->reduction_amount = LoyaltyModule::getVoucherValue((int) $customer_points); $cart_rule->quantity = 1; $cart_rule->quantity_per_user = 1; // If merchandise returns are allowed, the voucher musn't be usable before this max return date $date_from = Db::getInstance()->getValue(' SELECT UNIX_TIMESTAMP(date_add) n FROM ' . _DB_PREFIX_ . 'loyalty WHERE id_cart_rule = 0 AND id_customer = ' . (int) $this->context->cookie->id_customer . ' ORDER BY date_add DESC'); if (Configuration::get('PS_ORDER_RETURN')) { $date_from += 60 * 60 * 24 * (int) Configuration::get('PS_ORDER_RETURN_NB_DAYS'); } $cart_rule->date_from = date('Y-m-d H:i:s', $date_from); $cart_rule->date_to = date('Y-m-d H:i:s', strtotime($cart_rule->date_from . ' +1 year')); $cart_rule->minimum_amount = (double) Configuration::get('PS_LOYALTY_MINIMAL'); $cart_rule->active = 1; $categories = Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY'); if ($categories != '' && $categories != 0) { $categories = explode(',', Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY')); } else { die(Tools::displayError()); } $languages = Language::getLanguages(true); $default_text = Configuration::get('PS_LOYALTY_VOUCHER_DETAILS', (int) Configuration::get('PS_LANG_DEFAULT')); foreach ($languages as $language) { $text = Configuration::get('PS_LOYALTY_VOUCHER_DETAILS', (int) $language['id_lang']); $cart_rule->name[(int) $language['id_lang']] = $text ? strval($text) : strval($default_text); } if (is_array($categories) && count($categories)) { $cart_rule->add(true, false, $categories); } else { $cart_rule->add(); } // Register order(s) which contributed to create this voucher LoyaltyModule::registerDiscount($cart_rule); Tools::redirect($this->context->link->getModuleLink('loyalty', 'default', array('process' => 'summary'))); } }
/** * @deprecated 1.5.0.1 */ public static function discountExists($discountName, $id_discount = 0) { return parent::cartRuleExists($discountName); }
private static function create_split_discount($amount, $id_customer, $id_currency, $id_carts) { ${"GLOBALS"}["lpfswanqwex"] = "code"; ${"GLOBALS"}["iuztfsobjr"] = "id_customer"; $ezdxpbfeg = "languages"; ${"GLOBALS"}["rnwtmfeg"] = "amount"; $wbglpjrhabt = "id_carts"; $wvwcmnzwlplf = "id_currency"; global $cookie; ${${"GLOBALS"}["lpfswanqwex"]} = "split discount-" . ${${"GLOBALS"}["qnutktejfsm"]}; ${"GLOBALS"}["rommybk"] = "languages"; ${"GLOBALS"}["pjlvntsji"] = "discount"; $zwjuqmhrgn = "timeinfo"; if (CartRule::cartRuleExists(${${"GLOBALS"}["thjhsxt"]})) { ${"GLOBALS"}["mutlcfyzn"] = "cartRuleInfo"; $efjrrcbmmc = "code"; ${"GLOBALS"}["dvulqgqhgy"] = "cartRuleInfo"; ${${"GLOBALS"}["dvulqgqhgy"]} = CartRule::getCartsRuleByCode(${$efjrrcbmmc}, $cookie->id_lang); if (!empty(${${"GLOBALS"}["mutlcfyzn"]})) { ${"GLOBALS"}["dutusymn"] = "id_currency"; $ugjhbkcy = "id_customer"; $vhkwbuk = "discount"; ${"GLOBALS"}["wtngbnwjou"] = "amount"; ${$vhkwbuk} = new CartRule((int) ${${"GLOBALS"}["exnqrgnk"]}[0]["id_cart_rule"]); $discount->reduction_amount = Tools::ps_round(abs(${${"GLOBALS"}["wtngbnwjou"]}), 2); $discount->id_customer = ${$ugjhbkcy}; $discount->reduction_currency = ${${"GLOBALS"}["dutusymn"]}; ${"GLOBALS"}["lftybruvzf"] = "discount"; $discount->save(); return ${${"GLOBALS"}["lftybruvzf"]}; } } ${$zwjuqmhrgn} = AgileHelper::getDbDateTime(1, "DAY"); ${${"GLOBALS"}["rommybk"]} = Language::getLanguages(); ${${"GLOBALS"}["pjlvntsji"]} = new CartRule(); $discount->code = "split discount-" . ${$wbglpjrhabt}; $discount->description = $discount->code; $discount->id_customer = ${${"GLOBALS"}["iuztfsobjr"]}; $discount->id_group = 0; $discount->reduction_currency = ${${"GLOBALS"}["lppjvltcyn"]}; $discount->reduction_amount = Tools::ps_round(abs(${${"GLOBALS"}["rnwtmfeg"]}), 2); $discount->minimum_amount_currency = ${$wvwcmnzwlplf}; $discount->quantity = 1; $discount->quantity_per_user = 1; $discount->date_from = ${${"GLOBALS"}["vwwosyf"]}["timenow"]; $discount->date_to = ${${"GLOBALS"}["vwwosyf"]}["newtime"]; $discount->partial_use = 0; $discount->include_tax = 1; $discount->active = 1; $discount->cart_display = 0; $discount->date_add = ${${"GLOBALS"}["vwwosyf"]}["timenow"]; $discount->date_upd = ${${"GLOBALS"}["vwwosyf"]}["timenow"]; foreach (${$ezdxpbfeg} as ${${"GLOBALS"}["ehrifiqsh"]}) { $edrgrgkvw = "fields"; $hfpvhmutci = "field"; ${${"GLOBALS"}["samttghly"]} = array("name"); $gigicrqhcvtw = "language"; $vuqkbfsbtw = "field"; foreach (${$edrgrgkvw} as ${$vuqkbfsbtw}) { $discount->{${$hfpvhmutci}}[intval(${$gigicrqhcvtw}["id_lang"])] = $discount->code; } } $discount->save(); return ${${"GLOBALS"}["gwtztyfxho"]}; }
/** * Transform loyalty point to a voucher */ public function processTransformPoints() { $customer_points = (int) LoyaltyModule::getPointsByCustomer((int) $this->context->customer->id); if ($customer_points > 0) { /* Generate a voucher code */ $voucher_code = null; do { $voucher_code = 'FID' . rand(1000, 100000); } while (CartRule::cartRuleExists($voucher_code)); // Voucher creation and affectation to the customer $cart_rule = new CartRule(); $cart_rule->code = $voucher_code; $cart_rule->id_customer = (int) $this->context->customer->id; $cart_rule->reduction_currency = (int) $this->context->currency->id; $cart_rule->reduction_amount = LoyaltyModule::getVoucherValue((int) $customer_points); $cart_rule->quantity = 1; $cart_rule->highlight = 1; $cart_rule->quantity_per_user = 1; $cart_rule->reduction_tax = (bool) Configuration::get('PS_LOYALTY_TAX'); // If merchandise returns are allowed, the voucher musn't be usable before this max return date $date_from = Db::getInstance()->getValue(' SELECT UNIX_TIMESTAMP(date_add) n FROM ' . _DB_PREFIX_ . 'loyalty WHERE id_cart_rule = 0 AND id_customer = ' . (int) $this->context->cookie->id_customer . ' ORDER BY date_add DESC'); if (Configuration::get('PS_ORDER_RETURN')) { $date_from += 60 * 60 * 24 * (int) Configuration::get('PS_ORDER_RETURN_NB_DAYS'); } $cart_rule->date_from = date('Y-m-d H:i:s', $date_from); $cart_rule->date_to = date('Y-m-d H:i:s', strtotime($cart_rule->date_from . ' +1 year')); $cart_rule->minimum_amount = (double) Configuration::get('PS_LOYALTY_MINIMAL'); $cart_rule->minimum_amount_currency = (int) $this->context->currency->id; $cart_rule->active = 1; $categories = Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY'); if ($categories != '' && $categories != 0) { $categories = explode(',', Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY')); } else { die(Tools::displayError()); } $languages = Language::getLanguages(true); $default_text = Configuration::get('PS_LOYALTY_VOUCHER_DETAILS', (int) Configuration::get('PS_LANG_DEFAULT')); foreach ($languages as $language) { $text = Configuration::get('PS_LOYALTY_VOUCHER_DETAILS', (int) $language['id_lang']); $cart_rule->name[(int) $language['id_lang']] = $text ? strval($text) : strval($default_text); } $contains_categories = is_array($categories) && count($categories); if ($contains_categories) { $cart_rule->product_restriction = 1; } $cart_rule->add(); //Restrict cartRules with categories if ($contains_categories) { //Creating rule group $id_cart_rule = (int) $cart_rule->id; $sql = "INSERT INTO " . _DB_PREFIX_ . "cart_rule_product_rule_group (id_cart_rule, quantity) VALUES ('{$id_cart_rule}', 1)"; Db::getInstance()->execute($sql); $id_group = (int) Db::getInstance()->Insert_ID(); //Creating product rule $sql = "INSERT INTO " . _DB_PREFIX_ . "cart_rule_product_rule (id_product_rule_group, type) VALUES ('{$id_group}', 'categories')"; Db::getInstance()->execute($sql); $id_product_rule = (int) Db::getInstance()->Insert_ID(); //Creating restrictions $values = array(); foreach ($categories as $category) { $category = (int) $category; $values[] = "('{$id_product_rule}', '{$category}')"; } $values = implode(',', $values); $sql = "INSERT INTO " . _DB_PREFIX_ . "cart_rule_product_rule_value (id_product_rule, id_item) VALUES {$values}"; Db::getInstance()->execute($sql); } // Register order(s) which contributed to create this voucher if (!LoyaltyModule::registerDiscount($cart_rule)) { $cart_rule->delete(); } } Tools::redirect($this->context->link->getModuleLink('loyalty', 'default', array('process' => 'summary'))); }
include_once dirname(__FILE__) . '/LoyaltyStateModule.php'; include_once dirname(__FILE__) . '/loyalty.php'; Tools::displayFileAsDeprecated(); $context = Context::getContext(); if (!$context->customer->isLogged()) { Tools::redirect('index.php?controller=authentication&back=modules/loyalty/loyalty-program.php'); } $context->controller->addJqueryPlugin(array('dimensions', 'cluetip')); $customerPoints = (int) LoyaltyModule::getPointsByCustomer((int) $cookie->id_customer); /* transform point into voucher if needed */ if (Tools::getValue('transform-points') == 'true' and $customerPoints > 0) { /* Generate a voucher code */ $voucherCode = NULL; do { $voucherCode = 'FID' . rand(1000, 100000); } while (CartRule::cartRuleExists($voucherCode)); /* Voucher creation and affectation to the customer */ $cartRule = new CartRule(); $cartRule->code = $voucherCode; $cartRule->id_customer = (int) $context->customer->id; $cartRule->id_currency = (int) $context->currency->id; $cartRule->reduction_amount = LoyaltyModule::getVoucherValue((int) $customerPoints); $cartRule->quantity = 1; $cartRule->quantity_per_user = 1; /* If merchandise returns are allowed, the voucher musn't be usable before this max return date */ $dateFrom = Db::getInstance()->getValue(' SELECT UNIX_TIMESTAMP(date_add) n FROM ' . _DB_PREFIX_ . 'loyalty WHERE id_cart_rule = 0 AND id_customer = ' . (int) $cookie->id_customer . ' ORDER BY date_add DESC'); if (Configuration::get('PS_ORDER_RETURN')) {