Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

I really need your help - tep_get_cat_path()


Herr_Schmidt

Recommended Posts

I read anything on the forum and on the web concerning

 

tep_get_cat_path()

 

but i can't get rid of this error. If I change an order in the order editor e.g. the amount of an article i get this error of:

 

Call to undefined function tep_get_cat_path() in /includes/modules/order_total/ot_cat_qvb_discount.php

 

I honestly do not have a clue what could solve this problem. It would be very very kind of you if you could help me with this!

 

kind regards

 

Herr Schmidt

Link to comment
Share on other sites

Your are right - but i already googled this corrections, implemented them - that is why i started this thread.

 

Problem still there!

 

kind regards

 

Herr Schmidt

 

<?php
 class ot_cat_qvb_discount {
var $title, $output, $discounts, $deduction, $tax_amount;


function tep_get_category_name($category_id, $languages_id) {
$category_query = tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . (int)$category_id . "' and language_id = '" . (int)$languages_id . "'");
$category = tep_db_fetch_array($category_query);
return $category['categories_name'];
}

function category_discount_display ($current_category_id) {
global $category, $currencies, $languages_id;

$cat_disc_message = '';

}






function tep_get_cat_path ($current_category_id = '') {
$last_category_query = tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where categories_id = '" . $current_category_id . "'");
$last_category = tep_db_fetch_array($last_category_query);
if ($last_category['parent_id'] != 0) {
$cat_string = $last_category['parent_id'] . '_' . $current_category_id;
while ($last_category['parent_id'] != 0) {
$last_category_query = tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where categories_id = '" . $last_category['parent_id'] . "'");
$last_category = tep_db_fetch_array($last_category_query);
$cat_string .= $last_category['parent_id'] . '_' . $cat_string;
}
return $cat_string;
} else {
return $current_category_id;
}
}


function ot_cat_qvb_discount() {
  $this->code = 'ot_cat_qvb_discount';
  $this->title = MODULE_CAT_QVB_DISCOUNT_TITLE;
  $this->description = MODULE_CAT_QVB_DISCOUNT_DESCRIPTION;
  $this->enabled = ((MODULE_CAT_QVB_DISCOUNT_STATUS == 'true') ? true : false);
  $this->sort_order = MODULE_CAT_QVB_DISCOUNT_SORT_ORDER;
  $this->output = array();
  $this->discounts = array();
}

function process() {
  global $order, $ot_subtotal;

  $this->deduction = 0;				  // no deductions yet
  $this->tax_amount = 0;				 // no deductions yet
  $this->fill_category_discount_array(); // fill the discount definitions
  $this->add_cart_info();				// add the cart information
  $this->set_breaks();				   // determine the break index
  $this->process_discounts();			// set the discounts
  $order->info['total'] -= $this->deduction;
  //$order->info['tax'] -= $this->tax_amount;
  //if ($this->sort_order < $ot_subtotal->sort_order) $order->info['subtotal'] -= $this->deduction;
  $order->info['subtotal'] -= $this->deduction;

  $tod_amount = $order->info['subtotal'] / 1.19;
  $order->info['tax'] = $order->info['subtotal']-$tod_amount;

  reset($order->info['tax_groups']);
  while (list($key, $value) = each($order->info['tax_groups'])) {
$tod_amount = $order->info['subtotal'] / 1.19;
	$order->info['tax_groups'][$key] = $order->info['subtotal']-$tod_amount;
  }
}

function calculate_credit() {
  global $order, $ot_subtotal;

  $this->deduction = 0;				  // no deductions yet
  $this->tax_amount = 0;				 // no deductions yet
  $this->fill_category_discount_array(); // fill the discount definitions
  $this->add_cart_info();				// add the cart information
  $this->set_breaks();				   // determine the break index
  $this->process_discounts();			// set the discounts

  return $this->deduction;

  //$order->info['total'] -= $this->deduction;
  //$order->info['tax'] -= $this->tax_amount;
  //if ($this->sort_order < $ot_subtotal->sort_order) $order->info['subtotal'] -= $this->deduction;
}

// fill the discount information table
function fill_category_discount_array () {
 global $cart;

 $category_discount_definitions = split(',',MODULE_CAT_QVB_DISCOUNT_RATES);
 $n = sizeof($category_discount_definitions);
 for ($c = 0; $c < $n; $c++) {
$category_discount_parts = split(':',$category_discount_definitions[$c]);
$this->discounts[$c]['category'] = $category_discount_parts[0];
$this->discounts[$c]['dc_type']  = $category_discount_parts[1];
$this->discounts[$c]['th_type']  = $category_discount_parts[2];
$this->discounts[$c]['cart']	 = 0;
$this->discounts[$c]['value']	= 0;
$this->discounts[$c]['tax']	  = 0;
$this->discounts[$c]['index']	= -1;
$breaks = split(';', $category_discount_parts[3]);
$m = sizeof($breaks);
$index = 0;
for ($b = 0; $b < $m; $b+=2) {
  $this->discounts[$c]['breaks'][$index]['threshold'] = $breaks[$b];
  $this->discounts[$c]['breaks'][$index]['amount']	= $breaks[$b+1];
  $index++;
}
 }
}

// add the cart information
function add_cart_info () {
 global $cart;

 $products = $cart->get_products();
 $pn = sizeof($products);
 for ($p=0; $p<$pn; $p++) {
$t_prid = tep_get_prid($products[$p]['id']);
$products_tax = tep_get_tax_rate($products[$p]['tax_class_id']);
$cat_query = tep_db_query("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $t_prid . "'");
$cat_result = tep_db_fetch_array($cat_query); 
$n = sizeof($this->discounts);
for ($i=0; $i<$n; $i++) {
  if ($this->cat_under_cat($this->discounts[$i]['category'],$cat_result['categories_id'])) {
	$this->discounts[$i]['cart'] = $this->discounts[$i]['cart'] + $cart->get_quantity($products[$p]['id']);
	$this->discounts[$i]['value'] = $this->discounts[$i]['value'] + ($products[$p]['price']+$products_tax)*$cart->get_quantity($products[$p]['id']);
	$this->discounts[$i]['tax'] = $this->discounts[$i]['tax'] + ($products[$p]['price']*$products_tax/100);
	$this->tax_amount = $this->tax_amount + $this->discounts[$i]['tax'];
  }
}
 }
}

// determine the break index based on category quantity or value
function set_breaks () {

 $n = sizeof($this->discounts);
 for ($x=0; $x<$n; $x++) {
if ($this->discounts[$x]['th_type']  == 'Q') { // quantity or value
  $this->discounts[$x]['index'] = $this->determine_break_index($this->discounts[$x]['cart'], $this->discounts[$x]['breaks']); // break on quantity
} else {
  $this->discounts[$x]['index'] = $this->determine_break_index($this->discounts[$x]['value'], $this->discounts[$x]['breaks']); // break on value
}
 }
}

function determine_break_index ($amount, $breaks) {
$break_index = -1;
$n = sizeof($breaks);
 for ($b=0; $b<$n; $b++) {
  if ($amount >= $breaks[$b]['threshold']) $break_index = $b;
 }
 return $break_index;
}


function process_discounts () {

 $n = sizeof($this->discounts);
 for ($x=0; $x<$n; $x++) {
if ($this->discounts[$x]['index'] > -1) { // break found
	$this->set_discounts($this->discounts[$x]['category'], $this->discounts[$x]['dc_type'], $this->discounts[$x]['th_type'], $this->discounts[$x]['cart'], $this->discounts[$x]['value'], $this->discounts[$x]['breaks'][$this->discounts[$x]['index']]['threshold'], $this->discounts[$x]['breaks'][$this->discounts[$x]['index']]['amount']);
}
 }
}

// set the discount output based on type
function set_discounts ($category, $dc_type, $th_type, $cart_amount, $value, $threshold, $discount_amount) {
 global $currencies;

 if ($th_type != 'Q') $cart_amount = $currencies->format($value);
 $this->output[] = array('title' => $this->discount_message($category, $dc_type, $th_type, $threshold, $discount_amount),
					  'text' =>  sprintf(MODULE_CAT_QVB_DISCOUNT_FORMATED_TEXT, $currencies->format($this->discount_amount($dc_type, $th_type, $cart_amount, $value, $threshold, $discount_amount))),
					  'value' => $this->discount_amount($dc_type, $th_type, $cart_amount, $value, $threshold, $discount_amount));
 $this->deduction = $this->deduction + $this->discount_amount($dc_type, $th_type, $cart_amount, $value, $threshold, $discount_amount);
}

function discount_message ($category, $dc_type, $th_type, $threshold, $discount_amount) {
 global $currencies;

 if ($th_type != 'Q') $threshold = 'for ' . $currencies->format($threshold);
 switch($dc_type) {
case 'MS' : $message = CAT_QVB_DISC_MSG_MS;break;
case 'MM' : $message = CAT_QVB_DISC_MSG_MM;break;
case 'ME' : $message = CAT_QVB_DISC_MSG_ME;break;
case 'IM' : $message = CAT_QVB_DISC_MSG_IM;break;
case 'PE' : $message = CAT_QVB_DISC_MSG_PE;break;
 }
 return $message;
}

function discount_amount ($dc_type, $th_type, $cart_amount, $value, $threshold, $discount_amount) {

 if ($th_type != 'Q') $cart_amount = $value;
 switch($dc_type) {
case 'MS' : $od_amount = $discount_amount;break;
case 'MM' : $od_amount = $discount = floor(($cart_amount / $threshold)) *  $discount_amount;break;
case 'ME' : $od_amount = $cart_amount * $discount_amount;break;
case 'IM' : $od_amount = floor(($cart_amount / $threshold)) * ($value/$cart_amount) * $discount_amount;break;
case 'PE' : $od_amount = ($value * $discount_amount / 100);break;
 }
 return $od_amount;
}


function cat_name ($cat_id) {
 global $languages_id;

 $cat_query = tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . "  
						 where categories_id = '".$cat_id."' 
						   and language_id = '" . (int)$languages_id . "'");
 $cat = tep_db_fetch_array($cat_query);
 return $cat['categories_name'];
}










function cat_under_cat ($cat1, $cat2) {
$cat_path = tep_get_cat_path($cat2);
$cat_path_array = split("_" , $cat_path);
if (in_array ($cat1,$cat_path_array)) {
  return true;
} else {
  return false;
}
}


// returns all breaks for the category if present
function breaks ($catid) {

 $this->fill_category_discount_array();
 $n = sizeof($this->discounts);
 for ($c=0; $c<$n; $c++) {
if ($this->cat_under_cat($this->discounts[$c]['category'],$catid)) {
  return $this->discounts[$c]['breaks'];
}
 }
}

function teaser ($catid, $multiple = true, $all = true) {

 $teaser = '';
 $this->fill_category_discount_array();
 $this->add_cart_info();
 $this->set_breaks();
 $n = sizeof($this->discounts);
 for ($c=0; $c<$n; $c++) {
if ($this->cat_under_cat($this->discounts[$c]['category'],$catid)) {
  $bn = sizeof($this->discounts[$c]['breaks']);
  // what teasers to show, all (including already qualified) or just all next or just 1 next
  if ($all) { // show all breaks
	 $bg = 0;
  } else { // start by showing the next
	 $bg = $this->discounts[$c]['index']+1;
  }
  if ($multiple) { // show all breaks
	$bl = $bn;
  } else {  // show only the next break
	$bl = $this->discounts[$c]['index']+2;
  }
  for ($b=$bg; $b<$bl; $b++) {
	$teaser .= $this->discount_message($catid, $this->discounts[$c]['dc_type'],$this->discounts[$c]['th_type'],$this->discounts[$c]['breaks'][$b]['threshold'],$this->discounts[$c]['breaks'][$b]['amount']).'<br>';
  }
}
 }
 if ($teaser !='') {
 return 
 '<tr>
<td>'.tep_draw_separator('pixel_trans.gif', '100%', '5').'</td>
  </tr>
  <tr>
<td>
 <table width=100% class="borderGray" cellpadding="4">
  <tr>
   <td class="discountHead" nowrap>'.$this->cat_name($catid).' Offer</td>
   <td align="center" width="100%" class="discountMain" bgcolor="#ffffe0">'.$teaser.'</td>
  </tr>
 </table>
</td>
  </tr>
  <tr>
<td>'.tep_draw_separator('pixel_trans.gif', '100%', '5').'</td>
  </tr>';
  } else {
 return '';
  }
}

// display the discounts in the cart
function display_discounts () {

 $this->fill_category_discount_array(); // fill the discount definitions
 $this->add_cart_info();				// add the cart information
 $this->set_breaks();				   // determine the break index
 $this->process_discounts();			// set the discounts
 $n = sizeof($this->output);
 for ($x=0; $x<$n; $x++) {
echo '<tr><td align="right">'.$this->output[$x]['title'].'</td><td align="right">'.$this->output[$x]['text'].'</td></tr>';
 }
 return $this->deduction;
}


function check() {
  if (!isset($this->check)) {
	$check_query = tep_db_query("select configuration_value 
								 from " . TABLE_CONFIGURATION . " 
								 where configuration_key = 'MODULE_CAT_QVB_DISCOUNT_STATUS'");
	$this->check = mysql_num_rows($check_query);
  }

  return $this->check;
}

function keys() {
  return array('MODULE_CAT_QVB_DISCOUNT_STATUS', 'MODULE_CAT_QVB_DISCOUNT_SORT_ORDER', 'MODULE_CAT_QVB_DISCOUNT_RATES');
}

function install() {
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values 
('Activate Category Quantity Discount', 'MODULE_CAT_QVB_DISCOUNT_STATUS', 'true', 'Do you want to enable the category quantity discount module?', '6', '1','tep_cfg_select_option(array(\'true\', \'false\'), ', now())");
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values 
('Sort Order', 'MODULE_CAT_QVB_DISCOUNT_SORT_ORDER', '2', 'Sort order of display.', '6', '2', now())");
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values 
('Discount Rates', 'MODULE_CAT_QVB_DISCOUNT_RATES', '21:MS:Q:1;200;2;400;3;500,28:MM:Q:1;10;3;20,206:MS:Q:1;200;2;400;3;500;4;600;5;700;5;800,93:IM:Q:10;1,102:IM:Q:10;2,207:MS:V:1400;100;2800;200', 'The discount is based on the number of items in the same category tree or their value.', '6', '5', now())");
}

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

?>

 

Result:

 

Call to undefined function tep_get_cat_path() in /home/cs/www/typo3conf/ext/meta_oscommerce/mod1/oscommerce/includes/modules/order_total/ot_cat_qvb_discount.php on line 233

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...