Contributions
Discount Coupon Codes
Create coupon codes for your customers to use for discounts on orders.
Discounts are applied before tax and are displayed as one order total line for each applicable tax class. You can configure whether to display the order subtotal including the discount, or before the discount is applied.
Coupon codes may be configured with a start or ending date, number of times they may be used, and an order minimum.
Expand All / Collapse All
Whilst the Discount Coupon Codes add-on allows you to specify table names in the
database_tables.php fies, the install function for the order total module
ignores these and uses the default names. This archive contains a modified
version of the ot_discount_coupon.php file from Discount Coupon Codes 3.3 that
corrects this oversight.
--
Safalra (Stephen Morley)
in catalog/admin/includes/filenames.php, the following line needs to be added at around line 14 : define('FILENAME_ADMINISTRATORS', 'administrators.php');
After installing this contribution some tables are missing for the sql database, meaning when you try to insert a new coupon you recive an sql error similar to this:
1136 - Column count doesn't match value count at row 1
insert into discount_coupons values ( 'myspace', 'MySpace Friend 20% off', '.20', 'percent', null, "2008-06-08", 0, 0, null, 100)
Fix:
Using the SQL below you should be able to remove your existing table (which will remove any coupons already created) and create the table with the appropriate columns:
drop table if exists discount_coupons;
create table discount_coupons (
coupons_id varchar(32) not null ,
coupons_description varchar(64) not null ,
coupons_discount_amount decimal(15,12) default '0.000000000000' not null ,
coupons_discount_type enum('fixed','percent','shipping') default 'percent' not null ,
coupons_date_start datetime ,
coupons_date_end datetime ,
coupons_max_use int(3) default '0' not null ,
coupons_min_order decimal(15,4) default '0.0000' not null ,
coupons_min_order_type enum('price','quantity') default 'price' ,
coupons_number_available int(3) default '0' not null ,
PRIMARY KEY (coupons_id)
);
Missing line of Code in file /public_html/admin/includes/database_tables.php
At or Around Line 16 add:
define('TABLE_ADMINISTRATORS', 'administrators');
When using a fixed amount discount, I wanted to keep the shipping charge.
Currently, if a discount coupon exceeds the order total amount, the order total will be 0.
Example:
$50 Subtotal
$10 Shipping
-$100 Coupon
--------------
$0 Total
Now, you can choose in the Admin section to retain the shipping charge so that the total will not be 0. Discount will only apply to the subtotal, not the order total.
Example:
$50 Subtotal
$10 Shipping
-$100 Coupon
--------------
$10 Total
in catalog/admin/includes/filenames.php, the following line needs to be added at around line 35: define('FILENAME_LOGIN', 'login.php');
I precisely followed all of the installation instructions, twice, and still ran into the same problem.
When everything was updated and I attempted to log into the admin, the menu would not load correctly causing the rest of the admin not to load. It ended up being an issue with the updates required for the files admin/includes/boxes/catalog.php and admin/includes/boxes/reports.php
For admin/includes/boxes/catalog.php the update should should be,
//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>' );
/***************
'<a href="' . tep_href_link(FILENAME_PRODUCTS_EXPECTED, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CATALOG_PRODUCTS_EXPECTED . '</a>' );
***************/
//end kgt - discount coupons
For admin/includes/boxes/reports.php the update should should be,
//kgt - discount coupons report
'<a href="' . tep_href_link(FILENAME_STATS_CUSTOMERS, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_REPORTS_ORDERS_TOTAL . '</a><br>' .
'<a href="' . tep_href_link(FILENAME_STATS_DISCOUNT_COUPONS, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_REPORTS_DISCOUNT_COUPONS . '</a>');
/*************
'<a href="' . tep_href_link(FILENAME_STATS_CUSTOMERS, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_REPORTS_ORDERS_TOTAL . '</a>');
*************/
//end kgt - discount coupons report
Both instances were missing a period after the first updated piece of code with the link. It caused the rest of the code to not execute.
This is based on kgt's Paypal IPN v 2.2 17 Apr 2007 .
His file didn't work properly with current version of paypal ipn as no ipn was received and order status was not changing.
I used his edited lines on a up to date paypal_ipn.php and that fixed the problem.
All credits to kgt.
This is an optional combo fix which includes my subtotals bug fix (see the bug fix below this one for more info) as well as a fix for table shipping calculations. If you do not use the table shipping method for calculating shipping, you do not need to install this fix. You should instead download and install the fix below this one.
The zip file includes the new discount_coupon.php and table.php files. There are two readme files included - one for users who have already installed the previous fix, and one for users who have not installed either of the fixes.
NOTE: This is a temporary fix for anyone who needs it. It is NOT official, and is only meant to tide users over until KGT or one of the other developers includes such a fix in their official releases. DO NOT message me for support on this bug fix or any other problems you may have with DCC. If you have a problem with this bug fix, simply uninstall it and wait for something more official.
Good luck,
Agra
NOTE: This is a temporary fix for anyone who needs it. It is NOT official, and is only meant to tide users over until KGT or one of the other developers includes such a fix in their official releases. DO NOT message me for support on this bug fix or any other problem you may have with DCC. If you have a problem with this bug fix, simply uninstall it and wait for something more official.
---------------------------
About this bug fix:
---------------------------
This fix is for 3.31 of DCC and includes only the discount_coupon.php file. It is for anyone who is having problems with the discount being applied to subtotals even if the option is chosen to display subtotals without the discount applied. Additionally, this was causing the discount to be applied twice when FALSE was chosen.
I cannot gaurantee the effects of this fix on your installation of DCC. It worked for me on my clean installation of DCC, and I am offering it to the community in hopes that others will find it helpful. There is a readme file included which includes more information and explains how to install this fix manually.
Cheers,
Agra
Small update incorporates 3.3 bug fix and installation instruction update to include installing the image button for shipping zone exclusions.
This is a full package. Upgrade instructions assume version 3.2 is installed.
At the code was missing two (.) :
1) At admin/includes/boxes/catalog.php has to be
//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>' );
/***************
'<a href="' . tep_href_link(FILENAME_PRODUCTS_EXPECTED, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CATALOG_PRODUCTS_EXPECTED . '</a>' );
***************/
//end kgt - discount coupons
and
2) At admin/includes/boxes/reports.php has to be
//kgt - discount coupons report
'<a href="' . tep_href_link(FILENAME_STATS_CUSTOMERS, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_REPORTS_ORDERS_TOTAL . '</a><br>'.
'<a href="' . tep_href_link(FILENAME_STATS_DISCOUNT_COUPONS, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_REPORTS_DISCOUNT_COUPONS . '</a>');
/*************
'<a href="' . tep_href_link(FILENAME_STATS_CUSTOMERS, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_REPORTS_ORDERS_TOTAL . '</a>'); *************/
//end kgt - discount coupons report
Full Add On with changed install directions to edit catalog/create_account.php
Without the changes to create_account.php, a new customer who sets up their account during checkout will not be allowed to use a coupon code during that same checkout session as the customer_group_id is not being passed.
Bug Fixes:
* Fixed bug that caused subtotal to be incorrect when products with more than 1 quantity are in cart.
This is a full package. Upgrade instructions assume version 3.2 is installed.
Other Changes:
Added the ability to toggle how tax is displayed with the discount line. This will affect mainly store owners who display prices with tax.
This is a full package. Upgrade instructions assume version 3.1 is installed.
Bug Fixes:
Fixed incorrect fixed discount calculation in includes/classes/discount_coupon.php. The bug (and this fix) should affect only stores displaying prices with tax.
Fixed bug that did not associate orders with coupons, so the report did not tally coupon usage, and customers could reuse coupons.
Other Changes:
Added a feature to check against table shipping rates to ensure the shipping fee didn't change as a result of a lower order total after the discount is applied.
This is a complete package. The upgrade instructions assume you have Discount Coupon Codes 3.0 (24 Apr 2007) with Discount Coupon Codes 3.0 checkout_process bugfix (26 Apr 2007) and Discount Coupon Codes 3.0 discount_coupon class bugfix (2 May 2007) installed. The full instructions include those bugfixes.
After having a sale and realizing we just lost money on a purchase (product came to below wholesale cost) I devised a little snip of code to exclude any items on sale from being processed through the sale. But regular items will still receive discount.
You can use the code below or just replace the discount_coupon.php with the one in the zip file. Which ever is easier for you.
Good Luck!
------------------------------------------------
///// In the classes/discount_coupon.php file
Replace the calc function (last function of the file) with this:
function calculate_discount( $product, $product_count ) {
//Start [Central50] sale exclusion
//check if this product ($product['id'] on sale
$specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . $product['id'] . "' and status = '1'");
if (tep_db_num_rows($specials_query) > 0) {
$specials = tep_db_fetch_array($specials_query);
$specialprice = $specials['specials_new_products_price'];
}
// End [Central50] sale exclusion
//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 ) );
//Start [Central50] sale exclusion
if ($specialprice > 0) {
//This item is on sale, do not apply ANY discount
$applied_discount = 0;
} else {
//This item is of regular value, let the system proceed with applied discount
$applied_discount = tep_add_tax( $product['final_price'] * $max_applied_percentage * $this->coupon['coupons_discount_percent'], $product['tax'] ) * $product['qty'];
}
//End [Central50] sale exclusion
//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'];
return $applied_discount;
}
-------------------------------------
What I have done is used the code the check for specials from the shopping_cart class file. What I originally did was checked if any item was on sale and just shut off the coupons, but thats not fair to the customer if they have other items that are of regular price.
This will be included in the for loop in the classes/order.php file and if that product is on sale, will not apply the sale to it. If it is not on sale, it will act of regular function.
I am still learning in coding, I have done some extensive custom coding to both of my sites but if anyone sees any problems with this or can improve on it, by all means please do.
And my staff and I have checked the outcome and it does work for me as far as I can tell.
USE AT YOUR OWN RISK, NOT RESPONSIBLE FOR ANYTHING.
This is a bugfix update to the discount coupon class. The bug (and this fix) should affect only stores displaying prices with tax. Simply upload the packaged file to catalog/includes/classes/discount_coupon.php.
This should allow stores that use Separate Pricing Per Customer to exclude a Customer Group from using a Coupon. This is an add-on for v3.0. My store is heavily modified, so I am giving a text document with instructions for modifying your code, as well as the SQL file to run on your database and the image for the Admin side. Thanks to Kristen for all her help in creating this!
This is just the corrected install instructions and bugfix for checkout_process.php. This fixes the bug that did not associate orders with coupons, so the report did not tally coupon usage, and customers could reuse coupons.
Bug Fixes:
Reduced possibility of inaccurate discounts due to rounding errors.
Fixed bug that limited discount to item price (should not be done for fixed discounts).
Other Changes:
True fixed discounts added.
Shipping discounts added.
Exclusions based on products, categories, manufacturers, and customers added.
TracyS provided code for an additional exclusion type, shipping zones.
Added new coupon minimum types "product quantity" and "price total" to limit coupon usage depending on cart item quantity or price total, respectively.
Added module configuration option to toggle whether product specials are excluded.
Added module configuration option to toggle whether order totals are allowed to be negative (can happen if you create a fixed discount with a discount amount greater than the minimum order).
Added a module configuration option to toggle whether debugging should be on.
Hi,
After Applying the code to commerce cart i found that % doesn't work and then it was also stupid that you can't edit the coupon as well as discount % has be added in stupid e.g 15 -> .15. So i decided to work on it and fixed some errors
PLEASE BACKUP YOUR STUFF BEFORE YOU TRY THIS PACKAGE
Features Added
+ You can now edit coupon in full using admin
Bugs Fixed
+ % bug fixed, now you can add the 15% as 15 instead of .15
+ bug fixed which was making 100 % discount if you your discount %
+ see everywhere real % information
+ in admin reports has also been displayed real %
+ admin user manual has been updated.
THIS IS A FULL PACKAGE
Paypal IPN 2.2 (http://www.oscommerce.com/community/contributions,2679) modified for Discount Coupon Codes.
Upload to includes/modules/payment/paypal_ipn.php
This is a fix of the PayPal IPN module to get discount coupons working. No install instructions, just the module which needs to be uploaded to includes/modules/payment/paypal_ipn.php.
This is for version 1.4 found here:
http://www.oscommerce.com/community/contributions,2679
These files provide a german translation of discount coupon codes - for the front- and backend.
The tar.gz contains only the language files - not the whole package. you have to install discount coupon codes first.
ToDo: translate the manual.
After installing this contribution, my client clicked on the link to view the online help manual for this contribution from the admin page. He got a 404 error! The link is to coupons_manual.php, but the file is .html. I have changed the extension to .php for this file. This upload contains the full package for v 2.1, including reporting feature added recently.
If you downloaded version 2.1, you do not need to download this separately, as the report is included in that download.
This is the complete install package.
Bug Fixes:
* Replaced tep_db_prepare_input() with tep_db_input() in includes/classes/discount_coupon.php to correctly sanitize string for database query.
* Max_use, min_order, number_available checks did not work with update to 2.0 because of a missing line.
* Error message for max_use would not display because it was not being saved as a object variable.
* Global currencies variable was not declared in function to check min_order so resulted in an error.
* If discount is more than min_order, do not allow applied discount to exceed the products price to prevent negative order totals.
* Unregister the coupon session variable when logging off.
Other changes:
* Added configuration option to select whether to use language files for order total line display or to use the module configuration field. This is needed for shops using multiple languages that wish to display the order total line formatted for each language.
This is the complete install package.
This also includes the admin report for coupon usage.
Small update to get usage checking working. The fixed upgrade instructions and install instructions are included along with the fixed files.
checkout_confirmation.php line 74 after
$this_coupon = new discount_coupon( $HTTP_POST_VARS['coupon'] );
add
$this_coupon->verify_code();
includes/classes/discount_coupon.php line 68-78 replace
function check_coupons_max_use( $code = '' ) {
$check_use_query = tep_db_query($sql = "SELECT COUNT(*) AS cnt
FROM ".TABLE_ORDERS." AS o
INNER JOIN ".TABLE_DISCOUNT_COUPONS_TO_ORDERS." dc2o
ON dc2o.orders_id=o.orders_id
AND o.customers_id = '".$customer_id."'
AND dc2o.coupons_id='".tep_db_prepare_input( $this->code )."'");
$use = tep_db_fetch_array( $check_use_query );
//show error message if coupons_max_use is equal to the number of times this customer has used the code
if( $this->coupon['coupons_max_use'] <= $use['cnt'] ) $error_message[] = sprintf( ENTRY_DISCOUNT_COUPON_USE_ERROR, $use['cnt'], $this->coupon['coupons_max_use'] ); //display the error message for number of times used
}
with
function check_coupons_max_use() {
global $customer_id;
$check_use_query = tep_db_query($sql = "SELECT COUNT(*) AS cnt
FROM ".TABLE_ORDERS." AS o
INNER JOIN ".TABLE_DISCOUNT_COUPONS_TO_ORDERS." dc2o
ON dc2o.orders_id=o.orders_id
AND o.customers_id = '".(int)$customer_id."'
AND dc2o.coupons_id='".tep_db_prepare_input( $this->code )."'");
$use = tep_db_fetch_array( $check_use_query );
//show error message if coupons_max_use is equal to the number of times this customer has used the code
if( $this->coupon['coupons_max_use'] <= $use['cnt'] ) $this->error_message[] = sprintf( ENTRY_DISCOUNT_COUPON_USE_ERROR, $use['cnt'], $this->coupon['coupons_max_use'] ); //display the error message for number of times used
}
Bug Fixes:
* If free shipping is used, do not allow free shipping if discount brings order total below the minimum for free shipping.
Other Changes:
* Added ability to set maximum order amount to apply the discount. This also allows for using either fixed amount discounts or percentage discounts.
* Updated the manual to include information for the Max Order and Number Available fields.
* Updated manual to be HTML page accessible from coupons admin screen.
* Added discount coupons class to clean up some code in checkout_confirmation.php and order.php.
* Added ability to configure how the discount order total line displays in the order confirmation screen, invoices, etc.
* Added configuration option to choose whether discount order total lines for each tax group should be added and displayed as one line.
This is the complete installation package. Also includes upgrade instructions for Discount Coupon Codes 1.4, posted 27 Jun 2006 with Fixed coupons.php, posted 28 Jun 2006.
PLEASE NOTE: Due to the way osCommerce handles order total calculation and the way that Discount Coupon Codes applies a discount to order totals, fixed discounts have the possibility of being off by small fractions. This can possibly result in a fixed discount of $5.00 being displayed in the order total line as $4.99, for example. The frequency of this happening will be very low. The reason has to do with when the Discount Coupon Codes contribution calculates discounts. The calculation happens during the order object creation, when final total values are not yet known, so the discount is applied incrementally. There are pros and cons to this method. Other Discount Coupon modules calculate discounts after the order object has been created and so may handle fixed discounts with a higher degree of accuracy. If the possibility of fractional rounding errors is unacceptable to you or your customers, I recommend trying one of the other discount coupon contributions.
This is a modified version of 1.4. Same exact install directions. This is designed for new installs only because I have not placed any code in here to alter the mysql tables for upgrades. If you wish to use this as an upgrade or replacement, you would need to alter the table 'discount_coupons' in your mysql. Change coupons_discount_percent setup from decimal for varchar(5).
New installs can just follow directions in install file which has been slightly modified.
Just amended the install txt file to read better, including missing define.
Adds a Discount Coupon Codes Usage Report under the Reports menu in the admin section.
This will only work with the latest version (1.4).
When installing this contribution some people found in admin that it threw and error with mismatched columns - manually edit the code as below or use the new file uploaded
This fixes the issue around line 95
[CODE]tep_db_query($sql = "insert into " . TABLE_DISCOUNT_COUPONS . " (
coupons_id,
coupons_description,
coupons_discount_percent,
date_start,
date_end,
max_use,
min_order)[/CODE]
Change to this
[CODE]tep_db_query($sql = "insert into " . TABLE_DISCOUNT_COUPONS . " (
coupons_id,
coupons_description,
coupons_discount_percent,
date_start,
date_end,
max_use,
min_order,
number_available)[/CODE]
Regards
Mark (Crash3903)
Bug Fixes:
* If "Display Subtotal with Applied Discount" is set to true and min order is set, customer may be incorrectly told that the order subtotal is too low.
This happens when the discount is enough to bring the order subtotal below the min order amount.
* Date limit on coupons was non-inclusive. Discounts with ending dates would be expired at 11:59:59 the night before the set end date.
Other Changes:
* Added ability to set global number of discount coupons available.
Full package. Upgrade instructions from version 1.3 included.
This update makes this great contrib work with Access with Level Account.
This is not the full package.
This is a corrected version of the file included in the previous download. The instructions were correct, so if an install was done by copying and pasting per the instructions, then this file is not needed.
This package contains just the fixed version of this file.
Bug Fixes:
* Fix for hardcoded customer id in query that checks for number of times code has been used.
Other changes:
* Changed dates to accept current admin date format, and to always display using current admin date format.
* Added index to orders table on customers_id to make lookup faster when testing against Max Use.
Bug Fixes:
* Fix for empty coupon order variable that required a refresh before coupon could be displayed.
* Fix for empty variables in coupon INSERT statement.
Other changes:
* Added random code generator contributed by Cubez to coupon code admin.
* Added configure for the length of randomly generated codes in the order total module admin.
* Changed coupon code text box to be uneditable when editing a discount coupon.
Português translation by apopular.
This includes the install instructions and language files. Not a full package.
http://forums.oscommerce.com/index.php?showtopic=213019
Bugs Fixed:
* The Max Use field would not stop a code from being used more than max_use times if the Min Order was not set (set to unlimited).
* The coupon session variable was not destroyed after the checkout processing.
* Some orders with no coupon codes were being entered into the discount_coupons_to_orders table.
Other changes:
* Added a "New Coupon" button to replace the "New Product" button.
* Added an index to the discount_coupons_to_orders table.
This is the full package. Upgrade instructions for the previous versions are included.
Full package. This includes a correction in the manual.
There was an error in the install instructions. This is the complete package with the correct instructions included.
Create coupon codes for your customers to use for discounts on orders.
Discounts are applied before tax and are displayed as one order total line for each applicable tax class. You can configure whether to display the order subtotal including the discount, or before the discount is applied.
Coupon codes may be configured with a start or ending date, number of times they may be used, and an order minimum.
Note: Contributions are used at own risk.