Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Category Discount


boxtel

Recommended Posts

like the instructions state:

 

4) in index.php in the "nested" AND in the "products" section you add

echo category_discount_display($current_category_id);

so you have to add that statement twice in index.php.

"the discount does not get calculated once you checkout"

 

where are you expecting to see the calculation ?

 

I have included the code twice in Index.php one in nested and one in products.

 

 

I actually purchased a few item from my own store to see if this worked and I was charged full price...

Edited by EidolonNight

James Tomasello

Link to comment
Share on other sites

  • Replies 169
  • Created
  • Last Reply

Top Posters In This Topic

I have included the code twice in Index.php one in nested and one in products.

I actually purchased a few item from my own store to see if this worked and I was charged full price...

 

 

well, it is not showing there so check that you have it just before the call to include the module product_listing.php.

 

check your sort order of the ot module, see if it does not conflict with other modules, I cannot test it for you as you require a CC before checkout and your pages load very slow. (lose the category counts).

Treasurer MFC

Link to comment
Share on other sites

well, it is not showing there so check that you have it just before the call to include the module product_listing.php.

 

check your sort order of the ot module, see if it does not conflict with other modules, I cannot test it for you as you require a CC before checkout and your pages load very slow. (lose the category counts).

 

use this in includes/functions/category_discount.php for toplevel name

 

 

<?php

function tep_get_category_name($category_id, $languages_id) {

$category_query = tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . (int)$category_id . "' and language_id = '" . (int)$languages_id . "'");

$category = tep_db_fetch_array($category_query);

return $category['categories_name'];

}

 

function category_discount_display ($current_category_id) {

global $category, $currencies, $languages_id;

 

$cat_disc_message = '';

 

if (MODULE_CAT_QTY_DISCOUNT_STATUS == 'true') {

$discount_rate = split("[:,]" , MODULE_CAT_QTY_DISCOUNT_RATES);

$size = sizeof($discount_rate);

for ($i=0; $i<$size; $i+=4) {

$cat_disc_message = '';

$cat_path = tep_get_cat_path($current_category_id);

$cat_path_array = split("_" , $cat_path);

$cat_name = tep_get_category_name($discount_rate[$i], $languages_id);

if (in_array($discount_rate[$i],$cat_path_array)) {

switch ($discount_rate[$i+3]) {

case 'q' : $cat_disc_message = sprintf(CAT_DISCOUNT_SPECIAL_QTY, $discount_rate[$i+1],$cat_name,$discount_rate[$i+2]);

break;

case 'm' : $money = $currencies->format($discount_rate[$i+2]);

$cat_disc_message = sprintf(CAT_DISCOUNT_SPECIAL_MON, $discount_rate[$i+1],$cat_name,$money);

break;

case 'p' : $money = $currencies->format($discount_rate[$i+2]);

$cat_disc_message = sprintf(CAT_DISCOUNT_SPECIAL_PRI, $discount_rate[$i+1],$cat_name,$money);

break;

default : $cat_disc_message = '';

break;

}

if ($cat_disc_message != '') {

$cat_disc_message = '<tr>

<td>'.tep_draw_separator('pixel_trans.gif', '100%', '10').'</td>

</tr>

<tr>

<td>

<table width=100% class="borderGray" cellpadding="4">

<tr>

<td><img src="images/save-icon_sm.gif" alt="$" title="$"></td>

<td align="center" width="100%" class="borderGray feat" bgcolor="#ffffe0">'.$cat_disc_message.'</td>

</tr>

</table>

</td>

</tr>

<tr>

<td>'.tep_draw_separator('pixel_trans.gif', '100%', '10').'</td>

</tr>';

}

break;

}

}

}

return $cat_disc_message;

}

?>

Treasurer MFC

Link to comment
Share on other sites

use this in includes/functions/category_discount.php for toplevel name

<?php

function tep_get_category_name($category_id, $languages_id) {

$category_query = tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . (int)$category_id . "' and language_id = '" . (int)$languages_id . "'");

$category = tep_db_fetch_array($category_query);

return $category['categories_name'];

}

 

function category_discount_display ($current_category_id) {

global $category, $currencies, $languages_id;

 

$cat_disc_message = '';

 

if (MODULE_CAT_QTY_DISCOUNT_STATUS == 'true') {

$discount_rate = split("[:,]" , MODULE_CAT_QTY_DISCOUNT_RATES);

$size = sizeof($discount_rate);

for ($i=0; $i<$size; $i+=4) {

$cat_disc_message = '';

$cat_path = tep_get_cat_path($current_category_id);

$cat_path_array = split("_" , $cat_path);

$cat_name = tep_get_category_name($discount_rate[$i], $languages_id);

if (in_array($discount_rate[$i],$cat_path_array)) {

switch ($discount_rate[$i+3]) {

case 'q' : $cat_disc_message = sprintf(CAT_DISCOUNT_SPECIAL_QTY, $discount_rate[$i+1],$cat_name,$discount_rate[$i+2]);

break;

case 'm' : $money = $currencies->format($discount_rate[$i+2]);

$cat_disc_message = sprintf(CAT_DISCOUNT_SPECIAL_MON, $discount_rate[$i+1],$cat_name,$money);

break;

case 'p' : $money = $currencies->format($discount_rate[$i+2]);

$cat_disc_message = sprintf(CAT_DISCOUNT_SPECIAL_PRI, $discount_rate[$i+1],$cat_name,$money);

break;

default : $cat_disc_message = '';

break;

}

if ($cat_disc_message != '') {

$cat_disc_message = '<tr>

<td>'.tep_draw_separator('pixel_trans.gif', '100%', '10').'</td>

</tr>

<tr>

<td>

<table width=100% class="borderGray" cellpadding="4">

<tr>

<td><img src="images/save-icon_sm.gif" alt="$" title="$"></td>

<td align="center" width="100%" class="borderGray feat" bgcolor="#ffffe0">'.$cat_disc_message.'</td>

</tr>

</table>

</td>

</tr>

<tr>

<td>'.tep_draw_separator('pixel_trans.gif', '100%', '10').'</td>

</tr>';

}

break;

}

}

}

return $cat_disc_message;

}

?>

 

 

and change the tep_get_cat_path function to this (one . too many):

 

 

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;

}

}

Treasurer MFC

Link to comment
Share on other sites

Alright... the CC module has been modified to use Cash on Delivery for testing purposes. I also double checked the placement of the display directly before the call to include the module product_listing. For the sort order, everything has it's own number.... I think I'll come back to this tomorrow and start fresh..

 

Thank you again

James Tomasello

Link to comment
Share on other sites

Alright... the CC module has been modified to use Cash on Delivery for testing purposes. I also double checked the placement of the display directly before the call to include the module product_listing. For the sort order, everything has it's own number.... I think I'll come back to this tomorrow and start fresh..

 

Thank you again

 

well, this is on your site :

 

sports.jpg

Treasurer MFC

Link to comment
Share on other sites

so your ot module is ok, the only thing is the recognition of cat depth > 2 levels so make sure you make the last change.

 

if in the file includes/functions/category_discount.php

 

you move these 2 statement:

 

$cat_path = tep_get_cat_path($current_category_id);

$cat_path_array = split("_" , $cat_path);

 

above this statement:

 

for ($i=0; $i<$size; $i+=4) {

 

it will save you some (number of conditions - 1) queries.

 

and use this simplified version of tep_get_cat_path in general.php

 

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;

}

Treasurer MFC

Link to comment
Share on other sites

  • 3 weeks later...

Hello again Amanda,

 

I'm trying to put a new type for category discount, but I can't. That I want is to make a 10% Discount to the products of a category if the client buy 2 or more products.

 

I tried this:

 

case 'a' : if ($cat_qty_discount_array[$i]['cqty'] >= $cat_qty_discount_array[$i]['xqty']) {

$od_amount = $od_amount + ($cat_qty_discount_array[$i]['price'] * $cat_qty_discount_array[$i]['yqty'] / 100);

}

break;

 

But $cat_qty_discount_array[$i]['price'] is only the price of the last product added of this category, and I need a variable with the price of the total of products of this category added to the shopping cart.

 

How can I do it?

Link to comment
Share on other sites

Hello again Amanda,

 

I'm trying to put a new type for category discount, but I can't. That I want is to make a 10% Discount to the products of a category if the client buy 2 or more products.

 

I tried this:

 

case 'a' : if ($cat_qty_discount_array[$i]['cqty'] >= $cat_qty_discount_array[$i]['xqty']) {

$od_amount = $od_amount + ($cat_qty_discount_array[$i]['price'] * $cat_qty_discount_array[$i]['yqty'] / 100);

}

break;

 

But $cat_qty_discount_array[$i]['price'] is only the price of the last product added of this category, and I need a variable with the price of the total of products of this category added to the shopping cart.

 

How can I do it?

 

yes, that was because of the q discount.

 

in the order total module ot_cat_qty_discount.php

you can change this line:

 

$cat_qty_discount_array[$i]["price"] = $products[$p]['price'];

 

into this line:

 

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

 

which would result in that that field now will hold the total value of the items from that category.

as in quantity * price.

 

NOTE: this will give you wrong results when used with q discount unless you also change this line:

 

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

 

 

to this:

 

case 'q' : $od_amount = $od_amount + 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']) ;

Treasurer MFC

Link to comment
Share on other sites

Hello, It's me again!!

 

Your contib. works great! However, When a product option or attribute is selected it cancels out the discount. That is ok for some of the attributes because certain options change the price anyway. Some of these options are color choice only and it's ok to get the discount then. What I would like to see this contrib do is apply the dicount unless the price has been changed up or down due to attribute selections. Have you done this yet, or is it even possible? Thanks for your time! Talk to you later!!

 

Thank you!!!

James Tomasello

Link to comment
Share on other sites

Hi and thanks for the contribution.

 

However I can't get it to work correct if the products in a choosen Discount Category also is linked to another Category.

 

If I move the item from its original category to the Discount category it works fine, but if I make a link to the discount category it doesn't deduct the discount at checkout. I would really appreciate if someone could ghelp me solve this.

 

Thanks

 

//Fred

Link to comment
Share on other sites

Hi and thanks for the contribution.

 

However I can't get it to work correct if the products in a choosen Discount Category also is linked to another Category.

 

If I move the item from its original category to the Discount category it works fine, but if I make a link to the discount category it doesn't deduct the discount at checkout. I would really appreciate if someone could ghelp me solve this.

 

Thanks

 

//Fred

 

well, in the cases that a product can be linked to multiple categories then you need to create a loop in

the order total module.

 

currently it uses this query:

 

$cat_query = tep_db_query("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $t_prid . "'");

 

which determines the category the product belongs to and then determined the entire category path upwarts to see later if any of them is defined for discounts.

 

the code now takes 1 result from that query, so if there are more, run the query and subsequent logic in a loop.

Treasurer MFC

Link to comment
Share on other sites

well, in the cases that a product can be linked to multiple categories then you need to create a loop in

the order total module.

 

currently it uses this query:

 

$cat_query = tep_db_query("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $t_prid . "'");

 

which determines the category the product belongs to and then determined the entire category path upwarts to see later if any of them is defined for discounts.

 

the code now takes 1 result from that query, so if there are more, run the query and subsequent logic in a loop.

 

Thanks for your reply.

 

I have to admit that I'm not so good at this. So I would really appreciate if you could give me a hint on how to "run the query and subsequent logic in a loop"

Link to comment
Share on other sites

Wonderful contribution! It does everything I need it to so far, however I do have a question and try to bear with me as I am still learning php.

 

What I am wondering is if there is any way to setup different discount rates for each customer. I have a retail quantity discount and a wholesale discount table that I'm looking to use, but I don't want the retail customers seeing the wholesale pricing obviously. Is there any way to go about this? I have seen a contribution the gave seperate customer pricing, but that was item based, not category based.

 

Any help or ideas would be great!

 

Thanks,

Brendan.

Link to comment
Share on other sites

Hi,

 

can this contrib allow me to make a rule like:

buy 1 from cat x AND 1 from cat y AND 1 from cat z then give discount % on those items only ??

May need 4 products rather then 3.

 

Also - does it handle product attributes - other posting suggest it doesnt..

 

I have tried to do something similar using the ot_lev discount and this does handle attributes ok but when coupled with bundled products contrib to create bundles which contain 3 or more products I cannot get it to remove the extra discount from ot_lev discount contrib when attributes are used on the bundled product itself (yet - still working on that - something to do with {} in the products_id).

 

But the bundled products contrib doesnt let me actually choose the underlying products or thier attributes and you must pre-make your bundles, which isnt what i need.

 

I want to say buy 1 surfboard, 1 wetsuit and one pair of boots and get a % discount on those 3 items. If you remove one of these items then the discount goes away.. I will give it a try and see but the single attributes for two of these items (size) must be selectable and still apply the discount %.

 

can this contrib do that ?

Any slight mods to make it work in that way ?

 

thanks

mark

Regards

Mark Brindle

Link to comment
Share on other sites

Hello Amanda and other Category Discounters

 

Marvellous contribution especially through its simplicity and ease of install - great potential. A couple of remarks:

 

A good description of the various discount types would be :

 

A:Y:W:q, B:Y:X:p, C:Y:Z:m when prices in $ -

 

Q: Buy Y products in category A and get W products free (see point 1 below)

 

P: $X off each product when ordered Y or more from category B

 

M: $Z off sub-total for every Y products in category C

 

 

A couple of current bugs/oddities:

 

1) Q discount type: the W free items are the LAST ITEMS of category A added to the cart, it should be: W cheapest item(s) of cat A come free. See 2 posts up on how to solve this!

 

2) This contribution currently does not take into account products with attributes/options

 

Also the discount does currently not show up in the shopping cart info box and discounts within subcategories would be another great addition to this top-notch contribution. Another discount type could be: % - buy X products from category D and get Y % discount on all of these items (I am trying to get this done right now - will let you know)

 

Thanks Amanda!

 

Skylla

Edited by skylla
Link to comment
Share on other sites

Hello Amanda and other Category Discounters

 

Marvellous contribution especially through its simplicity and ease of install - great potential. A couple of remarks:

 

A good description of the various discount types would be :

 

A:Y:W:q, B:Y:X:p, C:Y:Z:m when prices in $ -

 

Q: Buy Y products in category A and get W products free (see point 1 below)

 

P: $X off each product when ordered Y or more from category B

 

M: $Z off sub-total for every Y products in category C

A couple of current bugs/oddities:

 

1) Q discount type: the W free items are the LAST ITEMS of category A added to the cart, it should be: W cheapest item(s) of cat A come free. See 2 posts up on how to solve this!

 

2) This contribution currently does not take into account products with attributes/options

 

Also the discount does currently not show up in the shopping cart info box and discounts within subcategories would be another great addition to this top-notch contribution. Another discount type could be: % - buy X products from category D and get Y % discount on all of these items (I am trying to get this done right now - will let you know)

 

Thanks Amanda!

 

Skylla

 

well, happy you like it, just do me one favor and don't use the terms bugs and oddities for designed behaviour, makes me very angry.

Treasurer MFC

Link to comment
Share on other sites

Sorry if I upset you Amanda, this, of course, was not intentionally and I would like to apologise. The last thing I want to do is to make you angry with all the hard and good work you put into this and many other fantastic contributions!

 

Please note that *the words* I used were regarding point 1) and 2) only. One man?s designed behaviour is another man?s ***** and I do think that the contribution would be opened up for a wider audience if these points can be taken into consideration.

 

The last paragraph of my post should not and was not to be read as an extension to point 1) and 2) ? hence not numbered 3) - they were just a couple of ideas from my distorted mind. It just happened that I was working on getting this done.

 

Skylla ? eating humble pie and looking for that back door?..

Link to comment
Share on other sites

I have a unique issue on my store. Bsically I want the following:

If someone adds 6-11 items (can be six completely different products from the category 21) to the cart, those items should be discounted by 10% and the discount should be reflected in the price shown. If they add 12 or more, the price should be discounted by 15%.

 

I tried to do this using this contrib. I added the following "Discount Rates"

21:6:10:p,21:12:15:p

This works well for the first part - i.e. it shows

Category Offer : Order 6 and we take $10.00 OFF each !

But what abt the formula for someone ordering > 12? How do i reflect that in my store?

Link to comment
Share on other sites

I also have another issue. When i select 11 items from the category, in the shopping cart, the price of the individual products shows up as discounted. I want to show something like this

 

Product A original Price A

Product B original price B

 

Subtotal original Subtotal

 

Category Discount (ir whatever words we decide) Some number

 

Total discounted total.

 

How do i do this?

Link to comment
Share on other sites

More issues with my store. This contribution works for just one product in the category. For example if i put 2 products in the cart, each quantity 10, it shows up the total of one of them as discounted, and another one as the original amount. Why is this happening? Why is this not showing up for all the products in the category?

I am really confused...Please help.

Will look at this tomorrow morning with a clearer head.

Link to comment
Share on other sites

Well I think I now know problem - even though I do not know the solution.

The contribution shows up fine on the admin->Modules->order total modules page. I can install it from there and add on my rules. Whe i enable the contribution, in the index page it shows up the text saying "Category Offer : Order 6 and we take $10.00 OFF each !" (Tho it shud say Category Offer : Order 6 and we take 10% OFF !)

But when i go to the cart and try to checkout, it doesnt show up any special discount option at all.

I had installed another contrib (handling fees) and it is also not behaving the way it should - i.e. it is also not showing up during the checkout process. So I think I am missing something trivial here. Any ideas what?

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