Twitch Restrict Categories by Customer or Group
Twitch Restrict Categories by Customer or Group
for ZenCart v1.51 - Version 14a
January 13.2014
Description:
- From your admin, this module will allow you to hide categories for multiple customers by new unlimited Group ID assignments, per single category.
- Works with category tabs, category sidebox and search/advanced search.
How it Works:
- In admin each category has a drop down menu that looks for group numbers you create.
- A new database table stores category_id and customers_cat_group relational data.
Note: There is no limitation/filter to enforce parent_id control - useful for hiding categories without disabling products.
- Category_id is set for default 0 so everyone can see the category until you change the Group ID.
- SQL included to add all existing categories to the new table.
- Filters are added to category tabs, category sidebox and search/advanced search to only display if category Group ID matches guest/logged in customer Group ID.
Related Uses:
Aside from hiding categories here and there, you could think it through a bit more...
- Without installing a full featured wholesale module you could simply create a wholesale customer group and keep all of the wholesale categories/products separate.
- Force all categories to have a Group ID != 0, no categories will show for guests - this would make it compatible with Customer Shop Status out of the box.
- Support tier membership, add categories for higher tiers.
- Hide seasonal categories/products.
This module is based on the updated v151 Display Specific Categories for a logged in Customer (single customer per category restriction)
This module is NOT related to Category Specific Access Restriction (CSAR)
1 Attachment(s)
Re: Twitch Restrict Categories by Customer or Group
Attachment 13668
Waiting for approval here:
http://www.zen-cart.com/downloads.php?do=file&id=1819
Available for download with all screenshots here:
http://twitchtoo.com/zencart/index.html
Currently working in a bone stock ZenCart v1.51.
It has also been installed successfully in two other sites running ZenCart 1.51 with the following modules installed:
Twitch Restrict Categories by Customer or Group
Admin Display Product/Catalog Thumbnails 1_5
Twitch TURN OFF SaleMaker & Specials & Discount Coupons for Wholesale Customers
Twitch SaleMaker & Specials for Attributes
Twitch Hidden Searchable Model Number
Twitch Wholesale with Twitch Wholesale Attributes
Twitch Base_Cost
Twitch List_Price
Re: Twitch Restrict Categories by Customer or Group
I have the Category Specific Access Restriction (CSAR) module installed on my site. Would this module interfer with it or can they work together?
Re: Twitch Restrict Categories by Customer or Group
CSAR is based on filtering customers based on store status, Twitch Restrict is based on customers that can be grouped regardless of store status.
I haven't tried to merge the two to date, what need are you attempting to fill with regards to customer access?
Re: Twitch Restrict Categories by Customer or Group
The Problem:
Twitch Restrict Categories by Customer or Group
Advanced Search Plus 2.0
Twitch Restrict hides categories, Advanced Search Plus searches categories...
The Fix:
In order to hide restricted categories when these two modules are installed together, you need to update:
includes/modules/YOUR_TEMPLATE/advanced_search_categories.php
line 47 - 48
from this:
$from_str_cat = " from " . TABLE_CATEGORIES_DESCRIPTION . " cd, " . TABLE_CATEGORIES . " c ";
$where_str_cat = " where c.categories_status <> 0 AND cd.categories_id = c.categories_id and cd.language_id = '" . (int)$_SESSION['languages_id'] . "'"; //2011-03-24 Included c.categories_status <> 0 AND condition to avoid displaying Disabled categories
to this:
$from_str_cat = " from " . TABLE_CATEGORIES_DESCRIPTION . " cd, " . TABLE_CATEGORIES_CUSTOMERS . " ccu, " . TABLE_CATEGORIES . " c ";
$where_str_cat = " where c.categories_status <> 0
AND cd.categories_id = c.categories_id
AND cd.language_id = '" . (int)$_SESSION['languages_id'] . "'
AND c.categories_id = ccu.categories_id
AND (ccu.customers_cat_group = '" . (int)$_SESSION['customers_cat_group'] . "' OR ccu.customers_cat_group = '0' )"; //2011-03-24 Included c.categories_status <> 0 AND condition to avoid displaying Disabled categories
Now the search return will hide restricted categories.
Note: This fix only applies when you have both modules installed.
Re: Twitch Restrict Categories by Customer or Group
Hi,
Do you have this available for 1.39h? I know I should upgrade, but haven't got round to it yet. If not, would it need much modification?
Thanks
Re: Twitch Restrict Categories by Customer or Group
Yes, it could be modified to work with 1.39h, however I currently don't have a site running 1.39h... I'll need login details for your site admin and FTP to get started. Also, do you have any other mods installed related to customer/category restrictions?
Re: Twitch Restrict Categories by Customer or Group
The Problem:
Twitch Restrict Categories by Customer or Group
Products currently have no filter to restrict them from the rest of the world.
The Fix:
If customers_cat_group doesn't match the category you're attempting to access, deny the product exists.
includes/modules/pages/product_info/header_php.php
Add at line 32-33:
// bof Twitch Restrict Categories by Customer or Group
$sql = "select categories_id, customers_cat_group from " . TABLE_CATEGORIES_CUSTOMERS . " WHERE categories_id = '" . (int)$current_category_id . "'";
$customer_group = $db->Execute($sql);
$cust_var = $customer_group->fields['customers_cat_group'];
if ($cust_var != $_SESSION['customers_cat_group']) {
// Not Authorized to see this product/not logged into account
unset($_GET['products_id']);
unset($breadcrumb->_trail[sizeof($breadcrumb->_trail)-1]['title']);
$robotsNoIndex = true;
header('HTTP/1.1 404 Not Found');
}
// eof Twitch Restrict Categories by Customer or Group
Applies to:
Guest/Everyone - Not Logged In
Retail & Wholesale - Logged in
Additional Information:
This fix works with linked products. Meaning there is one product in multiple categories.
If the product exists in a restricted category, it inherits the containing category restriction.
Note: This is NOT the add on that allows you to make individual product restrictions. I'm working on that separately.
Re: Twitch Restrict Categories by Customer or Group
UPDATE: The last fix in post #8 did not respect the customer_cat_group '0' for 'Everyone'
Please use this code moving forward:
// bof Twitch Restrict Categories by Customer or Group
$sql = "select categories_id, customers_cat_group from " . TABLE_CATEGORIES_CUSTOMERS . " WHERE categories_id = '" . (int)$current_category_id . "'";
$customer_group = $db->Execute($sql);
$cust_var = $customer_group->fields['customers_cat_group'];
if ($cust_var == '0') {
// do nothing - the category is set for 'Everyone'
} elseif ($cust_var != $_SESSION['customers_cat_group']) {
// Not Authorized to see this product/not logged into account
unset($_GET['products_id']);
unset($breadcrumb->_trail[sizeof($breadcrumb->_trail)-1]['title']);
$robotsNoIndex = true;
header('HTTP/1.1 404 Not Found');
}
// eof Twitch Restrict Categories by Customer or Group
This patch will be included in version 14b when it is released.
Re: Twitch Restrict Categories by Customer or Group
Twitch Restrict Categories by Customer or Group 14b is complete.
This version includes both fixes published in this forum:
Post #5 - Advanced Search Plus 2.0 + Hide Restricted Search Categories w/Twitch Restrict Categories Installed
Post #8 & #9 - Twitch Restrict Categories by Customer or Group + Inherited Product Restriction
It also includes a new Master 'customers_cat_group' ID
The purpose of this update is to allow one master login to access everything regardless of customers_cat_group status on the live site.
When category is set to customers_cat_group = 1
- Live Site - Master sees all categories and products in sidebox/category tabs/advanced search
- Admin - set category to Master 1 and you can restrict category to master only on live site
- Category status remains unchanged
- Product status remains unchanged
- Restriction remains inherited from nearest category