bebeboutik/override/controllers/ProductController.php

86 lines
3.1 KiB
PHP
Raw Normal View History

2016-01-04 12:48:08 +01:00
<?php
class ProductController extends ProductControllerCore {
public function preProcess() {
parent::preProcess();
global $cookie;
2016-01-04 12:48:08 +01:00
if(Module::isInstalled('privatesales')) {
$id_category = $this->product->id_category_default;
$sale = Sale::getSaleFromCategory($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;
2016-08-31 12:41:07 +02:00
} else {
2016-09-05 11:57:43 +02:00
// sale cat thumb
2016-08-31 12:41:07 +02:00
$id_category_thumb = $sale->id_category;
}
2016-01-04 12:48:08 +01:00
self::$smarty->assign(array(
'sale' => $sale,
'HOOK_PRIVATESALES_PRODUCT' => Module::hookExec('privatesales_product', array('sale' => $sale)),
'is_sale_home' => ($sale? $sale->id_category == $id_category: FALSE),
2016-08-31 12:41:07 +02:00
'is_thumb_vp' => (file_exists(_PS_ROOT_DIR_.'/img/c/'.$id_category_thumb.'_thumb_vp.jpg')),
'id_category_thumb' => $id_category_thumb,
2016-01-04 12:48:08 +01:00
));
2016-08-30 13:47:42 +02:00
// assign date estimation from sale delay
if (Module::isInstalled('privatesales_delay')) {
if (!class_exists('SaleDelay')) {
require_once _PS_ROOT_DIR_.'/modules/privatesales_delay/saledelay.php';
}
$date = new DateTime();
$delivery_date = SaleDelay::getDeliveryDate(array($sale->delivery_delay), null, $date, true);
}
2016-01-04 12:48:08 +01:00
}
$bestSaleCart = Module::hookExec('bestSaleCart');
self::$smarty->assign(array(
'bestSaleCart' => $bestSaleCart,
'product' => $this->product,
'coverImage' => Product::getCover($this->product->id),
'delivery_date' => (!empty($delivery_date)?$delivery_date:null),
2016-01-04 12:48:08 +01:00
));
}
public function setMedia() {
parent::setMedia();
global $css_files;
$css_files = array_slice($css_files, 0, 1);
2016-06-01 12:43:12 +02:00
if(!_PS_MOBILE_) {
Tools::addJS(array(
_THEME_JS_DIR_.'jquery.mousewheel.js',
_THEME_JS_DIR_.'jquery.jscrollpane.min.js'
));
}
2016-01-04 12:48:08 +01:00
}
}