Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Category Discount


boxtel

Recommended Posts

  • Replies 169
  • Created
  • Last Reply

Top Posters In This Topic

Hello!!

 

I am trying your contrib. it seems like what I need but the method of entering the dicount info is a little confusing. So if I need items in category 232 regularly priced at $18 to be discounted to $15 when 2 or more is purchaced, what would that look like?

 

232:2:-3:q I think this would only take off $3.

 

I am a little lost... Please help when you get the time!

 

Thank you

James Tomasello

Link to comment
Share on other sites

Hi,

 

I've installed the module as per your installation, but it doesn't show on the product page that a discount can be applied, nor does it apply the discount at the checkout stage.

 

The only aspect of your installation file I found difficult to follow was this part:

 

3) in index.php just before you call product_listing.php to display the products

 

By this i assume you mean BEFORE this section? :

 

<?php include(DIR_WS_MODULES . FILENAME_PRODUCT_LISTING); ?>

Edited by rflack
Link to comment
Share on other sites

Hello!!

 

I am trying your contrib. it seems like what I need but the method of entering the dicount info is a little confusing. So if I need items in category 232 regularly priced at $18 to be discounted to $15 when 2 or more is purchaced, what would that look like?

 

232:2:-3:q I think this would only take off $3.

 

I am a little lost... Please help when you get the time!

 

Thank you

 

you cannot use negative values, discount is already negative.

232:2:3:q would mean: buy 2 from category 232 get 3 for free. So at checkout they would see a discount of 3 x $18 if they buy 2 items, 6 x $ 18 if they buy 4 items, etc.

 

the format = category_id:limit:qty/amount discount:discount type,.....

Treasurer MFC

Link to comment
Share on other sites

Hello!!

 

I am trying your contrib. it seems like what I need but the method of entering the dicount info is a little confusing. So if I need items in category 232 regularly priced at $18 to be discounted to $15 when 2 or more is purchaced, what would that look like?

 

232:2:-3:q I think this would only take off $3.

 

I am a little lost... Please help when you get the time!

 

Thank you

 

add a new discount type 'p' :

 

232:2:3:p

 

 

change the function in the module to this:

 

function calculate_discount($cat_qty_discount_array) {

global $qty_discount, $order_total_array;

 

$od_amount = 0;

if ((MODULE_CAT_QTY_DISCOUNT_DISABLE_WITH_COUPON == 'true') && (isset($_SESSION['cc_id']))) return $od_amount;

for ($i=0; $i<sizeof($cat_qty_discount_array); $i++) {

switch ($cat_qty_discount_array[$i]['type']) {

case 'm' : $od_amount = $od_amount + floor(($cat_qty_discount_array[$i]['cqty'] / $cat_qty_discount_array[$i]['xqty'])) * $cat_qty_discount_array[$i]['yqty'];

break;

case 'q' : $od_amount = $od_amount + floor(($cat_qty_discount_array[$i]['cqty'] / $cat_qty_discount_array[$i]['xqty'])) * $cat_qty_discount_array[$i]['yqty'] * $cat_qty_discount_array[$i]['price'];

break;

case 'p' : $od_amount = $od_amount + ($cat_qty_discount_array[$i]['cqty'] * $cat_qty_discount_array[$i]['yqty']);

break;

}

}

return $od_amount;

}

 

 

change the code in index.php to this:

 

<?php

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

if (me()) echo $discount_rate[$i+3];

if ($discount_rate[$i] == $current_category_id) {

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

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

break;

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

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

break;

case 'p' : $cat_disc_message = 'Buy '.$discount_rate[$i+1].' or more and we take '.$currencies->format($discount_rate[$i+2]).' off each !';

break;

default : $cat_disc_message = '';

break;

}

if ($cat_disc_message != '') {

?>

<tr>

<td><?php echo 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_blink.gif" alt="$" title="$"></td>

<td align="center" width="100%" class="borderGray feat" bgcolor="#ffffe0"><?php echo $cat_disc_message; ?></td>

</tr>

</table>

</td>

</tr>

<tr>

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

</tr>

<?php

}

break;

}

}

}

?>

 

 

so basically you can add as many discount types as you like.

Treasurer MFC

Link to comment
Share on other sites

add a new discount type 'p' :

 

232:2:3:p

change the function in the module to this:

 

function calculate_discount($cat_qty_discount_array) {

global $qty_discount, $order_total_array;

 

$od_amount = 0;

if ((MODULE_CAT_QTY_DISCOUNT_DISABLE_WITH_COUPON == 'true') && (isset($_SESSION['cc_id']))) return $od_amount;

for ($i=0; $i<sizeof($cat_qty_discount_array); $i++) {

switch ($cat_qty_discount_array[$i]['type']) {

case 'm' : $od_amount = $od_amount + floor(($cat_qty_discount_array[$i]['cqty'] / $cat_qty_discount_array[$i]['xqty'])) * $cat_qty_discount_array[$i]['yqty'];

break;

case 'q' : $od_amount = $od_amount + floor(($cat_qty_discount_array[$i]['cqty'] / $cat_qty_discount_array[$i]['xqty'])) * $cat_qty_discount_array[$i]['yqty'] * $cat_qty_discount_array[$i]['price'];

break;

case 'p' : $od_amount = $od_amount + ($cat_qty_discount_array[$i]['cqty'] * $cat_qty_discount_array[$i]['yqty']);

break;

}

}

return $od_amount;

}

change the code in index.php to this:

 

<?php

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

if (me()) echo $discount_rate[$i+3];

if ($discount_rate[$i] == $current_category_id) {

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

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

break;

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

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

break;

case 'p' : $cat_disc_message = 'Buy '.$discount_rate[$i+1].' or more and we take '.$currencies->format($discount_rate[$i+2]).' off each !';

break;

default : $cat_disc_message = '';

break;

}

if ($cat_disc_message != '') {

?>

<tr>

<td><?php echo 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_blink.gif" alt="$" title="$"></td>

<td align="center" width="100%" class="borderGray feat" bgcolor="#ffffe0"><?php echo $cat_disc_message; ?></td>

</tr>

</table>

</td>

</tr>

<tr>

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

</tr>

<?php

}

break;

}

}

}

?>

so basically you can add as many discount types as you like.

 

better remove this:

 

if (me()) echo $discount_rate[$i+3];

Treasurer MFC

Link to comment
Share on other sites

Hi boxtel and thank you!

 

I have applied the code you suggested but now I have the same problem that rflack described:

 

Hi,

 

I've installed the module as per your installation, but it doesn't show on the product page that a discount can be applied, nor does it apply the discount at the checkout stage.

 

I don't know what I can do.. I'm not even sure if the code you gave me works because the shop performs just like nothing was added. Please help

 

Thank you

James Tomasello

Link to comment
Share on other sites

Hi boxtel and thank you!

 

I have applied the code you suggested but now I have the same problem that rflack described:

I don't know what I can do.. I'm not even sure if the code you gave me works because the shop performs just like nothing was added. Please help

 

Thank you

 

you added the code just before this in index.php ?

 

<tr>

<td><?php include(DIR_WS_MODULES . FILENAME_PRODUCT_LISTING); ?></td>

</tr>

 

 

and removed :

 

 

if (me()) echo $discount_rate[$i+3];

 

 

 

and added the condition to the module in admin ?

 

 

232:2:3:p

Treasurer MFC

Link to comment
Share on other sites

Yes I have changed the code exactly as you described... Do you need to see some code? I can send you whatever you need to diagnose this problem.

 

Thank you

 

put this:

 

echo $discount_rate[$i].' = '.$current_category_id.'<br>';

 

right before and after this:

 

if ($discount_rate[$i] == $current_category_id) {

 

and see what is says.

Treasurer MFC

Link to comment
Share on other sites

ok... So when I view category 197 I can see at the top of the page 232=197 followed by the page title then products.

 

Now how would I be able to give the discount on all items in the 232 top category when more than one is ordered?

James Tomasello

Link to comment
Share on other sites

ok... So when I view category 197 I can see at the top of the page 232=197 followed by the page title then products.

 

Now how would I be able to give the discount on all items in the 232 top category when more than one is ordered?

 

that is possible with some changes:

 

add this function to general.php:

 

// Generate a bare path to categories

function tep_get_path_bare($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) {

return $last_category['parent_id'] . '_' . $current_category_id;

} else {

return $current_category_id;

}

}

 

 

in the module :

 

in function function fill_discount_array()

 

after :

 

for ($i=0; $i<sizeof($cat_qty_discount_array); $i++) {

 

add:

 

$cat_path = tep_get_path_bare($cat_result['categories_id']);

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

 

and change this :

 

if ($cat_result['categories_id'] == $cat_qty_discount_array[$i]["cat"]) {

 

into this:

 

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

 

then every product belonging to 232 or 186 or 197 is counted

 

 

ps.

 

better also use this :

 

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

$od_amount = $od_amount + ($cat_qty_discount_array[$i]['cqty'] * $cat_qty_discount_array[$i]['yqty']);

}

break;

 

in your calculate function, the if for the condition was missing.

Treasurer MFC

Link to comment
Share on other sites

that is possible with some changes:

 

add this function to general.php:

 

// Generate a bare path to categories

function tep_get_path_bare($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) {

return $last_category['parent_id'] . '_' . $current_category_id;

} else {

return $current_category_id;

}

}

in the module :

 

in function function fill_discount_array()

 

after :

 

for ($i=0; $i<sizeof($cat_qty_discount_array); $i++) {

 

add:

 

$cat_path = tep_get_path_bare($cat_result['categories_id']);

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

 

and change this :

 

if ($cat_result['categories_id'] == $cat_qty_discount_array[$i]["cat"]) {

 

into this:

 

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

 

then every product belonging to 232 or 186 or 197 is counted

ps.

 

better also use this :

 

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

$od_amount = $od_amount + ($cat_qty_discount_array[$i]['cqty'] * $cat_qty_discount_array[$i]['yqty']);

}

break;

 

in your calculate function, the if for the condition was missing.

 

 

or better add this version of tep_get_path_bare to geberal.php if you have deep levels:

 

function tep_get_path_bare ($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

or better add this version of tep_get_path_bare to geberal.php if you have deep levels:

 

function tep_get_path_bare ($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;

}

}

 

 

 

for the display part :

 

in index.php you change :

 

if ($discount_rate[$i] == $current_category_id) {

 

into:

 

$cat_path = tep_get_cat_path($current_category_id);

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

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

 

 

and you now must put that entire "index.php" display code also in the categories section of index.php as

the message will display on all categories and product pages under the defined category id.

Treasurer MFC

Link to comment
Share on other sites

for the display part :

 

in index.php you change :

 

if ($discount_rate[$i] == $current_category_id) {

 

into:

 

$cat_path = tep_get_cat_path($current_category_id);

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

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

and you now must put that entire "index.php" display code also in the categories section of index.php as

the message will display on all categories and product pages under the defined category id.

 

 

with all these changes you can now enter a top category id in the admin string and ALL products under that top category will be subject to the discount. and on all category and product pages below the top category the message will display.

Treasurer MFC

Link to comment
Share on other sites

Thank you so much for helping me with this.

 

I still have a little problem.. When a category is selected from the first page in the store I get this:

 

Fatal error: Call to undefined function: tep_get_cat_path() in /catalog/includes/functions/category_discount.php on line 12

 

I know i did something wrong... probably with the line i added the code in the Index.php

 

Help!

 

Thank you

James Tomasello

Link to comment
Share on other sites

Thank you so much for helping me with this.

 

I still have a little problem.. When a category is selected from the first page in the store I get this:

 

Fatal error: Call to undefined function: tep_get_cat_path() in /catalog/includes/functions/category_discount.php on line 12

 

I know i did something wrong... probably with the line i added the code in the Index.php

 

Help!

 

Thank you

 

 

no, this was missing in the instructions:

 

add this function to general.php:

this function will return the category path string from current category to the top like 232_179_323 etc.

 

 

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

OK... Now we are getting somewhere.

 

Please go to http://bcpframeshop.com/catalog/index.php?cPath=232

 

Can you see what is happening?

 

just a little formatting issue. the display function starts with <tr> and ends with </tr> so you have to put it somewhere in the code after a </tr> tag not after a </td> tag like you have it now.

Treasurer MFC

Link to comment
Share on other sites

just a little formatting issue. the display function starts with <tr> and ends with </tr> so you have to put it somewhere in the code after a </tr> tag not after a </td> tag like you have it now.

 

Nice!! That is much better!

 

I was wondering how to make the offer always refer to the top category.... in this case Matted Photos?

Also on the Product section no offer is displayed and the discount does not get calculated once you checkout.

 

I'm so sorry for all this trouble!!

 

I hope I can help you this much one day!

 

Thank you

James Tomasello

Link to comment
Share on other sites

Nice!! That is much better!

 

I was wondering how to make the offer always refer to the top category.... in this case Matted Photos?

Also on the Product section no offer is displayed and the discount does not get calculated once you checkout.

 

I'm so sorry for all this trouble!!

 

I hope I can help you this much one day!

 

Thank you

 

 

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 ?

Treasurer MFC

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