Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2017
    Location
    White City
    Posts
    15
    Plugin Contributions
    0

    Default Hide Cod payment for retail customers, show Cod payment for Dealers, Distributors

    I am running zencart 1.5.6c I am totally stumped I have tried every option of disabling payment or shipping I have seen posted on the zencart forum without success. It seams like this should be so simple to make work.

    I am trying to Hide Cod payment for retail customers, show Cod payment for Dealers, Distributors

    I tried to replace:

    $this->enabled = (defined('MODULE_PAYMENT_COD_STATUS') && MODULE_PAYMENT_COD_STATUS == 'True');

    with:

    $this->enabled = ((MODULE_PAYMENT_PAYMENT_COD_STATUS == 'True') ? true : false);
    if ($_SESSION['customer_id'] == 12) {
    $this->enabled = false;
    }

    --------------------------------------------------------
    I have tried changing 12 to 0 it doesn't work.
    I have tried replacing 'customer_id' with 'group_pricing' and "customers_group_pricing' it doesn't work.
    I am stumped why this is not working or how to get it to work.
    Can any one help?

    Thanks in advance.

  2. #2
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,669
    Plugin Contributions
    9

    Default Re: Hide Cod payment for retail customers, show Cod payment for Dealers, Distributors

    this worked as expected for me:

    PHP Code:
          $this->enabled = (defined('MODULE_PAYMENT_COD_STATUS') && MODULE_PAYMENT_COD_STATUS == 'True');
          if (
    $_SESSION['customer_id'] == 12) {
              
    $this->enabled false;
          } 
    author of square Webpay.
    mxWorks has premium plugins. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  3. #3
    Join Date
    Sep 2017
    Location
    White City
    Posts
    15
    Plugin Contributions
    0

    Default Re: Hide Cod payment for retail customers, show Cod payment for Dealers, Distributors

    I tried again. No luck.

    I want COD to be hidden for Retail customers and visible for Wholesale customers.
    (1 Dealer, 2 e-tailer, 3 Distributor, 4 Manufacturer, in group_pricing in SQL)

    Replacing:

    $this->enabled = (defined('MODULE_PAYMENT_COD_STATUS') && MODULE_PAYMENT_COD_STATUS == 'True');

    with:

    $this->enabled = (defined('MODULE_PAYMENT_COD_STATUS') && MODULE_PAYMENT_COD_STATUS == 'True');
    if ($_SESSION['customer_id'] == 0) {
    $this->enabled = false;
    }

    -----------------------------------------------------------------------------
    Here are my results with my changes i tried.

    ($_SESSION['customer_id'] == 0)
    COD shows up on Retail and Wholesale price discounts logins at checkout.

    ($_SESSION['customer_id'] == 1)
    COD shows up on Retail and Wholesale price discounts logins at checkout.

    ($_SESSION['customer_id'] == 12)
    COD shows up on Retail and Wholesale price discounts logins at checkout.

    -----------------------------------------------------------------------------

    ($_SESSION['group_pricing'] == 0)
    COD is hidden on Retail and Wholesale price discounts logins at checkout.

    ($_SESSION['group_pricing'] == 1)
    COD shows up on Retail and Wholesale price discounts logins at checkout.

    ($_SESSION['group_pricing'] == 12)
    COD shows up on Retail and Wholesale price discounts logins at checkout.

    -----------------------------------------------------------------------------

    ($_SESSION['customers_group_pricing'] == 0)
    COD is hidden on Retail and Wholesale price discounts logins at checkout.

    ($_SESSION['customers_group_pricing'] == 1)
    COD shows up on Retail and Wholesale price discounts logins at checkout.

    ($_SESSION['customers_group_pricing'] == 12)
    COD shows up on Retail and Wholesale price discounts logins at checkout.

    -----------------------------------------------------------------------------

    ($_SESSION['customers_whole'] == 0)
    COD is hidden on Retail and Wholesale price discounts logins at checkout.

    ($_SESSION['customers_whole'] == 1)
    COD shows up on Retail and Wholesale price discounts logins at checkout.

    ($_SESSION['customers_whole'] == 12)
    COD shows up on Retail and Wholesale price discounts logins at checkout.

  4. #4
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,669
    Plugin Contributions
    9

    Default Re: Hide Cod payment for retail customers, show Cod payment for Dealers, Distributors

    oh dear.... my mistake...

    when posting on the board, i am a BIG of using bb code tags. there is link at the bottom of every board page for BB code and it's very helpful for me, especially when posting code.

    you have a bit of a learning curve.

    i have never used group pricing; the table seems part of the base ZC code; although i can not tell if you are using the following plugin:

    https://www.zen-cart.com/downloads.p...=154&styleid=2

    which is neither here nor there.

    the only useful SESSION variable available to you is the customer_id. this refers only to a particular customer. it is a number. the group that the particular customer is in is NOT available in the SESSION variables.

    i do not see customers_whole or customers_group_pricing being set as part of the user session. which explains the results you see. 0 is the same as false or not set (or something a little more specific, which is not really relevant to our conversation).

    during the _construct function in the COD class, there is a global variable called $order and specifically an array called $order->customer. when i look at that array on my heavily modified test system, the group pricing variable is also not there.

    what to do??

    so many choices:

    • we can add the group pricing variable to the SESSION.
    • we can add the group pricing variable to the order class. the most elegant way would be to make it part of a new observer class. that way when you upgrade you are not modifying the core order class code.
    • we can add a function in the COD class to determine the group the customer is in; and keep it all here. this involves modifying core code, but you are already doing that for this selection.


    i'm sure there are other ways to skin this cat, but i'll show you option 3, and then you can figure out what you want to do.

    here is modified COD class. you will need to bring this change along with you whenever you do an update.

    PHP Code:
          // class constructor
          
    function __construct() {
              global 
    $order;
            
              
    $this->code 'cod';
              
    $this->title MODULE_PAYMENT_COD_TEXT_TITLE;
              
    $this->description MODULE_PAYMENT_COD_TEXT_DESCRIPTION;
              
    $this->sort_order defined('MODULE_PAYMENT_COD_SORT_ORDER') ? MODULE_PAYMENT_COD_SORT_ORDER null;
              
    $this->enabled = (defined('MODULE_PAYMENT_COD_STATUS') && MODULE_PAYMENT_COD_STATUS == 'True');
            
              
    // only allow certain groups to use COD.
              
    $allowed_group_classes = array('1''2''3''4');
              if (!
    in_array($this->get_group_price($_SESSION['customer_id']), $allowed_group_classes)) {
                  
    $this->enabled false;
              }
            
              if (
    defined('MODULE_PAYMENT_COD_ORDER_STATUS_ID') && (int)MODULE_PAYMENT_COD_ORDER_STATUS_ID 0) {
                  
    $this->order_status MODULE_PAYMENT_COD_ORDER_STATUS_ID;
              }
            
              if (
    is_object($order)) {
                  
    $this->update_status();
              }
          }
        
          
    // class methods
          
    function get_group_price($customer_id) {
              global 
    $db;
            
              
    $query "SELECT customers_group_pricing from " TABLE_CUSTOMERS " WHERE customers_id = " . (int)$customer_id;
              
    $group_price $db->Execute($query);
              return 
    $group_price->fields['customers_group_pricing'];
          }
        
        
          function 
    update_status() {
              global 
    $order$db;
    ... 
    good luck.
    author of square Webpay.
    mxWorks has premium plugins. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  5. #5
    Join Date
    Dec 2007
    Location
    Payson, AZ
    Posts
    1,076
    Plugin Contributions
    15

    Default Re: Hide Cod payment for retail customers, show Cod payment for Dealers, Distributors

    As Carlwhat pointed out, sessions are not there and user ID would fail... this is one way that worked for me..

    in the file includes/modules/payment/cod.php
    red lines is modified.
    Code:
    // class constructor
        function __construct() {
          global $order, $db;
    
          $this->code = 'cod';
          $this->title = MODULE_PAYMENT_COD_TEXT_TITLE;
          $this->description = MODULE_PAYMENT_COD_TEXT_DESCRIPTION;
          $this->sort_order = defined('MODULE_PAYMENT_COD_SORT_ORDER') ? MODULE_PAYMENT_COD_SORT_ORDER : null;
         // $this->enabled = (defined('MODULE_PAYMENT_COD_STATUS') && MODULE_PAYMENT_COD_STATUS == 'True');
     //bof modified
     if (isset($_SESSION['customer_id']) && (defined('MODULE_ORDER_TOTAL_COD_STATUS') && MODULE_ORDER_TOTAL_COD_STATUS == 'true')) {
            $account_group = $db->Execute("SELECT customers_group_pricing FROM " . TABLE_CUSTOMERS . " WHERE customers_id = '" . (int)$_SESSION['customer_id'] . "'");
             $this->enabled = ($account_group->fields['customers_group_pricing'] != '0') ? true : false;
     }else{
          $this->enabled = (defined('MODULE_ORDER_TOTAL_COD_STATUS') && MODULE_ORDER_TOTAL_COD_STATUS == 'true');
     }
     //eof modified
          if (defined('MODULE_PAYMENT_COD_ORDER_STATUS_ID') && (int)MODULE_PAYMENT_COD_ORDER_STATUS_ID > 0) {
            $this->order_status = MODULE_PAYMENT_COD_ORDER_STATUS_ID;
          }
    Should work with group pricing set for the existing user COD would show, no group pricing set, no COD. not fully tested and looking at it here I think there is still a hole in the logic..
    Dave
    Always forward thinking... Lost my mind!

  6. #6
    Join Date
    Apr 2007
    Location
    Ontario, Canada
    Posts
    1,731
    Plugin Contributions
    27

    Default Re: Hide Cod payment for retail customers, show Cod payment for Dealers, Distributors

    Have a peek at the Twitch Wholesale filters as they work to filter this type of data for Dual Pricing, Group Pricing (ZC Stock) and a host of other payment and shipping modules.

    https://www.zen-cart.com/downloads.p...1771&styleid=4

    https://www.zen-cart.com/showthread....ale-Attributes


    As you can see there are a number of different methods, each with a specific purpose. Most of the Twitch filters focus on groups - all wholesale customers or all retail. The switches you are trying to change sometimes have direct on/off switch effects within the page code others you will find need multiple filters due to inconsistent use of functions and lookups throughout the Zen core.


    You don't need to install the module to pull the filters out and try them out. You could trace the files that need changing and perhaps find the solution... or contact one of us for a hands-on-the-code fix :)
    Twitch.
    https://www.twitchtoo.com Do you work for free? Please donate.
    Twitch Base7 with Wholesale PRO - 88 preinstalled plugins zero errors.

 

 

Similar Threads

  1. v138a Disabling COD payment for certain customers
    By moosesoom in forum Built-in Shipping and Payment Modules
    Replies: 5
    Last Post: 20 Feb 2014, 04:17 PM
  2. v139h Hide COD payment method from certain customers?
    By TroyC in forum General Questions
    Replies: 3
    Last Post: 5 Apr 2013, 04:19 PM
  3. Add fee percentage for COD payment
    By avotecnica in forum Built-in Shipping and Payment Modules
    Replies: 4
    Last Post: 8 Feb 2010, 10:55 PM
  4. Enable COD only for customers with Company
    By RaySpike in forum General Questions
    Replies: 1
    Last Post: 9 May 2009, 09:35 PM
  5. Handling fee for COD payment
    By Stoned-6 in forum Built-in Shipping and Payment Modules
    Replies: 1
    Last Post: 20 Oct 2007, 06:23 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