Some Prestashop users are challenged with a problem to display features with custom options in the module Blосklаyered. The main problem is that the module ignores custom features, and since each feature has its own unique ID, then when you try to output them into navigation your customers may see incorrect grouping as a result. We once received a task from a customer to display such features in navigation. He was using some custom import, which, due to certain reasons, was recording imported features into custom fields.
So we decided to transfer such values into the default list, ignoring the repeated values within the language. We had to create a script, which we wanted to schedule for implementing these tasks. But we have decided to slightly modify the logic of the module Blосklаyered and expand its functionality with the function “rebuildFeаtures( ) “, which would be called in the method BlосkLаyered: :getFilterBlосk( ):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
... case 'id_feature': //BelVG custom function $this->rebuildFeatures($id_lang, $alias, $filter['id_value'], $parent->nleft, $parent->nright, $id_parent); ... /** * Belvg Custom function * * @param $id_lang * @param $alias * @param $id_value * @param $nleft * @param $nright * @param $id_parent */ public function rebuildFeatures($id_lang, $alias, $id_value, $nleft, $nright, $id_parent) { $sql = 'SELECT fl.name feature_name, fp.id_feature, fv.id_feature_value, fvl.value, COUNT(DISTINCT p.id_product) nbr, lifl.url_name name_url_name, lifl.meta_title name_meta_title, lifvl.url_name value_url_name, lifvl.meta_title value_meta_title FROM '._DB_PREFIX_.'feature_product fp INNER JOIN '._DB_PREFIX_.'product p ON (p.id_product = fp.id_product) LEFT JOIN '._DB_PREFIX_.'feature_lang fl ON (fl.id_feature = fp.id_feature AND fl.id_lang = '.$id_lang.') INNER JOIN '._DB_PREFIX_.'feature_value fv ON (fv.id_feature_value = fp.id_feature_value AND fv.custom = 1) LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.id_feature_value = fp.id_feature_value AND fvl.id_lang = '.$id_lang.') LEFT JOIN '._DB_PREFIX_.'layered_indexable_feature_lang_value lifl ON (lifl.id_feature = fp.id_feature AND lifl.id_lang = '.$id_lang.') LEFT JOIN '._DB_PREFIX_.'layered_indexable_feature_value_lang_value lifvl ON (lifvl.id_feature_value = fp.id_feature_value AND lifvl.id_lang = '.$id_lang.') WHERE 1 AND fp.id_feature = '.(int)$id_value.' AND p.id_product IN ( SELECT id_product FROM '._DB_PREFIX_.'category_product cp INNER JOIN '._DB_PREFIX_.'category c ON (c.id_category = cp.id_category AND '.(Configuration::get('PS_LAYERED_FULL_TREE') ? 'c.nleft >= '.(int)$nleft.' AND c.nright <= '.(int)$nright : 'c.id_category = '.(int)$id_parent).' AND c.active = 1)) GROUP BY fv.id_feature_value'; $custom_features = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); //contains the list of custom feutures for a specific page //Cycle for modifying custom features into default ones foreach ($custom_features as $custom_feature) { $id_feature_value = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT fvl.`id_feature_value` FROM `' . _DB_PREFIX_ . 'feature_value` fv LEFT JOIN `' . _DB_PREFIX_ . 'feature_value_lang` fvl ON (fv.`id_feature_value` = fvl.`id_feature_value`) WHERE fv.`custom` = 0 AND fvl.`id_lang` = '.$id_lang.' AND value = \'' . $custom_feature['value'] . '\' AND fv.`id_feature` = '.(int)$custom_feature['id_feature'].' '); //perhaps, the same option is already in the database if (!$id_feature_value) { //if this feature is missing, then the custom feature is modified into the default one //update feature_value $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->execute(' UPDATE `' . _DB_PREFIX_ . 'feature_value` fv SET fv.`custom` = 0 WHERE fv.`id_feature_value` = '.(int)$custom_feature['id_feature_value'] ); if ($result) { $id_feature_value = (int)$custom_feature['id_feature_value']; } } if ($id_feature_value) { //updating data about the feature in the database //update product_feature_value $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->execute(' UPDATE `' . _DB_PREFIX_ . 'feature_product` fp SET fp.`id_feature_value` = '.(int)$id_feature_value.' WHERE fp.`id_feature_value` = '.(int)$custom_feature['id_feature_value'] ); } } return 1; } |
The above function modifies custom values into default ones on the fly, during the page load.
PrestaShop Support & Maintenance
Take your online store to the next level with BelVG PrestaShop Support & Maintenance
Visit the pageIf a feature has all values as custom, then it can not be added into navigation. To fix this, we have to modify the function BlockLayered::getContent()
from:
1 2 3 4 5 6 7 |
$features = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT fl.id_feature, fl.name, COUNT(DISTINCT(fv.id_feature_value)) n FROM '._DB_PREFIX_.'feature_lang fl LEFT JOIN '._DB_PREFIX_.'feature_value fv ON (fv.id_feature = fl.id_feature) WHERE (fv.custom IS NULL OR fv.custom = 0) AND fl.id_lang = '.(int)$cookie->id_lang.' GROUP BY fl.id_feature' ); |
into this one (deleted the custom feature verification):
1 2 3 4 5 6 7 |
$features = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT fl.id_feature, fl.name, COUNT(DISTINCT(fv.id_feature_value)) n FROM '._DB_PREFIX_.'feature_lang fl LEFT JOIN '._DB_PREFIX_.'feature_value fv ON (fv.id_feature = fl.id_feature) WHERE 1 AND fl.id_lang = '.(int)$cookie->id_lang.' GROUP BY fl.id_feature' ); |
PrestaShop Development
Take your online store to the next level with BelVG PrestaShop Development
Visit the page
Hi Emmanuel,
could you please contact our support team at [email protected]? There are some issues we should figure out to help you.
This is an issue we have been getting for a while now. We followed the steps you mentioned but for the function “rebuildFeаtures( ), can you help us with this please? We don’t actually know where this should be placed, is it in the “blocklayered.php” file?
Thank you,
Emmanuel
Alvaro, thank you for the reasonable comment! Subscribe to our blog to stay tuned :)
Hi,
Great solution, many thanks. And it WORKS for 1.6.1.15.
Does not work with 1.6 :(
Can someone point out what to change so it works with 1.6?
Would be really really helpful!
I have tried it with PS 1.6 and it doesn’t work. The custom values are added successfully into the predefined ones but they are not shown in navigation in front office.
I have checked the layered navigation module and the feature in enabled to be shown in front office.
Any suggestions or tutorials for PS 1.6??
Doesn’t work with PS 1.6. Any tips?
Thank you so much, you’re great
@Maksim, our support team will contact you directly.
Hello guys, was searching net for this kind solution, found here , but something doing wrong. im using blocklayered_mod module from warehouse theme, maybe problem in this , maybe not, looking for someone who have time to make it work (not free), who can help please email me [email protected], thanks
super solution!!!
Please answer – how checkbox replace to slider for numeric value
Filmo,
Actually the process itself is described in this article.
Hi,
This is exactly what I am looking for but I don’t know how to do.
Pleas can you write a process how to do?
Thank you so much.
John,
Please contact our support team at [email protected] and they will help you.
This is a great work around and is exactly what we need. The problem is, I need a noob step by step buide on how to implement it. If you could make it simple that would help greatly!