[*] FO : cart summary is adapted to cart rules with a special "friendly" display

This commit is contained in:
dMetzger
2012-05-19 13:26:21 +00:00
parent f1144c2f12
commit 2c30a0e3f3
5 changed files with 79 additions and 32 deletions
+45 -13
View File
@@ -2605,8 +2605,9 @@ class CartCore extends ObjectModel
*/ */
public function getSummaryDetails($id_lang = null) public function getSummaryDetails($id_lang = null)
{ {
$context = Context::getContext();
if (!$id_lang) if (!$id_lang)
$id_lang = Context::getContext()->language->id; $id_lang = $context->language->id;
$delivery = new Address((int)$this->id_address_delivery); $delivery = new Address((int)$this->id_address_delivery);
$invoice = new Address((int)$this->id_address_invoice); $invoice = new Address((int)$this->id_address_invoice);
@@ -2625,14 +2626,41 @@ class CartCore extends ObjectModel
$products = $this->getProducts(false); $products = $this->getProducts(false);
$gift_products = array(); $gift_products = array();
$cart_rules = $this->getCartRules(); $cart_rules = $this->getCartRules();
$total_shipping = $this->getTotalShippingCost();
$total_shipping_tax_exc = $this->getTotalShippingCost(null, false);
$total_products_wt = $this->getOrderTotal(true, Cart::ONLY_PRODUCTS);
$total_products = $this->getOrderTotal(false, Cart::ONLY_PRODUCTS);
$total_discounts = $this->getOrderTotal(true, Cart::ONLY_DISCOUNTS);
$total_discounts_tax_exc = $this->getOrderTotal(false, Cart::ONLY_DISCOUNTS);
// The cart content is altered for display
foreach ($cart_rules as &$cart_rule) foreach ($cart_rules as &$cart_rule)
{ {
if ($cart_rule['free_shipping'])
{
$cart_rule['value_real'] -= $total_shipping;
$cart_rule['value_tax_exc'] = $total_shipping_tax_exc;
$total_shipping = 0;
$total_shipping_tax_exc = 0;
}
if ($cart_rule['gift_product']) if ($cart_rule['gift_product'])
{ {
foreach ($products as $key => &$product) foreach ($products as $key => &$product)
if (empty($product['gift']) && $product['id_product'] == $cart_rule['gift_product'] && $product['id_product_attribute'] == $cart_rule['gift_product_attribute']) if (empty($product['gift']) && $product['id_product'] == $cart_rule['gift_product'] && $product['id_product_attribute'] == $cart_rule['gift_product_attribute'])
{ {
// Update product quantity and price // Update total products
$total_products_wt = Tools::ps_round($total_products_wt - $product['price_wt'], (int)$context->currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
$total_products = Tools::ps_round($total_products - $product['price'], (int)$context->currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
// Update total discounts
$total_discounts = Tools::ps_round($total_discounts - $product['price_wt'], (int)$context->currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
$total_discounts_tax_exc = Tools::ps_round($total_discounts_tax_exc - $product['price'], (int)$context->currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
// Update cart rule value
$cart_rule['value_real'] = Tools::ps_round($cart_rule['value_real'] - $product['price_wt'], (int)$context->currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
$cart_rule['value_tax_exc'] = Tools::ps_round($cart_rule['value_tax_exc'] - $product['price'], (int)$context->currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
// Update product quantity
$product['total_wt'] = Tools::ps_round($product['total_wt'] - $product['price_wt'], (int)$currency->decimals * _PS_PRICE_DISPLAY_PRECISION_); $product['total_wt'] = Tools::ps_round($product['total_wt'] - $product['price_wt'], (int)$currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
$product['total'] = Tools::ps_round($product['total'] - $product['price'], (int)$currency->decimals * _PS_PRICE_DISPLAY_PRECISION_); $product['total'] = Tools::ps_round($product['total'] - $product['price'], (int)$currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
$product['cart_quantity']--; $product['cart_quantity']--;
@@ -2643,16 +2671,20 @@ class CartCore extends ObjectModel
// Add a new product line // Add a new product line
$gift_product = $product; $gift_product = $product;
$gift_product['cart_quantity'] = 1; $gift_product['cart_quantity'] = 1;
$gift_product['price'] = $product['price']; $gift_product['price'] = 0;
$gift_product['price_wt'] = $product['price_wt']; $gift_product['price_wt'] = 0;
$gift_product['total_wt'] = $product['price_wt']; $gift_product['total_wt'] = 0;
$gift_product['total'] = $product['price']; $gift_product['total'] = 0;
$gift_product['gift'] = true; $gift_product['gift'] = true;
$gift_products[] = $gift_product; $gift_products[] = $gift_product;
} }
} }
} }
foreach ($cart_rules as $key => &$cart_rule)
if ($cart_rule['value_real'] == 0)
unset($cart_rules[$key]);
return array( return array(
'delivery' => $delivery, 'delivery' => $delivery,
'delivery_state' => State::getNameById($delivery->id_state), 'delivery_state' => State::getNameById($delivery->id_state),
@@ -2663,19 +2695,19 @@ class CartCore extends ObjectModel
'gift_products' => $gift_products, 'gift_products' => $gift_products,
'discounts' => $cart_rules, 'discounts' => $cart_rules,
'is_virtual_cart' => (int)$this->isVirtualCart(), 'is_virtual_cart' => (int)$this->isVirtualCart(),
'total_discounts' => $this->getOrderTotal(true, Cart::ONLY_DISCOUNTS), 'total_discounts' => $total_discounts,
'total_discounts_tax_exc' => $this->getOrderTotal(false, Cart::ONLY_DISCOUNTS), 'total_discounts_tax_exc' => $total_discounts_tax_exc,
'total_wrapping' => $this->getOrderTotal(true, Cart::ONLY_WRAPPING), 'total_wrapping' => $this->getOrderTotal(true, Cart::ONLY_WRAPPING),
'total_wrapping_tax_exc' => $this->getOrderTotal(false, Cart::ONLY_WRAPPING), 'total_wrapping_tax_exc' => $this->getOrderTotal(false, Cart::ONLY_WRAPPING),
'total_shipping' => $this->getTotalShippingCost(), 'total_shipping' => $total_shipping,
'total_shipping_tax_exc' => $this->getTotalShippingCost(null, false), 'total_shipping_tax_exc' => $total_shipping_tax_exc,
'total_products_wt' => $this->getOrderTotal(true, Cart::ONLY_PRODUCTS), 'total_products_wt' => $total_products_wt,
'total_products' => $this->getOrderTotal(false, Cart::ONLY_PRODUCTS), 'total_products' => $total_products,
'total_price' => $this->getOrderTotal(), 'total_price' => $this->getOrderTotal(),
'total_tax' => $total_tax, 'total_tax' => $total_tax,
'total_price_without_tax' => $this->getOrderTotal(false), 'total_price_without_tax' => $this->getOrderTotal(false),
'is_multi_address_delivery' => $this->isMultiAddressDelivery() || ((int)Tools::getValue('multi-shipping') == 1), 'is_multi_address_delivery' => $this->isMultiAddressDelivery() || ((int)Tools::getValue('multi-shipping') == 1),
'free_ship' => 0, 'free_ship' => $total_shipping ? 0 : 1,
'carrier' => new Carrier($this->id_carrier, $id_lang), 'carrier' => new Carrier($this->id_carrier, $id_lang),
); );
} }
+9 -1
View File
@@ -733,7 +733,14 @@ class CartRuleCore extends ObjectModel
{ {
// Discount (%) on the whole order // Discount (%) on the whole order
if ($this->reduction_percent && $this->reduction_product == 0) if ($this->reduction_percent && $this->reduction_product == 0)
$reduction_value += $context->cart->getOrderTotal($useTax, Cart::ONLY_PRODUCTS) * $this->reduction_percent / 100; {
// Do not give a reduction on free products!
$order_total = $context->cart->getOrderTotal($useTax, Cart::ONLY_PRODUCTS);
foreach ($context->cart->getCartRules(CartRule::FILTER_ACTION_GIFT) as $cart_rule)
$order_total -= Tools::ps_round($cart_rule['obj']->getContextualValue($useTax, $context, CartRule::FILTER_ACTION_GIFT), 2);
$reduction_value += $order_total * $this->reduction_percent / 100;
}
// Discount (%) on a specific product // Discount (%) on a specific product
if ($this->reduction_percent && $this->reduction_product > 0) if ($this->reduction_percent && $this->reduction_product > 0)
@@ -822,6 +829,7 @@ class CartRuleCore extends ObjectModel
{ {
$cart_amount_ti = $context->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS); $cart_amount_ti = $context->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
$cart_amount_te = $context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS); $cart_amount_te = $context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);
$cart_vat_amount = $cart_amount_ti - $cart_amount_te; $cart_vat_amount = $cart_amount_ti - $cart_amount_te;
if ($cart_vat_amount == 0 || $cart_amount_te == 0) if ($cart_vat_amount == 0 || $cart_amount_te == 0)
+2
View File
@@ -80,6 +80,8 @@ class BlockCart extends Module
$totalToPayWithoutTaxes = $params['cart']->getOrderTotal(false); $totalToPayWithoutTaxes = $params['cart']->getOrderTotal(false);
$this->smarty->assign('tax_cost', Tools::displayPrice($totalToPay - $totalToPayWithoutTaxes, $currency)); $this->smarty->assign('tax_cost', Tools::displayPrice($totalToPay - $totalToPayWithoutTaxes, $currency));
} }
// The cart content is altered for display
foreach ($cart_rules as &$cart_rule) foreach ($cart_rules as &$cart_rule)
{ {
if ($cart_rule['free_shipping']) if ($cart_rule['free_shipping'])
+17 -12
View File
@@ -31,20 +31,21 @@
<td class="cart_description"> <td class="cart_description">
<h5><a href="{$link->getProductLink($product.id_product, $product.link_rewrite, $product.category, null, null, null, $product.id_product_attribute)|escape:'htmlall':'UTF-8'}">{$product.name|escape:'htmlall':'UTF-8'}</a></h5> <h5><a href="{$link->getProductLink($product.id_product, $product.link_rewrite, $product.category, null, null, null, $product.id_product_attribute)|escape:'htmlall':'UTF-8'}">{$product.name|escape:'htmlall':'UTF-8'}</a></h5>
{if isset($product.attributes) && $product.attributes}<a href="{$link->getProductLink($product.id_product, $product.link_rewrite, $product.category, null, null, null, $product.id_product_attribute)|escape:'htmlall':'UTF-8'}">{$product.attributes|escape:'htmlall':'UTF-8'}</a>{/if} {if isset($product.attributes) && $product.attributes}<a href="{$link->getProductLink($product.id_product, $product.link_rewrite, $product.category, null, null, null, $product.id_product_attribute)|escape:'htmlall':'UTF-8'}">{$product.attributes|escape:'htmlall':'UTF-8'}</a>{/if}
{if !empty($product.gift)}
<br /><span class="gift-icon">{l s='Gift!'}</span>
{/if}
</td> </td>
<td class="cart_ref">{if $product.reference}{$product.reference|escape:'htmlall':'UTF-8'}{else}--{/if}</td> <td class="cart_ref">{if $product.reference}{$product.reference|escape:'htmlall':'UTF-8'}{else}--{/if}</td>
<td class="cart_unit"> <td class="cart_unit">
<span class="price" id="product_price_{$product.id_product}_{$product.id_product_attribute}_{$product.id_address_delivery|intval}{if !empty($product.gift)}_gift{/if}"> <span class="price" id="product_price_{$product.id_product}_{$product.id_product_attribute}_{$product.id_address_delivery|intval}{if !empty($product.gift)}_gift{/if}">
{if isset($product.is_discounted) && $product.is_discounted} {if !empty($product.gift)}
<span style="text-decoration:line-through;">{convertPrice price=$product.price_without_specific_price}</span><br /> <span class="gift-icon">{l s='Gift!'}</span>
{/if}
{if !$priceDisplay}
{convertPrice price=$product.price_wt}
{else} {else}
{convertPrice price=$product.price} {if isset($product.is_discounted) && $product.is_discounted}
<span style="text-decoration:line-through;">{convertPrice price=$product.price_without_specific_price}</span><br />
{/if}
{if !$priceDisplay}
{convertPrice price=$product.price_wt}
{else}
{convertPrice price=$product.price}
{/if}
{/if} {/if}
</span> </span>
</td> </td>
@@ -81,10 +82,14 @@
</td> </td>
<td class="cart_total"> <td class="cart_total">
<span class="price" id="total_product_price_{$product.id_product}_{$product.id_product_attribute}_{$product.id_address_delivery|intval}{if !empty($product.gift)}_gift{/if}"> <span class="price" id="total_product_price_{$product.id_product}_{$product.id_product_attribute}_{$product.id_address_delivery|intval}{if !empty($product.gift)}_gift{/if}">
{if $quantityDisplayed == 0 AND isset($customizedDatas.$productId.$productAttributeId)} {if !empty($product.gift)}
{if !$priceDisplay}{displayPrice price=$product.total_customization_wt}{else}{displayPrice price=$product.total_customization}{/if} <span class="gift-icon">{l s='Gift!'}</span>
{else} {else}
{if !$priceDisplay}{displayPrice price=$product.total_wt}{else}{displayPrice price=$product.total}{/if} {if $quantityDisplayed == 0 AND isset($customizedDatas.$productId.$productAttributeId)}
{if !$priceDisplay}{displayPrice price=$product.total_customization_wt}{else}{displayPrice price=$product.total_customization}{/if}
{else}
{if !$priceDisplay}{displayPrice price=$product.total_wt}{else}{displayPrice price=$product.total}{/if}
{/if}
{/if} {/if}
</span> </span>
</td> </td>
+6 -6
View File
@@ -150,20 +150,20 @@
</tr> </tr>
{if $use_taxes} {if $use_taxes}
{if $priceDisplay} {if $priceDisplay}
<tr class="cart_total_delivery" {if $shippingCost <= 0} style="display:none;"{/if}> <tr class="cart_total_delivery" {if $total_shipping_tax_exc <= 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 colspan="5">{if $display_tax_label}{l s='Total shipping (tax excl.):'}{else}{l s='Total shipping:'}{/if}</td>
<td colspan="2" class="price" id="total_shipping">{displayPrice price=$shippingCostTaxExc}</td> <td colspan="2" class="price" id="total_shipping">{displayPrice price=$total_shipping_tax_exc}</td>
</tr> </tr>
{else} {else}
<tr class="cart_total_delivery"{if $shippingCost <= 0} style="display:none;"{/if}> <tr class="cart_total_delivery"{if $total_shipping <= 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 colspan="5">{if $display_tax_label}{l s='Total shipping (tax incl.):'}{else}{l s='Total shipping:'}{/if}</td>
<td colspan="2" class="price" id="total_shipping" >{displayPrice price=$shippingCost}</td> <td colspan="2" class="price" id="total_shipping" >{displayPrice price=$total_shipping}</td>
</tr> </tr>
{/if} {/if}
{else} {else}
<tr class="cart_total_delivery"{if $shippingCost <= 0} style="display:none;"{/if}> <tr class="cart_total_delivery"{if $total_shipping_tax_exc <= 0} style="display:none;"{/if}>
<td colspan="5">{l s='Total shipping:'}</td> <td colspan="5">{l s='Total shipping:'}</td>
<td colspan="2" class="price" id="total_shipping" >{displayPrice price=$shippingCostTaxExc}</td> <td colspan="2" class="price" id="total_shipping" >{displayPrice price=$total_shipping_tax_exc}</td>
</tr> </tr>
{/if} {/if}