Results 1 to 9 of 9
  1. #1
    Join Date
    Dec 2012
    Posts
    68
    Plugin Contributions
    0

    Default Need help with Modified Priority handling module

    I took the Priority Handling Plugin and modified to become a Hazmat Shipping Fee Plugin that adds a one time fee is a designated item is added to the cart. I have that working to my liking. I then modified it again to create Surcharge Fee Plugin that adds a one time fee again if certain items are ordered and I have it working properly.

    The problem arises when both fees are triggered by a particular items, only one will show up. For example if I put an item in the cart that has Hazmat shipping it is properly added all the way through to checkout and appears on the Step 2 of 3 checkout page and also in the total on the Step 3 of 3 checkout page..

    If I add an item to the cart that has the Surcharge Fee flagged it also is properly added all the way through to checkout, the output appears on Page 2 of 3 and in the total on Page 3 of 3.

    The problem arises when I have one of each type item in the cart only the Hazmat fee out put is written to the page on both 2 of 3 and 3 of 3 during the checkout. If working correctly I would have both a Hazmat Fee notation and and Surcharge Fee notation on both of the remaining checkout pages.

    I have changed variable names, output names everything I can think off that might be causing some type of over write where Hazmat would take a precedence. I have changed sort orders in the admin trying to get Surcharge to take a precedence to no avail.

    These are two standalone modules, modified from the Priority Handling Module. They are identical except for the variable naming, I modified to be "hazmat handling" and "surcharge fee". Everything works properly adding and removing from Zen cart and they work properly separate from each other with both installed.
    The breakdown is when I had an item in cart that triggers the "Hazmat Handling" fee and also an item in the cart that triggers the "Surcharge Fee". In that instance only the "Hazmat Handling" fee is displayed and calculated.

    The URL is http://bms.night.net

    The test item in "Clone Kits" has the Hazmat Fee associated with it.
    The test item in "Stock Nose Cones" has the Surcharge Fee associated with it.
    Individually one of the other fee will be presented, together only the Hazmat Fee is presented.

    Links for the code files are below.

    http://bms.night.net/hazmat_handling_code.pdf
    http://bms.night.net/surcharge_fee_code.pdf

    The pdfs were to large to attach...

    Any insight is appreciated.

    Tony

  2. #2
    Join Date
    Jul 2012
    Posts
    16,734
    Plugin Contributions
    17

    Default Re: Need help with Modified Priority handling module

    OOOHHHHH... I think I see it now... (bumped this part up to the top of my message as resolving this will fix your bigger issue, though there are some comments below)... What happens if you reverse the add-to-cart sequence? My guess is that you will end up with the surcharge fee being applied and not the hazmat fee...


    There is a problem with the credit_selection logic... What happens is that each product is looked through... Whatever the status of the applicable fee is for the last product in the cart is what will be applied... If you want the surcharge no matter how many product there are added to the cart, then basically once such a product is found, the code needs to break out of the loop and apply the surcharge. The same thing for the haz, if there is a haz product in the cart, then need to break out of the loop and apply the hazmat "information"....



    Don't know how much of an effect it has on the total process, but something that keeps "bothering" me is that in both examples within the credit_selection function the applicable $set_xxx is set to be equal to a constant (no single quotes) but then is evaluated against the constant in quotes. I would suggest in both files:

    Code:
    $set_surcharge = 'SURCHARGE';
    } else {
    $set_surcharge = 'NOSURCHARGE';
    and equivalent for 'HAZMAT' and 'NOHAZMAT'

    The other thing that could maybe be a problem, is the Execute query and some potential query caching that might be at play within the $db->Execute($product_query_h) function. Might suggest:
    Code:
    $db->Execute($product_query_h, false, false, 0, true);
    And another is that within the same credit_selection (which is called when on the checkout_payment page), there is a test against the $_SESSION variable for the type of fee, previous use/check for that session variable was like !$_SESSION, instead of confirming that it was assigned a specific value, does that play a factor in this?

    There's also actually a lookup function that could take the place of at least three lines of code that are in each of the plugins:
    Code:
    $proid = zen_products_lookup($prod['id'], 'surcharge_fee');
    or equivalent for 'hazmat_fee'.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

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

    Default Re: Need help with Modified Priority handling module

    Why are these "credit" modules? That's normally only used for giving discounts .... not for charging a fee.
    .

    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.

  4. #4
    Join Date
    Dec 2012
    Posts
    68
    Plugin Contributions
    0

    Default Re: Need help with Modified Priority handling module

    Not sure about why they are credit modules. It looked like the original module several iterations ago, back to Zen cart 1.3, with an update at 1.5. It doesn't appear it was ever a "credit" module, from the Readme : This module is a modification of the Insurance Shipping module, which is a modification of the
    low order fee module from Harald Ponce de Leon.

    So I have no clue ,other than trying to make it work for my purpose, which i think I am close. It may had some function to reduce shipping it the order was for a very small purchase? I have used that type of logic (if you want to call it that...) in another cart where I wanted to reduce shipping cost based on something specific being ordered.

    TR

  5. #5
    Join Date
    Dec 2012
    Posts
    68
    Plugin Contributions
    0

    Default Re: Need help with Modified Priority handling module

    Thanks, that worked like a charm. The break in the for each took care of the problem. Thanks for your help. I also fixed the quoted variables and the db execute statement.
    I do not know the logic of the zen_cart_lookup to determine how things are stored, since my fields are custom in the database, does the zen_cart_lookup get all the variables associated with the product_id?

    TR

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

    Default Re: Need help with Modified Priority handling module

    Quote Originally Posted by tonyreynolds View Post
    Thanks, that worked like a charm. The break in the for each took care of the problem. Thanks for your help. I also fixed the quoted variables and the db execute statement.
    I do not know the logic of the zen_cart_lookup to determine how things are stored, since my fields are custom in the database, does the zen_cart_lookup get all the variables associated with the product_id?

    TR
    It will provide the result/field data of whatever field is provided for the products_id. The field must be in either the product's table or the products_description table. If it is in the products_description table, then there are also language considerations.

    I gave you the syntax to pull the surcharge_fee field instead of writing a select statement, an execute, and then an assignment of the field to the variable, that lookup function returns the field's result.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  7. #7
    Join Date
    Dec 2012
    Posts
    68
    Plugin Contributions
    0

    Default Re: Need help with Modified Priority handling module

    Thanks, I always like cleaner code. That eliminated the three lines of code and a query call.

    TR

  8. #8
    Join Date
    Dec 2012
    Posts
    68
    Plugin Contributions
    0

    Default Re: Need help with Modified Priority handling module

    In the Hazmat/Surcharge module I am working I want to assign a fixed value when product selection indicates either a hazmat fee or surcharge fee should be charged.
    In the Priority Handling Plugin it is a checkbox, Yes or No. I changed that to a hidden field and set the value to 1.
    'field' => zen_draw_hidden_field('opt_hazmat_handling', '1', $selected)
    There may be a better way to set the fixed value, I am not sure the "$selected has a meaning. Would it work this way:
    'field' => zen_draw_hidden_field('opt_hazmat_handling', '1') or is there a better Zen way to set a hidden form field and value?

    Tony

  9. #9
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,492
    Plugin Contributions
    88

    Default Re: Need help with Modified Priority handling module

    Tony, I've reworked your hazmat order-total. It's been simplified (no need for that credit-class, as DrByte pointed out) and should now interoperate with the One-Page Checkout.

    Here's your original order-total:
    Code:
    <?php
    /*
      Hazmat Fee Handling Module
      ot_hazmat_handling.php, v 1.0 2017/12/03
      osCommerce, Open Source E-Commerce Solutions
      http://www.oscommerce.com
    
      Copyright (c) 2002 osCommerce
    
      Modified to work with zen cart
    
    
      Released under the GNU General Public License
    */
    class ot_hazmat_handling {
        function ot_hazmat_handling()
        {
            $this->code = 'ot_hazmat_handling';
            $this->title = MODULE_ORDER_TOTAL_HAZMAT_HANDLING_TITLE;
            $this->description = MODULE_ORDER_TOTAL_HAZMAT_HANDLING_DESCRIPTION;
            $this->enabled = MODULE_ORDER_TOTAL_HAZMAT_HANDLING_STATUS;
            $this->sort_order = MODULE_ORDER_TOTAL_HAZMAT_HANDLING_SORT_ORDER;
            $this->credit_class = 'true';
            $this->output = array();
        }
        
        function process()
        {
            global $order, $currencies;
    
            if (MODULE_ORDER_TOTAL_HAZMAT_HANDLING_USE == 'true') {
                if (! $_SESSION['hazmat_handling']) {
                    $hz_charge_it = 'false';
                } else {
                    $hz_charge_it = 'true';
                }
    
                // get country/zone id (copy & paste from functions_taxes.php)
                if (isset($_SESSION['customer_id'])) {
                  $cntry_id = $_SESSION['customer_country_id'];
                  $zn_id = $_SESSION['customer_zone_id'];
                } else {
                  $cntry_id = STORE_COUNTRY;
                  $zn_id = STORE_ZONE;
                }
    
                if ($hz_charge_it == 'true') {
                    $tax = zen_get_tax_rate(MODULE_ORDER_TOTAL_HAZMAT_HANDLING_TAX_CLASS);
                    if (MODULE_ORDER_TOTAL_HAZMAT_HANDLING_TYPE =='percent') {
                        $hz_tax      = zen_calculate_tax(($order->info['subtotal'] * MODULE_ORDER_TOTAL_HAZMAT_HANDLING_PER / 100), $tax);
                        $hz_subtotal = $order->info['subtotal'] * MODULE_ORDER_TOTAL_HAZMAT_HANDLING_PER / 100;
                    } else {
                      if ($order->info['subtotal'] > MODULE_ORDER_TOTAL_HAZMAT_HANDLING_OVER) {
                        $st = MODULE_ORDER_TOTAL_HAZMAT_HANDLING_OVER;
                      } else {
                        $st = $order->info['subtotal'];
                      }
                        $how_often   = ceil($st/MODULE_ORDER_TOTAL_HAZMAT_HANDLING_INCREMENT);
                      $hz_tax      = zen_calculate_tax((MODULE_ORDER_TOTAL_HAZMAT_HANDLING_FEE * $how_often), $tax);
                      $hz_subtotal = (MODULE_ORDER_TOTAL_HAZMAT_HANDLING_FEE * $how_often);
                    }
                    if (MODULE_ORDER_TOTAL_HAZMAT_HANDLING_TAX_INLINE == 'Handling Fee') { 
                        $hz_text     = $currencies->format($hz_subtotal+$hz_tax, true, $order->info['currency'], $order->info['currency_value']);
                        $hz_value    = $hz_subtotal+$hz_tax; // nr@sebo addition
                    } else {
                        $tax_descrip = zen_get_tax_description(MODULE_ORDER_TOTAL_HAZMAT_HANDLING_TAX_CLASS, $cntry_id, $zn_id);
                        $order->info['tax_groups'][$tax_descrip]+= $hz_tax;
                        $hz_text     = $currencies->format($hz_subtotal, true, $order->info['currency'], $order->info['currency_value']);
                        $hz_value    = $hz_subtotal; // nr@sebo addition
                    }
                    $order->info['tax'] += $hz_tax; 
                    $order->info['total'] += $hz_subtotal + $hz_tax;
                    $this->output[] = array('title' => $this->title . ':','text' => $hz_text,'value' => $hz_value);
                } 
    
            } else if ($hz_charge_it == 'false') {
                $tax = zen_get_tax_rate(MODULE_ORDER_TOTAL_HAZMAT_HANDLING_TAX_CLASS);
                $hazmat_handling = 0;
                $order->info['tax'] += zen_calculate_tax($hazmat_handling, $tax);
                $order->info['total'] += $hazmat_handling + zen_calculate_tax($hazmat_handling, $tax);
                $this->output[] = array('title' => $this->title . ':',
                'text' => $currencies->format(zen_add_tax($hazmat_handling, $tax) + zen_calculate_tax($hazmat_handling, $tax), true, $order->info['currency'], $order->info['currency_value']),
                'value' => zen_add_tax($hazmat_handling, $tax));
            }
        }
    
        function pre_confirmation_check($order_total)
        {
            return 0.0;
        }
    
        function get_order_total() {
          global  $order;
          $order_total_tax = $order->info['tax'];
          $order_total = $order->info['total'];
          if ($this->include_shipping != 'true') $order_total -= $order->info['shipping_cost'];
          if ($this->include_tax != 'true') $order_total -= $order->info['tax'];
          $orderTotalFull = $order_total;
          $order_total = array('totalFull'=>$orderTotalFull, 'total'=>$order_total, 'tax'=>$order_total_tax);
      
          return $order_total;
        }
      
        function credit_selection()
        {
            global $db;
            global $order;
            $set_hazmat = "NOHAZMAT";
            
            //QUERY TO GET THE PRODUCTS ORDERED
            
            foreach ($order->products as $prod) {
            // Here we get the hazmat fee status of the product and set the flag.
                $proid = zen_products_lookup($prod['id'], 'hazmat_fee');
                if ($proid != 0)
                { 
                    $set_hazmat = 'HAZMAT';
                    break;
                } else {
                    $set_hazmat = 'NOHAZMAT';
                }
            
            }
    
    
        if ($set_hazmat == 'HAZMAT')
             {
        
                $selected = (($_SESSION['hazmat_handling'] == '1') ? true : false);
                $selection = array(
                  'id' => $this->code,
                  'module' => $this->title,
                  'redeem_instructions' => MODULE_ORDER_TOTAL_HAZMAT_HANDLING_TEXT_DESCR.'<br><br>',
                  'fields' => array(array(
                    'field' => zen_draw_hidden_field('opt_hazmat_handling', '1', $selected),
                    'title' => MODULE_ORDER_TOTAL_HAZMAT_HANDLING_ENTER_CODE
                  ))
                );
                return $selection;
           } 
       }
        
        function update_credit_account($i)
        {
        }
        
        function apply_credit()
        {
        }
        
        function clear_posts()
        {
            unset($_SESSION['hazmat_handling']);
        }
       
        function collect_posts()
        {
            global $db, $currencies;
            if ($_POST['opt_hazmat_handling']) {
                $_SESSION['hazmat_handling'] = $_POST['opt_hazmat_handling'];
            } else {
                $_SESSION['hazmat_handling'] = '0'; 
            }
        }
      
        function check()
        {
            global $db;
            if (!isset($this->check)) {
            $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_STATUS'");
            $this->check = $check_query->RecordCount();
            }
            
            return $this->check;
        }
        
        function keys()
        {
            return array('MODULE_ORDER_TOTAL_HAZMAT_HANDLING_STATUS','MODULE_ORDER_TOTAL_HAZMAT_HANDLING_USE', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_SORT_ORDER', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_TYPE', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_PER', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_FEE', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_INCREMENT', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_OVER', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_TAX_CLASS','MODULE_ORDER_TOTAL_HAZMAT_HANDLING_TAX_INLINE');
        }
        
        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 ('Enable Hazmat Fee Handling Module', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_STATUS', 'true', 'Do you want to enable this module? To fully turn this off, both this option and the one below should be set to false.', '6', '1','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('Offer Hazmat Fee Handling?', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_USE', 'true', 'Do you want to setup hazmat fee handling?', '6', '2', '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, date_added) values('Sort Order', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_SORT_ORDER', '150', 'Sort order of display.', '6', '3', 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('Priority Handling Charge Type', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_TYPE', 'percent', 'Specify whether the Hazmat fee should be a percentage of  cart subtotal, or specified as tiers below', '6', '4', 'zen_cfg_select_option(array(\'percent\', \'tiered\'), ', 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('Handling Charge: Percentage', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_PER', '5', 'Enter the percentage of subtotal to charge as handling fee.', '6', '5', '', 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('Handling Charge: Fee Tier', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_FEE', '.50', 'Enter the fee tier increment.  Hazmat charge will be: <br> (subtotal/price_tier) * fee_tier', '6', '6', '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('Handling Charge: Price Tier ', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_INCREMENT', '100', 'Enter the price tier increment.  To setup a flat-fee structure, enter a large value here and your flat fee in the fee tier above.  For example, if you want to always charge $10 and your orders are typically around $100, enter $5000 here and $10 in the Fee Tier box.', '6', '7', '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('Handling Charge: Price Tier Ceiling', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_OVER', '1000', 'Enter the price tier maximum.  For example, the default values setup a 50 cent charge for every $100 assessed up to $1000 of the cart subtotal, or $5 maximum.', '6', '8', 'currencies->format', 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_HAZMAT_HANDLING_TAX_CLASS', '0', 'If the hazmat fee is taxable, then select the tax class that should apply.', '6', '9', '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('Tax Display', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_TAX_INLINE', 'Tax Subtotal', 'Can have tax (see above) be added to the tax subtotal line for the class above or have the it be added to the hazmat  fee line.  Which line should it be added to?', '6', '10', 'zen_cfg_select_option(array(\'Tax Subtotal\', \'Handling Fee\'), ', now())");       
        }
        
        function remove()
        {
            global $db;
            $keys = '';
            $keys_array = $this->keys();
            for ($i=0; $i<sizeof($keys_array); $i++) {
                $keys .= "'" . $keys_array[$i] . "',";
            }
            $keys = substr($keys, 0, -1);
            
            $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in (" . $keys . ")");
        }
    }
    
    
    ?>
    ... and here's the reworked version, with the following changes:
    1. Renamed constructor method to __construct for PHP 7.0+ compliance
    2. Removed "declaration" that the module is credit-class. That, in turn, allowed the removal of the pre_confirmation_check, get_order_total, credit_selection, update_credit_account, apply_credit, clear_posts and collect_posts methods.
    3. Modified the process method to see if there are products in the order that "qualify" for the HazMat fee and, if so, record the update to the order's totals.

    Code:
    <?php
    /*
      Hazmat Fee Handling Module
      ot_hazmat_handling.php, v 1.0 2017/12/03
      osCommerce, Open Source E-Commerce Solutions
      http://www.oscommerce.com
    
      Copyright (c) 2002 osCommerce
    
      Modified to work with zen cart
    
    
      Released under the GNU General Public License
    */
    
    class ot_hazmat_handling 
    {
        function __construct()
        {
            $this->code = 'ot_hazmat_handling';
            $this->title = MODULE_ORDER_TOTAL_HAZMAT_HANDLING_TITLE;
            $this->description = MODULE_ORDER_TOTAL_HAZMAT_HANDLING_DESCRIPTION;
            $this->enabled = MODULE_ORDER_TOTAL_HAZMAT_HANDLING_STATUS;
            $this->sort_order = MODULE_ORDER_TOTAL_HAZMAT_HANDLING_SORT_ORDER;
            $this->output = array();
        }
        
        function process()
        {
            global $order, $currencies;
    
            if (MODULE_ORDER_TOTAL_HAZMAT_HANDLING_USE == 'true') {
                $hz_charge_it = false;
                foreach($order->products as $prod) {
                    // Here we get the hazmat fee status of the product and set the flag.
                    if (zen_products_lookup($prod['id'], 'hazmat_fee') != 0) {
                        $hz_charge_it = true;
                        break;
                    }
                } 
    
                if ($hz_charge_it) {
                    $tax_address = zen_get_tax_locations();
                    $tax = zen_get_tax_rate(MODULE_ORDER_TOTAL_HAZMAT_HANDLING_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']);
    
                    if (MODULE_ORDER_TOTAL_HAZMAT_HANDLING_TYPE == 'percent') {
                        $hz_tax      = zen_calculate_tax(($order->info['subtotal'] * MODULE_ORDER_TOTAL_HAZMAT_HANDLING_PER / 100), $tax);
                        $hz_subtotal = $order->info['subtotal'] * MODULE_ORDER_TOTAL_HAZMAT_HANDLING_PER / 100;
                    } else {
                        if ($order->info['subtotal'] > MODULE_ORDER_TOTAL_HAZMAT_HANDLING_OVER) {
                            $st = MODULE_ORDER_TOTAL_HAZMAT_HANDLING_OVER;
                        } else {
                            $st = $order->info['subtotal'];
                        }
                        $how_often   = ceil($st/MODULE_ORDER_TOTAL_HAZMAT_HANDLING_INCREMENT);
                        $hz_tax      = zen_calculate_tax((MODULE_ORDER_TOTAL_HAZMAT_HANDLING_FEE * $how_often), $tax);
                        $hz_subtotal = (MODULE_ORDER_TOTAL_HAZMAT_HANDLING_FEE * $how_often);
                    }
                    
                    if (MODULE_ORDER_TOTAL_HAZMAT_HANDLING_TAX_INLINE == 'Handling Fee') { 
                        $hz_text     = $currencies->format($hz_subtotal+$hz_tax, true, $order->info['currency'], $order->info['currency_value']);
                        $hz_value    = $hz_subtotal+$hz_tax; // nr@sebo addition
                    } else {
                        $order->info['tax_groups'][$tax_description] += $hz_tax;
                        $hz_text     = $currencies->format($hz_subtotal, true, $order->info['currency'], $order->info['currency_value']);
                        $hz_value    = $hz_subtotal; // nr@sebo addition
                    }
                    $order->info['tax'] += $hz_tax; 
                    $order->info['total'] += $hz_subtotal + $hz_tax;
                    $this->output[] = array('title' => $this->title . ':','text' => $hz_text,'value' => $hz_value);
                } 
            }
        }
        
        function check()
        {
            global $db;
            if (!isset($this->check)) {
                $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_STATUS'");
                $this->check = $check_query->RecordCount();
            }
            
            return $this->check;
        }
        
        function keys()
        {
            return array('MODULE_ORDER_TOTAL_HAZMAT_HANDLING_STATUS','MODULE_ORDER_TOTAL_HAZMAT_HANDLING_USE', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_SORT_ORDER', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_TYPE', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_PER', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_FEE', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_INCREMENT', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_OVER', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_TAX_CLASS','MODULE_ORDER_TOTAL_HAZMAT_HANDLING_TAX_INLINE');
        }
    
        
        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 ('Enable Hazmat Fee Handling Module', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_STATUS', 'true', 'Do you want to enable this module? To fully turn this off, both this option and the one below should be set to false.', '6', '1','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('Offer Hazmat Fee Handling?', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_USE', 'true', 'Do you want to setup hazmat fee handling?', '6', '2', '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, date_added) values('Sort Order', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_SORT_ORDER', '150', 'Sort order of display.', '6', '3', 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('Priority Handling Charge Type', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_TYPE', 'percent', 'Specify whether the Hazmat fee should be a percentage of  cart subtotal, or specified as tiers below', '6', '4', 'zen_cfg_select_option(array(\'percent\', \'tiered\'), ', 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('Handling Charge: Percentage', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_PER', '5', 'Enter the percentage of subtotal to charge as handling fee.', '6', '5', '', 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('Handling Charge: Fee Tier', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_FEE', '.50', 'Enter the fee tier increment.  Hazmat charge will be: <br> (subtotal/price_tier) * fee_tier', '6', '6', '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('Handling Charge: Price Tier ', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_INCREMENT', '100', 'Enter the price tier increment.  To setup a flat-fee structure, enter a large value here and your flat fee in the fee tier above.  For example, if you want to always charge $10 and your orders are typically around $100, enter $5000 here and $10 in the Fee Tier box.', '6', '7', '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('Handling Charge: Price Tier Ceiling', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_OVER', '1000', 'Enter the price tier maximum.  For example, the default values setup a 50 cent charge for every $100 assessed up to $1000 of the cart subtotal, or $5 maximum.', '6', '8', 'currencies->format', 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_HAZMAT_HANDLING_TAX_CLASS', '0', 'If the hazmat fee is taxable, then select the tax class that should apply.', '6', '9', '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('Tax Display', 'MODULE_ORDER_TOTAL_HAZMAT_HANDLING_TAX_INLINE', 'Tax Subtotal', 'Can have tax (see above) be added to the tax subtotal line for the class above or have the it be added to the hazmat  fee line.  Which line should it be added to?', '6', '10', 'zen_cfg_select_option(array(\'Tax Subtotal\', \'Handling Fee\'), ', now())");       
        }
        
        function remove()
        {
            global $db;
            $keys = '';
            $keys_array = $this->keys();
            for ($i=0; $i<sizeof($keys_array); $i++) {
                $keys .= "'" . $keys_array[$i] . "',";
            }
            $keys = substr($keys, 0, -1);
            
            $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in (" . $keys . ")");
        }
    }
    P.S. I've not validated the coding but on spot-check all looks good. I'll also point you to some documentation on the various order_total class methods.
    Last edited by DrByte; 17 Apr 2017 at 09:18 PM. Reason: missing parenthesis on line 42

 

 

Similar Threads

  1. Rush/Priority Handling Charge
    By mlankeit in forum Managing Customers and Orders
    Replies: 53
    Last Post: 16 Oct 2018, 07:58 PM
  2. v151 Priority Handling Search
    By riomaha in forum Managing Customers and Orders
    Replies: 1
    Last Post: 14 Dec 2013, 10:03 AM
  3. Replies: 1
    Last Post: 9 Jul 2010, 03:56 AM
  4. Rush Priority Handling Tax Calculation Issue
    By catteridge in forum Managing Customers and Orders
    Replies: 0
    Last Post: 9 Dec 2009, 09:00 PM
  5. Disable Priority Handling addon Module?
    By stride-r in forum All Other Contributions/Addons
    Replies: 0
    Last Post: 21 Apr 2009, 03:59 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