Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

[Contribution] Discount Coupon Codes


kgt

Recommended Posts

great contribution kgt, and thanks for the extended support!

 

maybe a stupid question, but is there a way to change the text at checkout and on the invoice from "Discount Coupon

 applied" to something else?  if possible, i'd rather it include the discount description (i.e., Discount of [10% off, $50 off, etc.] applied).
Link to comment
Share on other sites

Curses!

 

I'm upgrading from 1.4 to 2.0 and am having a bit of a challenge trying to figure out which changes apply to my 1.4 installation. I started out installing 1.4a, but when I determined that it only worked with dollar value discounts, I backed it out to 1.4. This may be part of my problem with the confusing upgrade path.

 

While making changes to admin/includes/languages/english/coupons.php I'm coming across changes that I have in my version of the file, that are not in the 2.0 version of the file. For example, these defines are in my 1.4 version of this file, but are not in the 2.0 version:

 

define('TEXT_DISCOUNT_COUPONS_ID_HINT', '(This is the code given to the customer.  Leave blank to generate a random code.)');
define('TEXT_DISCOUNT_COUPONS_PERCENT_HINT', '(Enter a decimal percent. eg ".15" instead of "15" or "15%")');
define('TEXT_DISCOUNT_COUPONS_MAX_USE_HINT', '(Maximum number of times a customer may use this code. Leave blank or enter 0 for unlimited.)');

This is a very minor issue since it looks like you've just removed the hint defines, but it makes me paranoid since the removal of these lines isn't mentioned in the manual upgrade instructions.

 

 

I didn't put in there to remove those because it doesn't really hurt anything to have them in there. I felt not including their removal in the upgrade instructions would make editing that file a little less complicated.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

great contribution kgt, and thanks for the extended support!

 

maybe a stupid question, but is there a way to change the text at checkout and on the invoice from "Discount Coupon

 applied" to something else?  if possible, i'd rather it include the discount description (i.e., Discount of [10% off, $50 off, etc.] applied).

 

Read the manual on how to do this. You can find it via a link on the coupons admin page at the top right.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

Kgt,

 

I've managed to solve the problem i think.

 

I removed the line:

 

"require_once( DIR_FS_CATALOG.DIR_WS_CLASSES.'discount_coupon.php' );"

 

from the file 'ot_discount_coupon.php'. Apparently this has resulted in 2 instances of require for the discount_coupon class. Kgt, let me know if this modification is acceptable.

 

The statement require_ONCE is supposed to not include the file again if it's already been included. Not sure why you seem to be having problems - no one else is. I cannot imagine it's due to any other contribution, but who knows? ;)

 

I think you'd be okay removing that line. The order class should include the discount coupons class file, and the code that needs the discount coupons class also needs the order class. So the require_once in ot_discount_coupon.php should be completely unnecessary and I don't think you'll run into problems by removing it.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

This is a great contribution!

 

Quick comment on the updated 2.0 "upgrade_from_ot_discount_coupon_codes_1.4.txt" upgrade instructions text:

 

In the database changes section, you may want to determine what the proper order is for the coupons_max_order field changes. It's obvious what needs to be done when one is making the changes, but you might be able to avoid questions in the future if you can figure out the requirements for the ADD COLUMN or CHANGE statement.

 

In my case, I didn't have the max_order field although i've been using the contribution successfully.

 

In any event, great contribution and thanks for all your hard work!

 

 

Hah, yes - the max_order change is ridiculous. That field is added in this contribution. I started copying and pasting and included the max_order field in the change. That statement should fail since you shouldn't have that field.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

great contribution kgt, and thanks for the extended support!

 

maybe a stupid question, but is there a way to change the text at checkout and on the invoice from "Discount Coupon

 applied" to something else?  if possible, i'd rather it include the discount description (i.e., Discount of [10% off, $50 off, etc.] applied).

You will need to upgrade to the excellent 2.0 version of this contribution though. It provides the ability to customize the text for the discount application on your invoices.

Link to comment
Share on other sites

Read the manual on how to do this. You can find it via a link on the coupons admin page at the top right.

 

 

wow, i feel stupid. :blush: thanks for making the whole process so easy!

Link to comment
Share on other sites

Kgt,

 

Thanks for the reply! Anyway accuracy in the computation of the total values are quite important for me for taxation purposes.

 

Good thing is all my products are set with a fixed amount of sales tax so I believe the computation will be as easy as modifying the code to subtract the discount amount from the final price.

 

Do you recommend any easy way to modify your code to achieve this?

Link to comment
Share on other sites

kgt,

 

sorry about the previous post. I have interpreted the problem wrongly so it doesnt actually make sense. However, I think there's some errors in the computation when the coupon amount is > than the total price of the order. Let me sort out my tots and I will post here again.

 

Thanks

 

Kgt,

 

Thanks for the reply! Anyway accuracy in the computation of the total values are quite important for me for taxation purposes.

 

Good thing is all my products are set with a fixed amount of sales tax so I believe the computation will be as easy as modifying the code to subtract the discount amount from the final price.

 

Do you recommend any easy way to modify your code to achieve this?

Link to comment
Share on other sites

Kgt,

 

Thanks for the reply! Anyway accuracy in the computation of the total values are quite important for me for taxation purposes.

 

Good thing is all my products are set with a fixed amount of sales tax so I believe the computation will be as easy as modifying the code to subtract the discount amount from the final price.

 

Do you recommend any easy way to modify your code to achieve this?

 

Accuracy for taxation is actually why it is possible that the discount amount is slightly off. To ensure that the discount is always an exact amount requires that you subtract the tax "saved" from the discount from the order tax. Because of rounding (rounding when tax was calculated for the display and rounding again after the discounted tax amount is subtracted) the tax can be incorrect by one or two cents. I leaned towards accurate tax calculation rather than accurate discount amount. I'd rather have my $5.00 discount display as the true rounded discount amount than have my tax calculation be slightly off.

 

Since ensuring an accurate discount amount requires that you subtract that amount after the other order totals have been calculated (and rounded), other contributions can guarantee an accurate discount amount, but probably cannot guarantee accurate tax unless they completely recalculate the order totals. It's just a fact of what happens when rounding is involved.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

kgt,

 

sorry about the previous post. I have interpreted the problem wrongly so it doesnt actually make sense. However, I think there's some errors in the computation when the coupon amount is > than the total price of the order. Let me sort out my tots and I will post here again.

 

Thanks

 

I can't make any guarantees for accuracy when the coupon is > the order total. It's simply a situation I didn't see a need for and so did not code or test with this in mind. It's quite possible there will be errors.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

kgt, please look at the computaton below, done using the latest contribution. A discount coupon has been created for a FIXED AMOUNT of $100 and is applied in the order below. Do note also that tax has been set at 10% for all products as well as for shipping. All prices below (subtotal, shipping) INCLUDES a 10% TAX.

 

Subtotal: A$73.00

Express Shipping (allow 2-3 business days for delivery): A$7.00

Discount Coupon (onehundreddollars): -A$100.00

Total: A$-19.98

 

What I found is that when the value of the discount coupon is greater than the total order value, the resulting total is a negative value. Not just that, the computed negative value is not accurate.

 

By right, Total = 73 + 7 - 100 = 80 -100 = -20. Here, instead of -20, the value of the total is being displayed as -19.98. It's a bit out of place, but thats not actually my primary concern. My real concern is that a negative Total amount is actually allowed! Seriously, i've no idea how my payment gateway will react to that as I've yet to try. I suspect they might ignore the negativity and charge the same numerical value. If that happens, I will expect lots of unhappy customers using this coupon! :)

 

In an attempt to prevent display of negativity, I'm attempting to make changes in order to show the ideal display, which is:

 

Subtotal: A$73.00

Express Shipping (allow 2-3 business days for delivery): A$7.00

Discount Coupon (onehundreddollars): -A$80.00

Total: A$0.00

 

I think to any customer and to the payment gateway, the above does make a lot more sense. Here's my attempt to first at least get Total to display $0.00, before even trying to get the discount coupon to show -$80 instead of -$100 (this step is not exactly important as it is still acceptable for one off use of a voucher, but I see the need of this when this contrib has been further improved to allow use of gift cards, meaning if this transaction uses only $80, then $20 would still be the balance of this coupon which the customer can use again in the future. OK sorry i'm sidetracking here, but its a good feature to have ;p)

 

Back to the attempt to show/set 'Total' to $0.00 instead of negativity....I tried to change the line in order_total/ot_shipping.php from:

 

$order->info['total'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);

 

to

 

if ($order->info['total']<0) {

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

} else {

$order->info['total'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);

}

 

What happens next is the following screen: :)

 

Subtotal: A$73.00

Express Shipping (allow 2-3 business days for delivery): A$7.00

Discount Coupon (onehundreddollars): -A$100.00

Total: A$0.00

 

I believe that solved the problem. Kgt, need your help therefore to help me analyse if this has somehow introduced an un-intended error into the whole computation. I'm in the process of getting the discount to show -$80 instead of -$100. Once I can get it, i will make a noise here again.

 

Thanks and any suggestions would be greatly appreciated.

Link to comment
Share on other sites

Back to the attempt to show/set 'Total' to $0.00 instead of negativity....I tried to change the line in order_total/ot_shipping.php from:

 

$order->info['total'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);

 

to

 

if ($order->info['total']<0) {

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

} else {

$order->info['total'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);

}

 

What happens next is the following screen: :)

 

Subtotal: A$73.00

Express Shipping (allow 2-3 business days for delivery): A$7.00

Discount Coupon (onehundreddollars): -A$100.00

Total: A$0.00

 

I believe that solved the problem. Kgt, need your help therefore to help me analyse if this has somehow introduced an un-intended error into the whole computation. I'm in the process of getting the discount to show -$80 instead of -$100. Once I can get it, i will make a noise here again.

 

Thanks and any suggestions would be greatly appreciated.

 

It's simpler than that, I think. There's no need to have retro-active correction of the discount. Just alter the code so that the discount cannot be more than the product price. In includes/classes/discount_coupon.php line 114, after

$applied_discount = tep_add_tax( $product['final_price'] * $max_applied_percentage * $this->coupon['coupons_discount_percent'], $product['tax'] ) * $product['qty'];

add

if( $applied_discount > ( tep_add_tax( $product['final_price'], $product['tax'] ) * $product['qty'] ) ) $applied_discount = tep_add_tax( $product['final_price'], $product['tax'] ) * $product['qty'];

This one line should meet both of your requirements and doesn't require altering ot_shipping.php.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

add

if( $applied_discount > ( tep_add_tax( $product['final_price'], $product['tax'] ) * $product['qty'] ) ) $applied_discount = tep_add_tax( $product['final_price'], $product['tax'] ) * $product['qty'];

 

It does work but it doesnt actually offset any shipping price I have set.

 

Subtotal: A$73.00

Express Shipping (allow 2-3 business days for delivery): A$7.00

Discount Coupon (onehundreddollars): -A$73.00

Total: A$7.00

(Inclusive of 10% GST: A$0.64)

 

Its offseting $73 dollars instead of the intended $80. Is there anyway to call the tep_calculate_tax($order->info['shipping_cost'], $shipping_tax) into this equation?

Link to comment
Share on other sites

Hi all,

 

Sorry to bump a potentially old thread, but I've got a problem with the discount percentage rates. Whenever I apply a percentage, it actually takes the percentage of the "Max Order" field, rather than the Order Total. Has anyone else experienced this? I've been digging through the code and I'm not to sure exactly where the coupon is processed and where it does the actual calculations.

 

Any help would be greatly appreciated!

Link to comment
Share on other sites

Did you try setting the "max order" field to 0? without a defined max order, it should always use the order total as the basis

 

Hi all,

 

Sorry to bump a potentially old thread, but I've got a problem with the discount percentage rates. Whenever I apply a percentage, it actually takes the percentage of the "Max Order" field, rather than the Order Total. Has anyone else experienced this? I've been digging through the code and I'm not to sure exactly where the coupon is processed and where it does the actual calculations.

 

Any help would be greatly appreciated!

Link to comment
Share on other sites

me too.

Fatal error: Cannot redeclare class discount_coupon in /www/includes/classes/discount_coupon.php on line 14

 

 

Kgt,

 

nice contrib, but i only managed to get it to work partly. I'm using v2.0 with the latest bugfix u posted.

 

here's the situation.

 

when i set the sort_order of the discount coupon order module to a UNIQUE number as u mentioned, I get this error at the checkout_confirmation.php screen:

 

Fatal error: Cannot redeclare class discount_coupon in c:\wamp\www\shop\includes\classes\discount_coupon.php on line 14

 

I find that when i set the order to something that is non-unique (same order number as that of sub-total for instance), the module works - only draw back is that it will not show the discount text since the order is non-unique.

 

I'm looking at how there a redeclare could have been introduced. Looking at the checkout_confirmation code, there is only one line that says "new discount_coupon(....)". The other instance occurs in class\order.php which is being "required" by checkout_confirmation.php. However, these are in your original files so I'm puzzled why its not working on mine.

 

Could this problem be due to my installation of "master products" contrib. Will appreciate any advise you can give. Thank you.

 

PS: I also double checked all the changes that are to be made and nothings amiss.

Link to comment
Share on other sites

I got error message in Discount Coupon Codes Usage Information after I upgarde to v.2.0

 

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

1054 - Unknown column 'dc.number_available' in 'field list'

 

select dc.coupons_id, dc.coupons_discount_percent, dc.number_available, COUNT(dcto.discount_coupons_to_orders_id) AS use_count from discount_coupons AS dc left join discount_coupons_to_orders AS dcto ON dc.coupons_id = dcto.coupons_id group by dc.coupons_id order by use_count desc, dc.coupons_id asc limit 0, 10

 

[TEP STOP]

 

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

 

any idea

Link to comment
Share on other sites

Hi all,

 

Sorry to bump a potentially old thread, but I've got a problem with the discount percentage rates. Whenever I apply a percentage, it actually takes the percentage of the "Max Order" field, rather than the Order Total. Has anyone else experienced this? I've been digging through the code and I'm not to sure exactly where the coupon is processed and where it does the actual calculations.

 

Any help would be greatly appreciated!

 

 

I got exactly problem on my shop. no problem if i dont setup Max Order.

 

need help

 

thanks

Link to comment
Share on other sites

I got error message in Discount Coupon Codes Usage Information after I upgarde to v.2.0

 

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

1054 - Unknown column 'dc.number_available' in 'field list'

 

select dc.coupons_id, dc.coupons_discount_percent, dc.number_available, COUNT(dcto.discount_coupons_to_orders_id) AS use_count from discount_coupons AS dc left join discount_coupons_to_orders AS dcto ON dc.coupons_id = dcto.coupons_id group by dc.coupons_id order by use_count desc, dc.coupons_id asc limit 0, 10

 

[TEP STOP]

 

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

 

any idea

 

 

I found the way to slove this problem:

 

in admin/stats_discount_coupons.php (Line 120)

 

Replace

***************

$coupons_query_raw = "select dc.coupons_id, dc.coupons_discount_percent, dc.number_available, COUNT(dcto.discount_coupons_to_orders_id) AS use_count from ".TABLE_DISCOUNT_COUPONS." AS dc left join ".TABLE_DISCOUNT_COUPONS_TO_ORDERS." AS dcto ON dc.coupons_id = dcto.coupons_id group by dc.coupons_id order by use_count desc, dc.coupons_id asc";

***************

 

with

 

****************

$coupons_query_raw = "select dc.coupons_id, dc.coupons_discount_percent, dc.coupons_number_available, COUNT(dcto.discount_coupons_to_orders_id) AS use_count from ".TABLE_DISCOUNT_COUPONS." AS dc left join ".TABLE_DISCOUNT_COUPONS_TO_ORDERS." AS dcto ON dc.coupons_id = dcto.coupons_id group by dc.coupons_id order by use_count desc, dc.coupons_id asc";

***************

Link to comment
Share on other sites

I found the way to slove this problem:

 

in admin/stats_discount_coupons.php (Line 120)

 

Replace

***************

$coupons_query_raw = "select dc.coupons_id, dc.coupons_discount_percent, dc.number_available, COUNT(dcto.discount_coupons_to_orders_id) AS use_count from ".TABLE_DISCOUNT_COUPONS." AS dc left join ".TABLE_DISCOUNT_COUPONS_TO_ORDERS." AS dcto ON dc.coupons_id = dcto.coupons_id group by dc.coupons_id order by use_count desc, dc.coupons_id asc";

***************

 

with

 

****************

$coupons_query_raw = "select dc.coupons_id, dc.coupons_discount_percent, dc.coupons_number_available, COUNT(dcto.discount_coupons_to_orders_id) AS use_count from ".TABLE_DISCOUNT_COUPONS." AS dc left join ".TABLE_DISCOUNT_COUPONS_TO_ORDERS." AS dcto ON dc.coupons_id = dcto.coupons_id group by dc.coupons_id order by use_count desc, dc.coupons_id asc";

***************

 

Yes, the admin report will break because the field names have changed. You might need to do this in several places in that file.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

Hi all,

 

Sorry to bump a potentially old thread, but I've got a problem with the discount percentage rates. Whenever I apply a percentage, it actually takes the percentage of the "Max Order" field, rather than the Order Total. Has anyone else experienced this? I've been digging through the code and I'm not to sure exactly where the coupon is processed and where it does the actual calculations.

 

Any help would be greatly appreciated!

 

I got exactly problem on my shop. no problem if i dont setup Max Order.

 

need help

 

thanks

 

That's what the max_order field is for. If you set a max_order, it will only apply the discount to that amount. So you can set a limit to the maximum discount people can recieve. This is used for fixed discounts, but it can be used for percentage discounts as well. There is a link to the manual at the top right of the coupons admin screen.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

add
if( $applied_discount > ( tep_add_tax( $product['final_price'], $product['tax'] ) * $product['qty'] ) ) $applied_discount = tep_add_tax( $product['final_price'], $product['tax'] ) * $product['qty'];

 

It does work but it doesnt actually offset any shipping price I have set.

 

Subtotal: A$73.00

Express Shipping (allow 2-3 business days for delivery): A$7.00

Discount Coupon (onehundreddollars): -A$73.00

Total: A$7.00

(Inclusive of 10% GST: A$0.64)

 

Its offseting $73 dollars instead of the intended $80. Is there anyway to call the tep_calculate_tax($order->info['shipping_cost'], $shipping_tax) into this equation?

 

 

The discount coupon is truly was truly not coded to apply any discount to shipping. It was meant to apply it to the subtotal only, so that tax would be correctly calculated and shipping would not be affected (most stores don't include shipping when figuring a discount). You can do this, but it will probably not be very easy.

 

It sounds to me like you're wanting more of a voucher, which is a form of payment, rather than a discount. Have you looked as CCGV?

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

Good morning,

 

I like this contribution, but... since I'm based in Europe the invoices have to mention all products, costs and promotions excl. vat and have the vat added to the final total.

 

But the Discount Coupon Codes contribution already includes VAT, is there any way to get the amount without VAT incorporated ?

 

 

Friendly Greetings,

Tim,

 

Example: (ands it even confusing for our customers)

 

Item1: 9,92EUR (excl)

Discount Coupon x applied: -2,00EUR (incl)

 

VAT 21%: 1,74EUR (vat)

Sub-total: 10,00EUR (incl)

Shipping: 6,54EUR (incl)

Total: 16,54EUR (incl)

 

 

Minor issue: I use multiple languages and in each language it says "Discount Coupon x applied"

 

Major issue: why is the error reporting in the header ?

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