Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2008
    Location
    Croatia
    Posts
    1,542
    Plugin Contributions
    19

    Default custom tax order total little help please

    I have an order_total module (which I built) but can't get one desired effect on it.

    I need it to collect info from the product in cart and check it's main category ID.

    I have tried the following code but it doesn't work:
    1) added anew function to includes/functions/functions_categories.php
    Code:
    function zen_get_main_category_by_product($products_id){
        global $db;
        $cPath = '';
    
        $category_query = "select p.products_id, p.master_categories_id
                           from " . TABLE_PRODUCTS . " p
                           where p.products_id = '" . (int)$products_id . "' limit 1";
    
    
        $category = $db->Execute($category_query);
    
        if ($category->RecordCount() > 0) {
    
          $categories = array();
          zen_get_parent_categories($categories, $category->fields['master_categories_id']);
          $categories = array_reverse($categories);
          
          return $categories[0];
    }
    }
    2) next, I added this to functions_tax.php:
    Code:
    function zen_get_sales_tax(){
    	 global $db;
    	 $products = $_SESSION['cart']->get_products();
    	 for ($i=0, $n=sizeof($products); $i<$n; $i++) {
    	 $productArray[$i] = array(
                                'id'=>$products[$i]['id']);
    	 }
    	 $main_category_id = zen_get_main_category_by_product($productArray[0]['id']);
    	
    	$sales_tax_select = "SELECT sales_tax from " . TABLE_CATEGORIES . " where categories_id = '" . (int)$main_category_id . "'";
    }
    3) finally, I added this to my new ot_sales_tax.php file:
    Code:
    <?php
    /**
     * ot_total order-total module
     *
     * @package orderTotal
     * @copyright Copyright 2003-2007 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: ot_loworderfee.php 6101 2007-04-01 10:30:22Z wilt $
     */
    
      class ot_sales_tax {
        var $title, $output;
    
        function ot_sales_tax() {
          $this->code = 'ot_sales_tax';
          $this->title = MODULE_ORDER_TOTAL_SALES_TAX_TITLE;
          $this->description = MODULE_ORDER_TOTAL_SALES_TAX_DESCRIPTION;
          $this->sort_order = MODULE_ORDER_TOTAL_SALES_TAX_SORT_ORDER;
    
          $this->output = array();
        }
    
        function process() {
          global $order, $currencies;
    
          if (MODULE_ORDER_TOTAL_SALES_TAX == 'true') {
    
    // calculate from flat fee or percentage
    				$sales_tax_defined = zen_get_sales_tax($sales_tax);
                  $sales_tax_value = ($order->info['subtotal'] * ($sales_tax_defined/100));
    
    			$order->info['total'] += $sales_tax_value;
    
                $this->output[] = array('title' => $this->title . ':',
                                        'text' => $currencies->format($sales_tax_value, true, $order->info['currency'], $order->info['currency_value']),
                                        'value' => $sales_tax_value);
              }
            }
    
        function check() {
    	  global $db;
          if (!isset($this->_check)) {
            $check_query = "select configuration_value
                            from " . TABLE_CONFIGURATION . "
                            where configuration_key = 'MODULE_ORDER_TOTAL_SALES_TAX_STATUS'";
    
            $check_query = $db->Execute($check_query);
            $this->_check = $check_query->RecordCount();
          }
    
          return $this->_check;
        }
    
        function keys() {
          return array('MODULE_ORDER_TOTAL_SALES_TAX_STATUS', 'MODULE_ORDER_TOTAL_SALES_TAX_SORT_ORDER', 'MODULE_ORDER_TOTAL_SALES_TAX', 'MODULE_ORDER_TOTAL_SALES_TAX_FEE');
        }
    
        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_SALES_TAX_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_SALES_TAX_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_SALES_TAX', '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', 'MODULE_ORDER_TOTAL_SALES_TAX_FEE', '5', 'Enter your percentage', '6', '5', '', now())");
        }
    
        function remove() {
    	  global $db;
          $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
        }
      }
    ?>
    Basically, what I'm trying to achieve is to get the ot module to find out the following:
    - check cart for current product
    - check that product's top level category id
    - select a DB entry based on category id
    - use that entry as tax percentage

    Can anyone help me out where I'm going wrong?

    Ajeh, please? Will send another big pack of donuts if we work this out. :)
    Last edited by balihr; 19 Jul 2011 at 02:46 PM. Reason: spelling error

  2. #2
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: custom tax order total little help please

    Do you need to know the master_categories_id of each Product in the cart?

    Or, do you need to know the parent category (Top Level Category) of the Product?
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today: v1.5.5]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  3. #3
    Join Date
    Oct 2008
    Location
    Croatia
    Posts
    1,542
    Plugin Contributions
    19

    Default Re: custom tax order total little help please

    Well, there's already a limit there so I can have only one category in cart. I can't add products from different categories.
    So, I'd need check the cart, see what product(s) is in, get the product's Top level category (if, for eg. cPath=11_36_54, I need 11). Then I need the query to select an entry from DB (which is already there for top level categories) and calculate the tax based on that entry. And it should all work with PayPal EC... :)

    I really really hope you can help, Ajeh, you're my last hope! Thank you!

  4. #4
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: custom tax order total little help please

    You can get a Products parent category with this function from the Admin ...

    You can copy this function in to an extra functions file such as:
    /includes/functions/extra_functions/my_sales_tax_functions.php
    Code:
    <?php
    ////
    // return products master_categories_id
    // TABLES: categories
      function zen_get_parent_category_id($product_id) {
        global $db;
    
        $categories_lookup = $db->Execute("select master_categories_id
                                    from " . TABLE_PRODUCTS . "
                                    where products_id = '" . (int)$product_id . "'");
    
        $parent_id = $categories_lookup->fields['master_categories_id'];
    
        return $parent_id;
      }
    Now you can just use it to get the parent category ...

    You function:
    function zen_get_sales_tax()

    is not returning any results ... so you are finding the
    $sales_tax_select->fields['sales_tax'

    but you are not returning it at the bottom of the function ...

    You are passing the $sales_tax to the function:
    Code:
    // calculate from flat fee or percentage
    				$sales_tax_defined = zen_get_sales_tax($sales_tax);
    but you did not define what $sales_tax is ... is that suppose to be a categories_id or products_id ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today: v1.5.5]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

 

 

Similar Threads

  1. Tax Order Total problems
    By champpower in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 1
    Last Post: 30 Oct 2010, 03:07 PM
  2. Order Total code guideline help please
    By hem in forum Contribution-Writing Guidelines
    Replies: 0
    Last Post: 27 May 2010, 01:18 PM
  3. Sub-total and total price are the same, please help!
    By albertvn in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 5 Jan 2010, 02:13 AM
  4. I want an order-total module to display total w/o tax
    By ivanc in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 4
    Last Post: 31 Oct 2009, 12:11 PM
  5. Apply GC INCREASES order total? - HELP please!
    By mcqueeneycoins in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 10
    Last Post: 21 Jul 2009, 11:10 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