[-] Core : Fixed a lot of issue with free shipping vouchers #PSCFV-7325

This commit is contained in:
Damien Metzger
2013-02-04 16:00:46 +01:00
parent a6a0dee0ca
commit 2bf3df1c7d
8 changed files with 60 additions and 49 deletions
+8 -16
View File
@@ -1465,7 +1465,7 @@ class CartCore extends ObjectModel
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
{
@@ -1491,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
@@ -2860,22 +2860,14 @@ class CartCore extends ObjectModel
foreach ($cart_rules as &$cart_rule)
{
// If the cart rule is automatic (wihtout any code) and include free shipping, it should not be displayed as a cart rule but only set the shipping cost to 0
if ($cart_rule['free_shipping'])
if ($cart_rule['free_shipping'] && (empty($cart_rule['code']) || preg_match('/^'.CartRule::BO_ORDER_CODE_PREFIX.'[0-9]+/', $cart_rule['code'])))
{
if (empty($cart_rule['code']) || preg_match('/^'.CartRule::BO_ORDER_CODE_PREFIX.'[0-9]+/', $cart_rule['code']))
{
$cart_rule['value_real'] -= $total_shipping;
$cart_rule['value_tax_exc'] = $total_shipping_tax_exc;
$cart_rule['value_real'] -= $total_shipping;
$cart_rule['value_tax_exc'] = $total_shipping_tax_exc;
// Update total shipping
$total_shipping = 0;
$total_shipping_tax_exc = 0;
}
else
{
$total_discounts += $total_shipping;
$total_discounts_tax_exc += $total_shipping_tax_exc;
}
// Update total shipping
$total_shipping = 0;
$total_shipping_tax_exc = 0;
}
if ($cart_rule['gift_product'])
{
+1 -1
View File
@@ -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))
{
+7 -1
View File
@@ -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();
}
+5
View File
@@ -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;