Merge branch 'development' of https://github.com/PrestaShop/PrestaShop into development

This commit is contained in:
Rémi Gaillard
2013-02-04 16:05:17 +01:00
11 changed files with 133 additions and 104 deletions
+7 -8
View File
@@ -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
View File
@@ -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)
+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;
+1
View File
@@ -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
View File
@@ -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;
+34 -32
View File
@@ -123,7 +123,8 @@ class StatsForecast extends Module
$dataTable[$row['fix_date']] = $row;
$this->_html .= '<div>
<div class="blocStats"><h2 class="icon-'.$this->name.'"><span></span>'.$this->displayName.'</h2>
<div class="blocStats">
<h2 class="icon-'.$this->name.'"><span></span>'.$this->displayName.'</h2>
<p>'.$this->l('All amounts are without taxes.').'</p>
<form id="granularity" action="'.Tools::safeOutput($ru).'#granularity" method="post">
<input type="hidden" name="submitGranularity" value="1" />
@@ -300,30 +301,28 @@ class StatsForecast extends Module
</div>
<div class="separation"></div>
<div class="blocConversion">
<span style="float:left;text-align:center;margin-right:10px; width:100px;">'.$this->l('Registered visitors').'</span>
<span style="float:left;text-align:center;margin-right:10px">
<img src="../modules/'.$this->name.'/next.png"> '.round(100 * $orders / max(1, $customers), 2).' % <img src="../modules/'.$this->name.'/next.png">
</span>
<span style="float:left;text-align:center;margin-right:10px">'.$this->l('orders').'</span>
</div>
<div class="separation"></div>
<div class="blocConversion">
<span style="float:left;text-align:center;margin-right:10px; width:100px;">'.$this->l('Visitors').'</span>
<span style="float:left;text-align:center;margin-right:10px">
<img src="../modules/'.$this->name.'/next.png"> '.round(100 * $orders / max(1, $visitors), 2).' % <img src="../modules/'.$this->name.'/next.png">
</span>
<span style="float:left;text-align:center;margin-right:10px">'.$this->l('orders').'</span>
<span style="float:left;text-align:center;margin-right:10px; width:100px;">'.$this->l('Registered visitors').'</span>
<span style="float:left;text-align:center;margin-right:10px">
<img src="../modules/'.$this->name.'/next.png"> '.round(100 * $orders / max(1, $customers), 2).' % <img src="../modules/'.$this->name.'/next.png">
</span>
<span style="float:left;text-align:center;margin-right:10px">'.$this->l('orders').'</span>
</div>
<div class="separation"></div>
<p>
'.$this->l('Turn your visitors into money:').'
<br />'.$this->l('Each visitor yields').' <b style="color:#000;">'.Tools::displayPrice($ca['ventil']['total'] / max(1, $visitors), $currency).'.</b>
<br />'.$this->l('Each registered visitor yields').' <b style="color:#000;">'.Tools::displayPrice($ca['ventil']['total'] / max(1, $customers), $currency).'</b>.
</p></div>';
<div class="separation"></div>
<div class="blocConversion">
<span style="float:left;text-align:center;margin-right:10px; width:100px;">'.$this->l('Visitors').'</span>
<span style="float:left;text-align:center;margin-right:10px">
<img src="../modules/'.$this->name.'/next.png"> '.round(100 * $orders / max(1, $visitors), 2).' % <img src="../modules/'.$this->name.'/next.png">
</span>
<span style="float:left;text-align:center;margin-right:10px">'.$this->l('orders').'</span>
</div>
<div class="separation"></div>
<p>
'.$this->l('Turn your visitors into money:').'
<br />'.$this->l('Each visitor yields').' <b style="color:#000;">'.Tools::displayPrice($ca['ventil']['total'] / max(1, $visitors), $currency).'.</b>
<br />'.$this->l('Each registered visitor yields').' <b style="color:#000;">'.Tools::displayPrice($ca['ventil']['total'] / max(1, $customers), $currency).'</b>.
</p>
</div>';
$from = strtotime($employee->stats_date_from.' 00:00:00');
$to = strtotime($employee->stats_date_to.' 23:59:59');
@@ -332,7 +331,10 @@ class StatsForecast extends Module
$this->_html .= '
<br />';
$this->_html .= '<div class="blocStats"><h2 class="icon-payment"><span></span>'.$this->l('Payment distribution').'</h2>
$this->_html .= '
<div class="blocStats">
<h2 class="icon-payment"><span></span>'.$this->l('Payment distribution').'</h2>
<p>'.$this->l('The amounts are <b>with</b> taxes, so you can get an estimation of the commission due to the payment method.').'</p>
<form id="cat" action="'.$ru.'#payment" method="post" >
<input type="hidden" name="submitIdZone" value="1" />
'.$this->l('Zone:').' <select name="stats_id_zone" onchange="this.form.submit();">
@@ -490,7 +492,7 @@ class StatsForecast extends Module
WHERE l.active = 1';
$languages = Db::getInstance()->executeS($sql);
foreach ($languages as $language)
$langValues .= 'SUM(IF(o.id_lang = '.(int)$language['id_lang'].', total_products / o.conversion_rate, 0)) as '.pSQL($language['iso_code']).',';
$langValues .= 'SUM(IF(o.id_lang = '.(int)$language['id_lang'].', total_paid_tax_excl / o.conversion_rate, 0)) as '.pSQL($language['iso_code']).',';
$langValues = rtrim($langValues, ',');
if ($langValues)
@@ -516,18 +518,18 @@ class StatsForecast extends Module
$ca['langprev'] = array();
}
$sql = 'SELECT module, SUM(total_products / o.conversion_rate) as total, COUNT(*) as nb, AVG(total_products / o.conversion_rate) as cart
$sql = 'SELECT module, SUM(total_paid_tax_incl / o.conversion_rate) as total, COUNT(*) as nb, AVG(total_paid_tax_incl / o.conversion_rate) as cart
FROM `'._DB_PREFIX_.'orders` o
'.$join.'
WHERE o.valid = 1
AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
'.$where.'
'.Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o').'
AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
'.$where.'
'.Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o').'
GROUP BY o.module
ORDER BY total DESC';
$ca['payment'] = Db::getInstance()->executeS($sql);
$sql = 'SELECT z.name, SUM(o.total_products / o.conversion_rate) as total, COUNT(*) as nb
$sql = 'SELECT z.name, SUM(o.total_paid_tax_excl / o.conversion_rate) as total, COUNT(*) as nb
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'address` a ON o.id_address_invoice = a.id_address
LEFT JOIN `'._DB_PREFIX_.'country` c ON c.id_country = a.id_country
@@ -539,7 +541,7 @@ class StatsForecast extends Module
ORDER BY total DESC';
$ca['zones'] = Db::getInstance()->executeS($sql);
$sql = 'SELECT cu.name, SUM(o.total_products / o.conversion_rate) as total, COUNT(*) as nb
$sql = 'SELECT cu.name, SUM(o.total_paid_tax_excl / o.conversion_rate) as total, COUNT(*) as nb
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'currency` cu ON o.id_currency = cu.id_currency
'.$join.'
@@ -551,7 +553,7 @@ class StatsForecast extends Module
ORDER BY total DESC';
$ca['currencies'] = Db::getInstance()->executeS($sql);
$sql = 'SELECT SUM(total_products / o.conversion_rate) as total, COUNT(*) AS nb
$sql = 'SELECT SUM(total_paid_tax_excl / o.conversion_rate) as total, COUNT(*) AS nb
FROM `'._DB_PREFIX_.'orders` o
WHERE o.valid = 1
AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
-3
View File
@@ -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}
+28 -28
View File
@@ -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}
{else}
{displayPrice price=$total_discounts}
{/if}
{else}
{displayPrice price=$total_discounts_tax_exc}
{/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">
+21 -17
View File
@@ -100,23 +100,6 @@
<td colspan="2" 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 && $display_tax_label}
{l s='Total vouchers (tax excl.):'}
{else}
{l s='Total vouchers:'}
{/if}
</td>
<td colspan="2" class="price-discount price" id="total_discount">
{if $use_taxes && !$priceDisplay}
{assign var='total_discounts_negative' value=$total_discounts * -1}
{else}
{assign var='total_discounts_negative' value=$total_discounts_tax_exc * -1}
{/if}
{displayPrice price=$total_discounts_negative}
</td>
</tr>
<tr class="cart_total_voucher" {if $total_wrapping == 0}style="display: none;"{/if}>
<td colspan="5">
{if $use_taxes}
@@ -162,6 +145,27 @@
</tr>
{/if}
{/if}
<tr class="cart_total_voucher" {if $total_discounts == 0}style="display:none"{/if}>
<td colspan="5">
{if $display_tax_label}
{if $use_taxes && $priceDisplay == 0}
{l s='Total vouchers (tax incl.):'}
{else}
{l s='Total vouchers (tax excl.):'}
{/if}
{else}
{l s='Total vouchers:'}
{/if}
</td>
<td colspan="2" class="price-discount price" id="total_discount">
{if $use_taxes}
{assign var='total_discounts_negative' value=$total_discounts * -1}
{else}
{assign var='total_discounts_negative' value=$total_discounts_tax_exc * -1}
{/if}
{displayPrice price=$total_discounts_negative}
</td>
</tr>
{if $use_taxes}
<tr class="cart_total_price">
<td colspan="5">{l s='Total (tax excl.):'}</td>