[-] Core: Fix cache issue and order slip pdf generation

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@17902 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
rGaillard
2012-10-22 12:40:15 +00:00
parent 6c09e8328d
commit 20ac37e6bb
13 changed files with 96 additions and 37 deletions
+1 -1
View File
@@ -1523,7 +1523,7 @@ class CartCore extends ObjectModel
$in_order = true;
if ($in_order)
$order_total_discount += $cart_rule['obj']->getContextualValue($with_taxes, null, CartRule::FILTER_ACTION_GIFT, $package, $use_cache);
$order_total_discount += $cart_rule['obj']->getContextualValue($with_taxes, $virtual_context, CartRule::FILTER_ACTION_GIFT, $package, $use_cache);
}
// If the cart rule offers a reduction, the amount is prorated (with the products in the package)
+4 -1
View File
@@ -1112,7 +1112,10 @@ class CartRuleCore extends ObjectModel
*/
public static function isFeatureActive()
{
return (bool)Configuration::get('PS_CART_RULE_FEATURE_ACTIVE');
static $is_feature_active = null;
if ($is_feature_active === null)
$is_feature_active = (bool)Configuration::get('PS_CART_RULE_FEATURE_ACTIVE');
return $is_feature_active;
}
/* When an entity associated to a product rule (product, category, attribute, supplier, manufacturer...) is deleted, the product rules must be updated */
+3 -3
View File
@@ -164,9 +164,9 @@ class ConfigurationCore extends ObjectModel
if ($id_shop && Configuration::hasKey($key, $id_lang, null, $id_shop))
return self::$_CONF[$id_lang]['shop'][$id_shop][$key];
else if ($id_shop_group && Configuration::hasKey($key, $id_lang, $id_shop_group))
elseif ($id_shop_group && Configuration::hasKey($key, $id_lang, $id_shop_group))
return self::$_CONF[$id_lang]['group'][$id_shop_group][$key];
else if (Configuration::hasKey($key, $id_lang))
elseif (Configuration::hasKey($key, $id_lang))
return self::$_CONF[$id_lang]['global'][$key];
return false;
}
@@ -231,7 +231,7 @@ class ConfigurationCore extends ObjectModel
$id_lang = (int)$id_lang;
if ($id_shop)
return isset(self::$_CONF[$id_lang]['shop'][$id_shop]) && array_key_exists($key, self::$_CONF[$id_lang]['shop'][$id_shop]);
else if ($id_shop_group)
elseif ($id_shop_group)
return isset(self::$_CONF[$id_lang]['group'][$id_shop_group]) && array_key_exists($key, self::$_CONF[$id_lang]['group'][$id_shop_group]);
return isset(self::$_CONF[$id_lang]['global']) && array_key_exists($key, self::$_CONF[$id_lang]['global']);
}
+1 -1
View File
@@ -410,7 +410,7 @@ class CurrencyCore extends ObjectModel
public static function getCurrencyInstance($id)
{
if (!array_key_exists($id, self::$currencies))
if (!isset(self::$currencies[$id]))
self::$currencies[(int)($id)] = new Currency($id);
return self::$currencies[(int)($id)];
}
+2 -2
View File
@@ -210,8 +210,8 @@ abstract class ObjectModelCore
// Get shop informations
if (Shop::isTableAssociated($this->def['table']))
$sql->leftJoin($this->def['table'].'_shop', 'c', 'a.'.$this->def['primary'].' = c.'.$this->def['primary'].' AND c.id_shop = '.(int)$this->id_shop);
Cache::store($cache_id, ObjectModel::$db->getRow($sql));
if ($row = ObjectModel::$db->getRow($sql))
Cache::store($cache_id, $row);
}
$result = Cache::retrieve($cache_id);
+3 -3
View File
@@ -381,7 +381,7 @@ class OrderInvoiceCore extends ObjectModel
public function getEcoTaxTaxesBreakdown()
{
$res = Db::getInstance()->executeS('
SELECT `ecotax_tax_rate` as `rate`, SUM(`ecotax`) as `ecotax_tax_excl`, SUM(`ecotax`) as `ecotax_tax_incl`, `product_quantity`
SELECT `ecotax_tax_rate` as `rate`, SUM(`ecotax` * `product_quantity`) as `ecotax_tax_excl`, SUM(`ecotax` * `product_quantity`) as `ecotax_tax_incl`
FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order` = '.(int)$this->id_order.'
AND `id_order_invoice` = '.(int)$this->id.'
@@ -391,8 +391,8 @@ class OrderInvoiceCore extends ObjectModel
if ($res)
foreach ($res as &$row)
{
$row['ecotax_tax_incl'] = Tools::ps_round(($row['ecotax_tax_excl'] * $row['product_quantity']) + ($row['ecotax_tax_excl'] * $row['product_quantity'] * $row['rate'] / 100), 2);
$row['ecotax_tax_excl'] = Tools::ps_round($row['ecotax_tax_excl'] * $row['product_quantity'], 2);
$row['ecotax_tax_incl'] = Tools::ps_round($row['ecotax_tax_excl'] + ($row['ecotax_tax_excl'] * $row['rate'] / 100), 2);
$row['ecotax_tax_excl'] = Tools::ps_round($row['ecotax_tax_excl'], 2);
}
return $res;
}
+21
View File
@@ -296,5 +296,26 @@ class OrderSlipCore extends ObjectModel
Db::getInstance()->insert('order_slip_detail', $insertOrderSlip);
}
}
public function getEcoTaxTaxesBreakdown()
{
$ecotax_detail = array();
foreach ($this->getOrdersSlipDetail((int)$this->id) as $order_slip_details)
{
$row = Db::getInstance()->getRow('
SELECT `ecotax_tax_rate` as `rate`, `ecotax` as `ecotax_tax_excl`, `ecotax` as `ecotax_tax_incl`, `product_quantity`
FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order_detail` = '.(int)$order_slip_details['id_order_detail']
);
if (!isset($ecotax_detail[$row['rate']]))
$ecotax_detail[$row['rate']] = array('ecotax_tax_incl' => 0, 'ecotax_tax_excl' => 0, 'rate' => $row['rate']);
$ecotax_detail[$row['rate']]['ecotax_tax_incl'] += Tools::ps_round(($row['ecotax_tax_excl'] * $order_slip_details['product_quantity']) + ($row['ecotax_tax_excl'] * $order_slip_details['product_quantity'] * $row['rate'] / 100), 2);
$ecotax_detail[$row['rate']]['ecotax_tax_excl'] += Tools::ps_round($row['ecotax_tax_excl'] * $order_slip_details['product_quantity'], 2);
}
return $ecotax_detail;
}
}
+11 -1
View File
@@ -154,6 +154,7 @@ class HTMLTemplateOrderSlipCore extends HTMLTemplateInvoice
'product_tax_breakdown' => $this->getProductTaxesBreakdown(),
'shipping_tax_breakdown' => $this->getShippingTaxesBreakdown(),
'order' => $this->order,
'ecotax_tax_breakdown' => $this->order_slip->getEcoTaxTaxesBreakdown(),
'is_order_slip' => true
));
@@ -205,8 +206,17 @@ class HTMLTemplateOrderSlipCore extends HTMLTemplateInvoice
}
$tmp_tax_infos[(string)number_format($tax_rate, 3)] = $infos;
}
}
// Delete ecotax from the total
$ecotax = $this->order_slip->getEcoTaxTaxesBreakdown();
if ($ecotax)
foreach ($tmp_tax_infos as $rate => &$row)
{
$row['total_price_tax_excl'] -= $ecotax[$rate]['ecotax_tax_excl'];
$row['total_amount'] -= ($ecotax[$rate]['ecotax_tax_incl'] - $ecotax[$rate]['ecotax_tax_excl']);
}
return $tmp_tax_infos;
}