Forums / All Other Contributions/Addons / Password Protected Categories (PPC) - Support Thread

Password Protected Categories (PPC) - Support Thread

Views: 7,613

Results 1 to 20 of 32
16 Sep 2009, 11:15 PM
#1
stevish avatar

stevish

New Zenner

Join Date:
Sep 2009
Posts:
12
Plugin Contributions:
0

Password Protected Categories (PPC) - Support Thread

This is my first editing experience with ZenCart, and I would really appreciate it if a few of you gurus out there would try applying this and give it a once-over to see if it's all done right. I don't really have time to do much support for this, I just did it because I needed it myself, and I wanted to share it with the community. So if anyone else out there gets the gumption to take this over, I'd be happy to let you.

Anyways, below is the official description (from the readme file)

The install files are attached.

##########################################

Password Protected Categories!

Current Version 1.0

Work so far done by Stevish

##########################################

This mod creates a new field for categories in the admin called "Password". When this field is left blank, nothing is changed from a basic install of ZC. When a password is entered, that category becomes locked, and neither the category nor any of its contained products (just in case someone gets a direct link to a product) can be viewed without the password.

Due to the use of the $_Session variable, this is based on a per-visit access. This also means that anyone who has the password, whether or not they have a user, can gain access to the locked category. If a visitor enters the correct password, and then logs in or registers, they will not have to re-enter the category password until their session expires.

This addon was designed with photographers (like my wife) in mind. It is perfectly suited for taking private pictures, putting them in a categore (say "Mike & Trish Wedding"), then password protecting them. You can then give Mike and Trish the password, and they can order prints right from your site, as well as handing out the password to all their family and friends so they can buy prints directly from you as well. All the while, no strangers browsing your site can even see what Mike and Trish look like without the password.

LIMITATIONS:
This is fairly simply done as I'm brand new to ZC. I tried to make sure I kept the code consistent with the rest, and as a result, multiple languages can be supported (though I only know english...). So because of my lack of knowledge and wanting to keep it simple, I ended up with the following limitations:

  1. The password is stored in plain text. This should not be too big a deal, because if someone is able to hack your database, and all they gain is access to "private" pictures (which they still have to pay for if they want them), there's really no harm done.
  2. Failed password attempts are not logged. Someone could sit at the site all day trying password after password until they get it right. And even if they try a million times, nobody will even know they were trying. Again, the amount of work this would take vs the "reward" is not very tempting even for the most desperate hackers.
  3. I wanted to add a little lock symbol next to the locked categories, but I never got around to it. I just don't see it being worth the work for me.

If anyone has the time/know-how to fix these limitations, or add more functionality, feel free to contact me (stevish [at] gmail [dot] com) with what is required and I will get this thing updated and give you credit. I also might just hand off the whole project to you if you are willing to take it on. I just don't think I'll have the time to provide support for this.

22 Sep 2009, 1:03 AM
#2
kachana avatar

kachana

New Zenner

Join Date:
Oct 2008
Posts:
24
Plugin Contributions:
0

Re: Password Protected Categories (PPC) - Support Thread

Thank you so much for this contribution. Installed and works flawless with hideCategories mod (just in case someone stumbles upon the hidden category or product).

22 Sep 2009, 1:10 AM
#3
stevish avatar

stevish

New Zenner

Join Date:
Sep 2009
Posts:
12
Plugin Contributions:
0

Re: Password Protected Categories (PPC) - Support Thread

kachana:

Thank you so much for this contribution. Installed and works flawless with hideCategories mod (just in case someone stumbles upon the hidden category or product).

Good! I'm glad to hear there's no conflicts with that mod as they'll probably be used together a lot.

23 Sep 2009, 2:35 PM
#4
noncents avatar

noncents

New Zenner

Join Date:
Sep 2009
Posts:
2
Plugin Contributions:
0

Re: Password Protected Categories (PPC) - Support Thread

Hi there, this sounds very promising for a site I'm setting up. how does this perform in connection with the search function? Does the 'hide categories' deal with keeping them out of that?

23 Sep 2009, 2:38 PM
#5
noncents avatar

noncents

New Zenner

Join Date:
Sep 2009
Posts:
2
Plugin Contributions:
0

Re: Password Protected Categories (PPC) - Support Thread

Actually i've just read that it can be hidden from the search with the other mod. In which case I think I better get cracking! Thanks for posting this btw, it will come in very handy for building a trade section to my clients site.

24 Sep 2009, 2:39 PM
#6
stevish avatar

stevish

New Zenner

Join Date:
Sep 2009
Posts:
12
Plugin Contributions:
0

Re: Password Protected Categories (PPC) - Support Thread

Noncents:

Hi there, this sounds very promising for a site I'm setting up. how does this perform in connection with the search function? Does the 'hide categories' deal with keeping them out of that?

Thanks for the comment, I need to edit this to make it so it will lock people out from searches as well... though I'm not sure how I will do that. I guess the current fix is to use the "Hide Categories" mod along with this one.

9 Oct 2009, 2:06 AM
#7
robbinsgj avatar

robbinsgj

New Zenner

Join Date:
Jul 2009
Posts:
48
Plugin Contributions:
0

Re: Password Protected Categories (PPC) - Support Thread

I'm trying to install your mod, but can not find some of the directories you say need to be modified.

/includes/languages/english/CUSTOM/index.php
/includes/languages/english/CUSTOM/product_info.php
/includes/templates/CUSTOM/templates/tpl_index_product_list.php
/includes/templates/CUSTOM/templates/tpl_product_info_display.php

It appears I do not have a CUSTOM folder in my install. Is the mod version specific or am I missing something?

Any help would be greatly appreciated!!

9 Oct 2009, 2:22 AM
#8
robbinsgj avatar

robbinsgj

New Zenner

Join Date:
Jul 2009
Posts:
48
Plugin Contributions:
0

Re: Password Protected Categories (PPC) - Support Thread

Ok I'm stupid....

I cannot find some of the lines to change

/includes/languages/english/CUSTOM/index.php
-->define('TEXT_PRODUCT_MODEL', 'Model: ');

/includes/languages/english/CUSTOM/product_info.php
-->define('TEXT_ALL_MANUFACTURERS', 'All Manufacturers');

I cannot find the following files
/includes/templates/CUSTOM/templates/tpl_index_product_list.php
/includes/templates/CUSTOM/templates/tpl_product_info_display.php

Am I missing something?

Any help would be greatly appreciated!!

9 Oct 2009, 2:41 AM
#9
robbinsgj avatar

robbinsgj

New Zenner

Join Date:
Jul 2009
Posts:
48
Plugin Contributions:
0

Re: Password Protected Categories (PPC) - Support Thread

Ok, I found the files but when I go to categories, I can't add a new category. I don't have the option to add anything...

9 Oct 2009, 3:43 AM
#10
stevish avatar

stevish

New Zenner

Join Date:
Sep 2009
Posts:
12
Plugin Contributions:
0

Re: Password Protected Categories (PPC) - Support Thread

robbinsgj:

Ok, I found the files but when I go to categories, I can't add a new category. I don't have the option to add anything...

Zen cart will only add categories if there are no products in that category. So if you've added products in the "root" category, you may have to delete them and add some categories instead... I'm not really sure if there's an easier way to do that.

10 Oct 2009, 2:42 AM
#11
robbinsgj avatar

robbinsgj

New Zenner

Join Date:
Jul 2009
Posts:
48
Plugin Contributions:
0

Re: Password Protected Categories (PPC) - Support Thread

I've followed all the steps 3x.
I am able to create password protected categories in the admin panel.
I am able to add a product under that category
When I visit the store and click on that category, I see the product. I am not prompted for a password.

Any ideas?

10 Oct 2009, 3:16 AM
#12
robbinsgj avatar

robbinsgj

New Zenner

Join Date:
Jul 2009
Posts:
48
Plugin Contributions:
0

Re: Password Protected Categories (PPC) - Support Thread

robbinsgj:

I've followed all the steps 3x.
I am able to create password protected categories in the admin panel.
I am able to add a product under that category
When I visit the store and click on that category, I see the product. I am not prompted for a password.

Any ideas?

I fixed this by bypassing the override directories and just modifying the files.

Additionally, the following instructions have the wrong lines in them:


FILE: /includes/languages/english/CUSTOM/index.php

Find (on or around line 48):

define('TEXT_PRODUCT_MODEL', 'Model: ');

Add the following lines underneath it:

define('CATEGORY_PASS_INVALID', '<h4 style="color: #ff0000;">Invalid Password</h4>');
define('CATEGORY_INSERT_PASSWORD', '<h3>Category Locked</h3><p>For security reasons, this category is password protected. If you haven't been given the password, then you are not authorized to view this category.</p><strong>Please enter the password</strong>: ');

**Repeat this with any other languages you use.


FILE: /includes/languages/english/CUSTOM/product_info.php

Find (on or around line 20):

define('TEXT_ALL_MANUFACTURERS', 'All Manufacturers');

Add the following lines underneath it:

define('CATEGORY_PASS_INVALID', '<h4 style="color: #ff0000;">Invalid Password</h4>');
define('CATEGORY_INSERT_PASSWORD', '<h3>Category Locked</h3><p>For security reasons, this category is password protected. If you haven't been given the password, then you are not authorized to view this category.</p><strong>Please enter the password</strong>: ');

**Repeat this with any other languages you use.


define('TEXT_PRODUCT_MODEL', 'Model: '); is actually on line 20 in file /includes/languages/english/CUSTOM/product_info.php

define('TEXT_ALL_MANUFACTURERS', 'All Manufacturers'); is actually on line 48 of file /includes/languages/english/CUSTOM/index.php

25 Nov 2009, 10:12 PM
#13
nonfinite avatar

nonfinite

Zen Follower

Join Date:
May 2008
Posts:
203
Plugin Contributions:
0

Re: Password Protected Categories (PPC) - Support Thread

I edited your text to reflect the changes you mention in page two. Can you update your zip with this text?

Also, If you can explain WHICH occurrence of <!--bof Form close--> to place code under that would be great! There are two there.

This installation includes editing 7 files, installing 1 new file, and applying one SQL patch (a fairly simple one).

  1. ADD FILES

Add the file "tpl_category_pass_check.php" to /includes/templates/CUSTOM/templates

######################################################################
2. INSTALL SQL PATCH

BE SURE TO BACKUP YOUR DATABASE BEFORE PROCEEDING

In the admin area, under "Tools -> Install SQL Patches", enter the following query:

ALTER TABLE categories ADD pw varchar(64);

WARNING! This assumes you have not used a prefix when installing your databases. If you did use a prefix, add it before "categories" (ie: prefix_categories)

######################################################################
3. EDIT FILES

If you don't understand the use of CUSTOM in some of the file paths, please read https://www.zen-cart.com/tutorials/index.php?article=36

WARNING! Currently there is no override system for admin files, so some of these files listed are the CORE files. Always do a backup of each file before you edit it.


FILE: /admin/includes/modules/category_product_listing.php

Find (on or near lines 100 AND 109) There are TWO! Replace them both!:

  $categories = $db->Execute("select c.categories_id, cd.categories_name, cd.categories_description, c.categories_image,
                                     c.parent_id, c.sort_order, c.date_added, c.last_modified,
                                     c.categories_status

Replace BOTH with:

  $categories = $db->Execute("select c.categories_id, cd.categories_name, cd.categories_description, c.categories_image,
                                     c.parent_id, c.sort_order, c.date_added, c.last_modified,
                                     c.categories_status, c.pw

(Just added ", pw")


FILE: /admin/categories.php

Find (on or near line 147):

  if (isset($_POST['categories_id'])) $categories_id = zen_db_prepare_input($_POST['categories_id']);
  $sort_order = zen_db_prepare_input($_POST['sort_order']);

  $sql_data_array = array('sort_order' => (int)$sort_order);

  if ($action == 'insert_category') {
    $insert_sql_data = array('parent_id' => $current_category_id,
                             'date_added' => 'now()');

Replace with:

  if (isset($_POST['categories_id'])) $categories_id = zen_db_prepare_input($_POST['categories_id']);
  if (isset($_POST['categories_pw'])) $categories_pw = zen_db_prepare_input($_POST['categories_pw']);
  $sort_order = zen_db_prepare_input($_POST['sort_order']);

  $sql_data_array = array('sort_order' => (int)$sort_order);

  if ($action == 'insert_category') {
    $insert_sql_data = array('parent_id' => $current_category_id,
                             'date_added' => 'now()',
							 'pw' => $categories_pw);

Find (on or near line 182):

    $update_sql_data = array('last_modified' => 'now()');

Replace with:

    $update_sql_data = array('last_modified' => 'now()',
                              'pw' => $categories_pw);

Find (on or near line 704 AND 758) There are TWO! Replace them both!:

  } else {
    $category_inputs_string .= zen_draw_textarea_field('categories_description[' . $languages[$i]['id'] . ']', 'soft', '100%', '20', zen_get_category_description($cInfo->categories_id, $languages[$i]['id']));
  }
}

Replace BOTH with:

  } else {
    $category_inputs_string .= zen_draw_textarea_field('categories_description[' . $languages[$i]['id'] . ']', 'soft', '100%', '20', zen_get_category_description($cInfo->categories_id, $languages[$i]['id']));
  }
  $category_inputs_string .= "<br /><br />" . TEXT_CATEGORIES_PASSWORD . zen_draw_input_field('categories_pw', $cInfo->pw, '', false, 'text', true);
}

FILE: /admin/includes/languages/english/categories.php

Find (on or near line 214):

define('TEXT_CATEGORIES_DESCRIPTION', 'Categories Description:');

Add the following line underneath it:

define('TEXT_CATEGORIES_PASSWORD', '(If Category Password is filled in, customers will have to enter a password to view/buy products in this category)<br/>Category Password: ');

**Repeat this with any other languages you use.


FILE: /includes/languages/english/CUSTOM/index.php

Find (on or around line 48):

define('TEXT_ALL_MANUFACTURERS', 'All Manufacturers');

Add the following lines underneath it:

define('CATEGORY_PASS_INVALID', '<h4 style="color: #ff0000;">Invalid Password</h4>');
define('CATEGORY_INSERT_PASSWORD', '<h3>Category Locked</h3><p>For security reasons, this category is password protected. If you haven't been given the password, then you are not authorized to view this category.</p><strong>Please enter the password</strong>: ');

**Repeat this with any other languages you use.


FILE: /includes/languages/english/CUSTOM/product_info.php

Find (on or around line 20):

define('TEXT_PRODUCT_MODEL', 'Model: ');

Add the following lines underneath it:

define('CATEGORY_PASS_INVALID', '<h4 style="color: #ff0000;">Invalid Password</h4>');
define('CATEGORY_INSERT_PASSWORD', '<h3>Category Locked</h3><p>For security reasons, this category is password protected. If you haven't been given the password, then you are not authorized to view this category.</p><strong>Please enter the password</strong>: ');

**Repeat this with any other languages you use.


FILE: /includes/templates/CUSTOM/templates/tpl_index_product_list.php

Find (on or around line 15):

<div class="centerColumn" id="indexProductList">

Add the following lines underneath it:

<?php 
$passed = false;
require($template->get_template_dir('tpl_category_pass_check.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_category_pass_check.php'); 
if($passed) { //Begin Check for Password
?>

Find (on or around line 208):

} //// eof: categories

Add the following line underneath it:

} //// End Check for Password

FILE: /includes/templates/CUSTOM/templates/tpl_product_info_display.php

Find (on or around line 16):

<div class="centerColumn" id="productGeneral">

Add the following lines underneath it:

<?php 
$passed = false;
require($template->get_template_dir('tpl_category_pass_check.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_category_pass_check.php'); 
if($passed) { //Begin Check for Password
?>

Find (on or around line 244):

<!--bof Form close-->

Add the following line underneath it:

<?php } //End Check for Password ?>
25 Nov 2009, 10:25 PM
#14
nonfinite avatar

nonfinite

Zen Follower

Join Date:
May 2008
Posts:
203
Plugin Contributions:
0

Re: Password Protected Categories (PPC) - Support Thread

This is very, VERY bad. All categories that have more than one item are now EMPTY. Please help!

25 Nov 2009, 11:22 PM
#15
nonfinite avatar

nonfinite

Zen Follower

Join Date:
May 2008
Posts:
203
Plugin Contributions:
0

Re: Password Protected Categories (PPC) - Support Thread

removing the code from /includes/templates/CUSTOM/templates/tpl_index_product_list.php restored my lists, I'll wait to try again when I hear back from you.

I also received this error after making my changes:

http://nonfinite.org/passworderror.png

19 May 2010, 4:38 PM
#16
valnoren avatar

valnoren

New Zenner

Join Date:
Mar 2006
Posts:
63
Plugin Contributions:
0

Re: Password Protected Categories (PPC) - Support Thread

Checking to see if this is a working solution I need to do this but was wondering how well it was working.

19 May 2010, 8:51 PM
#17
valnoren avatar

valnoren

New Zenner

Join Date:
Mar 2006
Posts:
63
Plugin Contributions:
0

Re: Password Protected Categories (PPC) - Support Thread

SWEET! It works! man this was huge I needed this mod so bad! THANKS YOU ROCK!

22 May 2010, 4:10 AM
#18
bmckinley avatar

bmckinley

New Zenner

Join Date:
Mar 2010
Posts:
3
Plugin Contributions:
0

Re: Password Protected Categories (PPC) - Support Thread

All hail STEVISH :cheers:

We owe you one (or more)...installed and working GREAT. We have wanted to allow our wholesale dealers to purchase online, and not have the pages accessable to others...you have allowed that to happen. Thank you.

View your work: http://wholesale.hearts4horses.com

Thanks again,

Bill

24 May 2010, 7:44 AM
#19
vsi10 avatar

vsi10

New Zenner

Join Date:
May 2010
Posts:
2
Plugin Contributions:
0

Re: Password Protected Categories (PPC) - Support Thread

did not work at all for me, it blocked ALL my categories and products on the admin panel. :huh:

i had to restore all my files that were edited.

23 Jul 2010, 3:41 PM
#20
mongolo avatar

mongolo

New Zenner

Join Date:
Jul 2010
Posts:
1
Plugin Contributions:
0

Re: Password Protected Categories (PPC) - Support Thread

This works great, but I've run into a small problem and hope that someone can help. Password-protecting categories with products works as intended, and so does password-protecting individual subcategories, but is there anyway to password protect a category with subcategories? Right now, it will only password-protect the subcategories under a category, but not that top category even though I've put in a password for it in admin.