PDA

View Full Version : Free Shipping Coupon and LinkPoint



driwashsolutions
01-07-2006, 09:13 PM
I'm trying to use a free shipping coupon in my store. I'm usin the linkpoint gateway, which required that the subtotal, shipping and total match. So, if any discounts are applied (such as a free shipping coupon) these don't add up as far as linkpoint is concerned.

So, I though I would take the free shipping off before the order is subtotaled, then everything would jive. I've done this through the order total module sort order.

Well, the subtotal is not removing the free shipping amount, so the values still don't jive.

What can I do to get this to work?

driwashsolutions
01-12-2006, 04:15 AM
OK figured out the problem for us Linkpoint users.

First, there is a piece of code missing from the catalog/includes/modules/order_total/ot_coupon.php file. Find the this section of code:

function process() {
global $PHP_SELF, $order, $currencies;


$order_total=$this->get_order_total();
$od_amount = $this->calculate_credit($order_total);
$tod_amount = 0.0; //Fred
$this->deduction = $od_amount;
if ($this->calculate_tax != 'None') { //Fred - changed from 'none' to 'None'!
$tod_amount = $this->calculate_tax_deduction($order_total, $this->deduction, $this->calculate_tax);
}

if ($od_amount > 0) {
$order->info['total'] = $order->info['total'] - $od_amount;


Then, add this just below it:


$_SESSION['od_amount'] = $od_amount;


This will then allow this piece of code which already exists in the catalog/includes/modules/order_total/ot_subtotal.php file to work correctly:


function process() {
global $order, $currencies;

// BOF: LINES ADDED
$od_amount = $_SESSION['od_amount'];
$subtotal = $order->info['subtotal'] - $od_amount;
$order->info['subtotal'] = $order->info['subtotal'] - $od_amount;
// EOF: LINES ADDED


Finally, change the sort order of the order total modules to put the Discount Coupons BEFORE the subtotal module, and everything will then work out. Here's how it looks in my store:

http://www.atoolcrib.com/images/oscdox1.gif

Now, I'm not a proficient PHP programmer, but there are sections of code that have the $_SESSION line commented out with a statement that says to use the global variable rather than the $_SESSION statement. So if there's a better, more preferred method of getting the $od_amount into the ot_subtotal routine, I would certainly welcome the tip.

John

red_fraggle
05-24-2006, 07:48 PM
actually you didnt figure this out, lol, its in the installation instructions i wrote and included with the module and which micheal has included in the module directory for you in the /includes/linkpoint directory.

this is plainly documented, it is required ONLY if you use this module or the credit class gift voucher modification.

linkpoint was originally written for stock oscommerce which did not come with these modules and therefore the code had to be changed IF and only IF you actually added these modules to your store. Since these modules come with oscmax, it needs to be done.

BadDog
12-16-2006, 07:40 PM
OK figured out the problem for us Linkpoint users.

Finally, change the sort order of the order total modules to put the Discount Coupons BEFORE the subtotal module, and everything will then work out.
John
Can you be more specific about what files are changed and how in order to change the sort order of the order total modules? I don't want to screw it up. :confused:

BadDog
12-18-2006, 05:04 AM
actually you didnt figure this out, lol, its in the installation instructions i wrote and included with the module and which micheal has included in the module directory for you in the /includes/linkpoint directory.

this is plainly documented, it is required ONLY if you use this module or the credit class gift voucher modification.

linkpoint was originally written for stock oscommerce which did not come with these modules and therefore the code had to be changed IF and only IF you actually added these modules to your store. Since these modules come with oscmax, it needs to be done.

I cannot find the file credit_voucher_gift_card_hack.txt mentioned in the install instructions. Can anyone poiint me in the right direction? I'm trying to make a mod called ccgv(trad) for osCommerce work with Linkpoint. Thanks.

michael_s
12-18-2006, 06:56 AM
OK figured out the problem for us Linkpoint users.

First, there is a piece of code missing from the catalog/includes/modules/order_total/ot_coupon.php file. Find the this section of code:

function process() {
global $PHP_SELF, $order, $currencies;


$order_total=$this->get_order_total();
$od_amount = $this->calculate_credit($order_total);
$tod_amount = 0.0; //Fred
$this->deduction = $od_amount;
if ($this->calculate_tax != 'None') { //Fred - changed from 'none' to 'None'!
$tod_amount = $this->calculate_tax_deduction($order_total, $this->deduction, $this->calculate_tax);
}

if ($od_amount > 0) {
$order->info['total'] = $order->info['total'] - $od_amount;
Then, add this just below it:


$_SESSION['od_amount'] = $od_amount;
This will then allow this piece of code which already exists in the catalog/includes/modules/order_total/ot_subtotal.php file to work correctly:


function process() {
global $order, $currencies;

// BOF: LINES ADDED
$od_amount = $_SESSION['od_amount'];
$subtotal = $order->info['subtotal'] - $od_amount;
$order->info['subtotal'] = $order->info['subtotal'] - $od_amount;
// EOF: LINES ADDED
Finally, change the sort order of the order total modules to put the Discount Coupons BEFORE the subtotal module, and everything will then work out. Here's how it looks in my store:

http://www.atoolcrib.com/images/oscdox1.gif

Now, I'm not a proficient PHP programmer, but there are sections of code that have the $_SESSION line commented out with a statement that says to use the global variable rather than the $_SESSION statement. So if there's a better, more preferred method of getting the $od_amount into the ot_subtotal routine, I would certainly welcome the tip.

John


Just follow these instructions...already there for you, no need to look elsewhere.

BadDog
12-18-2006, 08:19 AM
Just follow these instructions...already there for you, no need to look elsewhere.
Well, that seems to work for discount coupons, but it does not work for gift certificates (at least not with ccgv(trad)), so I'm still looking for a solution for that piece.

michael_s
12-18-2006, 09:08 AM
Maybe I am asking too much, but if it works in ot_coupon.php... why not make the logical connection that it should also work in ot_gv.php?

Here is the text file from the linkpoint mod:


Simple really, just had to figure out the "PHP" way to do it. Just a couple of edits so I won't include full files.

In /catalog/includes/modules/ot_coupon.php:

Find lines:

if ($od_amount > 0) {
$order->info['total'] = $order->info['total'] - $od_amount;

Add this line right after:

$_SESSION['od_amount'] = $od_amount;

In /catalog/includes/modules/ot_subtotal.php:

Find lines:

function process() {
global $order, $currencies;

Add right after:

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

Then, make sure the sort order of the payment lines (via OSCommerce admin
site) puts discount before subtotal.

Essentially, I just used the global PHP session to make the discount amount available in the standard subtotal routine. There may be more correct ways to do it but it works.

BadDog
12-18-2006, 10:00 AM
Maybe I am asking too much, but if it works in ot_coupon.php... why not make the logical connection that it should also work in ot_gv.php?

Here is the text file from the linkpoint mod:

I added the line from ot_coupon.php to ot_gv.php but it did not work. Maybe there is a conflict between discount coupons and gift certificates? Maybe you can only use one or the other but not both? Hopefully someone who knows more about these than I do can shed some light on this.

michael_s
12-18-2006, 11:36 AM
Did you put the gift voucher ot mod before the subtotal?

BadDog
12-18-2006, 11:57 AM
Did you put the gift voucher ot mod before the subtotal?
Yes. I moved it to before the discount coupon, and then tried it after the discount coupon., Both times it was before the subtotal and total. I agree that logically it should work, so I'm sure I'm just missing something. I've tried so many variations that I can't remember if I've tried gift certificates with discount coupons turned off or not. Do you think that would do it? I hate to give up discount coupons though.

michael_s
12-18-2006, 12:36 PM
I don't have access to linkpoint so the help I can offer is limited. It should work, as it all uses the same code. It has to be the order totals setup that is causing the problems. So what error is linkpoint giving you with the current set up?

BadDog
12-18-2006, 01:05 PM
I don't have access to linkpoint so the help I can offer is limited. It should work, as it all uses the same code. It has to be the order totals setup that is causing the problems. So what error is linkpoint giving you with the current set up?

As I understand it, Linkpoint compares the product total plus shipping and taxes to the charge amount and kicks back an error if they don't add up. The standard code for the gift certificates reduces the amount of the charge by the amount of the gift certificate, making Linnkpoint think things don't add up.

michael_s
12-18-2006, 01:24 PM
So if the subtotal is reduced before being sent to linkpoint, it should work correctly... That is what we are doing. Changing the subtotal before sending to linkpoint. I am at a loss as to why it is not working for you.

BadDog
12-18-2006, 01:37 PM
So if the subtotal is reduced before being sent to linkpoint, it should work correctly... That is what we are doing. Changing the subtotal before sending to linkpoint. I am at a loss as to why it is not working for you.

Ok, here is the latest. I removed discount coupons and installed gift certificates. I modified catalog/includes/moduals/order_total/ot_gv.php around line 52 to change it from this:


$order->info['total'] = $order->info['total'] - $od_amount;
if ($od_amount > 0) {
to this:


$order->info['total'] = $order->info['total'] - $od_amount;
$_SESSION['od_amount'] = $od_amount;
if ($od_amount > 0) {

and it seems to be working. The bottom line (I think) is that you cannot run both discounted coupons and gift certificates at the same time. Does that make sense?

FloridaTucano
12-18-2006, 09:57 PM
I have been debugging this problem and I believe I found the reason.

Sidenote:
The order of the ORDER_TOTAL modules does not really matter, the functionality seems to always calculate correctly based on the selected SORT_ORDER.
Moving the coupons before the Sub-Total looks really weird, especially if you use them for Free Shipping. They should be after the Shipping Module.

OK, here is the "real" problem:

checkout_process.php creates a new instance of $order.
require(DIR_WS_CLASSES . 'order.php');
$order = new order;

The order-class executes the cart() function, but the cart() function does not have any code for discount coupons or gift vouchers to manipulate the $order['subtotal'] value.
Here would be the correct place to implement.

Sorry I can't provide the code fix, maybe someone else is skilled enough.

Hope this helped.
Stefan

BadDog
12-19-2006, 04:29 AM
I have been debugging this problem and I believe I found the reason.

Sidenote:
The order of the ORDER_TOTAL modules does not really matter, the functionality seems to always calculate correctly based on the selected SORT_ORDER.
Moving the coupons before the Sub-Total looks really weird, especially if you use them for Free Shipping. They should be after the Shipping Module.

OK, here is the "real" problem:

checkout_process.php creates a new instance of $order.
require(DIR_WS_CLASSES . 'order.php');
$order = new order;

The order-class executes the cart() function, but the cart() function does not have any code for discount coupons or gift vouchers to manipulate the $order['subtotal'] value.
Here would be the correct place to implement.

Sorry I can't provide the code fix, maybe someone else is skilled enough.

Hope this helped.
Stefan
In the meantime, here is a fix that does work for me on osCommerce with CCGV(trad) installed:

In catalog/includes/modules/order_total/ot_subtotal.php

After this:
function process() {
global $order, $currencies;

Add this:

// BOF: LINES ADDED
$od_amount = $_SESSION['od_amount'];
$subtotal = $order->info['subtotal'] - $od_amount;
$order->info['subtotal'] = $order->info['subtotal'] - $od_amount;
// EOF: LINES ADDED

In catalog/includes/modules/order_total/ot_gv.php

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

add this:
//Added next line to fix Linkpoint problem
$_SESSION['od_amount'] = $od_amount;
//End of Linkpoint mod

When you install the CCGV(trad) mod, it gives a sort order of 734 or something like that (in Admin, click on Modules, then Order Total, then Gift Certificates). Try changing it to 9 and change tax to 10, subtotal to 11, and total to 12 (those are the values that work for me). I renamed Sub-Total to Product Total because that made more sense to me. I also eliminated references to coupons in the text (Account, Shopping Cart, etc.). As far as I can tell, you cannot use discount coupons and gift certificates at the same time. One or the other, but not both (at least I haven't figured that one out yet).

I'd be interested in any other approach that is cleaner, especially if it will let me run discount coupons and gift certificates at the same time.

FloridaTucano
12-19-2006, 04:51 PM
BadDog,

I have to disagree with this "hack" :no:

If you have to manipulate the $order values, you should do it in checkout_process.php something like this:

after:

require(DIR_WS_CLASSES . 'order.php');
$order = new order;

$od_amount = $_SESSION['od_amount']; // Order Discount Amount
$gv_amount = $_SESSION['gv_amount']; // Gift Voucher Amount

$order->info['subtotal'] = $order->info['subtotal'] - $od_amount - $gv_amount ;
if (DISPLAY_PRICE_WITH_TAX == 'true') {
$this->info['total'] = $this->info['subtotal'] + $this->info['shipping_cost'] ;
} else {
$this->info['total'] = $this->info['subtotal'] + $this->info['tax'] + $this->info['shipping_cost'];
}in ot_gv.php you declare in function process()
$_SESSION['gv_amount'] = $od_amount;
if ($od_amount > 0) {
[...]


Doing it in checkout_process.php does not require the change in linkpoint_api.php and has the benefit that the order is properly recorded in the order table.

You also don't have to change the sort_order in the Order Total, wouldn't you want to display the cart as follows:

Article1
Article2
Sub-Total
Shipping Cost
Discount Coupon
Tax
Total ?

instead of having the Discount Coupon reduce from your Sub-Total ?

The CLEAN approach is to change order.php -> function cart() and consider the Coupons and Gift Vouchers here without using the SESSION variables. No further changes would be needed in any other place.

Stefan

BadDog
12-19-2006, 05:31 PM
BadDog,

I have to disagree with this "hack" :no:

If you have to manipulate the $order values, you should do it in checkout_process.php something like this:

after:
require(DIR_WS_CLASSES . 'order.php');
$order = new order;

$od_amount = $_SESSION['od_amount']; // Order Discount Amount
$gv_amount = $_SESSION['gv_amount']; // Gift Voucher Amount

$order->info['subtotal'] = $order->info['subtotal'] - $od_amount - $gv_amount ;
if (DISPLAY_PRICE_WITH_TAX == 'true') {
$this->info['total'] = $this->info['subtotal'] + $this->info['shipping_cost'] ;
} else {
$this->info['total'] = $this->info['subtotal'] + $this->info['tax'] + $this->info['shipping_cost'];
}

in ot_gv.php you declare in function process()
$_SESSION['gv_amount'] = $od_amount;
if ($od_amount > 0) {
[...]


Doing it in checkout_process.php does not require the change in linkpoint_api.php and has the benefit that the order is properly recorded in the order table.

You also don't have to change the sort_order in the Order Total, wouldn't you want to display the cart as follows:

Article1
Article2
Sub-Total
Shipping Cost
Discount Coupon
Tax
Total ?

instead of having the Discount Coupon reduce from your Sub-Total ?

The CLEAN approach is to change order.php -> function cart() and consider the Coupons and Gift Vouchers here without using the SESSION variables. No further changes would be needed in any other place.

Stefan

I backed out the changes I outlined above and tried making your changes, but I got an error. I might not have followed your instructions, so let me tell you what changes I made and see if you can spot my error.

In ot_subtotal.php I commented out the lines I had added before:
// BOF: LINES ADDED
// $od_amount = $_SESSION['od_amount'];
// $subtotal = $order->info['subtotal'] - $od_amount;
// $order->info['subtotal'] = $order->info['subtotal'] - $od_amount;
// EOF: LINES ADDED

In ot_gv.php I commented out the lines I added before:
//Added next line to fix Linkpoint problem
//$_SESSION['od_amount'] = $od_amount;
//End of Linkpoint mod

In ot_gv.php I added these lines:
after function process() {
global $order, $currencies, $cot_gv;
I added
//LINKPOINT MOD START
$_SESSION['gv_amount'] = $od_amount;
if ($od_amount > 0) {
//LINKPOINT MOD END

In checkout_process.php, after
require(DIR_WS_CLASSES . 'order.php');
$order = new order;
I added:
//LINKPOINT MOD START
$od_amount = $_SESSION['od_amount']; // Order Discount Amount
$gv_amount = $_SESSION['gv_amount']; // Gift Voucher Amount

$order->info['subtotal'] = $order->info['subtotal'] - $od_amount - $gv_amount ;
if (DISPLAY_PRICE_WITH_TAX == 'true') {
$this->info['total'] = $this->info['subtotal'] + $this->info['shipping_cost'] ;
} else {
$this->info['total'] = $this->info['subtotal'] + $this->info['tax'] +

$this->info['shipping_cost'];
}
//LINKPOINT MOD END

Where did I go wrong?

FloridaTucano
12-19-2006, 06:02 PM
Sorry, my post wasn't really a step-by-step instruction, more like a how-to.

in ot_coupon.php - function process()
[...]
if ($od_amount > 0) {
$order->info['total'] = $order->info['total'] - $od_amount;
$this->output[] = array('title' => $this->title . ':' . $this->coupon_code .':', 'text' => '<b>-' . $currencies->format($od_amount) . '</b>', 'value' => $od_amount);
$_SESSION['od_amount'] = $od_amount; // Linkpoint Fix for Discount
}
[...]

in ot_gv.php - function process()
[...]
$order->info['total'] = tep_round($order->info['total'],2);
$od_amount = tep_round($od_amount,2);
$order->info['total'] = $order->info['total'] - $od_amount;
$_SESSION['gv_amount'] = $od_amount; // Linkpoint Fix for Gift Voucher
if ($od_amount > 0) {
[...]

Only the red lines need to be added.
And then the change in checkout_process.php as you have them.

Works for me, but I'd like a cleaner approach. Hopefully over christmas I will find some time to dig deeper into the code.

Stefan

BadDog
12-19-2006, 06:32 PM
Sorry, my post wasn't really a step-by-step instruction, more like a how-to.

in ot_coupon.php - function process()
[...]
if ($od_amount > 0) {
$order->info['total'] = $order->info['total'] - $od_amount;
$this->output[] = array('title' => $this->title . ':' . $this->coupon_code .':', 'text' => '<b>-' . $currencies->format($od_amount) . '</b>', 'value' => $od_amount);
$_SESSION['od_amount'] = $od_amount; // Linkpoint Fix for Discount
}
[...]

in ot_gv.php - function process()
[...]
$order->info['total'] = tep_round($order->info['total'],2);
$od_amount = tep_round($od_amount,2);
$order->info['total'] = $order->info['total'] - $od_amount;
$_SESSION['gv_amount'] = $od_amount; // Linkpoint Fix for Gift Voucher
if ($od_amount > 0) {
[...]

Only the red lines need to be added.
And then the change in checkout_process.php as you have them.

Works for me, but I'd like a cleaner approach. Hopefully over christmas I will find some time to dig deeper into the code.

Stefan

Fatal error: Using $this when not in object context in /home/********/catalog/checkout_process.php on line 57

FloridaTucano
12-19-2006, 09:42 PM
Okay, replace $this with $order

if (DISPLAY_PRICE_WITH_TAX == 'true') {
$order->info['total'] = $order->info['subtotal'] + $order->info['shipping_cost'] ;
} else {
$order->info['total'] = $order->info['subtotal'] + $order->info['tax'] + $order->info['shipping_cost'];
}