Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Customer Loyalty Discount Scheme


misspiggy

Recommended Posts

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.

 

 

oh, and ask your host to log errors and warnings in a log file and not spit it out to the screen, very bad practice if not debugging

Treasurer MFC

Link to comment
Share on other sites

  • 1 month later...
  • Replies 64
  • Created
  • Last Reply

Top Posters In This Topic

$Id: ot_loyalty_discount.php,v 1.1.2.1.2.2 2005/09/21 20:58:32 Michael Sasek Exp $

 

Defect Report

[Note this defect report was reported in the oscMAX bugtracker and I have crossposted it here since I believe that anyone running this module (see version information above) should be aware of the bug, it's potential costs and how to fix it - so "moderators" please be kind]

 

 

The following SQL statement in /includes/modules/order_total/ot_loyalty_discount.php can cost you a great deal

 

$history_query_raw = "select o.date_purchased, 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 = '" . $customers_id . "' and ot.class = 'ot_total' and o.orders_status >= '" . $this->loyalty_order_status . "' order by date_purchased DESC";

 

The problem arises when you add new order_status to your store.

 

order_status for Shipped (which the the point where you want to start offering discounts, after you have shipped them an order) is set on install to "3". If you add other order stats' after that they start at 100000. So, if I added a status called "challenges" it would get an order status value of 100000.

 

This SQL if I set the order status for "shipped" would include all orders that were shipped, but also include all orders that were in "challenges" when computing the discount for the customer.

 

Now I know that I have added "challenges", "credited", "cancelled" and "Purchase Order Processing" to a store and I don't want to give discounts on anything that is in those status fields. The solution is to change the query to:

 

$history_query_raw = "select o.date_purchased, 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 = '" . $customers_id . "' and ot.class = 'ot_total' and o.orders_status = '" . $this->loyalty_order_status . "' order by date_purchased DESC";

 

The query will now ONLY take those orders that have a "shipped" status (they paid you and you have shipped them the merchandise).

 

The potential cost of not applying this fix could be very large over time. Imagine you had a store that sold large ticket items. The customer ordered and was shipped $3,500 worth of product. They returned it. Then they came back in and ordered $2,500 worth of a different product (they misordered the first time and ordered correctly the second).

 

Now, you set your discounts up as 500:1,1250:2,2250:3,3500:4,5000:5

 

If you had added a status called "credited" and had credited the first order, when they placed the second order they would have been offered a 3% loyalty discount. Now, imagine this customer seeing this second smaller order get a discount, the best you could hope for is that they don't get pissed that they weren't offered a discount on the first larger order. The worst case is that the customer figures out that you still credited him for the larger order, calls and cancels the new order (which you move to your "cancelled" status) and then reorders the same second order getting a 5% discount since the returned and cancelled order would both be counted in the affinity code.

 

Now imagine, like one of my customers, that your average margin is about 10%.

 

### Added note ###

 

Okay, found another expensive screwup in the database query.

 

Here is the query:

 

$history_query_raw = "select o.date_purchased, 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 = '" . $this->loyalty_order_status . "' order by date_purchased DESC";

 

The expensive screwup this time is using the "ot.class = 'ot_total'"

 

In general ot_total includes:

 

1) taxes

2) shipping

3) low order fees

 

and of course any discounts that have been applied.

 

Now, what we want to do is apply any discounts (and any prior loyalty credit) to the sub-total, then apply all additional charges after the sub-total and the total. Then change the query to:

 

$history_query_raw = "select o.date_purchased, 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_subtotal' and o.orders_status = '" . $this->loyalty_order_status . "' order by date_purchased DESC";

 

This will ensure that customers are only getting credit on those charges that they PAID YOU for (unless you get a piece of UPS/FedEx action and the Taxes and want to credit them on that as well).

 

Geeze, didn't anyone think this query out before they installed it?

 

###

 

Once you have applied the second "fix" you will have to go into admin -> modules -> order total in the osc-admin and change the order of your sequence to apply discounts BEFORE you subtotal and additional charges AFTER you subtotal. But doing all the above will ensure that people get credit for what they paid you, not what they paid in shipping, taxes, etc.

Link to comment
Share on other sites

$Id: ot_loyalty_discount.php,v 1.1.2.1.2.2 2005/09/21 20:58:32 Michael Sasek Exp $

 

Defect Report

[Note this defect report was reported in the oscMAX bugtracker and I have crossposted it here since I believe that anyone running this module (see version information above) should be aware of the bug, it's potential costs and how to fix it - so "moderators" please be kind]

The following SQL statement in /includes/modules/order_total/ot_loyalty_discount.php can cost you a great deal

 

$history_query_raw = "select o.date_purchased, 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 = '" . $customers_id . "' and ot.class = 'ot_total' and o.orders_status >= '" . $this->loyalty_order_status . "' order by date_purchased DESC";

 

The problem arises when you add new order_status to your store.

 

order_status for Shipped (which the the point where you want to start offering discounts, after you have shipped them an order) is set on install to "3". If you add other order stats' after that they start at 100000. So, if I added a status called "challenges" it would get an order status value of 100000.

 

This SQL if I set the order status for "shipped" would include all orders that were shipped, but also include all orders that were in "challenges" when computing the discount for the customer.

 

Now I know that I have added "challenges", "credited", "cancelled" and "Purchase Order Processing" to a store and I don't want to give discounts on anything that is in those status fields. The solution is to change the query to:

 

$history_query_raw = "select o.date_purchased, 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 = '" . $customers_id . "' and ot.class = 'ot_total' and o.orders_status = '" . $this->loyalty_order_status . "' order by date_purchased DESC";

 

The query will now ONLY take those orders that have a "shipped" status (they paid you and you have shipped them the merchandise).

 

The potential cost of not applying this fix could be very large over time. Imagine you had a store that sold large ticket items. The customer ordered and was shipped $3,500 worth of product. They returned it. Then they came back in and ordered $2,500 worth of a different product (they misordered the first time and ordered correctly the second).

 

Now, you set your discounts up as 500:1,1250:2,2250:3,3500:4,5000:5

 

If you had added a status called "credited" and had credited the first order, when they placed the second order they would have been offered a 3% loyalty discount. Now, imagine this customer seeing this second smaller order get a discount, the best you could hope for is that they don't get pissed that they weren't offered a discount on the first larger order. The worst case is that the customer figures out that you still credited him for the larger order, calls and cancels the new order (which you move to your "cancelled" status) and then reorders the same second order getting a 5% discount since the returned and cancelled order would both be counted in the affinity code.

 

Now imagine, like one of my customers, that your average margin is about 10%.

 

### Added note ###

 

Okay, found another expensive screwup in the database query.

 

Here is the query:

 

$history_query_raw = "select o.date_purchased, 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 = '" . $this->loyalty_order_status . "' order by date_purchased DESC";

 

The expensive screwup this time is using the "ot.class = 'ot_total'"

 

In general ot_total includes:

 

1) taxes

2) shipping

3) low order fees

 

and of course any discounts that have been applied.

 

Now, what we want to do is apply any discounts (and any prior loyalty credit) to the sub-total, then apply all additional charges after the sub-total and the total. Then change the query to:

 

$history_query_raw = "select o.date_purchased, 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_subtotal' and o.orders_status = '" . $this->loyalty_order_status . "' order by date_purchased DESC";

 

This will ensure that customers are only getting credit on those charges that they PAID YOU for (unless you get a piece of UPS/FedEx action and the Taxes and want to credit them on that as well).

 

Geeze, didn't anyone think this query out before they installed it?

 

###

 

Once you have applied the second "fix" you will have to go into admin -> modules -> order total in the osc-admin and change the order of your sequence to apply discounts BEFORE you subtotal and additional charges AFTER you subtotal. But doing all the above will ensure that people get credit for what they paid you, not what they paid in shipping, taxes, etc.

 

old news.

Treasurer MFC

Link to comment
Share on other sites

  • 3 weeks later...

Hi all,

Just installed the contribution and I like it a lot.

Cheers.

I have one request that is way beyond me.

Is it possible to have the customers discount level displayed in the Admin section so that I can view who has what discount.

All the best

Colin

Link to comment
Share on other sites

  • 2 weeks later...
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.

 

I tried solution number 2 and there was not change.

 

Which file does solution 1 apply to?

 

Any help appreciated,

 

Regards,

 

Chris

Link to comment
Share on other sites

  • 4 months later...
  • 3 weeks later...

I have installed the 1.3 version of this contrib. I can see it in Admin console in order total modules. I have configured it, but for some unknown reason its just not showing up during checkout at all.

 

Any pointers ?

Link to comment
Share on other sites

  • 3 months later...
cant get the correct total to pass to the paypal ipn module. I can only get the subtotal and tax..?

Hiya, did you ever resolve this?

 

If so - can you enlighten us (or anyone else for that matter that has sorted this!)

 

Thanks

 

Jos

===============

Simple yet Creative

Get Online Web Design : getonlinedesign.com

===============

Link to comment
Share on other sites

  • 5 months later...

I just installed version 1.3 of this contrib. Very nice mod and very useful. I have found through testing that it isn't calculating the discount correctly. below is an example of what it's coming up with for a discount on a $15 dollar item with a 7.5% discount.

 

[b]1 x 5 Candle Scented Sampler 4oz (5VALUE04) = $15.00[/b]
Scent choice 1 Cranberry
Scent choice 2 Fresh & Clean
Scent choice 3 Lavender Vanilla
Scent choice 4 Pine
Scent choice 5 Wild Mint & Ivy
------------------------------------------------------
[b]Customer Loyalty Discount:You have spent $240.93 in the last year so qualify for a discount of 7.5%: $1.08[/b]
Sub-Total: $13.92
United States Postal Service (1 x 3.48lbs) (Priority (2 - 3 Days)): $5.70
Shipping Coupon 0K8GV7 for 10% off shipping applied.: -$0.57
WV TAX 6.0%: $0.90
Total: $19.95

 

You can see that it came up with $1.08. I figured it up at $1.12 so it's .04 off which has a cascading effect on everything that follows. I'm not sure why it's off, but it;s not right no matter what I See the percentage too. It's always 3 or 4 cents off.

 

Anyone have any ideas what may be happening?

Edited by candleman

Currently running 76 contibutions.

Link to comment
Share on other sites

for anyone else having the same problem I had, I did the following and it fixed it. In ot_loyalty_discount.php Find this

$history_query_raw = "select o.date_purchased, 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 >= '" . $this->loyalty_order_status . "' order by date_purchased DESC";

 

and change to this

$history_query_raw = "select o.date_purchased, 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_subtotal' and o.orders_status = '" . $this->loyalty_order_status . "' order by date_purchased DESC";

 

With this change you need to have the sub-total come after the loyalty discount and it should work correctly.

 

This worked for me, but I can't guarantee it will for everyone.

Currently running 76 contibutions.

Link to comment
Share on other sites

Hi all,

 

I tried to install the lastest version of the mod, and still get the php warning. It seems like it can't locate the language file. It's strange. I check everything, can't figure out how could it can't find the language file and gave the php warning in the order_total. Any hint or help pls?

 

Thanks

Link to comment
Share on other sites

  • 3 weeks later...
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 ?

 

Can anyone please help a floundering newbie ?

I am having problems with this patch to incorporate the Customer Loyalty Discount Scheme into my multi-currency shop.

When I cut & paste the above code into ot_loyalty_discount.php, I get a Parse error: syntax error, unexpected '}' on line 213.

When i take that out of the code, the discount scheme fails to appear on the order confirmation page

 

My code looks like this

 

<?php

/*

ot_loyalty_discount.php

$Id: ot_loyalty_discount.php,v 1.0 2003/06/09 22:49:11 sp Exp $

 

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2002 osCommerce

 

Released under the GNU General Plic License

*/

 

class ot_loyalty_discount {

var $title, $output;

 

function ot_loyalty_discount() {

$this->code = ot_loyalty_discount;

$this->title = MODULE_LOYALTY_DISCOUNT_TITLE;

$this->description = MODULE_LOYALTY_DISCOUNT_DESCRIPTION;

$this->enabled = MODULE_LOYALTY_DISCOUNT_STATUS;

$this->sort_order = MODULE_LOYALTY_DISCOUNT_SORT_ORDER;

$this->include_shipping = MODULE_LOYALTY_DISCOUNT_INC_SHIPPING;

$this->include_tax = MODULE_LOYALTY_DISCOUNT_INC_TAX;

$this->calculate_tax = MODULE_LOYALTY_DISCOUNT_CALC_TAX;

$this->table = MODULE_LOYALTY_DISCOUNT_TABLE;

$this->loyalty_order_status = MODULE_LOYALTY_DISCOUNT_ORDER_STATUS;

$this->cum_order_period = MODULE_LOYALTY_DISCOUNT_CUMORDER_PERIOD;

$this->output = array();

}

 

function process() {

global $order, $ot_subtotal, $currencies;

$od_amount = $this->calculate_credit($this->get_order_total(), $this->get_cum_order_total());

 

// round discount to nearest cent. Discount of less than .5 cent will not be deducted from amount payable.

$od_amount = round($od_amount, 2);

if ($od_amount>0) { // deduct discount from amount payable

$this->deduction = $od_amount;

$this->output[] = array('title' => $this->title . ':<br>' . MODULE_LOYALTY_DISCOUNT_SPENT . $currencies->format($this->cum_order_total) . $this->period_string . MODULE_LOYALTY_DISCOUNT_QUALIFY . $this->od_pc . '%:',

'text' => '<b>' . $currencies->format($od_amount) .'<b>' ,

'value' => $od_amount);

$order->info['total'] = $order->info['total'] - $od_amount;

if ($this->sort_order < $ot_subtotal->sort_order) {

$order->info['subtotal'] = $order->info['subtotal'] - $od_amount;

}

}

} // end of function process()

 

 

function calculate_credit($amount_order, $amount_cum_order) {

global $order;

$od_amount=0;

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

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

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

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

$this->od_pc = $od_pc;

}

}

// Calculate tax reduction if necessary

if($this->calculate_tax == 'true') {

// Calculate main tax reduction

$tod_amount = $order->info['tax']*$od_pc/100;

$order->info['tax'] = $order->info['tax'] - $tod_amount;

// Calculate tax group deductions

reset($order->info['tax_groups']);

while (list($key, $value) = each($order->info['tax_groups'])) {

$god_amount = $value*$od_pc/100;

$order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;

}

}

$od_amount = $amount_order*$od_pc/100;

$od_amount = $od_amount + $tod_amount;

return $od_amount;

}

 

 

function get_order_total() {

global $order, $cart;

$order_total = $order->info['total'];

// Check if gift voucher is in cart and adjust total

$products = $cart->get_products();

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

$t_prid = tep_get_prid($products[$i]['id']);

$gv_query = tep_db_query("select products_price, products_tax_class_id, products_model from " . TABLE_PRODUCTS . " where products_id = '" . $t_prid . "'");

$gv_result = tep_db_fetch_array($gv_query);

if (ereg('^GIFT', addslashes($gv_result['products_model']))) {

$qty = $cart->get_quantity($t_prid);

$products_tax = tep_get_tax_rate($gv_result['products_tax_class_id']);

if ($this->include_tax =='false') {

$gv_amount = $gv_result['products_price'] * $qty;

} else {

$gv_amount = ($gv_result['products_price'] + tep_calculate_tax($gv_result['products_price'],$products_tax)) * $qty;

}

$order_total=$order_total - $gv_amount;

}

}

if ($this->include_tax == 'false') $order_total=$order_total-$order->info['tax'];

if ($this->include_shipping == 'false') $order_total=$order_total-$order->info['shipping_cost'];

return $order_total;

}

 

function 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 = '" .

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

}

}

$this->cum_order_total = $cum_order_total;

return $cum_order_total;

 

}

else {

$cum_order_total = 0;

}

 

return $cum_order_total;

 

}

}

 

function get_cutoff_date() {

$rightnow = time();

switch ($this->cum_order_period) {

case alltime:

$this->period_string = MODULE_LOYALTY_DISCOUNT_WITHUS;

$cutoff_date = 0;

return $cutoff_date;

break;

case year:

$this->period_string = MODULE_LOYALTY_DISCOUNT_LAST . MODULE_LOYALTY_DISCOUNT_YEAR;

$cutoff_date = $rightnow - (60*60*24*365);

return $cutoff_date;

break;

case quarter:

$this->period_string = MODULE_LOYALTY_DISCOUNT_LAST . MODULE_LOYALTY_DISCOUNT_QUARTER;

$cutoff_date = $rightnow - (60*60*24*92);

return $cutoff_date;

break;

case month:

$this->period_string = MODULE_LOYALTY_DISCOUNT_LAST . MODULE_LOYALTY_DISCOUNT_MONTH;

$cutoff_date = $rightnow - (60*60*24*31);

return $cutoff_date;

break;

default:

$cutoff_date = $rightnow;

return $cutoff_date;

}

}

 

function get_date_in_period($cutoff_date, $raw_date) {

if ( ($raw_date == '0000-00-00 00:00:00') || ($raw_date == '') ) return false;

 

$year = (int)substr($raw_date, 0, 4);

$month = (int)substr($raw_date, 5, 2);

$day = (int)substr($raw_date, 8, 2);

$hour = (int)substr($raw_date, 11, 2);

$minute = (int)substr($raw_date, 14, 2);

$second = (int)substr($raw_date, 17, 2);

 

$order_date_purchased = mktime($hour,$minute,$second,$month,$day,$year);

if ($order_date_purchased >= $cutoff_date) {return true;}

else {return false;}

}

 

 

function check() {

if (!isset($this->check)) {

$check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_LOYALTY_DISCOUNT_STATUS'");

$this->check = tep_db_num_rows($check_query);

}

 

return $this->check;

}

 

function keys() {

return array('MODULE_LOYALTY_DISCOUNT_STATUS', 'MODULE_LOYALTY_DISCOUNT_SORT_ORDER', 'MODULE_LOYALTY_DISCOUNT_CUMORDER_PERIOD', 'MODULE_LOYALTY_DISCOUNT_TABLE', 'MODULE_LOYALTY_DISCOUNT_INC_SHIPPING', 'MODULE_LOYALTY_DISCOUNT_INC_TAX', 'MODULE_LOYALTY_DISCOUNT_CALC_TAX', 'MODULE_LOYALTY_DISCOUNT_ORDER_STATUS');

}

 

function install() {

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Display Total', 'MODULE_LOYALTY_DISCOUNT_STATUS', 'true', 'Do you want to enable the Order Discount?', '6', '1','tep_cfg_select_option(array(\'true\', \'false\'), ', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_LOYALTY_DISCOUNT_SORT_ORDER', '999', 'Sort order of display.', '6', '2', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('Include Shipping', 'MODULE_LOYALTY_DISCOUNT_INC_SHIPPING', 'true', 'Include Shipping in calculation', '6', '3', 'tep_cfg_select_option(array(\'true\', \'false\'), ', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('Include Tax', 'MODULE_LOYALTY_DISCOUNT_INC_TAX', 'true', 'Include Tax in calculation.', '6', '4','tep_cfg_select_option(array(\'true\', \'false\'), ', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('Calculate Tax', 'MODULE_LOYALTY_DISCOUNT_CALC_TAX', 'false', 'Re-calculate Tax on discounted amount.', '6', '5','tep_cfg_select_option(array(\'true\', \'false\'), ', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('Cumulative order total period', 'MODULE_LOYALTY_DISCOUNT_CUMORDER_PERIOD', 'year', 'Set the period over which to calculate cumulative order total.', '6', '6','tep_cfg_select_option(array(\'alltime\', \'year\', \'quarter\', \'month\'), ', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Discount Percentage', 'MODULE_LOYALTY_DISCOUNT_TABLE', '1000:5,1500:7.5,2000:10,3000:12.5,5000:15', 'Set the cumulative order total breaks per period set above, and discount percentages', '6', '7', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Order Status', 'MODULE_LOYALTY_DISCOUNT_ORDER_STATUS', '3', 'Set the minimum order status for an order to add it to the total amount ordered', '6', '8', now())");

}

 

function remove() {

$keys = '';

$keys_array = $this->keys();

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

$keys .= "'" . $keys_array[$i] . "',";

}

$keys = substr($keys, 0, -1);

 

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

}

}

?>

Link to comment
Share on other sites

  • 2 months later...

Hi in the account.php I have this error message

 

Fatal error: Call to undefined method order_total::output_discount() in /var/www/vhosts/mysite/httpdocs/store/catalog/account.php on line 100

 

this is what I add ..the line 100 is in red

 

?> <tr> <td><table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr> <td class="main"><b><?php echo MY_ACCOUNT_DISCOUNTS; ?></b></td> </tr> </table></td> </tr> <tr> <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox"> <tr class="infoBoxContents"> <td><table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr> <td><table border="0" width="100%" cellspacing="0" cellpadding="2"><?php require(DIR_WS_CLASSES . 'order_total.php'); require(DIR_WS_CLASSES . 'order.php'); $order = new order; $order_total_modules = new order_total; if (MODULE_ORDER_TOTAL_INSTALLED) { $order_total_modules->process(); echo '<tr><td align="left" class="main">' . MODULE_LOYALTY_DISCOUNT_TITLE . ' : ' . $order_total_modules->output_discount() . '%</td></tr>'; }?> </table></td> <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td> </tr> </table></td> </tr> </table></td> </tr> <tr> <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td> </tr><?php

Link to comment
Share on other sites

  • 1 month later...
Hi in the account.php I have this error message

 

Fatal error: Call to undefined method order_total::output_discount() in /var/www/vhosts/mysite/httpdocs/store/catalog/account.php on line 100

 

this is what I add ..the line 100 is in red

 

?> <tr> <td><table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr> <td class="main"><b><?php echo MY_ACCOUNT_DISCOUNTS; ?></b></td> </tr> </table></td> </tr> <tr> <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox"> <tr class="infoBoxContents"> <td><table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr> <td><table border="0" width="100%" cellspacing="0" cellpadding="2"><?php require(DIR_WS_CLASSES . 'order_total.php'); require(DIR_WS_CLASSES . 'order.php'); $order = new order; $order_total_modules = new order_total; if (MODULE_ORDER_TOTAL_INSTALLED) { $order_total_modules->process(); echo '<tr><td align="left" class="main">' . MODULE_LOYALTY_DISCOUNT_TITLE . ' : ' . $order_total_modules->output_discount() . '%</td></tr>'; }?> </table></td> <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td> </tr> </table></td> </tr> </table></td> </tr> <tr> <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td> </tr><?php

 

I have the exact same problem, does anyone have a fix for this??

Thanks

Edited by Kiwi_Dan
Link to comment
Share on other sites

I installed v1.4, it shows discount rate at user end.

But after I place order, the other functions under "My Account", are missing. Such as

"View or change my account information.

View or change entries in my address book.

Change my account password."

in "My Account";

 

"Subscribe or unsubscribe from newsletters.

View or change my product notification list"

in "Email Notification";

 

The only thing shows at the same page after place order is "View my orders".

 

Any one please help?

 

This is my website,

www.osgmyart.com

 

Also I am not able to edit My address after install V1.4.

 

Thanks!

Link to comment
Share on other sites

  • 2 weeks later...

Hi, I've had the loyalty scheme running for quite a while now and everything is great.

 

We recently installed the 'Purchase without account' module and this is conflicting with the loyalty scheme.

 

It seems that all customers checking out without an account are being issued the same customer_id and therefore each new customer that checks out without an account is getting a higher and higher loyalty bonus.

 

Is there a way to amend the code to say 'if customer_id = 0 (or whatever it is) then do not add loyalty bonus'?

 

Thanks

 

Jos

===============

Simple yet Creative

Get Online Web Design : getonlinedesign.com

===============

Link to comment
Share on other sites

  • 5 weeks later...
Hi in the account.php I have this error message

 

Fatal error: Call to undefined method order_total::output_discount() in /var/www/vhosts/mysite/httpdocs/store/catalog/account.php on line 100

 

this is what I add ..the line 100 is in red

 

?> <tr> <td><table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr> <td class="main"><b><?php echo MY_ACCOUNT_DISCOUNTS; ?></b></td> </tr> </table></td> </tr> <tr> <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox"> <tr class="infoBoxContents"> <td><table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr> <td><table border="0" width="100%" cellspacing="0" cellpadding="2"><?php require(DIR_WS_CLASSES . 'order_total.php'); require(DIR_WS_CLASSES . 'order.php'); $order = new order; $order_total_modules = new order_total; if (MODULE_ORDER_TOTAL_INSTALLED) { $order_total_modules->process(); echo '<tr><td align="left" class="main">' . MODULE_LOYALTY_DISCOUNT_TITLE . ' : ' . $order_total_modules->output_discount() . '%</td></tr>'; }?> </table></td> <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td> </tr> </table></td> </tr> </table></td> </tr> <tr> <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td> </tr><?php

 

I've also got this problem. I've edited order_total.php to insert the function into it, but it seems that it's not reading it for some reason.....

Link to comment
Share on other sites

  • 1 month later...
  • 3 weeks later...
Hi,

 

Has anyone figured out how to fix the problem of this module not passing the discounted total onto paypal? Just shows the normal total without the discount in paypal....

 

I have this installed and it works fine with paypal. What version of Paypal mod are u using? I'm using an older version, 1.4 since I'm also using CCGV and that will only work with that version of paypal IPN mod.

Currently running 76 contibutions.

Link to comment
Share on other sites

For those of you who are having problems getting the dsicount status to show in account.php, I have uploaded a new version with a modified install instructions to get it to show in account.php. It works well on my site.

 

One note: If you have CCGV or Discount coupons installed, this will work with that, however the discount will be applied to the subtotal after any other discounts are removed. I'm not a coder so I don't know of any way around it. It works for me, but may not be what you want.

Currently running 76 contibutions.

Link to comment
Share on other sites

@ Jos Medinger

 

Is there a way to amend the code to say 'if customer_id = 0 (or whatever it is) then do not add loyalty bonus'?

 

You can add this to the $history_query_raw:

 

... and o.customers_id != 0 and ot.class ...

Link to comment
Share on other sites

  • 1 month later...

module works great, but i find i need a way to check individual customers discount progress in admin, just like the customer can view there progress when they log in with the modifications to the account.php file below.

 

 

 

 

 

 

// 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($cust_tot_order_amount,0) . '<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($table_cost[$i]) . '</span></td>
<td width="100" align="center"><img src="images/checkmark.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($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($table_cost[$i]-$cust_tot_order_amount) . '</span></td>
</tr>';
}
}
$order_hist_text .= '</table>';
?>
 <tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
  </tr>
  <tr>
	<td><table border="0" width="100%" cellspacing="0" cellpadding="2">
	  <tr>
		<td class="main"><b><?php echo MY_DISCOUNTS_TITLE; ?></b></td>
	  </tr>
	</table></td>
  </tr>
  <tr>
	<td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
	  <tr class="infoBoxContents">
		<td><table border="0" width="100%" cellspacing="0" cellpadding="2">
		  <tr>
			<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
			<td width="60"><?php echo tep_image(DIR_WS_IMAGES . 'account_orders.gif'); ?></td>
			<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
			<td><table border="0" width="100%" cellspacing="0" cellpadding="2">
			  <tr>
				<td class="main"><?php echo $order_hist_text; ?></td>
			  </tr>
			</table></td>
			<td width="10" align="right"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
		  </tr>
		</table></td>
	  </tr>
	</table></td>
<!-- End display Loyalty discount for customer plus the table and his current place in it. -->

Link to comment
Share on other sites

Hi There,

i'm really excited about this contribution, it looks like a smart way to make customers happy.

I have an example :

I place 5% discount on 100 $$ total orders.

I settled up monthly as time period.

What i don't understand is :

Customer buy let's say 100 bucks and get 5% discount for all the next orders he will place.

The "time" the discount will last is 30 days from the date it's been agreed or forever??

So after 30 days it will be resetted again or it will last?

Thanks in advance, it may sound silly but i wish to be sure about it!

Regards

Fab

Edited by Freeman

Advice on forum are Free, Email or Pm to fix your site is work...which I charge for :)

-------------------

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