Post by acugraph » Sun Feb 26, 2012 5:14 am

Hi,
Has anyone come across a way to make certain categories only visible/available to users who have registered on a site.
I want to create "Registered Only" content areas.

Vincent

New member

Posts

Joined
Tue Dec 20, 2011 12:28 am


Post by straightlight » Wed Feb 29, 2012 7:54 pm

Here's an XML file you can upload.

As extra steps, you must do the following:

1 - In PHPMyAdmin, go to your main category table and execute the following query in the SQL tab:

Code: Select all

ALTER TABLE `oc_category` ADD `registered_customer_categories` INT(1) NOT NULL DEFAULT '0' AFTER `column`;
Note: Rename oc_ to your real prefix name (or remove if you don't have one).

2 - In your catalog/view/theme/<your_theme>/template/module/category.tpl file,

find:

Code: Select all

<?php if ($category['category_id'] == $category_id) { ?>
          <a href="<?php echo $category['href']; ?>" class="active"><?php echo $category['name']; ?></a>
          <?php } else { ?>
          <a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
          <?php } ?>
replace with:

Code: Select all

<?php if ($category['category_id'] == $category_id) { ?>			
			<?php if ((int)$category['registered_customer_categories'] == 1 && !$this->customer->isLogged()) { ?>
				<a href="#" onclick="alert('<?php echo $text_reg_cust_restrict; ?>'); return false;"> - <?php echo $category['name']; ?></a>
			<?php } else { ?>
				<a href="<?php echo $category['href']; ?>" class="active"><?php echo $category['name']; ?></a>
			<?php } ?>
          <?php } else { ?>
			<?php if ((int)$category['registered_customer_categories'] == 1 && !$this->customer->isLogged()) { ?>
				<a href="#" onclick="alert('<?php echo $text_reg_cust_restrict; ?>'); return false;"> - <?php echo $category['name']; ?></a>
			<?php } else { ?>
				<a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
			<?php } ?>
          <?php } ?>
Then, find:

Code: Select all

<?php if ($child['category_id'] == $child_id) { ?>
              <a href="<?php echo $child['href']; ?>" class="active"> - <?php echo $child['name']; ?></a>
              <?php } else { ?>
              <a href="<?php echo $child['href']; ?>"> - <?php echo $child['name']; ?></a>
              <?php } ?>
replace with:

Code: Select all

<?php if ($child['category_id'] == $child_id) { ?>
				<?php if (((int)$category['registered_customer_categories'] == 1 || (int)$child['registered_customer_categories'] == 1) && !$this->customer->isLogged()) { ?>
					<a href="#" onclick="alert('<?php echo $text_reg_cust_restrict; ?>'); return false;"> - <?php echo $child['name']; ?></a>
					
				<?php } else { ?>
					<a href="<?php echo $child['href']; ?>" class="active"> - <?php echo $child['name']; ?></a>
				<?php } ?>
              <?php } else { ?>
				<?php if (((int)$category['registered_customer_categories'] == 1 || (int)$child['registered_customer_categories'] == 1) && !$this->customer->isLogged()) { ?>
					<a href="#" onclick="alert('<?php echo $text_reg_cust_restrict; ?>'); return false;"> - <?php echo $child['name']; ?></a>
					
				<?php } else { ?>
					<a href="<?php echo $child['href']; ?>"> - <?php echo $child['name']; ?></a>
				<?php } ?>
              <?php } ?>
3 - In your catalog/view/theme/<your_theme>/template/common/header.tpl file,

find:

Code: Select all

<li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
replace with:

Code: Select all

<?php if ((int)$category['registered_customer_categories'] == 1 && !$this->customer->isLogged()) { ?>
		<li><a href="#" onClick="alert('<?php echo $text_reg_cust_restrict; ?>'); return false;"><?php echo $category['name']; ?></a>
	
	<?php } else { ?>
		<li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
	<?php } ?>
Then, find:

Code: Select all

<li><a href="<?php echo $category['children'][$i]['href']; ?>"><?php echo $category['children'][$i]['name']; ?></a></li>
replace with:

Code: Select all

<?php if (((int)$category['registered_customer_categories'] == 1 || (int)$category['children'][$i]['registered_customer_categories'] == 1) && !$this->customer->isLogged()) { ?>
				<li><a href="#" onClick="alert('<?php echo $text_reg_cust_restrict; ?>'); return false;"><?php echo $category['children'][$i]['name']; ?></a></li>
			<?php } else { ?>
				<li><a href="<?php echo $category['children'][$i]['href']; ?>"><?php echo $category['children'][$i]['name']; ?></a></li>
			<?php } ?>
4 - Go to your admin - > catalog - > categories - > insert or edit - > data. You will see at the bottom:

Code: Select all

Only to registered customers:
Only registered customers will have access to this category.
Set to yes from that desired category.

5 - Go to your store-front end and test the category in two ways:

- Click on the category straight. You should be redirected to the common/home page when restricted.
- Click on a unrestricted category and then, from the tree on your left, click on the restricted category. You should see a popup message box stating the category is restricted to registered customers only.

Note: This contribution requires that you have the category module installed from your admin - > extensions - > modules - > category and also enabled over the category and products.

Also take note that the sub-categories can also be inclusive in those restrictions. If the root category is restricted, the sub-categories will also be restricted.

Attachments

v1.5.1.3.1


Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by acugraph » Fri Mar 02, 2012 5:24 am

HI Straightlight,

Thank you for taking the time to reply to my post.

I have tried searching for the code you mentioned in step 3. But I cant find the reference in the header.tpl

Can you please send me the instructions again.

Thanks,

Vincent

New member

Posts

Joined
Tue Dec 20, 2011 12:28 am


Post by straightlight » Fri Mar 02, 2012 5:27 am

These instructions are for OpenCart v1.5.1.3.1 release. If you don't see these codes from step 3, it either means you're using a lower version or you may use the latest but with a custom template. On either case, you'd need to post your header.tpl file as an attachment so that I can take a look at it.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by acugraph » Fri Mar 02, 2012 5:41 am

Hi,

I am running OC 1.5.1.3. I will pm you the file.

Thanks

New member

Posts

Joined
Tue Dec 20, 2011 12:28 am


Post by ukdazza » Thu Jun 14, 2012 11:53 pm

Can you share a screenshot or link to a store where this has been actioned? I would like to see how it works. I am thinking of having a 'members only' website whereby the site is only accessible to those who are authorised members. I am considering having a single homepage that explains who we are and allows the visitor to contact us to apply for access and then if we make them an account they will have access.

Alternatively, wouldn't it be easier to just have a site but make all products viewable only to certain customer groups. Thus if they are not an 'approved' customer they can't see products/prices. That would work right?

Newbie

Posts

Joined
Mon Mar 19, 2012 10:01 pm

Post by vishnuinforce » Sat Jun 23, 2012 12:16 am

Can you kindly specify the path to upload the XML(registered_users_categories.xml) file.

Newbie

Posts

Joined
Fri Jun 22, 2012 12:06 pm

Post by fashion13 » Fri Aug 23, 2013 8:58 pm

I did everything exactly the same, but get the following error please help me.

undefined index registered customer categories

category.tpl line 8 - 14 - 25 - 32

opencart version 1.5.6

Newbie

Posts

Joined
Fri Aug 23, 2013 8:51 pm

Post by straightlight » Sat Sep 14, 2013 12:03 am

This little contribution has been coded on a previous version of OC. I will see what I can do for recent releases.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by chizzy500 » Sun Jul 19, 2015 2:59 am

straightlight wrote:This little contribution has been coded on a previous version of OC. I will see what I can do for recent releases.
i was reading up how to create an "only registered user account" i went through your write up

while i was using oc 1.5.1.3.1 the mod worked fine now i updated to the latest oc one and keep getting errors. please help i would be very grateful. sent you my header.pl. via pm thanks in advance

Newbie

Posts

Joined
Sun Jul 19, 2015 2:21 am
Who is online

Users browsing this forum: No registered users and 24 guests