Override method getCustomerDiscountsto to not display discount with
quantities = 0
This commit is contained in:
parent
a762200fc2
commit
96f4237fc7
@ -3,6 +3,51 @@ class Discount extends DiscountCore
|
||||
{
|
||||
public $orders;
|
||||
|
||||
/**
|
||||
* Return customer discounts
|
||||
*
|
||||
* @param integer $id_lang Language ID
|
||||
* @param boolean $id_customer Customer ID
|
||||
* @return array Discounts
|
||||
*/
|
||||
public static function getCustomerDiscounts($id_lang, $id_customer, $active = false, $includeGenericOnes = true, $stock = false)
|
||||
{
|
||||
global $cart;
|
||||
|
||||
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT d.*, dtl.`name` AS `type`, dl.`description`
|
||||
FROM `'._DB_PREFIX_.'discount` d
|
||||
LEFT JOIN `'._DB_PREFIX_.'discount_lang` dl ON (d.`id_discount` = dl.`id_discount` AND dl.`id_lang` = '.(int)($id_lang).')
|
||||
LEFT JOIN `'._DB_PREFIX_.'discount_type` dt ON dt.`id_discount_type` = d.`id_discount_type`
|
||||
LEFT JOIN `'._DB_PREFIX_.'discount_type_lang` dtl ON (dt.`id_discount_type` = dtl.`id_discount_type` AND dtl.`id_lang` = '.(int)($id_lang).')
|
||||
WHERE (`id_customer` = '.(int)($id_customer).'
|
||||
OR `id_group` IN (SELECT `id_group` FROM `'._DB_PREFIX_.'customer_group` WHERE `id_customer` = '.(int)($id_customer).')'.
|
||||
($includeGenericOnes ? ' OR (`id_customer` = 0 AND `id_group` = 0)' : '').')
|
||||
'.($active ? ' AND d.`active` = 1' : '').'
|
||||
'.($stock ? ' AND d.`quantity` != 0' : ''));
|
||||
|
||||
foreach ($res as $i => &$discount) {
|
||||
if ($discount['quantity_per_user']) {
|
||||
$quantity_used = Order::getDiscountsCustomer((int)($id_customer), (int)($discount['id_discount']));
|
||||
if (isset($cart) AND isset($cart->id)) {
|
||||
$quantity_used += $cart->getDiscountsCustomer((int)($discount['id_discount']));
|
||||
}
|
||||
$discount['quantity_for_user'] = $discount['quantity_per_user'] - $quantity_used;
|
||||
}
|
||||
else {
|
||||
$discount['quantity_for_user'] = 0;
|
||||
}
|
||||
|
||||
// Remove discount with zero quantities
|
||||
if ($discount['quantity_for_user'] == 0) {
|
||||
unset($res[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
public static function createOrderDiscount($order, $productList, $qtyList, $name, $shipping_cost = false, $id_category = 0, $subcategory = 0, $value = 10)
|
||||
{
|
||||
$languages = Language::getLanguages($order);
|
||||
|
Loading…
Reference in New Issue
Block a user