// 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
+8 -31
View File
@@ -87,8 +87,6 @@ class CartCore extends ObjectModel
protected $_products = NULL;
protected static $_totalWeight = array();
protected $_taxCalculationMethod = PS_TAX_EXC;
protected static $_discounts = NULL;
protected static $_discountsLite = NULL;
protected static $_carriers = NULL;
protected static $_taxes_rate = NULL;
protected static $_attributesLists = array();
@@ -256,13 +254,6 @@ class CartCore extends ObjectModel
return $this->getCartRules();
}
/**
* Return cart discounts
*
* @param bool true will return discounts with basic informations
* @param bool true will erase the cache
* @result array Discounts
*/
public function getCartRules()
{
// TODO : add cache
@@ -552,10 +543,10 @@ class CartCore extends ObjectModel
/**
* @deprecated 1.5.0.1
*/
public function addDiscount($id_discount)
public function addDiscount($id_cart_rule)
{
Tools::displayAsDeprecated();
return $this->addCartRule($id_discount);
return $this->addCartRule($id_cart_rule);
}
public function addCartRule($id_cart_rule)
@@ -809,10 +800,10 @@ class CartCore extends ObjectModel
/**
* @deprecated 1.5.0.1
*/
public function deleteDiscount($id_discount)
public function deleteDiscount($id_cart_rule)
{
Tools::displayAsDeprecated();
return $this->removeCartRule($id_discount);
return $this->removeCartRule($id_cart_rule);
}
public function removeCartRule($id_cart_rule)
@@ -966,8 +957,7 @@ class CartCore extends ObjectModel
if (!in_array($type, array(Cart::ONLY_PRODUCTS, Cart::ONLY_DISCOUNTS, Cart::BOTH, Cart::BOTH_WITHOUT_SHIPPING, Cart::ONLY_SHIPPING, Cart::ONLY_WRAPPING, Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING)))
die(Tools::displayError());
// if discounts are never used
// Todo: remove and replace by cart rules
// if cart rules are not used
if ($type == Cart::ONLY_DISCOUNTS && !CartRule::isFeatureActive())
return 0;
// no shipping cost if is a cart with only virtuals products
@@ -1289,12 +1279,12 @@ class CartCore extends ObjectModel
/**
* @deprecated 1.5.0.1
*/
public function checkDiscountValidity($discountObj, $discounts, $order_total, $products, $checkCartDiscount = false)
public function checkDiscountValidity($obj, $discounts, $order_total, $products, $checkCartDiscount = false)
{
Tools::displayAsDeprecated();
$context = Context::getContext()->cloneContext();
$context->cart = $this;
return $discountObj->checkValidity($context);
return $obj->checkValidity($context);
}
/**
@@ -1319,18 +1309,6 @@ class CartCore extends ObjectModel
if ($total_tax < 0)
$total_tax = 0;
$total_free_ship = 0;
if ($free_ship = Tools::convertPrice((float)(Configuration::get('PS_SHIPPING_FREE_PRICE')), new Currency((int)($this->id_currency))))
{
$discounts = $this->getCartRules();
$total_free_ship = $free_ship - ($this->getOrderTotal(true, Cart::ONLY_PRODUCTS) + $this->getOrderTotal(true, Cart::ONLY_DISCOUNTS));
foreach ($discounts as $discount)
if ($discount['id_discount_type'] == Discount::FREE_SHIPPING)
{
$total_free_ship = 0;
break;
}
}
return array(
'delivery' => $delivery,
'delivery_state' => State::getNameById($delivery->id_state),
@@ -1351,8 +1329,7 @@ class CartCore extends ObjectModel
'total_products' => $this->getOrderTotal(false, Cart::ONLY_PRODUCTS),
'total_price' => $this->getOrderTotal(),
'total_tax' => $total_tax,
'total_price_without_tax' => $this->getOrderTotal(false),
'free_ship' => $total_free_ship);
'total_price_without_tax' => $this->getOrderTotal(false));
}
public function checkQuantities()
+19 -21
View File
@@ -614,29 +614,32 @@ class OrderCore extends ObjectModel
}
return $virtual;
}
/**
* Get order discounts
*
* @return array Discounts with price and quantity
* @deprecated 1.5.0.1
*/
public function getDiscounts($details = false)
{
Tools::displayAsDeprecated();
return Order::getCartRules();
}
public function getCartRules()
{
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT *
FROM `'._DB_PREFIX_.'order_cart_rule` od '.
($details ? 'LEFT JOIN `'._DB_PREFIX_.'discount` d ON (d.`id_discount` = od.`id_discount`)' : '').'
WHERE od.`id_order` = '.(int)($this->id));
FROM `'._DB_PREFIX_.'order_cart_rule` ocr
LEFT JOIN `'._DB_PREFIX_.'cart_rule` cr ON cr.`id_cart_rule` = ocr.`id_cart_rule`
WHERE ocr.`id_order` = '.(int)$this->id);
}
public static function getDiscountsCustomer($id_customer, $id_discount)
public static function getDiscountsCustomer($id_customer, $id_cart_rule)
{
return Db::getInstance()->getValue('
SELECT COUNT(*) FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN '._DB_PREFIX_.'order_cart_rule od ON (od.id_order = o.id_order)
WHERE o.id_customer = '.(int)($id_customer).'
AND od.id_discount = '.(int)($id_discount));
SELECT COUNT(*) FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN '._DB_PREFIX_.'order_cart_rule ocr ON (ocr.id_order = o.id_order)
WHERE o.id_customer = '.(int)$id_customer.'
AND ocr.id_cart_rule = '.(int)$id_cart_rule);
}
/**
@@ -888,17 +891,12 @@ class OrderCore extends ObjectModel
}
/**
* Add a discount to order
*
* @param integer $id_discount Discount id
* @param string $name Discount name
* @param float $value Discount value
* @return boolean Query sucess or not
* @deprecated 1.5.0.1
*/
public function addDiscount($id_discount, $name, $value)
public function addDiscount($id_cart_rule, $name, $value)
{
Tools::displayAsDeprecated();
return Order::addCartRule($id_discount, $name, $value);
return Order::addCartRule($id_cart_rule, $name, $value);
}
public function addCartRule($id_cart_rule, $name, $value)
+8 -7
View File
@@ -99,7 +99,7 @@ class OrderSlipCore extends ObjectModel
public static function getOrdersSlipProducts($orderSlipId, $order)
{
$discounts = $order->getDiscounts(true);
$cart_rules = $order->getCartRules(true);
$productsRet = self::getOrdersSlipDetail($orderSlipId);
$products = $order->getProductsDetail();
@@ -112,16 +112,17 @@ class OrderSlipCore extends ObjectModel
{
$resTab[$key] = $product;
$resTab[$key]['product_quantity'] = $tmp[$product['id_order_detail']];
if (sizeof($discounts))
if (sizeof($cart_rules))
{
$order->setProductPrices($product);
$realProductPrice = $resTab[$key]['product_price'];
foreach ($discounts as $discount)
// Todo : must be updated to use the cart rules
foreach ($cart_rules as $cart_rule)
{
if ($discount['id_discount_type'] == Discount::PERCENT)
$resTab[$key]['product_price'] -= $realProductPrice * ($discount['value'] / 100);
elseif ($discount['id_discount_type'] == Discount::AMOUNT)
$resTab[$key]['product_price'] -= (($discount['value'] * ($product['product_price_wt'] / $order->total_products_wt)) / (1.00 + ($product['tax_rate'] / 100)));
if ($cart_rule['reduction_percent'])
$resTab[$key]['product_price'] -= $realProductPrice * ($cart_rule['reduction_percent'] / 100);
elseif ($cart_rule['reduction_amount'])
$resTab[$key]['product_price'] -= (($cart_rule['reduction_amount'] * ($product['product_price_wt'] / $order->total_products_wt)) / (1.00 + ($product['tax_rate'] / 100)));
}
}
+4 -4
View File
@@ -260,14 +260,14 @@ class ValidateCore
}
/**
* Check for discount coupon name validity
* Check for voucher name validity
*
* @param string $discountName Discount coupon name to validate
* @param string $voucher voucher to validate
* @return boolean Validity is ok or not
*/
public static function isDiscountName($discountName)
public static function isDiscountName($voucher)
{
return preg_match('/^[^!<>,;?=+()@"°{}_$%:]{3,32}$/u', $discountName);
return preg_match('/^[^!<>,;?=+()@"°{}_$%:]{3,32}$/u', $voucher);
}
/**
-1
View File
@@ -68,7 +68,6 @@ class ShopCore extends ObjectModel
'contact' => array('type' => 'shop'),
'country' => array('type' => 'shop'),
'currency' => array('type' => 'shop'),
'discount' => array('type' => 'shop'),
'employee' => array('type' => 'shop'),
'hook_module' => array('type' => 'fk_shop'),
'hook_module_exceptions' => array('type' => 'fk_shop', 'primary' => 'id_hook_module_exceptions'),
+3 -3
View File
@@ -317,12 +317,12 @@ class AdminCartsController extends AdminController
$errors = array();
$customer = new Customer((int)$this->context->cart->id_customer);
if (!$id_discount = Tools::getValue('id_voucher') OR !$discount = new Discount((int)$id_discount))
if (!$id_cart_rule = Tools::getValue('id_voucher') OR !$cartRule = new CartRule((int)$id_cart_rule))
$errors[] = Tools::displayError('Invalid voucher');
elseif ($err = $this->context->cart->checkDiscountValidity($discount, $this->context->cart->getDiscounts(), $this->context->cart->getOrderTotal(), $this->context->cart->getProducts(), true, $customer))
elseif ($err = $this->context->cart->checkDiscountValidity($cartRule, $this->context->cart->getDiscounts(), $this->context->cart->getOrderTotal(), $this->context->cart->getProducts(), true, $customer))
$errors[] = $err;
if (!sizeof($errors))
if (!$this->context->cart->addDiscount((int)$discount->id))
if (!$this->context->cart->addCartRule((int)$cartRule->id))
$errors[] = Tools::displayError('Can\'t add the voucher');
echo Tools::jsonEncode(array_merge($this->ajaxReturnVars(), array('errors' => $errors)));
}
@@ -253,18 +253,6 @@ class ParentOrderControllerCore extends FrontController
Product::addCustomizationPrice($summary['products'], $customizedDatas);
}
if ($free_ship = Tools::convertPrice((float)(Configuration::get('PS_SHIPPING_FREE_PRICE')), new Currency($this->context->cart->id_currency)))
{
$discounts = $this->context->cart->getCartRules();
$total_free_ship = $free_ship - ($summary['total_products_wt'] + $summary['total_discounts']);
foreach ($discounts as $discount)
if ($discount['id_discount_type'] == Discount::FREE_SHIPPING)
{
$total_free_ship = 0;
break;
}
$this->context->smarty->assign('free_ship', $total_free_ship);
}
foreach ($summary['products'] as $key => &$product)
{
$product['quantity'] = $product['cart_quantity'];// for compatibility with 1.2 themes
-60
View File
@@ -640,59 +640,6 @@ CREATE TABLE `PREFIX_delivery` (
KEY `id_range_weight` (`id_range_weight`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
CREATE TABLE `PREFIX_discount` (
`id_discount` int(10) unsigned NOT NULL auto_increment,
`id_discount_type` int(10) unsigned NOT NULL,
`behavior_not_exhausted` TINYINT(3) DEFAULT '1',
`id_customer` int(10) unsigned NOT NULL,
`id_group` int(10) unsigned NOT NULL default 0,
`id_currency` int unsigned NOT NULL default 0,
`name` varchar(32) NOT NULL,
`value` decimal(17,2) NOT NULL default '0.00',
`quantity` int(10) unsigned NOT NULL default '0',
`quantity_per_user` int(10) unsigned NOT NULL default '1',
`cumulable` tinyint(1) unsigned NOT NULL default '0',
`cumulable_reduction` tinyint(1) unsigned NOT NULL default '0',
`date_from` datetime NOT NULL,
`date_to` datetime NOT NULL,
`minimal` decimal(17,2) default NULL,
`include_tax` tinyint(1) NOT NULL default '0',
`active` tinyint(1) unsigned NOT NULL default '0',
`cart_display` tinyint(1) unsigned NOT NULL default '0',
`date_add` datetime NOT NULL,
`date_upd` datetime NOT NULL,
PRIMARY KEY (`id_discount`),
KEY `discount_name` (`name`),
KEY `discount_customer` (`id_customer`),
KEY `id_discount_type` (`id_discount_type`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
CREATE TABLE `PREFIX_discount_category` (
`id_category` int(11) unsigned NOT NULL,
`id_discount` int(11) unsigned NOT NULL,
PRIMARY KEY (`id_category`, `id_discount`),
KEY `discount` (`id_discount`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
CREATE TABLE `PREFIX_discount_lang` (
`id_discount` int(10) unsigned NOT NULL,
`id_lang` int(10) unsigned NOT NULL,
`description` text,
PRIMARY KEY (`id_discount`,`id_lang`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
CREATE TABLE `PREFIX_discount_type` (
`id_discount_type` int(10) unsigned NOT NULL auto_increment,
PRIMARY KEY (`id_discount_type`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
CREATE TABLE `PREFIX_discount_type_lang` (
`id_discount_type` int(10) unsigned NOT NULL,
`id_lang` int(10) unsigned NOT NULL,
`name` varchar(64) NOT NULL,
PRIMARY KEY (`id_discount_type`,`id_lang`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
CREATE TABLE `PREFIX_employee` (
`id_employee` int(10) unsigned NOT NULL auto_increment,
`id_profile` int(10) unsigned NOT NULL,
@@ -1997,13 +1944,6 @@ PRIMARY KEY (`id_scene`, `id_shop`),
KEY `id_shop` (`id_shop`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
CREATE TABLE `PREFIX_discount_shop` (
`id_discount` INT( 11 ) UNSIGNED NOT NULL ,
`id_shop` INT( 11 ) UNSIGNED NOT NULL,
PRIMARY KEY (`id_discount`, `id_shop`),
KEY `id_shop` (`id_shop`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
CREATE TABLE `PREFIX_group_module_restriction` (
`id_group` INT(11) UNSIGNED NOT NULL ,
`id_module` INT(11) UNSIGNED NOT NULL ,
+72 -11
View File
@@ -256,13 +256,6 @@ CREATE TABLE `PREFIX_cart_rule` (
PRIMARY KEY (`id_cart_rule`)
);
CREATE TABLE `PREFIX_cart_rule_lang` (
`id_cart_rule` int(10) unsigned NOT NULL,
`id_lang` int(10) unsigned NOT NULL,
`name` varchar(254) NOT NULL,
PRIMARY KEY (`id_cart_rule`, `id_lang`)
);
CREATE TABLE `PREFIX_cart_rule_country` (
`id_cart_rule` int(10) unsigned NOT NULL,
`id_country` int(10) unsigned NOT NULL,
@@ -295,12 +288,80 @@ CREATE TABLE `PREFIX_cart_rule_product_rule` (
PRIMARY KEY (`id_product_rule`)
);
CREATE TABLE `PREFIX_cart_rule_product_rule_value` (
`id_product_rule` int(10) unsigned NOT NULL,
`id_item` int(10) unsigned NOT NULL,
PRIMARY KEY (`id_product_rule`, `id_item`)
SET @id_currency_default = (SELECT value FROM `PREFIX_configuration` WHERE name = 'PS_CURRENCY_DEFAULT' LIMIT 1);
INSERT INTO `PREFIX_cart_rule` (
`id_cart_rule`,
`id_customer`,
`date_from`,
`date_to`,
`description`,
`quantity`,
`quantity_per_user`,
`priority`,
`code`,
`minimum_amount`,
`minimum_amount_tax`,
`minimum_amount_currency`,
`minimum_amount_shipping`,
`country_restriction`,
`carrier_restriction`,
`group_restriction`,
`cart_rule_restriction`,
`product_restriction`,
`free_shipping`,
`reduction_percent`,
`reduction_amount`,
`reduction_tax`,
`reduction_currency`,
`reduction_product`,
`gift_product`,
`active`,
`date_add`,
`date_upd`
) (
SELECT
`id_discount`,
`id_customer`,
`date_from`,
`date_to`,
`name`,
`quantity`,
`quantity_per_user`,
1,
`name`,
`minimal`,
1,
@id_currency_default,
1,
0,
0,
IF(id_group = 0, 0, 1),
IF(cumulable = 1, 0, 1),
0,
IF(id_discount_type = 3, 1, 0),
IF(id_discount_type = 1, value, 0),
IF(id_discount_type = 2, value, 0),
1,
`id_currency`,
0,
0,
`active`,
`date_add`,
`date_upd`
FROM `PREFIX_discount`
);
RENAME TABLE `PREFIX_discount_lang` TO `PREFIX_cart_rule_lang`;
ALTER TABLE `PREFIX_discount_lang` CHANGE `id_discount` `id_cart_rule` int(10) unsigned NOT NULL;
ALTER TABLE `PREFIX_discount_lang` CHANGE `description` `name` varchar(254) NOT NULL;
RENAME TABLE `PREFIX_discount_category` TO `PREFIX_cart_rule_product_rule_value`;
ALTER TABLE `PREFIX_cart_rule_product_rule_value` CHANGE `id_category` `id_item` int(10) unsigned NOT NULL;
ALTER TABLE `PREFIX_cart_rule_product_rule_value` CHANGE `id_discount` `id_product_rule` int(10) unsigned NOT NULL;
INSERT INTO `PREFIX_cart_rule_product_rule` (`id_product_rule`, `id_cart_rule`, `quantity`, `type`) (
SELECT DISTINCT `id_product_rule`, `id_product_rule`, 1, 'categories' FROM `PREFIX_cart_rule_product_rule_value`
);
UPDATE `PREFIX_cart_rule` SET product_restriction = 1 WHERE `id_cart_rule` IN (SELECT `id_cart_rule` FROM `PREFIX_cart_rule_product_rule`);
ALTER TABLE `PREFIX_cart_discount` CHANGE `id_discount` `id_cart_rule` int(10) unsigned NOT NULL;
ALTER TABLE `PREFIX_order_discount` CHANGE `id_discount` `id_cart_rule` int(10) unsigned NOT NULL;
ALTER TABLE `PREFIX_order_discount` CHANGE `id_order_discount` `id_order_cart_rule` int(10) unsigned NOT NULL;
+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.'`';