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

This commit is contained in:
Jerome Nadaud committed 2013-11-13 10:02:28 +01:00
commit 6a99b84452
79 files changed
+840 -504

No files matched your search

+1 -1
View File
@@ -34,7 +34,7 @@
.toolbarBox .process-icon-new-module { background-image: url('../img/process-icon-new-module.png')} .toolbarBox .process-icon-new-module { background-image: url('../img/process-icon-new-module.png')}
.toolbarBox .process-icon-new-module-addon { background-image: url('../img/process-icon-new-module-addon.png')} .toolbarBox .process-icon-new-module-addon { background-image: url('../img/process-icon-new-module-addon.png')}
div.fix-toolbar {border-bottom: 1px solid #E0E0E0;position:fixed;top:0;opacity:0.9;z-index:1} div.fix-toolbar {border-bottom: 1px solid #E0E0E0;position:fixed;top:0;opacity:0.9;z-index:11}
/*FILTER MODULE*/ /*FILTER MODULE*/
@@ -138,7 +138,7 @@
} }
else else
{ {
$('#group_discount_category_table').append('<tr class="alt_row" id="'+jsonData.id_category+'"><td>'+jsonData.catPath+'</td><td>{l s='Discount:'}'+jsonData.discount+'{l s='%'}</td><td><a href="#" onclick="deleteCategoryReduction('+jsonData.id_category+');"><img src="../img/admin/delete.gif"></a></td></tr>'); $('#group_discount_category_table').append('<tr class="alt_row" id="'+jsonData.id_category+'"><td>'+jsonData.catPath+'</td><td>{l s='Discount:'}' + ' ' + jsonData.discount+'{l s='%'}</td><td><a href="#" onclick="deleteCategoryReduction('+jsonData.id_category+');"><img src="../img/admin/delete.gif"></a></td></tr>');
var input_hidden = document.createElement("input"); var input_hidden = document.createElement("input");
input_hidden.setAttribute('type', 'hidden'); input_hidden.setAttribute('type', 'hidden');
@@ -168,7 +168,7 @@
{foreach $input['values'] key=key item=category } {foreach $input['values'] key=key item=category }
<tr class="alt_row" id="{$category.id_category}"> <tr class="alt_row" id="{$category.id_category}">
<td>{$category.path}</td> <td>{$category.path}</td>
<td>{l s='Discount: %d%%' sprintf=$category.reduction}</td> <td>{l s='Discount: %.2f%%' sprintf=$category.reduction}</td>
<td> <td>
<a href="#" onclick="deleteCategoryReduction({$category.id_category});"><img src="../img/admin/delete.gif"></a> <a href="#" onclick="deleteCategoryReduction({$category.id_category});"><img src="../img/admin/delete.gif"></a>
<input type="hidden" class="category_reduction" name="category_reduction[{$category.id_category}]" value="{$category.reduction}"> <input type="hidden" class="category_reduction" name="category_reduction[{$category.id_category}]" value="{$category.reduction}">
@@ -30,7 +30,7 @@
<fieldset> <fieldset>
<ul> <ul>
<li><span style="font-weight: bold; font-size: 13px; color:#000;">{l s='Name:'}</span> {$group->name[$language->id]}</li> <li><span style="font-weight: bold; font-size: 13px; color:#000;">{l s='Name:'}</span> {$group->name[$language->id]}</li>
<li><span style="font-weight: bold; font-size: 13px; color:#000;">{l s='Discount: %d%%' sprintf=$group->reduction}</span></li> <li><span style="font-weight: bold; font-size: 13px; color:#000;">{l s='Discount: %.2f%%' sprintf=$group->reduction}</span></li>
<li><span style="font-weight: bold; font-size: 13px; color:#000;">{l s='Current category discount:'}</span> <li><span style="font-weight: bold; font-size: 13px; color:#000;">{l s='Current category discount:'}</span>
{if !$categorieReductions} {if !$categorieReductions}
{l s='None'} {l s='None'}
@@ -39,7 +39,7 @@
{foreach $categorieReductions key=key item=category } {foreach $categorieReductions key=key item=category }
<tr class="alt_row"> <tr class="alt_row">
<td>{$category.path}</td> <td>{$category.path}</td>
<td>{l s='Discount: %d%%' sprintf=$category.reduction}</td> <td>{l s='Discount: %.2f%%' sprintf=$category.reduction}</td>
</tr> </tr>
{/foreach} {/foreach}
</table> </table>
@@ -87,7 +87,7 @@
}); });
// Method to check / uncheck all modules checkbox // Method to check / uncheck all modules checkbox
$('#checkme').click(function() $('#moduleContainer').on("click", "#checkme", function()
{ {
if ($(this).attr("rel") == 'false') if ($(this).attr("rel") == 'false')
{ {
@@ -321,8 +321,8 @@
catch(e){} catch(e){}
return false; return false;
}); });
$('.toggle_favorite').live('click', function(event) $('#moduleContainer').on("click", ".toggle_favorite", function()
{ {
var el = $(this); var el = $(this);
var value_pref = el.data('value'); var value_pref = el.data('value');
@@ -236,7 +236,7 @@
{if isset($fields_value[$input.name].image) && $fields_value[$input.name].image} {if isset($fields_value[$input.name].image) && $fields_value[$input.name].image}
<div id="image"> <div id="image">
{$fields_value[$input.name].image} {$fields_value[$input.name].image}
<p align="center">{l s='File size'} {$fields_value[$input.name].size}kb</p> <p align="center">{l s='File size'} {$fields_value[$input.name].size}{l s='kb'}</p>
<a href="{$current}&{$identifier}={$form_id}&token={$token}&deleteImage=1"> <a href="{$current}&{$identifier}={$form_id}&token={$token}&deleteImage=1">
<img src="../img/admin/delete.gif" alt="{l s='Delete'}" /> {l s='Delete'} <img src="../img/admin/delete.gif" alt="{l s='Delete'}" /> {l s='Delete'}
</a> </a>
@@ -49,6 +49,7 @@
{/if} {/if}
class="{if !$no_link}pointer{/if} class="{if !$no_link}pointer{/if}
{if isset($params.position) && $order_by == 'position' && $order_way != 'DESC'} dragHandle{/if} {if isset($params.position) && $order_by == 'position' && $order_way != 'DESC'} dragHandle{/if}
{if isset($params.class)} {$params.class}{/if}
{if isset($params.align)} {$params.align}{/if}" {if isset($params.align)} {$params.align}{/if}"
{if (!isset($params.position) && !$no_link && !isset($params.remove_onclick))} {if (!isset($params.position) && !$no_link && !isset($params.remove_onclick))}
onclick="document.location = '{$current_index}&{$identifier}={$tr.$identifier}{if $view}&view{else}&update{/if}{$table}&token={$token}'"> onclick="document.location = '{$current_index}&{$identifier}={$tr.$identifier}{if $view}&view{else}&update{/if}{$table}&token={$token}'">
+23 -15
View File
@@ -264,13 +264,17 @@ class AddressCore extends ObjectModel
if(!isset($id_address) || empty($id_address)) if(!isset($id_address) || empty($id_address))
return false; return false;
if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' $cache_id = 'Address::isCountryActiveById_'.(int)$id_address;
SELECT c.`active` if (!Cache::isStored($cache_id))
FROM `'._DB_PREFIX_.'address` a {
LEFT JOIN `'._DB_PREFIX_.'country` c ON c.`id_country` = a.`id_country` $result = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getvalue('
WHERE a.`id_address` = '.(int)$id_address)) SELECT c.`active`
return false; FROM `'._DB_PREFIX_.'address` a
return ($result['active']); LEFT JOIN `'._DB_PREFIX_.'country` c ON c.`id_country` = a.`id_country`
WHERE a.`id_address` = '.(int)$id_address);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
@@ -324,12 +328,17 @@ class AddressCore extends ObjectModel
{ {
if (!$id_customer) if (!$id_customer)
return false; return false;
$cache_id = 'Address::getFirstCustomerAddressId_'.(int)$id_customer.'-'.(bool)$active;
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' if (!Cache::isStored($cache_id))
SELECT `id_address` {
FROM `'._DB_PREFIX_.'address` $result = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
WHERE `id_customer` = '.(int)$id_customer.' AND `deleted` = 0'.($active ? ' AND `active` = 1' : '') SELECT `id_address`
); FROM `'._DB_PREFIX_.'address`
WHERE `id_customer` = '.(int)$id_customer.' AND `deleted` = 0'.($active ? ' AND `active` = 1' : '')
);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
@@ -379,5 +388,4 @@ class AddressCore extends ObjectModel
$query->where('id_warehouse = 0'); $query->where('id_warehouse = 0');
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query); return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
} }
} }
+4 -1
View File
@@ -190,7 +190,7 @@ class CMSCore extends ObjectModel
return (Db::getInstance()->getValue($sql)); return (Db::getInstance()->getValue($sql));
} }
public static function getCMSPages($id_lang = null, $id_cms_category = null, $active = true) public static function getCMSPages($id_lang = null, $id_cms_category = null, $active = true, $id_shop = null)
{ {
$sql = new DbQuery(); $sql = new DbQuery();
$sql->select('*'); $sql->select('*');
@@ -198,6 +198,9 @@ class CMSCore extends ObjectModel
if ($id_lang) if ($id_lang)
$sql->innerJoin('cms_lang', 'l', 'c.id_cms = l.id_cms AND l.id_lang = '.(int)$id_lang); $sql->innerJoin('cms_lang', 'l', 'c.id_cms = l.id_cms AND l.id_lang = '.(int)$id_lang);
if ($id_shop)
$sql->innerJoin('cms_shop', 'cs', 'c.id_cms = cs.id_cms AND cs.id_shop = '.(int)$id_shop);
if ($active) if ($active)
$sql->where('c.active = 1'); $sql->where('c.active = 1');
+43 -24
View File
@@ -277,17 +277,20 @@ class CarrierCore extends ObjectModel
public function getMaxDeliveryPriceByWeight($id_zone) public function getMaxDeliveryPriceByWeight($id_zone)
{ {
$sql = 'SELECT d.`price` $cache_id = 'Carrier::getMaxDeliveryPriceByWeight_'.(int)$this->id.'-'.(int)$id_zone;
FROM `'._DB_PREFIX_.'delivery` d if (!Cache::isStored($cache_id))
INNER JOIN `'._DB_PREFIX_.'range_weight` w ON d.`id_range_weight` = w.`id_range_weight` {
WHERE d.`id_zone` = '.(int)$id_zone.' $sql = 'SELECT d.`price`
AND d.`id_carrier` = '.(int)$this->id.' FROM `'._DB_PREFIX_.'delivery` d
'.Carrier::sqlDeliveryRangeShop('range_weight').' INNER JOIN `'._DB_PREFIX_.'range_weight` w ON d.`id_range_weight` = w.`id_range_weight`
ORDER BY w.`delimiter2` DESC LIMIT 1'; WHERE d.`id_zone` = '.(int)$id_zone.'
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); AND d.`id_carrier` = '.(int)$this->id.'
if (!isset($result[0]['price'])) '.Carrier::sqlDeliveryRangeShop('range_weight').'
return false; ORDER BY w.`delimiter2` DESC';
return $result[0]['price']; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
@@ -357,17 +360,20 @@ class CarrierCore extends ObjectModel
public function getMaxDeliveryPriceByPrice($id_zone) public function getMaxDeliveryPriceByPrice($id_zone)
{ {
$sql = 'SELECT d.`price` $cache_id = 'Carrier::getMaxDeliveryPriceByPrice_'.(int)$this->id.'-'.(int)$id_zone;
FROM `'._DB_PREFIX_.'delivery` d if (!Cache::isStored($cache_id))
INNER JOIN `'._DB_PREFIX_.'range_price` r ON d.`id_range_price` = r.`id_range_price` {
WHERE d.`id_zone` = '.(int)$id_zone.' $sql = 'SELECT d.`price`
AND d.`id_carrier` = '.(int)$this->id.' FROM `'._DB_PREFIX_.'delivery` d
'.Carrier::sqlDeliveryRangeShop('range_price').' INNER JOIN `'._DB_PREFIX_.'range_price` r ON d.`id_range_price` = r.`id_range_price`
ORDER BY r.`delimiter2` DESC LIMIT 1'; WHERE d.`id_zone` = '.(int)$id_zone.'
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); AND d.`id_carrier` = '.(int)$this->id.'
if (!isset($result[0]['price'])) '.Carrier::sqlDeliveryRangeShop('range_price').'
return false; ORDER BY r.`delimiter2` DESC';
return $result[0]['price']; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
@@ -449,7 +455,13 @@ class CarrierCore extends ObjectModel
GROUP BY c.`id_carrier` GROUP BY c.`id_carrier`
ORDER BY c.`position` ASC'; ORDER BY c.`position` ASC';
$carriers = Db::getInstance()->executeS($sql); $cache_id = 'Carrier::getCarriers_'.md5($sql);
if (!Cache::isStored($cache_id))
{
$carriers = Db::getInstance()->executeS($sql);
Cache::store($cache_id, $carriers);
}
$carriers = Cache::retrieve($cache_id);
if (is_array($carriers) && count($carriers)) if (is_array($carriers) && count($carriers))
{ {
@@ -1199,7 +1211,14 @@ class CarrierCore extends ObjectModel
$query->where('pc.id_product = '.(int)$product->id); $query->where('pc.id_product = '.(int)$product->id);
$query->where('pc.id_shop = '.(int)$id_shop); $query->where('pc.id_shop = '.(int)$id_shop);
$carriers_for_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); $cache_id = 'Carrier::getAvailableCarrierList_'.(int)$product->id.'-'.(int)$id_shop;
if (!Cache::isStored($cache_id))
{
$carriers_for_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
Cache::store($cache_id, $carriers_for_product);
}
$carriers_for_product = Cache::retrieve($cache_id);
$carrier_list = array(); $carrier_list = array();
if (!empty($carriers_for_product)) if (!empty($carriers_for_product))
{ {
+53 -30
View File
@@ -325,7 +325,7 @@ class CartCore extends ObjectModel
if (!CartRule::isFeatureActive() || !$this->id) if (!CartRule::isFeatureActive() || !$this->id)
return array(); return array();
$cache_key = 'Cart::getCartRules'.$this->id.'-'.$filter; $cache_key = 'Cart::getCartRules_'.$this->id.'-'.$filter;
if (!Cache::isStored($cache_key)) if (!Cache::isStored($cache_key))
{ {
$result = Db::getInstance()->executeS(' $result = Db::getInstance()->executeS('
@@ -368,12 +368,16 @@ class CartCore extends ObjectModel
{ {
if (!CartRule::isFeatureActive()) if (!CartRule::isFeatureActive())
return 0; return 0;
$cache_id = 'Cart::getDiscountsCustomer_'.(int)$this->id.'-'.(int)$id_cart_rule;
return Db::getInstance()->getValue(' if (!Cache::isStored($cache_id))
SELECT COUNT(*) {
FROM `'._DB_PREFIX_.'cart_cart_rule` $result = (int)Db::getInstance()->getValue('
WHERE `id_cart_rule` = '.(int)$id_cart_rule.' AND `id_cart` = '.(int)$this->id SELECT COUNT(*)
); FROM `'._DB_PREFIX_.'cart_cart_rule`
WHERE `id_cart_rule` = '.(int)$id_cart_rule.' AND `id_cart` = '.(int)$this->id);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
public function getLastProduct() public function getLastProduct()
@@ -632,14 +636,19 @@ class CartCore extends ObjectModel
if (!isset($row['pai_id_image']) || $row['pai_id_image'] == 0) if (!isset($row['pai_id_image']) || $row['pai_id_image'] == 0)
{ {
$row2 = Db::getInstance()->getRow(' $cache_id = 'Cart::getProducts_'.'-pai_id_image-'.(int)$row['id_product'].'-'.(int)$this->id_lang.'-'.(int)$row['id_shop'];
SELECT image_shop.`id_image` id_image, il.`legend` if (!Cache::isStored($cache_id))
FROM `'._DB_PREFIX_.'image` i {
JOIN `'._DB_PREFIX_.'image_shop` image_shop ON (i.id_image = image_shop.id_image AND image_shop.cover=1 AND image_shop.id_shop='.(int)$row['id_shop'].') $row2 = Db::getInstance()->getRow('
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$this->id_lang.') SELECT image_shop.`id_image` id_image, il.`legend`
WHERE i.`id_product` = '.(int)$row['id_product'].' AND image_shop.`cover` = 1' FROM `'._DB_PREFIX_.'image` i
); JOIN `'._DB_PREFIX_.'image_shop` image_shop ON (i.id_image = image_shop.id_image AND image_shop.cover=1 AND image_shop.id_shop='.(int)$row['id_shop'].')
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$this->id_lang.')
WHERE i.`id_product` = '.(int)$row['id_product'].' AND image_shop.`cover` = 122'
);
Cache::store($cache_id, $row2);
}
$row2 = Cache::retrieve($cache_id);
if (!$row2) if (!$row2)
$row2 = array('id_image' => false, 'legend' => false); $row2 = array('id_image' => false, 'legend' => false);
else else
@@ -727,7 +736,7 @@ class CartCore extends ObjectModel
* *
* @result integer Products quantity * @result integer Products quantity
*/ */
public function nbProducts() public function nbProducts()
{ {
if (!$this->id) if (!$this->id)
return 0; return 0;
@@ -1078,9 +1087,9 @@ class CartCore extends ObjectModel
); );
$id_customization = Db::getInstance()->Insert_ID(); $id_customization = Db::getInstance()->Insert_ID();
} }
$query = 'INSERT INTO `'._DB_PREFIX_.'customized_data` (`id_customization`, `type`, `index`, `value`) $query = 'INSERT INTO `'._DB_PREFIX_.'customized_data` (`id_customization`, `type`, `index`, `value`)
VALUES ('.(int)$id_customization.', '.(int)$type.', '.(int)$index.', \''.pSql($field).'\')'; VALUES ('.(int)$id_customization.', '.(int)$type.', '.(int)$index.', \''.pSQL($field).'\')';
if (!Db::getInstance()->execute($query)) if (!Db::getInstance()->execute($query))
return false; return false;
@@ -1094,7 +1103,13 @@ class CartCore extends ObjectModel
*/ */
public function orderExists() public function orderExists()
{ {
return (bool)Db::getInstance()->getValue('SELECT count(*) FROM `'._DB_PREFIX_.'orders` WHERE `id_cart` = '.(int)$this->id); $cache_id = 'Cart::orderExists_'.(int)$this->id;
if (!Cache::isStored($cache_id))
{
$result = (bool)Db::getInstance()->getValue('SELECT count(*) FROM `'._DB_PREFIX_.'orders` WHERE `id_cart` = '.(int)$this->id);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
@@ -2277,18 +2292,23 @@ class CartCore extends ObjectModel
public function getAddressCollection() public function getAddressCollection()
{ {
$collection = array(); $collection = array();
$result = Db::getInstance()->executeS( $cache_id = 'Cart::getAddressCollection'.(int)$this->id;
'SELECT DISTINCT `id_address_delivery` if (!Cache::isStored($cache_id))
FROM `'._DB_PREFIX_.'cart_product` {
WHERE id_cart = '.(int)$this->id $result = Db::getInstance()->executeS(
); 'SELECT DISTINCT `id_address_delivery`
FROM `'._DB_PREFIX_.'cart_product`
WHERE id_cart = '.(int)$this->id
);
Cache::store($cache_id, $result);
}
$result = Cache::retrieve($cache_id);
$result[] = array('id_address_delivery' => (int)$this->id_address_delivery); $result[] = array('id_address_delivery' => (int)$this->id_address_delivery);
foreach ($result as $row) foreach ($result as $row)
if ((int)$row['id_address_delivery'] != 0) if ((int)$row['id_address_delivery'] != 0)
$collection[(int)$row['id_address_delivery']] = new Address((int)$row['id_address_delivery']); $collection[(int)$row['id_address_delivery']] = new Address((int)$row['id_address_delivery']);
return $collection; return $collection;
} }
@@ -3038,7 +3058,6 @@ class CartCore extends ObjectModel
*/ */
public function addTextFieldToProduct($id_product, $index, $type, $text_value) public function addTextFieldToProduct($id_product, $index, $type, $text_value)
{ {
$text_value = str_replace(array("\n", "\r"), '', nl2br($text_value));
if (!_PS_MAGIC_QUOTES_GPC_){ if (!_PS_MAGIC_QUOTES_GPC_){
$text_value = str_replace('\\', '\\\\', $text_value); $text_value = str_replace('\\', '\\\\', $text_value);
$text_value = str_replace('\'', '\\\'', $text_value); $text_value = str_replace('\'', '\\\'', $text_value);
@@ -3466,10 +3485,14 @@ class CartCore extends ObjectModel
) )
WHERE `id_cart` = '.(int)$this->id.' WHERE `id_cart` = '.(int)$this->id.'
'.(Configuration::get('PS_ALLOW_MULTISHIPPING') ? ' AND `id_shop` = '.(int)$this->id_shop : ''); '.(Configuration::get('PS_ALLOW_MULTISHIPPING') ? ' AND `id_shop` = '.(int)$this->id_shop : '');
$result = Db::getInstance()->execute($sql); $cache_id = 'Cart::setNoMultishipping'.(int)$this->id.'-'.(int)$this->id_shop;
if ($result) if (!Cache::isStored($cache_id))
$emptyCache = true; {
if ($result = (bool)Db::getInstance()->execute($sql))
$emptyCache = true;
Cache::store($cache_id, $result);
}
if (Customization::isFeatureActive()) if (Customization::isFeatureActive())
Db::getInstance()->execute(' Db::getInstance()->execute('
+74 -48
View File
@@ -666,9 +666,9 @@ class CategoryCore extends ObjectModel
* @param boolean $active return only active categories * @param boolean $active return only active categories
* @return array categories * @return array categories
*/ */
public static function getHomeCategories($id_lang, $active = true) public static function getHomeCategories($id_lang, $active = true, $id_shop = false)
{ {
return self::getChildren(Configuration::get('PS_HOME_CATEGORY'), $id_lang, $active); return self::getChildren(Configuration::get('PS_HOME_CATEGORY'), $id_lang, $active, $id_shop);
} }
public static function getRootCategory($id_lang = null, Shop $shop = null) public static function getRootCategory($id_lang = null, Shop $shop = null)
@@ -704,16 +704,22 @@ class CategoryCore extends ObjectModel
if (!Validate::isBool($active)) if (!Validate::isBool($active))
die(Tools::displayError()); die(Tools::displayError());
$query = 'SELECT c.`id_category`, cl.`name`, cl.`link_rewrite`, category_shop.`id_shop` $cache_id = 'Category::getChildren_'.(int)$id_parent.'-'.(int)$id_lang.'-'.(bool)$active.'-'.(int)$id_shop;
FROM `'._DB_PREFIX_.'category` c if (!Cache::isStored($cache_id))
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category`'.Shop::addSqlRestrictionOnLang('cl').') {
'.Shop::addSqlAssociation('category', 'c').' $query = 'SELECT c.`id_category`, cl.`name`, cl.`link_rewrite`, category_shop.`id_shop`
WHERE `id_lang` = '.(int)$id_lang.' FROM `'._DB_PREFIX_.'category` c
AND c.`id_parent` = '.(int)$id_parent.' LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category`'.Shop::addSqlRestrictionOnLang('cl').')
'.($active ? 'AND `active` = 1' : '').' '.Shop::addSqlAssociation('category', 'c').'
GROUP BY c.`id_category` WHERE `id_lang` = '.(int)$id_lang.'
ORDER BY category_shop.`position` ASC'; AND c.`id_parent` = '.(int)$id_parent.'
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); '.($active ? 'AND `active` = 1' : '').'
GROUP BY c.`id_category`
ORDER BY category_shop.`position` ASC';
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
@@ -1008,14 +1014,20 @@ class CategoryCore extends ObjectModel
public function getGroups() public function getGroups()
{ {
$groups = array(); $groups = array();
$result = Db::getInstance()->executeS(' $cache_id = 'Category::getGroups_'.(int)$this->id;
SELECT cg.`id_group` if (!Cache::isStored($cache_id))
FROM '._DB_PREFIX_.'category_group cg {
WHERE cg.`id_category` = '.(int)$this->id $result = Db::getInstance()->executeS('
); SELECT cg.`id_group`
foreach ($result as $group) FROM '._DB_PREFIX_.'category_group cg
$groups[] = $group['id_group']; WHERE cg.`id_category` = '.(int)$this->id
return $groups; );
$groups = array();
foreach ($result as $group)
$groups[] = $group['id_group'];
Cache::store($cache_id, $groups);
}
return Cache::retrieve($cache_id);
} }
public function addGroupsIfNoExist($id_group) public function addGroupsIfNoExist($id_group)
@@ -1036,24 +1048,23 @@ class CategoryCore extends ObjectModel
*/ */
public function checkAccess($id_customer) public function checkAccess($id_customer)
{ {
if (!$id_customer) $cache_id = 'Category::checkAccess_'.(int)$this->id.'-'.$id_customer.(!$id_customer ? '-'.(int)Group::getCurrent()->id : '');
if (!Cache::isStored($cache_id))
{ {
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' if (!$id_customer)
$result = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT ctg.`id_group` SELECT ctg.`id_group`
FROM '._DB_PREFIX_.'category_group ctg FROM '._DB_PREFIX_.'category_group ctg
WHERE ctg.`id_category` = '.(int)$this->id.' AND ctg.`id_group` = '.(int)Group::getCurrent()->id.' WHERE ctg.`id_category` = '.(int)$this->id.' AND ctg.`id_group` = '.(int)Group::getCurrent()->id);
'); else
} else { $result = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT ctg.`id_group` SELECT ctg.`id_group`
FROM '._DB_PREFIX_.'category_group ctg FROM '._DB_PREFIX_.'category_group ctg
INNER JOIN '._DB_PREFIX_.'customer_group cg on (cg.`id_group` = ctg.`id_group` AND cg.`id_customer` = '.(int)$id_customer.') INNER JOIN '._DB_PREFIX_.'customer_group cg on (cg.`id_group` = ctg.`id_group` AND cg.`id_customer` = '.(int)$id_customer.')
WHERE ctg.`id_category` = '.(int)$this->id WHERE ctg.`id_category` = '.(int)$this->id);
); Cache::store($cache_id, $result);
} }
if ($result && isset($result['id_group']) && $result['id_group']) return Cache::retrieve($cache_id);
return true;
return false;
} }
/** /**
@@ -1199,12 +1210,16 @@ class CategoryCore extends ObjectModel
*/ */
public static function getInterval($id) public static function getInterval($id)
{ {
$sql = 'SELECT nleft, nright, level_depth $cache_id = 'Category::getInterval_'.(int)$id;
FROM '._DB_PREFIX_.'category if (!Cache::isStored($cache_id))
WHERE id_category = '.(int)$id; {
if (!$result = Db::getInstance()->getRow($sql)) $sql = 'SELECT nleft, nright, level_depth
return false; FROM '._DB_PREFIX_.'category
return $result; WHERE id_category = '.(int)$id;
$result = Db::getInstance()->getRow($sql);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
@@ -1386,11 +1401,17 @@ class CategoryCore extends ObjectModel
public static function getCategoriesWithoutParent() public static function getCategoriesWithoutParent()
{ {
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' $cache_id = 'Category::getCategoriesWithoutParent_'.(int)Context::getContext()->language->id;
SELECT DISTINCT c.* if (!Cache::isStored($cache_id))
FROM `'._DB_PREFIX_.'category` c {
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = '.(int)Context::getContext()->language->id.') $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
WHERE `level_depth` = 1'); SELECT DISTINCT c.*
FROM `'._DB_PREFIX_.'category` c
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = '.(int)Context::getContext()->language->id.')
WHERE `level_depth` = 1');
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
public function isRootCategoryForAShop() public function isRootCategoryForAShop()
@@ -1409,12 +1430,17 @@ class CategoryCore extends ObjectModel
public static function getTopCategory($id_lang = null) public static function getTopCategory($id_lang = null)
{ {
if (is_null($id_lang)) if (is_null($id_lang))
$id_lang = Context::getContext()->language->id; $id_lang = (int)Context::getContext()->language->id;
$id_category = Db::getInstance()->getValue(' $cache_id = 'Category::getTopCategory_'.(int)$id_lang;
SELECT `id_category` if (!Cache::isStored($cache_id))
FROM `'._DB_PREFIX_.'category` {
WHERE `id_parent` = 0'); $id_category = (int)Db::getInstance()->getValue('
return new Category($id_category, $id_lang); SELECT `id_category`
FROM `'._DB_PREFIX_.'category`
WHERE `id_parent` = 0');
Cache::store($cache_id, new Category($id_category, $id_lang));
}
return Cache::retrieve($cache_id);
} }
public function addPosition($position, $id_shop = null) public function addPosition($position, $id_shop = null)
+10 -4
View File
@@ -296,10 +296,16 @@ class CurrencyCore extends ObjectModel
*/ */
public static function getIdByIsoCode($iso_code, $id_shop = 0) public static function getIdByIsoCode($iso_code, $id_shop = 0)
{ {
$query = Currency::getIdByQuery($id_shop); $cache_id = 'Currency::getIdByIsoCode_'.pSQL($iso_code).'-'.(int)$id_shop;
$query->where('iso_code = \''.pSQL($iso_code).'\''); if (!Cache::isStored($cache_id))
{
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query->build()); $query = Currency::getIdByQuery($id_shop);
$query->where('iso_code = \''.pSQL($iso_code).'\'');
$result = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query->build());
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
+48 -29
View File
@@ -362,15 +362,18 @@ class CustomerCore extends ObjectModel
{ {
if (!Validate::isUnsignedId($id_customer)) if (!Validate::isUnsignedId($id_customer))
return true; return true;
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' $cache_id = 'Customer::isBanned_'.(int)$id_customer;
SELECT `id_customer` if (!Cache::isStored($cache_id))
FROM `'._DB_PREFIX_.'customer` {
WHERE `id_customer` = \''.(int)$id_customer.'\' $result = (bool)!Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
AND active = 1 SELECT `id_customer`
AND `deleted` = 0'); FROM `'._DB_PREFIX_.'customer`
if (isset($result['id_customer'])) WHERE `id_customer` = \''.(int)$id_customer.'\'
return false; AND active = 1
return true; AND `deleted` = 0');
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
@@ -413,7 +416,7 @@ class CustomerCore extends ObjectModel
public static function customerHasAddress($id_customer, $id_address) public static function customerHasAddress($id_customer, $id_address)
{ {
$key = (int)$id_customer.'-'.(int)$id_address; $key = (int)$id_customer.'-'.(int)$id_address;
if (!array_key_exists($id_address, self::$_customerHasAddress)) if (!array_key_exists($key, self::$_customerHasAddress))
{ {
self::$_customerHasAddress[$key] = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' self::$_customerHasAddress[$key] = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT `id_address` SELECT `id_address`
@@ -439,15 +442,22 @@ class CustomerCore extends ObjectModel
*/ */
public function getAddresses($id_lang) public function getAddresses($id_lang)
{ {
$sql = 'SELECT DISTINCT a.*, cl.`name` AS country, s.name AS state, s.iso_code AS state_iso $share_order = (bool)Context::getContext()->shop->getGroup()->share_order;
FROM `'._DB_PREFIX_.'address` a $cache_id = 'Customer::getAddresses'.(int)$this->id.'-'.(int)$id_lang.'-'.$share_order;
LEFT JOIN `'._DB_PREFIX_.'country` c ON (a.`id_country` = c.`id_country`) if (!Cache::isStored($cache_id))
LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON (c.`id_country` = cl.`id_country`) {
LEFT JOIN `'._DB_PREFIX_.'state` s ON (s.`id_state` = a.`id_state`) $sql = 'SELECT DISTINCT a.*, cl.`name` AS country, s.name AS state, s.iso_code AS state_iso
'.(Context::getContext()->shop->getGroup()->share_order ? '' : Shop::addSqlAssociation('country', 'c')).' FROM `'._DB_PREFIX_.'address` a
WHERE `id_lang` = '.(int)$id_lang.' AND `id_customer` = '.(int)$this->id.' AND a.`deleted` = 0'; LEFT JOIN `'._DB_PREFIX_.'country` c ON (a.`id_country` = c.`id_country`)
LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON (c.`id_country` = cl.`id_country`)
LEFT JOIN `'._DB_PREFIX_.'state` s ON (s.`id_state` = a.`id_state`)
'.($share_order ? '' : Shop::addSqlAssociation('country', 'c')).'
WHERE `id_lang` = '.(int)$id_lang.' AND `id_customer` = '.(int)$this->id.' AND a.`deleted` = 0';
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
@@ -476,12 +486,17 @@ class CustomerCore extends ObjectModel
{ {
if (!Validate::isUnsignedId($id_customer) || !Validate::isMd5($passwd)) if (!Validate::isUnsignedId($id_customer) || !Validate::isMd5($passwd))
die (Tools::displayError()); die (Tools::displayError());
$cache_id = 'Customer::checkPassword'.(int)$id_customer.'-'.$passwd;
$sql = 'SELECT `id_customer` if (!Cache::isStored($cache_id))
FROM `'._DB_PREFIX_.'customer` {
WHERE `id_customer` = '.$id_customer.' $sql = 'SELECT `id_customer`
FROM `'._DB_PREFIX_.'customer`
WHERE `id_customer` = '.$id_customer.'
AND `passwd` = \''.$passwd.'\''; AND `passwd` = \''.$passwd.'\'';
return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); $result = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
@@ -574,12 +589,16 @@ class CustomerCore extends ObjectModel
public static function customerIdExistsStatic($id_customer) public static function customerIdExistsStatic($id_customer)
{ {
$row = Db::getInstance()->getRow(' $cache_id = 'Customer::customerIdExistsStatic'.(int)$id_customer;
SELECT `id_customer` if (!Cache::isStored($cache_id))
FROM '._DB_PREFIX_.'customer c {
WHERE c.`id_customer` = '.(int)$id_customer); $result = (int)Db::getInstance()->getValue('
SELECT `id_customer`
return isset($row['id_customer']); FROM '._DB_PREFIX_.'customer c
WHERE c.`id_customer` = '.(int)$id_customer);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
+10 -1
View File
@@ -305,12 +305,21 @@ class GroupCore extends ObjectModel
public static function getCurrent() public static function getCurrent()
{ {
static $groups = array(); static $groups = array();
$customer = Context::getContext()->customer; $customer = Context::getContext()->customer;
if (Validate::isLoadedObject($customer)) if (Validate::isLoadedObject($customer))
{
$id_group = (int)$customer->id_default_group; $id_group = (int)$customer->id_default_group;
$group = new Group((int)$id_group);
if (!$group->isAssociatedToShop(Context::getContext()->shop->id))
$group = new Group((int)Configuration::get('PS_CUSTOMER_GROUP'));
}
else else
$id_group = (int)Configuration::get('PS_UNIDENTIFIED_GROUP'); $id_group = (int)Configuration::get('PS_UNIDENTIFIED_GROUP');
if (!isset($groups[$id_group]) && isset($group))
$groups[$id_group] = $group;
if (!isset($groups[$id_group])) if (!isset($groups[$id_group]))
$groups[$id_group] = new Group($id_group); $groups[$id_group] = new Group($id_group);
+4 -1
View File
@@ -326,7 +326,10 @@ class HookCore extends ObjectModel
if ($frontend) if ($frontend)
{ {
$sql->leftJoin('module_group', 'mg', 'mg.`id_module` = m.`id_module`'); $sql->leftJoin('module_group', 'mg', 'mg.`id_module` = m.`id_module`');
$sql->where('mg.`id_group` IN ('.implode(', ', $groups).')'); if (Validate::isLoadedObject($context->shop))
$sql->where('mg.id_shop = '.((int)$context->shop->id).' AND mg.`id_group` IN ('.implode(', ', $groups).')');
else
$sql->where('mg.`id_group` IN ('.implode(', ', $groups).')');
$sql->groupBy('hm.id_hook, hm.id_module'); $sql->groupBy('hm.id_hook, hm.id_module');
} }
+29
View File
@@ -619,6 +619,35 @@ class LanguageCore extends ObjectModel
return Db::getInstance()->getValue('SELECT `language_code` FROM `'._DB_PREFIX_.'lang` WHERE `iso_code` = \''.pSQL(strtolower($iso_code)).'\''); return Db::getInstance()->getValue('SELECT `language_code` FROM `'._DB_PREFIX_.'lang` WHERE `iso_code` = \''.pSQL(strtolower($iso_code)).'\'');
} }
public static function getLanguageByIETFCode($code)
{
if (!Validate::isLanguageCode($code))
die(sprintf(Tools::displayError('Fatal error: IETF code %s is not correct'), $code));
// $code is in the form of 'xx-YY' where xx is the language code
// and 'YY' a country code identifying a variant of the language.
$lang_country = explode('-', $code);
// Get the language component of the code
$lang = $lang_country[0];
// Find the id_lang of the language.
// We look for anything with the correct language code
// and sort on equality with the exact IETF code wanted.
// That way using only one query we get either the exact wanted language
// or a close match.
$id_lang = Db::getInstance()->getValue(
'SELECT `id_lang` FROM '
.'`'._DB_PREFIX_.'lang` WHERE LEFT(`language_code`,2) = \''.pSQL($lang).'\' '
.'ORDER BY language_code = \''.pSQL($code).'\' DESC'
);
// Instantiate the Language object if we found it.
if ($id_lang)
return new Language($id_lang);
else
return false;
}
/** /**
* Return array (id_lang, iso_code) * Return array (id_lang, iso_code)
* *
+9
View File
@@ -423,6 +423,15 @@ class LinkCore
*/ */
public function getPageLink($controller, $ssl = null, $id_lang = null, $request = null, $request_url_encode = false, $id_shop = null) public function getPageLink($controller, $ssl = null, $id_lang = null, $request = null, $request_url_encode = false, $id_shop = null)
{ {
//If $controller contains '&' char, it means that $controller contains request data and must be parsed first
$p = strpos($controller, '&');
if ($p !== false) {
$request = substr($controller, $p + 1);
$request_url_encode = false;
$controller = substr($controller, 0, $p);
}
$controller = Tools::strReplaceFirst('.php', '', $controller); $controller = Tools::strReplaceFirst('.php', '', $controller);
if (!$id_lang) if (!$id_lang)
$id_lang = (int)Context::getContext()->language->id; $id_lang = (int)Context::getContext()->language->id;
+1
View File
@@ -63,6 +63,7 @@ class LocalizationPackCore
if ($install_mode && $res && isset($this->iso_currency)) if ($install_mode && $res && isset($this->iso_currency))
{ {
Cache::clean('Currency::getIdByIsoCode_*');
$res &= Configuration::updateValue('PS_CURRENCY_DEFAULT', (int)Currency::getIdByIsoCode($this->iso_currency)); $res &= Configuration::updateValue('PS_CURRENCY_DEFAULT', (int)Currency::getIdByIsoCode($this->iso_currency));
Currency::refreshCurrencies(); Currency::refreshCurrencies();
} }
+22 -15
View File
@@ -277,24 +277,31 @@ class MetaCore extends ObjectModel
FROM `'._DB_PREFIX_.'category_lang` cl FROM `'._DB_PREFIX_.'category_lang` cl
WHERE cl.`id_lang` = '.(int)$id_lang.' WHERE cl.`id_lang` = '.(int)$id_lang.'
AND cl.`id_category` = '.(int)$id_category.Shop::addSqlRestrictionOnLang('cl'); AND cl.`id_category` = '.(int)$id_category.Shop::addSqlRestrictionOnLang('cl');
if ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql))
$cache_id = 'Meta::getCategoryMetas'.(int)$id_category.'-'.(int)$id_lang;
if (!Cache::isStored($cache_id))
{ {
if (empty($row['meta_description'])) if ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql))
$row['meta_description'] = strip_tags($row['description']); {
if (empty($row['meta_description']))
// Paginate title $row['meta_description'] = strip_tags($row['description']);
if (!empty($row['meta_title']))
$row['meta_title'] = $title.$row['meta_title'].(!empty($page_number) ? ' ('.$page_number.')' : '').' - '.Configuration::get('PS_SHOP_NAME'); // Paginate title
if (!empty($row['meta_title']))
$row['meta_title'] = $title.$row['meta_title'].(!empty($page_number) ? ' ('.$page_number.')' : '').' - '.Configuration::get('PS_SHOP_NAME');
else
$row['meta_title'] = $row['name'].(!empty($page_number) ? ' ('.$page_number.')' : '').' - '.Configuration::get('PS_SHOP_NAME');
if (!empty($title))
$row['meta_title'] = $title.(!empty($page_number) ? ' ('.$page_number.')' : '').' - '.Configuration::get('PS_SHOP_NAME');
$result = Meta::completeMetaTags($row, $row['name']);
}
else else
$row['meta_title'] = $row['name'].(!empty($page_number) ? ' ('.$page_number.')' : '').' - '.Configuration::get('PS_SHOP_NAME'); $result = Meta::getHomeMetas($id_lang, $page_name);
Cache::store($cache_id, $result);
if (!empty($title))
$row['meta_title'] = $title.(!empty($page_number) ? ' ('.$page_number.')' : '').' - '.Configuration::get('PS_SHOP_NAME');
return Meta::completeMetaTags($row, $row['name']);
} }
return Cache::retrieve($cache_id);
return Meta::getHomeMetas($id_lang, $page_name);
} }
/** /**
+11 -6
View File
@@ -191,7 +191,7 @@ abstract class ObjectModelCore
if ($id) if ($id)
{ {
// Load object from database if object id is present // Load object from database if object id is present
$cache_id = 'objectmodel_'.$this->def['classname'].'_'.(int)$id.'_'.(int)$id_shop.'_'.(int)$id_lang; $cache_id = 'objectmodel_'.$this->def['classname'].'_'.(int)$id.'_'.(int)$this->id_shop.'_'.(int)$id_lang;
if (!Cache::isStored($cache_id)) if (!Cache::isStored($cache_id))
{ {
$sql = new DbQuery(); $sql = new DbQuery();
@@ -1234,11 +1234,16 @@ abstract class ObjectModelCore
if ($id_shop === null) if ($id_shop === null)
$id_shop = Context::getContext()->shop->id; $id_shop = Context::getContext()->shop->id;
$sql = 'SELECT id_shop $cache_id = 'objectmodel_shop_'.$this->def['classname'].'_'.(int)$this->id.'-'.(int)$id_shop;
FROM `'.pSQL(_DB_PREFIX_.$this->def['table']).'_shop` if (!Cache::isStored($cache_id))
WHERE `'.$this->def['primary'].'` = '.(int)$this->id.' {
AND id_shop = '.(int)$id_shop; $sql = 'SELECT id_shop
return (bool)Db::getInstance()->getValue($sql); FROM `'.pSQL(_DB_PREFIX_.$this->def['table']).'_shop`
WHERE `'.$this->def['primary'].'` = '.(int)$this->id.'
AND id_shop = '.(int)$id_shop;
Cache::store($cache_id, (bool)Db::getInstance()->getValue($sql));
}
return Cache::retrieve($cache_id);
} }
/** /**
+64 -56
View File
@@ -229,7 +229,13 @@ class ProductCore extends ObjectModel
protected static $_prices = array(); protected static $_prices = array();
protected static $_pricesLevel2 = array(); protected static $_pricesLevel2 = array();
protected static $_incat = array(); protected static $_incat = array();
/**
* @since 1.5.6.1
* @var array $_cart_quantity is deprecated since 1.5.6.1
*/
protected static $_cart_quantity = array(); protected static $_cart_quantity = array();
protected static $_tax_rules_group = array(); protected static $_tax_rules_group = array();
protected static $_cacheFeatures = array(); protected static $_cacheFeatures = array();
protected static $_frontFeaturesCache = array(); protected static $_frontFeaturesCache = array();
@@ -2434,13 +2440,18 @@ class ProductCore extends ObjectModel
{ {
if (!$context) if (!$context)
$context = Context::getContext(); $context = Context::getContext();
$cache_id = 'Product::getOrderStates_'.(int)$id_product.'-'.(int)$context->shop->id;
$sql = 'SELECT image_shop.`id_image` if (!Cache::isStored($cache_id))
FROM `'._DB_PREFIX_.'image` i {
'.Shop::addSqlAssociation('image', 'i').' $sql = 'SELECT image_shop.`id_image`
WHERE i.`id_product` = '.(int)$id_product.' FROM `'._DB_PREFIX_.'image` i
AND image_shop.`cover` = 1'; '.Shop::addSqlAssociation('image', 'i').'
return Db::getInstance()->getRow($sql); WHERE i.`id_product` = '.(int)$id_product.'
AND image_shop.`cover` = 1';
$result = Db::getInstance()->getRow($sql);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
@@ -2502,15 +2513,17 @@ class ProductCore extends ObjectModel
$cart_quantity = 0; $cart_quantity = 0;
if ((int)$id_cart) if ((int)$id_cart)
{ {
$condition = ''; $cache_id = 'Product::getPriceStatic_'.(int)$id_product.'-'.(int)$id_cart;
$cache_name = (int)$id_cart.'_'.(int)$id_product; if (!Cache::isStored($cache_id))
if (!isset(self::$_cart_quantity[$cache_name]) || self::$_cart_quantity[$cache_name] != (int)$quantity) {
self::$_cart_quantity[$cache_name] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' $sql = 'SELECT SUM(`quantity`)
SELECT SUM(`quantity`)
FROM `'._DB_PREFIX_.'cart_product` FROM `'._DB_PREFIX_.'cart_product`
WHERE `id_product` = '.(int)$id_product.' WHERE `id_product` = '.(int)$id_product.'
AND `id_cart` = '.(int)$id_cart); AND `id_cart` = '.(int)$id_cart;
$cart_quantity = self::$_cart_quantity[$cache_name]; $cart_quantity = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
Cache::store($cache_id, $cart_quantity);
}
$cart_quantity = Cache::retrieve($cache_id);
} }
$id_currency = (int)Validate::isLoadedObject($context->currency) ? $context->currency->id : Configuration::get('PS_CURRENCY_DEFAULT'); $id_currency = (int)Validate::isLoadedObject($context->currency) ? $context->currency->id : Configuration::get('PS_CURRENCY_DEFAULT');
@@ -4300,19 +4313,25 @@ class ProductCore extends ObjectModel
public function checkAccess($id_customer) public function checkAccess($id_customer)
{ {
if (!$id_customer) $cache_id = 'Product::checkAccess_'.(int)$this->id.'-'.(int)$id_customer.(!$id_customer ? '-'.(int)Group::getCurrent()->id : '');
return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' if (!Cache::isStored($cache_id))
SELECT ctg.`id_group` {
FROM `'._DB_PREFIX_.'category_product` cp if (!$id_customer)
INNER JOIN `'._DB_PREFIX_.'category_group` ctg ON (ctg.`id_category` = cp.`id_category`) $result = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
WHERE cp.`id_product` = '.(int)$this->id.' AND ctg.`id_group` ='.(int)Group::getCurrent()->id); SELECT ctg.`id_group`
else FROM `'._DB_PREFIX_.'category_product` cp
return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' INNER JOIN `'._DB_PREFIX_.'category_group` ctg ON (ctg.`id_category` = cp.`id_category`)
SELECT cg.`id_group` WHERE cp.`id_product` = '.(int)$this->id.' AND ctg.`id_group` = '.(int)Group::getCurrent()->id);
FROM `'._DB_PREFIX_.'category_product` cp else
INNER JOIN `'._DB_PREFIX_.'category_group` ctg ON (ctg.`id_category` = cp.`id_category`) $result = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
INNER JOIN `'._DB_PREFIX_.'customer_group` cg ON (cg.`id_group` = ctg.`id_group`) SELECT cg.`id_group`
WHERE cp.`id_product` = '.(int)$this->id.' AND cg.`id_customer` = '.(int)$id_customer); FROM `'._DB_PREFIX_.'category_product` cp
INNER JOIN `'._DB_PREFIX_.'category_group` ctg ON (ctg.`id_category` = cp.`id_category`)
INNER JOIN `'._DB_PREFIX_.'customer_group` cg ON (cg.`id_group` = ctg.`id_group`)
WHERE cp.`id_product` = '.(int)$this->id.' AND cg.`id_customer` = '.(int)$id_customer);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
@@ -4872,8 +4891,12 @@ class ProductCore extends ObjectModel
*/ */
public static function getAttributesParams($id_product, $id_product_attribute) public static function getAttributesParams($id_product, $id_product_attribute)
{ {
$id_lang = (int)Context::getContext()->language->id;
$id_shop = (int)Context::getContext()->shop->id;
$cache_id = 'Product::getAttributesParams_'.(int)$id_product.'-'.(int)$id_product_attribute.'-'.(int)$id_lang.'-'.(int)$id_shop;
// if blocklayered module is installed we check if user has set custom attribute name // if blocklayered module is installed we check if user has set custom attribute name
if (Module::isInstalled('blocklayered')) if (Module::isInstalled('blocklayered') && Module::isEnabled('blocklayered'))
{ {
$nb_custom_values = Db::getInstance()->executeS(' $nb_custom_values = Db::getInstance()->executeS('
SELECT DISTINCT la.`id_attribute`, la.`url_name` as `name` SELECT DISTINCT la.`id_attribute`, la.`url_name` as `name`
@@ -4884,7 +4907,7 @@ class ProductCore extends ObjectModel
ON (pac.`id_product_attribute` = pa.`id_product_attribute`) ON (pac.`id_product_attribute` = pa.`id_product_attribute`)
'.Shop::addSqlAssociation('product_attribute', 'pa').' '.Shop::addSqlAssociation('product_attribute', 'pa').'
LEFT JOIN `'._DB_PREFIX_.'layered_indexable_attribute_lang_value` la LEFT JOIN `'._DB_PREFIX_.'layered_indexable_attribute_lang_value` la
ON (la.`id_attribute` = a.`id_attribute` AND la.`id_lang` = '.(int)Context::getContext()->language->id.') ON (la.`id_attribute` = a.`id_attribute` AND la.`id_lang` = '.(int)$id_lang.')
WHERE la.`url_name` IS NOT NULL AND la.`url_name` != \'\' WHERE la.`url_name` IS NOT NULL AND la.`url_name` != \'\'
AND pa.`id_product` = '.(int)$id_product.' AND pa.`id_product` = '.(int)$id_product.'
AND pac.`id_product_attribute` = '.(int)$id_product_attribute); AND pac.`id_product_attribute` = '.(int)$id_product_attribute);
@@ -4902,7 +4925,7 @@ class ProductCore extends ObjectModel
LEFT JOIN `'._DB_PREFIX_.'attribute` a LEFT JOIN `'._DB_PREFIX_.'attribute` a
ON (a.`id_attribute_group` = g.`id_attribute_group`) ON (a.`id_attribute_group` = g.`id_attribute_group`)
WHERE a.`id_attribute` = '.(int)$attribute['id_attribute'].' WHERE a.`id_attribute` = '.(int)$attribute['id_attribute'].'
AND g.`id_lang` = '.(int)Context::getContext()->language->id.' AND g.`id_lang` = '.(int)$id_lang.'
AND g.`url_name` IS NOT NULL AND g.`url_name` != \'\''); AND g.`url_name` IS NOT NULL AND g.`url_name` != \'\'');
if (empty($group)) if (empty($group))
{ {
@@ -4912,7 +4935,7 @@ class ProductCore extends ObjectModel
LEFT JOIN `'._DB_PREFIX_.'attribute` a LEFT JOIN `'._DB_PREFIX_.'attribute` a
ON (a.`id_attribute_group` = g.`id_attribute_group`) ON (a.`id_attribute_group` = g.`id_attribute_group`)
WHERE a.`id_attribute` = '.(int)$attribute['id_attribute'].' WHERE a.`id_attribute` = '.(int)$attribute['id_attribute'].'
AND g.`id_lang` = '.(int)Context::getContext()->language->id.' AND g.`id_lang` = '.(int)$id_lang.'
AND g.`name` IS NOT NULL'); AND g.`name` IS NOT NULL');
} }
$result[] = array_merge($attribute, $group[0]); $result[] = array_merge($attribute, $group[0]);
@@ -4921,9 +4944,9 @@ class ProductCore extends ObjectModel
SELECT DISTINCT a.`id_attribute_group`, al.`name`, agl.`name` as `group` SELECT DISTINCT a.`id_attribute_group`, al.`name`, agl.`name` as `group`
FROM `'._DB_PREFIX_.'attribute` a FROM `'._DB_PREFIX_.'attribute` a
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al
ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)Context::getContext()->language->id.') ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl
ON (a.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)Context::getContext()->language->id.') ON (a.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac
ON (a.`id_attribute` = pac.`id_attribute`) ON (a.`id_attribute` = pac.`id_attribute`)
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa
@@ -4932,45 +4955,30 @@ class ProductCore extends ObjectModel
WHERE pa.`id_product` = '.(int)$id_product.' WHERE pa.`id_product` = '.(int)$id_product.'
AND pac.id_product_attribute = '.(int)$id_product_attribute.' AND pac.id_product_attribute = '.(int)$id_product_attribute.'
AND a.`id_attribute` NOT IN('.implode(', ', $tab_id_attribute).')'); AND a.`id_attribute` NOT IN('.implode(', ', $tab_id_attribute).')');
$result = array_merge($values_not_custom, $result); return array_merge($values_not_custom, $result);
}
else
{
$result = Db::getInstance()->executeS('
SELECT al.`name`, agl.`name` as `group`
FROM `'._DB_PREFIX_.'attribute` a
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al
ON (al.`id_attribute` = a.`id_attribute` AND al.`id_lang` = '.(int)Context::getContext()->language->id.')
LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac
ON (pac.`id_attribute` = a.`id_attribute`)
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa
ON (pa.`id_product_attribute` = pac.`id_product_attribute`)
'.Shop::addSqlAssociation('product_attribute', 'pa').'
LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl
ON (a.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)Context::getContext()->language->id.')
WHERE pa.`id_product` = '.(int)$id_product.'
AND pac.`id_product_attribute` = '.(int)$id_product_attribute.'
AND agl.`id_lang` = '.(int)Context::getContext()->language->id);
} }
} }
else
if (!Cache::isStored($cache_id))
{ {
$result = Db::getInstance()->executeS(' $result = Db::getInstance()->executeS('
SELECT al.`name`, agl.`name` as `group` SELECT al.`name`, agl.`name` as `group`
FROM `'._DB_PREFIX_.'attribute` a FROM `'._DB_PREFIX_.'attribute` a
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al
ON (al.`id_attribute` = a.`id_attribute` AND al.`id_lang` = '.(int)Context::getContext()->language->id.') ON (al.`id_attribute` = a.`id_attribute` AND al.`id_lang` = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac
ON (pac.`id_attribute` = a.`id_attribute`) ON (pac.`id_attribute` = a.`id_attribute`)
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa
ON (pa.`id_product_attribute` = pac.`id_product_attribute`) ON (pa.`id_product_attribute` = pac.`id_product_attribute`)
'.Shop::addSqlAssociation('product_attribute', 'pa').' '.Shop::addSqlAssociation('product_attribute', 'pa').'
LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl
ON (a.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)Context::getContext()->language->id.') ON (a.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)$id_lang.')
WHERE pa.`id_product` = '.(int)$id_product.' WHERE pa.`id_product` = '.(int)$id_product.'
AND pac.`id_product_attribute` = '.(int)$id_product_attribute.' AND pac.`id_product_attribute` = '.(int)$id_product_attribute.'
AND agl.`id_lang` = '.(int)Context::getContext()->language->id); AND agl.`id_lang` = '.(int)$id_lang);
Cache::store($cache_id, $result);
} }
$result = Cache::retrieve($cache_id);
return $result; return $result;
} }
-1
View File
@@ -89,7 +89,6 @@ class ProductSaleCore
$ids = count($ids) > 0 ? implode(',', $ids) : 'NULL'; $ids = count($ids) > 0 ? implode(',', $ids) : 'NULL';
//Main query //Main query
if ($order_by == 'date_add')
$sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, $sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity,
pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`,
pl.`meta_keywords`, pl.`meta_title`, pl.`name`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`,
+26 -14
View File
@@ -80,13 +80,19 @@ class StateCore extends ObjectModel
*/ */
public static function getNameById($id_state) public static function getNameById($id_state)
{ {
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' if (!$id_state)
SELECT `name` return false;
FROM `'._DB_PREFIX_.'state` $cache_id = 'State::getNameById_'.(int)$id_state;
WHERE `id_state` = '.(int)$id_state if (!Cache::isStored($cache_id))
); {
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
return $result['name']; SELECT `name`
FROM `'._DB_PREFIX_.'state`
WHERE `id_state` = '.(int)$id_state
);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
@@ -97,13 +103,19 @@ class StateCore extends ObjectModel
*/ */
public static function getIdByName($state) public static function getIdByName($state)
{ {
$result = Db::getInstance()->getValue(' if (empty($state))
SELECT `id_state` return false;
FROM `'._DB_PREFIX_.'state` $cache_id = 'State::getNameById_'.pSQL($state);
WHERE `name` LIKE \''.pSQL($state).'\' if (!Cache::isStored($cache_id))
'); {
$result = (int)Db::getInstance()->getValue('
return (int)$result; SELECT `id_state`
FROM `'._DB_PREFIX_.'state`
WHERE `name` LIKE \''.pSQL($state).'\'
');
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
+14 -8
View File
@@ -190,14 +190,20 @@ class TabCore extends ObjectModel
*/ */
public static function getTab($id_lang, $id_tab) public static function getTab($id_lang, $id_tab)
{ {
/* Tabs selection */ $cache_id = 'Tab::getTab_'.(int)$id_lang.'-'.(int)$id_tab;
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' if (!Cache::isStored($cache_id))
SELECT * {
FROM `'._DB_PREFIX_.'tab` t /* Tabs selection */
LEFT JOIN `'._DB_PREFIX_.'tab_lang` tl $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
ON (t.`id_tab` = tl.`id_tab` AND tl.`id_lang` = '.(int)$id_lang.') SELECT *
WHERE t.`id_tab` = '.(int)$id_tab FROM `'._DB_PREFIX_.'tab` t
); LEFT JOIN `'._DB_PREFIX_.'tab_lang` tl
ON (t.`id_tab` = tl.`id_tab` AND tl.`id_lang` = '.(int)$id_lang.')
WHERE t.`id_tab` = '.(int)$id_tab
);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
+11 -15
View File
@@ -346,17 +346,12 @@ class ToolsCore
/* Automatically detect language if not already defined, detect_language is set in Cookie::update */ /* Automatically detect language if not already defined, detect_language is set in Cookie::update */
if ((!$cookie->id_lang || isset($cookie->detect_language)) && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) if ((!$cookie->id_lang || isset($cookie->detect_language)) && isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
{ {
$array = explode(',', Tools::strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE'])); $array = explode(',', Tools::strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']));
if (Tools::strlen($array[0]) > 2) $string = $array[0];
if (Validate::isLanguageCode($string))
{ {
$tab = explode('-', $array[0]); $lang = Language::getLanguageByIETFCode($string);
$string = $tab[0];
}
else
$string = $array[0];
if (Validate::isLanguageIsoCode($string))
{
$lang = new Language(Language::getIdByIso($string));
if (Validate::isLoadedObject($lang) && $lang->active && $lang->isAssociatedToShop()) if (Validate::isLoadedObject($lang) && $lang->active && $lang->isAssociatedToShop())
{ {
Context::getContext()->language = $lang; Context::getContext()->language = $lang;
@@ -364,7 +359,7 @@ class ToolsCore
} }
} }
} }
if (isset($cookie->detect_language)) if (isset($cookie->detect_language))
unset($cookie->detect_language); unset($cookie->detect_language);
@@ -374,7 +369,7 @@ class ToolsCore
$iso = Language::getIsoById((int)$cookie->id_lang); $iso = Language::getIsoById((int)$cookie->id_lang);
@include_once(_PS_THEME_DIR_.'lang/'.$iso.'.php'); @include_once(_PS_THEME_DIR_.'lang/'.$iso.'.php');
return $iso; return $iso;
} }
@@ -689,9 +684,10 @@ class ToolsCore
public static function safePostVars() public static function safePostVars()
{ {
if (!is_array($_POST)) if (!isset($_POST) || !is_array($_POST))
return array(); $_POST = array();
$_POST = array_map(array('Tools', 'htmlentitiesUTF8'), $_POST); else
$_POST = array_map(array('Tools', 'htmlentitiesUTF8'), $_POST);
} }
/** /**
+12 -6
View File
@@ -54,12 +54,18 @@ class ZoneCore extends ObjectModel
*/ */
public static function getZones($active = false) public static function getZones($active = false)
{ {
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' $cache_id = 'Zone::getZones_'.(bool)$active;
SELECT * if (!Cache::isStored($cache_id))
FROM `'._DB_PREFIX_.'zone` {
'.($active ? 'WHERE active = 1' : '').' $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
ORDER BY `name` ASC SELECT *
'); FROM `'._DB_PREFIX_.'zone`
'.($active ? 'WHERE active = 1' : '').'
ORDER BY `name` ASC
');
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
+2 -2
View File
@@ -523,13 +523,13 @@ abstract class DbCore
$this->last_cached = true; $this->last_cached = true;
return $result; return $result;
} }
$this->result = $this->query($sql); $this->result = $this->query($sql);
if (!$this->result) if (!$this->result)
return false; return false;
$this->last_cached = false; $this->last_cached = false;
$result = $this->nextRow($this->result); $result = $this->nextRow($this->result);
if (is_null($result))
$result = false;
if ($use_cache && $this->is_cache_enabled) if ($use_cache && $this->is_cache_enabled)
Cache::getInstance()->setQuery($sql, $result); Cache::getInstance()->setQuery($sql, $result);
return $result; return $result;
+7 -1
View File
@@ -1864,7 +1864,13 @@ abstract class ModuleCore
*/ */
public static function getModuleIdByName($name) public static function getModuleIdByName($name)
{ {
return Db::getInstance()->getValue('SELECT `id_module` FROM `'._DB_PREFIX_.'module` WHERE `name` = "'.pSQL($name).'"'); $cache_id = 'Module::getModuleIdByName_'.pSQL($name);
if (!Cache::isStored($cache_id))
{
$result = (int)Db::getInstance()->getValue('SELECT `id_module` FROM `'._DB_PREFIX_.'module` WHERE `name` = "'.pSQL($name).'"');
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
+11 -5
View File
@@ -721,11 +721,17 @@ class OrderCore extends ObjectModel
public static function getDiscountsCustomer($id_customer, $id_cart_rule) public static function getDiscountsCustomer($id_customer, $id_cart_rule)
{ {
return Db::getInstance()->getValue(' $cache_id = 'Order::getDiscountsCustomer_'.(int)$id_customer.'-'.(int)$id_cart_rule;
SELECT COUNT(*) FROM `'._DB_PREFIX_.'orders` o if (!Cache::isStored($cache_id))
LEFT JOIN '._DB_PREFIX_.'order_cart_rule ocr ON (ocr.id_order = o.id_order) {
WHERE o.id_customer = '.(int)$id_customer.' $result = (int)Db::getInstance()->getValue('
AND ocr.id_cart_rule = '.(int)$id_cart_rule); SELECT COUNT(*) FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN '._DB_PREFIX_.'order_cart_rule ocr ON (ocr.id_order = o.id_order)
WHERE o.id_customer = '.(int)$id_customer.'
AND ocr.id_cart_rule = '.(int)$id_cart_rule);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
+12 -6
View File
@@ -112,12 +112,18 @@ class OrderStateCore extends ObjectModel
*/ */
public static function getOrderStates($id_lang) public static function getOrderStates($id_lang)
{ {
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' $cache_id = 'OrderState::getOrderStates_'.(int)$id_lang;
SELECT * if (!Cache::isStored($cache_id))
FROM `'._DB_PREFIX_.'order_state` os {
LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int)$id_lang.') $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
WHERE deleted = 0 SELECT *
ORDER BY `name` ASC'); FROM `'._DB_PREFIX_.'order_state` os
LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int)$id_lang.')
WHERE deleted = 0
ORDER BY `name` ASC');
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
+13 -8
View File
@@ -187,14 +187,19 @@ class ShopCore extends ObjectModel
public function setUrl() public function setUrl()
{ {
$row = Db::getInstance()->getRow(' $cache_id = 'Shop::setUrl_'.(int)$this->id;
SELECT su.physical_uri, su.virtual_uri, su.domain, su.domain_ssl, t.id_theme, t.name, t.directory if (!Cache::isStored($cache_id))
FROM '._DB_PREFIX_.'shop s {
LEFT JOIN '._DB_PREFIX_.'shop_url su ON (s.id_shop = su.id_shop) $row = Db::getInstance()->getRow('
LEFT JOIN '._DB_PREFIX_.'theme t ON (t.id_theme = s.id_theme) SELECT su.physical_uri, su.virtual_uri, su.domain, su.domain_ssl, t.id_theme, t.name, t.directory
WHERE s.id_shop = '.(int)$this->id.' FROM '._DB_PREFIX_.'shop s
AND s.active = 1 AND s.deleted = 0 AND su.main = 1'); LEFT JOIN '._DB_PREFIX_.'shop_url su ON (s.id_shop = su.id_shop)
LEFT JOIN '._DB_PREFIX_.'theme t ON (t.id_theme = s.id_theme)
WHERE s.id_shop = '.(int)$this->id.'
AND s.active = 1 AND s.deleted = 0 AND su.main = 1');
Cache::store($cache_id, $row);
}
$row = Cache::retrieve($cache_id);
if (!$row) if (!$row)
return false; return false;
+18 -11
View File
@@ -53,6 +53,8 @@ class StockAvailableCore extends ObjectModel
/** @var bool determine if a product is out of stock - it was previously in Product class */ /** @var bool determine if a product is out of stock - it was previously in Product class */
public $out_of_stock = false; public $out_of_stock = false;
protected static $cache_quantity_available;
/** /**
* @see ObjectModel::$definition * @see ObjectModel::$definition
*/ */
@@ -343,18 +345,23 @@ class StockAvailableCore extends ObjectModel
if ($id_product_attribute === null) if ($id_product_attribute === null)
$id_product_attribute = 0; $id_product_attribute = 0;
$query = new DbQuery(); $key = (int)$id_product.'-'.(int)$id_product_attribute.'-'.(int)$id_shop;
$query->select('SUM(quantity)'); if (!isset(self::$cache_quantity_available[$key]))
$query->from('stock_available'); {
$query = new DbQuery();
$query->select('SUM(quantity)');
$query->from('stock_available');
// if null, it's a product without attributes
if ($id_product !== null)
$query->where('id_product = '.(int)$id_product);
$query->where('id_product_attribute = '.(int)$id_product_attribute);
$query = StockAvailable::addSqlShopRestriction($query, $id_shop);
// if null, it's a product without attributes self::$cache_quantity_available[$key] = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
if ($id_product !== null) }
$query->where('id_product = '.(int)$id_product); return self::$cache_quantity_available[$key];
$query->where('id_product_attribute = '.(int)$id_product_attribute);
$query = StockAvailable::addSqlShopRestriction($query, $id_shop);
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
} }
/** /**
+7 -3
View File
@@ -124,9 +124,13 @@ class TaxRuleCore extends ObjectModel
*/ */
public static function isTaxInUse($id_tax) public static function isTaxInUse($id_tax)
{ {
return Db::getInstance()->getValue(' $cache_id = 'TaxRule::isTaxInUse_'.(int)$id_tax;
SELECT COUNT(*) FROM `'._DB_PREFIX_.'tax_rule` WHERE `id_tax` = '.(int)$id_tax if (!Cache::isStored($cache_id))
); {
$result = (int)Db::getInstance()->getValue('SELECT COUNT(*) FROM `'._DB_PREFIX_.'tax_rule` WHERE `id_tax` = '.(int)$id_tax);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
+5 -10
View File
@@ -33,9 +33,6 @@ class TaxRulesTaxManagerCore implements TaxManagerInterface
public $type; public $type;
public $tax_calculator; public $tax_calculator;
protected static $cache_tax_calculator;
/** /**
* *
* @param Address $address * @param Address $address
@@ -80,7 +77,8 @@ class TaxRulesTaxManagerCore implements TaxManagerInterface
if (!empty($this->address->postcode)) if (!empty($this->address->postcode))
$postcode = $this->address->postcode; $postcode = $this->address->postcode;
if (!isset(self::$cache_tax_calculator[(int)$this->address->id_country.'-'.$postcode.'-'.$this->type])) $cache_id = (int)$this->address->id_country.'-'.(int)$this->address->id_state.'-'.$postcode.'-'.(int)$this->type;
if (!Cache::isStored($cache_id))
{ {
$rows = Db::getInstance()->executeS(' $rows = Db::getInstance()->executeS('
SELECT * SELECT *
@@ -110,11 +108,8 @@ class TaxRulesTaxManagerCore implements TaxManagerInterface
if ($row['behavior'] == 0) if ($row['behavior'] == 0)
break; break;
} }
Cache::store($cache_id, new TaxCalculator($taxes, $behavior));
self::$cache_tax_calculator[$postcode.'-'.$this->type] = new TaxCalculator($taxes, $behavior);
} }
return Cache::retrieve($cache_id);
return self::$cache_tax_calculator[$postcode.'-'.$this->type];
} }
} }
@@ -2660,6 +2660,10 @@ class AdminProductsControllerCore extends AdminController
$product_supplier->id_product = $product->id; $product_supplier->id_product = $product->id;
$product_supplier->id_product_attribute = 0; $product_supplier->id_product_attribute = 0;
$product_supplier->id_supplier = $id; $product_supplier->id_supplier = $id;
if ($this->context->currency->id)
$product_supplier->id_currency = (int)$this->context->currency->id;
else
$product_supplier->id_currency = (int)Configuration::get('PS_CURRENCY_DEFAULT');
$product_supplier->save(); $product_supplier->save();
$associated_suppliers[] = $product_supplier; $associated_suppliers[] = $product_supplier;
+8 -4
View File
@@ -30,12 +30,13 @@ class CmsControllerCore extends FrontController
public $assignCase; public $assignCase;
public $cms; public $cms;
public $cms_category; public $cms_category;
public $ssl = false;
public function canonicalRedirection($canonicalURL = '') public function canonicalRedirection($canonicalURL = '')
{ {
if (Tools::getValue('live_edit')) if (Tools::getValue('live_edit'))
return ; return ;
if (Validate::isLoadedObject($this->cms) && ($canonicalURL = $this->context->link->getCMSLink($this->cms))) if (Validate::isLoadedObject($this->cms) && ($canonicalURL = $this->context->link->getCMSLink($this->cms, $this->cms->link_rewrite, $this->ssl)))
parent::canonicalRedirection($canonicalURL); parent::canonicalRedirection($canonicalURL);
else if (Validate::isLoadedObject($this->cms_category) && ($canonicalURL = $this->context->link->getCMSCategoryLink($this->cms_category))) else if (Validate::isLoadedObject($this->cms_category) && ($canonicalURL = $this->context->link->getCMSCategoryLink($this->cms_category)))
parent::canonicalRedirection($canonicalURL); parent::canonicalRedirection($canonicalURL);
@@ -47,13 +48,16 @@ class CmsControllerCore extends FrontController
*/ */
public function init() public function init()
{ {
parent::init();
if ($id_cms = (int)Tools::getValue('id_cms')) if ($id_cms = (int)Tools::getValue('id_cms'))
$this->cms = new CMS($id_cms, $this->context->language->id); $this->cms = new CMS($id_cms, $this->context->language->id);
else if ($id_cms_category = (int)Tools::getValue('id_cms_category')) else if ($id_cms_category = (int)Tools::getValue('id_cms_category'))
$this->cms_category = new CMSCategory($id_cms_category, $this->context->language->id); $this->cms_category = new CMSCategory($id_cms_category, $this->context->language->id);
if (Configuration::get('PS_SSL_ENABLED') && Tools::getValue('content_only') && Tools::getValue('id_cms') == (int)Configuration::get('PS_CONDITIONS_CMS_ID') && Validate::isLoadedObject($this->cms))
$this->ssl = true;
parent::init();
$this->canonicalRedirection(); $this->canonicalRedirection();
// assignCase (1 = CMS page, 2 = CMS category) // assignCase (1 = CMS page, 2 = CMS category)
@@ -120,7 +124,7 @@ class CmsControllerCore extends FrontController
'category' => $this->cms_category, //for backward compatibility 'category' => $this->cms_category, //for backward compatibility
'cms_category' => $this->cms_category, 'cms_category' => $this->cms_category,
'sub_category' => $this->cms_category->getSubCategories($this->context->language->id), 'sub_category' => $this->cms_category->getSubCategories($this->context->language->id),
'cms_pages' => CMS::getCMSPages($this->context->language->id, (int)($this->cms_category->id) ), 'cms_pages' => CMS::getCMSPages($this->context->language->id, (int)($this->cms_category->id), true, (int)$this->context->shop->id),
'path' => ($this->cms_category->id !== 1) ? Tools::getPath($this->cms_category->id, $this->cms_category->name, false, 'CMS') : '', 'path' => ($this->cms_category->id !== 1) ? Tools::getPath($this->cms_category->id, $this->cms_category->name, false, 'CMS') : '',
)); ));
} }
+12 -11
View File
@@ -415,6 +415,17 @@ class ParentOrderControllerCore extends FrontController
if (key($customerAddresses) != 0) if (key($customerAddresses) != 0)
$customerAddresses = array_values($customerAddresses); $customerAddresses = array_values($customerAddresses);
if (!count($customerAddresses))
{
$bad_delivery = false;
if (($bad_delivery = (bool)!Address::isCountryActiveById((int)$this->context->cart->id_address_delivery)) || (!Address::isCountryActiveById((int)$this->context->cart->id_address_invoice)))
{
$back_url = $this->context->link->getPageLink('order', true, (int)$this->context->language->id, array('step' => Tools::getValue('step'), 'multi-shipping' => (int)Tools::getValue('multi-shipping')));
$params = array('multi-shipping' => (int)Tools::getValue('multi-shipping'), 'id_address' => ($bad_delivery ? (int)$this->context->cart->id_address_delivery : (int)$this->context->cart->id_address_invoice), 'back' => $back_url);
Tools::redirect($this->context->link->getPageLink('address', true, (int)$this->context->language->id, $params));
}
}
$this->context->smarty->assign(array( $this->context->smarty->assign(array(
'addresses' => $customerAddresses, 'addresses' => $customerAddresses,
'formatedAddressFieldsValuesList' => $formatedAddressFieldsValuesList)); 'formatedAddressFieldsValuesList' => $formatedAddressFieldsValuesList));
@@ -465,16 +476,6 @@ class ParentOrderControllerCore extends FrontController
$address = new Address($this->context->cart->id_address_delivery); $address = new Address($this->context->cart->id_address_delivery);
$id_zone = Address::getZoneById($address->id); $id_zone = Address::getZoneById($address->id);
$bad_delivery = false; $bad_delivery = false;
if (($bad_delivery = (bool)!Address::isCountryActiveById((int)$this->context->cart->id_address_delivery)) || (!Address::isCountryActiveById((int)$this->context->cart->id_address_invoice)))
{
if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1 && Dispatcher::getInstance()->getController() != 'order-opc')
{
$back_url = $this->context->link->getPageLink('order', true, (int)$this->context->language->id, array('step' => Tools::getValue('step'), 'multi-shipping' => (int)Tools::getValue('multi-shipping')));
$params = array('multi-shipping' => (int)Tools::getValue('multi-shipping'), 'id_address' => ($bad_delivery ? (int)$this->context->cart->id_address_delivery : (int)$this->context->cart->id_address_invoice), 'back' => $back_url);
Tools::redirect($this->context->link->getPageLink('address', true, (int)$this->context->language->id, $params));
}
Tools::redirect('index.php?controller=order&step=1');
}
$carriers = $this->context->cart->simulateCarriersOutput(); $carriers = $this->context->cart->simulateCarriersOutput();
$checked = $this->context->cart->simulateCarrierSelectedOutput(); $checked = $this->context->cart->simulateCarrierSelectedOutput();
$delivery_option_list = $this->context->cart->getDeliveryOptionList(); $delivery_option_list = $this->context->cart->getDeliveryOptionList();
@@ -510,7 +511,7 @@ class ParentOrderControllerCore extends FrontController
// TOS // TOS
$cms = new CMS(Configuration::get('PS_CONDITIONS_CMS_ID'), $this->context->language->id); $cms = new CMS(Configuration::get('PS_CONDITIONS_CMS_ID'), $this->context->language->id);
$this->link_conditions = $this->context->link->getCMSLink($cms, $cms->link_rewrite); $this->link_conditions = $this->context->link->getCMSLink($cms, $cms->link_rewrite, (bool)Configuration::get('PS_SSL_ENABLED'));
if (!strpos($this->link_conditions, '?')) if (!strpos($this->link_conditions, '?'))
$this->link_conditions .= '?content_only=1'; $this->link_conditions .= '?content_only=1';
else else
+1 -1
View File
@@ -548,7 +548,7 @@ class ProductControllerCore extends FrontController
$path = Tools::getPath((int)$this->context->shop->id_category, $this->product->name); $path = Tools::getPath((int)$this->context->shop->id_category, $this->product->name);
$this->context->smarty->assign('path', $path); $this->context->smarty->assign('path', $path);
$this->context->smarty->assign('categories', Category::getHomeCategories($this->context->language->id)); $this->context->smarty->assign('categories', Category::getHomeCategories($this->context->language->id, true, (int)$this->context->shop->id));
$this->context->smarty->assign(array('HOOK_PRODUCT_FOOTER' => Hook::exec('displayFooterProduct', array('product' => $this->product, 'category' => $this->category)))); $this->context->smarty->assign(array('HOOK_PRODUCT_FOOTER' => Hook::exec('displayFooterProduct', array('product' => $this->product, 'category' => $this->category))));
} }
+1 -1
View File
@@ -279,6 +279,6 @@ class StoresControllerCore extends FrontController
if (!Configuration::get('PS_STORES_SIMPLIFIED')) if (!Configuration::get('PS_STORES_SIMPLIFIED'))
$this->addJS(_THEME_JS_DIR_.'stores.js'); $this->addJS(_THEME_JS_DIR_.'stores.js');
$default_country = new Country((int)Configuration::get('PS_COUNTRY_DEFAULT')); $default_country = new Country((int)Configuration::get('PS_COUNTRY_DEFAULT'));
$this->addJS('http://maps.google.com/maps/api/js?sensor=true&amp;region='.substr($default_country->iso_code, 0, 2)); $this->addJS('http'.((Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE')) ? 's' : '').'://maps.google.com/maps/api/js?sensor=true&amp;region='.substr($default_country->iso_code, 0, 2));
} }
} }
File renamed without changes.
Internal Server Error - Senolage Gitea: Git with a cup of tea
500 Internal Server Error

An error occurred:

An error occurred

Gitea Version: 28.1.0