// code review
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@12910 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -100,6 +100,9 @@ class CartRuleCore extends ObjectModel
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* @see ObjectModel::add()
|
||||
*/
|
||||
public function add($autodate = true, $nullValues = false)
|
||||
{
|
||||
if (!parent::add($autodate, $nullValues))
|
||||
@@ -109,6 +112,9 @@ class CartRuleCore extends ObjectModel
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ObjectModel::delete()
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
if (!parent::delete())
|
||||
@@ -125,6 +131,13 @@ class CartRuleCore extends ObjectModel
|
||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'cart_rule_product_rule_value` WHERE `id_product_rule` NOT IN (SELECT `id_product_rule` FROM `'._DB_PREFIX_.'cart_rule_product_rule`)');
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy conditions from one cart rule to an other
|
||||
*
|
||||
* @static
|
||||
* @param int $id_cart_rule_source
|
||||
* @param int $id_cart_rule_destination
|
||||
*/
|
||||
public static function copyConditions($id_cart_rule_source, $id_cart_rule_destination)
|
||||
{
|
||||
Db::getInstance()->Execute('
|
||||
@@ -146,6 +159,13 @@ class CartRuleCore extends ObjectModel
|
||||
// Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'cart_rule_product_rule_value` WHERE `id_product_rule` NOT IN (SELECT `id_product_rule` FROM `'._DB_PREFIX_.'cart_rule_product_rule`)');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the id associated to the given code
|
||||
*
|
||||
* @static
|
||||
* @param string $code
|
||||
* @return int|bool
|
||||
*/
|
||||
public static function getIdByCode($code)
|
||||
{
|
||||
if (!Validate::isDiscountName($code))
|
||||
@@ -153,6 +173,16 @@ class CartRuleCore extends ObjectModel
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT `id_cart_rule` FROM `'._DB_PREFIX_.'cart_rule` WHERE `code` = \''.pSQL($code).'\'');
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param $id_lang
|
||||
* @param $id_customer
|
||||
* @param bool $active
|
||||
* @param bool $includeGeneric
|
||||
* @param bool $inStock
|
||||
* @param Cart|null $cart
|
||||
* @return array
|
||||
*/
|
||||
public static function getCustomerCartRules($id_lang, $id_customer, $active = false, $includeGeneric = true, $inStock = false, Cart $cart = null)
|
||||
{
|
||||
if (!CartRule::isFeatureActive())
|
||||
@@ -180,12 +210,17 @@ class CartRuleCore extends ObjectModel
|
||||
foreach ($cartRuleGroups as $cartRuleGroup)
|
||||
if (in_array($cartRuleGroups['id_group'], $customerGroups))
|
||||
continue 2;
|
||||
|
||||
unset($result[$key]);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id_customer
|
||||
* @return bool
|
||||
*/
|
||||
public function usedByCustomer($id_customer)
|
||||
{
|
||||
return (bool)Db::getInstance()->getValue('
|
||||
@@ -196,6 +231,11 @@ class CartRuleCore extends ObjectModel
|
||||
AND o.`id_customer` = '.(int)$id_customer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param $name
|
||||
* @return bool
|
||||
*/
|
||||
public static function cartRuleExists($name)
|
||||
{
|
||||
if (!CartRule::isFeatureActive())
|
||||
@@ -207,6 +247,11 @@ class CartRuleCore extends ObjectModel
|
||||
WHERE `code` = \''.pSQL($name).'\'');
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param $id_customer
|
||||
* @return bool
|
||||
*/
|
||||
public static function deleteByIdCustomer($id_customer)
|
||||
{
|
||||
$return = true;
|
||||
@@ -217,6 +262,9 @@ class CartRuleCore extends ObjectModel
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getProductRuleGroups()
|
||||
{
|
||||
if (!Validate::isLoadedObject($this) || $this->product_restriction == 0)
|
||||
@@ -236,6 +284,10 @@ class CartRuleCore extends ObjectModel
|
||||
return $productRuleGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id_product_rule_group
|
||||
* @return array ('type' => ? , 'values' => ?)
|
||||
*/
|
||||
public function getProductRules($id_product_rule_group)
|
||||
{
|
||||
if (!Validate::isLoadedObject($this) || $this->product_restriction == 0)
|
||||
@@ -257,6 +309,13 @@ class CartRuleCore extends ObjectModel
|
||||
}
|
||||
|
||||
// Todo : Add shop management
|
||||
/**
|
||||
* Check if this cart rule can be applied
|
||||
*
|
||||
* @param Context $context
|
||||
* @param bool $alreadyInCart
|
||||
* @return bool|mixed|string
|
||||
*/
|
||||
public function checkValidity(Context $context, $alreadyInCart = false)
|
||||
{
|
||||
if (!CartRule::isFeatureActive())
|
||||
@@ -306,7 +365,7 @@ class CartRuleCore extends ObjectModel
|
||||
if (!$combinable)
|
||||
{
|
||||
$cartRule = new CartRule($otherCartRule['cart_rule_restriction'], $context->cart->id_lang);
|
||||
return Tools::displayError('This voucher is not combinable with an other voucher already in your cart:').' '.$this->name;
|
||||
return Tools::displayError('This voucher is not combinable with an other voucher already in your cart:').' '.$cartRule->name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -482,7 +541,7 @@ class CartRuleCore extends ObjectModel
|
||||
if ($this->minimum_amount == 0 || $minimumAmountCurrency->conversion_rate == 0)
|
||||
$minimum_amount = 0;
|
||||
else
|
||||
$minimum_amount = $this->minimum_amount / $minimumAmountCurrency->convertion_rate;
|
||||
$minimum_amount = $this->minimum_amount / $minimumAmountCurrency->conversion_rate;
|
||||
}
|
||||
$cartTotal = $context->cart->getOrderTotal($this->minimum_amount_tax, Cart::ONLY_PRODUCTS);
|
||||
if ($this->minimum_amount_shipping)
|
||||
@@ -686,7 +745,7 @@ class CartRuleCore extends ObjectModel
|
||||
$array = $this->getCartRuleCombinations();
|
||||
else
|
||||
{
|
||||
$result = Db::getInstance()->ExecuteS('
|
||||
$resource = Db::getInstance()->query('
|
||||
SELECT t.*, tl.*, IF(crt.id_'.$type.' IS NULL, 0, 1) as selected
|
||||
FROM `'._DB_PREFIX_.$type.'` t
|
||||
LEFT JOIN `'._DB_PREFIX_.$type.'_lang` tl ON t.id_'.$type.' = tl.id_'.$type.' AND tl.id_lang = '.(int)Context::getContext()->language->id.'
|
||||
@@ -694,7 +753,7 @@ class CartRuleCore extends ObjectModel
|
||||
'.($active ? 'WHERE t.active = 1' : '').'
|
||||
ORDER BY name ASC',
|
||||
false);
|
||||
while ($row = Db::getInstance()->nextRow())
|
||||
while ($row = Db::getInstance()->nextRow($resource))
|
||||
$array[($row['selected'] || $this->{$type.'_restriction'} == 0) ? 'selected' : 'unselected'][] = $row;
|
||||
}
|
||||
}
|
||||
@@ -721,6 +780,11 @@ class CartRuleCore extends ObjectModel
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param Context|null $context
|
||||
* @return mixed
|
||||
*/
|
||||
public static function autoAddToCart(Context $context = null)
|
||||
{
|
||||
if ($context === null)
|
||||
@@ -775,11 +839,21 @@ class CartRuleCore extends ObjectModel
|
||||
$context->cart->addCartRule($cartRule->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @return bool
|
||||
*/
|
||||
public static function isFeatureActive()
|
||||
{
|
||||
return (bool)Configuration::get('PS_CART_RULE_FEATURE_ACTIVE');
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param $name
|
||||
* @param $id_lang
|
||||
* @return array
|
||||
*/
|
||||
public static function getCartsRuleByCode($name, $id_lang)
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('
|
||||
|
||||
Reference in New Issue
Block a user