[-] MO: Fix blockviewd for non identified customers #PSCFV-6042
This commit is contained in:
@@ -49,9 +49,9 @@ class BlockViewed extends Module
|
|||||||
public function install()
|
public function install()
|
||||||
{
|
{
|
||||||
if (!parent::install()
|
if (!parent::install()
|
||||||
OR !$this->registerHook('leftColumn')
|
|| !$this->registerHook('leftColumn')
|
||||||
OR !$this->registerHook('header')
|
|| !$this->registerHook('header')
|
||||||
OR !Configuration::updateValue('PRODUCTS_VIEWED_NBR', 2))
|
|| !Configuration::updateValue('PRODUCTS_VIEWED_NBR', 2))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -95,7 +95,7 @@ class BlockViewed extends Module
|
|||||||
$id_product = (int)Tools::getValue('id_product');
|
$id_product = (int)Tools::getValue('id_product');
|
||||||
$productsViewed = (isset($params['cookie']->viewed) && !empty($params['cookie']->viewed)) ? array_slice(explode(',', $params['cookie']->viewed), 0, Configuration::get('PRODUCTS_VIEWED_NBR')) : array();
|
$productsViewed = (isset($params['cookie']->viewed) && !empty($params['cookie']->viewed)) ? array_slice(explode(',', $params['cookie']->viewed), 0, Configuration::get('PRODUCTS_VIEWED_NBR')) : array();
|
||||||
|
|
||||||
if (sizeof($productsViewed))
|
if (count($productsViewed))
|
||||||
{
|
{
|
||||||
$defaultCover = Language::getIsoById($params['cookie']->id_lang).'-default';
|
$defaultCover = Language::getIsoById($params['cookie']->id_lang).'-default';
|
||||||
|
|
||||||
@@ -116,11 +116,11 @@ class BlockViewed extends Module
|
|||||||
);
|
);
|
||||||
|
|
||||||
$productsImagesArray = array();
|
$productsImagesArray = array();
|
||||||
foreach ($productsImages AS $pi)
|
foreach ($productsImages as $pi)
|
||||||
$productsImagesArray[$pi['id_product']] = $pi;
|
$productsImagesArray[$pi['id_product']] = $pi;
|
||||||
|
|
||||||
$productsViewedObj = array();
|
$productsViewedObj = array();
|
||||||
foreach ($productsViewed AS $productViewed)
|
foreach ($productsViewed as $productViewed)
|
||||||
{
|
{
|
||||||
$obj = (object)'Product';
|
$obj = (object)'Product';
|
||||||
if (!isset($productsImagesArray[$productViewed]) || (!$obj->active = $productsImagesArray[$productViewed]['active']))
|
if (!isset($productsImagesArray[$productViewed]) || (!$obj->active = $productsImagesArray[$productViewed]['active']))
|
||||||
@@ -147,29 +147,20 @@ class BlockViewed extends Module
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($id_product AND !in_array($id_product, $productsViewed))
|
if ($id_product && !in_array($id_product, $productsViewed))
|
||||||
{
|
{
|
||||||
// Check if the user to the right of access to this product
|
// Check if the user to the right of access to this product
|
||||||
$result = Db::getInstance()->getRow('
|
$product = new Product((int)$id_product);
|
||||||
SELECT COUNT(cug.`id_customer`) AS total
|
if ($product->checkAccess((int)$this->context->customer->id))
|
||||||
FROM `'._DB_PREFIX_.'product` p
|
|
||||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = p.`id_product`)
|
|
||||||
LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`)
|
|
||||||
LEFT JOIN `'._DB_PREFIX_.'customer_group` cug ON (cug.`id_group` = cg.`id_group`)
|
|
||||||
WHERE p.`id_product` = '.(int)($id_product).'
|
|
||||||
'.($this->context->customer->id ? 'AND cug.`id_customer` = '.(int)$this->context->customer->id :
|
|
||||||
'AND cg.`id_group` = 1')
|
|
||||||
);
|
|
||||||
if ($result['total'])
|
|
||||||
array_unshift($productsViewed, $id_product);
|
array_unshift($productsViewed, $id_product);
|
||||||
}
|
}
|
||||||
$viewed = '';
|
$viewed = '';
|
||||||
foreach ($productsViewed AS $id_product_viewed)
|
foreach ($productsViewed as $id_product_viewed)
|
||||||
$viewed .= (int)($id_product_viewed).',';
|
$viewed .= (int)($id_product_viewed).',';
|
||||||
$params['cookie']->viewed = rtrim($viewed, ',');
|
$params['cookie']->viewed = rtrim($viewed, ',');
|
||||||
|
|
||||||
if (!sizeof($productsViewedObj))
|
if (!count($productsViewedObj))
|
||||||
return ;
|
return;
|
||||||
|
|
||||||
$this->smarty->assign(array(
|
$this->smarty->assign(array(
|
||||||
'productsViewedObj' => $productsViewedObj,
|
'productsViewedObj' => $productsViewedObj,
|
||||||
@@ -179,7 +170,7 @@ class BlockViewed extends Module
|
|||||||
}
|
}
|
||||||
elseif ($id_product)
|
elseif ($id_product)
|
||||||
$params['cookie']->viewed = (int)($id_product);
|
$params['cookie']->viewed = (int)($id_product);
|
||||||
return ;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hookLeftColumn($params)
|
public function hookLeftColumn($params)
|
||||||
|
|||||||
Reference in New Issue
Block a user