Jump to content
Sign in to follow this  
boxtel

Category Discount

Recommended Posts

Hi Amanda!

 

I am so happy that your contrib. now handles products with attributes as per post #53. I would like to try and take it another step and have the discount apply to products whos attributes do not change the product price.

 

In my store we sell photos that are matted and framed. Our standard product is a matted photo for $18.00.

 

You may choose to have it framed for $17.00 additional.

 

OR

 

You may choose to order the photo only (without mats) for $5.95.

 

There are other options but they are a matter of mat color and do not change the price.

 

In these two examples the options will change the original product price... My category discount will give a $3.00 discount on each photo if more than one photo is ordered. So, if two photos are ordered for $5.95 the new price is $2.95, that's not ok!

 

So what I'm trying to do is have the module not apply the discount if the original product price has changed. What I don't know is, where to apply the IF statement. Can it be added to the catalog/includes/module/order_total/ot_cat_qty_dicount.php?

 

Anyway, I can't get it to work yet but I will continue to work it out, please feel free to post any suggestions.

 

Thank you

 

well, the catalog/includes/module/order_total/ot_cat_qty_discount.php is pretty straightforward.

 

the module structure is in 3 parts:

 

1) fill the table with the discount info from admin

2) add the applicable cart quantities and values based on those conditions

3) calculate the discounts based on the the resulting table

 

1 and 2 is done by function function fill_discount_array()

 

the items quantity and value from the cart are added if it is determined that that item resides in the category tree of the category id in your conditions.

 

if (in_array ($cat_qty_discount_array[$i]["cat"],$cat_path_array)) {

 

so if you would like to exclude items based on additional conditions, simply add those conditions to that of structure and those items are not added to the table and not included in the subsequent discount calculation.

 

like :

 

if (in_array ($cat_qty_discount_array[$i]["cat"],$cat_path_array)) { // item resides in the category tree

if (other condition which has to apply) {

$cat_qty_discount_array[$i]["cqty"] = $cat_qty_discount_array[$i]["cqty"] + $cart->get_quantity($t_prid); // increase item quantity

$cat_qty_discount_array[$i]["price"] = $cat_qty_discount_array[$i]["price"] + $products[$p]['price']*$cart->get_quantity($products[$p]['id']); // increase value

$cart_items_in_discount++; // increase count

}

}

 

 

you could for instance do a compare between the normal products price and the price in the cart and if they are different then obviously the attributes have changed it.

(assuming you do not have other discounts like member discount installed as that one also changes the products price in the cart)


Treasurer MFC

Share this post


Link to post
Share on other sites
added this function to the ot class:

 

function display_discounts () {

global $currencies, $cat_qty_discount_array;

 

$cat_qty_discount_array = $this->fill_discount_array($cat_qty_discount_array);

$this->calculate_discount($cat_qty_discount_array);

$n = sizeof($this->discounts);

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

$tod_amount = 0;

$od_amount = $this->discounts[$i]['discount'];

echo '<tr><td align="right">'.MODULE_CAT_QTY_DISCOUNT_FORMATED_TITLE. ' - ' .$this->discounts[$i]['text'].':</td><td align="right">'. sprintf(MODULE_CAT_QTY_DISCOUNT_FORMATED_TEXT,$currencies->format($this->discounts[$i]['discount'])).'</td></tr>';

if ($this->calculate_tax == 'true') $tod_amount = $this->calculate_tax_effect($od_amount);

$this->deduction += $od_amount+$tod_amount;

}

return $this->deduction;

}

added this to shopping cart.php:

 

right after :

 

<td align="right" width="85%"><?php echo SUB_TITLE_SUB_TOTAL; ?></td><td align="right">

<?php echo $currencies->format($cart->show_total()); ?>

</td>

</tr>

 

add this :

<?php

$new_total = $cart->show_total();

include (DIR_WS_MODULES.'order_total/ot_cat_qty_discount.php');

include(DIR_WS_LANGUAGES . $language . '/modules/order_total/ot_cat_qty_discount.php');

$cat_qty_discount = new ot_cat_qty_discount;

$cat_deduction = $cat_qty_discount->display_discounts();

if ($cat_deduction > 0) {

$new_total = $new_total - $cat_deduction;

}

 

if ($easy_discount->count() > 0) {

echo easy_discount_display();

if ($easy_discount->total() > 0) {

$new_total = $new_total - $easy_discount->total();

}

}

 

if ($new_total == 0) {

echo '<tr><td align="right">'.SUB_TITLE_TOTAL.'</td><td align="right">'.FREE_TEXT.'</td></tr>';

} else {

echo '<tr><td align="right">'.SUB_TITLE_TOTAL.'</td><td align="right">'.$currencies->format($new_total).'</td></tr>';

}

?>

 

adjust at will.

 

Hello, trying to do this in order to display the discount in the shopping_card, but il doesn't work :

 

Fatal error: Call to undefined function: display_discounts() in c:\web_v2\easyphp1-8\www\catalog\shopping_cart.php on line 177

 

 

Can you explain me ? thanks

Share this post


Link to post
Share on other sites
Hello, trying to do this in order to display the discount in the shopping_card, but il doesn't work :

 

Fatal error: Call to undefined function: display_discounts() in c:\web_v2\easyphp1-8\www\catalog\shopping_cart.php on line 177

Can you explain me ? thanks

 

well, you need to do this:

 

added this function to the ot class:

 

function display_discounts () {

global $currencies, $cat_qty_discount_array;

 

$cat_qty_discount_array = $this->fill_discount_array($cat_qty_discount_array);

$this->calculate_discount($cat_qty_discount_array);

$n = sizeof($this->discounts);

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

$tod_amount = 0;

$od_amount = $this->discounts[$i]['discount'];

echo '<tr><td align="right">'.MODULE_CAT_QTY_DISCOUNT_FORMATED_TITLE. ' - ' .$this->discounts[$i]['text'].':</td><td align="right">'. sprintf(MODULE_CAT_QTY_DISCOUNT_FORMATED_TEXT,$currencies->format($this->discounts[$i]['discount'])).'</td></tr>';

if ($this->calculate_tax == 'true') $tod_amount = $this->calculate_tax_effect($od_amount);

$this->deduction += $od_amount+$tod_amount;

}

return $this->deduction;

}


Treasurer MFC

Share this post


Link to post
Share on other sites
well, you need to do this:

 

added this function to the ot class:

 

function display_discounts () {

global $currencies, $cat_qty_discount_array;

 

$cat_qty_discount_array = $this->fill_discount_array($cat_qty_discount_array);

$this->calculate_discount($cat_qty_discount_array);

$n = sizeof($this->discounts);

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

$tod_amount = 0;

$od_amount = $this->discounts[$i]['discount'];

echo '<tr><td align="right">'.MODULE_CAT_QTY_DISCOUNT_FORMATED_TITLE. ' - ' .$this->discounts[$i]['text'].':</td><td align="right">'. sprintf(MODULE_CAT_QTY_DISCOUNT_FORMATED_TEXT,$currencies->format($this->discounts[$i]['discount'])).'</td></tr>';

if ($this->calculate_tax == 'true') $tod_amount = $this->calculate_tax_effect($od_amount);

$this->deduction += $od_amount+$tod_amount;

}

return $this->deduction;

}

 

OK, but where is the " ot class "

 

= www\catalog\includes\classes\order_total.php ??

 

Thank you

Share this post


Link to post
Share on other sites
OK, but where is the " ot class "

 

= www\catalog\includes\classes\order_total.php ??

 

Thank you

 

catalog/includes/modules/order_total/ot_cat_qty_discount.php


Treasurer MFC

Share this post


Link to post
Share on other sites
catalog/includes/modules/order_total/ot_cat_qty_discount.php

 

OK, no error now but it doesn't work : No discount calculate.

 

I have : sub-total = 30 euro

Total = 30 euro

 

If I put (to test) :

 

echo '<tr><td align="right">'.MODULE_CAT_QTY_DISCOUNT_FORMATED_TITLE. ' - ' .$this->discounts[$i]['text'].':</td><td align="right">'. sprintf(MODULE_CAT_QTY_DISCOUNT_FORMATED_TEXT,$currencies->format($this->discounts[$i]['discount'])).'</td></tr>';

 

I have : Discount : - 00.00 euro

 

Any idea ??

 

(sorry for by bad english)

Share this post


Link to post
Share on other sites
OK, no error now but it doesn't work : No discount calculate.

 

I have : sub-total = 30 euro

Total = 30 euro

 

If I put (to test) :

 

echo '<tr><td align="right">'.MODULE_CAT_QTY_DISCOUNT_FORMATED_TITLE. ' - ' .$this->discounts[$i]['text'].':</td><td align="right">'. sprintf(MODULE_CAT_QTY_DISCOUNT_FORMATED_TEXT,$currencies->format($this->discounts[$i]['discount'])).'</td></tr>';

 

I have : Discount : - 00.00 euro

 

Any idea ??

 

(sorry for by bad english)

well, you need to be a little more specific than that.

 

whether a discount is given depends on the conditions you set in admin and if those conditions are met in the cart/order.

So without the whole picture I can advice nothing but to use trace commands to see where it goes different than expected.


Treasurer MFC

Share this post


Link to post
Share on other sites

Hello hello,

 

Your contrib seems to do "almost" exactly what i need but.... one thing

 

I want someone to get a discount by category bought, (me download music), exemple if you bought already 2 live albums, then get a xxx euros discount on the third one...

 

more precisely discount would be like this (nbr of album bought -1) = discount

buy 3, get 2 euros discount , buy 4 get 3 euros...

It's exactly from what 'im reading what your contrib does... but i would want this thing to look into order history, not only cart ...

 

ie (your order history("from all time") + your cart) shows 4 albums of live category, so you get 3 euros discount on the item of the said live category...

 

I just don't know if it's easy to ad that in the function ? and if yes, which code exactly where (i'm dumb at php, so i can't quite figure out even what is the name of the variable(s) to set the number of item of the said category in the custumer history...

 

Hope you could help, i was thinking of trying to mix it with le loyalty scheme, but can't figure out how to use that aas well...

 

thanks if you can help really :)

 

Steph

x

 

2MS2 (051113)

Share this post


Link to post
Share on other sites
Hello hello,

 

Your contrib seems to do "almost" exactly what i need but.... one thing

 

I want someone to get a discount by category bought, (me download music), exemple if you bought already 2 live albums, then get a xxx euros discount on the third one...

 

more precisely discount would be like this (nbr of album bought -1) = discount

buy 3, get 2 euros discount , buy 4 get 3 euros...

It's exactly from what 'im reading what your contrib does... but i would want this thing to look into order history, not only cart ...

 

ie (your order history("from all time") + your cart) shows 4 albums of live category, so you get 3 euros discount on the item of the said live category...

 

I just don't know if it's easy to ad that in the function ? and if yes, which code exactly where (i'm dumb at php, so i can't quite figure out even what is the name of the variable(s) to set the number of item of the said category in the custumer history...

 

Hope you could help, i was thinking of trying to mix it with le loyalty scheme, but can't figure out how to use that aas well...

 

thanks if you can help really :)

 

Steph

x

 

2MS2 (051113)

 

well, in principle it is not so difficult, it just requires an extra step to add the quantities from the order history to the category quantity (tmp)table. Currently it only processes the cart items, figures out what category they came from and adds them to the table. After that the totals are compared to the conditions set for discount. You would have to query order history to get all previously bought items and do exactly the same with them before comparing the totals.

 

But there are constraints, it can only be done for registered users who are signed in and you have to incorporate some checks for when previously ordered products no longer exist.


Treasurer MFC

Share this post


Link to post
Share on other sites
well, you need to be a little more specific than that.

 

whether a discount is given depends on the conditions you set in admin and if those conditions are met in the cart/order.

So without the whole picture I can advice nothing but to use trace commands to see where it goes different than expected.

 

OK, sorry.

 

In admin the discount is : " 23:5:2:p " and it work fine in " checkout_confirmation.php "

You can see it here :

CatD2.jpg

 

 

But the disoucnt doesn't appear in the shopping card :

CatD1.jpg

 

After serach, the " $cat_deduction " isn't calculate ( = 0)

 

Maybe the probleme is in my " ot_cat_qty_discount.php" can you look it :

 

 

<?php
 class ot_cat_qty_discount {
var $title, $output;

function ot_cat_qty_discount() {
  $this->code = 'ot_cat_qty_discount';
  $this->title = MODULE_CAT_QTY_DISCOUNT_TITLE;
  $this->description = MODULE_CAT_QTY_DISCOUNT_DESCRIPTION;
  $this->enabled = ((MODULE_CAT_QTY_DISCOUNT_STATUS == 'true') ? true : false);

  $this->sort_order = MODULE_CAT_QTY_DISCOUNT_SORT_ORDER;
  $this->include_shipping = MODULE_CAT_QTY_DISCOUNT_INC_SHIPPING;
  $this->include_tax = MODULE_CAT_QTY_DISCOUNT_INC_TAX;
  $this->calculate_tax = MODULE_CAT_QTY_DISCOUNT_CALC_TAX;
  $this->output = array();
}

function process() {
  global $order, $currencies, $ot_subtotal, $cat_qty_discount_array, $cart_items_in_discount, $cart;

  $cat_qty_discount_array = $this->fill_discount_array($cat_qty_discount_array);
  if ($cart_items_in_discount > 0) {$od_amount = $this->calculate_discount($cat_qty_discount_array);}
  else { $od_amount = 0;}

  if ($this->calculate_tax == 'true') $tod_amount = $this->calculate_tax_effect($od_amount);

  if ($od_amount > 0) {
	$this->deduction = $od_amount+$tod_amount;
	$this->output[] = array('title' => sprintf(MODULE_CAT_QTY_DISCOUNT_FORMATED_TITLE),
							'text' => sprintf(MODULE_CAT_QTY_DISCOUNT_FORMATED_TEXT, $currencies->format($od_amount)),
							'value' => $od_amount);
	$order->info['total'] -= $this->deduction;
	$order->info['tax'] -= $tod_amount;
	if ($this->sort_order < $ot_subtotal->sort_order) $order->info['subtotal'] -= $this->deduction;
  }
}

function fill_discount_array() {
 global $cart_items_in_discount, $cat_qty_discount_array, $cart;
 $cart_items_in_discount = 0;
 // fill the discount conditions
 $discount_rate = split("[:,]" , MODULE_CAT_QTY_DISCOUNT_RATES);
 $size = sizeof($discount_rate);
 $index = 0;
 for ($i=0; $i<$size; $i+=4) {
   $cat_qty_discount_array[$index]["cat"] = $discount_rate[$i]; 
   $cat_qty_discount_array[$index]["xqty"] = $discount_rate[$i+1]; 
   $cat_qty_discount_array[$index]["yqty"] = $discount_rate[$i+2]; 
   $cat_qty_discount_array[$index]["type"] = $discount_rate[$i+3];
   $cat_qty_discount_array[$index]["cqty"] = 0;
   $cat_qty_discount_array[$index]["price"] = 0;
   $index++;
 }
 // add the quantities from the shopping cart
 $products = $cart->get_products();
 for ($p=0; $p<sizeof($products); $p++) {
  $t_prid = tep_get_prid($products[$p]['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); 
  for ($i=0; $i<sizeof($cat_qty_discount_array); $i++) {

	$cat_path = tep_get_cat_path($cat_result['categories_id']);
	 $cat_path_array = split("_" , $cat_path);

//		if ($cat_result['categories_id'] == $cat_qty_discount_array[$i]["cat"]) {
	if (in_array ($cat_qty_discount_array[$i]["cat"],$cat_path_array)) {
	  $cat_qty_discount_array[$i]["cqty"] = $cat_qty_discount_array[$i]["cqty"] + $cart->get_quantity($t_prid);
	  //echo 'cq=' . $cat_qty_discount_array[$i]["cqty"];
		$cat_qty_discount_array[$i]["price"] = $products[$p]['price'];
	  //echo 'cp=' . $cat_qty_discount_array[$i]["price"];
	  $cart_items_in_discount++; 
	}
  }
 }
 return $cat_qty_discount_array;
}

function calculate_discount($cat_qty_discount_array) {
  global $qty_discount, $order_total_array;

  $od_amount = 0;
  if ((MODULE_CAT_QTY_DISCOUNT_DISABLE_WITH_COUPON == 'true') && (isset($_SESSION['cc_id']))) return $od_amount;
  for ($i=0; $i<sizeof($cat_qty_discount_array); $i++) {
	switch ($cat_qty_discount_array[$i]['type']) {
	  case 'm' : $od_amount = $od_amount + floor(($cat_qty_discount_array[$i]['cqty'] / $cat_qty_discount_array[$i]['xqty'])) *  $cat_qty_discount_array[$i]['yqty'];
				 break;
	  case 'q' : $od_amount = $od_amount + floor(($cat_qty_discount_array[$i]['cqty'] / $cat_qty_discount_array[$i]['xqty'])) *  $cat_qty_discount_array[$i]['yqty'] * $cat_qty_discount_array[$i]['price'];
				 break;
	  case 'p' : if ($cat_qty_discount_array[$i]['cqty'] >= $cat_qty_discount_array[$i]['xqty']) {
				   $od_amount = $od_amount + ($cat_qty_discount_array[$i]['cqty'] * $cat_qty_discount_array[$i]['yqty']);
				 }
				 break;
	}
  }
  return $od_amount;
}

function display_discounts () {
global $currencies, $cat_qty_discount_array;

$cat_qty_discount_array = $this->fill_discount_array($cat_qty_discount_array);
$this->calculate_discount($cat_qty_discount_array);
$n = sizeof($this->discounts);
for ($i = 0; $i < $n; $i++) {
$tod_amount = 0;
$od_amount = $this->discounts[$i]['discount'];
echo '<tr><td align="right">'.MODULE_CAT_QTY_DISCOUNT_FORMATED_TITLE. ' - ' .$this->discounts[$i]['text'].':</td><td align="right">'. sprintf(MODULE_CAT_QTY_DISCOUNT_FORMATED_TEXT,$currencies->format($this->discounts[$i]['discount'])).'</td></tr>';
if ($this->calculate_tax == 'true') $tod_amount = $this->calculate_tax_effect($od_amount);
$this->deduction += $od_amount+$tod_amount;
}
return $this->deduction;
}


function calculate_tax_effect($od_amount) {
  global $order;

  if (MODULE_QTY_DISCOUNT_RATE_TYPE == 'percentage') {
	$tod_amount = 0; 
	reset($order->info['tax_groups']); 
	while (list($key, $value) = each($order->info['tax_groups'])) { 
	  $god_amount = 0; 
	  $tax_rate = tep_get_tax_rate_from_desc($key); 
	  $net = ($tax_rate * $order->info['tax_groups'][$key]);
	  if ($net > 0) {
		$god_amount = $this->calculate_discount($order->info['tax_groups'][$key]);
		$tod_amount += $god_amount;
		$order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount; 
	  } 
	}
  } else {
	$tod_amount = 0; 
	reset($order->info['tax_groups']); 
	while (list($key, $value) = each($order->info['tax_groups'])) { 
	  $god_amount = 0; 
	  $tax_rate = tep_get_tax_rate_from_desc($key); 
	  $net = ($tax_rate * $order->info['tax_groups'][$key]);
	  if ($net>0) { 
		$god_amount = ($tax_rate/100)*$od_amount;
		$tod_amount += $god_amount; 
		$order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount; 
	  } 
	}			
  }

  return $tod_amount;		  
}

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

  return $this->check;
}

function keys() {
  return array('MODULE_CAT_QTY_DISCOUNT_STATUS', 'MODULE_CAT_QTY_DISCOUNT_SORT_ORDER', 'MODULE_CAT_QTY_DISCOUNT_DISABLE_WITH_COUPON', 'MODULE_CAT_QTY_DISCOUNT_RATES', 'MODULE_CAT_QTY_DISCOUNT_INC_SHIPPING', 'MODULE_CAT_QTY_DISCOUNT_INC_TAX', 'MODULE_CAT_QTY_DISCOUNT_CALC_TAX');
}

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_QTY_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_QTY_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, set_function, date_added) values 
('Disable If Coupon Used', 'MODULE_CAT_QTY_DISCOUNT_DISABLE_WITH_COUPON', 'true', 'Do you want to disable the quantity discount module if a discount coupon is being used by the user?', '6', '3','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 
('Discount Rates', 'MODULE_CAT_QTY_DISCOUNT_RATES', '98:10:1:q,103:10:100:m', 'The discount is based on the number of items in the same category.  Example: 94:10:1:q,56:5:2:m.. buy 10 from category 94 you get 1 item free - 1 dollar or the price of 1 item. q = quantity m = money', '6', '5', now())");
  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 
('Include Shipping', 'MODULE_CAT_QTY_DISCOUNT_INC_SHIPPING', 'false', 'Include Shipping in calculation', '6', '6', '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, set_function ,date_added) values 
('Include Tax', 'MODULE_CAT_QTY_DISCOUNT_INC_TAX', 'false', 'Include Tax in calculation.', '6', '7','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, set_function ,date_added) values 
('Calculate Tax', 'MODULE_CAT_QTY_DISCOUNT_CALC_TAX', 'true', 'Re-calculate Tax on discounted amount.', '6', '8','tep_cfg_select_option(array(\'true\', \'false\'), ', now())");
}

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

//// 
// Get tax rate from tax description
 if (!function_exists(tep_get_tax_rate_from_desc)) {
function tep_get_tax_rate_from_desc($tax_desc) { 
  $tax_query = tep_db_query("select tax_rate from " . TABLE_TAX_RATES . " where tax_description = '" . $tax_desc . "'"); 
  $tax = mysql_fetch_assoc($tax_query); 
  return $tax['tax_rate']; 
}
 }
?>

 

Sorry if i'm not clear but i'm new in the php world....

 

Thank you for your help.

Share this post


Link to post
Share on other sites
OK, sorry.

 

In admin the discount is : " 23:5:2:p " and it work fine in " checkout_confirmation.php "

You can see it here :

CatD2.jpg

But the disoucnt doesn't appear in the shopping card :

CatD1.jpg

 

After serach, the " $cat_deduction " isn't calculate ( = 0)

 

Maybe the probleme is in my " ot_cat_qty_discount.php" can you look it :

<?php
 class ot_cat_qty_discount {
var $title, $output;

function ot_cat_qty_discount() {
  $this->code = 'ot_cat_qty_discount';
  $this->title = MODULE_CAT_QTY_DISCOUNT_TITLE;
  $this->description = MODULE_CAT_QTY_DISCOUNT_DESCRIPTION;
  $this->enabled = ((MODULE_CAT_QTY_DISCOUNT_STATUS == 'true') ? true : false);

  $this->sort_order = MODULE_CAT_QTY_DISCOUNT_SORT_ORDER;
  $this->include_shipping = MODULE_CAT_QTY_DISCOUNT_INC_SHIPPING;
  $this->include_tax = MODULE_CAT_QTY_DISCOUNT_INC_TAX;
  $this->calculate_tax = MODULE_CAT_QTY_DISCOUNT_CALC_TAX;
  $this->output = array();
}

function process() {
  global $order, $currencies, $ot_subtotal, $cat_qty_discount_array, $cart_items_in_discount, $cart;

  $cat_qty_discount_array = $this->fill_discount_array($cat_qty_discount_array);
  if ($cart_items_in_discount > 0) {$od_amount = $this->calculate_discount($cat_qty_discount_array);}
  else { $od_amount = 0;}

  if ($this->calculate_tax == 'true') $tod_amount = $this->calculate_tax_effect($od_amount);

  if ($od_amount > 0) {
	$this->deduction = $od_amount+$tod_amount;
	$this->output[] = array('title' => sprintf(MODULE_CAT_QTY_DISCOUNT_FORMATED_TITLE),
							'text' => sprintf(MODULE_CAT_QTY_DISCOUNT_FORMATED_TEXT, $currencies->format($od_amount)),
							'value' => $od_amount);
	$order->info['total'] -= $this->deduction;
	$order->info['tax'] -= $tod_amount;
	if ($this->sort_order < $ot_subtotal->sort_order) $order->info['subtotal'] -= $this->deduction;
  }
}

function fill_discount_array() {
 global $cart_items_in_discount, $cat_qty_discount_array, $cart;
 $cart_items_in_discount = 0;
 // fill the discount conditions
 $discount_rate = split("[:,]" , MODULE_CAT_QTY_DISCOUNT_RATES);
 $size = sizeof($discount_rate);
 $index = 0;
 for ($i=0; $i<$size; $i+=4) {
   $cat_qty_discount_array[$index]["cat"] = $discount_rate[$i]; 
   $cat_qty_discount_array[$index]["xqty"] = $discount_rate[$i+1]; 
   $cat_qty_discount_array[$index]["yqty"] = $discount_rate[$i+2]; 
   $cat_qty_discount_array[$index]["type"] = $discount_rate[$i+3];
   $cat_qty_discount_array[$index]["cqty"] = 0;
   $cat_qty_discount_array[$index]["price"] = 0;
   $index++;
 }
 // add the quantities from the shopping cart
 $products = $cart->get_products();
 for ($p=0; $p<sizeof($products); $p++) {
  $t_prid = tep_get_prid($products[$p]['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); 
  for ($i=0; $i<sizeof($cat_qty_discount_array); $i++) {

	$cat_path = tep_get_cat_path($cat_result['categories_id']);
	 $cat_path_array = split("_" , $cat_path);

//		if ($cat_result['categories_id'] == $cat_qty_discount_array[$i]["cat"]) {
	if (in_array ($cat_qty_discount_array[$i]["cat"],$cat_path_array)) {
	  $cat_qty_discount_array[$i]["cqty"] = $cat_qty_discount_array[$i]["cqty"] + $cart->get_quantity($t_prid);
	  //echo 'cq=' . $cat_qty_discount_array[$i]["cqty"];
		$cat_qty_discount_array[$i]["price"] = $products[$p]['price'];
	  //echo 'cp=' . $cat_qty_discount_array[$i]["price"];
	  $cart_items_in_discount++; 
	}
  }
 }
 return $cat_qty_discount_array;
}

function calculate_discount($cat_qty_discount_array) {
  global $qty_discount, $order_total_array;

  $od_amount = 0;
  if ((MODULE_CAT_QTY_DISCOUNT_DISABLE_WITH_COUPON == 'true') && (isset($_SESSION['cc_id']))) return $od_amount;
  for ($i=0; $i<sizeof($cat_qty_discount_array); $i++) {
	switch ($cat_qty_discount_array[$i]['type']) {
	  case 'm' : $od_amount = $od_amount + floor(($cat_qty_discount_array[$i]['cqty'] / $cat_qty_discount_array[$i]['xqty'])) *  $cat_qty_discount_array[$i]['yqty'];
				 break;
	  case 'q' : $od_amount = $od_amount + floor(($cat_qty_discount_array[$i]['cqty'] / $cat_qty_discount_array[$i]['xqty'])) *  $cat_qty_discount_array[$i]['yqty'] * $cat_qty_discount_array[$i]['price'];
				 break;
	  case 'p' : if ($cat_qty_discount_array[$i]['cqty'] >= $cat_qty_discount_array[$i]['xqty']) {
				   $od_amount = $od_amount + ($cat_qty_discount_array[$i]['cqty'] * $cat_qty_discount_array[$i]['yqty']);
				 }
				 break;
	}
  }
  return $od_amount;
}

function display_discounts () {
global $currencies, $cat_qty_discount_array;

$cat_qty_discount_array = $this->fill_discount_array($cat_qty_discount_array);
$this->calculate_discount($cat_qty_discount_array);
$n = sizeof($this->discounts);
for ($i = 0; $i < $n; $i++) {
$tod_amount = 0;
$od_amount = $this->discounts[$i]['discount'];
echo '<tr><td align="right">'.MODULE_CAT_QTY_DISCOUNT_FORMATED_TITLE. ' - ' .$this->discounts[$i]['text'].':</td><td align="right">'. sprintf(MODULE_CAT_QTY_DISCOUNT_FORMATED_TEXT,$currencies->format($this->discounts[$i]['discount'])).'</td></tr>';
if ($this->calculate_tax == 'true') $tod_amount = $this->calculate_tax_effect($od_amount);
$this->deduction += $od_amount+$tod_amount;
}
return $this->deduction;
}
function calculate_tax_effect($od_amount) {
  global $order;

  if (MODULE_QTY_DISCOUNT_RATE_TYPE == 'percentage') {
	$tod_amount = 0; 
	reset($order->info['tax_groups']); 
	while (list($key, $value) = each($order->info['tax_groups'])) { 
	  $god_amount = 0; 
	  $tax_rate = tep_get_tax_rate_from_desc($key); 
	  $net = ($tax_rate * $order->info['tax_groups'][$key]);
	  if ($net > 0) {
		$god_amount = $this->calculate_discount($order->info['tax_groups'][$key]);
		$tod_amount += $god_amount;
		$order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount; 
	  } 
	}
  } else {
	$tod_amount = 0; 
	reset($order->info['tax_groups']); 
	while (list($key, $value) = each($order->info['tax_groups'])) { 
	  $god_amount = 0; 
	  $tax_rate = tep_get_tax_rate_from_desc($key); 
	  $net = ($tax_rate * $order->info['tax_groups'][$key]);
	  if ($net>0) { 
		$god_amount = ($tax_rate/100)*$od_amount;
		$tod_amount += $god_amount; 
		$order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount; 
	  } 
	}			
  }

  return $tod_amount;		  
}

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

  return $this->check;
}

function keys() {
  return array('MODULE_CAT_QTY_DISCOUNT_STATUS', 'MODULE_CAT_QTY_DISCOUNT_SORT_ORDER', 'MODULE_CAT_QTY_DISCOUNT_DISABLE_WITH_COUPON', 'MODULE_CAT_QTY_DISCOUNT_RATES', 'MODULE_CAT_QTY_DISCOUNT_INC_SHIPPING', 'MODULE_CAT_QTY_DISCOUNT_INC_TAX', 'MODULE_CAT_QTY_DISCOUNT_CALC_TAX');
}

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_QTY_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_QTY_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, set_function, date_added) values 
('Disable If Coupon Used', 'MODULE_CAT_QTY_DISCOUNT_DISABLE_WITH_COUPON', 'true', 'Do you want to disable the quantity discount module if a discount coupon is being used by the user?', '6', '3','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 
('Discount Rates', 'MODULE_CAT_QTY_DISCOUNT_RATES', '98:10:1:q,103:10:100:m', 'The discount is based on the number of items in the same category.  Example: 94:10:1:q,56:5:2:m.. buy 10 from category 94 you get 1 item free - 1 dollar or the price of 1 item. q = quantity m = money', '6', '5', now())");
  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 
('Include Shipping', 'MODULE_CAT_QTY_DISCOUNT_INC_SHIPPING', 'false', 'Include Shipping in calculation', '6', '6', '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, set_function ,date_added) values 
('Include Tax', 'MODULE_CAT_QTY_DISCOUNT_INC_TAX', 'false', 'Include Tax in calculation.', '6', '7','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, set_function ,date_added) values 
('Calculate Tax', 'MODULE_CAT_QTY_DISCOUNT_CALC_TAX', 'true', 'Re-calculate Tax on discounted amount.', '6', '8','tep_cfg_select_option(array(\'true\', \'false\'), ', now())");
}

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

//// 
// Get tax rate from tax description
 if (!function_exists(tep_get_tax_rate_from_desc)) {
function tep_get_tax_rate_from_desc($tax_desc) { 
  $tax_query = tep_db_query("select tax_rate from " . TABLE_TAX_RATES . " where tax_description = '" . $tax_desc . "'"); 
  $tax = mysql_fetch_assoc($tax_query); 
  return $tax['tax_rate']; 
}
 }
?>

 

Sorry if i'm not clear but i'm new in the php world....

 

Thank you for your help.

 

what is the code you currently have in shopping_cart.php to display the discount?


Treasurer MFC

Share this post


Link to post
Share on other sites
well, in principle it is not so difficult, it just requires an extra step to add the quantities from the order history to the category quantity (tmp)table. Currently it only processes the cart items, figures out what category they came from and adds them to the table. After that the totals are compared to the conditions set for discount. You would have to query order history to get all previously bought items and do exactly the same with them before comparing the totals.

 

But there are constraints, it can only be done for registered users who are signed in and you have to incorporate some checks for when previously ordered products no longer exist.

 

 

Hello hello (bonjour :-))

 

Thanks for your reply, actually my question was yep, but *how* do i do this "simply" querry in order history (same as in cart, but in order history) (ie what is the code ?) and where do i place it then ? and how do i "ad" it to the querry in cart content so it gives me the result for the whole cart content + history...

 

I won't have the problem of products which no longer exists since i will let all products in the database once created (i don't have many many), it's a download music store only so i'll just desable the link when it's not availaible anymore and the site will be designed anyway to show only "featured products" (so the customer won't see the d/l not available, but they still exist :-))

 

The only concern is then for the non yet signed in (because obviously if he's not a registered at all he won't qualify with the order history anyway, what's in cart is what qualifies him for the discount...)

 

Would it make sense then to make a twisted discount category like this :

 

discount category in shopping cart (just scan the content as it is),

ad a relevant discount (exactly the same as you wrote per category)

 

extra discount when check out confirmation (you're obliged to be registered by this stage) :

a twisted discount category, would pick up categories of items (again in check out confirmation), make an extra discount as : (in euro let's say) : x of "live albums category" in order history = x euros "extra discount"

 

ad this extra discount as the number coming from cart > new total, go to payment

 

then the extra script is only :

-show category discount in shopping_cart

 

- show and ad to total from cart (with category discount) a "# of category items in history = # extra discount" in check out confirmation

 

and go to payment..

 

Is this complicated code ?

 

the second option being :

force ppl to sign in before adding anything to cart and then having the script for discount category twisted like this :

discount category = (nbr of items of said category in cart) + (number of items of said category in order hsitory) -1 for exemple

 

show discount in shopping_cart

 

I don't know which one is better or easier... i'd say it's prob better if you see your discount right in the shopping cart, it's more encouraging otherwise you doubt you got your discount... but then for this i should have forced to sign in before shopping_cart which i guess isn't quite difficult to make ?

 

Well i actually don't know "where" i could beg for the piece of code i need, as, as said, i'm pretty completely newbie to php and can't figure out how to "write" that search in history and then apply the relevant discount...

 

would you be sooooooo kind if you get time to help me out ?

 

thanks,

steph

Edited by Steph Mu Bai

Share this post


Link to post
Share on other sites
what is the code you currently have in shopping_cart.php to display the discount?

 

Code in shopping_card.php :

 

<?php
$new_total = $cart->show_total();
include (DIR_WS_MODULES.'order_total/ot_cat_qty_discount.php');
include(DIR_WS_LANGUAGES . $language . '/modules/order_total/ot_cat_qty_discount.php');
$cat_qty_discount = new ot_cat_qty_discount;
$cat_deduction = $cat_qty_discount->display_discounts();
if ($cat_deduction > 0) {
$new_total = $new_total - $cat_deduction;
}

if ($new_total == 0) {
echo '<tr><td align="right">'.SUB_TITLE_TOTAL.'</td><td align="right">'.FREE_TEXT.'</td></tr>';
} else {
echo '<tr><td align="right">'.SUB_TITLE_TOTAL.'</td><td align="right">'.$currencies->format($new_total).'</td></tr>';
}
?>

 

(I have delete the part for "easy_discount")

Share this post


Link to post
Share on other sites
Code in shopping_card.php :

 

<?php
$new_total = $cart->show_total();
include (DIR_WS_MODULES.'order_total/ot_cat_qty_discount.php');
include(DIR_WS_LANGUAGES . $language . '/modules/order_total/ot_cat_qty_discount.php');
$cat_qty_discount = new ot_cat_qty_discount;
$cat_deduction = $cat_qty_discount->display_discounts();
if ($cat_deduction > 0) {
$new_total = $new_total - $cat_deduction;
}

if ($new_total == 0) {
echo '<tr><td align="right">'.SUB_TITLE_TOTAL.'</td><td align="right">'.FREE_TEXT.'</td></tr>';
} else {
echo '<tr><td align="right">'.SUB_TITLE_TOTAL.'</td><td align="right">'.$currencies->format($new_total).'</td></tr>';
}
?>

 

(I have delete the part for "easy_discount")

 

in shopping_cart.php I have :

 

<?php

$new_total = $cart_total;

 

// Category Quantity/Value Breaks Discount

if (MODULE_CAT_QVB_DISCOUNT_STATUS) {

include (DIR_WS_MODULES.'order_total/ot_cat_qvb_discount.php');

include(DIR_WS_LANGUAGES . $language . '/modules/order_total/ot_cat_qvb_discount.php');

$cat_qvb_discount = new ot_cat_qvb_discount;

$cat_deduction = $cat_qvb_discount->display_discounts();

if ($cat_deduction > 0) {

$new_total = $new_total - $cat_deduction;

}

}

 

// Category Quantity Discount

if (MODULE_CAT_QTY_DISCOUNT_STATUS) {

include (DIR_WS_MODULES.'order_total/ot_cat_qty_discount.php');

include(DIR_WS_LANGUAGES . $language . '/modules/order_total/ot_cat_qty_discount.php');

$cat_qty_discount = new ot_cat_qty_discount;

$cat_deduction = $cat_qty_discount->display_discounts();

if ($cat_deduction > 0) {

$new_total = $new_total - $cat_deduction;

}

}

 

// Easy Discount

if ($easy_discount->count() > 0) {

echo $easy_discount->display();

$new_total = $new_total - $easy_discount->total();

}

 

// 2Gether Discount

include (DIR_WS_MODULES.'order_total/ot_together.php');

$together = new ot_together;

$together_discount = $together->calculate_2gether_discount();

if ($together_discount > 0) {

echo '<tr><td align="right"><img src="images/2gether_sm.jpg" border="0" style="vertical-align:middle" alt="2gether discount" title="2gether discount"> Discount:</td><td align="right"><font color="red">-'.$currencies->format($together_discount).'</font></td></tr>';

$new_total = $new_total - $together_discount;

}

 

if ($new_total != $cart_total) {

if ($new_total == 0) {

echo '<tr><td align="right">'.SUB_TITLE_TOTAL.'</td><td align="right">'.FREE_TEXT.'</td></tr>';

} else {

echo '<tr><td align="right">'.SUB_TITLE_TOTAL.'</td><td align="right">'.$currencies->format($new_total).'</td></tr>';

}

}

?>

 

You can remove the ones you do not have.

 

 

in the order_total module the display function looks like:

 

function display_discounts () {

global $currencies, $cat_qty_discount_array;

 

$this->deduction = 0;

$cat_qty_discount_array = $this->fill_discount_array();

$this->calculate_discount($cat_qty_discount_array);

$n = sizeof($this->discounts);

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

$tod_amount = 0;

$od_amount = $this->discounts[$i]['discount'];

echo '<tr><td align="right">'.$this->discounts[$i]['text'].':</td><td align="right">'. sprintf(MODULE_CAT_QTY_DISCOUNT_FORMATED_TEXT,$currencies->format($this->discounts[$i]['discount'])).'</td></tr>';

if ($this->calculate_tax == 'true') $tod_amount = $this->calculate_tax_effect($od_amount);

$this->deduction += $od_amount+$tod_amount;

}

return $this->deduction;

}

 

that should work.


Treasurer MFC

Share this post


Link to post
Share on other sites

Thank you, but it the same....

 

But i have find something, if i change the " function calculate_discount" in ot_cat_qty_discount.php by this :

 

 

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 calculate_discount($cat_qty_discount_array) {
global $qty_discount, $order_total_array;

$od_amount = 0;
if ((MODULE_CAT_QTY_DISCOUNT_DISABLE_WITH_COUPON == 'true') && (isset($_SESSION['cc_id']))) return $od_amount;
for ($i=0; $i<sizeof($cat_qty_discount_array); $i++) {
switch ($cat_qty_discount_array[$i]['type']) {
case 'm' : $discount = floor(($cat_qty_discount_array[$i]['cqty'] / $cat_qty_discount_array[$i]['xqty'])) * $cat_qty_discount_array[$i]['yqty'];
if ($discount > 0) $this->discounts[] = array('text' => $this->cat_name($cat_qty_discount_array[$i]["cat"]).'- Buy '.$cat_qty_discount_array[$i]['xqty'].' get '.$cat_qty_discount_array[$i]['yqty'].' off'.' ['.$cat_qty_discount_array[$i]['cqty'].']', 'discount' => $discount);
break;
case 'q' : $discount = floor(($cat_qty_discount_array[$i]['cqty'] / $cat_qty_discount_array[$i]['xqty'])) * ($cat_qty_discount_array[$i]['price']/$cat_qty_discount_array[$i]['cqty']);
if ($discount > 0) $this->discounts[] = array('text' => $this->cat_name($cat_qty_discount_array[$i]["cat"]).'- Buy '.$cat_qty_discount_array[$i]['xqty'].' get '.$cat_qty_discount_array[$i]['yqty'].' for FREE'.' ['.$cat_qty_discount_array[$i]['cqty'].']', 'discount' => $discount);
break;
case 'p' : if ($cat_qty_discount_array[$i]['cqty'] >= $cat_qty_discount_array[$i]['xqty']) {
$discount = ($cat_qty_discount_array[$i]['cqty'] * $cat_qty_discount_array[$i]['yqty']);
if ($discount > 0) $this->discounts[] = array('text' => $this->cat_name($cat_qty_discount_array[$i]["cat"]).'- Buy '.$cat_qty_discount_array[$i]['xqty'].' get '.$cat_qty_discount_array[$i]['yqty'].' off each'.' ['.$cat_qty_discount_array[$i]['cqty'].']', 'discount' => $discount);
}
break;
}
}


  return $od_amount;
}

 

It word find in the shopping card :

CatD4.jpg

 

 

But now it doesn't work in the " checkout_confirmation.php" :

CatD3.jpg

 

 

I'm going to be crazy...

Share this post


Link to post
Share on other sites

Just to say : IT WORK

 

(it whas an error in " ot_cat_qty_discount.php ")

 

Thank you very much for your help boxtel.

Share this post


Link to post
Share on other sites

Dear Amanda,

Your Category Discount contribution looks great!

I think it does almost what I need. I was just wondering if I could get some advice from you on how to make it do what I want.

 

I have a group of products, where if someone orders 2, I would like to give $2 off per product, and if they order 3 or more, I would like to give $8 off per product. I know the contribution doesn't currently have that capability.

What if I made a variation on the "p" option, where you enter the information as:

34:2;3:2;8:x

where the "2;3" represents a quantity 2 products and 3 products, and the "2;8" represents $2 off, and $8 off.

Then, in ot_cat_qty_discount.php, fill_discount_array could stay the same (I think--xqty and yqty would just contain "2;3" and "2;8", instead of a single number, right?)

And then, in calculate_discount, I would add another option for x:

It would split xqty and yqty into 2 arrays, and would check backwards in the xqty array, and see if the highest quantity is met, and if so, it gets the comparable discount value from the yqty array.

Does this sound like it will work?

 

Thanks very much for any help with this.

Regards,

-Lori-

Share this post


Link to post
Share on other sites
Dear Amanda,

Your Category Discount contribution looks great!

I think it does almost what I need. I was just wondering if I could get some advice from you on how to make it do what I want.

 

I have a group of products, where if someone orders 2, I would like to give $2 off per product, and if they order 3 or more, I would like to give $8 off per product. I know the contribution doesn't currently have that capability.

What if I made a variation on the "p" option, where you enter the information as:

34:2;3:2;8:x

where the "2;3" represents a quantity 2 products and 3 products, and the "2;8" represents $2 off, and $8 off.

Then, in ot_cat_qty_discount.php, fill_discount_array could stay the same (I think--xqty and yqty would just contain "2;3" and "2;8", instead of a single number, right?)

And then, in calculate_discount, I would add another option for x:

It would split xqty and yqty into 2 arrays, and would check backwards in the xqty array, and see if the highest quantity is met, and if so, it gets the comparable discount value from the yqty array.

Does this sound like it will work?

 

Thanks very much for any help with this.

Regards,

-Lori-

 

you mean like a kind of quantity break discount per category ?

 

well, it just so happens that I completed such an extention to category discount and is called category quantity/value break discount. You can add quantity breaks or value breaks for the specified categories.

 

I will release it this week so you can have a look if it does what you need.


Treasurer MFC

Share this post


Link to post
Share on other sites
you mean like a kind of quantity break discount per category ?

 

well, it just so happens that I completed such an extention to category discount and is called category quantity/value break discount. You can add quantity breaks or value breaks for the specified categories.

 

I will release it this week so you can have a look if it does what you need.

Great--thanks so much! I'm looking forward to seeing it!

Could you please post a message to this thread, so I can get an email notification when it comes out?

Thanks very much!

 

Regards,

-Lori-

Share this post


Link to post
Share on other sites
Great--thanks so much! I'm looking forward to seeing it!

Could you please post a message to this thread, so I can get an email notification when it comes out?

Thanks very much!

 

Regards,

-Lori-

 

sure, You can see an example here:

 

spiritual-art-charles-frizzell-notecards-C-54_102.html

 

the site address is in my member info


Treasurer MFC

Share this post


Link to post
Share on other sites

The category discount is exactly what I need also. Your example worked perfectly with my testing. I hope you are able to release it very soon and let us help you with the testing.

 

sure, You can see an example here:

 

spiritual-art-charles-frizzell-notecards-C-54_102.html

Share this post


Link to post
Share on other sites
sure, You can see an example here:

 

spiritual-art-charles-frizzell-notecards-C-54_102.html

 

the site address is in my member info

Hi Amanda. I looked at your example site, and it looks great! I really like the look of the site, as well as how the contribution works there! You've done a great job!

 

I'm really looking forward to seeing the contribution, when you've got it ready! I second Jeff's offer to help you with the testing, when you are ready.

 

Great job!

 

Regards,

-Lori-

Share this post


Link to post
Share on other sites
Hi Amanda. I looked at your example site, and it looks great! I really like the look of the site, as well as how the contribution works there! You've done a great job!

 

I'm really looking forward to seeing the contribution, when you've got it ready! I second Jeff's offer to help you with the testing, when you are ready.

 

Great job!

 

Regards,

-Lori-

 

Right, not sure if it is ready as I have had very little time this week to screen it for general purpose but I promised and since you are kind enough to volunteer to test I cannot possibly bug out.

 

http://www.oscommerce.com/community/contributions,4451


Treasurer MFC

Share this post


Link to post
Share on other sites
Right, not sure if it is ready as I have had very little time this week to screen it for general purpose but I promised and since you are kind enough to volunteer to test I cannot possibly bug out.

 

http://www.oscommerce.com/community/contributions,4451

 

see, now I forgot the shopping cart addon:

 

Let me show you what I have in total there so you can see how it integrates with the other discounts.

note: $cart_total is my value derived from $cart->show_total();

I set that once in application_top because that cart function triggers an entire cart recalculation and I only like to do that once. Hence the use of a single variable for that.

 

<tr>

<td>

<table width="100%">

<tr>

<td align="right" width="85%"><?php echo SUB_TITLE_SUB_TOTAL; ?></td><td align="right">

<?php echo $currencies->format($cart_total); ?>

</td>

</tr>

<?php

$new_total = $cart_total;

 

// Category Quantity/Value Breaks Discount

if (MODULE_CAT_QVB_DISCOUNT_STATUS) {

include (DIR_WS_MODULES.'order_total/ot_cat_qvb_discount.php');

include(DIR_WS_LANGUAGES . $language . '/modules/order_total/ot_cat_qvb_discount.php');

$cat_qvb_discount = new ot_cat_qvb_discount;

$cat_deduction = $cat_qvb_discount->display_discounts();

if ($cat_deduction > 0) {

$new_total = $new_total - $cat_deduction;

}

}

 

// Easy Discount

if ($easy_discount->count() > 0) {

echo $easy_discount->display();

$new_total = $new_total - $easy_discount->total();

}

 

// 2Gether Discount

include (DIR_WS_MODULES.'order_total/ot_together.php');

$together = new ot_together;

$together_discount = $together->calculate_2gether_discount();

if ($together_discount > 0) {

echo '<tr><td align="right"><img src="images/2gether_sm.jpg" border="0" style="vertical-align:middle" alt="2gether discount" title="2gether discount"> Discount:</td><td align="right"><font color="red">-'.$currencies->format($together_discount).'</font></td></tr>';

$new_total = $new_total - $together_discount;

}

 

if ($new_total != $cart_total) {

if ($new_total == 0) {

echo '<tr><td align="right">'.SUB_TITLE_TOTAL.'</td><td align="right">'.FREE_TEXT.'</td></tr>';

} else {

echo '<tr><td align="right">'.SUB_TITLE_TOTAL.'</td><td align="right">'.$currencies->format($new_total).'</td></tr>';

}

}

?>

</table>

</td>

</tr>

<tr>

<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>

</tr>


Treasurer MFC

Share this post


Link to post
Share on other sites
Hi Amanda. I looked at your example site, and it looks great! I really like the look of the site, as well as how the contribution works there! You've done a great job!

 

I'm really looking forward to seeing the contribution, when you've got it ready! I second Jeff's offer to help you with the testing, when you are ready.

 

Great job!

 

Regards,

-Lori-

 

thanks but that is not an example site, it is the only site I have, supporting the only real shop I run.


Treasurer MFC

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×