Perhaps this should be put in the commerce_coupon_fixed_amount queue, however, I'm having difficultly applying any coupons to orders.

Everything up to date with latest dev, caches cleared, fields all look correct or order and line item type, rules all clear and reverted to defaults.

However, adding a coupon code via the admin order ui and via the checkout process never adds the coupon to the order.

During checkout, the following rules error is logged:

0 ms Reacting on event Redeem a coupon.
0.4 ms Evaluating conditions of rule Redeem a coupon with fixed amount.
1.443 ms Unable to get a data value. Error: Invalid data value given. Be sure it matches the required data type and format.
2.01 ms Unable to evaluate condition data_is. [edit ( /admin/config/workflow/rules/components/manage/commerce_coupon_fixed_amount_calculate_amount/edit/3 ) ]

Furthermore, looking in the database, I see when I added coupons to orders, a record was logged, e.g:

select * from field_data_commerce_coupon_order_reference LIMIT 1;

| entity_type    | bundle         | deleted | entity_id | revision_id | language | delta | commerce_coupon_order_reference_target_id | commerce_coupon_order_reference_target_type |
+----------------+----------------+---------+-----------+-------------+----------+-------+-------------------------------------------+---------------------------------------------+
| commerce_order | commerce_order |       0 |      8371 |       15484 | und      |     0 |                                         5 | commerce_coupon  

However, looking at the line item reference table, a record is added, but the coupon target_id is NULL

select * from field_data_commerce_coupon_reference LIMIT 1;

| entity_type        | bundle          | deleted | entity_id | revision_id | language | delta | commerce_coupon_reference_target_id | commerce_coupon_reference_target_type |
+--------------------+-----------------+---------+-----------+-------------+----------+-------+-------------------------------------+---------------------------------------+
| commerce_line_item | commerce_coupon |       0 |      9278 |        9278 | und      |     0 |                                NULL | commerce_coupon

Any thoughts?

thanks.

DT

Comments

Issue summary:View changes

formatting

I'm guessing it's something to do with commerce_coupon.info.inc and entity properties, maybe the fact $properties['type'] seems to be defined twice?

Actually the second one appears defined for a different property set, perhaps it's this bit:

  $properties['type'] = array(
    'type' => 'commerce_coupon_type',
    'label' => t('Type'),
    'description' => t('The human readable name of the coupon type.'),
    'setter callback' => 'entity_property_verbatim_set',
    'options list' => 'commerce_coupon_type_options_list',
    'required' => FALSE,
    'schema field' => 'type',
  );

'type' => 'commerce_coupon_type',

doesn't appear to be a valid property data type, as per http://drupal.org/node/905580

Yes, changing that to 'commerce_coupon_type' to 'text' helps, at least for percentage coupons.

  $properties['type'] = array(
    'type' => 'text',
    'label' => t('Type'),
    'description' => t('The human readable name of the coupon type.'),
    'setter callback' => 'entity_property_verbatim_set',
    'options list' => 'commerce_coupon_type_options_list',
    'required' => FALSE,
    'schema field' => 'type',
  );

For fixed amount, it errors out with a new error:

Notice: Undefined property: EntityValueWrapper::$label in commerce_coupon_line_item_new() (line 922 of .../sites/all/modules/contrib/commerce_coupon/commerce_coupon.module).

and then

[Tue May 22 16:29:22 2012] [error] [client 192.168.2.243] PHP Fatal error:  Call to a member function value() on a non-object in .../sites/all/modules/contrib/commerce_coupon/commerce_coupon.module on line 922, referer: .../checkout/9155

I guess when trying to create the line item

DT

Status:Needs review» Active

It's this bit that causes the Fatal Error:

$line_item->line_item_label = $coupon_wrapper->type->label->value() . ': ' . $coupon_wrapper->commerce_coupon_code->value();

$coupon_wrapper->type->label->value() isn't valid for some reason, changing that to e.g 'Coupon' allows fixed amount coupon to be applied.

Need to get that value correctly.

So, after this debugging, it looks like the patch needs to:

TODO

  1. Fix $properties['type']['type'] = 'commerce_coupon_type'; to use 'text' in commerce_coupon.info.inc
  2. Fix $coupon_wrapper->type->label->value() to get label correctly.

Cheers,

DT

Status:Active» Needs review
StatusFileSize
new834 bytes

Here's an initial patch for item 1, to fix entity property info in commerce_coupon.info.inc

I can work on another one for line_item_new tomorrow.

Cheers,

DT

OK, Here's the patch for Item 2,

Looks like can just use:

$coupon_wrapper->type->label()

instead of

$coupon_wrapper->type->label->value()

Please commit when possible, thanks.

Cheers,

DT

Status:Active» Needs review

I don't see anything wrong with "$coupon_wrapper->type->label->value()" it just works for me, but let's use label() instead as it's better practice.

About #1, you can specify a property to be an entity type, you can see that in action in commerce core where some properties are "commerce_order" or "commerce_product"

I added a commit today that fixes a very important issue, you should have a commerce_coupon_order_reference field at the order level, you may want to check that.

Thanks for reporting, let's keep this open to follow up.

Thanks for the update, I updated to dev earlier today and, after the other update_hook patches I submitted, had a smooth update.

The update created the commerce_coupon_order_reference field on the order ( as per first field_data_commerce_coupon_order_reference SQL query in #1 ), so that's all good.

Regarding the entity property info, I see what you mean re: entity as a data type, I wasn't expecting commerce_coupon_type to be an entity as well as commerce_coupon ( I was thinking they were bundles instead ). Nevertheless, changing the property data type to 'text' solved the related rules error for me there.

Any idea why the default property entity type (commerce_coupon_type) would have failed to evaluate the coupon type in rules, whereas 'text' evaluated fine? If so, that'd be good to fix.

It's now only that final step of adding a coupon via the admin order ui form that I need to get working then should be all good to go.
The field is there, but currently seems to be adding a coupon with no target_id in the line item reference field. Also, the autocomplete drop down always appears blank for some reason when entering a valid coupon code.. I'll look into that more tomorrow.

Thanks for your help on this useful module.

Cheers,

DT

The text vs commerce_coupon_type is odd as as soon as you change it to text everything should be broken as we're relying on type properties in a lot of places.

I'd like to track this down before tagging a beta5 (which I'd like to do as soon as possible :))

Thanks, I realized it may have been an issue with the contrib versions I was using, which were slightly behind latest stable so I updated entityreference and ctools

entityreference 7.x-1.0-rc1
ctools 7.x-1.0

I had some issues with the update, documented and fixed here: http://drupal.org/node/1423778#comment-6024276

and after that I was able to add coupons using the field on the admin order ui form!

I'll have a go reverting that entity property 'type' back to 'commerce_coupon_type' and retesting soon.

cheers,

DT

I'll have a go reverting that entity property 'type' back to 'commerce_coupon_type' and retesting soon.

woot! it worked as per default with the latest stable releases of ctools and entityreference, please disregard the patch for item 1 in #5

All working!

Thanks again pcambra, great stuff.

Shall we close this one?

Status:Needs review» Fixed

Please allow me :-)

Status:Fixed» Closed (fixed)

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

Title:Fixed amount coupon not applied.Coupon not applied. Invalid data value given during rules comparison.
Status:Closed (fixed)» Active

This issue still appears in version 7.x-1.x-dev (2012-06-22). Is it possible that davidwhthomas no longer has the issue because of the coupon he created while his patch in #5 was applied?

I am using the following:

  • Commerce Coupon Percentage 7.x-1.x-dev (2012-May-26)
  • Commerce Coupon 7.x-1.x-dev (2012-Jun-22) also tried Commerce Coupon 7.x-1.0-beta5
  • Chaos Tools 7.x-1.0
  • Entity Reference 7.x-1.0-rc3

I have uninstalled and reinstalled the modules. I have flushed all caches. I have removed and recreated the coupon. The error logs being generated are the same as in the original bug report. The symptom is that the actual coupon is not displayed, nor the amount deducted on the order review page.

Here are the logs:

rules|/checkout/47|1||Unable to get a data value. Error: Invalid data value given. Be sure it matches the required data type and format.
rules|/checkout/47|1|edit configuration|Unable to evaluate condition data_is.

Here is a quick view of the corresponding tables after trying to redeem a coupon:

mysql> select * from field_data_commerce_coupon_reference;
Empty set (0.00 sec)
mysql> select * from field_data_commerce_coupon_order_reference;
Empty set (0.00 sec)

Good afternoon.

I'm experiencing exactly the same issues and errors as per the original poster and #15.

Does anybody have any further updates?

Tried all the latest dev modules, cleared caches, flushed the db etc. All still result in the same errors.

I have a client who needs to implement coupons asap, so any advice or pointers gratefully received.

Thanks
Lates

Status:Active» Postponed (maintainer needs more info)

As I've been saying all through this issue, the commerce_coupon_type should be the correct one instead of using text.

Patch in #5 has not been applied as you can see in this same issue for the reason above.

I'd need much more information, such as the exact steps to reproduce this error and if you install latest coupon in a clean kickstart v1 you can reproduce it as well.
Using latest versions of rules, entity and ctools also is a must.

Maybe a registry rebuild also would help.

Status:Postponed (maintainer needs more info)» Needs work

I am having this problem as well. I have updated ctools, entity api, rules and commerce to the latest versions.

Upon installation, the system throws a generic page loading error when I enable either the commerce_coupon_fixed_amount or commerce_coupon_pct modules.

The website encountered an unexpected error. Please try again later.

In the message log, I see this:

PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'commerce_coupon_fixed' for column 'entity_id' at row 1: INSERT INTO {metatag} (entity_type, entity_id, data) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => commerce_coupon_type [:db_insert_placeholder_1] => commerce_coupon_fixed [:db_insert_placeholder_2] => a:0:{} ) in metatag_metatags_save() (line 228 of /var/www/[domain]/sites/all/modules/metatag/metatag.module).

My assumption is that there is a variable namespace collision going on between the coupon module and (in this case) the metatag module.

When I attempt to uninstall the module it throws this error again:

The website encountered an unexpected error. Please try again later.

So, there's no clean way to get rid of the modules once they are installed.

Status:Needs work» Postponed (maintainer needs more info)

@denvermatt that's not the same issue at all, in the module description we've informed of this issue related with upgrade problems: #1604918: Review uninstall/upgrade process from beta4 and there's also this doc page with tips and more information.

If you find some sort of collision with other module that it is possible to reproduce in a plain environment, please open a new issue for that and inform the steps to reproduce it.

Actually, the reason I ended up on this page looking for a solution is because I was also getting the exact error the OP posted. My thought was that if the entities were getting mucked up on install, that it could then cause problems further down the line when the system attempts to redeem a coupon. I don't know if it is or it isn't, but if others have the same issue, then we could look to see if this might be the cause.

More importantly would be pcambra's willingness to listen to feedback and not dismiss people's attempt to help him improve his product.

@denvermatt the logs you've pasted here have nothing to do with the original issue, I've redirected you to other docs and the upgrade issue which might be a more accurate place. In any case you can open a new issue if you feel it's not related with upgrade path either.

More importantly would be pcambra's willingness to listen to feedback and not dismiss people's attempt to help him improve his product.

Everyone is very welcome to provide feedback and of course, patches.

Issue summary:View changes

formatting