Merge branch 'development' of https://github.com/PrestaShop/PrestaShop into development
This commit is contained in:
+7
-8
@@ -1331,6 +1331,9 @@ class CartCore extends ObjectModel
|
||||
else
|
||||
$shipping_fees = 0;
|
||||
|
||||
if ($type == Cart::ONLY_SHIPPING)
|
||||
return $shipping_fees;
|
||||
|
||||
if ($type == Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING)
|
||||
$type = Cart::ONLY_PRODUCTS;
|
||||
|
||||
@@ -1455,12 +1458,14 @@ class CartCore extends ObjectModel
|
||||
$wrapping_fees = 0;
|
||||
if ($this->gift)
|
||||
$wrapping_fees = Tools::convertPrice(Tools::ps_round($this->getGiftWrappingPrice($with_taxes), 2), Currency::getCurrencyInstance((int)$this->id_currency));
|
||||
if ($type == Cart::ONLY_WRAPPING)
|
||||
return $wrapping_fees;
|
||||
|
||||
$order_total_discount = 0;
|
||||
if (!in_array($type, array(Cart::ONLY_SHIPPING, Cart::ONLY_PRODUCTS)) && CartRule::isFeatureActive())
|
||||
{
|
||||
// First, retrieve the cart rules associated to this "getOrderTotal"
|
||||
if ($with_shipping)
|
||||
if ($with_shipping || $type == Cart::ONLY_DISCOUNTS)
|
||||
$cart_rules = $this->getCartRules(CartRule::FILTER_ACTION_ALL);
|
||||
else
|
||||
{
|
||||
@@ -1486,7 +1491,7 @@ class CartCore extends ObjectModel
|
||||
foreach ($cart_rules as $cart_rule)
|
||||
{
|
||||
// If the cart rule offers free shipping, add the shipping cost
|
||||
if ($with_shipping && $cart_rule['obj']->free_shipping)
|
||||
if (($with_shipping || $type == Cart::ONLY_DISCOUNTS) && $cart_rule['obj']->free_shipping)
|
||||
$order_total_discount += Tools::ps_round($cart_rule['obj']->getContextualValue($with_taxes, $virtual_context, CartRule::FILTER_ACTION_SHIPPING, ($param_product ? $package : null), $use_cache), 2);
|
||||
|
||||
// If the cart rule is a free gift, then add the free gift value only if the gift is in this package
|
||||
@@ -1512,12 +1517,6 @@ class CartCore extends ObjectModel
|
||||
$order_total -= $order_total_discount;
|
||||
}
|
||||
|
||||
if ($type == Cart::ONLY_SHIPPING)
|
||||
return $shipping_fees;
|
||||
|
||||
if ($type == Cart::ONLY_WRAPPING)
|
||||
return $wrapping_fees;
|
||||
|
||||
if ($type == Cart::BOTH)
|
||||
$order_total += $shipping_fees + $wrapping_fees;
|
||||
|
||||
|
||||
+19
-14
@@ -223,7 +223,7 @@ class CartRuleCore extends ObjectModel
|
||||
FROM `'._DB_PREFIX_.'cart_rule` cr
|
||||
LEFT JOIN `'._DB_PREFIX_.'cart_rule_lang` crl ON (cr.`id_cart_rule` = crl.`id_cart_rule` AND crl.`id_lang` = '.(int)$id_lang.')
|
||||
WHERE (
|
||||
cr.`id_customer` = '.(int)$id_customer.'
|
||||
cr.`id_customer` = '.(int)$id_customer.' OR cr.group_restriction = 1
|
||||
'.($includeGeneric ? 'OR cr.`id_customer` = 0' : '').'
|
||||
)
|
||||
AND cr.date_from < "'.date('Y-m-d H:i:s').'"
|
||||
@@ -232,20 +232,17 @@ class CartRuleCore extends ObjectModel
|
||||
'.($inStock ? 'AND cr.`quantity` > 0' : ''));
|
||||
|
||||
// Remove cart rule that does not match the customer groups
|
||||
if ($includeGeneric)
|
||||
{
|
||||
$customerGroups = Customer::getGroupsStatic($id_customer);
|
||||
foreach ($result as $key => $cart_rule)
|
||||
if ($cart_rule['group_restriction'])
|
||||
{
|
||||
$cartRuleGroups = Db::getInstance()->getValue('SELECT id_group FROM '._DB_PREFIX_.'cart_rule_group WHERE id_cart_rule = '.(int)$cart_rule['id_cart_rule']);
|
||||
foreach ($cartRuleGroups as $cartRuleGroup)
|
||||
if (in_array($cartRuleGroups['id_group'], $customerGroups))
|
||||
continue 2;
|
||||
$customerGroups = Customer::getGroupsStatic($id_customer);
|
||||
foreach ($result as $key => $cart_rule)
|
||||
if ($cart_rule['group_restriction'])
|
||||
{
|
||||
$cartRuleGroups = Db::getInstance()->executeS('SELECT id_group FROM '._DB_PREFIX_.'cart_rule_group WHERE id_cart_rule = '.(int)$cart_rule['id_cart_rule']);
|
||||
foreach ($cartRuleGroups as $cartRuleGroup)
|
||||
if (in_array($cartRuleGroup['id_group'], $customerGroups))
|
||||
continue 2;
|
||||
|
||||
unset($result[$key]);
|
||||
}
|
||||
}
|
||||
unset($result[$key]);
|
||||
}
|
||||
|
||||
foreach ($result as &$cart_rule)
|
||||
if ($cart_rule['quantity_per_user'])
|
||||
@@ -867,7 +864,15 @@ class CartRuleCore extends ObjectModel
|
||||
|
||||
// If it has the same tax application that you need, then it's the right value, whatever the product!
|
||||
if ($this->reduction_tax == $use_tax)
|
||||
{
|
||||
// The reduction cannot exceed the products total, except when we do not want it to be limited (for the partial use calculation)
|
||||
if ($filter != CartRule::FILTER_ACTION_ALL_NOCAP)
|
||||
{
|
||||
$cart_amount = $context->cart->getOrderTotal($use_tax, Cart::ONLY_PRODUCTS);
|
||||
$reduction_amount = min($reduction_amount, $cart_amount);
|
||||
}
|
||||
$reduction_value += $prorata * $reduction_amount;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->reduction_product > 0)
|
||||
|
||||
@@ -469,7 +469,7 @@ abstract class PaymentModuleCore extends Module
|
||||
$values['tax_excl'] -= $values['tax_excl'] - $order->total_products;
|
||||
}
|
||||
|
||||
$order->addCartRule($cart_rule['obj']->id, $cart_rule['obj']->name, $values);
|
||||
$order->addCartRule($cart_rule['obj']->id, $cart_rule['obj']->name, $values, 0, $cart_rule['obj']->free_shipping);
|
||||
|
||||
if ($id_order_state != Configuration::get('PS_OS_ERROR') && $id_order_state != Configuration::get('PS_OS_CANCELED') && !in_array($cart_rule['obj']->id, $cart_rule_used))
|
||||
{
|
||||
|
||||
@@ -1027,7 +1027,7 @@ class OrderCore extends ObjectModel
|
||||
* @param int $id_order_invoice
|
||||
* @return bool
|
||||
*/
|
||||
public function addCartRule($id_cart_rule, $name, $values, $id_order_invoice = 0)
|
||||
public function addCartRule($id_cart_rule, $name, $values, $id_order_invoice = 0, $free_shipping = null)
|
||||
{
|
||||
$order_cart_rule = new OrderCartRule();
|
||||
$order_cart_rule->id_order = $this->id;
|
||||
@@ -1036,6 +1036,12 @@ class OrderCore extends ObjectModel
|
||||
$order_cart_rule->name = $name;
|
||||
$order_cart_rule->value = $values['tax_incl'];
|
||||
$order_cart_rule->value_tax_excl = $values['tax_excl'];
|
||||
if ($free_shipping === null)
|
||||
{
|
||||
$cart_rule = new CartRule($id_cart_rule);
|
||||
$free_shipping = $cart_rule->free_shipping;
|
||||
}
|
||||
$order_cart_rule->free_shipping = (int)$free_shipping;
|
||||
$order_cart_rule->add();
|
||||
}
|
||||
|
||||
|
||||
@@ -345,6 +345,11 @@ class OrderInvoiceCore extends ObjectModel
|
||||
// shipping cost are added in the product taxes breakdown
|
||||
if ($this->useOneAfterAnotherTaxComputationMethod())
|
||||
return $taxes_breakdown;
|
||||
|
||||
// No shipping breakdown if it's free!
|
||||
foreach ($order->getCartRules() as $cart_rule)
|
||||
if ($cart_rule['free_shipping'])
|
||||
return $taxes_breakdown;
|
||||
|
||||
$shipping_tax_amount = $this->total_shipping_tax_incl - $this->total_shipping_tax_excl;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user