Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2016
    Location
    Columbia TN
    Posts
    5
    Plugin Contributions
    0

    Default If products_id=28 then do not calculate low order fee....

    I am working on elks72.org
    The club told me to add a convenience fee of 3.5%.
    I have advised against this but lost the battle for the moment.
    I have advised the club to allow me to increase the price of the product but lost that battle. (customers - arrrrrr)
    I used the zen cart code "ot_loworderfee.php" below to accomplish this convenience fee.
    Now they want the fee on some products and not on others, but not based on price.
    I could use help identifying how to not include a specific product id number when totaling the convenience fee.
    If products_id=28 then do not calculate low order fee....

    I also welcome other ideas. Thanks Dennis Sayer. Webmaster
    The Benevolent and Protective Order of Elks Nashville-Franklin, Lodge No. 72

    PHP Code:
    <?php
    /**
     * ot_total order-total module
     *
     * @package orderTotal
     * @copyright Copyright 2003-2016 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @license [URL]http://www.zen-cart.com/license/2_0.txt[/URL] GNU Public License V2.0
     * @version $Id: Author: DrByte  Thu Apr 2 14:27:45 2015 -0400 Modified in v1.5.5 $
     */
      
    class ot_loworderfee {
        var 
    $title$output;

        function 
    __construct() {
          
    $this->code 'ot_loworderfee';
          
    $this->title MODULE_ORDER_TOTAL_LOWORDERFEE_TITLE;
          
    $this->description MODULE_ORDER_TOTAL_LOWORDERFEE_DESCRIPTION;
          
    $this->sort_order MODULE_ORDER_TOTAL_LOWORDERFEE_SORT_ORDER;

          
    $this->output = array();
        }

        function 
    process() {
          global 
    $order$currencies;

          if (
    MODULE_ORDER_TOTAL_LOWORDERFEE_LOW_ORDER_FEE == 'true') {
            switch (
    MODULE_ORDER_TOTAL_LOWORDERFEE_DESTINATION) {
              case 
    'national':
                if (
    $order->delivery['country_id'] == STORE_COUNTRY$pass true; break;
              case 
    'international':
                if (
    $order->delivery['country_id'] != STORE_COUNTRY$pass true; break;
              case 
    'both':
                
    $pass true; break;
              default:
                
    $pass false; break;
            }

    //        if ( ($pass == true) && ( ($order->info['total'] - $order->info['shipping_cost']) < MODULE_ORDER_TOTAL_LOWORDERFEE_ORDER_UNDER) ) {
            
    if ( ($pass == true) && ( $order->info['subtotal'] < MODULE_ORDER_TOTAL_LOWORDERFEE_ORDER_UNDER) ) {
              
    $charge_it 'true';
              
    $cart_content_type $_SESSION['cart']->get_content_type();
              
    $gv_content_only $_SESSION['cart']->gv_only();
              if (
    $cart_content_type == 'physical' or $cart_content_type == 'mixed') {
                
    $charge_it 'true';
              } else {
                
    // check to see if everything is virtual, if so - skip the low order fee.
                
    if ((($cart_content_type == 'virtual') and MODULE_ORDER_TOTAL_LOWORDERFEE_VIRTUAL == 'true')) {
                  
    $charge_it 'false';
                  if (((
    $gv_content_only 0) and MODULE_ORDER_TOTAL_LOWORDERFEE_GV == 'false')) {
                    
    $charge_it 'true';
                  }
                }

                if (((
    $gv_content_only 0) and MODULE_ORDER_TOTAL_LOWORDERFEE_GV == 'true')) {
                
    // check to see if everything is gift voucher, if so - skip the low order fee.
                  
    $charge_it 'false';
                  if (((
    $cart_content_type == 'virtual') and MODULE_ORDER_TOTAL_LOWORDERFEE_VIRTUAL == 'false')) {
                    
    $charge_it 'true';
                  }
                }
              }

              if (
    $charge_it == 'true') {
                
    $tax_address zen_get_tax_locations();
                
    $tax zen_get_tax_rate(MODULE_ORDER_TOTAL_LOWORDERFEE_TAX_CLASS$tax_address['country_id'], $tax_address['zone_id']);
                
    $tax_description zen_get_tax_description(MODULE_ORDER_TOTAL_LOWORDERFEE_TAX_CLASS$tax_address['country_id'], $tax_address['zone_id']);

    // calculate from flat fee or percentage
                
    if (substr(MODULE_ORDER_TOTAL_LOWORDERFEE_FEE, -1) == '%') {
                  
    $low_order_fee = ($order->info['subtotal'] * (MODULE_ORDER_TOTAL_LOWORDERFEE_FEE/100));
                } else {
                  
    $low_order_fee MODULE_ORDER_TOTAL_LOWORDERFEE_FEE;
                }


                
    $order->info['tax'] += zen_calculate_tax($low_order_fee$tax);
                
    $order->info['tax_groups']["$tax_description"] += zen_calculate_tax($low_order_fee$tax);
                
    $order->info['total'] += $low_order_fee zen_calculate_tax($low_order_fee$tax);
                if (
    DISPLAY_PRICE_WITH_TAX == 'true') {
                  
    $low_order_fee += zen_calculate_tax($low_order_fee$tax);
                }

                
    $this->output[] = array('title' => $this->title ':',
                                        
    'text' => $currencies->format($low_order_feetrue$order->info['currency'], $order->info['currency_value']),
                                        
    'value' => $low_order_fee);
              }
            }
          }
        }

        function 
    check() {
          global 
    $db;
          if (!isset(
    $this->_check)) {
            
    $check_query "select configuration_value
                            from " 
    TABLE_CONFIGURATION "
                            where configuration_key = 'MODULE_ORDER_TOTAL_LOWORDERFEE_STATUS'"
    ;

            
    $check_query $db->Execute($check_query);
            
    $this->_check $check_query->RecordCount();
          }

          return 
    $this->_check;
        }

        function 
    keys() {
          return array(
    'MODULE_ORDER_TOTAL_LOWORDERFEE_STATUS''MODULE_ORDER_TOTAL_LOWORDERFEE_SORT_ORDER''MODULE_ORDER_TOTAL_LOWORDERFEE_LOW_ORDER_FEE''MODULE_ORDER_TOTAL_LOWORDERFEE_ORDER_UNDER''MODULE_ORDER_TOTAL_LOWORDERFEE_FEE''MODULE_ORDER_TOTAL_LOWORDERFEE_DESTINATION''MODULE_ORDER_TOTAL_LOWORDERFEE_TAX_CLASS''MODULE_ORDER_TOTAL_LOWORDERFEE_VIRTUAL''MODULE_ORDER_TOTAL_LOWORDERFEE_GV');
        }

        function 
    install() {
          global 
    $db;
          
    $db->Execute("insert into " TABLE_CONFIGURATION " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('This module is installed', 'MODULE_ORDER_TOTAL_LOWORDERFEE_STATUS', 'true', '', '6', '1','zen_cfg_select_option(array(\'true\'), ', now())");
          
    $db->Execute("insert into " TABLE_CONFIGURATION " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_ORDER_TOTAL_LOWORDERFEE_SORT_ORDER', '400', 'Sort order of display.', '6', '2', now())");
          
    $db->Execute("insert into " TABLE_CONFIGURATION " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Allow Low Order Fee', 'MODULE_ORDER_TOTAL_LOWORDERFEE_LOW_ORDER_FEE', 'false', 'Do you want to allow low order fees?', '6', '3', 'zen_cfg_select_option(array(\'true\', \'false\'), ', now())");
          
    $db->Execute("insert into " TABLE_CONFIGURATION " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, date_added) values ('Order Fee For Orders Under', 'MODULE_ORDER_TOTAL_LOWORDERFEE_ORDER_UNDER', '50', 'Add the low order fee to orders under this amount.', '6', '4', 'currencies->format', now())");
          
    $db->Execute("insert into " TABLE_CONFIGURATION " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, date_added) values ('Order Fee', 'MODULE_ORDER_TOTAL_LOWORDERFEE_FEE', '5', 'For Percentage Calculation - include a % Example: 10%<br />For a flat amount just enter the amount - Example: 5 for $5.00', '6', '5', '', now())");
          
    $db->Execute("insert into " TABLE_CONFIGURATION " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Attach Low Order Fee On Orders Made', 'MODULE_ORDER_TOTAL_LOWORDERFEE_DESTINATION', 'both', 'Attach low order fee for orders sent to the set destination.', '6', '6', 'zen_cfg_select_option(array(\'national\', \'international\', \'both\'), ', now())");
          
    $db->Execute("insert into " TABLE_CONFIGURATION " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_ORDER_TOTAL_LOWORDERFEE_TAX_CLASS', '0', 'Use the following tax class on the low order fee.', '6', '7', 'zen_get_tax_class_title', 'zen_cfg_pull_down_tax_classes(', now())");
          
    $db->Execute("insert into " TABLE_CONFIGURATION " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('No Low Order Fee on Virtual Products', 'MODULE_ORDER_TOTAL_LOWORDERFEE_VIRTUAL', 'false', 'Do not charge Low Order Fee when cart is Virtual Products Only', '6', '8', 'zen_cfg_select_option(array(\'true\', \'false\'), ', now())");
          
    $db->Execute("insert into " TABLE_CONFIGURATION " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('No Low Order Fee on Gift Vouchers', 'MODULE_ORDER_TOTAL_LOWORDERFEE_GV', 'false', 'Do not charge Low Order Fee when cart is Gift Vouchers Only', '6', '9', 'zen_cfg_select_option(array(\'true\', \'false\'), ', now())");
        }

        function 
    remove() {
          global 
    $db;
          
    $db->Execute("delete from " TABLE_CONFIGURATION " where configuration_key in ('" implode("', '"$this->keys()) . "')");
        }
      }
    ?>

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

    Default Re: If products_id=28 then do not calculate low order fee....

    Now they want the fee on some products and not on others, but not based on price.
    I could use help identifying how to not include a specific product id number when totaling the convenience fee.
    If products_id=28 then do not calculate low order fee....
    there are many ways to achieve this solution. that said, i'm not exactly sure what you are asking, as the above quote is ambiguous.... but in either case, my solution would be the same.

    there might be a better way to do this using an observer, but i am not as familiar with observers and that solution might make use of additional database queries.

    if the code below, you can see the $low_order_fee is based on the $order->info['subtotal']:

    Code:
    // calculate from flat fee or percentage
    if (substr(MODULE_ORDER_TOTAL_LOWORDERFEE_FEE, -1) == '%') {
    $low_order_fee = ($order->info['subtotal'] * (MODULE_ORDER_TOTAL_LOWORDERFEE_FEE/100));
    the number is created in the order class... and specifically in the cart function. my idea would be to create a new variable there to store the amount to be used as opposed to the subtotal. all of the necessary logic would be in the order class and you could then use those variables to replace the above line. for example, if products_id =28 - do not charge a low order fee - for the whole order or just for the subtotal amount of products_id = 28? if the former establish a variable charge_low_order_fee and set it to true; then flip it to false if 28 exists in the order. alternatively if do not charge only on that amount, create a new subtotal called subtotal_for_low_fee and don't add it there.

    for example, ~ line 407, you see where the $this->info = array gets established. right after that line, you can add:

    Code:
    $this->info['charge_low_order_fee'] = true;
    $this->info['subtotal_for_low_fee'] = 0;
    then ~line 613 after $this->info['subtotal'] += $shown_price; you can add the following code:

    Code:
    if ($this->products[$index]['id'] == 28) {
      $this->info['charge_low_order_fee'] = false;
    } else {
      $this->info['subtotal_for_low_fee'] += $shown_price;
    }
    depending on what you want to do, you can then use those 2 array elements in the $order to modify your first bit of code i quoted above. those elements would be available in your new code as:

    Code:
    $order->info['charge_low_order_fee'] 
    $order->info['subtotal_for_low_fee']
    modifying the order class would require you to make a note of it, and bring those changes with you whenever you upgrade your version of ZC.

    i hope that helps!

    good luck. let us know how it goes!
    author of square Webpay.
    mxWorks has premium plugins. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  3. #3
    Join Date
    Oct 2016
    Location
    Columbia TN
    Posts
    5
    Plugin Contributions
    0

    Default Re: If products_id=28 then do not calculate low order fee....

    Making sure you are talking about "includes\classes\order.php" because I cant find "$this->info" on line 407
    I would want the low order fee to be included in all other purchases except those identified as exempt.

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

    Default Re: If products_id=28 then do not calculate low order fee....

    that is the correct file. needless to say, i have modified mine....

    i'm now looking at the file from v155b. it is dated as such:

    Code:
    * @version $Id: Author: DrByte  Fri Jan 1 12:23:19 2016 -0500 Modified in v1.5.5 $
    the line i am talking about is 351. it starts like this:

    Code:
        $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID,
                            'currency' => $_SESSION['currency'],
                            'currency_value' => $currencies->currencies[$_SESSION['currency']]['value'],
                            'payment_method' => $GLOBALS[$class]->title,
                            'payment_module_code' => $GLOBALS[$class]->code,
                            'coupon_code' => $coupon_code->fields['coupon_code'],
        //                          'cc_type' => (isset($GLOBALS['cc_type']) ? $GLOBALS['cc_type'] : ''),
        //                          'cc_owner' => (isset($GLOBALS['cc_owner']) ? $GLOBALS['cc_owner'] : ''),
        //                          'cc_number' => (isset($GLOBALS['cc_number']) ? $GLOBALS['cc_number'] : ''),
        //                          'cc_expires' => (isset($GLOBALS['cc_expires']) ? $GLOBALS['cc_expires'] : ''),
        //                          'cc_cvv' => (isset($GLOBALS['cc_cvv']) ? $GLOBALS['cc_cvv'] : ''),
                            'shipping_method' => (isset($_SESSION['shipping']['title'])) ? $_SESSION['shipping']['title'] : '',
                            'shipping_module_code' => (isset($_SESSION['shipping']['id']) && strpos($_SESSION['shipping']['id'], '_') > 0 ? $_SESSION['shipping']['id'] : $_SESSION['shipping']),
                            'shipping_cost' => isset($_SESSION['shipping']['cost']) ? $_SESSION['shipping']['cost'] : 0,
                            'subtotal' => 0,
                            'shipping_tax' => 0,
                            'tax' => 0,
                            'total' => 0,
                            'tax_groups' => array(),
                            'comments' => (isset($_SESSION['comments']) ? $_SESSION['comments'] : ''),
                            'ip_address' => $_SESSION['customers_ip_address'] . ' - ' . $_SERVER['REMOTE_ADDR']
                            );
    that is where the info array section gets initialized.

    the next line i mention is at 539:

    Code:
            $this->info['subtotal'] += $shown_price;
    best.
    author of square Webpay.
    mxWorks has premium plugins. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  5. #5
    Join Date
    Oct 2016
    Location
    Columbia TN
    Posts
    5
    Plugin Contributions
    0

    Default Re: If products_id=28 then do not calculate low order fee....

    Thank you, I will try your suggestions tomorrow. I will try and make the logic in such a way that all but the exempted products still acquire the fee.

  6. #6
    Join Date
    Jul 2012
    Posts
    16,732
    Plugin Contributions
    17

    Default Re: If products_id=28 then do not calculate low order fee....

    Use of an observer for the purpose of comparing a products_id ($products[$i]['id']) against a known number would not require any additional database query in the cart function, unless some table or other characteristic of such product was set within the database that is/was not already available. One such notifier to observe would be: NOTIFY_ORDER_CART_ADD_PRODUCT_LIST

    Also, note, if any product is to be considered for comparison, that product has attributes, and the specific attributes are not of concern, then the comparison of $this->products[$index]['id'] to the products_id should be made without the additional hash of the attributes (uprid) either through casting to an integer or the use of zen_get_prid such as:
    Code:
    if (zen_get_prid($this->products[$i]['id']) == 28) {
    If you are going to end up with multiple such product, then there are a couple of ways to accomplish the comparison,comparison, can create an array with all of the products_ids as values then query the array to identify if the value is in the array, could build additional comparisons through a series of or (||) comparisons, etc...

    Capturing the necessary data for each individual product "up-front" certainly is a better/easier way to go than to try to deconstruct/remove things from within that order_total module after everything has already been calculated. Yes, it does require a bit of modification because of the change in reference variable, but it does seem like you'll be able to meet the customer's desired expectations at least that way.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  7. #7
    Join Date
    Oct 2016
    Location
    Columbia TN
    Posts
    5
    Plugin Contributions
    0

    Default Re: If products_id=28 then do not calculate low order fee....

    Thank you but there will not be any comparisons. The store sells virtual items, like tickets, donations and membership fees. Some items they want a fee added at checkout and some items no fee.

  8. #8
    Join Date
    Jul 2012
    Posts
    16,732
    Plugin Contributions
    17

    Default Re: If products_id=28 then do not calculate low order fee....

    Quote Originally Posted by EKLS72 View Post
    Thank you but there will not be any comparisons. The store sells virtual items, like tickets, donations and membership fees. Some items they want a fee added at checkout and some items no fee.
    Not sure what is meant by there not being any comparisons.

    All items listed as those sold by the store are perfect examples of when attributes might be used and if used then to identify that a specific products_id (i.e. 28) is used/included the cart/order designation for the product must not include the attribute portion. Virtual items, if they include downloads then that will have an attribute affect. Tickets, if the ticket is sold for an event but in "sections" of the venue: attributes. Donations, if a pick list is provided instead of simply typing in a "dollar" amount as the quantity of product to add: attributes. Membership fees, where a customer "pays into" a program, but possibly for a duration or at a level of payment, these things would be covered by attributes. Therefore, when evaluating what product to include/exclude from having this extra fee, it would be of benefit to evaluate the data to exclude the consideration of attributes as long as those attributes are considered unnecessary for the purpose of needing the fee.

    Basically, once the product is added to the cart and it has/had attributes, then its products_id (or 'id') no longer is just the number related to the product. It now also contains other data that is expected to uniquely identify that product and the choices made for that product/purchase.

    The comparison to which I was referring was the identification that the product is in the cart. Evaluating whether a data value is equal to a known/desired value is a comparison. (ie. $this->products[$i]['id'] == 28 compares the value stored for $this->products[$i]['id'] to the integer 28.)

    If the product identified to products_id has or could have attributes, then once the product is added to the cart with its attribute, the value of $this->products[$i]['id'] will begin with 28: and end with a md5 hash value related to the attribute(s) that were added and the entire "entry" for $this->products[$i]['id'] will not be 28 and in the comparison will be false because 28:xxxxxxxx does not equal 28. Use of something like zen_get_prid(28:xxxxxxxx) will evaluate as 28 and therefore zen_get_prid(28:xxxxxxxx) == 28 will evaluate to true and indicate that the product known to be products_id 28 is in the cart....
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 

Similar Threads

  1. Low Order Fee
    By tsrplatelayer in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 1
    Last Post: 31 Jul 2016, 08:58 AM
  2. Low Order Fee not working with Authorize.net AIM
    By Feznizzle in forum Built-in Shipping and Payment Modules
    Replies: 3
    Last Post: 22 Mar 2014, 12:00 AM
  3. Coupon not allowing the Low Order Fee
    By jensurge in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 1
    Last Post: 4 Jan 2009, 10:49 AM
  4. low order fee is not charged
    By Mistica in forum General Questions
    Replies: 0
    Last Post: 22 Jun 2008, 11:02 AM

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