// Retro compatibility and updater improved for Discount/CartRules

This commit is contained in:
dMetzger
2011-11-02 14:23:44 +00:00
parent 61213efb5b
commit 4fbb25168e
21 changed files with 238 additions and 275 deletions
+4 -4
View File
@@ -239,8 +239,8 @@ class Blocknewsletter extends Module
else
return $this->error = $this->l('Error during subscription');
if ($discount = Configuration::get('NW_VOUCHER_CODE'))
$this->sendVoucher($email, $discount);
if ($code = Configuration::get('NW_VOUCHER_CODE'))
$this->sendVoucher($email, $code);
if (Configuration::get('NW_CONFIRMATION_EMAIL'))
$this->sendConfirmationEmail($email);
@@ -427,9 +427,9 @@ class Blocknewsletter extends Module
* @param string $discount
* @return bool
*/
protected function sendVoucher($email, $discount)
protected function sendVoucher($email, $code)
{
return Mail::Send($this->context->language->id, 'newsletter_voucher', Mail::l('Newsletter voucher'), array('{discount}' => $discount), $email, null, null, null, null, null, dirname(__FILE__).'/mails/');
return Mail::Send($this->context->language->id, 'newsletter_voucher', Mail::l('Newsletter voucher'), array('{discount}' => $code), $email, null, null, null, null, null, dirname(__FILE__).'/mails/');
}
/**
+26 -30
View File
@@ -59,7 +59,7 @@ class Followup extends Module
CREATE TABLE '._DB_PREFIX_.'log_email (
`id_log_email` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`id_email_type` INT UNSIGNED NOT NULL ,
`id_discount` INT UNSIGNED NOT NULL ,
`id_cart_rule` INT UNSIGNED NOT NULL ,
`id_customer` INT UNSIGNED NULL ,
`id_cart` INT UNSIGNED NULL ,
`date_add` DATETIME NOT NULL,
@@ -195,11 +195,11 @@ class Followup extends Module
$stats = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT DATE_FORMAT(l.date_add, \'%Y-%m-%d\') date_stat, l.id_email_type, COUNT(l.id_log_email) nb,
(SELECT COUNT(l2.id_discount)
(SELECT COUNT(l2.id_cart_rule)
FROM '._DB_PREFIX_.'log_email l2
LEFT JOIN '._DB_PREFIX_.'order_discount od ON (od.id_discount = l2.id_discount)
LEFT JOIN '._DB_PREFIX_.'orders o ON (o.id_order = od.id_order)
WHERE l2.id_email_type = l.id_email_type AND l2.date_add = l.date_add AND od.id_order IS NOT NULL AND o.valid = 1) nb_used
LEFT JOIN '._DB_PREFIX_.'order_cart_rule ocr ON (ocr.id_cart_rule = l2.id_cart_rule)
LEFT JOIN '._DB_PREFIX_.'orders o ON (o.id_order = ocr.id_order)
WHERE l2.id_email_type = l.id_email_type AND l2.date_add = l.date_add AND ocr.id_order IS NOT NULL AND o.valid = 1) nb_used
FROM '._DB_PREFIX_.'log_email l
WHERE l.date_add >= DATE_SUB(CURDATE(), INTERVAL 30 DAY)
GROUP BY DATE_FORMAT(l.date_add, \'%Y-%m-%d\'), l.id_email_type');
@@ -260,9 +260,9 @@ class Followup extends Module
}
/* Log each sent e-mail */
private function logEmail($id_email_type, $id_discount, $id_customer = NULL, $id_cart = NULL)
private function logEmail($id_email_type, $id_cart_rule, $id_customer = NULL, $id_cart = NULL)
{
$values = array('id_email_type' => (int)($id_email_type), 'id_discount' => (int)($id_discount), 'date_add' => date('Y-m-d H:i:s'));
$values = array('id_email_type' => (int)($id_email_type), 'id_cart_rule' => (int)$id_cart_rule, 'date_add' => date('Y-m-d H:i:s'));
if (!empty($id_cart))
$values['id_cart'] = (int)($id_cart);
if (!empty($id_customer))
@@ -455,30 +455,26 @@ class Followup extends Module
private function createDiscount($id_email_type, $amount, $id_customer, $dateValidity, $description)
{
$discount = new Discount();
$discount->id_discount_type = Discount::PERCENT;
$discount->value = (float)($amount);
$discount->id_customer = (int)($id_customer);
$discount->date_to = $dateValidity;
$discount->date_from = date('Y-m-d H:i:s');
$discount->quantity = 1;
$discount->quantity_per_user = 1;
$discount->cumulable = 0;
$discount->cumulable_reduction = 1;
$discount->minimal = 0;
$cartRule = new CartRule();
$cartRule->reduction_percent = (float)$amount;
$cartRule->id_customer = (int)$id_customer;
$cartRule->date_to = $dateValidity;
$cartRule->date_from = date('Y-m-d H:i:s');
$cartRule->quantity = 1;
$cartRule->quantity_per_user = 1;
$cartRule->cart_rule_restriction = 1;
$cartRule->minimum_amount = 0;
$languages = Language::getLanguages(true);
foreach ($languages AS $language)
$discount->description[(int)($language['id_lang'])] = $description;
$cartRule->name[(int)$language['id_lang']] = $description;
$name = 'FLW-'.(int)($id_email_type).'-'.strtoupper(Tools::passwdGen(10));
$discount->name = $name;
$discount->active = 1;
$result = $discount->add();
if (!$result)
$code = 'FLW-'.(int)($id_email_type).'-'.strtoupper(Tools::passwdGen(10));
$cartRule->name = $code;
$cartRule->active = 1;
if (!$cartRule->add())
return false;
return $discount;
return $cartRule;
}
public function cronTask()
@@ -497,12 +493,12 @@ class Followup extends Module
/* Clean-up database by deleting all outdated discounts */
if ($conf['PS_FOLLOW_UP_CLEAN_DB'] == 1)
{
$outdatedDiscounts = Db::getInstance()->executeS('SELECT id_discount FROM '._DB_PREFIX_.'discount WHERE date_to < NOW()');
$outdatedDiscounts = Db::getInstance()->executeS('SELECT id_cart_rule FROM '._DB_PREFIX_.'cart_rule WHERE date_to < NOW() AND code LIKE "FLW-%"');
foreach ($outdatedDiscounts AS $outdatedDiscount)
{
$discount = new Discount((int)($outdatedDiscount['id_discount']));
if (Validate::isLoadedObject($discount))
$discount->delete();
$cartRule = new CartRule((int)$outdatedDiscount['id_cart_rule']);
if (Validate::isLoadedObject($cartRule))
$cartRule->delete();
}
}
}
+3 -3
View File
@@ -223,9 +223,9 @@ class GCheckout extends PaymentModule
if ($wrapping = $this->context->cart->getOrderTotal(true, Cart::ONLY_WRAPPING))
$googleCart->AddItem(new GoogleItem(utf8_decode($this->l('Wrapping')), '', 1, $wrapping));
foreach ($this->context->cart->getDiscounts() AS $voucher)
$googleCart->AddItem(new GoogleItem(utf8_decode($voucher['name']),
utf8_decode($voucher['description']), 1, '-'.$voucher['value_real']));
foreach ($this->context->cart->getCartRules() AS $cart_tule)
$googleCart->AddItem(new GoogleItem(utf8_decode($cart_tule['code']),
utf8_decode($cart_tule['name']), 1, '-'.$cart_tule['value_real']));
if (!Configuration::get('GCHECKOUT_NO_SHIPPING'))
{
+15 -15
View File
@@ -33,13 +33,13 @@ class LoyaltyModule extends ObjectModel
public $id_loyalty_state;
public $id_customer;
public $id_order;
public $id_discount;
public $id_cart_rule;
public $points;
public $date_add;
public $date_upd;
protected $fieldsRequired = array('id_customer', 'points');
protected $fieldsValidate = array('id_loyalty_state' => 'isInt', 'id_customer' => 'isInt', 'id_discount' => 'isInt', 'id_order' => 'isInt', 'points' => 'isInt');
protected $fieldsValidate = array('id_loyalty_state' => 'isInt', 'id_customer' => 'isInt', 'id_cart_rule' => 'isInt', 'id_order' => 'isInt', 'points' => 'isInt');
protected $table = 'loyalty';
protected $identifier = 'id_loyalty';
@@ -50,7 +50,7 @@ class LoyaltyModule extends ObjectModel
$fields['id_loyalty_state'] = (int)$this->id_loyalty_state;
$fields['id_customer'] = (int)$this->id_customer;
$fields['id_order'] = (int)$this->id_order;
$fields['id_discount'] = (int)$this->id_discount;
$fields['id_cart_rule'] = (int)$this->id_cart_rule;
$fields['points'] = (int)$this->points;
$fields['date_add'] = pSQL($this->date_add);
$fields['date_upd'] = pSQL($this->date_upd);
@@ -110,8 +110,8 @@ class LoyaltyModule extends ObjectModel
}
$total += ($taxesEnabled == PS_TAX_EXC ? $product['price'] : $product['price_wt'])* (int)($product['cart_quantity']);
}
foreach ($cart->getDiscounts(false) AS $discount)
$total -= $discount['value_real'];
foreach ($cart->getCartRules(false) AS $cart_rule)
$total -= $cart_rule['value_real'];
}
return self::getNbPointsByPrice($total);
@@ -175,24 +175,24 @@ class LoyaltyModule extends ObjectModel
public static function getDiscountByIdCustomer($id_customer, $last=false)
{
$query = '
SELECT f.id_discount AS id_discount, f.date_upd AS date_add
SELECT f.id_cart_rule AS id_cart_rule, f.date_upd AS date_add
FROM `'._DB_PREFIX_.'loyalty` f
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (f.`id_order` = o.`id_order`)
WHERE f.`id_customer` = '.(int)($id_customer).'
AND f.`id_discount` > 0
AND f.`id_cart_rule` > 0
AND o.`valid` = 1';
if ($last === true)
$query.= ' ORDER BY f.id_loyalty DESC LIMIT 0,1';
$query.= ' GROUP BY f.id_discount';
$query.= ' GROUP BY f.id_cart_rule';
return Db::getInstance()->executeS($query);
}
public static function registerDiscount($discount)
public static function registerDiscount($cartRule)
{
if (!Validate::isLoadedObject($discount))
die(Tools::displayError('Incorrect object Discount.'));
$items = self::getAllByIdCustomer((int)$discount->id_customer, NULL, true);
if (!Validate::isLoadedObject($cartRule))
die(Tools::displayError('Incorrect object CartRule.'));
$items = self::getAllByIdCustomer((int)$cartRule->id_customer, NULL, true);
foreach ($items AS $item)
{
$f = new LoyaltyModule((int)$item['id_loyalty']);
@@ -203,18 +203,18 @@ class LoyaltyModule extends ObjectModel
if ($f->points + $negativePoints <= 0)
continue;
$f->id_discount = (int)$discount->id;
$f->id_cart_rule = (int)$cartRule->id;
$f->id_loyalty_state = (int)LoyaltyStateModule::getConvertId();
$f->save();
}
}
public static function getOrdersByIdDiscount($id_discount)
public static function getOrdersByIdDiscount($id_cart_rule)
{
$items = Db::getInstance()->executeS('
SELECT f.id_order AS id_order, f.points AS points, f.date_upd AS date
FROM `'._DB_PREFIX_.'loyalty` f
WHERE f.id_discount = '.(int)($id_discount).' AND f.id_loyalty_state = '.(int)(LoyaltyStateModule::getConvertId()));
WHERE f.id_cart_rule = '.(int)$id_cart_rule.' AND f.id_loyalty_state = '.(int)LoyaltyStateModule::getConvertId());
if (!empty($items) AND is_array($items))
{
+24 -26
View File
@@ -47,56 +47,54 @@ if (Tools::getValue('transform-points') == 'true' AND $customerPoints > 0)
{
/* Generate a voucher code */
$voucherCode = NULL;
do $voucherCode = 'FID'.rand(1000, 100000);
while (Discount::discountExists($voucherCode));
do
$voucherCode = 'FID'.rand(1000, 100000);
while (CartRule::cartRuleExists($voucherCode));
/* Voucher creation and affectation to the customer */
$voucher = new Discount();
$voucher->name = $voucherCode;
$voucher->id_discount_type = Discount::AMOUNT; // Discount on order (amount)
$voucher->id_customer = (int)($cookie->id_customer);
$voucher->id_currency = (int)($cookie->id_currency);
$voucher->value = LoyaltyModule::getVoucherValue((int)$customerPoints);
$voucher->quantity = 1;
$voucher->quantity_per_user = 1;
$voucher->cumulable = 1;
$voucher->cumulable_reduction = 1;
$cartRule = new CartRule();
$cartRule->code = $voucherCode;
$cartRule->id_customer = (int)$cookie->id_customer;
$cartRule->id_currency = (int)$cookie->id_currency;
$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_discount = 0 AND id_customer = '.(int)$cookie->id_customer.'
WHERE id_cart_rule = 0 AND id_customer = '.(int)$cookie->id_customer.'
ORDER BY date_add DESC');
if (Configuration::get('PS_ORDER_RETURN'))
$dateFrom += 60 * 60 * 24 * (int)Configuration::get('PS_ORDER_RETURN_NB_DAYS');
$voucher->date_from = date('Y-m-d H:i:s', $dateFrom);
$voucher->date_to = date('Y-m-d H:i:s', $dateFrom + 31536000); // + 1 year
$cartRule->date_from = date('Y-m-d H:i:s', $dateFrom);
$cartRule->date_to = date('Y-m-d H:i:s', $dateFrom + 31536000); // + 1 year
$voucher->minimal = (float)Configuration::get('PS_LOYALTY_MINIMAL');
$voucher->active = 1;
$cartRule->minimum_amount = (float)Configuration::get('PS_LOYALTY_MINIMAL');
$cartRule->active = 1;
$categories = Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY');
if ($categories != '' AND $categories != 0)
$categories = explode(',', Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY'));
else
die(Tools::displayError());
die (Tools::displayError());
$languages = Language::getLanguages(true);
$default_text = Configuration::get('PS_LOYALTY_VOUCHER_DETAILS', (int)(Configuration::get('PS_LANG_DEFAULT')));
$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']));
$voucher->description[(int)($language['id_lang'])] = $text ? strval($text) : strval($default_text);
$text = Configuration::get('PS_LOYALTY_VOUCHER_DETAILS', (int)$language['id_lang']);
$cartRule->name[(int)$language['id_lang']] = $text ? strval($text) : strval($default_text);
}
if (is_array($categories) AND sizeof($categories))
$voucher->add(true, false, $categories);
$cartRule->add(true, false, $categories);
else
$voucher->add();
$cartRule->add();
/* Register order(s) which contributed to create this voucher */
LoyaltyModule::registerDiscount($voucher);
@@ -125,13 +123,13 @@ $smarty->assign(array(
/* Discounts */
$nbDiscounts = 0;
$discounts = array();
if ($ids_discount = LoyaltyModule::getDiscountByIdCustomer((int)($cookie->id_customer)))
if ($ids_discount = LoyaltyModule::getDiscountByIdCustomer((int)$cookie->id_customer))
{
$nbDiscounts = count($ids_discount);
foreach ($ids_discount AS $key => $discount)
{
$discounts[$key] = new Discount((int)$discount['id_discount'], (int)($cookie->id_lang));
$discounts[$key]->orders = LoyaltyModule::getOrdersByIdDiscount((int)$discount['id_discount']);
$discounts[$key] = new Discount((int)$discount['id_cart_rule'], (int)$cookie->id_lang);
$discounts[$key]->orders = LoyaltyModule::getOrdersByIdDiscount((int)$discount['id_cart_rule']);
}
}
+2 -2
View File
@@ -104,14 +104,14 @@ class Loyalty extends Module
`id_loyalty_state` INT UNSIGNED NOT NULL DEFAULT 1,
`id_customer` INT UNSIGNED NOT NULL,
`id_order` INT UNSIGNED DEFAULT NULL,
`id_discount` INT UNSIGNED DEFAULT NULL,
`id_cart_rule` INT UNSIGNED DEFAULT NULL,
`points` INT NOT NULL DEFAULT 0,
`date_add` DATETIME NOT NULL,
`date_upd` DATETIME NOT NULL,
PRIMARY KEY (`id_loyalty`),
INDEX index_loyalty_loyalty_state (`id_loyalty_state`),
INDEX index_loyalty_order (`id_order`),
INDEX index_loyalty_discount (`id_discount`),
INDEX index_loyalty_discount (`id_cart_rule`),
INDEX index_loyalty_customer (`id_customer`)
) DEFAULT CHARSET=utf8 ;');
+2 -2
View File
@@ -170,11 +170,11 @@ class MailAlerts extends Module
<td style="padding:0.6em 0.4em; text-align:right;">'.Tools::displayPrice(($unit_price * $product['product_quantity']), $currency, false).'</td>
</tr>';
}
foreach ($params['order']->getDiscounts() AS $discount)
foreach ($params['order']->getCartRules() AS $discount)
{
$itemsTable .=
'<tr style="background-color:#EBECEE;">
<td colspan="4" style="padding:0.6em 0.4em; text-align:right;">'.$this->l('Voucher code:').' '.$discount['name'].'</td>
<td colspan="4" style="padding:0.6em 0.4em; text-align:right;">'.$this->l('Voucher code:').' '.$discount['code'].'</td>
<td style="padding:0.6em 0.4em; text-align:right;">-'.Tools::displayPrice($discount['value'], $currency, false).'</td>
</tr>';
}
@@ -84,36 +84,29 @@ class ReferralProgramModule extends ObjectModel
{
$configurations = Configuration::getMultiple(array('REFERRAL_DISCOUNT_TYPE', 'REFERRAL_PERCENTAGE', 'REFERRAL_DISCOUNT_VALUE_'.(int)$id_currency));
$discount = new Discount();
$discount->id_discount_type = (int)$configurations['REFERRAL_DISCOUNT_TYPE'];
/* % */
$cartRule = new CartRule();
if ($configurations['REFERRAL_DISCOUNT_TYPE'] == Discount::PERCENT)
$discount->value = (float)$configurations['REFERRAL_PERCENTAGE'];
/* Fixed amount */
elseif ($configurations['REFERRAL_DISCOUNT_TYPE'] == Discount::AMOUNT AND isset($configurations['REFERRAL_DISCOUNT_VALUE_'.(int)($id_currency)]))
$discount->value = (float)$configurations['REFERRAL_DISCOUNT_VALUE_'.(int)($id_currency)];
/* Unknown or value undefined for this currency (configure your module correctly) */
else
$discount->value = 0;
$cartRule->reduction_percent = (float)$configurations['REFERRAL_PERCENTAGE'];
elseif ($configurations['REFERRAL_DISCOUNT_TYPE'] == Discount::AMOUNT AND isset($configurations['REFERRAL_DISCOUNT_VALUE_'.(int)$id_currency]))
$cartRule->reduction_amount = (float)$configurations['REFERRAL_DISCOUNT_VALUE_'.(int)$id_currency];
$discount->quantity = 1;
$discount->quantity_per_user = 1;
$discount->date_from = date('Y-m-d H:i:s', time());
$discount->date_to = date('Y-m-d H:i:s', time() + 31536000); // + 1 year
$discount->name = $this->getDiscountPrefix().Tools::passwdGen(6);
$discount->description = Configuration::getInt('REFERRAL_DISCOUNT_DESCRIPTION');
$discount->id_customer = (int)$id_customer;
$discount->id_currency = (int)$id_currency;
$cartRule->quantity = 1;
$cartRule->quantity_per_user = 1;
$cartRule->date_from = date('Y-m-d H:i:s', time());
$cartRule->date_to = date('Y-m-d H:i:s', time() + 31536000); // + 1 year
$cartRule->code = $this->getDiscountPrefix().Tools::passwdGen(6);
$cartRule->name = Configuration::getInt('REFERRAL_DISCOUNT_DESCRIPTION');
$cartRule->id_customer = (int)$id_customer;
$cartRule->id_currency = (int)$id_currency;
if ($discount->add())
if ($cartRule->add())
{
if ($register != false)
{
if ($register == 'sponsor')
$this->id_discount_sponsor = (int)$discount->id;
$this->id_cart_rule_sponsor = (int)$cartRule->id;
elseif ($register == 'sponsored')
$this->id_discount = (int)$discount->id;
$this->id_cart_rule = (int)$cartRule->id;
return $this->save();
}
return true;
+1 -1
View File
@@ -46,7 +46,7 @@ $file = str_replace('{email}', $customer->email, $file);
$file = str_replace('{firstname_friend}', 'XXXXX', $file);
$file = str_replace('{lastname_friend}', 'xxxxxx', $file);
$file = str_replace('{link}', 'authentication.php?create_account=1', $file);
$file = str_replace('{discount}', Discount::display((float)(Configuration::get('REFERRAL_DISCOUNT_VALUE_' . Context::getContext()->currency->id)), (int)(Configuration::get('REFERRAL_DISCOUNT_TYPE')), Context::getContext()->currency), $file);
$file = str_replace('{discount}', ReferralProgram::displayDiscount((float)Configuration::get('REFERRAL_DISCOUNT_VALUE_' . Context::getContext()->currency->id), (int)Configuration::get('REFERRAL_DISCOUNT_TYPE'), Context::getContext()->currency), $file);
echo $file;
@@ -41,7 +41,7 @@ $context->controller->addJqueryPlugin(array('thickbox', 'idTabs'));
include(dirname(__FILE__).'/../../header.php');
// get discount value (ready to display)
$discount = Discount::display((float)(Configuration::get('REFERRAL_DISCOUNT_VALUE_'.(int)($cookie->id_currency))), (int)(Configuration::get('REFERRAL_DISCOUNT_TYPE')), new Currency($cookie->id_currency));
$discount = ReferralProgram::displayDiscount((float)Configuration::get('REFERRAL_DISCOUNT_VALUE_'.(int)($cookie->id_currency)), (int)Configuration::get('REFERRAL_DISCOUNT_TYPE'), new Currency($cookie->id_currency));
$activeTab = 'sponsor';
$error = false;
+27 -15
View File
@@ -92,8 +92,8 @@ class ReferralProgram extends Module
`lastname` VARCHAR(128) NOT NULL,
`firstname` VARCHAR(128) NOT NULL,
`id_customer` INT UNSIGNED DEFAULT NULL,
`id_discount` INT UNSIGNED DEFAULT NULL,
`id_discount_sponsor` INT UNSIGNED DEFAULT NULL,
`id_cart_rule` INT UNSIGNED DEFAULT NULL,
`id_cart_rule_sponsor` INT UNSIGNED DEFAULT NULL,
`date_add` DATETIME NOT NULL,
`date_upd` DATETIME NOT NULL,
PRIMARY KEY (`id_referralprogram`),
@@ -133,6 +133,18 @@ class ReferralProgram extends Module
return true;
}
public static function displayDiscount($discountValue, $discountType, $currency = false)
{
if ((float)$discountValue AND (int)$discountType)
{
if ($discountType == 1)
return $discountValue.chr(37); // ASCII #37 --> % (percent)
elseif ($discountType == 2)
return Tools::displayPrice($discountValue, $currency);
}
return ''; // return a string because it's a display method
}
private function _postProcess()
{
Configuration::updateValue('REFERRAL_ORDER_QUANTITY', (int)(Tools::getValue('order_quantity')));
@@ -354,13 +366,13 @@ class ReferralProgram extends Module
$referralprogram = new ReferralProgramModule($id_referralprogram);
if (!Validate::isLoadedObject($referralprogram))
return false;
$discount = new Discount($referralprogram->id_discount);
if (!Validate::isLoadedObject($discount))
$cartRule = new CartRule($referralprogram->id_cart_rule);
if (!Validate::isLoadedObject($cartRule))
return false;
if ($params['cart']->checkDiscountValidity($discount, $params['cart']->getDiscounts(), $params['cart']->getOrderTotal(true, Cart::ONLY_PRODUCTS), $params['cart']->getProducts(), false, $this->context) === false)
if ($cartRule->checkValidity($this->context) === false)
{
$this->context->smarty->assign(array('discount_display' => Discount::display($discount->value, $discount->id_discount_type, new Currency($params['cookie']->id_currency)), 'discount' => $discount));
$this->context->smarty->assign(array('discount_display' => ReferralProgram::displayDiscount($cartRule->reduction_percent ? $cartRule->reduction_percent : $cartRule->reduction_amount, $cartRule->reduction_percent ? 1 : 2, new Currency($params['cookie']->id_currency)), 'discount' => $cartRule));
return $this->display(__FILE__, 'shopping-cart.tpl');
}
return false;
@@ -455,13 +467,13 @@ class ReferralProgram extends Module
$referralprogram->save();
if ($referralprogram->registerDiscountForSponsored((int)$params['cookie']->id_currency))
{
$discount = new Discount((int)$referralprogram->id_discount);
if (Validate::isLoadedObject($discount))
$cartRule = new CartRule((int)$referralprogram->id_cart_rule);
if (Validate::isLoadedObject($cartRule))
{
$data = array(
'{firstname}' => $newCustomer->firstname,
'{lastname}' => $newCustomer->lastname,
'{voucher_num}' => $discount->name,
'{voucher_num}' => $cartRule->code,
'{voucher_amount}' => (Configuration::get('REFERRAL_DISCOUNT_TYPE') == 2 ? Tools::displayPrice((float)Configuration::get('REFERRAL_DISCOUNT_VALUE_'.(int)$this->context->currency->id), (int)Configuration::get('PS_CURRENCY_DEFAULT')) : (float)Configuration::get('REFERRAL_PERCENTAGE').'%'));
Mail::Send(
@@ -565,10 +577,10 @@ class ReferralProgram extends Module
$sponsor = new Customer((int)$referralprogram->id_sponsor);
if ((int)$nbOrdersCustomer == (int)$this->_configuration['REFERRAL_ORDER_QUANTITY'])
{
$discount = new Discount((int)$referralprogram->id_discount_sponsor);
if (!Validate::isLoadedObject($discount))
$cartRule = new CartRule((int)$referralprogram->id_cart_rule_sponsor);
if (!Validate::isLoadedObject($cartRule))
return false;
$this->context->smarty->assign(array('discount' => $discount->display($discount->value, (int)$discount->id_discount_type, new Currency((int)$params['objOrder']->id_currency)), 'sponsor_firstname' => $sponsor->firstname, 'sponsor_lastname' => $sponsor->lastname));
$this->context->smarty->assign(array('discount' => ReferralProgram::displayDiscount($cartRule->reduction_percent ? $cartRule->reduction_percent : $cartRule->reduction_amount, $cartRule->reduction_percent ? 1 : 2, new Currency((int)$params['objOrder']->id_currency)), 'sponsor_firstname' => $sponsor->firstname, 'sponsor_lastname' => $sponsor->lastname));
return $this->display(__FILE__, 'order-confirmation.tpl');
}
return false;
@@ -598,10 +610,10 @@ class ReferralProgram extends Module
$sponsor = new Customer((int)$referralprogram->id_sponsor);
if ((int)$orderState->logable AND $nbOrdersCustomer >= (int)$this->_configuration['REFERRAL_ORDER_QUANTITY'] AND $referralprogram->registerDiscountForSponsor((int)$order->id_currency))
{
$discount = new Discount((int)$referralprogram->id_discount_sponsor);
$cartRule = new CartRule((int)$referralprogram->id_cart_rule_sponsor);
$currency = new Currency((int)$order->id_currency);
$discount_display = $discount->display($discount->value, (int)$discount->id_discount_type, $currency);
$data = array('{sponsored_firstname}' => $customer->firstname, '{sponsored_lastname}' => $customer->lastname, '{discount_display}' => $discount_display, '{discount_name}' => $discount->name);
$discount_display = ReferralProgram::displayDiscount($cartRule->reduction_percent ? $cartRule->reduction_percent : $cartRule->reduction_amount, $cartRule->reduction_percent ? 1 : 2, $currency);
$data = array('{sponsored_firstname}' => $customer->firstname, '{sponsored_lastname}' => $customer->lastname, '{discount_display}' => $discount_display, '{discount_name}' => $cartRule->code);
Mail::Send((int)$order->id_lang, 'referralprogram-congratulations', Mail::l('Congratulations!'), $data, $sponsor->email, $sponsor->firstname.' '.$sponsor->lastname, strval(Configuration::get('PS_SHOP_EMAIL')), strval(Configuration::get('PS_SHOP_NAME')), NULL, NULL, dirname(__FILE__).'/mails/');
return true;
}
@@ -111,13 +111,13 @@ class StatsBestVouchers extends ModuleGrid
public function getData()
{
$this->_query = 'SELECT SQL_CALC_FOUND_ROWS od.name, COUNT(od.id_discount) as total, SUM(o.total_paid_real) / o.conversion_rate as ca
FROM '._DB_PREFIX_.'order_discount od
LEFT JOIN '._DB_PREFIX_.'orders o ON o.id_order = od.id_order
$this->_query = 'SELECT SQL_CALC_FOUND_ROWS ocr.code, COUNT(ocr.id_cart_rule) as total, SUM(o.total_paid_real) / o.conversion_rate as ca
FROM '._DB_PREFIX_.'order_cart_rule ocr
LEFT JOIN '._DB_PREFIX_.'orders o ON o.id_order = ocr.id_order
WHERE o.valid = 1
'.$this->sqlShopRestriction(Shop::SHARE_ORDER, 'o').'
AND o.invoice_date BETWEEN '.$this->getDate().'
GROUP BY od.id_discount';
GROUP BY ocr.id_cart_rule';
if (Validate::IsName($this->_sort))
{
$this->_query .= ' ORDER BY `'.$this->_sort.'`';