Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

fatel error


mods2003

Recommended Posts

hi

 

i was adding a contribution and delted some thing some where cant remeber what ive done (and no dam i didnt make a back up :blush: ) on all product pages im now getting the following error

 

Fatal error: Cannot redeclare tep_session_start() in /home/sites/site210/web/wightarts/shop/catalog/includes/functions/sessions.php on line 66

 

example link:

 

http://www.screen-art.co.uk/wightarts/shop...products_id/189

 

site wightarts.co.uk

 

any help would be great as im well stuck with this one

many thanks

 

dean

[email protected]

 

is o so simple to get it wrong!

Link to comment
Share on other sites

i have edited shoping_cart.php

 

i had added Actual_Attribute_Price_V1.2.2 - i have now removed that

i was adding another attributes mod (which i cant rember at the moment)

 

here is my shoping_cart.php file /includes/classes/

 

does this look right?

<?php
/*
 $Id: shopping_cart.php,v 1.35 2003/06/25 21:14:33 hpdl Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

 class shoppingCart {
   var $contents, $total, $weight, $cartID, $content_type;

   function shoppingCart() {
     $this->reset();
   }

   function restore_contents() {
     global $customer_id;

     if (!tep_session_is_registered('customer_id')) return false;

// insert current cart contents in database
     if (is_array($this->contents)) {
       reset($this->contents);
       while (list($products_id, ) = each($this->contents)) {
         $qty = $this->contents[$products_id]['qty'];
         $product_query = tep_db_query("select products_id from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
         if (!tep_db_num_rows($product_query)) {
           tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET . " (customers_id, products_id, customers_basket_quantity, customers_basket_date_added) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . $qty . "', '" . date('Ymd') . "')");
           if (isset($this->contents[$products_id]['attributes'])) {
             reset($this->contents[$products_id]['attributes']);
             while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
               tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . (int)$option . "', '" . (int)$value . "')");
             }
           }
         } else {
           tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . $qty . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
         }
       }
     }

// reset per-session cart contents, but not the database contents
     $this->reset(false);

     $products_query = tep_db_query("select products_id, customers_basket_quantity from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "'");
     while ($products = tep_db_fetch_array($products_query)) {
       $this->contents[$products['products_id']] = array('qty' => $products['customers_basket_quantity']);
// attributes
       $attributes_query = tep_db_query("select products_options_id, products_options_value_id from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products['products_id']) . "'");
       while ($attributes = tep_db_fetch_array($attributes_query)) {
         $this->contents[$products['products_id']]['attributes'][$attributes['products_options_id']] = $attributes['products_options_value_id'];
       }
     }

     $this->cleanup();
   }

   function reset($reset_database = false) {
     global $customer_id;

     $this->contents = array();
     $this->total = 0;
     $this->weight = 0;
     $this->content_type = false;

     if (tep_session_is_registered('customer_id') && ($reset_database == true)) {
       tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "'");
       tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "'");
     }

     unset($this->cartID);
     if (tep_session_is_registered('cartID')) tep_session_unregister('cartID');
   }

   function add_cart($products_id, $qty = '1', $attributes = '', $notify = true) {
     global $new_products_id_in_cart, $customer_id;

     $products_id = tep_get_uprid($products_id, $attributes);
     if ($notify == true) {
       $new_products_id_in_cart = $products_id;
       tep_session_register('new_products_id_in_cart');
     }

     if ($this->in_cart($products_id)) {
       $this->update_quantity($products_id, $qty, $attributes);
     } else {
       $this->contents[] = array($products_id);
       $this->contents[$products_id] = array('qty' => $qty);
// insert into database
       if (tep_session_is_registered('customer_id')) tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET . " (customers_id, products_id, customers_basket_quantity, customers_basket_date_added) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . $qty . "', '" . date('Ymd') . "')");

       if (is_array($attributes)) {
         reset($attributes);
         while (list($option, $value) = each($attributes)) {
           $this->contents[$products_id]['attributes'][$option] = $value;
// insert into database
           if (tep_session_is_registered('customer_id')) tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . (int)$option . "', '" . (int)$value . "')");
         }
       }
     }
     $this->cleanup();

// assign a temporary unique ID to the order contents to prevent hack attempts during the checkout procedure
     $this->cartID = $this->generate_cart_id();
   }

   function update_quantity($products_id, $quantity = '', $attributes = '') {
     global $customer_id;

     if (empty($quantity)) return true; // nothing needs to be updated if theres no quantity, so we return true..

     $this->contents[$products_id] = array('qty' => $quantity);
// update database
     if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . $quantity . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");

     if (is_array($attributes)) {
       reset($attributes);
       while (list($option, $value) = each($attributes)) {
         $this->contents[$products_id]['attributes'][$option] = $value;
// update database
         if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " set products_options_value_id = '" . (int)$value . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "' and products_options_id = '" . (int)$option . "'");
       }
     }
   }

   function cleanup() {
     global $customer_id;

     reset($this->contents);
     while (list($key,) = each($this->contents)) {
       if ($this->contents[$key]['qty'] < 1) {
         unset($this->contents[$key]);
// remove from database
         if (tep_session_is_registered('customer_id')) {
           tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($key) . "'");
           tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($key) . "'");
         }
       }
     }
   }

   function count_contents() {  // get total number of items in cart
     $total_items = 0;
     if (is_array($this->contents)) {
       reset($this->contents);
       while (list($products_id, ) = each($this->contents)) {
         $total_items += $this->get_quantity($products_id);
       }
     }

     return $total_items;
   }

   function get_quantity($products_id) {
     if (isset($this->contents[$products_id])) {
       return $this->contents[$products_id]['qty'];
     } else {
       return 0;
     }
   }

   function in_cart($products_id) {
     if (isset($this->contents[$products_id])) {
       return true;
     } else {
       return false;
     }
   }

   function remove($products_id) {
     global $customer_id;

     unset($this->contents[$products_id]);
// remove from database
     if (tep_session_is_registered('customer_id')) {
       tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
       tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
     }

// assign a temporary unique ID to the order contents to prevent hack attempts during the checkout procedure
     $this->cartID = $this->generate_cart_id();
   }

   function remove_all() {
     $this->reset();
   }

   function get_product_id_list() {
     $product_id_list = '';
     if (is_array($this->contents)) {
       reset($this->contents);
       while (list($products_id, ) = each($this->contents)) {
         $product_id_list .= ', ' . $products_id;
       }
     }

     return substr($product_id_list, 2);
   }

   function calculate() {
     $this->total = 0;
     $this->weight = 0;
     if (!is_array($this->contents)) return 0;

     reset($this->contents);
     while (list($products_id, ) = each($this->contents)) {
       $qty = $this->contents[$products_id]['qty'];

// products price
       $product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
       if ($product = tep_db_fetch_array($product_query)) {
         $prid = $product['products_id'];
         $products_tax = tep_get_tax_rate($product['products_tax_class_id']);
         $products_price = $product['products_price'];
         $products_weight = $product['products_weight'];

         $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");
         if (tep_db_num_rows ($specials_query)) {
           $specials = tep_db_fetch_array($specials_query);
           $products_price = $specials['specials_new_products_price'];
         }

    
         $this->total += tep_add_tax($products_price, $products_tax) * $qty;
         $this->weight += ($qty * $products_weight);
       }

// attributes price
       if ($this->contents[$products_id]['attributes']) {
         reset($this->contents[$products_id]['attributes']);
         while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
           $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . $prid . "' and options_id = '" . $option . "' and options_values_id = '" . $value . "'");
           $attribute_price = tep_db_fetch_array($attribute_price_query);
           if ($attribute_price['price_prefix'] == '+') {
             $this->total += $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);
           } else {
             $this->total -= $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);
           }
         }
       }
     }
   }

   function attributes_price($products_id) {
     if ($this->contents[$products_id]['attributes']) {
       reset($this->contents[$products_id]['attributes']);
       while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
         $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . $products_id . "' and options_id = '" . $option . "' and options_values_id = '" . $value . "'");
         $attribute_price = tep_db_fetch_array($attribute_price_query);
         if ($attribute_price['price_prefix'] == '+') {
           $attributes_price += $attribute_price['options_values_price'];
         } else {
           $attributes_price -= $attribute_price['options_values_price'];
         }
       }
     }

     return $attributes_price;
   } 

   function get_products() {
     global $languages_id;

     if (!is_array($this->contents)) return false;

     $products_array = array();
     reset($this->contents);
     while (list($products_id, ) = each($this->contents)) {
       $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
       if ($products = tep_db_fetch_array($products_query)) {
         $prid = $products['products_id'];
         $products_price = $products['products_price'];

         $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");
         if (tep_db_num_rows($specials_query)) {
           $specials = tep_db_fetch_array($specials_query);
           $products_price = $specials['specials_new_products_price'];
         }

         $products_array[] = array('id' => $products_id,
                                   'name' => $products['products_name'],
                                   'model' => $products['products_model'],
                                   'image' => $products['products_image'],
                                   'price' => $products_price,
                                   'quantity' => $this->contents[$products_id]['qty'],
                                   'weight' => $products['products_weight'],
                                   'final_price' => ($products_price + $this->attributes_price($products_id)),
                                   'tax_class_id' => $products['products_tax_class_id'],
                                   'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''));
       }
     }

     return $products_array;
   }

   function show_total() {
     $this->calculate();

     return $this->total;
   }

   function show_weight() {
     $this->calculate();

     return $this->weight;
   }

   function generate_cart_id($length = 5) {
     return tep_create_random_value($length, 'digits');
   }

   function get_content_type() {
     $this->content_type = false;

     if ( (DOWNLOAD_ENABLED == 'true') && ($this->count_contents() > 0) ) {
       reset($this->contents);
       while (list($products_id, ) = each($this->contents)) {
         if (isset($this->contents[$products_id]['attributes'])) {
           reset($this->contents[$products_id]['attributes']);
           while (list(, $value) = each($this->contents[$products_id]['attributes'])) {
             $virtual_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad where pa.products_id = '" . (int)$products_id . "' and pa.options_values_id = '" . (int)$value . "' and pa.products_attributes_id = pad.products_attributes_id");
             $virtual_check = tep_db_fetch_array($virtual_check_query);

             if ($virtual_check['total'] > 0) {
               switch ($this->content_type) {
                 case 'physical':
                   $this->content_type = 'mixed';

                   return $this->content_type;
                   break;
                 default:
                   $this->content_type = 'virtual';
                   break;
               }
             } else {
               switch ($this->content_type) {
                 case 'virtual':
                   $this->content_type = 'mixed';

                   return $this->content_type;
                   break;
                 default:
                   $this->content_type = 'physical';
                   break;
               }
             }
           }
         } else {
           switch ($this->content_type) {
             case 'virtual':
               $this->content_type = 'mixed';

               return $this->content_type;
               break;
             default:
               $this->content_type = 'physical';
               break;
           }
         }
       }
     } else {
       $this->content_type = 'physical';
     }

     return $this->content_type;
   }

   function unserialize($broken) {
     for(reset($broken);$kv=each($broken);) {
       $key=$kv['key'];
       if (gettype($this->$key)!="user function")
       $this->$key=$kv['value'];
     }
   }

 }
?>

 

other edited file

general.php . in /includes/functions/

 

<?php

/*

 $Id: general.php,v 1.212 2003/02/17 07:55:54 hpdl Exp $

 

 osCommerce, Open Source E-Commerce Solutions

 http://www.oscommerce.com

 

 Copyright (c) 2003 osCommerce

 

 Released under the GNU General Public License

*/

 

////

// Stop from parsing any further PHP code

 function tep_exit() {

  tep_session_close();

  exit();

 }

 

////

// Redirect to another page or site

 function tep_redirect($url) {

   if ( (ENABLE_SSL == true) && (getenv('HTTPS') == 'on') ) { // We are loading an SSL page

     if (substr($url, 0, strlen(HTTP_SERVER)) == HTTP_SERVER) { // NONSSL url

       $url = HTTPS_SERVER . substr($url, strlen(HTTP_SERVER)); // Change it to SSL

     }

   }

 

   header('Location: ' . $url);

 

   tep_exit();

 }

 

////

// Error message wrapper

// When optional parameters are provided, it closes the application

// (ie, halts the current application execution task)

 function tep_error_message($error_message, $close_application = false, $close_application_error = '') {

   echo $error_message;

 

   if ($close_application == true) {

     die($close_application_error);

   }

 }

 

////

// Return a random row from a database query

 function tep_random_select($query) {

   $random_product = '';

   $random_query = tep_db_query($query);

   $num_rows = tep_db_num_rows($random_query);

   if ($num_rows > 0) {

     $random_row = tep_rand(0, ($num_rows - 1));

     tep_db_data_seek($random_query, $random_row);

     $random_product = tep_db_fetch_array($random_query);

   }

 

   return $random_product;

 }

 

////

// Return a product's name

// TABLES: products

 function tep_get_products_name($product_id, $language = '') {

   global $languages_id;

 

   if (empty($language)) $language = $languages_id;

 

   $product_query = tep_db_query("select products_name from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . $product_id . "' and language_id = '" . $language . "'");

   $product = tep_db_fetch_array($product_query);

 

   return $product['products_name'];

 }

 

////

// Return a product's special price (returns nothing if there is no offer)

// TABLES: products

 function tep_get_products_special_price($product_id) {

   $product_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . $product_id . "' and status");

   $product = tep_db_fetch_array($product_query);

 

   return $product['specials_new_products_price'];

 }

 

////

// Return a product's stock

// TABLES: products

 function tep_get_products_stock($products_id) {

   $products_id = tep_get_prid($products_id);

   $stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . $products_id . "'");

   $stock_values = tep_db_fetch_array($stock_query);

 

   return $stock_values['products_quantity'];

 }

 

////

// Check if the required stock is available

// If insufficent stock is available return an out of stock message

 function tep_check_stock($products_id, $products_quantity) {

   $stock_left = tep_get_products_stock($products_id) - $products_quantity;

   $out_of_stock = '';

 

   if ($stock_left < 0) {

     $out_of_stock = '<span class="markProductOutOfStock">' . STOCK_MARK_PRODUCT_OUT_OF_STOCK . '</span>';

   }

 

   return $out_of_stock;

 }

 

////

// Break a word in a string if it is longer than a specified length ($len)

 function tep_break_string($string, $len, $break_char = '-') {

   $l = 0;

   $output = '';

   for ($i=0, $n=strlen($string); $i<$n; $i++) {

     $char = substr($string, $i, 1);

     if ($char != ' ') {

       $l++;

     } else {

       $l = 0;

     }

     if ($l > $len) {

       $l = 1;

       $output .= $break_char;

     }

     $output .= $char;

   }

 

   return $output;

 }

 

////

// Return all HTTP GET variables, except those passed as a parameter

 function tep_get_all_get_params($exclude_array = '') {

   global $HTTP_GET_VARS;

 

   if (!is_array($exclude_array)) $exclude_array = array();

 

   $get_url = '';

   if (is_array($HTTP_GET_VARS) && (sizeof($HTTP_GET_VARS) > 0)) {

     reset($HTTP_GET_VARS);

     while (list($key, $value) = each($HTTP_GET_VARS)) {

       if ( (strlen($value) > 0) && ($key != tep_session_name()) && ($key != 'error') && (!in_array($key, $exclude_array)) && ($key != 'x') && ($key != 'y') ) {

         $get_url .= $key . '=' . rawurlencode(stripslashes($value)) . '&';

       }

     }

   }

 

   return $get_url;

 }

 

////

// Returns an array with countries

// TABLES: countries

 function tep_get_countries($countries_id = '', $with_iso_codes = false) {

   $countries_array = array();

   if (tep_not_null($countries_id)) {

     if ($with_iso_codes == true) {

       $countries = tep_db_query("select countries_name, countries_iso_code_2, countries_iso_code_3 from " . TABLE_COUNTRIES . " where countries_id = '" . $countries_id . "' order by countries_name");

       $countries_values = tep_db_fetch_array($countries);

       $countries_array = array('countries_name' => $countries_values['countries_name'],

                                'countries_iso_code_2' => $countries_values['countries_iso_code_2'],

                                'countries_iso_code_3' => $countries_values['countries_iso_code_3']);

     } else {

       $countries = tep_db_query("select countries_name from " . TABLE_COUNTRIES . " where countries_id = '" . $countries_id . "'");

       $countries_values = tep_db_fetch_array($countries);

       $countries_array = array('countries_name' => $countries_values['countries_name']);

     }

   } else {

     $countries = tep_db_query("select countries_id, countries_name from " . TABLE_COUNTRIES . " order by countries_name");

     while ($countries_values = tep_db_fetch_array($countries)) {

       $countries_array[] = array('countries_id' => $countries_values['countries_id'],

                                  'countries_name' => $countries_values['countries_name']);

     }

   }

 

   return $countries_array;

 }

 

////

// Alias function to tep_get_countries, which also returns the countries iso codes

 function tep_get_countries_with_iso_codes($countries_id) {

   return tep_get_countries($countries_id, true);

 }

 

////

// Generate a path to categories

 function tep_get_path($current_category_id = '') {

   global $cPath_array;

 

   if (tep_not_null($current_category_id)) {

     $cp_size = sizeof($cPath_array);

     if ($cp_size == 0) {

       $cPath_new = $current_category_id;

     } else {

       $cPath_new = '';

       $last_category_query = tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where categories_id = '" . $cPath_array[($cp_size-1)] . "'");

       $last_category = tep_db_fetch_array($last_category_query);

 

       $current_category_query = tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where categories_id = '" . $current_category_id . "'");

       $current_category = tep_db_fetch_array($current_category_query);

 

       if ($last_category['parent_id'] == $current_category['parent_id']) {

         for ($i=0; $i<($cp_size-1); $i++) {

           $cPath_new .= '_' . $cPath_array[$i];

         }

       } else {

         for ($i=0; $i<$cp_size; $i++) {

           $cPath_new .= '_' . $cPath_array[$i];

         }

       }

       $cPath_new .= '_' . $current_category_id;

 

       if (substr($cPath_new, 0, 1) == '_') {

         $cPath_new = substr($cPath_new, 1);

       }

     }

   } else {

     $cPath_new = implode('_', $cPath_array);

   }

 

   return 'cPath=' . $cPath_new;

 }

 

////

// Returns the clients browser

 function tep_browser_detect($component) {

   global $HTTP_USER_AGENT;

 

   return stristr($HTTP_USER_AGENT, $component);

 }

 

////

// Alias function to tep_get_countries()

 function tep_get_country_name($country_id) {

   $country_array = tep_get_countries($country_id);

 

   return $country_array['countries_name'];

 }

 

////

// Returns the zone (State/Province) name

// TABLES: zones

 function tep_get_zone_name($country_id, $zone_id, $default_zone) {

   $zone_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . $country_id . "' and zone_id = '" . $zone_id . "'");

   if (tep_db_num_rows($zone_query)) {

     $zone = tep_db_fetch_array($zone_query);

     return $zone['zone_name'];

   } else {

     return $default_zone;

   }

 }

 

////

// Returns the zone (State/Province) code

// TABLES: zones

 function tep_get_zone_code($country_id, $zone_id, $default_zone) {

   $zone_query = tep_db_query("select zone_code from " . TABLE_ZONES . " where zone_country_id = '" . $country_id . "' and zone_id = '" . $zone_id . "'");

   if (tep_db_num_rows($zone_query)) {

     $zone = tep_db_fetch_array($zone_query);

     return $zone['zone_code'];

   } else {

     return $default_zone;

   }

 }

 

////

// Wrapper function for round() for php3 compatibility

 function tep_round($value, $precision) {

   if (PHP_VERSION < 4) {

     $exp = pow(10, $precision);

     return round($value * $exp) / $exp;

   } else {

     return round($value, $precision);

   }

 }

 

////

// Returns the tax rate for a zone / class

// TABLES: tax_rates, zones_to_geo_zones

 function tep_get_tax_rate($class_id, $country_id = -1, $zone_id = -1) {

   global $customer_zone_id, $customer_country_id;

 

   if ( ($country_id == -1) && ($zone_id == -1) ) {

     if (!tep_session_is_registered('customer_id')) {

       $country_id = STORE_COUNTRY;

       $zone_id = STORE_ZONE;

     } else {

       $country_id = $customer_country_id;

       $zone_id = $customer_zone_id;

     }

   }

 

   $tax_query = tep_db_query("select sum(tax_rate) as tax_rate from " . TABLE_TAX_RATES . " tr left join " . TABLE_ZONES_TO_GEO_ZONES . " za on (tr.tax_zone_id = za.geo_zone_id) left join " . TABLE_GEO_ZONES . " tz on (tz.geo_zone_id = tr.tax_zone_id) where (za.zone_country_id is null or za.zone_country_id = '0' or za.zone_country_id = '" . $country_id . "') and (za.zone_id is null or za.zone_id = '0' or za.zone_id = '" . $zone_id . "') and tr.tax_class_id = '" . $class_id . "' group by tr.tax_priority");

   if (tep_db_num_rows($tax_query)) {

     $tax_multiplier = 0;

     while ($tax = tep_db_fetch_array($tax_query)) {

       $tax_multiplier += $tax['tax_rate'];

     }

     return $tax_multiplier;

   } else {

     return 0;

   }

 }

 

////

// Return the tax description for a zone / class

// TABLES: tax_rates;

 function tep_get_tax_description($class_id, $country_id, $zone_id) {

   $tax_query = tep_db_query("select tax_description from " . TABLE_TAX_RATES . " tr left join " . TABLE_ZONES_TO_GEO_ZONES . " za on (tr.tax_zone_id = za.geo_zone_id) left join " . TABLE_GEO_ZONES . " tz on (tz.geo_zone_id = tr.tax_zone_id) where (za.zone_country_id is null or za.zone_country_id = '0' or za.zone_country_id = '" . $country_id . "') and (za.zone_id is null or za.zone_id = '0' or za.zone_id = '" . $zone_id . "') and tr.tax_class_id = '" . $class_id . "' order by tr.tax_priority");

   if (tep_db_num_rows($tax_query)) {

     $tax_description = '';

     while ($tax = tep_db_fetch_array($tax_query)) {

       $tax_description .= $tax['tax_description'] . ' + ';

     }

     $tax_description = substr($tax_description, 0, -3);

 

     return $tax_description;

   } else {

     return TEXT_UNKNOWN_TAX_RATE;

   }

 }

 

/////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////

// BOF AAP V1.2.1

// actual attribute price adjustment (used with no price prefix only)

//  function tep_adjust_price($attribute, $price) {

//    global $currencies;

//

//    $adjustment = ($attribute-$price);

//   return $adjustment;

//    }

//EOF AAP V1.2.1

/////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////

 

 

////

// Add tax to a products price

 function tep_add_tax($price, $tax) {

   global $currencies;

 

   if ( (DISPLAY_PRICE_WITH_TAX == 'true') && ($tax > 0) ) {

     return tep_round($price, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']) + tep_calculate_tax($price, $tax);

   } else {

     return tep_round($price, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);

   }

 }

 

// Calculates Tax rounding the result

 function tep_calculate_tax($price, $tax) {

   global $currencies;

 

   return tep_round($price * $tax / 100, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);

 }

 

////

// Return the number of products in a category

// TABLES: products, products_to_categories, categories

 function tep_count_products_in_category($category_id, $include_inactive = false) {

   $products_count = 0;

   if ($include_inactive == true) {

     $products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id and p2c.categories_id = '" . $category_id . "'");

   } else {

     $products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id and p.products_status = '1' and p2c.categories_id = '" . $category_id . "'");

   }

   $products = tep_db_fetch_array($products_query);

   $products_count += $products['total'];

 

   $child_categories_query = tep_db_query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . $category_id . "'");

   if (tep_db_num_rows($child_categories_query)) {

     while ($child_categories = tep_db_fetch_array($child_categories_query)) {

       $products_count += tep_count_products_in_category($child_categories['categories_id'], $include_inactive);

     }

   }

 

   return $products_count;

 }

 

////

// Return true if the category has subcategories

// TABLES: categories

 function tep_has_category_subcategories($category_id) {

   $child_category_query = tep_db_query("select count(*) as count from " . TABLE_CATEGORIES . " where parent_id = '" . $category_id . "'");

   $child_category = tep_db_fetch_array($child_category_query);

 

   if ($child_category['count'] > 0) {

     return true;

   } else {

     return false;

   }

 }

 

////

// Returns the address_format_id for the given country

// TABLES: countries;

 function tep_get_address_format_id($country_id) {

   $address_format_query = tep_db_query("select address_format_id as format_id from " . TABLE_COUNTRIES . " where countries_id = '" . $country_id . "'");

   if (tep_db_num_rows($address_format_query)) {

     $address_format = tep_db_fetch_array($address_format_query);

     return $address_format['format_id'];

   } else {

     return '1';

   }

 }

 

////

// Return a formatted address

// TABLES: address_format

 function tep_address_format($address_format_id, $address, $html, $boln, $eoln) {

   $address_format_query = tep_db_query("select address_format as format from " . TABLE_ADDRESS_FORMAT . " where address_format_id = '" . $address_format_id . "'");

   $address_format = tep_db_fetch_array($address_format_query);

 

   $company = addslashes($address['company']);

   $firstname = addslashes($address['firstname']);

   $lastname = addslashes($address['lastname']);

   $street = addslashes($address['street_address']);

   $suburb = addslashes($address['suburb']);

   $city = addslashes($address['city']);

   $state = addslashes($address['state']);

   $country_id = $address['country_id'];

   $zone_id = $address['zone_id'];

   $postcode = addslashes($address['postcode']);

   $zip = $postcode;

   $country = tep_get_country_name($country_id);

   $state = tep_get_zone_code($country_id, $zone_id, $state);

 

   if ($html) {

// HTML Mode

     $HR = '<hr>';

     $hr = '<hr>';

     if ( ($boln == '') && ($eoln == "\n") ) { // Values not specified, use rational defaults

       $CR = '<br>';

       $cr = '<br>';

       $eoln = $cr;

     } else { // Use values supplied

       $CR = $eoln . $boln;

       $cr = $CR;

     }

   } else {

// Text Mode

     $CR = $eoln;

     $cr = $CR;

     $HR = '----------------------------------------';

     $hr = '----------------------------------------';

   }

 

   $statecomma = '';

   $streets = $street;

   if ($suburb != '') $streets = $street . $cr . $suburb;

   if ($firstname == '') $firstname = addslashes($address['name']);

   if ($country == '') $country = addslashes($address['country']);

   if ($state != '') $statecomma = $state . ', ';

 

   $fmt = $address_format['format'];

   eval("\$address = \"$fmt\";");

   $address = stripslashes($address);

 

   if ( (ACCOUNT_COMPANY == 'true') && (tep_not_null($company)) ) {

     $address = $company . $cr . $address;

   }

 

   return $boln . $address . $eoln;

 }

 

////

// Return a formatted address

// TABLES: customers, address_book

 function tep_address_label($customers_id, $address_id = 1, $html = false, $boln = '', $eoln = "\n") {

   $address_query = tep_db_query("select entry_firstname as firstname, entry_lastname as lastname, entry_company as company, entry_street_address as street_address, entry_suburb as suburb, entry_city as city, entry_postcode as postcode, entry_state as state, entry_zone_id as zone_id, entry_country_id as country_id from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . $customers_id . "' and address_book_id = '" . $address_id . "'");

   $address = tep_db_fetch_array($address_query);

 

   $format_id = tep_get_address_format_id($address['country_id']);

 

   return tep_address_format($format_id, $address, $html, $boln, $eoln);

 }

 

////

// Return a formatted address

// TABLES: address_book, address_format

 function tep_address_summary($customers_id, $address_id) {

   $customers_id = tep_db_prepare_input($customers_id);

   $address_id = tep_db_prepare_input($address_id);

 

   $address_query = tep_db_query("select ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_state, ab.entry_country_id, ab.entry_zone_id, c.countries_name, c.address_format_id from " . TABLE_ADDRESS_BOOK . " ab, " . TABLE_COUNTRIES . " c where ab.address_book_id = '" . tep_db_input($address_id) . "' and ab.customers_id = '" . tep_db_input($customers_id) . "' and ab.entry_country_id = c.countries_id");

   $address = tep_db_fetch_array($address_query);

 

   $street_address = $address['entry_street_address'];

   $suburb = $address['entry_suburb'];

   $postcode = $address['entry_postcode'];

   $city = $address['entry_city'];

   $state = tep_get_zone_code($address['entry_country_id'], $address['entry_zone_id'], $address['entry_state']);

   $country = $address['countries_name'];

 

   $address_format_query = tep_db_query("select address_summary from " . TABLE_ADDRESS_FORMAT . " where address_format_id = '" . $address['address_format_id'] . "'");

   $address_format = tep_db_fetch_array($address_format_query);

 

//    eval("\$address =

[email protected]

 

is o so simple to get it wrong!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...