'all',
_THEME_CSS_DIR_.'scenes.css' => 'all'));
Tools::addJS(_PS_JS_DIR_.'jquery/jquery-ui-1.8.10.custom.min.js');
Tools::addCSS(_PS_CSS_DIR_.'jquery-ui-1.8.10.custom.css', 'all');
if (Configuration::get('PS_COMPARATOR_MAX_ITEM') > 0)
Tools::addJS(_THEME_JS_DIR_.'products-comparison.js');
}
public function displayHeader()
{
parent::displayHeader();
$this->productSort();
}
public function canonicalRedirection()
{
// Automatically redirect to the canonical URL if the current in is the right one
// $_SERVER['HTTP_HOST'] must be replaced by the real canonical domain
if (Validate::isLoadedObject($this->category))
{
$currentURL = self::$link->getCategoryLink($this->category);
$currentURL = preg_replace('/[?&].*$/', '', $currentURL);
if (!preg_match('/^'.Tools::pRegexp($currentURL, '/').'([&?].*)?$/', Tools::getProtocol().$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']))
{
header('HTTP/1.0 301 Moved');
if (defined('_PS_MODE_DEV_') AND _PS_MODE_DEV_ )
die('[Debug] This page has moved
Please use the following URL instead: '.$currentURL.'');
Tools::redirectLink($currentURL);
}
}
}
public function preProcess()
{
if ($id_category = (int)Tools::getValue('id_category'))
{
if ($id_category === 1)
{
Tools::redirect('/');
}
$this->category = new Category($id_category, self::$cookie->id_lang);
}
if (!Validate::isLoadedObject($this->category))
{
header('HTTP/1.1 404 Not Found');
header('Status: 404 Not Found');
}
else
$this->canonicalRedirection();
parent::preProcess();
}
private function implodeFeatureParam($aFeaturesParams, $iFeatureToChange, $iParamToRemove, $iParamToAdd)
{
$aFeatureStrings = array();
foreach ($aFeaturesParams as $iFeatureKey => $aFeature)
{
if ($iFeatureToChange == $iFeatureKey)
{
if ($iParamToRemove)
{
$iPos = array_search($iParamToRemove, $aFeature);
if ($iPos !== false)
{
unset($aFeature[$iPos]);
}
}
elseif ($iParamToAdd)
{
array_push($aFeature, $iParamToAdd);
}
}
if (count($aFeature))
{
$aFeatureStrings[] = $iFeatureKey . 'v' . implode(':', $aFeature);
}
}
if (!isset($aFeaturesParams[$iFeatureToChange]) && $iParamToAdd)
{
$aFeatureStrings[] = $iFeatureToChange . 'v' . $iParamToAdd;
}
return implode(';', $aFeatureStrings);
}
public function process()
{
global $currency;
parent::process();
if (!($id_category = (int)Tools::getValue('id_category')) OR !Validate::isUnsignedId($id_category))
$this->errors[] = Tools::displayError('Missing category ID');
else
{
if (!Validate::isLoadedObject($this->category))
$this->errors[] = Tools::displayError('Category does not exist');
elseif (!$this->category->checkAccess((int)(self::$cookie->id_customer)))
$this->errors[] = Tools::displayError('You do not have access to this category.');
elseif (!$this->category->active)
self::$smarty->assign('category', $this->category);
else
{
$rewrited_url = self::$link->getCategoryLink((int)$this->category->id, $this->category->link_rewrite);
$this->category->description = nl2br2($this->category->description);
self::$smarty->assign('category', $this->category);
// manufacturers management
$aManufacturers = $this->category->getManufacturers();
$sBrandId = '';
$aBrandValues = array();
if ($mBrandValue = Tools::getValue('brand'))
{
$aBrandValues = explode(':', $mBrandValue);
}
$aActiveManufacturers = array();
if (count($aManufacturers) > 1)
{
foreach ($aManufacturers as &$aManufacturer)
{
if (in_array($aManufacturer['id_manufacturer'], $aBrandValues))
{
$aManufacturer['active'] = true;
$aActiveManufacturers[] = $aManufacturer['id_manufacturer'];
}
else
{
$aManufacturer['active'] = false;
}
}
foreach ($aManufacturers as &$aManufacturer)
{
if ($aManufacturer['active'])
{
// create link without this manufacturer in params
$aBrandParams = $aActiveManufacturers;
$iCurrentBrandPos = array_search($aManufacturer['id_manufacturer'], $aBrandParams);
if($iCurrentBrandPos !== false)
{
unset($aBrandParams[$iCurrentBrandPos]);
}
$sBrandParam = implode(':', $aBrandParams);
$aManufacturer['url'] = self::$link->getCategoryUrlWith('brand', $sBrandParam);
}
else
{
// create link with this manufacturer in params
$aBrandParams = $aActiveManufacturers;
array_push($aBrandParams, $aManufacturer['id_manufacturer']);
$sBrandParam = implode(':', $aBrandParams);
$aManufacturer['url'] = self::$link->getCategoryUrlWith('brand', $sBrandParam);
}
}
}
$sActiveManufacturers = implode(':', $aActiveManufacturers);
// features management
$aAvailableFeatures = array();
if (!$aAllFeatures = $this->category->getFeatures((int)(self::$cookie->id_lang)))
{
$aAllFeatures = array();
}
foreach ($aAllFeatures as $aFeature)
{
$iFeatureId = $aFeature['id_feature'];
$iFeatureValueId = $aFeature['id_feature_value'];
if (!isset($aAvailableFeatures[$iFeatureId]))
{
$aAvailableFeatures[$iFeatureId] = array(
'name' => $aFeature['feature_name'],
'values' => array()
);
}
$aAvailableFeatures[$iFeatureId]['values'][$iFeatureValueId] = array(
'value' => $aFeature['feature_value_name'],
'active' => false
);
}
$aFeatureValues = array();
$aFeaturesValues = array();
if ($mFeatureValue = Tools::getValue('feature'))
{
$aFeatureValues = explode(';', $mFeatureValue);
foreach ($aFeatureValues as $aFeatureValue)
{
$aFeatureValueExploded = explode('v', $aFeatureValue);
if (!isset($aFeatureValueExploded[1]))
{
break;
}
// $aFeatureValueExploded[0] - feature ID
// $aFeatureValueExploded[1] - feature values
$iFeatureId = intval($aFeatureValueExploded[0]);
$aFeaturesValues[$iFeatureId] = explode(':', $aFeatureValueExploded[1]);
foreach ($aFeaturesValues[$iFeatureId] as &$aFeaturesValuesSingle)
{
$aFeaturesValuesSingle = intval($aFeaturesValuesSingle);
}
}
}
foreach ($aAvailableFeatures as $iFeatureId => &$aFeature)
{
if (isset($aFeaturesValues[$iFeatureId]))
{
$aSelectedValues = $aFeaturesValues[$iFeatureId];
}
else
{
$aSelectedValues = array();
}
$iFirstFeatureValueKey = false;
foreach ($aFeature['values'] as $iFeatureValueKey => &$aFeatureValue)
{
if (!$iFirstFeatureValueKey)
{
$iFirstFeatureValueKey = $iFeatureValueKey;
}
$sFeatureParam = '';
// set active and get feature link
if (count($aSelectedValues)
&& in_array($iFeatureValueKey, $aSelectedValues)
) {
$aFeatureValue['active'] = true;
$sFeatureParam = $this->implodeFeatureParam(
$aFeaturesValues, $iFeatureId, $iFeatureValueKey, false
);
}
else
{
$sFeatureParam = $this->implodeFeatureParam(
$aFeaturesValues, $iFeatureId, false, $iFeatureValueKey
);
}
$aFeatureValue['url'] = self::$link->getCategoryUrlWith('feature', $sFeatureParam);
}
if (count($aFeature['values']) < 2)
{
//
$aCurrent = $aFeature['values'][$iFirstFeatureValueKey];
if (!$aCurrent['active'])
{
unset($aAvailableFeatures[$iFeatureId]);
continue;
}
//
}
}
$aPriceValues = array(
false, false
);
if ($mPriceValue = Tools::getValue('price'))
{
$aPriceValues = explode('_', $mPriceValue);
}
if ($this->category->id != 1)
{
$nbProducts = $this->category->getProducts(NULL, NULL, NULL, $this->orderBy, $this->orderWay, true, true, false, 1, true, $this->online_only);
$this->pagination((int)$nbProducts);
self::$smarty->assign('nb_products', (int)$nbProducts);
$cat_products = $this->category->getProducts((int)(self::$cookie->id_lang), (int)($this->p), (int)($this->n), $this->orderBy, $this->orderWay, false, true, false, 1, true, $this->online_only);
}
self::$smarty->assign(array(
'products' => (isset($cat_products) AND $cat_products) ? $cat_products : NULL,
'id_category' => (int)($this->category->id),
'id_category_parent' => (int)($this->category->id_parent),
'return_category_name' => Tools::safeOutput($this->category->name),
'path' => Tools::getPath((int)($this->category->id)),
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
'categorySize' => Image::getSize('category'),
'mediumSize' => Image::getSize('medium'),
'thumbSceneSize' => Image::getSize('thumb_scene'),
'imgSize' => Image::getSize('product_list'),
'availableManufacturers' => $aManufacturers,
'availableManufacturersCount' => count($aManufacturers),
'sActiveManufacturers' => $sActiveManufacturers,
'aAvailableFeatures' => $aAvailableFeatures,
'rangePrices' => $this->category->getRangePrices(),
'rangePricesFrom' => (int)$aPriceValues[0],
'rangePricesTo' => (int)$aPriceValues[1],
'rangePricesUrl' => self::$link->getCategoryUrlWith('price', ''),
'displayFilter' => (($mBrandValue || $mPriceValue || $mFeatureValue) ? true : false),
'currencySign' => $currency->sign,
));
if (isset(self::$cookie->id_customer))
self::$smarty->assign('compareProducts', CompareProduct::getCustomerCompareProducts((int)self::$cookie->id_customer));
elseif (isset(self::$cookie->id_guest))
self::$smarty->assign('compareProducts', CompareProduct::getGuestCompareProducts((int)self::$cookie->id_guest));
}
}
self::$smarty->assign(array(
'allow_oosp' => (int)(Configuration::get('PS_ORDER_OUT_OF_STOCK')),
'comparator_max_item' => (int)(Configuration::get('PS_COMPARATOR_MAX_ITEM')),
'suppliers' => Supplier::getSuppliers()
));
}
public function displayContent()
{
parent::displayContent();
self::$smarty->display(_PS_THEME_DIR_.'category.tpl');
}
}