I had a rule saying that if order contains a particular product, set coupon as invalid.

When I tried to use the coupon, it spit out this error.

Notice: Trying to get property of non-object in commerce_coupon_fixed_amount_commerce_cart_line_item_refresh() (line 96 of /Applications/MAMP/htdocs/dev-store/sites/all/modules/commerce_coupon_fixed_amount/commerce_coupon_fixed_amount.module).
Notice: Trying to get property of non-object in commerce_coupon_remove_coupon_from_order() (line 624 of /Applications/MAMP/htdocs/dev-store/sites/all/modules/commerce_coupon/commerce_coupon.module).
PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'field_data_commerce_coupon_reference0.commerce_coupon_reference_target_id' in 'where clause': SELECT field_data_commerce_coupon_reference0.entity_type AS entity_type, field_data_commerce_coupon_reference0.entity_id AS entity_id, field_data_commerce_coupon_reference0.revision_id AS revision_id, field_data_commerce_coupon_reference0.bundle AS bundle FROM {field_data_commerce_coupon_reference} field_data_commerce_coupon_reference0 INNER JOIN {commerce_line_item} commerce_line_item ON commerce_line_item.line_item_id = field_data_commerce_coupon_reference0.entity_id WHERE (field_data_commerce_coupon_reference0.commerce_coupon_reference_target_id = :db_condition_placeholder_0) AND (field_data_commerce_coupon_reference0.deleted = :db_condition_placeholder_1) AND (commerce_line_item.order_id = :db_condition_placeholder_2) AND (commerce_line_item.type = :db_condition_placeholder_3) AND (field_data_commerce_coupon_reference0.entity_type = :db_condition_placeholder_4) ; Array ( [:db_condition_placeholder_0] => [:db_condition_placeholder_1] => 0 [:db_condition_placeholder_2] => 12 [:db_condition_placeholder_3] => commerce_coupon [:db_condition_placeholder_4] => commerce_line_item ) in field_sql_storage_field_storage_query() (line 577 of /Applications/MAMP/htdocs/dev-store/modules/field/modules/field_sql_storage/field_sql_storage.module).

I did an isset check on the $coupon variable and it returned true.

do you guys have any idea what may have caused this?



akosipax’s picture

I did a fresh install, by the way. And out of the box (I created a fixed amount coupon and tried to use it), it spits out this error.

pcambra’s picture

Category: bug » support
Priority: Major » Normal

I had a rule saying that if order contains a particular product, set coupon as invalid.

A good start will be attaching the exported rule with a path to reproduce the error.

akosipax’s picture

Hmmm. I tried the coupon even without this rule, and it still didn't work...

But here it is anyway.

{ "rules_check_if_cart_contains_non_donate_products" : {
    "LABEL" : "Check if cart contains non-donate products",
    "PLUGIN" : "reaction rule",
    "TAGS" : [ "Coupon Validation" ],
    "REQUIRES" : [ "commerce_order", "rules", "commerce_coupon" ],
    "ON" : [ "commerce_coupon_validate" ],
    "IF" : [
      { "commerce_order_contains_product" : {
          "commerce_order" : [ "commerce-order" ],
          "product_id" : "DONGEN",
          "operator" : "\u003E=",
          "value" : "1"
    "DO" : [
      { "drupal_message" : {
          "message" : "Sorry, you can\u0027t use a coupon on a donation.",
          "type" : "error"
      { "commerce_coupon_action_is_invalid_coupon" : [  ] }

Thanks for the help.

patrickharris’s picture

I get the identical error, also on a clean install.

deggertsen’s picture

Category: support » bug

Same issue here. Clean install. Don't know why this was marked down from major to normal because as is this module doesn't work at all due to this problem. I'm at least going to mark it as a bug again. I've reproduced this several times as well by simply installing the module and creating a fixed price coupon and then trying to apply the coupon.

I did manage to avoid the problem by creating a validation rule that made the coupon invalid, but as long as the coupon is valid I get this error.

This issue also breaks my view at /admin/commerce/orders/carts

Does anybody know how to at least manually remove the orders with the broken applied coupons? Where in the database would I need to remove the records? Any time I try to go to a page that even references an order with one of these coupons, it throws this error.

deggertsen’s picture

This is the line item in the database that is causing the errors. As soon as I remove it from the database the errors stop coming up. Does that help at all? I really don't even know where to start on this issue.

INSERT INTO `commerce_line_item` (`line_item_id`, `order_id`, `type`, `line_item_label`, `quantity`, `created`, `changed`, `data`) VALUES
(1148, 35, 'commerce_coupon', 'Fixed coupon: TESTING3', '1.00', 1339011969, 1339011969, 0x613a303a7b7d);
pcambra’s picture

Status: Active » Postponed (maintainer needs more info)

Marking this as need more info as I've just installed a commerce kickstart out of the box + commerce coupon, dev version + pct & fixed modules, also dev version. No trace of the error, I even imported rule on #3.
I've tried to delete, disable, and do all kind of things with the fixed coupon but no error.

Same issue here. Clean install

Could you please tell me a consistent way to reproduce this in a clean install?

Please please, make sure you're using latest dev of commerce coupon.

deggertsen’s picture

Okay, so for me I was not installing on a new drupal install. I was simply uninstalling commerce coupon and associated modules and then re-installing. After uninstalling again I found the table "field_data_commerce_coupon_code" still in the database. So I manually removed it from the database as well as any other coupon related entries and installed everything again. I'm still having some issues, but different ones now that I'm sure have something to do with my manual manipulation of the database.

So this issue seems to be stuff that is left over when uninstalling commerce coupon and that there probably isn't a very good update path from the current version to the most recent dev version. Assuming this is the problem, what is the solution? Seems to me that something is wrong with the uninstall script, but I really have no idea what I'm talking about so maybe someone else can shed some light on a possible answer.

Can those above who are having the same issue confirm that they had older versions of commerce coupon installed before updating to the most recent version?

patrickharris’s picture

Yes, I had an older version of commerce coupon, and also found that when I uninstalled/reinstalled the old and then dev versions, tables were not deleted properly that caused problems when reinstalling.

pcambra’s picture

Title: error when setting coupon as invalid when order contains a particular product » Review uninstall/upgrade process from beta4
Project: Commerce coupon fixed amount » Commerce Coupon
Status: Postponed (maintainer needs more info) » Active

Well, then don't report this as "clean install" errors when you're clearly not doing this in a clean install.

The thing here will be:

- Install a beta4 version
- Create a new coupon
- Apply coupon to an order
- Download and replace with dev version + fixed + pct modules
- Upgrade
- Test.

But also:
- Install a beta4 version
- Create a new coupon
- Uninstall beta4
- See if there's something left behind
- Download and install dev version + fixed + pct modules
- Test

It will really help getting some feedback on this part. Setting this to Commerce coupon itself

pcambra’s picture

deggertsen’s picture

Guess I didn't understand what a clean install was before now. Glad we were able to figure out where this issue actually exists. I had to go in an manually delete quite a few tables to make sure it is installed completely and finally got rid of the errors; however, I'm still having problems with the database when I do reinstall it. Is there any specific information that would be helpful?

patrickharris’s picture

After upgrading to dev from beta4, I'm unable to uninstall - I get "The website encountered an unexpected error. Please try again later.", and Unknown data property commerce_coupon_order_reference. in EntityStructureWrapper->getPropertyInfo() in the log..

@pcambra - could you advise on how to manually uninstall, so I can try & successfully reinstall it? I can manually delete the commerce_coupon tables, and alter the modules' status in settings, & delete relevant variables, but I still get the commerce_coupon_order_reference error. Should I also be altering field_config and field_config_instance?

pcambra’s picture

see the issue above about uninstall not deleting reference fields

generalconsensus’s picture

We should really limit which modules are able to be installed with which in the info files and start to work on creating a README file to explain to newcomers the differentiation between the dev and beta branches. I just ended up trashing my database and restoring a backup over trying to hunt down all the errant fields in all the tables.

FAAREIA’s picture

I need to reinstall this module but i can't disable it. "commerce_coupon_reference" Field in Coupon line item is stopping me to do so.
I need to reinstall because i......somehow.....delete the coupon field in "/admin/commerce/config/order/fields/" and i can't recreate a field with "commerce_" prefix.


generalconsensus’s picture

Priority: Normal » Major

I continue to get errors with my database even after having used all the existing delete methods available on both the dev and beta branches install files (field_delete_instance and field_delete_field)

1. The table field_config_instance still contains entity types "commerce_coupon", "commerce_line_item", and "commerce_coupon_log"
2. The table field_config contains a field_name "commerce_coupon_reference"

Here are the errors I get

Notice: Undefined index: commerce_coupon in commerce_product_reference_entity_info_alter() (line 811 of /Users/dannymacom/Sites/Umbabox.KickstartDev/profiles/commerce_kickstart/modules/commerce/modules/product_reference/commerce_product_reference.module).

Warning: Invalid argument supplied for foreach() in commerce_product_reference_entity_info_alter() (line 811 of /Users/dannymacom/Sites/Umbabox.KickstartDev/profiles/commerce_kickstart/modules/commerce/modules/product_reference/commerce_product_reference.module)

Over the course of the evening I've made multiple attempts to manually delete from the database (NOT A GOOD IDEA). In place of that I would like assistance from anyone on how to delete these entities and fields so I can start fresh with the dev branch of commerce coupon. Seriously thanks everyone, I'm not looking for hand outs I want to grow this module -- but first I need to be able to get my database running normally again.

patrickharris’s picture

@pcambra - indeed, isn't this the issue we are discussing? Are you able to give an answer?

pcambra’s picture

Guys if you want to really help in here I've already mentioned how you can do this in #1604918-10: Review uninstall/upgrade process from beta4

#18, see #11

pcambra’s picture

I've commited the uninstall fix on #1619094: Uninstall does not delete reference fields so the fields are deleted for -dev version on uninstall.

The way for deleting the fields would be field_delete_field('field_name'), no need to mess in the database, you definitely don't want to do this.
Bear in mind that the fields will remain in the database for a while until field_purge_batch is run and cleans up the database. They would remain as field_data_deleted_XX or something similar.

I'd say that -dev version is just ok as I've uninstall and reinstall it again. Let's see what happens with beta4.

pcambra’s picture

Ok, just upgraded from beta4, had some issues but after clearing cache you can perform all the updates.

Bear in mind that the Basic coupon type is not supported anymore. You've got to install either pct submodule, fixed amount submodule or both and go to "admin/commerce/coupons/settings" and run the upgrade process.

I'll probably push dev as beta5 very soon so we can get rid of as much of this issues in the future.

pcambra’s picture

Ok, just created this documentation page for doing some documentation, history and tips to solve common problems.
I'll start with some background information but please feel free to complete things in there.

beta5 is in its way, so anyone that installs from now on gets stuck in this upgrade thing.

And as a general information, please do not try to uninstall beta4 using beta5 code.

FAAREIA’s picture

All right, i just manage to uninstall my "beta4+25" version.
Here are the steps i did:

1- Changed line 237 from commerce_delete_fields('commerce_coupon_reference'); to commerce_delete_field('commerce_coupon_reference'); at "commerce_coupon.install" file. I did this because of this issue "Uninstall does not delete reference fields". As you notice, beta4+25 does not have those 2 lines from the issue, so i replaced only one line.. Plus if you don't do this change, you will probably get this error when you uninstall commerce coupon module: "Invalid argument supplied for foreach() in commerce_product_reference_entity_info_alter() (line 823....."

2- Disable all Coupon modules. If you can't disable "commerce_coupon" module beacuse there is a blocked field at Coupon line item, just drush -> "drush field-delete commerce_coupon_reference".

That's my case with "beta4+25" version.
Hope it helps someone.
pcambra, many thanks for pushing forward this project.

AdamGerthel’s picture

After following pcambra's documentation page, I seem to have managed to upgrade from Beta 3 to Beta 5. One problem that still persists is that I'm getting this error both when editing and viewing the coupon review pane:

Fatal error: Call to undefined method views_plugin_query_default::get_result_entities() in /path-to-site/all/modules/contrib/commerce_coupon/includes/views/handlers/commerce_coupon_handler_field_coupon_granted_amount.inc on line 23

pcambra’s picture

@AdamGerthel That's maybe a problem with an old views version, see get_result_entities definition in the API

@Stackcreativa it would be great if you could update the documentation page with your update process.

AdamGerthel’s picture

@pcambra I'm running Views 7.x-3.3 which is the latest stable release

FAAREIA’s picture

@pcambra. Just added the steps to documentation page. Feel free to edit or correct any word, it's my first time at add some documentation and i don't speak english. =)

pcambra’s picture

Thanks @Stakcreativa!

@AdamGerthel that is just confusing, the function is in the latest -dev (http://drupalcode.org/project/views.git/blob/refs/heads/7.x-3.x:/plugins...), could you check if you've got it in the same place?

AdamGerthel’s picture

@pcambra Like I said, I'm running Views 3.3. It does have "function get_result_entities" though, on line 1499.

Sorry about that. The installation profile on the site has Views 3.3. There was however, a dev version running in modules/contrib. Probably since that dev was required back in september when the site was launched. My bad.

pcambra’s picture

If, like you said, you've got views 3.3 and the function is there, there's no particular reason why the method is not found other than cache clear or registry rebuild.

patrickharris’s picture

I've successfully managed to uninstall the module, and get the site running by changing the commerce_coupon_order_reference widget to select from autocomplete (http://drupal.org/node/1594114#comment-6042656) (!).

However, now when I try and install beta5 of commerce coupon, the fields "field_data_commerce_coupon_order_reference" and "field_data_commerce_coupon_reference" are not created. The module doesn't function properly, and when I try and uninstall it, I get errors that the two fields mentioned don't exist, when the uninstall tries to remove them.

pcambra’s picture

I don't know why this field is hitting you so bad, it's created normally the same way than the reference in the line items, no difference there.
This is the function that creates it: commerce_coupon_order_configuration

The easiest workaround would be to create the field yourself with the settings that you can see in the function above.

rtdean93’s picture

This same thing happened with me... I had to jump through many hoops to fully remove beta 4 - and finally got beta 5 working... but once I add a coupon to the cart I get a WSOD -

PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'betablue_blueline3.field_data_commerce_coupon_reference' doesn't exist: INSERT INTO {field_data_commerce_coupon_reference} (entity_type, entity_id, revision_id, bundle, delta, language, commerce_coupon_reference_value, commerce_coupon_reference_format) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7); Array ( [:db_insert_placeholder_0] => commerce_line_item [:db_insert_placeholder_1] => 1940 [:db_insert_placeholder_2] => 1940 [:db_insert_placeholder_3] => commerce_coupon [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => 2 [:db_insert_placeholder_7] => ) in field_sql_storage_field_storage_write() (line 448 of /home/betablue/blueline-grs64/www/modules/field/modules/field_sql_storage/field_sql_storage.module).

Here are my steps to remove 4 beta+26...
1. Disable product_reference_view module - not needed and throwing a conflict.
2. Delete commerce coupont pct fields from the commerce coupon UI
3. Delete commerce coupon pct type
4. Disable commerce coupon pct mod
5. Then disable the other coupon mods - fixed, ui, then coupon.
6. Perform module uninstall for all the coupon mods.
7. Using PHPMYADMIN or Drush - DROP TABLE `field_data_commerce_coupon_reference`, `field_revision_commerce_coupon_reference`;

Then I upgraded the commerce code to beta 5.

Only issue is "However, now when I try and install beta5 of commerce coupon, the fields "field_data_commerce_coupon_order_reference" and "field_data_commerce_coupon_reference" are not created. " I will do this manually for now.

rtdean93’s picture

Update - and a question... the error in the log is "field_data_commerce_coupon_reference' doesn't exist" but my database has a column called field_data_commerce_coupon_order_reference - not that the database entry (which was automatically created."

I can't create a field since the title field_data_commerce_coupon_reference is too long...

Any suggestions?

patrickharris’s picture

I manually uninstalled beta4 and then installed beta5. When I then uninstalled beta5 and reinstalled beta5, I get the error

Notice: Undefined index: commerce_coupon_percent_amount in _token_field_info() (line 1322 of token/token.tokens.inc).
Warning: array_count_values() [function.array-count-values]: Can only count STRING and INTEGER values! in _token_field_info() (line 1329 of token/token.tokens.inc).

This error stopped the following fields being created, that had been previously successfully created on the first beta5 install:
field_data_commerce_coupon_order_reference, field_data_commerce_coupon_percentage_amount, field_data_commerce_coupon_reference, field_revision_commerce_coupon_order_reference, field_revision_commerce_coupon_reference

somatics’s picture

Well, I completely uninstalled all Coupon modules and also dropped the tables field_data_commerce_coupon_reference` and `field_revision_commerce_coupon_reference`.

When I reinstalled Beta 5, I checked the MySQL database, and it included the following tables:


When I tried to check out with a value entered into the coupon field, I got a fatal error screen and the dblogs contained this error for the event:

DOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'pantheon.field_data_commerce_coupon_reference' doesn't exist: INSERT INTO {field_data_commerce_coupon_reference} (entity_type, entity_id, revision_id, bundle, delta, language, commerce_coupon_reference_value, commerce_coupon_reference_format) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7); Array ( [:db_insert_placeholder_0] => commerce_line_item [:db_insert_placeholder_1] => 1720 [:db_insert_placeholder_2] => 1720 [:db_insert_placeholder_3] => commerce_coupon [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => 2 [:db_insert_placeholder_7] => ) in field_sql_storage_field_storage_write() (line 448 of /path-to-drupal/modules/field/modules/field_sql_storage/field_sql_storage.module).

I'm not clear about whether there is a definitive answer on how to solve this. What is causing the failure of Beta5 to install all the necessary tables? Is there something else I need to manually remove from the database so it will successfully install properly?

I really need to use Coupons for our current marketing campaigns. I've got a lot of irritated customers, who are opting to not be customers since they can't get their coupon discount. Can someone tell me what to do to finish the uninstall properly or install it properly, because it's not clear to me.

pcambra’s picture

Category: bug » support
Priority: Major » Normal
bendev’s picture

I have a similar issue with the upgrade from beta4 to more recent version.

I first thaught it was solved but the issue came back as soon as I added a product to the cart. The commerce order is created in the database and I immediatley get the error:

EntityMetadataWrapperException: Unknown data property commerce_coupon_order_reference. in EntityStructureWrapper->getPropertyInfo() ...

The only way I found to make this message disappear is to delete the commerce order created in the database.

So, to summarize, I came to this problem after an upgrade from beta 4.
I have tried several times to uninstall end reinstall commerce_coupon, to clear caches with drush, to delete the reference field manually or with PHP commands or drush ... and I am still experiencing this issue

I looked at the install file of beta 6 and I see in the function update_7004
"// Remove old field and force a new creation, no way to rename it.
// see http://drupal.org/node/1201898

I tried to perform it manually in the database but couldn't fix it.
At the moment I don't know what else I could try and any suggestion is more than welcome. Unfortunately I can't start from scratch since the site is almost finished besides the coupon feature...
I would really appreaciate if someone could guide me to fix the issue either via the forum, email, IRC or whatever other mean. I will of course share the solution back with the community when it will be fixed...

Thanks already

pcambra’s picture

You've got a bunch of suggestions in the doc page for solving that.

If everything else fails, what I'd do in that case is to completely uninstall commerce coupon beta4, the uninstaller from beta6 won't work there, btw, delete the files, delete the remaining fields from coupon and run the cron until there's no field_delete table in the database. Then, reinstall.

Something to explore for those with problems is reuse some of the techniques used in Commerce Repair.

bendev’s picture

It seems (but I will stay cautious this time) that the problem could be fixed.

I did two things:

In the list of fields that I could see in the reports, there were still mention of coupon and coupon_reference fields unused... I deleted them using this http://drupal.org/node/1351506
and these error disappeared but I still had the issue EntityMetadataWrapperException: Unknown data property commerce_coupon_order_reference. in EntityStructureWrapper->getPropertyInfo()

Then I realised that the beta 6 version installed a commerce_coupon_order_reference entity reference only in the main order admin/commerce/config/order/fields. But I had created a custom order type with the order type module and this reference field was not created there. I added the same commerce_coupon_order_reference in my custom order type and it seems to solve the issue.


drupalninja99’s picture

@pcambra the issue to me is that commerce_coupon_order_configuration(); is never called from a clean install correct? I see a hook_schema() but I do not see a hook_install(). It seems to me that some logic from commerce_coupon_update_7004() perhaps needs to get dropped into a hook_install()?

If you do a clean install those update hooks are never called, correct?

drupalninja99’s picture

If I run these commands from the command line:


Then I no longer get an error at /admin/commerce/coupons, altho I still have a couple missing handlers in the coupons view:

"Broken/missing handler (Broken handler commerce_coupon.type)"
"Broken/missing handler (Active)"

aidanlis’s picture

I'm pretty mad that there was a structural change of this magnitude hidden in a minor version bump, beta notwithstanding.

The code in http://drupal.org/node/1532136#comment-5908990 is the only thing that got me through this. If you're having trouble and nothing else is working, check your line item types /admin/commerce/config/line-items/commerce-coupon/fields

pcambra’s picture

I'm pretty mad that there was a structural change of this magnitude hidden in a minor version bump, beta notwithstanding.

This happened almost half a year ago, the previous version of the module was clearly not functional and there's a issue here in the queue called roadmap for coupons where everything is quite well documented. Thanks for your positive feedback.

aidanlis’s picture

I would have been mad half a year ago too!

The new modules look great and I'm super appreciative of your hard work, I can see why it's important to separate the modules out like this. It looks like there will be a lot more flexibility down the line ... It's just a shock losing almost an entire day trying to fix a broken checkout on a minor version bump for a beta. It's still not working properly. This is the sort of change I'd have expected to go into a new major version (even if there wasn't a stable yet).

pcambra’s picture

I would have been mad half a year ago too!

You could have jumped in the discussion then, beta4 was at any point functional and that's why there was no 2.x release and instead I released beta5.

You've got a ton of suggestions here and in the doc page to fix the problem, normally related with reference fields not present, if someone wants to provide a solution similar to Commerce Repair, it will be greatly appreciated.

pcambra’s picture

Status: Active » Fixed

This has been inactive enough time, we've got documentation and options to solve all this issues, closing this one.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.