[-] Core : Fixed a lot of issue with free shipping vouchers #PSCFV-7325
This commit is contained in:
+8
-16
@@ -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'])
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -1182,6 +1182,7 @@ CREATE TABLE `PREFIX_order_cart_rule` (
|
||||
`name` varchar(254) NOT NULL,
|
||||
`value` decimal(17,2) NOT NULL default '0.00',
|
||||
`value_tax_excl` decimal(17,2) NOT NULL default '0.00',
|
||||
`free_shipping` BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
PRIMARY KEY (`id_order_cart_rule`),
|
||||
KEY `id_order` (`id_order`),
|
||||
KEY `id_cart_rule` (`id_cart_rule`)
|
||||
|
||||
@@ -10,3 +10,13 @@ UPDATE `PREFIX_customer` c, `PREFIX_orders` o SET c.id_lang = o.id_lang WHERE c.
|
||||
|
||||
UPDATE `PREFIX_quick_access` SET `link` = 'index.php?controller=AdminCartRules&addcart_rule' WHERE `link` = 'index.php?tab=AdminDiscounts&adddiscount';
|
||||
|
||||
ALTER TABLE `PREFIX_order_cart_rule` ADD `free_shipping` BOOLEAN NOT NULL DEFAULT FALSE AFTER `value_tax_excl`;
|
||||
|
||||
UPDATE `PREFIX_order_cart_rule` ocr, `PREFIX_cart_rule` cr SET ocr.free_shipping = 1 WHERE ocr.id_cart_rule = cr.id_cart_rule AND cr.free_shipping = 1;
|
||||
|
||||
UPDATE `PREFIX_orders` o, `PREFIX_order_cart_rule` ocr SET
|
||||
o.`total_discounts` = o.total_discounts + o.`total_shipping_tax_incl`,
|
||||
o.`total_discounts_tax_incl` = o.`total_discounts_tax_incl` + o.`total_shipping_tax_incl`,
|
||||
o.`total_discounts_tax_excl` = o.`total_discounts_tax_excl` + o.`total_shipping_tax_excl`
|
||||
WHERE o.id_order = ocr.id_order AND ocr.free_shipping = 1;
|
||||
|
||||
|
||||
@@ -194,9 +194,6 @@
|
||||
<tr style="line-height:6px;background-color:{$bgcolor}" text-align="left">
|
||||
<td style="line-height:3px;text-align:left;width:60%;vertical-align:top" colspan="{if !$tax_excluded_display}5{else}4{/if}">{$cart_rule.name}</td>
|
||||
<td>
|
||||
{if $cart_rule.free_shipping}
|
||||
{assign var="shipping_discount_tax_incl" value=$order_invoice->total_shipping_tax_incl}
|
||||
{/if}
|
||||
{if $tax_excluded_display}
|
||||
- {$cart_rule.value_tax_excl}
|
||||
{else}
|
||||
|
||||
@@ -88,31 +88,7 @@
|
||||
<td class="price" id="total_product">{displayPrice price=$total_products}</td>
|
||||
</tr>
|
||||
{/if}
|
||||
<tr class="cart_total_voucher" {if $total_discounts == 0}style="display: none;"{/if}>
|
||||
<td colspan="5">
|
||||
{if $use_taxes}
|
||||
{if $priceDisplay}
|
||||
{if $display_tax_label}{l s='Total vouchers (tax excl.):'}{else}{l s='Total vouchers:'}{/if}
|
||||
{else}
|
||||
{if $display_tax_label}{l s='Total vouchers (tax incl.):'}{else}{l s='Total vouchers:'}{/if}
|
||||
{/if}
|
||||
{else}
|
||||
{l s='Total vouchers:'}
|
||||
{/if}
|
||||
</td>
|
||||
<td class="price-discount price" id="total_discount">
|
||||
{if $use_taxes}
|
||||
{if $priceDisplay}
|
||||
{displayPrice price=$total_discounts_tax_exc*-1}
|
||||
{else}
|
||||
{displayPrice price=$total_discounts*-1}
|
||||
{/if}
|
||||
{else}
|
||||
{displayPrice price=$total_discounts_tax_exc*-1}
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="cart_total_voucher" {if $total_wrapping == 0}style="display: none;"{/if}>
|
||||
<tr class="cart_total_voucher" {if $total_wrapping == 0}style="display:none"{/if}>
|
||||
<td colspan="5">
|
||||
{if $use_taxes}
|
||||
{if $priceDisplay}
|
||||
@@ -144,23 +120,47 @@
|
||||
{else}
|
||||
{if $use_taxes}
|
||||
{if $priceDisplay}
|
||||
<tr class="cart_total_delivery" {if $shippingCost <= 0} style="display:none;"{/if}>
|
||||
<tr class="cart_total_delivery" {if $shippingCost <= 0} style="display:none"{/if}>
|
||||
<td colspan="5">{if $display_tax_label}{l s='Total shipping (tax excl.):'}{else}{l s='Total shipping:'}{/if}</td>
|
||||
<td class="price" id="total_shipping">{displayPrice price=$shippingCostTaxExc}</td>
|
||||
</tr>
|
||||
{else}
|
||||
<tr class="cart_total_delivery"{if $shippingCost <= 0} style="display:none;"{/if}>
|
||||
<tr class="cart_total_delivery"{if $shippingCost <= 0} style="display:none"{/if}>
|
||||
<td colspan="5">{if $display_tax_label}{l s='Total shipping (tax incl.):'}{else}{l s='Total shipping:'}{/if}</td>
|
||||
<td class="price" id="total_shipping" >{displayPrice price=$shippingCost}</td>
|
||||
</tr>
|
||||
{/if}
|
||||
{else}
|
||||
<tr class="cart_total_delivery"{if $shippingCost <= 0} style="display:none;"{/if}>
|
||||
<tr class="cart_total_delivery"{if $shippingCost <= 0} style="display:none"{/if}>
|
||||
<td colspan="5">{l s='Total shipping:'}</td>
|
||||
<td class="price" id="total_shipping" >{displayPrice price=$shippingCostTaxExc}</td>
|
||||
</tr>
|
||||
{/if}
|
||||
{/if}
|
||||
<tr class="cart_total_voucher" {if $total_discounts == 0}style="display:none"{/if}>
|
||||
<td colspan="5">
|
||||
{if $use_taxes}
|
||||
{if $priceDisplay}
|
||||
{if $display_tax_label}{l s='Total vouchers (tax excl.):'}{else}{l s='Total vouchers:'}{/if}
|
||||
{else}
|
||||
{if $display_tax_label}{l s='Total vouchers (tax incl.):'}{else}{l s='Total vouchers:'}{/if}
|
||||
{/if}
|
||||
{else}
|
||||
{l s='Total vouchers:'}
|
||||
{/if}
|
||||
</td>
|
||||
<td class="price-discount price" id="total_discount">
|
||||
{if $use_taxes}
|
||||
{if $priceDisplay}
|
||||
{displayPrice price=$total_discounts_tax_exc*-1}
|
||||
{else}
|
||||
{displayPrice price=$total_discounts*-1}
|
||||
{/if}
|
||||
{else}
|
||||
{displayPrice price=$total_discounts_tax_exc*-1}
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
{if $use_taxes}
|
||||
{if $priceDisplay && $total_tax != 0}
|
||||
<tr class="cart_total_tax">
|
||||
|
||||
Reference in New Issue
Block a user