The standard Zen Cart installation can be configured in Admin > Configuration > Customer Details asf:
Customer Shop Status - View Shop and Prices
Customer must be approved to shop
0= Not required
1= Must login to browse
2= May browse but no prices unless logged in
3= Showroom Only
Selecting any of these options assigns conditions 0-3 globally, meaning that every category / product detail page is treated the same way.
I was faced with restricting only certain categories to option 1 or 2 but leave the bulk of the remaining cats at option 0.
To achieve this 2 core files had to be copied to my relevant template folder(s) using the override system.
(I am using ZC version 1.3.9f - but this may work with any 1.3.x install ??)
These files are:
1. includes/modules/product_listing.php
copied to includes/modules/MY_TEMPLATE/product_listing.php
2. includes/templates/template_default/templates/tpl_product_info_display.php
copied to includes/templates/MY_TEMPLATE/templates/tpl_product_info_display.php
Next, these 2 files were edited:
File product_listing.php
After line 17 insert: $hide_productprice_cPath = "3_19_45,68,78";
This specifies categories 68, 78 and category 3 with sub-cat 19 and sub-sub-cat 45 to be restricted that only approved / logged-in customers can see prices.
Then find
Code:
case 'PRODUCT_LIST_PRICE':
$lc_price = zen_get_products_display_price($listing->fields['products_id']) . '<br />';
and edit to read:
Code:
case 'PRODUCT_LIST_PRICE':
if (!$_SESSION['customer_id'] && in_array($cPath,explode(',', $hide_productprice_cPath)) ) {
$lc_price = '';
} else
$lc_price = zen_get_products_display_price($listing->fields['products_id']) . '<br />';
and find
Code:
// more info in place of buy now
$lc_button = '';
if (zen_has_product_attributes($listing->fields['products_id']) or PRODUCT_LIST_PRICE_BUY_NOW == '0') {
$lc_button = '<a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id']) > 0 ? zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? $_GET['cPath'] : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . MORE_INFO_TEXT . '</a>';
} else
edit to read:
Code:
// more info in place of buy now
$lc_button = '';
if (!$_SESSION['customer_id'] && in_array($cPath,explode(',', $hide_productprice_cPath)) ) {
$lc_button = '<a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id']) > 0 ? zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? $_GET['cPath'] : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . MORE_INFO_TEXT . '</a>';
} else
if (zen_has_product_attributes($listing->fields['products_id']) or PRODUCT_LIST_PRICE_BUY_NOW == '0') {
$lc_button = '<a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id']) > 0 ? zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? $_GET['cPath'] : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . MORE_INFO_TEXT . '</a>';
} else {
File tpl_product_info_display.php
Around lines 14-15 find
Code:
//require(DIR_WS_MODULES . '/debug_blocks/product_info_prices.php');
?>
Right after these 2 lines insert new code
Code:
<?php
/**
* here you can specify product info pages of categories to be accessed by logged in customers only
*/
$login_required_cPath = "3_19_45,68,78";
?>
<?php
/**
* if you want product details of certain categories accessed by members only, redirect them to the login page
*/
if (!$_SESSION['customer_id'] && in_array($cPath,explode(',', $login_required_cPath)) ) {
$_SESSION['navigation']->set_snapshot();
zen_redirect(zen_href_link(FILENAME_LOGIN, '', 'SSL'));
}
?>
That's it.
Now the whole store works as normal, customers can browse, see prices, add products to the cart and check out. The only categories with are restricted are categories 68, 78 and category 3 with sub-cat 19 and sub-sub-cat 45. These 3 cats will not display prices on listings. If the customer clicks on a short product description within the listing they are prompted to register or log in.
Make sure you backup, backup, backup before making changes.
The next step would be to make this configurable from the admin. That, however, is outside my programming skills. If someone has an idea how to do this they are most welcome to post their suggestions / solutions.
Bookmarks