Forums / Discounts/Coupons, Gift Certificates, Newsletters, Ads / Code: is customer member of discount group? - restricting view based on membership

Code: is customer member of discount group? - restricting view based on membership

Locked

Views: 4,210

Results 1 to 9 of 9
This thread is locked. New replies are disabled.
14 Mar 2007, 4:33 PM
#1
wputler avatar

wputler

New Zenner

Join Date:
Feb 2007
Posts:
3
Plugin Contributions:
0

Code: is customer member of discount group? - restricting view based on membership

I would like to add the following to my category tree:

if (customer is member of wholesale)
{
select all categories
} else {

select all categories except ID=2

}

I have the code for the select statements, I just don't know how to determine if the customer is a member of a certain group.

I realize I will probably have to write a function, but I am brand new to Zen-cart and have no idea which tables & fields I would be looking for.

If someone can point me in the right direction, I'd appreciate it.

/Wendy

3 Apr 2007, 12:05 PM
#2
cyber_duck avatar

cyber_duck

New Zenner

Join Date:
Dec 2006
Posts:
3
Plugin Contributions:
0

Re: Code: is customer member of discount group? - restricting view based on membership

have a look at the field "customers_group_pricing" in the "customers" table, i think that's what you are looking for in your function

sylv

4 Apr 2007, 4:53 AM
#3
wputler avatar

wputler

New Zenner

Join Date:
Feb 2007
Posts:
3
Plugin Contributions:
0

Re: Code: is customer member of discount group? - restricting view based on membership

Thanks for the tip. I should have posted that I have it mostly figured out.

I have a wholesale category that I don't want anyone but wholesalers to see.

So I had to make some hacks that I know will cause problems when we upgrade - if anyone has some ideas for improvement, I'm up for that.

Changes made:
includes/modules/pages/login/header_php.php

I added "customers_group_pricing" to the SQL query

  $check_customer_query = "SELECT customers_id, customers_firstname, customers_lastname, customers_password,
                                    customers_email_address, customers_default_address_id,
                                    customers_authorization, customers_group_pricing, customers_referral
                           FROM " . TABLE_CUSTOMERS . "
                           WHERE customers_email_address = :email";		

Then I set a session variable to indicate if they are wholesale members or not

	  // PDD - added info to check for wholesalers
	$_SESSION['wholesale_member'] = 0;
    if (isset($_SESSION['customer_id']) ) {

      $pdd_group_member_of = $check_customer->fields['customers_group_pricing'];

      $sql = "select group_id from " . TABLE_GROUP_PRICING . "
                where group_name = 'Wholesalers'";
      $pdd_group_result = $db->Execute($sql);
      $pdd_group_number = $pdd_group_result->fields['group_id'];
	  
	  if ($pdd_group_member_of == $pdd_group_number) {
	  	$_SESSION['wholesale_member'] = 1;
	 } // end if member of wholesale group
    } // end if customer logged in

I included an if statement in my SQL query construction to exclude the wholesale category if they are not wholesalers.
includes/classes/category_tree.php

 if (!(isset($_SESSION['wholesale_member']) && ($_SESSION['wholesale_member'] == 1) )) {
							 	$categories_query .= " and c.categories_id != 2 ";
}

This works great, unless they view ALL or NEW products. I have determined that I really need to modify the product retrieval query and if I excluded products from the wholesale category, then that category shouldn't even show up because there would be 0 products in the query result.

I made changes to the product query, but I'm getting an SQL error about the syntax being incorrect on the SELECT COUNT part of the query. I tested the query itself and it runs fine. I just think that SELECT COUNT can't support a LEFT JOIN. I'm still investigating this.

This is my first Zen-cart install and I wish I knew more.

/Wendy

19 Feb 2009, 12:27 AM
#4
kehrli avatar

kehrli

Zen Follower

Join Date:
Aug 2007
Location:
Cannon Beach, OR
Posts:
180
Plugin Contributions:
0

Re: Code: is customer member of discount group? - restricting view based on membership

Hi Wendy,

I need to do the exact same thing. Did you solve the "All Products" query? If so, I'd like to see it.

Also, being new, you may not have become familiar with the template override system. I think these files can all be overridden which will make upgrades easier to accomplish.

When I get in tomorrow, I will try to execute what you have done on my store using override files.

19 Feb 2009, 6:59 AM
#5
bunyip avatar

bunyip

Totally Zenned

Join Date:
Sep 2004
Location:
Western Massachusetts
Posts:
2,361
Plugin Contributions:
1

Re: Code: is customer member of discount group? - restricting view based on membership

A lot of what you want to achieve can in fact be done within the template override system - except for the products_all and products_new listings. For those two listings, you'll need to modify the sql queries in the relevant includes/modules/pages/products_(new-all)/header_php.php files.

Rather than modify the category_tree class and have to worry about upgrades, why not duplicate the class file, rename it my_category_tree and rename/modify the two functions within it. (you're going to have to modify it anyway, so with only a little more work you can save a lot of hassle for upgrades in the future - don't forget to pay attention to the cross-references between the two functions).

Having done that, you simply make an override copy of includes/modules/sideboxes/categories.php to call your new category tree class rather than the regular one.

Neville
An assumption is what you arrive at when you get tired of thinking...

19 Feb 2009, 7:12 AM
#6
bunyip avatar

bunyip

Totally Zenned

Join Date:
Sep 2004
Location:
Western Massachusetts
Posts:
2,361
Plugin Contributions:
1

Re: Code: is customer member of discount group? - restricting view based on membership

A couple of other things to think about that you may have overlooked:

  1. you also have to filter the category out from searches
  2. you also need to prevent access (by someone simply typing in the direct url to the page) to the product listing page for that category and to individual product info pages for that category if the customer shouldn't have access.

As an example of how this has been implemented on a working site, visit blackjackbuffers.com and try to view his 'dealer specials' category (cPath is 81) or one of the products within it (product_id 682, named Bulk Discount Buffers.)

Neville
An assumption is what you arrive at when you get tired of thinking...

20 Feb 2009, 5:46 PM
#7
kehrli avatar

kehrli

Zen Follower

Join Date:
Aug 2007
Location:
Cannon Beach, OR
Posts:
180
Plugin Contributions:
0

Re: Code: is customer member of discount group? - restricting view based on membership

Thank you.

I think I'd like to get a professional to do these mods for me. Is there a resource somewhere where the pro PHP/ZenCart programmers links can be found?

20 Feb 2009, 6:58 PM
#8
bunyip avatar

bunyip

Totally Zenned

Join Date:
Sep 2004
Location:
Western Massachusetts
Posts:
2,361
Plugin Contributions:
1

Re: Code: is customer member of discount group? - restricting view based on membership

You won't find a list of programmers anywhere, but you can post a request in the Commercial Help Wanted forum

Neville
An assumption is what you arrive at when you get tired of thinking...

20 Feb 2009, 7:43 PM
#9
kehrli avatar

kehrli

Zen Follower

Join Date:
Aug 2007
Location:
Cannon Beach, OR
Posts:
180
Plugin Contributions:
0

Re: Code: is customer member of discount group? - restricting view based on membership

Exellent, thanks.