Merge branch 'fix-bestSellerCache' into develop
This commit is contained in:
commit
7174dc2f25
@ -105,11 +105,15 @@ class BlockBestSellers extends Module
|
||||
if(!$step || ($step && $step != 3 && $step != 4)) {
|
||||
$id_lang = $cookie->id_lang;
|
||||
|
||||
Tools::enableCache();
|
||||
$smarty->cache_lifetime = 3600;
|
||||
$cache_id = "blockbestsellers".$id_lang;
|
||||
$id_lang = $cookie->id_lang;
|
||||
$filename = _PS_ROOT_DIR_.'/modules/blockbestsellers/blockbestsellers_'.$id_lang.'.txt';
|
||||
$expire = time() -3600;
|
||||
|
||||
if(!$this->isCached('blockbestsellers_'.(int) $cookie->id_lang.'.tpl', $cache_id)) {
|
||||
if(file_exists($filename) && filemtime($filename) > $expire) {
|
||||
$data = file_get_contents($filename);
|
||||
$best_sellers = json_decode($data, TRUE);
|
||||
} else {
|
||||
$file = fopen($filename, 'w+');
|
||||
$currency = new Currency((int)($params['cookie']->id_currency));
|
||||
$bestsellers = ProductSale::getBestSalesVp((int)($params['cookie']->id_lang), 0, 5, NULL, NULL, 10);
|
||||
if (!$bestsellers AND !Configuration::get('PS_BLOCK_BESTSELLERS_DISPLAY'))
|
||||
@ -123,15 +127,15 @@ class BlockBestSellers extends Module
|
||||
$best_sellers[] = $bestseller;
|
||||
}
|
||||
|
||||
$smarty->assign(array(
|
||||
'best_sellers' => $best_sellers,
|
||||
'mediumSize' => Image::getSize('medium')));
|
||||
fwrite($file, json_encode($best_sellers));
|
||||
fclose($file);
|
||||
}
|
||||
|
||||
$display = $this->display(__FILE__, 'blockbestsellers_'.(int) $cookie->id_lang.'.tpl', $cache_id);
|
||||
Tools::restoreCacheSettings();
|
||||
$smarty->cache_lifetime = -1;
|
||||
return $display;
|
||||
$smarty->assign(array(
|
||||
'best_sellers' => $best_sellers,
|
||||
'mediumSize' => Image::getSize('medium'))
|
||||
);
|
||||
return $this->display(__FILE__, 'blockbestsellers_'.(int) $cookie->id_lang.'.tpl');
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,12 +149,14 @@ class BlockBestSellers extends Module
|
||||
global $cookie;
|
||||
|
||||
$id_lang = $cookie->id_lang;
|
||||
$filename = _PS_ROOT_DIR_.'/modules/blockbestsellers/blockbestsellers_cart_'.$id_lang.'.txt';
|
||||
$expire = time() -3600;
|
||||
|
||||
Tools::enableCache();
|
||||
$smarty->cache_lifetime = 3600;
|
||||
$cache_id = "blockbestsellers_cart".$id_lang;
|
||||
|
||||
if(!$this->isCached('blockbestsellers_cart_'.(int) $id_lang.'.tpl', $cache_id)) {
|
||||
if(file_exists($filename) && filemtime($filename) > $expire) {
|
||||
$data = file_get_contents($filename);
|
||||
$best_sellers = json_decode($data, TRUE);
|
||||
} else {
|
||||
$file = fopen($filename, 'w+');
|
||||
$currency = new Currency((int)($params['cookie']->id_currency));
|
||||
$bestsellers = ProductSale::getBestSalesVp((int)($params['cookie']->id_lang), 0, 3, NULL, NULL, 10);
|
||||
|
||||
@ -165,17 +171,16 @@ class BlockBestSellers extends Module
|
||||
$best_sellers[] = $bestseller;
|
||||
}
|
||||
|
||||
fwrite($file, json_encode($best_sellers));
|
||||
fclose($file);
|
||||
}
|
||||
$smarty->assign(
|
||||
array(
|
||||
'best_sellers' => $best_sellers,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$display = $this->display(__FILE__, 'blockbestsellers_cart_'.(int) $id_lang.'.tpl' , $cache_id);
|
||||
Tools::restoreCacheSettings();
|
||||
$smarty->cache_lifetime = -1;
|
||||
return $display;
|
||||
return $this->display(__FILE__, 'blockbestsellers_cart_'.(int) $id_lang.'.tpl');
|
||||
}
|
||||
|
||||
public function hookbestSaleHome($params)
|
||||
@ -188,12 +193,14 @@ class BlockBestSellers extends Module
|
||||
global $cookie;
|
||||
|
||||
$id_lang = $cookie->id_lang;
|
||||
$filename = _PS_ROOT_DIR_.'/modules/blockbestsellers/blockbestsellers_home_'.$id_lang.'.txt';
|
||||
$expire = time() -3600;
|
||||
|
||||
Tools::enableCache();
|
||||
$smarty->cache_lifetime = 3600;
|
||||
$cache_id = "blockbestsellers_home".$id_lang;
|
||||
|
||||
if(!$this->isCached('blockbestsellers_home_'.(int) $cookie->id_lang.'.tpl', $cache_id)) {
|
||||
if(file_exists($filename) && filemtime($filename) > $expire) {
|
||||
$data = file_get_contents($filename);
|
||||
$best_sellers = json_decode($data, TRUE);
|
||||
} else {
|
||||
$file = fopen($filename, 'w+');
|
||||
$currency = new Currency((int)($params['cookie']->id_currency));
|
||||
$bestsellers = ProductSale::getBestSalesVp((int)($params['cookie']->id_lang), 0, 5, NULL, NULL, 10);
|
||||
if (!$bestsellers AND !Configuration::get('PS_BLOCK_BESTSELLERS_DISPLAY'))
|
||||
@ -207,17 +214,16 @@ class BlockBestSellers extends Module
|
||||
$best_sellers[] = $bestseller;
|
||||
}
|
||||
|
||||
fwrite($file, json_encode($best_sellers));
|
||||
fclose($file);
|
||||
}
|
||||
$smarty->assign(
|
||||
array(
|
||||
'best_sellers' => $best_sellers,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$display = $this->display(__FILE__, 'blockbestsellers_home_'.(int) $cookie->id_lang.'.tpl' , $cache_id);
|
||||
Tools::restoreCacheSettings();
|
||||
$smarty->cache_lifetime = -1;
|
||||
return $display;
|
||||
return $this->display(__FILE__, 'blockbestsellers_home_'.(int) $cookie->id_lang.'.tpl');
|
||||
}
|
||||
|
||||
public function hookProductFooter($params)
|
||||
@ -231,11 +237,14 @@ class BlockBestSellers extends Module
|
||||
|
||||
$id_lang = $cookie->id_lang;
|
||||
|
||||
Tools::enableCache();
|
||||
$smarty->cache_lifetime = 3600;
|
||||
$cache_id = "blockbestsellers_productfooter".$id_lang;
|
||||
$filename = _PS_ROOT_DIR_.'/modules/blockbestsellers/blockbestsellers_productfooter_'.$id_lang.'.txt';
|
||||
$expire = time() -3600;
|
||||
|
||||
if(!$this->isCached('blockbestsellers_productfooter_'.(int) $cookie->id_lang.'.tpl', $cache_id)) {
|
||||
if(file_exists($filename) && filemtime($filename) > $expire) {
|
||||
$data = file_get_contents($filename);
|
||||
$best_sellers = json_decode($data, TRUE);
|
||||
} else {
|
||||
$file = fopen($filename, 'w+');
|
||||
$currency = new Currency((int)($params['cookie']->id_currency));
|
||||
$bestsellers = ProductSale::getBestSalesVp((int)($params['cookie']->id_lang), 0, 6, NULL, NULL, 10);
|
||||
if (!$bestsellers AND !Configuration::get('PS_BLOCK_BESTSELLERS_DISPLAY'))
|
||||
@ -249,20 +258,19 @@ class BlockBestSellers extends Module
|
||||
$best_sellers[] = $bestseller;
|
||||
}
|
||||
|
||||
fwrite($file, json_encode($best_sellers));
|
||||
fclose($file);
|
||||
}
|
||||
|
||||
$smarty->assign(
|
||||
array(
|
||||
'best_sellers' => $best_sellers,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$display = $this->display(__FILE__, 'blockbestsellers_productfooter_'.(int) $cookie->id_lang.'.tpl' , $cache_id);
|
||||
Tools::restoreCacheSettings();
|
||||
$smarty->cache_lifetime = -1;
|
||||
return $display;
|
||||
return $this->display(__FILE__, 'blockbestsellers_productfooter_'.(int) $cookie->id_lang.'.tpl');
|
||||
}
|
||||
|
||||
|
||||
public function hookLeftColumn($params)
|
||||
{
|
||||
if(_PS_MOBILE_) {
|
||||
|
Loading…
Reference in New Issue
Block a user