Jump to content
kgt

[Contribution] Discount Coupon Codes

Recommended Posts

You should be making manual backups whenever you make changes to the database. MySQL will not automatically make a backup for you when you alter the database structure.

 

Just provide the state of your table as it is now. And tell me which version of this contribution you're trying to use. If you don't know how to get the table structure, just enter this into the SQL tab:

 

SHOW CREATE TABLE discount_coupons

 

Thanks for your help:

 

CREATE TABLE `discount_coupons` (\n `coupons_id` varchar(32) NOT NULL default '',\n `coupons_description` varchar(64) NOT NULL default '',\n `coupons_discount_percent` decimal(7,4) default NULL,\n `coupons_date_start` datetime default NULL,\n `coupons_date_end` datetime default NULL,\n `coupons_max_use` int(3) NOT NULL default '0',\n `coupons_min_order` decimal(15,4) NOT NULL default '0.0000',\n `coupons_max_order` decimal(15,4) NOT NULL default '0.0000',\n PRIMARY KEY (`coupons_id`)\n) ENGINE=MyISAM DEFAULT CHARSET=latin1

 

Version 2.1.*

Share this post


Link to post
Share on other sites
Try changing the function calculate_discount() in includes/classes/discount_coupon.php to the following:

 

	function calculate_discount( $product, $product_count ) {
		$applied_discount = 0;
		if (DISPLAY_PRICE_WITH_TAX == 'true') {
			//if there's a maximum order amount to apply the discount to, determine the percentage of this product's final price we should apply the discount to
			$max_applied_percentage = ( $this->coupon['coupons_max_order'] == 0 ? '1.00' : $this->coupon['coupons_max_order'] / ( tep_add_tax( $product['final_price'] * $product['qty'], $product['tax'] ) * $product_count ) );
		  $applied_discount = tep_add_tax( $product['final_price'] * $max_applied_percentage * $this->coupon['coupons_discount_percent'], $product['tax'] ) * $product['qty'];
		  //don't allow the discount amount to be more than the product price
		  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'];
		} else if( !( $special_price = tep_get_products_special_price( $product['products_id'] ) ) ) {
	//if there's a maximum order amount to apply the discount to, determine the percentage of this product's final price we should apply the discount to
			$max_applied_percentage = ( $this->coupon['coupons_max_order'] == 0 ? '1.00' : $this->coupon['coupons_max_order'] / ( $product['final_price'] * $product['qty'] * $product_count ) );
		  $applied_discount = $product['final_price'] * $max_applied_percentage * $this->coupon['coupons_discount_percent'] * $product['qty'];
		  //don't allow the discount amount to be more than the product price
		  if( $applied_discount > ( $product['final_price'] * $product['qty'] ) ) $applied_discount = $product['final_price'] * $product['qty'];
		}
		return $applied_discount;
	}

I replaced the code you suggested. When I did it gave me an error, I added a } at the very end and the error went away. However, it does not exclude items that are on special from being included in the discount. Any thoughts?

Share this post


Link to post
Share on other sites
However, the table IS in the DB.

 

I have also checked that everything is declared in both /includes/filenames.php and admin/includes/filenames.php

 

I have also resubmitted the SQL statements and rechecked all the files, but still no ideas.... anyone have any idea what might be causing this?

 

 

The table names are stored in includes/database_tables.php, not includes/filenames.php.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
I'm having a problem with sortof a combination of mods here. I use paypal direct payment pro on my website. This mod works perfectly if the customer selects to pay via direct payment visa, mastercard, etc. However, if they choose paypal express pay, it skips checkout_payment.php entirely... So they never have a place to enter the code.

 

Would it be at all possible to set it up so they can enter the coupon code at the bottom of the shipping page, rather then the payment page? I have been fiddling with this a bit but not been able to get it to work- I can make it display the box and stuff ~ correctly but you enter a code, go through the process and it doesn't show up on the order confirmation page.

 

I helped someone else with this before. I won't support it (just too much to handle), but I will give you the files if you want them. PM me with your email address and I will send it to you.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
getting the following

 

Fatal error: Cannot redeclare tep_db_connect() (previously declared in /catalog/admin/includes/functions/database.php:13) in /catalog/admin/includes/functions/database.php on line 13

 

Everything else seems to work fine just can't get the report to work.

Any ideas?

 

It shows up directky after clicking on the Discount Coupon Link in the report section.

I've checked all files involved yet I can't find the problem.

 

You've put a code file into the language directory. Re-upload admin/includes/languages/english/stats_discount_coupons.php from the installation zip file.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
I replaced the code you suggested. When I did it gave me an error, I added a } at the very end and the error went away. However, it does not exclude items that are on special from being included in the discount. Any thoughts?

 

Try this function instead. It checks that the specials function returns null. It worked on my test site.

 

	function calculate_discount( $product, $product_count ) {
	$applied_discount = 0;
	if( DISPLAY_PRICE_WITH_TAX == 'true' && tep_not_null( $special_price = tep_get_products_special_price( $product['products_id'] ) ) ) {
		//if there's a maximum order amount to apply the discount to, determine the percentage of this product's final price we should apply the discount to
		$max_applied_percentage = ( $this->coupon['coupons_max_order'] == 0 ? '1.00' : $this->coupon['coupons_max_order'] / ( tep_add_tax( $product['final_price'] * $product['qty'], $product['tax'] ) * $product_count ) );
		$applied_discount = tep_add_tax( $product['final_price'] * $max_applied_percentage * $this->coupon['coupons_discount_percent'], $product['tax'] ) * $product['qty'];
		//don't allow the discount amount to be more than the product price
		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'];
	} else if( tep_not_null( $special_price = tep_get_products_special_price( $product['products_id'] ) ) ) {
		//if there's a maximum order amount to apply the discount to, determine the percentage of this product's final price we should apply the discount to
		$max_applied_percentage = ( $this->coupon['coupons_max_order'] == 0 ? '1.00' : $this->coupon['coupons_max_order'] / ( $product['final_price'] * $product['qty'] * $product_count ) );
		$applied_discount = $product['final_price'] * $max_applied_percentage * $this->coupon['coupons_discount_percent'] * $product['qty'];
		//don't allow the discount amount to be more than the product price
	if( $applied_discount > ( $product['final_price'] * $product['qty'] ) ) $applied_discount = $product['final_price'] * $product['qty'];
	}
	return $applied_discount;
}


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
Thanks for your help:

 

CREATE TABLE `discount_coupons` (\n `coupons_id` varchar(32) NOT NULL default '',\n `coupons_description` varchar(64) NOT NULL default '',\n `coupons_discount_percent` decimal(7,4) default NULL,\n `coupons_date_start` datetime default NULL,\n `coupons_date_end` datetime default NULL,\n `coupons_max_use` int(3) NOT NULL default '0',\n `coupons_min_order` decimal(15,4) NOT NULL default '0.0000',\n `coupons_max_order` decimal(15,4) NOT NULL default '0.0000',\n PRIMARY KEY (`coupons_id`)\n) ENGINE=MyISAM DEFAULT CHARSET=latin1

 

Version 2.1.*

 

ALTER TABLE discount_coupons ADD COLUMN coupons_number_available INT(3) DEFAULT 0 NOT NULL

 

That should work.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
That should work.

 

Great - I am progressing forward. I appreciate your help more than I can express. I am now able to add coupons in my admin, but if I try to retrieve it as a customer I get the following error:

 

Fatal error: Cannot redeclare class discount_coupon in c:\hosting\webhost4life\member\mikescoin\catalog\includes\classes\discount_coupon.php on line 14

 

I think I need to just re-enstall the discount_coupon.php code - would you agree?

Share this post


Link to post
Share on other sites
Great - I am progressing forward. I appreciate your help more than I can express. I am now able to add coupons in my admin, but if I try to retrieve it as a customer I get the following error:

 

Fatal error: Cannot redeclare class discount_coupon in c:\hosting\webhost4life\member\mikescoin\catalog\includes\classes\discount_coupon.php on line 14

 

I think I need to just re-enstall the discount_coupon.php code - would you agree?

 

 

Comment out this line in includes/modules/order_total/ot_discount_coupon.php:

 

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


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
Comment out this line in includes/modules/order_total/ot_discount_coupon.php:

 

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

 

 

Thanks Once again - All appears to be working (at least I do not get any errors) but as I work through the checkout it never added (or deducts) the coupon. Now I am completely lost.

 

Any thoughts?

Share this post


Link to post
Share on other sites
Thanks Once again - All appears to be working (at least I do not get any errors) but as I work through the checkout it never added (or deducts) the coupon. Now I am completely lost.

 

Any thoughts?

 

Now just make sure the code you have in checkout_payment.php and checkout_confirmation.php matches the code in the install file.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
Now just make sure the code you have in checkout_payment.php and checkout_confirmation.php matches the code in the install file.

 

All, I am still looking for an easy way to do a "free ship" coupon, I know there is a contrib to do "free ship if over $x", but is there anyway to create a "free shipping" coupon code.

Share this post


Link to post
Share on other sites
Now just make sure the code you have in checkout_payment.php and checkout_confirmation.php matches the code in the install file.

 

 

Thanks for your help KGT! I finally have this contribution working. I doublechecked each of these codes and both were correct. So I re-installed a few other pages and somewhere in the process it worked. Thanks for your help.

 

I do have one question regarding the Sub totals deduction working properly... I am going to mainly use this for a fixed discount or rather for Gift Cards of 25 - 50 - 100. I would feel pretty bad if someone bought some merchandise and it deducted 99.90 (or whatever) instead of $100 What is the best way to ensure that the proper amount is deducted and the rounding does not come into play? Have there been any bug fixes for this yet?

 

Once again thanks for all your help on this contribution - I am so happy that it works!

 

James

Share this post


Link to post
Share on other sites
Thanks for your help KGT! I finally have this contribution working. I doublechecked each of these codes and both were correct. So I re-installed a few other pages and somewhere in the process it worked. Thanks for your help.

 

I do have one question regarding the Sub totals deduction working properly... I am going to mainly use this for a fixed discount or rather for Gift Cards of 25 - 50 - 100. I would feel pretty bad if someone bought some merchandise and it deducted 99.90 (or whatever) instead of $100 What is the best way to ensure that the proper amount is deducted and the rounding does not come into play? Have there been any bug fixes for this yet?

 

 

If you display prices with tax, you're basically out of luck. If you display prices without tax, see this post:

 

http://forums.oscommerce.com/index.php?sho...019&st=460#


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
If you display prices with tax, you're basically out of luck. If you display prices without tax, see this post:

 

http://forums.oscommerce.com/index.php?sho...019&st=460#

 

Thanks - that is the thread I was looking for. I had read it was better to use percentages rather than fixed when I was looking for a Coupon Contrib, but I thought I would install this discount contribution instead of any others (I thought it was better suited). Since I do not display my products with tax, I will add the code suggested in the post to my site this evening. Your help has been appreciated greatly.

Share this post


Link to post
Share on other sites

First off I would like to say I'm new to osCommerce. I believe i've succesfully installed he Discoutn Coupon Codes Contribution, but the pennsylvania Sales Tax is being shown incorrectly based on the Shipping price. The Total, on the other hand, is calculated correctly.

 

Any help would be greatly appreciated.

Thanks in advance, Mike

Share this post


Link to post
Share on other sites
First off I would like to say I'm new to osCommerce. I believe i've succesfully installed he Discoutn Coupon Codes Contribution, but the pennsylvania Sales Tax is being shown incorrectly based on the Shipping price. The Total, on the other hand, is calculated correctly.

 

An example of the incorrect calculations would be helpful.

 

Is your shipping module set to charge tax on shipping fees?


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
First off I would like to say I'm new to osCommerce. I believe i've succesfully installed he Discoutn Coupon Codes Contribution, but the pennsylvania Sales Tax is being shown incorrectly based on the Shipping price. The Total, on the other hand, is calculated correctly.

 

An example of the incorrect calculations would be helpful.

 

Is your shipping module set to charge tax on shipping fees?


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites

Hello :)

 

I've got this contribution working in our store, but now the boss wants something different.

 

They made up some business cards with "$1.00 off each item purchased" and a coupon code was included.

 

I can see that this was set up to give a percentage discount off of the total order. Is there any way to make this plan work with the 'discount coupon codes' contrib?

 

 

If not, can anyone suggest a coupon code contribution that will do that?

 

Thanks a bunch :)

Share this post


Link to post
Share on other sites
Hello :)

 

I've got this contribution working in our store, but now the boss wants something different.

 

They made up some business cards with "$1.00 off each item purchased" and a coupon code was included.

 

I can see that this was set up to give a percentage discount off of the total order. Is there any way to make this plan work with the 'discount coupon codes' contrib?

If not, can anyone suggest a coupon code contribution that will do that?

 

You'd have to do some customizing to get it to work, especially if it's supposed to still work with regular discounts.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
No, the regular discounts wouldn't need to work any longer. Does this make it easier?

 

It makes it easier.

 

I have no clue if this will work, but I think maybe all you need to do is edit includes/classes/discount_coupon.php to calculate the discount like you want it to. You can set the fixed discount at $1.00 when you create the coupon, then change

 

return $applied_discount;

 

to

 

return ( $applied_discount * $product['qty'] );


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites

Hmmm, I see your plan there, though I'm not familiar with your code.

 

I tried that change, but it still only shows -$1.00 on the checkout page, when there are 2 items in the cart.

 

Any other ideas?

Share this post


Link to post
Share on other sites

Just for kicks I changed that code to:

 

return ( $applied_discount * 2 );

 

This does return -$2.00, so it would appear that $product['qty'] is not returning the correct value.

Share this post


Link to post
Share on other sites
Just for kicks I changed that code to:

 

return ( $applied_discount * 2 );

 

This does return -$2.00, so it would appear that $product['qty'] is not returning the correct value.

 

 

No, that's not what it is. Change it back to return $applied_discount or you'll get funky results when you have multiple quantities of one item. The change you want needs to occur on these two lines:

 

$max_applied_percentage = ( $this->coupon['coupons_max_order'] == 0 ? '1.00' : $this->coupon['coupons_max_order'] / ( tep_add_tax( $product['final_price'] * $product['qty'], $product['tax'] ) * $product_count ) );

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

 

Fixed discounts are normally applied to the entire order total. So we need to change this to apply to each item instead of figuring out the amount to discount per item in order to reach an entire order discount of $x.


Contributions

 

Discount Coupon Codes

Donations

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

×