Jump to content

(SOLVED) is it possible to only show selected CMS to a group of members?


Recommended Posts

Solved:

here are the instructions:

1) add in yourtheme/cms.tpl

 

 

{if $cms->id==8}    <- the last number depends on the cms you want to "hide"
{if $checkcustomer->id_default_group==4}              <- the last number depends on the customer group
<p>whatever you want </p>
{else}
{l s='no access'}
  {/if}
{else}
 
2)in  /controllers/front/CmsController.php
add this 
 
 $this->context->smarty->assign(array('customer' => new Customer($this->context->customer->id)));
 
just before:
$this->setTemplate(_PS_THEME_DIR_.'cms.tpl');
}
}

 

 

those are the last lines ,

 

 

right now im using 1.5 ps, 

what i want is to selected group of costumers, say i make a group called, all access, and those members can see the CMS. 

Edited by zupermanzito (see edit history)
Link to comment
Share on other sites

hello

 

yes you can.

 

by default you can define "group access" for each category

JETuOZ4.png

 

 

you can create new customer group and allow access to category only for this group.

attach members to new group and then - only they will see this category

Link to comment
Share on other sites

:| my bad, im sorry, i just thought that you're talking about categories.

 

 

option that you want doesn't exist by default, unfortunately you can achieve it only with:

 

1) .tpl file modifications (easiest)

2) controllers modificaiton (very hard)

Link to comment
Share on other sites

you can do it .tpl file with if condition:

 

{if $cms->id==2}

  {if $customer->id_group_default==5}

    HERE CONTENTS OF CMS.TPL

  {else}

    {l s='no access'}

  {/if}

{else}

HERE CONTENTS

{/if}

 

code above will block access to customers that aren't in group 5, and only for CMS page with id==2.

before this you will need to pass $customer object to smarty array in CmsController.php file (controllers/CmsController.php)

  • Like 1
Link to comment
Share on other sites

while i understand the code. ill make a wild guess and ill say i got to cms.tpl on my theme folder right?

 

yes :) /themes/YOUR_THEME/cms.tpl file

 

and by:

 

 

however this wanst clear.

i mean that i have to add code: $this->context->smarty->assign(array('customer' => new Customer($this->context->customer->id)));

to the public function initContent() function in controllers/front/CMSController.php file. ADd code i mentioned right before this: $this->setTemplate(_PS_THEME_DIR_.'cms.tpl');

 

 

init function should looks like:

	public function initContent()
	{
		parent::initContent();

		$parent_cat = new CMSCategory(1, $this->context->language->id);
		$this->context->smarty->assign('id_current_lang', $this->context->language->id);
		$this->context->smarty->assign('home_title', $parent_cat->name);
		$this->context->smarty->assign('cgv_id', Configuration::get('PS_CONDITIONS_CMS_ID'));
		if (isset($this->cms->id_cms_category) && $this->cms->id_cms_category)
			$path = Tools::getFullPath($this->cms->id_cms_category, $this->cms->meta_title, 'CMS');
		else if (isset($this->cms_category->meta_title))
			$path = Tools::getFullPath(1, $this->cms_category->meta_title, 'CMS');
		if ($this->assignCase == 1)
		{
			$this->context->smarty->assign(array(
				'cms' => $this->cms,
                
				'content_only' => (int)(Tools::getValue('content_only')),
				'path' => $path
			));
		}
		else if ($this->assignCase == 2)
		{
			$this->context->smarty->assign(array(
				'category' => $this->cms_category, //for backward compatibility
				'cms_category' => $this->cms_category,
				'sub_category' => $this->cms_category->getSubCategories($this->context->language->id),
				'cms_pages' => CMS::getCMSPages($this->context->language->id, (int)($this->cms_category->id) ),
				'path' => ($this->cms_category->id !== 1) ? Tools::getPath($this->cms_category->id, $this->cms_category->name, false, 'CMS') : '',
			));
		}

        $this->context->smarty->assign(array('customer' => new Customer($this->context->customer->id)));
		$this->setTemplate(_PS_THEME_DIR_.'cms.tpl');
	}
  • Like 1
Link to comment
Share on other sites

Well i have tried, however dosent matter the group the customer is. it simply deny all acces to the selected CMS, im guessing  the problem is in the controller

public function initContent()
	{
		parent::initContent();

		$parent_cat = new CMSCategory(1, $this->context->language->id);
		$this->context->smarty->assign('id_current_lang', $this->context->language->id);
		$this->context->smarty->assign('home_title', $parent_cat->name);
		$this->context->smarty->assign('cgv_id', Configuration::get('PS_CONDITIONS_CMS_ID'));
		if (isset($this->cms->id_cms_category) && $this->cms->id_cms_category)
			$path = Tools::getFullPath($this->cms->id_cms_category, $this->cms->meta_title, 'CMS');
		else if (isset($this->cms_category->meta_title))
			$path = Tools::getFullPath(1, $this->cms_category->meta_title, 'CMS');
		if ($this->assignCase == 1)
		{
			$this->context->smarty->assign(array(
				'cms' => $this->cms,
				'content_only' => (int)(Tools::getValue('content_only')),
				'path' => $path
			));
		}
		else if ($this->assignCase == 2)
		{
			$this->context->smarty->assign(array(
				'category' => $this->cms_category, //for backward compatibility
				'cms_category' => $this->cms_category,
				'sub_category' => $this->cms_category->getSubCategories($this->context->language->id),
				'cms_pages' => CMS::getCMSPages($this->context->language->id, (int)($this->cms_category->id) ),
				'path' => ($this->cms_category->id !== 1) ? Tools::getPath($this->cms_category->id, $this->cms_category->name, false, 'CMS') : '',
			));
		}
		
	$this->context->smarty->assign(array('customer' => new Customer($this->context->customer->id)));
		$this->setTemplate(_PS_THEME_DIR_.'cms.tpl');
	}
}
Link to comment
Share on other sites


{if ($content_only == 0)}

{include file="$tpl_dir./breadcrumb.tpl"}

{/if}

{if $cms->id==2}

{if $customer->id_group_default==4}

{if isset($cms) && !isset($cms_category)}

{if !$cms->active}

<br />

<div id="admin-action-cms">

<p>{l s='This CMS page is not visible to your customers.'}

<input type="hidden" id="admin-action-cms-id" value="{$cms->id}" />

<input type="submit" value="{l s='Publish'}" class="exclusive" onclick="submitPublishCMS('{$base_dir}{$smarty.get.ad|escape:'htmlall':'UTF-8'}', 0, '{$smarty.get.adtoken|escape:'htmlall':'UTF-8'}')"/>

<input type="submit" value="{l s='Back'}" class="exclusive" onclick="submitPublishCMS('{$base_dir}{$smarty.get.ad|escape:'htmlall':'UTF-8'}', 1, '{$smarty.get.adtoken|escape:'htmlall':'UTF-8'}')"/>

</p>

<div class="clear" ></div>

<p id="admin-action-result"></p>

</p>

</div>

{/if}

<div class="rte{if $content_only} content_only{/if}">

{$cms->content}

</div>

 

 

{elseif isset($cms_category)}

<div class="block-cms">

 

<h1><a href="{if $cms_category->id eq 1}{$base_dir}{else}{$link->getCMSCategoryLink($cms_category->id, $cms_category->link_rewrite)}{/if}">{$cms_category->name|escape:'htmlall':'UTF-8'}</a></h1>

{if isset($sub_category) && !empty($sub_category)}

<p class="title_block">{l s='List of sub categories in %s:' sprintf=$cms_category->name}</p>

<ul class="bullet">

{foreach from=$sub_category item=subcategory}

<li>

<a href="{$link->getCMSCategoryLink($subcategory.id_cms_category, $subcategory.link_rewrite)|escape:'htmlall':'UTF-8'}">{$subcategory.name|escape:'htmlall':'UTF-8'}</a>

</li>

{/foreach}

</ul>

{/if}

{if isset($cms_pages) && !empty($cms_pages)}

<p class="title_block">{l s='List of pages in %s:' sprintf=$cms_category->name}</p>

<ul class="bullet">

{foreach from=$cms_pages item=cmspages}

<li>

<a href="{$link->getCMSLink($cmspages.id_cms, $cmspages.link_rewrite)|escape:'htmlall':'UTF-8'}">{$cmspages.meta_title|escape:'htmlall':'UTF-8'}</a>

</li>

{/foreach}

</ul>

{/if}

</div>

{else}

<div class="error">

{l s='This page does not exist.'}

</div>

{/if}

{else}

{l s='no access'}

{/if}

{else}

<p> test </p>

{/if}

 

 

Link to comment
Share on other sites

sorry i missed your reply

in cms controller file (controllers/front/CmsController.php) in initContent() function add this:

$this->context->smarty->assign('checkcustomer',$this->context->customer);

then, in cms.tpl file you can use this:

 

{if $checkcustomer->id_default_group==3}

CONTENT HERE

{/if}

Link to comment
Share on other sites

  • 1 month later...

Hi

 

Can i get a help with a part of the coding? i am not a coder, so i am sorry if my question is dumb

 

{if $cms->id==8}    <- the last number depends on the cms you want to "hide"
{if $checkcustomer->id_default_group==4}              <- the last number depends on the customer group
<p>whatever you want </p>
{else}
{l s='no access'}
  {/if}
{else}
 
First, the part in red is the name of the link that will appear in the frontoffice? like "About us" ?
 
Second, is this possible:
 
{if $cms->id==8}    <- the last number depends on the cms you want to "hide"
{if $checkcustomer->id_default_group==4 OR if $checkcustomer->id_default_group==5 OR if $checkcustomer->id_default_group==6}              <- the last number depends on the customer group
<p>whatever you want </p>
{else}
{l s='no access'}
  {/if}
{else}

 

This could work?

 

I have this exact same need, i need to hide one CMS page from the public, but i have 6 groups of clients that i need to be able to see it

Link to comment
Share on other sites

Hello

 

I am sorry to bother again but i really need this.

 

First i've added the info on the edited first post, testing the text from CMS.tpl in the beggining and the end of the file, and i got some errors.

 

Then looking at the code from zupermanzito from 28 October, i've made changes accordantly.

 

And then no one can access the page, being from the group or not.

 

I am betting that i am messing something in the cml.tpl code, either the position of the instructions or other subject.

Can someone please clarify?

 

Thanks in advance.

Link to comment
Share on other sites

It seems that the best i am getting is this, placed at the end of the CML.tpl file:

 

{else}
    {l s='This page does not exist.'}
{/if}
{if $cms->id==12}
  {if $checkcustomer->id_group_default==5}
<p> test </p>
{else}
{l s='no access'}
  {/if}
{/if}
<br />
 
Page enters in all users but only has this error:
 
Notice: Undefined property: Customer::$id_group_default in/cache/smarty/compile/d6/74/ba/d674ba370f6a7fe32b33981b076a5be2abdb7881.file.cms.tpl.phpon line 117
no access 
 
I am confused, since my cms.tpl only has 82 lines... this is problably on other file
Link to comment
Share on other sites

  • 1 year later...

I know it's a bit of an old topic to kick back into life, but what changes do I need to make to this solution to make it work on 1.6.1.1?

Currently I'm working on a new website for our trade customers and I need to add certain files for download (trade price list, image, other information that we don't want to release to consumers) which can only be visible to customers, and I'll be the one creating the accounts.

 

Right now, if I implement the solution as posted by Vekia, the [spam-filter] himself, I get the following error: Fatal error: Uncaught --> Smarty Compiler: Syntax error in template "C:\xampp\htdocs\prestashop\themes\theme1133\cms.tpl" on line 70 "{else}" unclosed {else} tag <-- thrown in C:\xampp\htdocs\prestashop\tools\smarty\sysplugins\smarty_internal_templatecompilerbase.php on line 70

 

When I check that line it is a commented out or blank line. If I remove the {else} at the end of the posted solution, it throws a variation of the error, claiming there's an unclosed {if} tag.

So add another {/if} and the page loads again as normal, but with errors displayed on the page (cms category page):

 

Notice: Undefined index: cms in C:\xampp\htdocs\prestashop\tools\smarty\sysplugins\smarty_internal_templatebase.php(157) : eval()'d codeon line 124

Notice: Trying to get property of non-object in C:\xampp\htdocs\prestashop\tools\smarty\sysplugins\smarty_internal_templatebase.php(157) : eval()'d code on line 124

Notice: Trying to get property of non-object in C:\xampp\htdocs\prestashop\tools\smarty\sysplugins\smarty_internal_templatebase.php(157) : eval()'d code on line 124
]

 

When I click the actual page (CMS ID 10), I can actually proceed to the page, even though I'm a visitor, i.e. not logged in.

Can someone help me out?

Link to comment
Share on other sites

×
×
  • Create New...