Improved coupon discount

Contrib type: 
Module
Status: 
awaiting
Latest version: 
1.5
Compatibility: 
Ubercart 1.x

Hi there,

The module is not tested with release of Ubercart after the beta 1.5 I wait at least for the 1.0 release or the first D6 compatible to make update of my store and the coupon module

As promised, there is an improved version of the original coupon module.

Not compatible with the old one, please, desinstall the old one and install this one

One you have installed the module, find the settings page under the Customers section of the Store administration menu.

1.5

  • Make admin discount creation / edition more simple to use.
  • Make module compatible with TAPIr, so you can set tables listing as you want.
  • Add product restriction, you can now apply a discount only on specific products. Works with attributes
  • Correct some minor bugs

1.4

  • Correct uses left, max uses, and max uses for one user display in coupon listing
  • Improve order status integration, now compatible with custom order states

1.3

  • Correct a minor bug that considered the value as an integet instead of a float. Now, it's a float

1.2

  • Correct max use calculation error if max uses = 0

1.1

  • Compatible with Ubercart Alpha 8
  • More possibilities when creating a coupon
    • Better date selection (no need of jcalendar)
    • Can set maximum use for a single user
    • Can set role restriction
    • Added weight to choose when show the coupon in line item system
    • No user or no roles selected = all user or roles
    • More fields in coupon listing
  • You can get coupons in checkout
    • Added a button "Get coupon" in checkout page
    • Progress bar with a custom error message if a coupon can't apply
    • if a coupon apply, define it in line item system
  • Improved report system
    • Correct some bug in report system
    • Added user informations in columns
  • More friend with internationalization
  • Maybe more but I don't remember Eye-wink

Let's try it and feedback me if you have errors, suggestions.

Enjoy


PreviewAttachmentSize
uc_coupon_1.5.zip19.38 KB
Joined: 08/17/2007
Juice: 100

Hi zmove - hmm, haven't been able to get it to work yet. When I apply a coupon in checkout, it just sits there trying to apply and nothing happens. Still troubleshooting to see whats up. I also got a script error when I created a coupon in Firefox - box popped up asking if I want to stop script that was running continuously. The coupon did get created though. This does look very promising though. Will report back on more if I can get it functioning. Perhaps I didn't completely uninstall the first module, but thought I had.

-Aaron

Joined: 08/13/2007
Juice: 1108

Maybe try to clean your previous module.

As I said, I change some things in the database and I didn't had time to make an update and test in the .install file.

So this module is not compatible with the previous one. You have to disable it and uninstall it (remove tables in the database).

Joined: 08/18/2007
Juice: 132

After install, I didn't find the admin options that would allow me to set up a coupon.

.... 10 min later .....

Oops, I found the coupon admin under Customers admin. Smiling

Joined: 09/20/2007
Juice: 156

Hello, thank you for the coupon system. We have tested it today and it is working nearly perfect! One small thing: I can't see the cupon deduction and the name of the cupon on the invoice or on any other message from the system.

update: the cupon is shown at the checkout and applied but not shown in the conformation window.

Joined: 08/13/2007
Juice: 1108

Strange...

Some small questions :

  • Did you install the module on a clean ubercart install (no update of the previous coupon)
  • Did you theme your confirmation page or your invoice
  • Did you tried to change the weight of the coupon you applied ?
  • Do you have an online sandbox where I can reproduce the problem ? (you can send it me by PM)
Joined: 09/20/2007
Juice: 156

- Haven't used the coupon system before.. clean install
- Haven't themed the confirmation page
- Yes, have changed the weight to try, but nothing changed
- Not really, will send you.

------------
I have a second installation of an older version of my entire system (there are less modules active) and it was working out of the box. I'm now trying to reproduce.

------------
Copied everything from the server to the local machine and everything was working.
------------
Tried it on a second server. What I found is very easy

the module is not compatible with php4 and needs php5!

AttachmentSize
tablestructure.txt 1.77 KB
Joined: 08/29/2007
Juice: 55

great work updating the coupon module, before I install it over my current Coupons module, do I need to run the Drupal update script afterwards?

now some questions/suggestions:

Is it possible to make a coupon code valid only for one item? Or free shipping? That way we can have promos like "enter code XXXX to receive this product for free".

Also, since there's already an expiration date for coupons, any ways to make a "starting date"?

Joined: 08/18/2007
Juice: 91

I installed coupon 1.3 and tried to create a coupon. When I clicked save, I was taken back to the list of coupons, which was still blank, and I got an error notice that said "Sorry coupon could not be added. Try again"

I have tried 6 times. Does anyone know what's wrong?

Joined: 08/13/2007
Juice: 1108

to 2shortstories :

For coupon to apply on one product, I want to add that soon. I think I will make a catalog browse with ubrowser. That's why I asked some documentation to Ryan on the forum.

For the starting date, it could be added pretty easily, but it's not my priority at the moment.

to somatics :

Some people seems to have problems on PHP4 install. Do you run your website on PHP4 ? I'm looking for somebody to test and debug the module on PHP4.

Joined: 08/18/2007
Juice: 91

I'm running PHP 5.2.4.

Joined: 09/23/2007
Juice: 18

Thanks for the update. I had the old plugin installed and removed it to install this version. I've tried uninstalling and reinstalling a few times, but to no avail. Any ideas?

Joined: 08/13/2007
Juice: 1108

Make sure the coupon table created in the database are removed after uninstalling the module.

If yes, make sure you have PHP5, PHP4 installation, for unknown reasons seems to have problems.

Joined: 09/20/2007
Juice: 156

checked on php4 and it is not working.

Joined: 11/15/2007
Juice: 7

I found that the uc_coupon table is not being created because my MySQL (I have version 4.0.27) is throwing an error like "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near character set utf8 ".

The uc_coupon.install file has a db query that creates the uc_coupon table. In that query are a few lines where have "character set utf8".

You can create the table manually following what's in the query or remove all the "character set utf8 " instances and run the query and it will work fine.

I removed the text and ran query. The table created fine and it works now.

Joined: 12/12/2007
Juice: 42

UTF8 may not be enabled by default with some versions of mysql (ie multibyte tables). So you'd need to turn that on at the server level before tables can be created supporting UTF8.

Joined: 12/11/2007
Juice: 15

I would love to see the ability to limit the coupon to specific product classes. As it is, I have created a new gift certificate class (for the gc module), and I don't want the discount to apply to these products.

I could get this to work with the "coupon on one product" functionality you describe above (as long as you allow multiple products, not just one) but limiting it to the product class would be ideal for me.

Joined: 08/13/2007
Juice: 1108

I'm working on 1.5 that allow to apply discount only on specified products.

edit : the 1.5 version will contain product restriction. You will be able to select products and attributes for which apply a discount. A product class restriction is not planned ATM because I don't need this functionnality at the moment and my boss didn't give unlimited time to work on this module.

It will be tweaky, but you will be able to select all products of your class one by one (could be long, but it will work).

Joined: 11/20/2007
Juice: 32

Howdy,

When I added a product condition to my first coupon, I was getting PHP errors both on the page that lists the coupons and at the product listing page related to the 'attributes' array. I deleted the product condition, installed the attributes module, re-added the product, and both the errors went away.

Thus, I believe the attributes module should be a required module for this, but it is not, not as of version 1.5.

Cheers,

Shiraz

Joined: 08/13/2007
Juice: 1108

Ok, I will add the attribute dependency for the next release. Thank you for your report.

Joined: 11/27/2007
Juice: 129

I am using beta3 and uc_coupon 1.5. My site is also running on PHP4.2.11. It correctly calculates the coupon discount on the checkout page. However, it does not apply it either on the Review Cart page nor is it transmitted to Paypal payments. The payment is requested for the original amount BEFORE applying the coupon.

Joined: 08/13/2007
Juice: 1108

For the review page, check if the coupon you defined have the same weitght than another line item.

For the paypal problem, I don't use it, I don't have paypal account try to see in others modules how variables are passed to paypal to apply the discount.

Joined: 11/27/2007
Juice: 129

The coupon does not have the same weight as another line item. The checkout page correctly calculates and shows the coupon discount. The review order page does NOT show the coupon discount. It disappears. I am using Ubercart revision 791, Drupal 5.6, and Coupon 1.5. I also am using flat rate shipping.

I have also tried specifying payment by Paypal and other. Doesn't matter. the coupon discount is correctly calculated and applied on the checkout page and disappears on the review order page.

I tried another website I am developing which is currently using Ubercart revision 748, Drupal 5.5, and coupon 1.5. Also using flatrate shipping. Same result.

Joined: 01/29/2008
Juice: 4

Thanks for creating this module I really need it. The only problem is I'm getting an error when I test it out. It responds with undefinedundefined = undefined under the get coupon button. Any ideas?

Joined: 08/13/2007
Juice: 1108

to seedseller & josie says:

I don't know what could be the cause of your problems. Could you create me a sandbox where I could reproduce the bug ?

pm me the link if it's possible.

Joined: 01/29/2008
Juice: 4

I don't know what that is. The site isn't currently being advertised until Friday the 1st. Here is the link.
http://www.3clothingco.com

Joined: 08/13/2007
Juice: 1108

Hi,

A sandbox is a copy of your website with a temporary admin account in which I could reproduce the bug. with just a customer account and without knowing the coupon code, I can't help you...

Joined: 09/19/2007
Juice: 89

The issue turns out to be a small omission:

On line 655 of uc_coupon.module the & was missing from the $arg1 parameter.
function uc_checkout_pane_coupon($op, &$arg1, $arg2) {

Just edit your own module and make this change to have the coupons work.
I had the exact same issue, and decided to investigate and figure out the problem.

The $arg1 was being modified in the function, but as it was not being passed by reference, the value never gets back to the calling function.

Great module!

Cheers,
Gord.

Joined: 11/27/2007
Juice: 129

Wonderful!!!

I was trying to get this high enough on my list to check it out. In version 1.5, my editor tells me that the change is on line 1029. Works well with beta five EXCEPT that there is a rounding error.

Applying a 10% coupon to a product priced at $129.95 correctly gives me a $13.00 discount. When I go to the review page, the discount incorrectly shows a $12.99 discount. It is only a penny, but for some customers it could be a deal breaker.

Joined: 09/28/2007
Juice: 85

Greetings,

Everything with this module works great, except for one critical problem.

Every time I try to add a restriction to a coupon and hit submit the screen goes white and I get this error:

Fatal error: [] operator not supported for strings in /home/site/public_html/sites/all/modules/uc_coupon/uc_coupon.module on line 341

What can I do to fix this?

TIA,
txcrew

Joined: 08/13/2007
Juice: 1108

For the next month, I will not have time to maintain this module, so, I would appreciate that you point me problems and try to post the solution, I will continue to update the module if I point that it's a real issue.

I will try to post the 1.6 during the march month.

Joined: 01/30/2008
Juice: 66

First off, my question: How does this contribution differ from the Gift Certificate Module?

Now my feature request: Is it possible for you to implment something in the notification area where the admin of the site is notified if someone makes a new coupon, etc.? The person who I am working for wanted to know if there was a feature to let him know if new coupons were created or given out to users, since he is going to possibly be handing store administration off to another user/worker.

Thanks!

Joined: 03/03/2008
Juice: 22

regarding the line 341 question..I fixed this by changing:

if (!empty($products_number)) {

while ($product = db_fetch_object($product_list)) {
$product_data = unserialize($product->data);
$attributes_list = array();
foreach($product_data['attributes'] as $key => $attribute) {
$attributes_list[] = $key.' : '.$attribute;
}
$products2[] = $product->title.theme_item_list($attributes_list, '', 'ul', array('class' => 'attributes-list'));

}
$products = theme_item_list($products2, '', 'ul', array('class' => 'products-list'));
//$products = t('products');
} else {
$products = t('all');
}

TO

if (!empty($products_number)) {

while ($product = db_fetch_object($product_list)) {
$product_data = unserialize($product->data);
$attributes_list = array();
foreach($product_data['attributes'] as $key => $attribute) {
$attributes_list[] = $key.' : '.$attribute;
}
$products2[] = $product->title.theme_item_list($attributes_list, '', 'ul', array('class' => 'attributes-list'));

}
$products = theme_item_list($products2, '', 'ul', array('class' => 'products-list'));
unset($products2);
} else {
$products = t('all');
}

* Modified 03/21/08

Joined: 03/20/2008
Juice: 9

user warning: Unknown column 'max_user_uses' in 'field list' query: INSERT INTO uc_coupons (cid, name, code, value, type, status, valid_until, max_uses, max_user_uses, users, roles, minimum_order, weight) VALUES ('1', 'Promotional Code', 'Promo2008', '10', 'price', '1', '1213938000', '0', '1', '', '', '10', '0') in [path]\includes\database.mysql.inc on line 172.

I've updated to the latest. I'm thinking about just adding the field myself. Thoughts? This would be a great module - I feel that it should be included with UC's core (or something like it.... that works)

Joined: 03/03/2008
Juice: 22

The code below is the table creation script from coupon installation--
Perhaps see what may be missing from your database and add it in.
(May be when update script was run, it did not add the necessary new fields (I don't know what version you had before- so just in case.)

CREATE TABLE {uc_coupons} (
cid int(11) NOT NULL auto_increment,
name varchar(30) NOT NULL,
code varchar(40) NOT NULL default 'coupon_code',
value decimal(6,2) NOT NULL,
type varchar(12) NOT NULL default 'price',
status int(1) NOT NULL default '1',
valid_until int(11) default NULL,
max_uses int(4) NOT NULL,
max_user_uses int(4) NOT NULL,
users text,
roles text,
minimum_order decimal(6,2) NOT NULL default 0.00,
weight tinyint(2),
PRIMARY KEY  (cid)
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ;

You can also delete the table and run the following script.

CREATE TABLE uc_coupons (
cid int(11) NOT NULL auto_increment,
name varchar(30) NOT NULL,
code varchar(40) NOT NULL default 'coupon_code',
value decimal(6,2) NOT NULL,
type varchar(12) NOT NULL default 'price',
status int(1) NOT NULL default '1',
valid_until int(11) default NULL,
max_uses int(4) NOT NULL,
max_user_uses int(4) NOT NULL,
users text,
roles text,
minimum_order decimal(6,2) NOT NULL default 0.00,
weight tinyint(2),
PRIMARY KEY  (cid)
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ;
Joined: 03/03/2008
Juice: 22

The "gift certificate module" that I used have an ablity to specify who (by email) can use the gift certificate (and also who it is from). Visitor will have ability to buy the "gift certificate". Also it seemed to only allow the certificate to be used *once*.

Coupon have more flexiblity - and you can also define your own "coupon code", specify products to be used, number of times used (or unlimited), etc...

Joined: 08/14/2007
Juice: 3867

Correct. Gift Certificates are for a specified amount for a specified user. Coupons can be used by multiple users a select number of times (or whatever configuration you like) and the amount can vary based on whether you are doing a percentage or dollar value.

Help directly fund development: Donate via PayPal!

Joined: 03/03/2008
Juice: 22

FYI-

When installing this for the first time, you may need to modify the script (I had to ...)

uc_coupon.install's function uc_coupon_install() to be:

function uc_coupon_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {uc_coupons} (
cid int(11) NOT NULL auto_increment,
name varchar(30) NOT NULL,
code varchar(40) NOT NULL default 'coupon_code',
value decimal(6,2) NOT NULL,
type varchar(12) NOT NULL default 'price',
status int(1) NOT NULL default '1',
valid_until int(11) default NULL,
max_uses int(4) NOT NULL,
max_user_uses int(4) NOT NULL,
users text,
roles text,
minimum_order decimal(6,2) NOT NULL default 0.00,
weight tinyint(2),
PRIMARY KEY  (cid)
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ;");
db_query("CREATE TABLE {uc_coupons_products} (
`coupon_product_id` int(9) NOT NULL auto_increment,
`cid` mediumint(9) NOT NULL,
`nid` mediumint(9) NOT NULL,
`title` varchar(128) NOT NULL,
`manufacturer` varchar(32) NOT NULL,
`model` varchar(32) NOT NULL,
`data` text NOT NULL,
PRIMARY KEY  (`coupon_product_id`),
KEY `coupon_id` (`cid`)
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ;");
db_query("CREATE TABLE {uc_coupons_orders} (
cuid int(11) NOT NULL auto_increment,
cid int(11) NOT NULL,
oid int(11) NOT NULL default '0',
value decimal(10,2) NOT NULL default '0.00',
code varchar(40) NOT NULL default 'default_code',
PRIMARY KEY  (cuid)
) /*!40100 DEFAULT CHARACTER SET UTF8 */");
    break;
  }
}

`{uc_coupons_products}` - the single quote around this caused a problem in my install.

Joined: 03/25/2008
Juice: 69

I seem to be having problems with the product restriction function. Mainly that mine shows up blank! I am using uc_coupon_1.5 and Ubercart 5.10 beta7. The only different thing i can think about my site is that its in a subdirectory. Ie its not installed into www.prodseminars.com, its www.prodseminars.com/courses . However this has never been a problem before. I also just started getting this error:

warning: Invalid argument supplied for foreach() in /public_html/courses/includes/form.inc on line 949.

Any ideas? Im racking my brains here. Thanks !

Joined: 08/13/2007
Juice: 1108

Hi,

I work on beta 6 and the module works, It seems the beta 7 break something in the module.

I don't have the beta 7 and I don't plan to install it, It breaks too much things (VAT, coupon etc...) I will wait for the first release of UC working on drupal 6 and I will make an huge upgrade of my website at this moment.

Joined: 08/14/2007
Juice: 3867

Zmove, Drupal 6? That's a long way for me and I'm sure most of the Ubercart community. I have a live site using Ubercart and D5 and I'd love to get coupons working for the next version of our website, which will most likely also be on D5 (unless all of the dependencies get updated in the next few months).

It's strange that updates between two beta versions would break that much stuff? Do you have a dev server you can test the new builds on? Perhaps the bugs you are talking about got fixed (or will get fixed) in latest bazaar code?

Help directly fund development: Donate via PayPal!

Joined: 03/25/2008
Juice: 69

Im kind of at my wits end about this, and I need to get it up and working for a client by the weekend. Has anyone had any problems going from Uber 7 to 6? Any other possible solutions? Thank you everyone for your help!

Joined: 08/13/2007
Juice: 1108

Hmm If I can't wait for a D6 version I will wait at least the 1.0 release to be sure if I make changes to the module, it will be for a pretty long time.

I finished the project for my client that needed the coupon module, ATM, I have a lot of work but none of them are commerce website, that's don't justify I work on it so and ATM I don't have enough free time to do it after the work.

So the next time I will be able to improve the module is when the 1.0 release of UC or when D6 will have enough module to be used in a production environment.

Joined: 03/20/2008
Juice: 9

Thank you, dropping the table and re-adding it worked

Joined: 08/23/2007
Juice: 77

I got this error when attempting to edit an existing coupon to work for just one item in the store.

user warning: Unknown column 'max_user_uses' in 'field list' query: UPDATE uc_coupons SET name = 'DASH15', code = 'DASH15', value = 15, type = 'percentage', status = 1, valid_until = 1214888400, max_uses = 0, max_user_uses = 1, users = '', roles = '1,2,', minimum_order = 0, weight = 0 WHERE cid = 2 in /home/rofl/public_html/includes/database.mysql.inc on line 172.

Coupon could not be updated. Try again.

This is line 172 in /home/rofl/public_html/includes/database.mysql.inc

    trigger_error(check_plain(mysql_error($active_db) ."\nquery: ". $query), E_USER_WARNING);
Joined: 04/14/2008
Juice: 4

I've installed your module to my website. But, when trying to add new coupon, I always get the following errors:

Quote:

Fatal error: Call to undefined function mb_substr_count() in /public_html/sites/default/modules/uc_coupon/uc_coupon.module on line 293

What should I do to fix this problem?

FYI, I have uninstalled the previous version of this module and delete the table from database (I can only find the table that related to this module in the "System" Table) before installing the current version.

Thanks a bunch.
Dedy.

Joined: 08/14/2007
Juice: 3867

Sounds like you are using PHP version less than 4.3.

http://us.php.net/mb_substr_count

mb_substr_count

(PHP 4 >= 4.3.0, PHP 5)

mb_substr_count — Count the number of substring occurrences

Help directly fund development: Donate via PayPal!

Joined: 01/23/2008
Juice: 185

I think that a modification should be done on uc_coupon_add_form function

Under $form['general']['code'] the length should be restricted:
'#maxlength' => 14,

Without this restriction, you can create coupon codes bigger than the checkout form accepts.
The database field of the uc_coupons table should be reduced to 14 too, but this is a more delicate change.

Joined: 01/30/2008
Juice: 66

Hello,
I do not think coupons are being applied properly with Ubercart 1.0-rc2. More information about my Drupal/Ubercart install is here.

Thank You!

Joined: 04/14/2008
Juice: 4

For torgosPizza,

I've checked my php and found that my php version is php 5.

What should I do with those codes? Should I add them to some table in my database?

Thanks.
Dedy.

Joined: 11/24/2007
Juice: 8

@BlindWolf,

Confirmed: coupons not being applied/carried over when going from Checkout to Review Order page. On Checkout page it shows the discount but going forward, no. I am using 1.0-rc2 with uc_coupon_2.

I would be willing to help sponsor the finalization/fix of this EXCELLENT module (the improvements are great). We're a bootstrap startup, low on cash, and need it for prominent blog sites that want exclusive coupons for them to promote us. I'm willing to help if a few others can go in with me to defray the cost and get this sooner than later. Let me know, BlindWolf, or anyone else willing to get this going NOW (I can do this only if others can help). Send me private msg, or in comments(?). Thanks, team.