update filter with all attribute groups of sale

This commit is contained in:
Marion Muszynski 2017-08-28 18:08:55 +02:00
parent 4015a120f5
commit 9f7da4b63a
3 changed files with 143 additions and 36 deletions

View File

@ -1,15 +1,23 @@
{if count($sizes) > 0}
{if count($attr) > 0}
<div class="block_filter">
<div class="content">
<h4 class="open">{l s='Recherche par' mod='filtervp'} {$name}</h4>
<h4 class="open">{l s='Recherche par' mod='filtervp'}</h4>
<div class="content_filter">
<ul id="filters">
{foreach from=$sizes item=size}
<h5>{$attr[0]['group']}</h5>
{assign var="current_name" value=$attr[0]['group']}
<ul class="filters" id="filters">
{foreach from=$attr key=key item=attribute}
{if $key!=0 && $current_name!=$attribute['group']}
</ul>
<h5>{$attribute['group']}</h5>
<ul class="filters">
{/if}
<li>
<input type="checkbox" name="size" value="{$size.id_attribute}" id="size_{$size.id_attribute}">
<label for="size_{$size.id_attribute}">{$size.name}</label>
<input type="checkbox" name="size" value="{$attribute['id_attribute']}" id="size_{$size.id_attribute}">
<label for="size_{$size.id_attribute}">{$attribute['name']}</label>
</li>
{assign var="current_name" value=$attribute['group']}
{/foreach}
</ul>
</div>

View File

@ -1,7 +1,8 @@
<?php
class Filtervp extends Module {
const FILTER_ID = 75;
const FILTER_SIZE = 272;
// const FILTER_ID = 75;
const FILTER_ID = 1;
// const FILTER_SIZE = 272;
public function __construct() {
$this->name = 'filtervp';
@ -23,36 +24,98 @@ class Filtervp extends Module {
return TRUE;
}
public function hookdisplayLeftVP($params) {
global $smarty;
$sizes = self::getAllValueAttr(Filtervp::FILTER_ID, Tools::getValue('id_category'));
public function hookPrivateSales_Edit($params) {
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);
$attr_groups = Db::getInstance()->ExecuteS('
SELECT
al.`name`,
a.`id_attribute_group`'.($params['sale'] !== NULL? ', (
SELECT IFNULL(s.`id_sale`, NULL)
FROM `'._DB_PREFIX_.'attribute_group_ps` s
WHERE a.`id_attribute_group` = s.`id_attribute_group` AND s.`id_sale` = '.$params['sale']->id.'
) AS `id_sale`': '').'
FROM ps_attribute_group a
LEFT JOIN ps_attribute_group_lang al ON al.id_attribute_group = a.id_attribute_group
WHERE al.`id_lang` = 2
');
echo '
<div class="form-group">
<label class="control-label">'.$this->l('Attribute groups:').'</label>
<div class="">
<select id="attr_groups" name="attr_groups[]" multiple="multiple" size="5" class="form-control">';
$all_opt = array();
foreach($attr_groups as $attribute) {
$all_opt[] = $attribute['id_attribute_group'];
echo '<option value="'.$attribute['id_attribute_group'].'"'.(isset($attribute['id_sale']) && $attribute['id_sale'] !== NULL?' selected="selected"':'').'>'.$attribute['name'].'</option>';
}
echo '
</select>
</div>
<div class="btn-group btn-group-sm" role="group">
<button type="button" class="select_all_for_attr_group btn btn-default">Tout</button>
<button type="button" class="clear_for_attr_group btn btn-default">Clear</button>
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#attr_groups").select2({
maximumSelectionLength: '.count($attr_groups).',
placeholder: "'.$this->l('Select one or more attribute group:').'",
allowClear: true
});
$(".select_all_for_attr_group").on("click", function () { $("#attr_groups").select2().val(["'.(implode('","',$all_opt)).'"]).trigger("change"); });
$(".clear_for_attr_group").on("click", function () { $("#attr_groups").select2().val(null).trigger("change"); });
});
</script>
<div class="clear"></div>
</div>';
}
public function hookPrivateSales_Delete($params) {
Db::getInstance()->Execute('
DELETE FROM `'._DB_PREFIX_.'attribute_group_ps`
WHERE `id_sale` = '.$params['sale']->id
);
}
public function hookPrivateSales_Create($params) {
if($attr_groups = Tools::getValue('attr_groups')) {
foreach($attr_groups as $group) {
Db::getInstance()->Execute('
INSERT INTO `'._DB_PREFIX_.'attribute_group_ps` VALUES (
'.(int) $group.', '.$params['sale']->id.'
)
');
}
}
}
if($name == 'Tailles') {
$name = 'Taille';
};
public function hookPrivateSales_Update($params) {
Db::getInstance()->Execute('
DELETE FROM `'._DB_PREFIX_.'attribute_group_ps`
WHERE `id_sale` = '.$params['sale']->id
);
$this->hookPrivateSales_Create($params);
}
public function hookdisplayLeftVP($params) {
global $smarty;
$attributes = self::getAllAttrByGroup(Tools::getValue('id_category'));
$smarty->assign(array(
'name' => $name,
'sizes' => $sizes,
'attr' => $attributes,
));
return $this->display(__FILE__, 'filter.tpl');
}
return $this->display(__FILE__, 'filter.tpl');
}
public static function getAllValueAttr($id_attr, $id_cat){
public static function getAllValueAttr($id_attr, $id_cat){
global $cookie;
$id_lang = $cookie->id_lang;
$results = Db::getInstance()->ExecuteS('
SELECT
al.`name`,
SELECT
al.`name`,
a.`id_attribute`
FROM
`'._DB_PREFIX_.'attribute` a
@ -61,23 +124,52 @@ class Filtervp extends Module {
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.'"
WHERE
a.id_attribute_group = "'.$id_attr.'"
GROUP BY
a.`id_attribute`
ORDER BY
al.`name` ASC
al.`name` ASC
');
return $results;
}
public static function getAttrName($id_attr){
public function getAllAttrByGroup($id_cat)
{
global $cookie;
$id_lang = $cookie->id_lang;
$results = Db::getInstance()->ExecuteS('
SELECT
al.`name`,
a.`id_attribute`,
agl.`name` as `group`
FROM
`'._DB_PREFIX_.'attribute` a
LEFT JOIN '._DB_PREFIX_.'attribute_lang al ON al.id_lang = '.(int)$id_lang.' AND al.id_attribute = a.id_attribute
LEFT JOIN '._DB_PREFIX_.'attribute_group_lang agl ON agl.id_attribute_group = a.id_attribute_group AND agl.id_lang = '.(int)$id_lang.'
LEFT JOIN '._DB_PREFIX_.'attribute_group_ps agp ON agp.id_attribute_group = agl.id_attribute_group
LEFT JOIN '._DB_PREFIX_.'privatesale_category pc ON pc.id_sale = agp.id_sale
LEFT JOIN '._DB_PREFIX_.'category_product cp ON cp.id_category = pc.id_category
LEFT JOIN '._DB_PREFIX_.'product p ON cp.id_product = p.id_product
INNER JOIN ps_product_attribute pa ON pa.id_product = cp.id_product
INNER JOIN ps_product_attribute_combination pac ON pac.id_attribute = a.id_attribute AND pac.id_product_attribute = pa.id_product_attribute
WHERE agp.id_sale IS NOT NULL AND pc.id_category = '.(int)$id_cat.'
GROUP BY
a.`id_attribute`
ORDER BY
agl.`name` ASC, 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`
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.'"
');

View File

@ -7350,4 +7350,11 @@ table#carrierTable tbody td {
#cart_remove_gift_message{
float:right;
background: #e26ea2;
}
.block_filter .content_filter h5{
font-size: 15px;
text-decoration: underline;
color: #514E8C;
margin:10px 0px;
}