Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Strider

Credit Class/Gift Vouchers/Discount Coupons 5.10

Recommended Posts

Hey guys...

 

I am using version 5.15a1, and everything seems to be working great. Thanks for all the good work...!

Edited by RollingStone

Share this post


Link to post
Share on other sites

Hi there,

 

You must be one of the lucky few then....Do you use Paypal for payments? If the voucher balance is more then the amount to pay for, does Paypal get the right amount instead of e.g. 0,= ? Did you change anything yourself in this contribution? And if so, what did you change? Do you use discount for new users and does the redeem process work (not having to redeem 2 times e.g.)....etc...etc...

 

Regards,

Sokos.

 

Hey guys...

 

I am using version 5.15a1, and everything seems to be working great. Thanks for all the good work...!

Share this post


Link to post
Share on other sites
Hey guys...

 

I am using version 5.15a1, and everything seems to be working great. Thanks for all the good work...!

so you're saying that you are not getting the error i posted just a few posts above? i'm on 5.15a1 also...

Share this post


Link to post
Share on other sites
so you're saying that you are not getting the error i posted just a few posts above? i'm on 5.15a1 also...

 

The problem you are refering to is a universal error with this contribution and as far as I know there is no fix for it!!!

 

I am not a coder but if I were this fix fould be Priority #1!!

 

Thanks for pointing out the error in admin/column_left.php.... That will be fixed in 5.15a2.....(along with the coupon enter 2x error!!)

Share this post


Link to post
Share on other sites

Hello to all of you

 

I found some people having the same problem than me but no clear answer:

 

 

 

If I create a discount coupon + free shipping then only free shipping works, it overides the discount entered in coupon_value.

In the admin page, it shows a coupon value in EUR and not in % if I ticked free shipping

 

Is it a normal behaviour or a bug?

 

Thanks for your help

Patrice

Edited by patator

Share this post


Link to post
Share on other sites

Everything works great except the product prices do not display in the catalog is has "Zeros" (0).

Is there something I am missing? Can anyone tell me what needs to be fixed so the prices will display?

Edited by carolgann

Share this post


Link to post
Share on other sites
Hello to all of you

 

I found some people having the same problem than me but no clear answer:

If I create a discount coupon + free shipping then only free shipping works, it overides the discount entered in coupon_value.

In the admin page, it shows a coupon value in EUR and not in % if I ticked free shipping

 

Is it a normal behaviour or a bug?

 

Thanks for your help

Patrice

i don't think a percentage and free shipping is able to work together at the same time right now, it automatically changes it to a standard dollar amount in the selected currency.

Share this post


Link to post
Share on other sites
Everything works great except the product prices do not display in the catalog is has "Zeros" (0).

Is there something I am missing? Can anyone tell me what needs to be fixed so the prices will display?

<p>Also in the Admin/ Modules /Total Order/Gift Vouchers, the text where you Edit is in French not English. How do I change it to English</p>

Share this post


Link to post
Share on other sites

ok so does the latest version work or not??? I want to know if I should install this on my store or not install it, I really would like to offer this but I dont want any problems.


Don't die with the music in you!!!

 

Failure is just another boundary to sucess!!! But that doesn't mean your getting somewhere...

Share this post


Link to post
Share on other sites
i don't think a percentage and free shipping is able to work together at the same time right now, it automatically changes it to a standard dollar amount in the selected currency.

 

I also have verified that when checking Free Shipping, any percent value changes to a $ value when free shipping is checked. For example, if you have configure a 10$ coupon but then tick the Free Shipping checkbox and save the coupon, the 10% changes to $10.

 

Joe

Share this post


Link to post
Share on other sites

I get the same problem- you have to enter the discount code twice to get it to go through. I'm using the latest version.

 

One temporary work around is to edit the error message to "error: please enter your code again". Most people will think they had made a typo when they first tried to enter the code and put the code in again without thinking twice!

 

Does anyone know how to move the discount code box to the top of the checkout payment page? I would like to do that so the customer redeems the coupon first and then enters their credit card info. Right now they end up having to edit the credit card info twice.

Share this post


Link to post
Share on other sites

I have a working CCVG v5.15 (with a few fixes) and recently have been testing use of the Coupon Admin settings:

 

Valid Product List

Valid Categories List

 

I first found that when the View button was checked I received a file not found error. Research showed that the CCVG v5.15 contribution is correctly configured to use the "CCVG Treeview". However, the Treeview add-on files needed to make this contribution work were missing. Once the CCVG Treeview contribution add-on files were added, it functioned properly with a graphical tree view ans select capability of all categories and products.

 

Testing of a 10% coupon redemption functioned normally until I tried to restrict the coupon to specific products or categories using the Valid Product List or Valid Categories List. When I redeemed coupons that were in the Valid Product List or Valid Category List, the redeem produced an error indicating the coupon was good:

 

***HOWEVER:No reducion available, please see the coupon restrictions***

 

So I have resolved the problem as follows:

 

In /catalog/includes/modules/order_total/ot_coupon.php, find this line in two places in "Function calculate_credit($amount)"

 

$pr_c = $this->product_price($pr_ids[$ii]); //Fred 2003-10-28, fix for the row above, otherwise the discount is calc based on price excl VAT!

 

Comment the lines out and replace it with this:

 

$pr_c = ($order->products[$i]['final_price'] * $order->products[$i]['qty']);

 

If you experience Coupons not being Redeemed when using the Valid Product List or Valid Category List settings, this does resolve it. I will be doing more testing over the next several days and will post more as I find it. Hope this helps and if someone has a better answer of if I have made an error, please do bring it up. I can take it. :-"

 

Joe

Share this post


Link to post
Share on other sites
Guest

Thanks Shane Jackson, I have just finally got CCGV to work on my new shop.

 

I still had issues, but these were not in the CCGV codes. Since I have many mods installed, I retained my existing files and copied the CCGV changes to them. To get CCGV working, I had to copy all of my mods into the CCGV files.

 

I also had to put Discount Coupons on a lower priority than Gift Vouchers.

 

I have not completed testing yet, but the only problem is with Discount Coupons. The only way that I can get the discount to apply to products is to have both the valid product list and valid category list empty. This is not good because I do not want to offer a discount on Gift Vouchers.

Share this post


Link to post
Share on other sites

I'm working through this contribution trying to get it to work with Linkpoint. I'm looking at the ot_subtotal.php and see there has been an addition that relates to the CCGV mod. These lines are:

 

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

 

Interestingly, other sections of code for the order totals have any _SESSION lines commented out, with text that says

 

//$cc_id = $_SESSION['cc_id']; //Fred commented out, do not use $_SESSION[] due to backward comp. Reference the global var instead.

 

So, my question is: how does one replace the $od_amount = $_SESSION['od_amount']; line with a global variable?

 

This section of code should remove the coupon amount from the subtotal, which is not working in my store. My subtotal equals the dollar amount in the cart, even after the coupon is applied. I suspect this is the issue, since when using Linkpoint, the subtotal, shipping and total are sent to the Linkpoint CC Gateway and right now, they don't add up.


John Skurka

Share this post


Link to post
Share on other sites
I get the same problem- you have to enter the discount code twice to get it to go through. I'm using the latest version.

 

One temporary work around is to edit the error message to "error: please enter your code again". Most people will think they had made a typo when they first tried to enter the code and put the code in again without thinking twice!

 

Does anyone know how to move the discount code box to the top of the checkout payment page? I would like to do that so the customer redeems the coupon first and then enters their credit card info. Right now they end up having to edit the credit card info twice.

 

Ed, I am not having this problem using CCVG v5.15 and the fix I posted a few pages back to resolve this (for v5.15). I only enter my Coupon code once and it is good. I have added the "Easier2Understand Payment Add-on v1.2" and this provides the order total at the Checkout Payment screen and posts the discount coupon there where they enter their credit card payment. The Easier2Understand Payment Add-on v1.2 contribution was a bit tedious to get installed but once in there, works great and is a great benefit.

 

Here is a screen shot of my site for example:

 

009.jpg

 

Joe

Share this post


Link to post
Share on other sites
***HOWEVER:No reducion available, please see the coupon restrictions***

 

So I have resolved the problem as follows:

 

In /catalog/includes/modules/order_total/ot_coupon.php, find this line in two places in "Function calculate_credit($amount)"

 

$pr_c = $this->product_price($pr_ids[$ii]); //Fred 2003-10-28, fix for the row above, otherwise the discount is calc based on price excl VAT!

 

Comment the lines out and replace it with this:

 

$pr_c = ($order->products[$i]['final_price'] * $order->products[$i]['qty']);

 

If you experience Coupons not being Redeemed when using the Valid Product List or Valid Category List settings, this does resolve it. I will be doing more testing over the next several days and will post more as I find it. Hope this helps and if someone has a better answer of if I have made an error, please do bring it up. I can take it. :-"

 

Joe

 

 

Tried it but still have to enter the coupon 2x...........

Share this post


Link to post
Share on other sites

Ok, here's what I've been able to pinpoint so far in regards to the error:

Congratulations, you have redeemed <BR>***HOWEVER:No reducion available, please see the coupon restrictions***

The error message that appear 2x's comes from the code from the Redeem message fix from the CCGV contribution added by Scranmer. It you remove the code he added (marked by **si** 09-11-05) to the includes\modules\order_total\ot_coupon.php file and go back to the original code, you should only get one redeem message and it should redeem the correct amount as a temporary fix for now. BUT the problem the message generates is from the ERROR_REDEEMED_AMOUNT from the includes\languages\english.php file

 

So, it tells us that even though it is applying the coupon correctly, it is generating text using an ERROR redeem message (Note: instead of fixing this problem, someone just changed the ERROR_REDEEMED_AMOUNT message to a positive 'Congratulations' message instead.)

 

So far, i have been able to isolate where the ERROR_REDEEMED_AMOUNT code is coming from... in the Update 5.13a that Rigadin contributed, he added the following code to the includes\modules\order_total\ot_coupon.php file:

tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_REDEEMED_AMOUNT), 'SSL')); // Added in v5.13a by Rigadin

 

Not sure why a successful redeem is being redirect to the payment_error function. Anyone have any suggestions?

Share this post


Link to post
Share on other sites
It you remove the code he added (marked by **si** 09-11-05) to the includes\modules\order_total\ot_coupon.php file and go back to the original code, you should only get one redeem message and it should redeem the correct amount as a temporary fix for now.

 

This results in receiving no message at all. also it does not apply the discount, it just takes you to the order confrimation screen........

 

I.E. this does not help....

Share this post


Link to post
Share on other sites
Tried it but still have to enter the coupon 2x...........

 

Shane,

 

That fix was to resolve the error occurring when using the Valid Products List or Valid Categories List. For CCVG v5.15, I fixed the 2x coupon problem here. Hope it works for you.

 

2x Coupon Fix for CCVG v5.15

 

Joe

Share this post


Link to post
Share on other sites
Shane,

 

That fix was to resolve the error occurring when using the Valid Products List or Valid Categories List. For CCVG v5.15, I fixed the 2x coupon problem here. Hope it works for you.

 

2x Coupon Fix for CCVG v5.15

 

Joe

 

Ok I have it working now with one exception.....

 

My order total still does not reflect the discount.....

 

sub = 10.00

tax = .70

shipping 6.00

Total 16.70

Discount 1.00

 

 

any ideas????

Share this post


Link to post
Share on other sites
Ok I have it working now with one exception.....

 

My order total still does not reflect the discount.....

 

sub = 10.00

tax = .70

shipping 6.00

Total 16.70

Discount 1.00

any ideas????

go into your modules, then order total. move the discounts and coupons above total

Share this post


Link to post
Share on other sites
This results in receiving no message at all. also it does not apply the discount, it just takes you to the order confrimation screen........

 

I.E. this does not help....

Shane,

Yes, my suggestion should work but remember, if you remove scanmer's code, you will need to uncomment the original code so it will work. My fault, i should have been more clear. Here's what yu need to do:

Remove:

//**si** 09-11-05
/*
			if ($coupon_result['coupon_type']=='S') {
					$coupon_amount = $order->info['shipping_cost'];
			} else {
					$coupon_amount = $currencies->format($coupon_result['coupon_amount']) . ' ';
			}
			if ($coupon_result['coupon_type']=='P') $coupon_amount = $coupon_result['coupon_amount'] . '% ';
			if ($coupon_result['coupon_minimum_order']>0) $coupon_amount .= 'on orders greater than ' . $coupon_result['coupon_minimum_order'];
			if (!tep_session_is_registered('cc_id')) tep_session_register('cc_id'); //Fred - this was commented out before
			$cc_id = $coupon_result['coupon_id']; //Fred ADDED, set the global and session variable
			tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_REDEEMED_AMOUNT), 'SSL')); // Added in v5.13a by Rigadin
*/
			global $order,$ot_coupon,$currency;

			$coupon_amount= tep_round($ot_coupon->pre_confirmation_check($order->info['subtotal']), $currencies->currencies[$currency]['decimal_places']); // $cc_id
/* you will need to uncomment this if your tax order total module is AFTER shipping eg you have all of your tax, including tax from shipping module, in your tax total.
			if ($coupon_result['coupon_type']=='S')  {
					//if not zero rated add vat to shipping
					$coupon_amount = tep_add_tax($coupon_amount, '17.5');
			}
*/
			$coupon_amount_out = $currencies->format($coupon_amount) . ' ';
			if ($coupon_result['coupon_minimum_order']>0) $coupon_amount_out .= 'on orders greater than ' . $currencies->format($coupon_result['coupon_minimum_order']);

			if (!tep_session_is_registered('cc_id')) tep_session_register('cc_id');
			$cc_id = $coupon_result['coupon_id'];

			if ( strlen($cc_id)>0 && $coupon_amount==0 ) {
					$err_msg = ERROR_REDEEMED_AMOUNT.ERROR_REDEEMED_AMOUNT_ZERO;
			} else {
					$err_msg = ERROR_REDEEMED_AMOUNT.$coupon_amount_out;
			}
			tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode($err_msg), 'SSL'));
//**si** 09-11-05 end

Replace with:

				if ($coupon_result['coupon_type']=='S') {
					$coupon_amount = $order->info['shipping_cost'];
			} else {
					$coupon_amount = $currencies->format($coupon_result['coupon_amount']) . ' ';
			}
			if ($coupon_result['coupon_type']=='P') $coupon_amount = $coupon_result['coupon_amount'] . '% ';
			if ($coupon_result['coupon_minimum_order']>0) $coupon_amount .= 'on orders greater than ' . $coupon_result['coupon_minimum_order'];
			if (!tep_session_is_registered('cc_id')) tep_session_register('cc_id'); //Fred - this was commented out before
			$cc_id = $coupon_result['coupon_id']; //Fred ADDED, set the global and session variable
			tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_REDEEMED_AMOUNT), 'SSL')); // Added in v5.13a by Rigadin

Please let me know if this works.

Share this post


Link to post
Share on other sites

Question:

 

When you redeem a coupon, what is supposed to happen?

 

In my store, you are returned to the checkout_payment page, and the cart in the RH column is updated showing the coupon name but that's it.


John Skurka

Share this post


Link to post
Share on other sites
Shane,

 

That fix was to resolve the error occurring when using the Valid Products List or Valid Categories List. For CCVG v5.15, I fixed the 2x coupon problem here. Hope it works for you.

 

2x Coupon Fix for CCVG v5.15

 

Joe

 

Hi Joe

Applied your fix, still getting the 2x entry on coupon. Would you be able to post your ot_coupon.php, as the one I used from the current version is a bloodbath of comment outs and still not fixing the issue. Thanks in advance.

Cathy


Cath

Share this post


Link to post
Share on other sites
Hi Joe

Applied your fix, still getting the 2x entry on coupon. Would you be able to post your ot_coupon.php, as the one I used from the current version is a bloodbath of comment outs and still not fixing the issue. Thanks in advance.

Cathy

 

Here is is (/catalog/includes/modules/order_total/ot_coupon.php). PM me with your e-mail address and I can send the file properly indented if you would like.

 

<?php

/*

$Id: ot_coupon.php,v 1.1.2.37.3 2004/01/01 22:52:59 Strider Exp $

$Id: ot_coupon.php,v 1.1.2.37 2003/07/24 22:52:59 Strider-Cote Exp $

$Id: ot_coupon.php,v 1.1.2.36 2003/05/14 22:52:59 wilt Exp $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com/

 

Copyright ? 2002 osCommerce

 

Released under the GNU General Public License

*/

 

class ot_coupon {

var $title, $output;

 

function ot_coupon() {

$this->code = 'ot_coupon';

$this->header = MODULE_ORDER_TOTAL_COUPON_HEADER;

$this->title = MODULE_ORDER_TOTAL_COUPON_TITLE;

$this->description = MODULE_ORDER_TOTAL_COUPON_DESCRIPTION;

$this->user_prompt = '';

$this->enabled = MODULE_ORDER_TOTAL_COUPON_STATUS;

$this->sort_order = MODULE_ORDER_TOTAL_COUPON_SORT_ORDER;

$this->include_shipping = MODULE_ORDER_TOTAL_COUPON_INC_SHIPPING;

$this->include_tax = MODULE_ORDER_TOTAL_COUPON_INC_TAX;

$this->calculate_tax = MODULE_ORDER_TOTAL_COUPON_CALC_TAX;

$this->tax_class = MODULE_ORDER_TOTAL_COUPON_TAX_CLASS;

$this->credit_class = true;

$this->output = array();

}

 

function process() {

global $PHP_SELF, $order, $currencies;

$order_total=$this->get_order_total();

$od_amount = $this->calculate_credit($order_total);

$tod_amount = 0.0;

$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;

$this->output[] = array('title' => $this->title . ' (' . $this->coupon_code .'):','text' => '<b>-' . $currencies->format($od_amount) . '</b>', 'value' => $od_amount); //Fred added hyphen

}

}

 

function selection_test() {

return false;

}

 

 

function pre_confirmation_check($order_total) {

global $customer_id;

return $this->calculate_credit($order_total);

}

 

function use_credit_amount() {

return $output_string;

}

 

function credit_selection() {

global $customer_id, $currencies, $language;

$selection_string = '';

$selection_string .= '<tr>' . "\n";

$selection_string .= ' <td width="10">' . tep_draw_separator('pixel_trans.gif', '10', '1') .'</td>';

$selection_string .= ' <td class="main">' . "\n";

$image_submit = '<input type="image" name="submit_redeem" onClick="submitFunction()" src="' . DIR_WS_LANGUAGES . $language . '/images/buttons/button_redeem.gif" border="0" alt="' . IMAGE_REDEEM_VOUCHER . '" title = "' . IMAGE_REDEEM_VOUCHER . '">';

$selection_string .= TEXT_ENTER_COUPON_CODE . tep_draw_input_field('gv_redeem_code') . '</td>';

$selection_string .= ' <td align="right">' . $image_submit . '</td>';

$selection_string .= ' <td width="10">' . tep_draw_separator('pixel_trans.gif', '10', '1') . '</td>';

$selection_string .= '</tr>' . "\n";

return $selection_string;

}

 

 

function collect_posts() {

global $HTTP_POST_VARS, $customer_id, $currencies, $cc_id;

if ($HTTP_POST_VARS['gv_redeem_code']) {

// get some info from the coupon table

$coupon_query=tep_db_query("select coupon_id, coupon_amount, coupon_type, coupon_minimum_order,uses_per_coupon, uses_per_user, restrict_to_products,restrict_to_categories from " . TABLE_COUPONS . " where coupon_code='".$HTTP_POST_VARS['gv_redeem_code']."' and coupon_active='Y'");

$coupon_result=tep_db_fetch_array($coupon_query);

if ($coupon_result['coupon_type'] != 'G') {

if (tep_db_num_rows($coupon_query)==0) {

tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_NO_INVALID_REDEEM_COUPON), 'SSL'));

}

$date_query=tep_db_query("select coupon_start_date from " . TABLE_COUPONS . " where coupon_start_date <= now() and coupon_code='".$HTTP_POST_VARS['gv_redeem_code']."'");

if (tep_db_num_rows($date_query)==0) {

tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_INVALID_STARTDATE_COUPON), 'SSL'));

}

$date_query=tep_db_query("select coupon_expire_date from " . TABLE_COUPONS . " where coupon_expire_date >= now() and coupon_code='".$HTTP_POST_VARS['gv_redeem_code']."'");

if (tep_db_num_rows($date_query)==0) {

tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_INVALID_FINISDATE_COUPON), 'SSL'));

}

$coupon_count = tep_db_query("select coupon_id from " . TABLE_COUPON_REDEEM_TRACK . " where coupon_id = '" . $coupon_result['coupon_id']."'");

$coupon_count_customer = tep_db_query("select coupon_id from " . TABLE_COUPON_REDEEM_TRACK . " where coupon_id = '" . $coupon_result['coupon_id']."' and customer_id = '" . $customer_id . "'");

if (tep_db_num_rows($coupon_count)>=$coupon_result['uses_per_coupon'] && $coupon_result['uses_per_coupon'] > 0) {

tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_INVALID_USES_COUPON . $coupon_result['uses_per_coupon'] . TIMES ), 'SSL'));

}

if (tep_db_num_rows($coupon_count_customer)>=$coupon_result['uses_per_user'] && $coupon_result['uses_per_user'] > 0) {

tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_INVALID_USES_USER_COUPON . $coupon_result['uses_per_user'] . TIMES ), 'SSL'));

}

global $order,$ot_coupon,$currency;

// BEGIN >>> CCVG 5.15 - Custom Modification - fix Coupon code redemption error

// Moved code up a few lines

if (!tep_session_is_registered('cc_id')) tep_session_register('cc_id');

$cc_id = $coupon_result['coupon_id'];

// END <<< CCVG 5.15 - Custom Modification - fix Coupon code redemption error

 

$coupon_amount = tep_round($ot_coupon->pre_confirmation_check($order->info['subtotal']), $currencies->currencies[$currency]['decimal_places']); // $cc_id

/* you will need to uncomment this if your tax order total module is AFTER shipping eg you have all of your tax, including tax from shipping module, in your tax total.

if ($coupon_result['coupon_type']=='S') {

//if not zero rated add vat to shipping

$coupon_amount = tep_add_tax($coupon_amount, '17.5');

}

*/

// BEGIN >>> CCVG v5.15 - Custom Modification - Change Redeem Message.

$coupon_amount_out = $currencies->format($coupon_amount) . '.';

//if ($coupon_result['coupon_minimum_order']>0) $coupon_amount_out .= 'on orders greater than ' . $currencies->format($coupon_result['coupon_minimum_order']);

// END <<< CCVG v5.15 - Custom Modification - Change Redeem Message.

 

//if (!tep_session_is_registered('cc_id')) tep_session_register('cc_id');

//$cc_id = $coupon_result['coupon_id'];

 

if ( strlen($cc_id)>0 && $coupon_amount==0 ) {

$err_msg = ERROR_REDEEMED_AMOUNT.ERROR_REDEEMED_AMOUNT_ZERO;

} else {

$err_msg = ERROR_REDEEMED_AMOUNT.$coupon_amount_out;

}

tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode($err_msg), 'SSL'));

} // ENDIF valid coupon code

} // ENDIF code entered

// v5.13a If no code entered and coupon redeem button pressed, give an alarm

if ($HTTP_POST_VARS['submit_redeem_coupon_x']) tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_NO_REDEEM_CODE), 'SSL'));

}

 

function calculate_credit($amount) {

//global $customer_id, $order, $cc_id;

global $customer_id, $order, $cc_id, $currencies, $currency;

$od_amount = 0;

if (isset($cc_id) ) {

$coupon_query = tep_db_query("select coupon_code from " . TABLE_COUPONS . " where coupon_id = '" . $cc_id . "'");

if (tep_db_num_rows($coupon_query) !=0 ) {

$coupon_result = tep_db_fetch_array($coupon_query);

$this->coupon_code = $coupon_result['coupon_code'];

$coupon_get = tep_db_query("select coupon_amount, coupon_minimum_order, restrict_to_products, restrict_to_categories, coupon_type from " . TABLE_COUPONS ." where coupon_code = '". $coupon_result['coupon_code'] . "'");

$get_result = tep_db_fetch_array($coupon_get);

$c_deduct = $get_result['coupon_amount'];

// Calcul de l'affichage du coupon

if ($get_result['coupon_type']=='S') $c_deduct = $order->info['shipping_cost'];

//Calcul du coupon si celui ci est > 0 avec les frais d'envoie

if ($get_result['coupon_type']=='S' && $get_result['coupon_amount'] > 0 ) $c_deduct = $order->info['shipping_cost'] + $get_result['coupon_amount'];

if ($get_result['coupon_minimum_order'] <= $this->get_order_total()) {

if ($get_result['restrict_to_products'] || $get_result['restrict_to_categories']) {

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

if ($get_result['restrict_to_products']) {

$pr_ids = split("[,]", $get_result['restrict_to_products']);

for ($ii = 0; $ii < count($pr_ids); $ii++) {

if ($pr_ids[$ii] == tep_get_prid($order->products[$i]['id'])) {

if ($get_result['coupon_type'] == 'P') {

$pr_c = ($order->products[$i]['final_price'] * $order->products[$i]['qty']);

//$pr_c = $this->product_price($pr_ids[$ii]); //Fred 2003-10-28, fix for the row above, otherwise the discount is calc based on price excl VAT!

$pod_amount = round($pr_c*10)/10*$c_deduct/100;

$od_amount = $od_amount + $pod_amount;

} else {

$od_amount = $c_deduct;

}

}

}

} else {

$cat_ids = split("[,]", $get_result['restrict_to_categories']);

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

$my_path = tep_get_product_path(tep_get_prid($order->products[$i]['id']));

$sub_cat_ids = split("[_]", $my_path);

for ($iii = 0; $iii < count($sub_cat_ids); $iii++) {

for ($ii = 0; $ii < count($cat_ids); $ii++) {

if ($sub_cat_ids[$iii] == $cat_ids[$ii]) {

if ($get_result['coupon_type'] == 'P') {

$pr_c = ($order->products[$i]['final_price'] * $order->products[$i]['qty']);

//$pr_c = $this->product_price($pr_ids[$ii]); //Fred 2003-10-28, fix for the row above, otherwise the discount is calc based on price excl VAT!

$pod_amount = round($pr_c*10)/10*$c_deduct/100;

$od_amount = $od_amount + $pod_amount;

continue 3; // v5.13a Tanaka 2005-4-30: to prevent double counting of a product discount

} else {

$od_amount = $c_deduct;

continue 3; // Tanaka 2005-4-30: to prevent double counting of a product discount

}

}

}

}

}

}

}

} else {

if ($get_result['coupon_type'] !='P') {

$od_amount = $c_deduct;

} else {

$od_amount = $amount * $get_result['coupon_amount'] / 100;

}

}

}

}

if ($od_amount>$amount) $od_amount = $amount;

}

// BEGIN >>> CCVG v5.15 Custom Modification - Round Discount Coupon amount

// Round Discount Coupon amount to currency configured number of decimal places to correct order total amount.

$od_amount = tep_round($od_amount, $currencies->currencies[$currency]['decimal_places']);

// END <<< CCVG v5.15 Custom Modification - Round Discount Coupon amount

return $od_amount;

}

 

function calculate_tax_deduction($amount, $od_amount, $method) {

global $customer_id, $order, $cc_id, $cart;

$coupon_query = tep_db_query("select coupon_code from " . TABLE_COUPONS . " where coupon_id = '" . $cc_id . "'");

if (tep_db_num_rows($coupon_query) !=0 ) {

$coupon_result = tep_db_fetch_array($coupon_query);

$coupon_get = tep_db_query("select coupon_amount, coupon_minimum_order, restrict_to_products, restrict_to_categories, coupon_type from " . TABLE_COUPONS . " where coupon_code = '". $coupon_result['coupon_code'] . "'");

$get_result = tep_db_fetch_array($coupon_get);

if ($get_result['coupon_type'] != 'S') {

//RESTRICTION--------------------------------

if ($get_result['restrict_to_products'] || $get_result['restrict_to_categories']) {

// What to do here.

// Loop through all products and build a list of all product_ids, price, tax class

// at the same time create total net amount.

// then

// for percentage discounts. simply reduce tax group per product by discount percentage

// or

// for fixed payment amount

// calculate ratio based on total net

// for each product reduce tax group per product by ratio amount.

$products = $cart->get_products();

$valid_product = false;

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

$valid_product = false;

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

$cc_query = tep_db_query("select products_tax_class_id from " . TABLE_PRODUCTS . " where products_id = '" . $t_prid . "'");

$cc_result = tep_db_fetch_array($cc_query);

if ($get_result['restrict_to_products']) {

$pr_ids = split("[,]", $get_result['restrict_to_products']);

for ($p = 0; $p < sizeof($pr_ids); $p++) {

if ($pr_ids[$p] == $t_prid) $valid_product = true;

}

}

if ($get_result['restrict_to_categories']) {

// v5.13a Tanaka 2005-4-30: New code, this correctly identifies valid products in subcategories

$cat_ids = split("[,]", $get_result['restrict_to_categories']);

$my_path = tep_get_product_path($t_prid);

$sub_cat_ids = split("[_]", $my_path);

for ($iii = 0; $iii < count($sub_cat_ids); $iii++) {

for ($ii = 0; $ii < count($cat_ids); $ii++) {

if ($sub_cat_ids[$iii] == $cat_ids[$ii]) {

$valid_product = true;

continue 2;

}

}

}

}

if ($valid_product) {

$price_excl_vat = $products[$i]['final_price'] * $products[$i]['quantity']; //Fred - added

$price_incl_vat = $this->product_price($t_prid); //Fred - added

$valid_array[] = array('product_id' => $t_prid, 'products_price' => $price_excl_vat, 'products_tax_class' => $cc_result['products_tax_class_id']); //jason //Fred - changed from $products[$i]['final_price'] 'products_tax_class' => $cc_result['products_tax_class_id']);

$total_price += $price_excl_vat; // changed

}

}

if (sizeof($valid_array) > 0) {

if ($get_result['coupon_type'] == 'P') {

$ratio = $get_result['coupon_amount']/100;

} else {

$ratio = $od_amount / $total_price;

}

if ($get_result['coupon_type'] == 'S') $ratio = 1;

if ($method=='Credit Note') {

$tax_rate = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);

$tax_desc = tep_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);

if ($get_result['coupon_type'] == 'P') {

$tod_amount = $od_amount / (100 + $tax_rate)* $tax_rate;

} else {

$tod_amount = $order->info['tax_groups'][$tax_desc] * $od_amount/100;

}

$order->info['tax_groups'][$tax_desc] -= $tod_amount;

$order->info['total'] -= $tod_amount; // need to modify total ...OLD

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

} else {

for ($p=0; $p<sizeof($valid_array); $p++) {

$tax_rate = tep_get_tax_rate($valid_array[$p]['products_tax_class'], $order->delivery['country']['id'], $order->delivery['zone_id']);

$tax_desc = tep_get_tax_description($valid_array[$p]['products_tax_class'], $order->delivery['country']['id'], $order->delivery['zone_id']);

if ($tax_rate > 0) {

$tod_amount = ($valid_array[$p]['products_price'] * $tax_rate)/100 * $ratio; // calc total tax Fred - added

$order->info['tax_groups'][$tax_desc] -= ($valid_array[$p]['products_price'] * $tax_rate)/100 * $ratio;

$order->info['total'] -= ($valid_array[$p]['products_price'] * $tax_rate)/100 * $ratio; // adjust total

$order->info['tax'] -= ($valid_array[$p]['products_price'] * $tax_rate)/100 * $ratio; // adjust tax -- Fred - added

}

}

}

}

//NO RESTRICTION--------------------------------

} else {

if ($get_result['coupon_type'] =='F') {

$tod_amount = 0;

if ($method=='Credit Note') {

$tax_rate = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);

$tax_desc = tep_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);

$tod_amount = $od_amount / (100 + $tax_rate)* $tax_rate;

$order->info['tax_groups'][$tax_desc] -= $tod_amount;

} else {

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

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

$ratio1 = $od_amount/($amount-$order->info['tax_groups'][$key]); ////debug

$tax_rate = tep_get_tax_rate_from_desc($key);

$net = $tax_rate * $order->info['tax_groups'][$key];

if ($net>0) {

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

$tod_amount += $god_amount;

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

}

}

}

$order->info['total'] -= $tod_amount; //OLD

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

}

if ($get_result['coupon_type'] =='P') {

$tod_amount=0;

if ($method=='Credit Note') {

$tax_desc = tep_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);

$tod_amount = $order->info['tax_groups'][$tax_desc] * $od_amount/100;

$order->info['tax_groups'][$tax_desc] -= $tod_amount;

} else {

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

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

$god_amount=0;

$tax_rate = tep_get_tax_rate_from_desc($key);

$net = $tax_rate * $order->info['tax_groups'][$key];

if ($net>0) {

$god_amount = $order->info['tax_groups'][$key] * $get_result['coupon_amount']/100;

$tod_amount += $god_amount;

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

}

}

}

$order->info['total'] -= $tod_amount; // have to modify total also

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

}

}

}

}

return $tod_amount;

}

 

function update_credit_account($i) {

return false;

}

 

function apply_credit() {

global $insert_id, $customer_id, $REMOTE_ADDR, $cc_id;

if ($this->deduction !=0) {

tep_db_query("insert into " . TABLE_COUPON_REDEEM_TRACK . " (coupon_id, redeem_date, redeem_ip, customer_id, order_id) values ('" . $cc_id . "', now(), '" . $REMOTE_ADDR . "', '" . $customer_id . "', '" . $insert_id . "')");

}

tep_session_unregister('cc_id');

}

 

function get_order_total() {

global $order, $cart, $customer_id, $cc_id;

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

// OK for global coupons but what about restricted coupons

// where you can only redeem against certain products/categories.

$coupon_query=tep_db_query("select coupon_code from " . TABLE_COUPONS . " where coupon_id='".$cc_id."'");

if (tep_db_num_rows($coupon_query) !=0) {

$coupon_result=tep_db_fetch_array($coupon_query);

$coupon_get=tep_db_query("select coupon_amount, coupon_minimum_order,restrict_to_products,restrict_to_categories, coupon_type from " . TABLE_COUPONS . " where coupon_code='".$coupon_result['coupon_code']."'");

$get_result=tep_db_fetch_array($coupon_get);

$in_cat = true;

if ($get_result['restrict_to_categories']) {

$cat_ids = split("[,]", $get_result['restrict_to_categories']);

$in_cat=false;

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

if (is_array($this->contents)) {

reset($this->contents);

while (list($products_id, ) = each($this->contents)) {

$cat_query = tep_db_query("select products_id from products_to_categories where products_id = '" . $products_id . "' and categories_id = '" . $cat_ids[$i] . "'");

if (tep_db_num_rows($cat_query) !=0 ) {

$in_cat = true;

$total_price += $this->get_product_price($products_id);

}

}

}

}

}

$in_cart = true;

if ($get_result['restrict_to_products']) {

$pr_ids = split("[,]", $get_result['restrict_to_products']);

$in_cart=false;

$products_array = $cart->get_products();

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

for ($ii = 1; $ii<=sizeof($products_array); $ii++) {

if (tep_get_prid($products_array[$ii-1]['id']) == $pr_ids[$i]) {

$in_cart=true;

$total_price += $this->get_product_price($products_array[$ii-1]['id']);

}

}

}

$order_total = $total_price;

}

}

return $order_total;

}

 

function get_product_price($product_id) {

global $cart, $order;

$products_id = tep_get_prid($product_id);

// products price

$qty = $cart->contents[$product_id]['qty'];

$product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id='" . $product_id . "'");

if ($product = tep_db_fetch_array($product_query)) {

$prid = $product['products_id'];

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

$products_price = $product['products_price'];

$specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . $prid . "' and status = '1'");

if (tep_db_num_rows ($specials_query)) {

$specials = tep_db_fetch_array($specials_query);

$products_price = $specials['specials_new_products_price'];

}

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

$total_price += ($products_price + tep_calculate_tax($products_price, $products_tax)) * $qty;

} else {

$total_price += $products_price * $qty;

}

// attributes price

if (isset($cart->contents[$product_id]['attributes'])) {

reset($cart->contents[$product_id]['attributes']);

while (list($option, $value) = each($cart->contents[$product_id]['attributes'])) {

$attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . $prid . "' and options_id = '" . $option . "' and options_values_id = '" . $value . "'");

$attribute_price = tep_db_fetch_array($attribute_price_query);

if ($attribute_price['price_prefix'] == '+') {

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

$total_price += $qty * ($attribute_price['options_values_price'] + tep_calculate_tax($attribute_price['options_values_price'], $products_tax));

} else {

$total_price += $qty * ($attribute_price['options_values_price']);

}

} else {

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

$total_price -= $qty * ($attribute_price['options_values_price'] + tep_calculate_tax($attribute_price['options_values_price'], $products_tax));

} else {

$total_price -= $qty * ($attribute_price['options_values_price']);

}

}

}

}

}

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

$total_price += $order->info['shipping_cost'];

}

return $total_price;

}

 

//JUST RETURN THE PRODUCT PRICE (INCL ATTRIBUTE PRICES) WITH OR WITHOUT TAX

function product_price($product_id) {

$total_price = $this->get_product_price($product_id);

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

return $total_price;

}

 

// show module errors on checkout_payment page

function get_error() {

global $HTTP_GET_VARS;

$error = array('title' => MODULE_ORDER_TOTAL_COUPON_TEXT_ERROR,

'error' => stripslashes(urldecode($HTTP_GET_VARS['error'])));

return $error;

}

 

function check() {

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

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

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

}

return $this->check;

}

 

function keys() {

return array('MODULE_ORDER_TOTAL_COUPON_STATUS', 'MODULE_ORDER_TOTAL_COUPON_SORT_ORDER', 'MODULE_ORDER_TOTAL_COUPON_INC_SHIPPING', 'MODULE_ORDER_TOTAL_COUPON_INC_TAX', 'MODULE_ORDER_TOTAL_COUPON_CALC_TAX', 'MODULE_ORDER_TOTAL_COUPON_TAX_CLASS');

}

 

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_ORDER_TOTAL_COUPON_STATUS', 'true', 'Do you want to display the Discount Coupon value?', '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_ORDER_TOTAL_COUPON_SORT_ORDER', '9', '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_ORDER_TOTAL_COUPON_INC_SHIPPING', 'true', 'Include Shipping in calculation', '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 ('Include Tax', 'MODULE_ORDER_TOTAL_COUPON_INC_TAX', 'true', 'Include Tax in calculation.', '6', '6','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 ('Re-calculate Tax', 'MODULE_ORDER_TOTAL_COUPON_CALC_TAX', 'None', 'Re-Calculate Tax', '6', '7','tep_cfg_select_option(array(\'None\', \'Standard\', \'Credit Note\'), ', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_ORDER_TOTAL_COUPON_TAX_CLASS', '0', 'Use the following tax class when treating Discount Coupon as Credit Note.', '6', '0', 'tep_get_tax_class_title', 'tep_cfg_pull_down_tax_classes(', 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 . ")");

}

 

}

?>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×