Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2007
    Location
    Nijmegen, Netherlands
    Posts
    44
    Plugin Contributions
    0

    Default 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.
    Last edited by pe7er; 20 Feb 2008 at 02:01 AM.
    Kind Regards,
    Peter Martin, Joomla specialist
    www.db8.nl

  2. #2
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default 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.

  3. #3
    Join Date
    Apr 2007
    Location
    Nijmegen, Netherlands
    Posts
    44
    Plugin Contributions
    0

    Default 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

  4. #4
    Join Date
    Apr 2007
    Location
    Nijmegen, Netherlands
    Posts
    44
    Plugin Contributions
    0

    Default 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?

    Code:
    // 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

  5. #5
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default 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.

  6. #6
    Join Date
    Apr 2007
    Location
    Nijmegen, Netherlands
    Posts
    44
    Plugin Contributions
    0

    Default 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:
    Code:
    // 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

  7. #7
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Limit payment module to certain group of customers?

    Quote Originally Posted by pe7er View Post
    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?ma...roducts_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.

 

 

Similar Threads

  1. Credit Card Limit - Hiding Payment Option on Certain Values
    By limelites in forum General Questions
    Replies: 2
    Last Post: 5 Apr 2011, 02:04 PM
  2. Limit payment type to a customer group (or customer)?
    By pharry in forum Built-in Shipping and Payment Modules
    Replies: 5
    Last Post: 21 Oct 2010, 07:04 PM
  3. Add certain customers to Group automatically...
    By rebekah in forum Managing Customers and Orders
    Replies: 5
    Last Post: 20 Apr 2009, 10:00 PM
  4. Limit the products that a group of customers can see
    By Thieving_Gypsy in forum General Questions
    Replies: 4
    Last Post: 4 Mar 2009, 09:22 AM
  5. Need help with module configuration--enable certain payment module for certain items
    By maxus in forum Built-in Shipping and Payment Modules
    Replies: 0
    Last Post: 10 Mar 2008, 04:24 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR