Jump to content

Hide specific attribute to specific group of customers - How ?


Thomas G.

Recommended Posts

Hi everyone,

 

I'd like to get some help about a little problem : I've got two group of customers, and i've got specific attributes in some products.

 

The attribute that causes me problem is "Warranty" ("without warranty" and "with 6 months warranty"), i want this attribute to be used by a specific group of customers ("Private Persons"), but i don't want the other group ("Professionnals") to see and use this specific attribute.

 

So i'd like to know how to hide a specific attribute for a specific group of customers, please.

 

I'm not a PHP developper, but i'll be able to make some changes in the php or tpl files. I guess i'll have to use a specific code in my product.tpl but i can't find the right code to put in.

 

Thanks for your help !

 

PS : I put a screenshot in attachment so you can see the attribute in his context, that's the part i'd like to hide from "professionnals" groupe of customer, but allow to the "private" groupe of customer (By the way, sorry, it's in French...) : post-1199694-0-09786000-1459431228_thumb.jpg

Link to comment
Share on other sites

Thanks for your answer, my theme is "Magica" (in case it can help), and here's the product.tpl code at the <!-- attributes --> place :

<!-- attributes -->

<div id="attributes">

<div class="clearfix"></div>
{foreach from=$groups key=id_attribute_group item=group}
{if $group.attributes|@count}

<fieldset class="attribute_fieldset">
<label class="attribute_label" {if $group.group_type != 'color' && $group.group_type != 'radio'}for="group_{$id_attribute_group|intval}"{/if}>{$group.name|escape:'html':'UTF-8'} : </label>
{assign var="groupName" value="group_$id_attribute_group"}

<div class="attribute_list">
{if ($group.group_type == 'select')}

<select name="{$groupName}" id="group_{$id_attribute_group|intval}" class="form-control attribute_select no-print">
{foreach from=$group.attributes key=id_attribute item=group_attribute}
<option value="{$id_attribute|intval}"{if (isset($smarty.get.$groupName) && $smarty.get.$groupName|intval == $id_attribute) || $group.default == $id_attribute} selected="selected"{/if} title="{$group_attribute|escape:'html':'UTF-8'}">{$group_attribute|escape:'html':'UTF-8'}</option>
{/foreach}
</select>

{elseif ($group.group_type == 'color')}

<ul id="color_to_pick_list" class="clearfix">

{assign var="default_colorpicker" value=""}
{foreach from=$group.attributes key=id_attribute item=group_attribute}

<li{if $group.default == $id_attribute} class="selected"{/if}>
<a href="{$link->getProductLink($product)|escape:'html':'UTF-8'}" id="color_{$id_attribute|intval}" name="{$colors.$id_attribute.name|escape:'html':'UTF-8'}" class="color_pick{if ($group.default == $id_attribute)} selected{/if}" style="background: {$colors.$id_attribute.value|escape:'html':'UTF-8'};" title="{$colors.$id_attribute.name|escape:'html':'UTF-8'}">
{if file_exists($col_img_dir|cat:$id_attribute|cat:'.jpg')}
<img src="{$img_col_dir}{$id_attribute|intval}.jpg" alt="{$colors.$id_attribute.name|escape:'html':'UTF-8'}" width="20" height="20" />
{/if}
</a>
</li>

{if ($group.default == $id_attribute)}
{$default_colorpicker = $id_attribute}
{/if}
{/foreach}

</ul>

<input type="hidden" class="color_pick_hidden" name="{$groupName|escape:'html':'UTF-8'}" value="{$default_colorpicker|intval}" />
{elseif ($group.group_type == 'radio')}

<ul>

{foreach from=$group.attributes key=id_attribute item=group_attribute}
<li>
<input type="radio" class="attribute_radio" name="{$groupName|escape:'html':'UTF-8'}" value="{$id_attribute}" {if ($group.default == $id_attribute)} checked="checked"{/if} />
<span>{$group_attribute|escape:'html':'UTF-8'}</span>
</li>
{/foreach}

</ul>
{/if}

</div> 



<!-- end attribute_list -->

</fieldset>
{/if}
{/foreach}

</div> 

<!-- end attributes -->
{/if}

</div> 
<!-- end product_attributes -->

Can it help ? Please, what code can i add or change to get the result I need ?

 

For information, my prestashop version is 1.6.1.4

 

Thank you so much !

Edited by Thomas G. (see edit history)
Link to comment
Share on other sites

I'll try to be clearer - maybe it's gonna be easier for you to help me find a solution. Infact, my code should probably go like :

{if $checkcustomer->id_default_group==1 || $checkcustomer->id_default_group==2 || $checkcustomer->id_default_group==3}
<!-- SHOW ATTRIBUTE ID=7 -->
{else}
<!-- HIDE ATTRIBUTE ID=7 -->
{/if}

I think that's what the code could look like... So if my customer is in group 1, 2 or 3 he can see and choose the attribute 7 ; but if my customer is connected and recognized in another group (5, 6, 7....), attribute 7 will be hidden for him.

 

I'm still stuck here, if someone can give me a hand, it'll be very nice.

 

Thanks !

Link to comment
Share on other sites

  • 2 years later...

You can try this quick solution (tested for 10 minutes (1.7) seems to work). Override classes/Product method getAttributesGroups. Replace return line with following code:

        $attributesResults = Db::getInstance()->executeS($sql);
        $context = Context::getContext();    
        $userGroupId = $context->customer->id_default_group;  
        if (isset($userGroupId) && $userGroupId == 111) { // replace with a group id where restrictions will take place. can be raplaced with in_array function
            
            foreach ($attributesResults as $key => $attributeGroup) {
                if ($attributeGroup[group_name] == 'ABC' && $attributeGroup[attribute_name] != '1kg') { // change condition to what you like
                    unset($attributesResults[$key]);
                }
            }
        }    
        return $attributesResults;

Please remember to change conditions in the code.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...