Forums / Built-in Shipping and Payment Modules / Limit payment module to certain group of customers?

Limit payment module to certain group of customers?

Locked

Views: 1,556

Results 1 to 7 of 7
This thread is locked. New replies are disabled.
20 Feb 2008, 12:57 AM
#1
pe7er avatar

pe7er

New Zenner

Join Date:
Apr 2007
Location:
Nijmegen, Netherlands
Posts:
44
Plugin Contributions:
0

Limit payment module to certain group of customers?

How can I change the payment method "Check/Money Order" in v1.3.7 so that it will be displayed for
(and can only be used by) a certain group of customers defined in Group Pricing?

I would like to give "distributors" (who are defined in "group pricing"
and who get a % discount) also the possibility to use "Check/Money Order"
and pay after the receipt of the order.

The "Check/Money Order" method should not be visible for any other customers.

Currently the "Check/Money Order" module has only "Payment Zone" as 'variable'
(in the sense that is dependent on some other customer characteristics) configuration option.

Kind Regards,
Peter Martin, Joomla specialist
www.db8.nl

20 Feb 2008, 3:24 AM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Limit payment module to certain group of customers?

It'll take a bit of custom coding:
Edit the module's update_status() function, and do a query to check the current customer's group-discount membership. If they're in the required group, allow the module to remain enabled. If they're not, disable it.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

21 Feb 2008, 2:46 PM
#3
pe7er avatar

pe7er

New Zenner

Join Date:
Apr 2007
Location:
Nijmegen, Netherlands
Posts:
44
Plugin Contributions:
0

Re: Limit payment module to certain group of customers?

Thanks!
I will experiment with the Module's update_status() function.

Kind Regards,
Peter Martin, Joomla specialist
www.db8.nl

25 Feb 2008, 11:48 PM
#4
pe7er avatar

pe7er

New Zenner

Join Date:
Apr 2007
Location:
Nijmegen, Netherlands
Posts:
44
Plugin Contributions:
0

Re: Limit payment module to certain group of customers?

I edited /includes/modules/payment/moneyorder.php and included:

//check if current customer is part of a certain (customers_group_pricing) group pricing (zen_group_pricing -> 1) category
$gpcheck = $db->Execute("select count(*) as count from " . TABLE_CUSTOMERS . " where customers_id = '".$order->customer['customers_id']."' AND customers_group_pricing = '1'; ");
if ($gpcheck->fields['count'] >0){ $check_flag = true; }else{ $check_flag = false; }
//end modification

into the class method function update_status().
I am trying to check if the current customer is part of the
Group Pricing group "1" and if not, disabling this payment method.
Unfortunately it is not working.
Did I make some error, or is this modification not possible this way?

// class methods
    function update_status() {
      global $order, $db;

      if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_MONEYORDER_ZONE > 0) ) {
        $check_flag = false;
        $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_MONEYORDER_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id");
        while (!$check->EOF) {
          if ($check->fields['zone_id'] < 1) {
            $check_flag = true;
            break;
          } elseif ($check->fields['zone_id'] == $order->billing['zone_id']) {
            $check_flag = true;
            break;
          }
          $check->MoveNext();
        }

        //check if current customer is part of a certain (customers_group_pricing) group pricing (zen_group_pricing -> 1) category
        $gpcheck = $db->Execute("select count(*) as count from " . TABLE_CUSTOMERS . " where customers_id = '".$order->customer['customers_id']."' AND customers_group_pricing = '1'; ");
        if ($gpcheck->fields['count'] >0){ $check_flag = true; }else{ $check_flag = false; }
        //end modification

        if ($check_flag == false) {
          $this->enabled = false;
        }
      }

Kind Regards,
Peter Martin, Joomla specialist
www.db8.nl

26 Feb 2008, 3:57 AM
#5
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Limit payment module to certain group of customers?

By "it's not working", do you mean it's just not giving you what you expected? Or throwing an error?

I'd be inclined to suggest that you remove the ; in the query, since it's irrelevant in this sort of approach.
I'd also suggest changing $order->customer['customers_id'] to $_SESSION['customer_id']
I'd also remove the else { $check_flag = false;} part of your if statement.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

26 Feb 2008, 3:47 PM
#6
pe7er avatar

pe7er

New Zenner

Join Date:
Apr 2007
Location:
Nijmegen, Netherlands
Posts:
44
Plugin Contributions:
0

Re: Limit payment module to certain group of customers?

Sorry, I meant that the code did not change the status of the payment module.
I did not get any errors.
With your help I changed the code to:

// class methods
    function update_status() {
      global $order, $db;

      if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_MONEYORDER_ZONE > 0) ) {
        $check_flag = false;
        $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_MONEYORDER_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id");
        while (!$check->EOF) {
          if ($check->fields['zone_id'] < 1) {
            $check_flag = true;
            break;
          } elseif ($check->fields['zone_id'] == $order->billing['zone_id']) {
            $check_flag = true;
            break;
          }
          $check->MoveNext();
        }

        //check if current customer is part of a certain (customers_group_pricing) group pricing (zen_group_pricing -> 1) category
        $gpcheck = $db->Execute("select count(*) as count from " . TABLE_CUSTOMERS . " where customers_id = '".$_SESSION['customer_id']."' AND customers_group_pricing = '1' ");
        if ($gpcheck->fields['count'] >0){ $check_flag = true; }
        //end modification

        if ($check_flag == false) {
          $this->enabled = false;
        }
      }
    }
```However, it still does not work properly: 
the (Check/Money Order) payment module is published 
(Payment Zone: --none--,  Set Order Status: default, Sort order of display: 0).
But the module is shown in all cases; the added code does not hide the payment module for customers who are NOT in the Group Price group (who have customers_group_pricing=1 in their record).

I analysed the code that is parsed just before my modification:
If the module is enabled and the customer is located in the zone were the payment module is assigned to, then **$check_flag = true;**
In case it is set to **$check_flag = true; **then my modification cannot alter it to false, can it?
So maybe I should add the else { $check_flag = false;}  part to my if statement?


Furthermore I have two general questions regarding module modification:- If the PHP code of some module is changed, are the effects immediate?
Or should I unpublish (remove) the module and republish (install) it before any changes will work?
- How can you debug the modules?
Using echo / print_r commands won't work: 
there will be no screen output from within the class/method.

Kind Regards,
Peter Martin, Joomla specialist
www.db8.nl

27 Feb 2008, 6:46 AM
#7
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Limit payment module to certain group of customers?

pe7er:

Furthermore I have two general questions regarding module modification:- >

  • If the PHP code of some module is changed, are the effects immediate?

Or should I unpublish (remove) the module and republish (install) it before any changes will work?

  • How can you debug the modules?

Using echo / print_r commands won't work:
there will be no screen output from within the class/method.

  1. With this particular change, the effects are immediate.
  2. Sometimes you need to use die() statements instead of echo/print statements, due to page-refresh actions, etc. You could also log info to a file using the errorlog() function ie: in conjunction with this contrib: http://www.zen-cart.com/index.php?main_page=product_contrib_info&products_id=860

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.