bebeboutik/modules/filtervp/filtervp.php
2018-03-19 10:15:54 +01:00

96 lines
2.7 KiB
PHP
Executable File

<?php
class Filtervp extends Module
{
const FILTER_ID = 75;
const FILTER_SIZE = 272;
public function __construct()
{
$this->name = 'filtervp';
$this->tab = 'front_office_features';
$this->version = '1.0';
parent::__construct();
$this->displayName = $this->l('Filter by size');
$this->description = $this->l('Enable to filter by size in VP.');
}
public function install()
{
if (!parent::install()
|| !$this->registerHook('displayLeftVP')) {
return false;
}
return true;
}
public function hookdisplayLeftVP($params)
{
global $smarty;
$sizes = self::getAllValueAttr(Filtervp::FILTER_ID, Tools::getValue('id_category'));
if (empty($sizes)) {
$sizes = self::getAllValueAttr(self::FILTER_SIZE, Tools::getValue('id_category'));
$name = self::getAttrName(self::FILTER_SIZE);
} else {
$name = self::getAttrName(self::FILTER_ID);
}
if ($name == 'Tailles') {
$name = 'Taille';
};
$smarty->assign(array(
'name' => $name,
'sizes' => $sizes,
));
return $this->display(__FILE__, 'filter.tpl');
}
public static function getAllValueAttr($id_attr, $id_cat)
{
global $cookie;
$id_lang = $cookie->id_lang;
$results = Db::getInstance()->ExecuteS('
SELECT
al.`name`,
a.`id_attribute`
FROM
`'._DB_PREFIX_.'attribute` a
INNER JOIN '._DB_PREFIX_.'attribute_lang al ON al.id_lang = "'.$id_lang.'" AND al.id_attribute = a.id_attribute
INNER JOIN '._DB_PREFIX_.'category_product cp ON cp.id_category = "'.$id_cat.'"
LEFT JOIN '._DB_PREFIX_.'product p ON cp.id_product = p.id_product
INNER JOIN '._DB_PREFIX_.'product_attribute pa ON pa.id_product = cp.id_product
INNER JOIN '._DB_PREFIX_.'product_attribute_combination pac ON pac.id_attribute = a.id_attribute AND pac.id_product_attribute = pa.id_product_attribute
WHERE
a.id_attribute_group = "'.$id_attr.'"
GROUP BY
a.`id_attribute`
ORDER BY
al.`name` ASC
');
return $results;
}
public static function getAttrName($id_attr)
{
global $cookie;
$id_lang = $cookie->id_lang;
return Db::getInstance()->getValue('
SELECT
`public_name`
FROM `'._DB_PREFIX_.'attribute_group_lang`
WHERE `id_attribute_group` = "'.(int)$id_attr.'"
AND `id_lang` = "'.(int)$id_lang.'"
');
}
}