Merge branch 'ticket-9260' into develop

This commit is contained in:
Marion Muszynski 2016-09-05 16:22:59 +02:00
commit 797a27cea3

View File

@ -2,38 +2,41 @@
class ProductController extends ProductControllerCore {
public function preProcess() {
parent::preProcess();
global $cookie;
if(Module::isInstalled('privatesales')) {
$id_category = $this->product->id_category_default;
$sale = Sale::getSaleFromCategory($id_category);
/* Finding out the right Category for thumb*/
$found_category = false;
if (isset($_SERVER['HTTP_REFERER']) AND preg_match('!^(.*)\/([0-9]+)\-(.*[^\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs) AND !strstr($_SERVER['HTTP_REFERER'], '.html'))
{
if (isset($regs[2]) AND is_numeric($regs[2]))
{
if (Product::idIsOnCategoryId((int)($this->product->id), array('0' => array('id_category' => (int)($regs[2])))))
$found_category = (int)$regs[2];
}
elseif (isset($regs[5]) AND is_numeric($regs[5]))
{
if (Product::idIsOnCategoryId((int)($this->product->id), array('0' => array('id_category' => (int)($regs[5])))))
$found_category = (int)$regs[5];
}
}
$parent_category = ($found_category)?Category::getIdParent((int)$found_category):Category::getIdParent((int)$id_category);
if ($found_category && file_exists(_PS_ROOT_DIR_.'/img/c/'.(int)$found_category.'_thumb_vp.jpg') && $found_category != $sale->id_category) {
// cat thumb
$id_category_thumb = $found_category;
} elseif ($parent_category && file_exists(_PS_ROOT_DIR_.'/img/c/'.(int)$parent_category.'_thumb_vp.jpg') && $parent_category != $sale->id_category) {
// parent cat thumb
$id_category_thumb = $parent_category;
} elseif (file_exists(_PS_ROOT_DIR_.'/img/c/'.(int)$id_category.'_thumb_vp.jpg') && $id_category != $sale->id_category) {
// default cat thumb
$id_category_thumb = $id_category;
/* Finding out the right Category for thumb - 4 levels of category */
$available_cat = $this->product->getCategories();
$first_step_cats = Category::getChildren($sale->id_category,$cookie->id_lang);
foreach ($first_step_cats as $key => $first_step_cat) {
if(in_array($first_step_cat['id_category'], $available_cat)){
$first_step_cat = $first_step_cat['id_category'];
break;
}
}
$second_step_cats = (isset($first_step_cat))?Category::getChildren((int)$first_step_cat,$cookie->id_lang):array();
foreach ($second_step_cats as $key => $second_step_cat) {
if(in_array($second_step_cat['id_category'], $available_cat)){
$second_step_cat = $second_step_cat['id_category'];
break;
}
}
$third_step_cats = (isset($second_step_cat))?Category::getChildren((int)$second_step_cat,$cookie->id_lang):array();
foreach ($third_step_cats as $key => $third_step_cat) {
if(in_array($third_step_cat['id_category'], $available_cat)){
$third_step_cat = $third_step_cat['id_category'];
break;
}
}
if (isset($third_step_cat) && file_exists(_PS_ROOT_DIR_.'/img/c/'.(int)$third_step_cat.'_thumb_vp.jpg')) {
$id_category_thumb = (int)$third_step_cat;
} elseif (isset($second_step_cat) && file_exists(_PS_ROOT_DIR_.'/img/c/'.(int)$second_step_cat.'_thumb_vp.jpg')) {
$id_category_thumb = (int)$second_step_cat;
} elseif (isset($first_step_cat) && file_exists(_PS_ROOT_DIR_.'/img/c/'.(int)$first_step_cat.'_thumb_vp.jpg')) {
$id_category_thumb = (int)$first_step_cat;
} else {
// sale cat thumb
$id_category_thumb = $sale->id_category;