Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Customer Loyalty Discount Scheme


misspiggy

Recommended Posts

Customer Loyalty Discount Scheme >> ot_lotalty_discount v1.3(Astrid)

Contribution can be found here:

Customer Loyalty Discount Scheme

 

I was told by a shop owner that a rounding off error of amounts occured in the Customer Loyalty Discount Scheme 1.1 of the author: Clement Nicolaescu so I created a small FIX. (posting of 5 Aug 2004 - Fix to rectify the rounding off error with figures is the correct one.)

 

##############################################################

THE FIX: I have added a few lines to the file ot_loyalty_discount.php to make sure that this rounding off error of amounts is rectified. The amount of discount is immediately rounded off to two figures after the comma, before it is used.

##############################################################

PLEASE NOTE:

Before installing the new script ot_loyalty_discount.php (catalog/includes/modules/order_total/ot_loyalty_discount.php)

You must first do as follows >>

(i) Go to admin >> Order Total Modules

Remove (with button) the Module Customer Loyalty Discount (removes the Module from the database !!)

(ii) Then remove the old script ot_loyalty_discount.php from your folder order_total

(iii) Go back to admin >> Order Total Modules >> no Module Customer Loyalty Discount can be seen

(iv) You can now safely place the new script in the appropriate map: (catalog/includes/modules/order_total/ot_loyalty_discount.php)

and the language script in the appropriate language map:

catalog/includes/languages/english/modules/order_total/ot_loyalty_discount.php)

Please make sure that the scripts have the right permissions and no syntax errors !!

(v) Go back to admin >> Order Total Modules >>

Module Customer Loyalty Discount can be seen again!!

(vii) Install this Module now with the appropriate button and edit as needed.

Hope this helps !!

SCREENSHOTS:

order_confirmation.gif

Order_Total_Modules.gif

Link to comment
Share on other sites

  • 3 weeks later...
  • Replies 64
  • Created
  • Last Reply

Top Posters In This Topic

Customer Loyalty Discount Scheme >> ot_lotalty_discount v1.3(Astrid)

Contribution can be found here:

Customer Loyalty Discount Scheme

 

I was told by a shop owner that a rounding off error of amounts occured in the  Customer Loyalty Discount Scheme 1.1 of the author: Clement Nicolaescu so I created a small FIX. (posting of 5 Aug 2004 - Fix to rectify the rounding off error with figures is the correct one.)

 

##############################################################

THE FIX: I have added a few lines to the file ot_loyalty_discount.php to make sure that this rounding off error of amounts is rectified. The amount of discount is immediately rounded off to two figures after the comma, before it is used.

##############################################################

PLEASE NOTE:

Before installing the new script ot_loyalty_discount.php (catalog/includes/modules/order_total/ot_loyalty_discount.php)

You must first do as follows >>

(i) Go to admin >> Order Total Modules

Remove (with button) the Module Customer Loyalty Discount (removes the Module from the database !!)

(ii) Then remove the old script ot_loyalty_discount.php from your folder order_total

(iii) Go back to admin >> Order Total Modules >> no Module Customer Loyalty Discount can be seen

(iv) You can now safely place the new script in the appropriate map: (catalog/includes/modules/order_total/ot_loyalty_discount.php)

and the language script in the appropriate language map:

catalog/includes/languages/english/modules/order_total/ot_loyalty_discount.php)

Please make sure that the scripts have the right permissions and no syntax errors !!

(v) Go back to admin >> Order Total Modules >> 

Module Customer Loyalty Discount can be seen again!!

(vii) Install this Module now with the appropriate button and edit as needed.

Hope this helps !!

SCREENSHOTS:

order_confirmation.gif

Order_Total_Modules.gif

 

 

The big problem I have now is that the loyalty module is basically flawed.

You see, it does not take into account that in the order_total table, different currencies can be stored. So when you add up the amounts you may have US$, Pounds etc. in there if the customer previously ordered using a different currency.

 

So the function needs to be altered and access the orders table where the currency is stored for any particular order.

 

So for stores with only 1 currency it is OK as well as when you can trust customers to always order in the same currency. Otherwise, the loyalty discount is bogus.

 

 

the function in loyalty discount should be something like this :

 

function get_cum_order_total() {

global $order, $customer_id;

 

$history_query_raw = "select o.date_purchased, o.currency_value,

ot.value as order_total

from " . TABLE_ORDERS . " o left join

" . TABLE_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id)

where o.customers_id = '" . $customer_id . "' and

ot.class = 'ot_total' and

o.orders_status >= '" . MODULE_LOYALTY_DISCOUNT_ORDER_STATUS . "'

order by date_purchased DESC";

 

$history_query = tep_db_query($history_query_raw);

 

if (tep_db_num_rows($history_query)) {

$cum_order_total_twd = 0;

$cutoff_date = get_cutoff_date();

while ($history = tep_db_fetch_array($history_query)) {

if (get_date_in_period($cutoff_date, $history['date_purchased']) == true){

$cum_order_total = $cum_order_total + $history['order_total'] * $history['currency_value'];

}

}

} else {

$cum_order_total = 0;

}

 

return $cum_order_total;

 

}

 

so with the currency value incorporated

 

right ?

Treasurer MFC

Link to comment
Share on other sites

Hi,

 

Firstly many thanks for the contribution - it is a very

handy one for my scenario so cheers!!

 

 

Couple of quick questions though -

 

I am using the August 2004 version as with the later ones

I seem to be having problems and they will not open

correctly (for me anyway). The August one works fine

but just wanted to know if the rounding issue was resolved

in that one.

 

Finally it would be great if a customer who hadn't reached the

required limit for a discount was shown a message like:

 

You have not reached the required level for a discount

- click here for details...

 

Anyone know if this is possible and where to put it - can't

seem to get it right but I have been working too long :huh:

 

Any help greatly appreciated.

 

Cheers

 

Steve

Link to comment
Share on other sites

  • 1 month later...

Hello osCommerce Users

 

This is a really nice and easy contrib that works well. Because I think it?s better for my customers that they don?t see what they spend I wanted to ask you if it is possible to chance this contrib like this? Or can somebody tell me how I can do this.

 

?You have reach you discount level during the last 3 months from ? %?

 

Is there somebody who can help me

Thanks

 

Marcel ;)

Link to comment
Share on other sites

Hi All,

 

Thanks for the contribution, i've used it and its working well.

 

Right now, i'll need another discount scheme, that is by product categories.

 

For instance, all computer softwares are entitled to 5% off stated price but not hardwares.

 

Could someone recommend me which contributions to use, if available?

Will contribution 'Product_families_discount' work ?

 

Thanks aLL!

 

 

Cindy :thumbsup:

Link to comment
Share on other sites

Hi,

Thanks for the loyalty discount module.

It works , BUT 1 small error I found.

In the account history of the customer the discount (as also an other discount I have running - quantity discount) is ADDED instead of deducted.

That increases there sales

AND

gives the customer in the history the idea that he/she was overcharged. Of course the original e-mail sent and charge was as it should be with discount deducted.

 

This can easily be change in the admin customers/orders, by going to the order and set the discount in the order from e.g. 10.00 to -10.00

 

I am a newby and have NO knowlegde of PHP,

so if anyone can look into this, so the manaully changes do not have to be made in the order status.

 

Thank you, Eangkarn

Link to comment
Share on other sites

Hi

I have set up oscoomerce to the product of a kitchen sink manufacturer they sell the products in the lage amount they dont accept credit card , just cash on delivery ,so I wanted to make administratore of site to be able to see the orderes and give suitable discount manualy :'( could any one help me how to do that?

Edited by arena_s21
Link to comment
Share on other sites

Nice & easy to install! It works like a charm... EXCEPT, I also have the CCGV contrib. This contrib would be better if it ignored the products that start with "GIFT" - that way, it is compatible with CCGV and people can't abuse the loyalty scheme by buying GCs, then turning around and using them for their purchases.

 

Anybody wants to take this on?

"If the facts don't fit the theory, change the facts." - Einstein

Link to comment
Share on other sites

  • 3 weeks later...

Also,

On the first order, when using the paypal ipn, the customer loyalty discount will be awarded in the confirmation email, but will not show up on the invoice or in the system. I assume this is because the order history is checked, and the discount awarded on the preparing Paypal ipn order, treating it as an earlier order.

 

The mod works great when not using the paypal ipn. With it (the PayPal IPN Module v1.0), the discount is not passed to paypal AND there is the bug mentioned above where the discount is mentioned in the confirmation email, when it should not be applied. (even though it is never auto-appled during the paypal payment proceess.)

 

Please help, as this is a great mod id like to continue using.

Link to comment
Share on other sites

  • 1 month later...

Very nice contribution.

 

However, I'm looking to modify the code slightly. Perhaps someone can help me. See, I will be giving my customers discount codes to give out to bring in new customers. Instead of the discount being calculated to their cum. order total, I'd like the calc to include how the cum. order total for customers that used their codes. Seems like this would be easy but I'm not too fluid with php...

Link to comment
Share on other sites

  • 8 months later...
Hey, does anyone know how to make the % discount each customer gets visible in account.php?

 

The method in http://www.oscommerce.com/community/contri...ons,1286/page,3

 

is wrong.

 

Please help me.

 

I use this :

 

// Display Loyalty discount for customer plus the table and his current place in it.

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

$loyalty = new ot_loyalty_discount;

$cust_tot_order_amount = $loyalty->get_cum_order_total();

$table_cost = split("[:,]" , MODULE_LOYALTY_DISCOUNT_TABLE);

$discount_perc = 0;

 

for ($i = 0; $i < count($table_cost); $i+=2) {

if ($cust_tot_order_amount >= $table_cost[$i]) {

$discount_perc = $table_cost[$i+1];

}

}

 

if ($cust_tot_order_amount > 0) {

$order_hist_text = 'Your order amount in the last ' . MODULE_LOYALTY_DISCOUNT_CUMORDER_PERIOD . ' totals: ' . $currencies->display_price_nodiscount($cust_tot_order_amount) . '<br><br>Therefore, you are eligible for an EXTRA DISCOUNT of ' . $discount_perc . '% on your next purchases.';

} else {

$order_hist_text = 'You are currently not eligible for this very lucrative discount.';

}

 

$order_hist_text .= '<br><br>Our current Loyalty Discount Table for purchases made over the last ' . MODULE_LOYALTY_DISCOUNT_CUMORDER_PERIOD . ':<br><br>';

$order_hist_text .= '<table>';

$order_hist_text .= '<tr><td align="right" class="main">Amount</td>

<td width="100" align="center"> </td>

<td><span class="main">%</td>

<td align="right" width="10px"> </td>

<td align="center" class="main">To Go</td>

</tr>';

 

for ($i = 0; $i < count($table_cost); $i+=2) {

if ($discount_perc >= $table_cost[$i+1]) {

$order_hist_text .= '<tr><td align="right"><span class="main">' . $currencies->display_price_nodiscount($table_cost[$i]) . '</span></td>

<td width="100" align="center"><img src="images/checkout_bullet0.gif" alt="Your Discount" title="Your Discount"></td>

<td><span class="main">' . $table_cost[$i+1] . '%</span></td>

<td align="right" width="10px"> </td>

<td align="right"> </td>

</tr>';

} else {

$order_hist_text .= '<tr><td align="right"><span class="main">' . $currencies->display_price_nodiscount($table_cost[$i]) . '</span></td>

<td align="center"><img src="images/arrow_south_east.gif" alt="This Could Be Your Discount" title="This Could Be Your Discount"></td>

<td><span class="main">' . $table_cost[$i+1] . '%</span></td>

<td align="right" width="10px"> </td>

<td align="right"><span class="main">' . $currencies->display_price_nodiscount($table_cost[$i]-$cust_tot_order_amount) . '</span></td>

</tr>';

}

}

$order_hist_text .= '</table>';

?>

<table width="100%">

<tr>

<td class="pageheading">Loyalty Discount (up to 30%) - (Excluding VIP & Wholesale Customers)</td>

</tr>

<tr>

<td>

<table border="0" width="100%" cellspacing="2" cellpadding="2">

<tr class="infoBoxContents">

<td>' . $order_hist_text . '</td>

</tr>

</table>

</td>

</tr>

</table>

Treasurer MFC

Link to comment
Share on other sites

I use this :

 

// Display Loyalty discount for customer plus the table and his current place in it.

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

$loyalty = new ot_loyalty_discount;

$cust_tot_order_amount = $loyalty->get_cum_order_total();

$table_cost = split("[:,]" , MODULE_LOYALTY_DISCOUNT_TABLE);

$discount_perc = 0;

 

for ($i = 0; $i < count($table_cost); $i+=2) {

if ($cust_tot_order_amount >= $table_cost[$i]) {

$discount_perc = $table_cost[$i+1];

}

}

 

if ($cust_tot_order_amount > 0) {

$order_hist_text = 'Your order amount in the last ' . MODULE_LOYALTY_DISCOUNT_CUMORDER_PERIOD . ' totals: ' . $currencies->display_price_nodiscount($cust_tot_order_amount) . '<br><br>Therefore, you are eligible for an EXTRA DISCOUNT of ' . $discount_perc . '% on your next purchases.';

} else {

$order_hist_text = 'You are currently not eligible for this very lucrative discount.';

}

 

$order_hist_text .= '<br><br>Our current Loyalty Discount Table for purchases made over the last ' . MODULE_LOYALTY_DISCOUNT_CUMORDER_PERIOD . ':<br><br>';

$order_hist_text .= '<table>';

$order_hist_text .= '<tr><td align="right" class="main">Amount</td>

<td width="100" align="center"> </td>

<td><span class="main">%</td>

<td align="right" width="10px"> </td>

<td align="center" class="main">To Go</td>

</tr>';

 

for ($i = 0; $i < count($table_cost); $i+=2) {

if ($discount_perc >= $table_cost[$i+1]) {

$order_hist_text .= '<tr><td align="right"><span class="main">' . $currencies->display_price_nodiscount($table_cost[$i]) . '</span></td>

<td width="100" align="center"><img src="images/checkout_bullet0.gif" alt="Your Discount" title="Your Discount"></td>

<td><span class="main">' . $table_cost[$i+1] . '%</span></td>

<td align="right" width="10px"> </td>

<td align="right"> </td>

</tr>';

} else {

$order_hist_text .= '<tr><td align="right"><span class="main">' . $currencies->display_price_nodiscount($table_cost[$i]) . '</span></td>

<td align="center"><img src="images/arrow_south_east.gif" alt="This Could Be Your Discount" title="This Could Be Your Discount"></td>

<td><span class="main">' . $table_cost[$i+1] . '%</span></td>

<td align="right" width="10px"> </td>

<td align="right"><span class="main">' . $currencies->display_price_nodiscount($table_cost[$i]-$cust_tot_order_amount) . '</span></td>

</tr>';

}

}

$order_hist_text .= '</table>';

?>

<table width="100%">

<tr>

<td class="pageheading">Loyalty Discount (up to 30%) - (Excluding VIP & Wholesale Customers)</td>

</tr>

<tr>

<td>

<table border="0" width="100%" cellspacing="2" cellpadding="2">

<tr class="infoBoxContents">

<td>' . $order_hist_text . '</td>

</tr>

</table>

</td>

</tr>

</table>

 

 

you may need to change these if you do not have group discount:

 

display_price_nodiscount

 

to

 

display_price

Treasurer MFC

Link to comment
Share on other sites

This still doesn't work :/. I have the latest Customer Loyalty modules installed, and only those.

 

With that said, how would i make the customers discount show up in account.php?

 

Boxtel, that doesn't work. Do you just place that code in account.php where you want it to show or do you have to do something else?

 

Someone please help, been working on this for days and cannot figure out a solution.

Link to comment
Share on other sites

This still doesn't work :/. I have the latest Customer Loyalty modules installed, and only those.

 

With that said, how would i make the customers discount show up in account.php?

 

Boxtel, that doesn't work. Do you just place that code in account.php where you want it to show or do you have to do something else?

 

Someone please help, been working on this for days and cannot figure out a solution.

 

 

ok, change this :

 

<td>' . $order_hist_text . '</td>

 

into this :

 

 

<td><?php echo $order_hist_text; ?></td>

 

 

and you can put it anywhere in account.php but as it is a table, embed it like <tr><td> code </td></tr>

Treasurer MFC

Link to comment
Share on other sites

ok, change this :

 

<td>' . $order_hist_text . '</td>

 

into this :

<td><?php echo $order_hist_text; ?></td>

and you can put it anywhere in account.php but as it is a table, embed it like <tr><td> code </td></tr>

 

 

so like this :

 

 

<tr><td>

<?php

// Display Loyalty discount for customer plus the table and his current place in it.

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

$loyalty = new ot_loyalty_discount;

$cust_tot_order_amount = $loyalty->get_cum_order_total();

$table_cost = split("[:,]" , MODULE_LOYALTY_DISCOUNT_TABLE);

$discount_perc = 0;

 

for ($i = 0; $i < count($table_cost); $i+=2) {

if ($cust_tot_order_amount >= $table_cost[$i]) {

$discount_perc = $table_cost[$i+1];

}

}

 

if ($cust_tot_order_amount > 0) {

$order_hist_text = 'Your order amount in the last ' . MODULE_LOYALTY_DISCOUNT_CUMORDER_PERIOD . ' totals: ' . $currencies->display_price_nodiscount($cust_tot_order_amount) . '<br><br>Therefore, you are eligible for an EXTRA DISCOUNT of ' . $discount_perc . '% on your next purchases.';

} else {

$order_hist_text = 'You are currently not eligible for this very lucrative discount.';

}

 

$order_hist_text .= '<br><br>Our current Loyalty Discount Table for purchases made over the last ' . MODULE_LOYALTY_DISCOUNT_CUMORDER_PERIOD . ':<br><br>';

$order_hist_text .= '<table>';

$order_hist_text .= '<tr><td align="right" class="main">Amount</td>

<td width="100" align="center"> </td>

<td><span class="main">%</td>

<td align="right" width="10px"> </td>

<td align="center" class="main">To Go</td>

</tr>';

 

for ($i = 0; $i < count($table_cost); $i+=2) {

if ($discount_perc >= $table_cost[$i+1]) {

$order_hist_text .= '<tr><td align="right"><span class="main">' . $currencies->display_price_nodiscount($table_cost[$i]) . '</span></td>

<td width="100" align="center"><img src="images/checkout_bullet0.gif" alt="Your Discount" title="Your Discount"></td>

<td><span class="main">' . $table_cost[$i+1] . '%</span></td>

<td align="right" width="10px"> </td>

<td align="right"> </td>

</tr>';

} else {

$order_hist_text .= '<tr><td align="right"><span class="main">' . $currencies->display_price_nodiscount($table_cost[$i]) . '</span></td>

<td align="center"><img src="images/arrow_south_east.gif" alt="This Could Be Your Discount" title="This Could Be Your Discount"></td>

<td><span class="main">' . $table_cost[$i+1] . '%</span></td>

<td align="right" width="10px"> </td>

<td align="right"><span class="main">' . $currencies->display_price_nodiscount($table_cost[$i]-$cust_tot_order_amount) . '</span></td>

</tr>';

}

}

$order_hist_text .= '</table>';

?>

<table width="100%">

<tr>

<td class="pageheading">Loyalty Discount (up to 30%) - (Excluding VIP & Wholesale Customers)</td>

</tr>

<tr>

<td>

<table border="0" width="100%" cellspacing="2" cellpadding="2">

<tr class="infoBoxContents">

<td><?php echo $order_hist_text; ?></td>

</tr>

</table>

</td>

</tr>

</table>

</td></tr>

Treasurer MFC

Link to comment
Share on other sites

Do this contribution calculate the yearly discount on purchases made since sign up date or does it look at any purchases over a rolling 365 days?

~~~~~~~~~~~~~~~~~~~~~

motivating is like eating on a full stomach..It creates more s!@t to deal with later!

Link to comment
Share on other sites

Do this contribution calculate the yearly discount on purchases made since sign up date or does it look at any purchases over a rolling 365 days?

 

rolling

 

alltime

year

quarter

month

Treasurer MFC

Link to comment
Share on other sites

Hey Boxtel, still have problems. Is there a stream lined code i can make to just say this:

You have spent (customer purchases totaled up) with us so you are eligable for a discount of (current discount level).

 

well, what are those problems ???

 

 

anyhow, streamlined :

 

<?php

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

$loyalty = new ot_loyalty_discount;

$cust_tot_order_amount = $loyalty->get_cum_order_total();

$table_cost = split("[:,]" , MODULE_LOYALTY_DISCOUNT_TABLE);

$discount_perc = 0;

 

for ($i = 0; $i < count($table_cost); $i+=2) {

if ($cust_tot_order_amount >= $table_cost[$i]) {

$discount_perc = $table_cost[$i+1];

}

}

 

if ($cust_tot_order_amount > 0) {

echo 'Your have spend ' . $currencies->display_price($cust_tot_order_amount) . ' in the last ' . MODULE_LOYALTY_DISCOUNT_CUMORDER_PERIOD . ' with us so you are eligable for a discount of ' . $discount_perc . '%';

}

?>

Treasurer MFC

Link to comment
Share on other sites

Warning: Missing argument 2 for display_price() in /home/salvaged/public_html/includes/classes/currencies.php on line 71

Your have spent $149.46 with us so you are eligable for a discount of 5%

 

 

 

is the error i get when i put that code in accout.php above the heading:

 

My Account Information

 

 

Any ideas?

Link to comment
Share on other sites

Warning: Missing argument 2 for display_price() in /home/salvaged/public_html/includes/classes/currencies.php on line 71

Your have spent $149.46 with us so you are eligable for a discount of 5%

is the error i get when i put that code in accout.php above the heading:

 

My Account Information

Any ideas?

 

ah, that tax information.

2 solutions:

 

1) use $currencies->display_price($cust_tot_order_amount,0)

2) in class currencies

 

change this :

 

function display_price($products_price, $products_tax, $quantity = 1) {

 

into this:

 

function display_price($products_price, $products_tax = 0, $quantity = 1) {

 

which wil make the tax 0 if not supplied to the function.

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