Quite often store owners or developers need to create new features which they do not want to be visible on the product page. To solve this problem I have created a new Visibility module which makes it possible to enable or disable visibility for each feature.
The module itself:
The new visibility field:
The module installs a new Visibility column which also indicates whether the visibility is on/off for a specific feature.
I used the following products for testing:
Without the module
With the module
Without the module
With the module
To add font verification we need to edit product.tpl.
To add to product.tpl, before “{foreach from=$features item=feature}” :
1 2 3 |
{* Check features visibility *} {assign var="features" value=Module::getInstanceByName('belvg_featurevisibility')->getFrontFeatures($product->id, ', ')} {* /Check features visibility *} |
To apply this module to the populal module PM_MultipleFeatures
you need to modify the method pm_multiplefeatures as follows:
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 |
public function getFrontFeatures($id_product, $separator = ', ') { global $id_lang; $belvg_featurevisibility_where = ''; $belvg_featurevisibility_join = ''; if ($belvg_featurevisibility = Module::getInstanceByName('belvg_featurevisibility')) { if ($belvg_featurevisibility->active) { $belvg_featurevisibility_join = 'LEFT JOIN `' . _DB_PREFIX_ . 'belvg_featurevisibility` bfv ON (f.`id_feature` = bfv.`id_feature`)'; $belvg_featurevisibility_where = ' AND bfv.`visibility` = 1'; } } if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) $id_lang = (int)Context::getContext()->cookie->id_lang; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT fp.id_feature, vl.value, fl.name FROM `'._DB_PREFIX_.'feature_product` fp LEFT JOIN `'._DB_PREFIX_.'feature_value` v ON (fp.`id_feature_value` = v.`id_feature_value`) LEFT JOIN `'._DB_PREFIX_.'feature_value_lang` vl ON (v.`id_feature_value` = vl.`id_feature_value` AND vl.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'feature` f ON (f.`id_feature` = v.`id_feature`) '.(version_compare(_PS_VERSION_, '1.5.0.0', '>=') && Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP ? Shop::addSqlAssociation('feature', 'f') : '').' '.$belvg_featurevisibility_join.' LEFT JOIN `'._DB_PREFIX_.'feature_lang` fl ON (fl.`id_feature` = f.`id_feature` AND fl.`id_lang` = '.(int)$id_lang.') WHERE fp.`id_product` = '.(int)$id_product.$belvg_featurevisibility_where); $return = array(); if ($result && is_array($result) && sizeof($result)) { foreach ($result as $row) { $return[$row['id_feature']]['values'][] = $row['value']; $return[$row['id_feature']]['name'] = $row['name']; } foreach ($return as $key=>$row) $return[$key]['value'] = implode($separator, $row['values']); } return $return; } |
rebelbitz,
Thanks a lot for this improvement!
Great module!
Just a little improvement…
The features do not show in the product page taking in account the “position” parameter you set up in the Product Features admin area.
So, all it is needed to fix this issue is adding a simple line of code to your “belvg_featurevisibility.php” file.
The SQL query located in the “getFrontFeatures” public function needs this ORDER clause:
ORDER BY f.
position
ASC’So, the new query must look like this:
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(‘
SELECT fp.id_feature, vl.value, fl.name
FROM
'._DB_PREFIX_.'feature_product
fpLEFT JOIN
'._DB_PREFIX_.'feature_value
v ON (fp.id_feature_value
= v.id_feature_value
)LEFT JOIN
'._DB_PREFIX_.'feature_value_lang
vl ON (v.id_feature_value
= vl.id_feature_value
AND vl.id_lang
= ‘.(int)$id_lang.’)LEFT JOIN
'._DB_PREFIX_.'feature
f ON (f.id_feature
= v.id_feature
)LEFT JOIN
'._DB_PREFIX_.'belvg_featurevisibility
bfv ON (f.id_feature
= bfv.id_feature
)‘.(version_compare(_PS_VERSION_, ‘1.5.0.0’, ‘>=’) && Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP ? Shop::addSqlAssociation(‘feature’, ‘f’) : ”).’
LEFT JOIN
'._DB_PREFIX_.'feature_lang
fl ON (fl.id_feature
= f.id_feature
AND fl.id_lang
= ‘.(int)$id_lang.’)WHERE fp.
id_product
= ‘.(int)$id_product.’ AND bfv.visibility
= 1ORDER BY f.
position
ASC’);
Thanks for your great contribution!
Laurence,
Thanks for your feedback :) Most probably the problem is that in the code which you provided use the object $product, from which you get ID, but on the catalog page this is not an object but an array, so the proper way would be to refer to {$product.id} but not to {$product->id}
Hi
thanks for the the module it’s working great. I was wondering if there was a way to use it in the product list as well as the product page.
I’ve tried the same code as for the product but it doesn’t work for me :
{* Check features visibility *}
{assign var=”features” value=Module::getInstanceByName(‘belvg_featurevisibility’)->getFrontFeatures($product->id, ‘, ‘)}
{* /Check features visibility *}
{foreach from=$product.features item=feature}
{$feature.name}: {$feature.value}
{/foreach}
Thanks
Laurence