Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Category Discount


boxtel

Recommended Posts

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>

 

Hi Amanda. Thanks so much for what I know is going to be a great contribution!

I just tried installing it, and I've come up with a couple of issues.

1) When I display a category, I get this error:

Fatal error: Call to undefined function: tep_get_cat_path() in /home/lori/public_html/catalog/includes/modules/order_total/ot_cat_qvb_discount.php on line 161

 

I noticed that you had an includes/functions/ directory in the zip file, but there was nothing in the directory. Perhaps you forgot to include a file or function that is needed??

 

2) I'm having trouble figuring out where to insert the code that you have above, which I think you said goes in includes/application_top.php.

It looks like I do have some discounts installed in my version of oscommerce, although not the same ones you referred to. But I can't find them in application_top.php.

I'm not sure if this makes a difference, but I have BTS installed (Basic Template System), so things might be in slightly different places. I did a bunch of greps, but couldn't find an obvious place for this code.

 

Please help! This really looks like it's going to be a great addition to my site!

 

3) I apologize--I didn't mean to imply that your site was just an example site, just that it demonstrated an example of using this contribution. I think it looks great! It is visually appealing, and I can see that you put lots of work into it! I'd like to strive to have my site looking that nice. Right now I'm just in the beginning stages of figuring out which contributions and changes I need on my site.

 

Thanks very much for your help!

Regards,

-Lori-

Link to comment
Share on other sites

  • Replies 169
  • Created
  • Last Reply

Top Posters In This Topic

Hi Amanda. Thanks so much for what I know is going to be a great contribution!

I just tried installing it, and I've come up with a couple of issues.

1) When I display a category, I get this error:

Fatal error: Call to undefined function: tep_get_cat_path() in /home/lori/public_html/catalog/includes/modules/order_total/ot_cat_qvb_discount.php on line 161

 

I noticed that you had an includes/functions/ directory in the zip file, but there was nothing in the directory. Perhaps you forgot to include a file or function that is needed??

 

2) I'm having trouble figuring out where to insert the code that you have above, which I think you said goes in includes/application_top.php.

It looks like I do have some discounts installed in my version of oscommerce, although not the same ones you referred to. But I can't find them in application_top.php.

I'm not sure if this makes a difference, but I have BTS installed (Basic Template System), so things might be in slightly different places. I did a bunch of greps, but couldn't find an obvious place for this code.

 

Please help! This really looks like it's going to be a great addition to my site!

 

3) I apologize--I didn't mean to imply that your site was just an example site, just that it demonstrated an example of using this contribution. I think it looks great! It is visually appealing, and I can see that you put lots of work into it! I'd like to strive to have my site looking that nice. Right now I'm just in the beginning stages of figuring out which contributions and changes I need on my site.

 

Thanks very much for your help!

Regards,

-Lori-

 

ah yes, probably forgot that function again.

 

simply add this function to your includes/functions/general.php file

 

function tep_get_cat_path ($current_category_id = '') {

$last_category['parent_id'] = 1;

$cat_string = $current_category_id;

while ($last_category['parent_id'] != 0) {

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

$current_category_id = $last_category['parent_id'];

}

return $cat_string;

}

 

 

the code above is for the display of the discount in the shopping cart (where it displays the subtotal of the cart) and is not to go in application_top. what I meant to say is that I set the variable $cart_total in application top like :

 

$cart_total = $cart->show_total();

 

because that function does a full cart recalculation including database calls so you do not want to call that function every time you want to have the total of the cart. So just call it once and keep the value for multiple use.

 

if you do not have easy discount or 2gether discount installed, simply remove the references to them like :

 

<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;

}

}

 

 

if ($new_total != $cart_total) { // is there a difference between original subtotal and new subtotal

if ($new_total == 0) { // is the new subtotal zero -> display FREE instead of $0.00

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

Link to comment
Share on other sites

...

 

the code above is for the display of the discount in the shopping cart (where it displays the subtotal of the cart) and is not to go in application_top. what I meant to say is that I set the variable $cart_total in application top like :

 

$cart_total = $cart->show_total();

 

because that function does a full cart recalculation including database calls so you do not want to call that function every time you want to have the total of the cart. So just call it once and keep the value for multiple use.

 

if you do not have easy discount or 2gether discount installed, simply remove the references to them like :

 

<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;

}

}

if ($new_total != $cart_total) { // is there a difference between original subtotal and new subtotal

if ($new_total == 0) { // is the new subtotal zero -> display FREE instead of $0.00

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>

 

Sorry, I don't understand--which file should the above code go in?

 

Thanks very much.

Regards,

-Lori-

Link to comment
Share on other sites

Amanda,

Ok, I've added the function tep_get_cat_path to includes/functions/general.php, and I've added the new code to shopping_cart.php.

I have the following discount specified:

"3:ME:V:2;2;3;8"

I sell cases of juice. They cost $37 each. My intent is that 1 case costs $37, 2 cases cost $35 each ($2 discount per case), and 3 or more cases cost $29 each ($8 discount per case).

I think I'm using this in the right way, aren't I?

So, if I order 3 cases of juice, it should give me a discount of $8 * 3 = $24.

But what it's actually doing is taking the total cart amount, $111 (which is $37 * 3), and multiplying this by 8 to give me a discount of $888.

I put debugging statements in the discount_amount function, and this is what I get:

Entering discount_amount. dc_type: ME; th_type: V; cart_amount: $111.00; value: 111; threshold: 3; discount_amount: 8

od_amount: 888

 

I think this function needs as a parameter the quantity of items ordered in this category.

 

Ok, that's where I am so far. I'll try making some progress on it. Or, if it is very simple for you, and you have a few minutes, could you please give me suggestions on how to fix things.

 

Thanks very much!

Regards,

-Lori-

Link to comment
Share on other sites

Amanda,

Ok, I've added the function tep_get_cat_path to includes/functions/general.php, and I've added the new code to shopping_cart.php.

I have the following discount specified:

"3:ME:V:2;2;3;8"

I sell cases of juice. They cost $37 each. My intent is that 1 case costs $37, 2 cases cost $35 each ($2 discount per case), and 3 or more cases cost $29 each ($8 discount per case).

I think I'm using this in the right way, aren't I?

So, if I order 3 cases of juice, it should give me a discount of $8 * 3 = $24.

But what it's actually doing is taking the total cart amount, $111 (which is $37 * 3), and multiplying this by 8 to give me a discount of $888.

I put debugging statements in the discount_amount function, and this is what I get:

Entering discount_amount. dc_type: ME; th_type: V; cart_amount: $111.00; value: 111; threshold: 3; discount_amount: 8

od_amount: 888

 

I think this function needs as a parameter the quantity of items ordered in this category.

 

Ok, that's where I am so far. I'll try making some progress on it. Or, if it is very simple for you, and you have a few minutes, could you please give me suggestions on how to fix things.

 

Thanks very much!

Regards,

-Lori-

Oops, I just realized that I needed to change from 'V' to 'Q' in the discount specification.

So, the discount occurs when you have a "quantity" of 2 or 3, not a "value" of 2 or 3.

I switched that ("3:ME:Q:2;2;3;8") and it then calculated the discount correctly.

 

When I click on "checkout", it redirects me to:

https://www.mydomain.com/catalog/checkout_s...LECTED_SELECTED.

I'm not sure whether or not this is related to the new mod, or if it is because I just started using categories, and there is a problem there. So it's back to the drawing board for me...

 

-Lori-

Link to comment
Share on other sites

A few changes I had to make:

 

In shopping_cart.php and index.php, I had to change from

if (MODULE_CAT_QVB_DISCOUNT_STATUS)

to

if (MODULE_CAT_QVB_DISCOUNT_STATUS == 'true')

 

In shopping_cart.php, within

if (MODULE_CAT_QVB_DISCOUNT_STATUS == 'true') {

...

}

 

I think the closing "}" comes too soon.

I think it needs to include the following part:

if ($new_total != $cart_total) { // is there a difference between original subtotal and new subtotal

...

}

Otherwise, if the module is turned off, it will still execute that part.

 

That's it for now.

Now I have to figure out why I'm getting an error from the Multi-Vendor Shipping mod when I try to checkout.

 

-Lori-

Link to comment
Share on other sites

A few changes I had to make:

 

In shopping_cart.php and index.php, I had to change from

if (MODULE_CAT_QVB_DISCOUNT_STATUS)

to

if (MODULE_CAT_QVB_DISCOUNT_STATUS == 'true')

 

In shopping_cart.php, within

if (MODULE_CAT_QVB_DISCOUNT_STATUS == 'true') {

...

}

 

I think the closing "}" comes too soon.

I think it needs to include the following part:

if ($new_total != $cart_total) { // is there a difference between original subtotal and new subtotal

...

}

Otherwise, if the module is turned off, it will still execute that part.

 

That's it for now.

Now I have to figure out why I'm getting an error from the Multi-Vendor Shipping mod when I try to checkout.

 

-Lori-

 

ah yes, they are string based switches.

 

no, the } does not come too soon. the structure is set up so it only shows the total value in addition to the original subtotal if they differ. They can differ by several discounts in between:

 

new total = subtotal

 

discount from x -> new total changed or not

 

discount from y -> new total changed or not

 

if new total differs from subtotal

display the total field

 

so if all discounts do not alter anything to the subtotal we do not display the new total field.

Treasurer MFC

Link to comment
Share on other sites

ah yes, they are string based switches.

 

no, the } does not come too soon. the structure is set up so it only shows the total value in addition to the original subtotal if they differ. They can differ by several discounts in between:

 

new total = subtotal

 

discount from x -> new total changed or not

 

discount from y -> new total changed or not

 

if new total differs from subtotal

display the total field

 

so if all discounts do not alter anything to the subtotal we do not display the new total field.

Sorry, you're right. I had forgotten to include the line:

$new_total = $cart_total;

at the beginning of the additions in shopping_cart.php.

Link to comment
Share on other sites

A few more things on the Category Tree QVB Discount:

 

- When I got to checkout_confirmation.php, it didn't show the discount. Is there some additional code I need to add so that it shows the discount?

- When I processed the order, and it sent me the email, it didn't show the discount in the email. Is there some additional code I need to add so that the discount is used in processing the final order? (And, it would need to be used in the payment module--I avoided that part for now by choosing the "Cash on Delivery" module.)

- I have a little box on the top right which shows the shopping cart contents at all times--I think this is an add-on. How would I display the discount there?

 

Thanks very much!

Regards,

-Lori-

Link to comment
Share on other sites

A few more things on the Category Tree QVB Discount:

 

- When I got to checkout_confirmation.php, it didn't show the discount. Is there some additional code I need to add so that it shows the discount?

- When I processed the order, and it sent me the email, it didn't show the discount in the email. Is there some additional code I need to add so that the discount is used in processing the final order? (And, it would need to be used in the payment module--I avoided that part for now by choosing the "Cash on Delivery" module.)

- I have a little box on the top right which shows the shopping cart contents at all times--I think this is an add-on. How would I display the discount there?

 

Thanks very much!

Regards,

-Lori-

I did lots of tracing through the code, and made some major progress. It turns out that this module had the same sort order as the shipping module: 2, so it was getting overwritten in one of the arrays. I changed its sort order to 6, and now the discount shows up in checkout_confirmation.php.

 

However, I still have the problem that the discount doesn't show up in the shopping cart box on the right side of the page, which is in includes/boxes/shopping_cart.php. I'm going to work on adding some extra code to display the discount there, like the code you gave me for the top-level shopping_cart.php.

 

-Lori-

Link to comment
Share on other sites

I did lots of tracing through the code, and made some major progress. It turns out that this module had the same sort order as the shipping module: 2, so it was getting overwritten in one of the arrays. I changed its sort order to 6, and now the discount shows up in checkout_confirmation.php.

 

However, I still have the problem that the discount doesn't show up in the shopping cart box on the right side of the page, which is in includes/boxes/shopping_cart.php. I'm going to work on adding some extra code to display the discount there, like the code you gave me for the top-level shopping_cart.php.

 

-Lori-

personally I do not display it there seperately, I just add it to the others and show it combined.

Treasurer MFC

Link to comment
Share on other sites

personally I do not display it there seperately, I just add it to the others and show it combined.

Amanda,

That sounds like a good idea, since there is so little space.

Do you have code that I could use to display it in the shopping cart box?

I was having some problems when I was trying to modify the code there, since certain things were not available in the environment. For example, when I had moved the display_cart() function to application_top.php, application_top.php was not included in this file (the boxes shopping_cart.php file). I also had certain other classes not available. So, if you have code you've already written that works with this file, that would be really helpful to me. Thanks!

 

Regards,

-Lori-

Link to comment
Share on other sites

Amanda,

That sounds like a good idea, since there is so little space.

Do you have code that I could use to display it in the shopping cart box?

I was having some problems when I was trying to modify the code there, since certain things were not available in the environment. For example, when I had moved the display_cart() function to application_top.php, application_top.php was not included in this file (the boxes shopping_cart.php file). I also had certain other classes not available. So, if you have code you've already written that works with this file, that would be really helpful to me. Thanks!

 

Regards,

-Lori-

Amanda,

A specific problem I am having is as follows:

I've gotten the shopping cart box to show the total after the discount, on some pages.

But, when I checkout, and I get to the page checkout_confirmation.php, I get the error:

Fatal error: Cannot redeclare class ot_cat_qvb_discount in .../includes/modules/order_total/ot_cat_qvb_discount.php on line 5

 

I suspect that this is because checkout_confirmation.php finds all the order_total modules, and loads each one that is active, which defines the class. Then, in the shopping cart box, I am explicitly including the ot_cat_qvb_discount.php files, and this causes the conflict.

 

However, I even tried defining a variable at the end of this file, $otcatqvb, and then surrounding the code in the file with:

if (! isset($otcatqvb)) {

...

}

 

I thought that this would only allow the code in the file to be executed once, so I wouldn't get this error. But I am still getting it.

 

I'd really appreciate any help with this!! Perhaps whatever code you used in

includes/boxes/shopping_cart.php, and any other changes you made that you think might help.

 

Thanks so much for your help with this! It's a great contribution!

 

Regards,

-Lori-

Link to comment
Share on other sites

Amanda,

A specific problem I am having is as follows:

I've gotten the shopping cart box to show the total after the discount, on some pages.

But, when I checkout, and I get to the page checkout_confirmation.php, I get the error:

Fatal error: Cannot redeclare class ot_cat_qvb_discount in .../includes/modules/order_total/ot_cat_qvb_discount.php on line 5

 

I suspect that this is because checkout_confirmation.php finds all the order_total modules, and loads each one that is active, which defines the class. Then, in the shopping cart box, I am explicitly including the ot_cat_qvb_discount.php files, and this causes the conflict.

 

However, I even tried defining a variable at the end of this file, $otcatqvb, and then surrounding the code in the file with:

if (! isset($otcatqvb)) {

...

}

 

I thought that this would only allow the code in the file to be executed once, so I wouldn't get this error. But I am still getting it.

 

I'd really appreciate any help with this!! Perhaps whatever code you used in

includes/boxes/shopping_cart.php, and any other changes you made that you think might help.

 

Thanks so much for your help with this! It's a great contribution!

 

Regards,

-Lori-

 

 

in the shopping_cart box:

 

// 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 changed the function display_discounts in the ot module so you can call it via:

 

$cat_qvb_discount->display_discounts(false);

 

which will cause it not to display the individual discount lines but only return the total.

 

 

// display the discounts in the cart

function display_discounts ($echo = true) {

 

$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++) {

if ($echo) {

echo '<tr><td align="right">'.$this->output[$x]['title'].'</td><td align="right">'.$this->output[$x]['text'].'</td></tr>';

}

}

return $this->deduction;

}

 

 

ps. this I do not understand:

when I had moved the display_cart() function to application_top.php

Treasurer MFC

Link to comment
Share on other sites

Amanda,

 

 

 

 

I'm testing Category Tree QVB Discount with the following:

 

Discount Rate is set to: 21:IM:Q:10;1

 

The following 2 products are in that category

 

Price

 

product_a = $4.00

 

product_b = $0.24

 

 

 

Scenario 1

 

Now when I place qty = 10 from product_a I see a discount of $-4.00 correct sofar,

 

Now when I place qty = 10 from product _b I see a discount of $-4.24 also correct.

 

 

 

Scenario 2

 

Now when I place qty = 10 from product_a I see a discount of $-4.00 correct sofar,

 

Now when I place qty = 1 from product _b the discount changes to $-3.64

 

The sequence looks like this until qty = 10 of product_b is reached.

 

Throughout this sequence product_a is always qty = 10

 

Discount

 

Product_b qty = 1 $-3.64

 

Product_b qty = 2 $-3.37

 

Product_b qyt = 3 $-3.13

 

Product_b qty = 4 $-2.91

 

* * *

 

Product _b qty = 9 $-2.20

 

Product_b qty = 10 $ $-4.24 <- Finally correct discount amount

 

 

 

The discounts shows in the shopping cart as the sequence above.

 

I expected the discount to stay at $-4.00 until product_b reach the qty= 10 threshold

 

 

 

I trace the discount calculation to function discount_amount ()

 

Now for testing this function the cart has

 

Product_a qty = 10

 

Product b qty = 1

 

The parameters entering this function have the following values

 

 

 

dc_type = IM

 

$th_type = Q

 

$cart_amount = 11

 

$value = 40.24

 

$threshold = 10

 

$discount_amount = 1

 

 

 

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

 

 

 

In the switch statement is goes to case 'IM'

 

Now the calculation

 

$od_amount = floor(($cart_amount / $threshold)) * ($value/$cart_amount) * $discount_amount;

 

from the parameters passed to the function it gets evaluated to 3.65818181??.

 

 

 

This is the discount amount the shows up in the shopping cart 3.65818181 formated to 3.64

 

 

 

I expected the discount to stay at $-4.00 until product_b reach the qty= 10 threshold

Looks like the calculation discount valuates correctly when each of the product are at there threshold but anything between the threshold looks like the wrong discount. Am I over looking something?

 

Regards,

Marizka

Link to comment
Share on other sites

Amanda,

I'm testing Category Tree QVB Discount with the following:

Discount Rate is set to: 21:IM:Q:10;1

The following 2 products are in that category

Price

product_a = $4.00

product_b = $0.24

Scenario 1

Now when I place qty = 10 from product_a I see a discount of $-4.00 correct sofar,

Now when I place qty = 10 from product _b I see a discount of $-4.24 also correct.

Scenario 2

Now when I place qty = 10 from product_a I see a discount of $-4.00 correct sofar,

Now when I place qty = 1 from product _b the discount changes to $-3.64

The sequence looks like this until qty = 10 of product_b is reached.

Throughout this sequence product_a is always qty = 10

Discount

Product_b qty = 1 $-3.64

Product_b qty = 2 $-3.37

Product_b qyt = 3 $-3.13

Product_b qty = 4 $-2.91

* * *

Product _b qty = 9 $-2.20

Product_b qty = 10 $ $-4.24 <- Finally correct discount amount

The discounts shows in the shopping cart as the sequence above.

I expected the discount to stay at $-4.00 until product_b reach the qty= 10 threshold

I trace the discount calculation to function discount_amount ()

Now for testing this function the cart has

Product_a qty = 10

Product b qty = 1

The parameters entering this function have the following values

dc_type = IM

$th_type = Q

$cart_amount = 11

$value = 40.24

$threshold = 10

$discount_amount = 1

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

In the switch statement is goes to case 'IM'

Now the calculation

$od_amount = floor(($cart_amount / $threshold)) * ($value/$cart_amount) * $discount_amount;

from the parameters passed to the function it gets evaluated to 3.65818181??.

This is the discount amount the shows up in the shopping cart 3.65818181 formated to 3.64

I expected the discount to stay at $-4.00 until product_b reach the qty= 10 threshold

Looks like the calculation discount valuates correctly when each of the product are at there threshold but anything between the threshold looks like the wrong discount. Am I over looking something?

Regards,

Marizka

Here is another test case

 

This time Discount Rate is set to: 21:IM:Q:10;1,26:IM:Q:10;1

 

Product_a from categorie_26 = $5.20

 

Product_b from categorie_21=$0.25

 

Senario_3

 

In cart

 

 

Now when I place qty = 10 from product_a discount of $-5.20 correct,

 

In cart

 

Now when I place qty = 10 from product_a

 

 

Now when I place qty = 10 from product _b discount of $-5.45 correct.

 

Senario_4

 

In cart

 

Now when I place qty = 10 from product_a

 

 

Now when I place qty = 1 from product _b the discount stays at $-5.20 correct.

 

Throughout this sequence product_a is always qty = 10

Discount

Product_b qty = 1 discount $-5.20

Product_b qty = 2 $-5.20

Product_b qyt = 3 $-5.20

Product_b qty = 4 $-5.20

* * *

 

Product _b qty = 9 $-5.20

Product_b qty = 10 $ $-5.45 <- Throughout the sequence the discount stays at $-5.20 like expected, once product_b reaches the qty=10 threshold then the discount becomes $-5.45.

 

Senario_5

 

Product_a from categorie_26 = $5.20

 

Product_b from categorie_26=$16.96

 

In cart

 

Product_a qty=10 discount $-5.20 Expected result

 

In cart

 

Product_a qty=10

 

Product_b qty=10 discount $-22.16 Expected result

 

In cart

 

Product_a qty=10

 

Product_b qty=1 discount $-6.25 Expected $-$5.20 product_a is at qty=10 threshold. Same symptom as scenario_2

 

Is anybody else seeing there discounts behave this way?

 

Regards,

 

Marizka

Link to comment
Share on other sites

Amanda,

I'm testing Category Tree QVB Discount with the following:

 

Discount Rate is set to: 21:IM:Q:10;1

 

The following 2 products are in that category

 

Price

 

product_a = $4.00

 

product_b = $0.24

 

 

 

Scenario 1

 

Now when I place qty = 10 from product_a I see a discount of $-4.00 correct sofar,

 

Now when I place qty = 10 from product _b I see a discount of $-4.24 also correct.

 

 

 

Scenario 2

 

Now when I place qty = 10 from product_a I see a discount of $-4.00 correct sofar,

 

Now when I place qty = 1 from product _b the discount changes to $-3.64

 

The sequence looks like this until qty = 10 of product_b is reached.

 

Throughout this sequence product_a is always qty = 10

 

Discount

 

Product_b qty = 1 $-3.64

 

Product_b qty = 2 $-3.37

 

Product_b qyt = 3 $-3.13

 

Product_b qty = 4 $-2.91

 

* * *

 

Product _b qty = 9 $-2.20

 

Product_b qty = 10 $ $-4.24 <- Finally correct discount amount

 

 

 

The discounts shows in the shopping cart as the sequence above.

 

I expected the discount to stay at $-4.00 until product_b reach the qty= 10 threshold

 

 

 

I trace the discount calculation to function discount_amount ()

 

Now for testing this function the cart has

 

Product_a qty = 10

 

Product b qty = 1

 

The parameters entering this function have the following values

 

 

 

dc_type = IM

 

$th_type = Q

 

$cart_amount = 11

 

$value = 40.24

 

$threshold = 10

 

$discount_amount = 1

 

 

 

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

 

 

 

In the switch statement is goes to case 'IM'

 

Now the calculation

 

$od_amount = floor(($cart_amount / $threshold)) * ($value/$cart_amount) * $discount_amount;

 

from the parameters passed to the function it gets evaluated to 3.65818181??.

 

 

 

This is the discount amount the shows up in the shopping cart 3.65818181 formated to 3.64

 

 

 

I expected the discount to stay at $-4.00 until product_b reach the qty= 10 threshold

Looks like the calculation discount valuates correctly when each of the product are at there threshold but anything between the threshold looks like the wrong discount. Am I over looking something?

 

Regards,

Marizka

 

You are using IM (item multiple) on a category with very different prices, that is not a good idea.

 

IM basically sets buy 5 get 1 for free but you can ofcourse only give a money discount.

But in a category with products having very different prices, which item is then for free, product a at $4 or product b at $0.24 ? The module has no way of knowing that.

 

This is why the IM method calculates the average price value of the items of that category in the cart and uses that amount as the discount.

 

10 product A = $40

1 product B = $0.24

total value = $40.24

average value = $40.24/11 = $3.6

 

10 product A = $40

2 product B = $0.48

total value = $40.48

average value = $40.48/12 = $3.3

 

So when in categories with products having very different prices you better use a money discount.

Treasurer MFC

Link to comment
Share on other sites

in the shopping_cart box:

 

// 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 changed the function display_discounts in the ot module so you can call it via:

 

$cat_qvb_discount->display_discounts(false);

 

which will cause it not to display the individual discount lines but only return the total.

// display the discounts in the cart

function display_discounts ($echo = true) {

 

$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++) {

if ($echo) {

echo '<tr><td align="right">'.$this->output[$x]['title'].'</td><td align="right">'.$this->output[$x]['text'].'</td></tr>';

}

}

return $this->deduction;

}

Amanda,

Thanks, this is great!

Sorry for not continuing with this for so long--I was out of town for a couple of weeks.

I have a question. In the shopping cart box, it looks like you probably combine all the different discounts together, and then just display the total discount, or something like that, because I see

$discounts = $discounts + $cat_deduction;

Right now, this is my only type of discount, but would you mind showing me how you display the discount in the shopping cart box, so that it looks decent?

 

Thanks very much!

Regards,

-Lori-

Link to comment
Share on other sites

Amanda,

Thanks, this is great!

Sorry for not continuing with this for so long--I was out of town for a couple of weeks.

I have a question. In the shopping cart box, it looks like you probably combine all the different discounts together, and then just display the total discount, or something like that, because I see

$discounts = $discounts + $cat_deduction;

Right now, this is my only type of discount, but would you mind showing me how you display the discount in the shopping cart box, so that it looks decent?

 

Thanks very much!

Regards,

-Lori-

Amanda,

One other thing. I did put a simplistic line into the shopping cart box, so that it just prints:

Total after discounts: $xxx

 

Now, I start at the index.php page, and I add 3 cases of juice to my cart (there is a discount of $8 off per case for 3 or more cases). It takes me back to the index.php page, and the shopping cart box does not show the discount, it just shows the total without the discount.

The same happens if I add a 4th case of juice to the cart.

But, if I then click on the "cart contents" (shopping_cart.php) or "checkout" (checkout_shipping.php) links, it does display the line

"total after discounts: $87", after displaying the total cost.

I am using a mod, AddMultiProducts, which lets you specify how many of each product you want to add, and then click the "add to cart" button. I don't know if that is somehow interacting with the Category QVB Discount module on the index.php page, for the shopping cart box. Any suggestions?

 

Thanks very much for your help, and for a great contribution!

 

Regards,

-Lori-

Link to comment
Share on other sites

HELP! I am having a lot of trouble doing the initial install of Category Discount (Contribution 3926).

 

1st question: Where should the "echo category_discount_display($current_category_id);" lines be insered EXACTLY? Here is what my index.php looks like:

 

} else {

$category_parent_query = tep_db_query("select count(*) as total from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$current_category_id . "'");

$category_parent = tep_db_fetch_array($category_parent_query);

if ($category_parent['total'] > 0) {

$category_depth = 'nested'; // navigate through the categories

echo category_discount_display($current_category_id);

} else {

$category_depth = 'products'; // category has no products, but display the 'no products' message

echo category_discount_display($current_category_id);

}

}

 

I am getting this error message on top of the main page so I don't think above is correct:

 

correct version of tep_get_cat_path function : 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; } }

 

2ND QUESTION:

I added this to the general.php file at the very end of the file:

//---PayPal WPP Modification START ---//

function tep_paypal_wpp_enabled() {

$paypal_wpp_check = tep_db_query("SELECT configuration_id FROM " . TABLE_CONFIGURATION . " WHERE configuration_key = 'MODULE_PAYMENT_PAYPAL_DP_STATUS' AND configuration_value = 'True'");

if (tep_db_num_rows($paypal_wpp_check)) {

return true;

} else {

return false;

}

}

//---PayPal WPP Modification END ---//

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;

}

 

IS IT SUPPOSED TO GO SOMEWHERE ELSE IN GENERAL.PHP?

 

3RD QUESTION involves installing module through admin:

1) add the files to their respective directory and install the module in admin modules->order totals

 

includes/modules/order_total/ot_cat_qty_discount.php

includes/languages/english/modules/order_total/ot_cat_qty_discount.php

 

I COULD NOT FIGURE OUT HOW YOU INSTALL THE 2ND ONE LISTED.

 

SORRY IF THESE TOPICS HAVE ALREADY BEEN ADDRESSED. I AM A COMPLETE NEWBIE AT THIS.

Link to comment
Share on other sites

OK please ignore a lot of the above, I did some searching and have it "bascially working".

 

I still have these issues:

Where does "echo category_discount_display($current_category_id);" EXACTLY go in the Products section of index.php?

 

Right now the discount ONLY shows up on the Order Confirmation Page. How do you get it to show up in the shopping cart?

 

My discount setting is 22:2:7:p

I thought this meant a buyer would get a 7% discount on 2 or more items purchased from category 22. The discount shown is $14 (2 x $7). How does one give a PERCENTAGE discount?

 

Here is the website I am working on: https://www.rainbowbabe.com/catalog/index.php

 

Thanks in advance for any help you can provide.

Link to comment
Share on other sites

in the shopping_cart box:

 

// 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 changed the function display_discounts in the ot module so you can call it via:

 

$cat_qvb_discount->display_discounts(false);

 

which will cause it not to display the individual discount lines but only return the total.

// display the discounts in the cart

function display_discounts ($echo = true) {

 

$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++) {

if ($echo) {

echo '<tr><td align="right">'.$this->output[$x]['title'].'</td><td align="right">'.$this->output[$x]['text'].'</td></tr>';

}

}

return $this->deduction;

}

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-

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...