Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Customer Loyalty Discount Scheme


misspiggy

Recommended Posts

I just installed the latest version and have one small problem, the discount amount is calculated correctly but is displayed wrong. It is off by 2 or 3 cents for a .46 cent discount. Anyone else having this problem or is it just me?

 

Thanks

Sean

Link to comment
Share on other sites

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

Top Posters In This Topic

I need some quick help.

I have SPPC (separate price per customer) installed on my webpage and would like to disable the loyalty discount for all but 1 customer group.

 

The info to which customer group the customer belongs is stored in the database table CUSTOMERS in the field customer_group_id.

The module (including the account.php info box) should only be active if the customer_group_id = 0 and disabled for all other values.

 

Can someone come up with a quick fix for this?

Link to comment
Share on other sites

I managed to switch of the Discount information in account.php by wrapping the complete Loyalty Discount addition into:

if ($sppc_customer_group_id == 0) { 

//All the Loyalty Discount Code

<?php
; }
?>

 

This might not be the most elegant way but it works...

 

Unfortunately I can not figure out how to disable the loyalty discount in the order confirmation in a similar way. :'(

Can anyone help??

Edited by Idefix_SIN
Link to comment
Share on other sites

I got an answer. In case someone else needs to do the same:

 

includes\modules\order_total\ot_loyalty_discount.php

 

Add the following on the top directly behind function ot_loyalty_discount() {

 

// BOF Separate Pricing per Customer
 if (isset($_SESSION['sppc_customer_group_id']) && $_SESSION['sppc_customer_group_id'] != '0') {
   $this->cg_id = $_SESSION['sppc_customer_group_id'];
 } else {
   $this->cg_id = '0';
 }
// EOF Separate Pricing per Customer

 

a few lines down, change

 

$this->enabled = MODULE_LOYALTY_DISCOUNT_STATUS;

 

to

 

     if ($this->cg_id == '0') {
       $this->enabled = MODULE_LOYALTY_DISCOUNT_STATUS;
     } else {
       $this->enabled = false;
     }

Edited by Idefix_SIN
Link to comment
Share on other sites

Can anyone please help with this add on. The total sent to paypal does not subtract the discount ie if order is 4.99 and has a deduction of 0.05. when the result is sent to paypal it still appears as 4.99 and I have to go back to paypal and refund the 0.05p after the payment. Please help. Thank you.

Edited by kenyatopup
Link to comment
Share on other sites

  • 3 months later...

If the order status is set to "prepairing" the discount can been seen in the customers account, but if I update the order status to something like shipped, the discount dissapears in the customers account, any ideas?

Edited by Windows
Link to comment
Share on other sites

If the order status is set to "prepairing" the discount can been seen in the customers account, but if I update the order status to something like shipped, the discount dissapears in the customers account, any ideas?

Any ideas anyone?

 

Thanks

Link to comment
Share on other sites

  • 5 months later...

Hello,

 

I have a problem with this contrib.

 

I'm using OsCommerce 2.2 RC 2.a

 

I installed everything like the manual says.

In the User Account there is a list when the user gets discount, but he doesn't count the total orders.

And because of that there is no discount displaying on any order.

I have the minimal amount of purchases but nothing is counting up.

 

Does anybody know how i can get this to work??

 

Thanks

Greetings,

 

Henk Bartels

Link to comment
Share on other sites

  • 3 months later...

I have the following problem.

The discount is shown on the order page, but it jus say that the client have the right to recieve X $ (x=value) for that order, but is the last on the Total-Order form so is not applay to the order.

Sub total

shiping tax

Taxes

Total

Loyality discount

 

So the loiality discount is not apply and customer do not get's it

 

I have put here all the cod that i have. Please help

 

 

<?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, 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";

$history_query = tep_db_query($history_query_raw);

if (tep_db_num_rows($history_query)) {

$cum_order_total = 0;

$cutoff_date = $this->get_cutoff_date();

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

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

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

}

}

$this->cum_order_total = $cum_order_total;

return $cum_order_total;

 

}

else {

$cum_order_total = 0;

$this->cum_order_total = $cum_order_total;

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

  • 5 months later...

Please - has anyone found a fix for this? (discount not going thru to Paypal...)

 

Can anyone please help with this add on. The total sent to paypal does not subtract the discount ie if order is 4.99 and has a deduction of 0.05. when the result is sent to paypal it still appears as 4.99 and I have to go back to paypal and refund the 0.05p after the payment. Please help. Thank you.

Link to comment
Share on other sites

  • 6 months later...

I think the problem is this module only displays the discount the customer receives, it doesn't actually change it, that's why by paying directly (via PayPal) charges the full amount. If I knew where exactly the order total is calculated, maybe I could change it. I have looked extensively but the code is just to big and complicated to go looking blindly for such a small thing.

Link to comment
Share on other sites

  • 2 weeks later...

Hello!

I installed the Customer Loyalty Discount Scheme

After I installed no saw there a discount on first order.

Minimum order 100Euro

How can so that when customers first purchase over 200e for example, he will receive instant example. 5% discount.

Please help me with any suggestions.

Thanks

Link to comment
Share on other sites

  • 5 months later...

Hi All

 

I added this mod and its great but its not working fully.

 

i can see that i am able to recieve a discount on products but when i am in the checkout the checkout does not show any discount on price and the price on email confirmation is RRP not the discounted price.

 

When i am in my account page it shows i am able to have for exampple 15% discount, but it does not seem to be accouted for anywhere else apart from the account page.

 

Any ideas?

 

thanks!

Link to comment
Share on other sites

  • 1 year later...

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