Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

[Contribution] Discount Coupon Codes


kgt

Recommended Posts

When I go to create a new coupon code I enter 100 as the fixed amount and 299 as the minimum order. When I click insert it shows that the discount is 33.44% Which I assume is the percentage of 100 off of 299. Is it supposed to show as a percentage like that even though I want it to be a fixed amount? When I test it out by doing an order sometimes it will show -100 as the discount and -99.98 which is fine but certain products or totals will show -$84.98 or more than just a few cents less than $100. Has anyone else had unreliable results like these?

 

I would greatly appreciate any help.

Link to comment
Share on other sites

When I go to create a new coupon code I enter 100 as the fixed amount and 299 as the minimum order. When I click insert it shows that the discount is 33.44% Which I assume is the percentage of 100 off of 299. Is it supposed to show as a percentage like that even though I want it to be a fixed amount? When I test it out by doing an order sometimes it will show -100 as the discount and -99.98 which is fine but certain products or totals will show -$84.98 or more than just a few cents less than $100. Has anyone else had unreliable results like these?

 

I would greatly appreciate any help.

 

I seemed to have pinpoint when this occurs. It looks like it only happens when the subtotal cent amount is not .00 for example if the subtotal is 798.00 it adds the coupon code just fine but if it is 798.99 then the discount a lot less than $100.

 

Any ideas on why this is happening?

Link to comment
Share on other sites

The type of rounding you want to do is not exactly something that's built into a PHP round() function or anything. It's not difficult to do, but it takes finding a function to do it or working out the logic to do it yourself. If you do some searching and find some code someone has written to round like this, I will tell you how to add it in. Or ask in the general questions for someone to help you.

 

Hi kgt,

 

do you mean something like this:

<?php

$actual_value = 3.45; // 3.45

$temp1 = $actual_value * 2; // 6.9

$temp2 = round($actual_value, 0); // 7

$half_round = $temp2 / 2 // 3.5

?>

 

This seems to do what I need. Could you assist by telling me in which places the above needs to be inserted and probably need to be changed a little bit to pick up the values produced by your current code.

thanks

Link to comment
Share on other sites

I seemed to have pinpoint when this occurs. It looks like it only happens when the subtotal cent amount is not .00 for example if the subtotal is 798.00 it adds the coupon code just fine but if it is 798.99 then the discount a lot less than $100.

 

Any ideas on why this is happening?

 

Nevermind the above suggestion it is giving irregular values whether there is .00 or .00.

 

Please help. Any suggestions?

Link to comment
Share on other sites

Hi,

 

Thx or this contrib that work fine.

 

Now, i would like to put my coupon code box from checkout_payment.php to shopping_cart.php

And see the new price .

 

How hard is it?

 

Thanks for all.

Link to comment
Share on other sites

First off i would like to say that this is a GREAT contribution!!

 

I have installed it on my site and all seems to work just fine excpt for when i put in a wrong coupon code i dont get any error, i just keep on going to checkout without a coupon applied.

 

Also do you think its possible to add a free shipping option for a coupon code?

 

Thanks

Link to comment
Share on other sites

I also just noticed that Min and Max orders are nt getting applied at all.

Sorry fixed that problem. I must have fat fingered it during the install.

 

But the free shipping coupon would we a great add on.

Link to comment
Share on other sites

When i apply a fixed discount and set the minimum order and then set the max order to anything and create the coupon the max order will change to what my min order was.

 

lets say i set my min order to 3 and my max order 10 when i create the coupon the max order reverts to the min order and they become the same.

 

anyone know how to fix it or if there is a bug fix for that at all :)

Link to comment
Share on other sites

When i apply a fixed discount and set the minimum order and then set the max order to anything and create the coupon the max order will change to what my min order was.

 

lets say i set my min order to 3 and my max order 10 when i create the coupon the max order reverts to the min order and they become the same.

 

anyone know how to fix it or if there is a bug fix for that at all :)

 

This is how fixed discounts work. They are actually percentage discounts applied against the max_order amount. In order to have a consistent discount amount (fixed discount) the min_order and max_order need to be the same.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

Now, i would like to put my coupon code box from checkout_payment.php to shopping_cart.php

And see the new price .

 

How hard is it?

 

Pretty hard, at least if you're thinking of using this code. The shopping cart is handled by an object called shopping_cart. All of the checkout_* pages are handled by an object called order. You'd have to move quite a bit of code around. The shopping cart isn't really part of the checkout process, so the code needed to do this would probably be about 95% different from the code in this contribution.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

For everyone having accuracy issues with fixed discounts:

 

To increase the accuracy of fixed discounts, the coupons_discount_percent field in the discount_coupons table should be increased to decimal(15,12). This can be done via phpMyAdmin.

 

Also, see earlier in this thread for a fix that removes the tep_add_tax() function from the calculate_discount() function in includes/classes/discount_coupon.php.

 

Finally, comment out line 116 of includes/classes/discount_coupon.php.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

I just installed discount coupon module and the install went fine. I am testing right now and I have set up a coupon with a 5% discount rate. I add the coupon code (998712) to the payment page and proceed to the confirmation page, it is discounting the price of the item 100% thus leaving a total of zero.

 

Sub-Total: $0.00

Discount Coupon 998712 applied: -$194.99

Table Rate (Best Way): $0.00

Total: $0.00

 

 

I have to fix this problem and not sure where to start.

 

I am also willing to pay someone to do further customization of this module to meet my needs. Contact me if you are an original developer of this module.

Link to comment
Share on other sites

I just installed discount coupon module and the install went fine. I am testing right now and I have set up a coupon with a 5% discount rate. I add the coupon code (998712) to the payment page and proceed to the confirmation page, it is discounting the price of the item 100% thus leaving a total of zero.

 

Sub-Total: $0.00

Discount Coupon 998712 applied: -$194.99

Table Rate (Best Way): $0.00

Total: $0.00

I have to fix this problem and not sure where to start.

 

 

I'd need to know more information. What are the values you put in the other fields, and what other contributions do you have (especially ones that made changes to includes/classes/order.php?

 

I am also willing to pay someone to do further customization of this module to meet my needs. Contact me if you are an original developer of this module.

 

 

You can send me an email or PM by clicking on my name.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

Hi All,

 

im having issues with this mod and am hoping someone might be able to shed some light on it for me.

 

Being reasonably experienced with modding Osc i have jumped on in and installed this as per install instructions and all seems to work fine from the admin area and i get through checkout to checkout_confirmation.php no worries but on the checkout_confirmation.php page im having the well documented problem of my discount not being applied / listed with the other order totals.

 

My order_total sort orders are as follows:

 

Discount Coupon 11

Shipping 30

Sub-Total 20

Tax 50

Total 40

 

So the whole unique sort order thing should not be an issue right!?

 

and here is a dump of my debug coupon data from my print_r( $this_coupon ); call in checkout_confirmation.php

 

discount_coupon Object (

 => paul [error_message] => Array ( ) [coupon] => Array ( [coupons_discount_percent] => 0.1000 [coupons_description] => pauls test coupon [coupons_max_use] => 10 [coupons_min_order] => 0.0000 [coupons_max_order] => 0.0000 [coupons_number_available] => 100 ) )

 

The only thing that has made me wonder if i missed a step ( although i have triple checked the install ) is that in my checkout_confirmation.php prior to the second codeblock addition i had to a call to

require_once( DIR_WS_CLASSES . 'discount_coupon.php' ); as the class was coming back as non existent.

 

My store is heavily modded but i am 99% certain that there is no place for conlflicts and i have simply missed something, but have been staring at it far too long to pick up on it!

 

Anyone got any ideas, this has got me running way over budget and im stressing. This looks like a good straight forward mod that perfectly fits my needs ( many thanks to the author ) but sadly its got me stumped!

 

Any advice help on this would me much appreciated!!!!

 

Cheers.

 

Shin.

Link to comment
Share on other sites

Hi kgt,

do you mean something like this:

<?php

$actual_value = 3.45; // 3.45

$temp1 = $actual_value * 2; // 6.9

$temp2 = round($actual_value, 0); // 7

$half_round = $temp2 / 2 // 3.5

?>

This seems to do what I need. Could you assist by telling me in which places the above needs to be inserted and probably need to be changed a little bit to pick up the values produced by your current code.

thanks

KGT,

 

It seems you are busy with several questions/issues at the moment :o . Regarding the one I raised, could you tell me know whether the above is what you were asking for or whether I should look for some other code ?

I'm patienced but just would like to know whether you can do something with this or if you need other details. Again, your help is much appreciated !

Link to comment
Share on other sites

I just installed discount coupon module and the install went fine. I am testing right now and I have set up a coupon with a 5% discount rate. I add the coupon code (998712) to the payment page and proceed to the confirmation page, it is discounting the price of the item 100% thus leaving a total of zero.

 

Sub-Total: $0.00

Discount Coupon 998712 applied: -$194.99

Table Rate (Best Way): $0.00

Total: $0.00

I have to fix this problem and not sure where to start.

 

I am also willing to pay someone to do further customization of this module to meet my needs. Contact me if you are an original developer of this module.

I have a 5% coupon start 12/11/06 end 12/11/07 max use of 1 min order 1.00 max order of 10,000.00 and available of 50.

The only other contribution I have is the pay pal ipn.

Link to comment
Share on other sites

and here is a dump of my debug coupon data from my print_r( $this_coupon ); call in checkout_confirmation.php

 

discount_coupon Object (

 => paul [error_message] => Array ( ) [coupon] => Array ( [coupons_discount_percent] => 0.1000 [coupons_description] => pauls test coupon [coupons_max_use] => 10 [coupons_min_order] => 0.0000 [coupons_max_order] => 0.0000 [coupons_number_available] => 100 ) )

 

The only thing that has made me wonder if i missed a step ( although i have triple checked the install ) is that in my checkout_confirmation.php prior to the second codeblock addition i had to a call to

require_once( DIR_WS_CLASSES . 'discount_coupon.php' ); as the class was coming back as non existent.

 

My store is heavily modded but i am 99% certain that there is no place for conlflicts and i have simply missed something, but have been staring at it far too long to pick up on it!

 

Anyone got any ideas, this has got me running way over budget and im stressing. This looks like a good straight forward mod that perfectly fits my needs ( many thanks to the author ) but sadly its got me stumped!

 

Having to add the line in checkout_confirmation.php to include the discount_coupon class is suspicious to me, since it SHOULD be included in includes/classes/order.php. Why that fixes the issue for some, I am not sure. I highly suspect that your order object is not actually catching the coupon code. Double check the install instructions for that file and make sure everything looks right.

 

It's generally more revealing for this contribution if you debug the order object contents:

 

print_r( $order );

 

If the order does not contain the coupon code in the info array, then that's why you get no order total line displaying. The discount is actually calculated in order.php.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

KGT,

 

It seems you are busy with several questions/issues at the moment :o . Regarding the one I raised, could you tell me know whether the above is what you were asking for or whether I should look for some other code ?

I'm patienced but just would like to know whether you can do something with this or if you need other details. Again, your help is much appreciated !

 

I am sorry! I missed your second post. There was a little bit of a bug in your rounding code. $temp1 is never used. I squeezed it into 1 line, since it's pretty basic:

 

$value = round( ( $value * 2 ), 0 ) / 2;

 

Edit lines 40-45 of includes/modules/order_total/ot_discount_coupon.php:

 

 

			  if ($value > 0) {
			$display_type = ( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DISPLAY_TYPE == 'true' ? '-' : '' );
			$this->output[] = array('title' => $this->format_display( $order->info['coupon'], $key ) . ':',
									'text' => $display_type.$currencies->format( $value, true, $order->info['currency'], $order->info['currency_value'] ),
									'value' => $display_type.$value);
		  }

 

 

It should look like:

 

			  if ($value > 0) {
			$value = round( ( $value * 2 ), 0 ) / 2;
			$display_type = ( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DISPLAY_TYPE == 'true' ? '-' : '' );
			$this->output[] = array('title' => $this->format_display( $order->info['coupon'], $key ) . ':',
									'text' => $display_type.$currencies->format( $value, true, $order->info['currency'], $order->info['currency_value'] ),
									'value' => $display_type.$value);
		  }

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

I have a 5% coupon start 12/11/06 end 12/11/07 max use of 1 min order 1.00 max order of 10,000.00 and available of 50.

The only other contribution I have is the pay pal ipn.

 

 

Ah. See previous posts about max_order.

 

The naming of the field, and even how I indicated it could be used in the manual is very misleading. If a max order value is given, the discount will always be applied to the value of max order. Since your order total is less than $500, it's giving a discount = order total. Set max_order to zero and it should work fine.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

Having to add the line in checkout_confirmation.php to include the discount_coupon class is suspicious to me, since it SHOULD be included in includes/classes/order.php. Why that fixes the issue for some, I am not sure. I highly suspect that your order object is not actually catching the coupon code. Double check the install instructions for that file and make sure everything looks right.

 

It's generally more revealing for this contribution if you debug the order object contents:

 

print_r( $order );

 

If the order does not contain the coupon code in the info array, then that's why you get no order total line displaying. The discount is actually calculated in order.php.

 

 

You are the master! thanks so much, with your advice and a clear head i had indeed missed some code i had duplicated to deal with some messy shipping/tax issues that meant, i also had to also duplicate these code additions (messy i know but we wont go into that).

 

Moving forward i am looking to mod this further to allow for Manufacturer specific discounts, so once i have that up and running, i will take time to clean it up and post it back in the contribs, may be of some use to someone!

 

Thanks again it is most definately appreciated!

Link to comment
Share on other sites

It should look like:

 

			  if ($value > 0) {
			$value = round( ( $value * 2 ), 0 ) / 2;
			$display_type = ( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DISPLAY_TYPE == 'true' ? '-' : '' );
			$this->output[] = array('title' => $this->format_display( $order->info['coupon'], $key ) . ':',
									'text' => $display_type.$currencies->format( $value, true, $order->info['currency'], $order->info['currency_value'] ),
									'value' => $display_type.$value);
		  }

THANKS !

This seems to work fine for the discount line itself. However, the next lines (e.g. subtotal) are still calculated without this rounding. Could some logic be applied to the subtotal (and total ?) please ?

I guess the new rounded discount value needs to picked up when displaying the subtotal line rather then the original not-rounded amount.

e.g.

products : 104.00

discount 5% : 5.00 (original 5.22)

subtotal : 98.78 (this should be in fact 99 now because 104-5=99)

shipping: 6.20

Total : 104.98 (this should be in fact 105.20 now)

 

Could you help me with this or would it require a total re-design of the standard subtotal/total oscommerce logic ?

Link to comment
Share on other sites

Hello. I am installing this great contrib locally first. My store is live, so errors are not acceptable.

 

kgt, I have a contrib called 'products extra fields' installed. (gives me fields on product_info pages for text descriptions)When doing the manual edits for 'DC', I ran into a small snag. Your install instructions state:

 

admin/includes/boxes/catalog.php ----------------------------------------------

 

line 29

replace

 

'<a href="' . tep_href_link(FILENAME_PRODUCTS_EXPECTED, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CATALOG_PRODUCTS_EXPECTED . '</a>' );

 

with

 

//kgt - discount coupons

'<a href="' . tep_href_link(FILENAME_PRODUCTS_EXPECTED, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CATALOG_PRODUCTS_EXPECTED . '</a><br>'.

'<a href="' . tep_href_link(FILENAME_DISCOUNT_COUPONS, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CATALOG_DISCOUNT_COUPONS . '</a>' );

//end kgt - discount coupons

 

The appropriate section in my admin/includes/boxes/catalog.php looks like this:

 

// START: Product Extra Fields

'<a href="' . tep_href_link(FILENAME_PRODUCTS_EXPECTED, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CATALOG_PRODUCTS_EXPECTED . '</a><br>' .

'<a href="' . tep_href_link(FILENAME_PRODUCTS_EXTRA_FIELDS, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CATALOG_PRODUCTS_EXTRA_FIELDS . '</a>');

// END: Product Extra Fields

 

}

 

I'm not sure how to incorporate your code into the 'products_extra_fields' . All other manual edits appear to be simple 'adds', but this one involves integrating with another contribs code.

Any help would be appreciated.

Thanks

Link to comment
Share on other sites

I'm not sure how to incorporate your code into the 'products_extra_fields' . All other manual edits appear to be simple 'adds', but this one involves integrating with another contribs code.

Any help would be appreciated.

 

Replace this

 

// START: Product Extra Fields
'<a href="' . tep_href_link(FILENAME_PRODUCTS_EXPECTED, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CATALOG_PRODUCTS_EXPECTED . '</a><br>' .
'<a href="' . tep_href_link(FILENAME_PRODUCTS_EXTRA_FIELDS, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CATALOG_PRODUCTS_EXTRA_FIELDS . '</a>');
// END: Product Extra Fields

 

with this

 

// START: Product Extra Fields
'<a href="' . tep_href_link(FILENAME_PRODUCTS_EXPECTED, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CATALOG_PRODUCTS_EXPECTED . '</a><br>' .
'<a href="' . tep_href_link(FILENAME_PRODUCTS_EXTRA_FIELDS, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CATALOG_PRODUCTS_EXTRA_FIELDS . '</a><br>'.
// END: Product Extra Fields
//kgt - discount coupons
'<a href="' . tep_href_link(FILENAME_DISCOUNT_COUPONS, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CATALOG_DISCOUNT_COUPONS . '</a>' );
//end kgt - discount coupons

Contributions

 

Discount Coupon Codes

Donations

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