Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Oct 2008
    Location
    Croatia
    Posts
    1,740
    Plugin Contributions
    22

    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

 

 

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

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