Jump to content
Sign in to follow this  
boxtel

Category Discount

Recommended Posts

I think I've fixed the problem I was having with the shopping cart box, where it would not always display the discount. I have slightly modified the code you posted, as follows:

	// Category Quantity/Value Breaks Discount
  if (MODULE_CAT_QVB_DISCOUNT_STATUS == 'true') {
	if (!is_object($cat_qvb_discount)) {
	  include_once (DIR_WS_MODULES.'order_total/ot_cat_qvb_discount.php');
	  include_once (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(false);
	if ($cat_deduction > 0) {
	  //$totals_string .= '<tr><td align="right" class="vsmalltext">Category Discount:</td><td align="right" nowrap class="vsmalltext"><font color="red">-'.$currencies->format($cat_deduction).'</font></td></tr>';
	  $discounts = $discounts + $cat_deduction;
	  $new_total = $new_total - $cat_deduction;
	}
  }

I moved the calculation of $cat_deduction outside of the

if (!is_object(...)) { ... }

and now I get the deduction to display, when it wasn't displaying before.

 

-Lori-

 

Lori, you are absolutely correct, good catch thanks.


Treasurer MFC

Share this post


Link to post
Share on other sites

Hi. Love the contribution.

 

I noticed that if I have a product in a different category linked to a product in the discount category it does not pick up the discount during the checkout process. Is there a way this can be fixed?

Share this post


Link to post
Share on other sites
Hi. Love the contribution.

 

I noticed that if I have a product in a different category linked to a product in the discount category it does not pick up the discount during the checkout process. Is there a way this can be fixed?

 

a product in a different category linked to a product in the discount category

I beg your pardon?


Treasurer MFC

Share this post


Link to post
Share on other sites

Okay I try to describe this.

 

I have a product Z already in Category B. This category has no discount. Normal category etc.

 

I then link the product Z or copy to Category D. In this category I make it buy 2 get one free.

 

So product Z is in both Category B and Category D.

 

However, when I go to check out it will not pick the discount for this product Z that belongs to both categories. It will work fine if the products in Category D are not linked anywhere else (just existing in that category only).

 

Does this help? Sorry

Share this post


Link to post
Share on other sites
Okay I try to describe this.

 

I have a product Z already in Category B. This category has no discount. Normal category etc.

 

I then link the product Z or copy to Category D. In this category I make it buy 2 get one free.

 

So product Z is in both Category B and Category D.

 

However, when I go to check out it will not pick the discount for this product Z that belongs to both categories. It will work fine if the products in Category D are not linked anywhere else (just existing in that category only).

 

Does this help? Sorry

 

ah,

 

so not "a product in a different category linked to a product in the discount category" but "a product assigned to multiple categories".

 

No, that does not function as is.

Basically in the category tree determination, a query is made to determine the category the product belongs to and then move up the ladder to the top category. It assumes that that product belongs to 1 tree though.

 

It could be adapted but then you would have to create a loop if the product belongs to more than 1 category tree and check them all but you also have to consider, what if multiple trees for that product have a separate category discount, which one to take becomes the question.


Treasurer MFC

Share this post


Link to post
Share on other sites

I have installed the latest release of "Category Tree Discount" as found here:

 

http://www.oscommerce.com/community/contri...search,discount

 

It's installed, and I followed all instructions for installation to the tee.

 

 

Please visit: http://purefit.com/store/product_info.php?...;products_id=55

 

I have set up the discount code for the category that this product is in = 39.

 

The module is turned on:

 

Category Tree Quantity and Value Break Discount

 

Activate Category Quantity Discount

true

 

Sort Order

4

 

Discount Rates

39:4:1:p;39:6:3:p;39:8:5:p;

 

 

 

and nothing seems to be working. Can someone help me out? I appreciate the time you're taking!

Share this post


Link to post
Share on other sites

I dont know if anyone is still following this topic but i have a little problem:

The category discount is great, and also is the shopping cart add on!

 

But i also want level discount to show in the shopping cart!

This is what I build from showing the discount in the shopping cart.

// lev discount
if (MODULE_LEV_DISCOUNT_STATUS) {
include (DIR_WS_MODULES.'order_total/ot_lev_discount.php');
include(DIR_WS_LANGUAGES . $language . '/modules/order_total/ot_lev_discount.php');
$lev = new ot_lev_discount;
$lev_discount = $lev->$order_total;
if ($lev_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 - $lev_discount;
}
}

 

In the place of $order_total I also tried get_order_total()

but that didn't worked either.

 

Well nothing shows up, I just modified the 2gether add on, but it doesnt work.

Anyone that could point me in the right direction?

 

Below is the code for the lev_discount.

 

I would really thank anyone that will give any kind of help. Sorry for the bad English, i am from holland.

 

<?php
/*
<<<<<<< ot_lev_discount.php
 $Id: ot_lev_discount.php,v 1.0 2002/04/08 01:13:43 hpdl Exp $
=======
 $Id: ot_lev_discount.php,v 1.3 2002/09/04 22:49:11 wilt Exp $
 $Id: ot_lev_discount.php,v 2.4 2006/02/28 12:10:01 maniac101 Exp $
modified to calc discount correctly when tax is included in discount
>>>>>>> 2.4

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

 Copyright (c) 2002 osCommerce

 Released under the GNU General Public License
*/

 class ot_lev_discount {
var $title, $output;

function ot_lev_discount() {
  $this->code = 'ot_lev_discount';
  $this->title = MODULE_LEV_DISCOUNT_TITLE;
  $this->description = MODULE_LEV_DISCOUNT_DESCRIPTION;
  $this->enabled = MODULE_LEV_DISCOUNT_STATUS;
  $this->sort_order = MODULE_LEV_DISCOUNT_SORT_ORDER;
  $this->include_shipping = MODULE_LEV_DISCOUNT_INC_SHIPPING;
  $this->include_tax = MODULE_LEV_DISCOUNT_INC_TAX;
  $this->calculate_tax = MODULE_LEV_DISCOUNT_CALC_TAX;
  $this->table = MODULE_LEV_DISCOUNT_TABLE;
//	  $this->credit_class = true;
  $this->output = array();
}

function process() {
  global $order, $ot_subtotal, $currencies;
  $od_amount = $this->calculate_credit($this->get_order_total());
  if ($od_amount>0) {
  $this->deduction = $od_amount;
  $this->output[] = array('title' => $this->title . ':',
						  'text' => '<b>' . $currencies->format($od_amount) . '</b>',
						  'value' => $od_amount);
$order->info['total'] = $order->info['total'] - $od_amount;
if ($this->sort_order < $ot_subtotal->sort_order) {
  $order->info['subtotal'] = $order->info['subtotal'] - $od_amount;
}
}
}


 function calculate_credit($amount) {
global $order;
$od_amount=0;
$table_cost = split("[:,]" , MODULE_LEV_DISCOUNT_TABLE);
for ($i = 0; $i < count($table_cost); $i+=2) {
	  if ($amount >= $table_cost[$i]) {
		$od_pc = $table_cost[$i+1];
	  }
	}
// Calculate tax reduction if necessary
if($this->calculate_tax == 'true') {
// Calculate main tax reduction
  $tod_amount = round($order->info['tax']*10)/10*$od_pc/100;
  $order->info['tax'] = $order->info['tax'] - $tod_amount;
// Calculate tax group deductions
  reset($order->info['tax_groups']);
  while (list($key, $value) = each($order->info['tax_groups'])) {
	$god_amount = round($value*10)/10*$od_pc/100;
	$order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;
  }  
}
$od_amount = round($amount*10)/10*$od_pc/100;
//	$od_amount = $od_amount + $tod_amount;
// maniac101 above line was adding tax back into discount incorrectly for me
return $od_amount;
 }


 function get_order_total() {
global  $order, $cart;
$order_total = $order->info['total'];
// Check if gift voucher is in cart and adjust total
$products = $cart->get_products();
for ($i=0; $i<sizeof($products); $i++) {
  $t_prid = tep_get_prid($products[$i]['id']);
  $gv_query = tep_db_query("select products_price, products_tax_class_id, products_model from " . TABLE_PRODUCTS . " where products_id = '" . $t_prid . "'");
  $gv_result = tep_db_fetch_array($gv_query);
  if (ereg('^GIFT', addslashes($gv_result['products_model']))) { 
	$qty = $cart->get_quantity($t_prid);
	$products_tax = tep_get_tax_rate($gv_result['products_tax_class_id']);
	if ($this->include_tax =='false') {
	   $gv_amount = $gv_result['products_price'] * $qty;
	} else {
	  $gv_amount = ($gv_result['products_price'] + tep_calculate_tax($gv_result['products_price'],$products_tax)) * $qty;
	}
	$order_total=$order_total - $gv_amount;
  }
}
if ($this->include_tax == 'false') $order_total=$order_total-$order->info['tax'];
if ($this->include_shipping == 'false') $order_total=$order_total-$order->info['shipping_cost'];
return $order_total;
 }   



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

  return $this->check;
}

function keys() {
  return array('MODULE_LEV_DISCOUNT_STATUS', 'MODULE_LEV_DISCOUNT_SORT_ORDER','MODULE_LEV_DISCOUNT_TABLE', 'MODULE_LEV_DISCOUNT_INC_SHIPPING', 'MODULE_LEV_DISCOUNT_INC_TAX','MODULE_LEV_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 ('Display Total', 'MODULE_LEV_DISCOUNT_STATUS', 'true', 'Do you want to enable the Order Discount?', '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_LEV_DISCOUNT_SORT_ORDER', '999', '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 ('Include Shipping', 'MODULE_LEV_DISCOUNT_INC_SHIPPING', 'true', 'Include Shipping in calculation', '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, set_function ,date_added) values ('Include Tax', 'MODULE_LEV_DISCOUNT_INC_TAX', 'true', 'Include Tax in calculation.', '6', '4','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_LEV_DISCOUNT_CALC_TAX', 'false', 'Re-calculate Tax on discounted amount.', '6', '5','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 Percentage', 'MODULE_LEV_DISCOUNT_TABLE', '100:7.5,250:10,500:12.5,1000:15', 'Set the price breaks and discount percentages', '6', '6', now())");
}

function remove() {
  $keys = '';
  $keys_array = $this->keys();
  for ($i=0; $i<sizeof($keys_array); $i++) {
	$keys .= "'" . $keys_array[$i] . "',";
  }
  $keys = substr($keys, 0, -1);

  tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in (" . $keys . ")");
}
 }
?>

Share this post


Link to post
Share on other sites

hoi guys

 

is it posible with this tool to do the following.

i go into a category. and i want if some customer buys a complete set (all articles in a category) to have a discount/one item free.

 

or maybe when i go into a category you see an extra button for buy complete set.

 

is this posible with this or any other contib..??

Share this post


Link to post
Share on other sites

i looked the contibutions for combined products but cant find it .

i can find bundled products but with bundled products you have to pre 'make ' sets and thats lots of work now but also when prices change.

 

and master products orso where ya have master and slave settings is also not an option because almost all products are in more categories and so also in diferent sets.

 

i just want an option that combines all products within a category to one bundle for one price that i can set per categorie orso.

 

on some packages its called kitting products but i have not yet found it for oscommerce.

 

so if anybody know a way to do it it would be great because i realy need that option.

 

greets

Share this post


Link to post
Share on other sites

Installation issues:

 

i have installed the module four times now. It shows up under admin, and allows me the configure it. The buy two get one free shows up under the product catagory but when I add three to my cart I don't see any discount being applied, nor does the final price reflect the discount.

 

I have looked through the code, installed the shopping cart 'fix' and am stuck.

 

any ideas?

Share this post


Link to post
Share on other sites

I have installed this module and it is working well in that it correctly calculates the discount and displays it on the confirmation page. However, when the payment gets processed through authorize.net (using the AIM module) the full amount, not the discounted amount gets processed.

 

The discount module updates the total in process [$order->info['total'] -= $this->deduction;] and the authorize.net module reads [x_amount => number_format($order->info['total'], 2)] the amount from the the same spot. I am stumped as to why it would update it once, display correctly, then revert to the original amount.

 

Any ideas. We are trying to go live tomorrow. Any help would be greatly appreciated!

 

Thanks,

Diede

Share this post


Link to post
Share on other sites

Hi Amanda, Lori and all other Discounters!

 

A great contrib that has solved a particular problem that I've been struggling with for ages!

 

I'm using the QVB version, working fine in the main cart, but am having problems getting the Shopping Cart Infobox addon to work.

 

I've been through the posts and have been trying to work out what code goes where, without much success.

 

The discount does appear right at the top of the Shopping Cart IB but the info box changes to full with with Times New Roman at 10 or 12 point font. This obviously isn't right.

 

I also have Amanda's great CCGV(Trad) installed. Could there be a conflict?

 

The posts mention a change in Application_top, but what change is this exactly since I haven't applied that?

 

My shop is heavily modded so if anyone needs to see any of the files please let me know.

 

Any help much appreciated.

 

Regards

Simon

Edited by spannerman

Share this post


Link to post
Share on other sites

QVB VERSION AND TAX QUESTION:

 

I'm having a heck of a time making the tax work correctly. (Same issue as was discussed before - the tax is calculated BEFORE the discount is taken off).

 

I know that I need to edit includes/modules/order_total/ot_cat_qvb_discount.php, specifically the function process() (See Foxtel's Post here. - #195). But it seems that the QTY version is different, and I can't quite make it work.

 

 

Has anyone been able to modify ot_cat_qvb_discount.php to make the tax calculate correctly? If so, would you be willing to post your code?

 

Thanks a bunch!!

Share this post


Link to post
Share on other sites

New osCommerce user. I love the program and this module seems to be just exactly what I need. I downloaded the "category_discount_mc1" and "corrections" files and updated the files and code, but all I get is "echo category_discount_display($current_category_id);" at the top of the category and product listing pages, but not on the individual product page. And as far as I can tell, it's not discounting anything in the shopping cart. Any ideas where I zigged when I should have zagged? :blink:

 

Thanks!

Share this post


Link to post
Share on other sites

Hello, I have been troubleshooting this for a bit and I think it will involves a code restructure of some kind so I may need some guidance.

 

Basically, TAX is being calculated from the TOTAL not the SUBTOTAL that is determined after the discount. So My store is over taxing.

 

I understand a bit about sort order, so I looked at it and it is right. Order looks like this:

 

Category Discount 10

Subtotal 20

Tax 40

Shipping 50

Total 90

 

I moved Category Discount order all around but the order doesn't seem to matter, the outcome calculation is the same. So I am betting I need to change some code....Any suggestions, I looked around the forums and just got confused...

Share this post


Link to post
Share on other sites
Hello, I have been troubleshooting this for a bit and I think it will involves a code restructure of some kind so I may need some guidance.

 

Basically, TAX is being calculated from the TOTAL not the SUBTOTAL that is determined after the discount. So My store is over taxing.

 

I understand a bit about sort order, so I looked at it and it is right. Order looks like this:

 

Category Discount 10

Subtotal 20

Tax 40

Shipping 50

Total 90

 

I moved Category Discount order all around but the order doesn't seem to matter, the outcome calculation is the same. So I am betting I need to change some code....Any suggestions, I looked around the forums and just got confused...

 

Sorry for the confusion, if any. My Tax is being calculated from the "total products purchased" price before the discount is applied or shipping. It is not being calculated from the TOTAL like I said.

Share this post


Link to post
Share on other sites

My work so far on this:

 

There appears to be a problem with the code for QVB for people that need to charge tax.

 

And it is not a user "sort order" problem, in fact, the sort order in the admin utility doesn't work. The number changes but the sort order doesn't actually change no matter what number you give it. It is acting like it does not have a sort order number at all. I know this because I installed "Module Display Order Matches Sort Order in Admin" which sorts the order totals into the actual order they are calculated. No matter what number I give the QVB Discount in admin it always stays at the end of the calculation hiarchy, for some reason the number isn't actually determining the calculation order.

 

This would be a great fix to a great contribution. I would appreciate any direction or advice you may have. I am going to keep trucking on this. I will post any new findings.

Share this post


Link to post
Share on other sites
There appears to be a problem with the code for QVB for people that need to charge tax.

 

And it is not a user "sort order" problem . . .

 

This would be a great fix to a great contribution. I would appreciate any direction or advice you may have. I am going to keep trucking on this. I will post any new findings.

 

The problem lies specifically in this file:

 

includes/modules/order_total/ot_cat_qvb_discount.php

 

THIS is the file that calculates the total, subtotal, tax, and discount - in that order. So basically, this file needs to be change to caluculate in order of total, discount, subtotal, tax.

 

The original order total file (no modifactions) is ot_total.php. These two functions do the work:

 

	function ot_total() {
  $this->code = 'ot_total';
  $this->title = MODULE_ORDER_TOTAL_TOTAL_TITLE;
  $this->description = MODULE_ORDER_TOTAL_TOTAL_DESCRIPTION;
  $this->enabled = ((MODULE_ORDER_TOTAL_TOTAL_STATUS == 'true') ? true : false);
  $this->sort_order = MODULE_ORDER_TOTAL_TOTAL_SORT_ORDER;
  $this->output = array();
}

function process() {
  global $order, $currencies;
  $this->output[] = array('title' => $this->title . ':',
						  'text' => '<b>' . $currencies->format($order->info['total'], true, $order->info['currency'], $order->info['currency_value']) . '</b>',
						  'value' => $order->info['total']);
}

 

... Sorry, but I tried and failed many times trying to modify includes/modules/order_total/ot_cat_qvb_discount.php. Maybe someone else can figure it out!

 

ETA: Regarding the "Sort Order" - that's just the display order, not the calculation order. The file above does the actual calculations.

Edited by user1515

Share this post


Link to post
Share on other sites

To set the module to calcuate based on the subtotal instead of the total changing this in the includes/modules/order_total/ot_cat_qvb_discount.php

$order->info['total']

 

 

To

 

$order->info['subtotal']

Share this post


Link to post
Share on other sites
To set the module to calcuate based on the subtotal instead of the total changing this in the includes/modules/order_total/ot_cat_qvb_discount.php

$order->info['total']

To

 

$order->info['subtotal']

 

 

Thanks Dave, but that seems to make the discount happen 2 times, and the tax remains unchanged....I am open to trying what ever other advice you have...I will be monitoring the board and trying to work this out....

Share this post


Link to post
Share on other sites
Thanks Dave, but that seems to make the discount happen 2 times, and the tax remains unchanged....I am open to trying what ever other advice you have...I will be monitoring the board and trying to work this out....

 

Is ANYONE going to solve this problem? I'd like to hear more from the contributor of this module. He/she had some really odd ways of calculating the discount total and tax amount in that file (ot_cat_qvb_discount.php). I had to alter the code just to get it working at all. However, I'm still having the issue of the tax not being calculated correctly.

 

This was the original code:

 

		$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'];

 

Why would you add the $products_tax to the price? This will never equal the correct discount total. Then the tax_amount is being calculated as the total tax on one item in the cart before the discount. What kind of math is this? Very frustrating to say the least! We really need this to calculate tax correctly which is AFTER the discount has been deducted. Please help!

Share this post


Link to post
Share on other sites

Sorry for the stupid question, but about installing this contrib: do the files go under /includes/ in the admin folder, or the /includes folder in the root?

Share this post


Link to post
Share on other sites

And a follow-up question: Where exactly in the nested and product sections does the echo statement go?

Share this post


Link to post
Share on other sites

Ok, I got the installing dilemma sorted out on my own. Still trying to figure out where to place the discount text, but I think I will get the hang of it. It's been a while since I stared at PHP code.

 

A couple of more problems which have been referred to in this thread, but I don't think these features have been implemented in the current version of the contrib: First, the 'a' option is not coded in, is it? I mean percentage discount that some people asked about. A solution was sort of offered, but I would appreciate someoneshowing the exact code changes required.

 

Another item is that the discount isn't showing in the shopping cart with the current code. Again, this thing was discussed and apparently solved? Can anyone tell me what changes/additions are required, please?

 

I did seach this thread but I am still uncertain what's be best way to complement these. Thanks in advance.

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  

×