Closed (fixed)
Project:
Commerce coupon fixed amount
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
13 Apr 2012 at 15:13 UTC
Updated:
4 Jan 2014 at 01:39 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
pcambraOops, that was a typo I pushed, the coupon type is called commerce_coupon_fixed
Fixed now, many thanks for testing all this.
Comment #2
roam2345 commentedstill does not work.....
its fine if the page is not reloaded, add a coupon then reload that page again... gets zero'ed.
Comment #3
mrfelton commentedSeeing the same problem.
Comment #4
pcambraStrange, I can't reproduce this, could you make sure you've got the rules related to the fixed amount reverted and the cache cleared?
Are these the steps to reproduce it?
Comment #5
mrfelton commentedSo,
many hours later...
In our setup (where the commerce_coupon rules are in their default state) fixed price discounts simply did not get applied at all. The attached patch fixes the issue, although I have some questions about the specific of the implementation. The biggest question is wether we should really be using hook_commerce_cart_line_item_refresh() or hook_commerce_cart_order_refresh to handle the updating. I suspect the ater, although we only managed to get it working use the line item refresh hook. In order to make this work, we needed to use a simple static cache to ensure that each coupon would only be applied to the order once.
In any case it works in a very similar way as the percent based discounts, and we looks to be working well for us even with our own custom coupon block that enables coupons to be applied on the cart form as opposed to the checkout page.
Comment #6
pcambraI don't really think this is the solution to it.
hook_commerce_cart_line_item_refresh is invoked once for each line item of a cart state order, so there's no point of looping all, that would be something you do in hook_commerce_cart_order_refresh.
Then calls like these wouldn't be needed.
$commerce_coupon_fixed_amount_applied_coupons = &drupal_static(__FUNCTION__);I don't really see a change in the roots of the code here, basically on hook_commerce_cart_line_item_refresh, checks if the line item type is a coupon (that only works for fixed amount coupons) and if so, it applies it.
What you do change is the coupon log update, that is completely removed, and that's the piece of code that is failing for you as I've understood.
With your code, if there's a change in the coupon, log is never updated.
Comment #7
roam2345 commented@pcambra the current function checks that the line item is of the type "commerce_coupon" which never is TRUE in its current incarnation, and the refresh never happens to the cart. All though this needs work it does update the coupon fixed coupon amounts.
Also have noticed that commerce_coupon_code is used for the component name.
$price_component_name = $coupon->type . '_' . $coupon_wrapper->commerce_coupon_code->value();There is no clean up of that code that may have white space, etc.. not sure if this gonna cause issues?
Comment #8
roam2345 commentedAttached is a reroll that updates the log as well.
Comment #9
pcambraI'd say that the patch wouldn't apply as it seems is taken from the 1...
I don't see why this is not true, the line item type is always "commerce_coupon" for coupons.
That's probably true, we could use the coupon id, but probably we're going to need a coupon label at some point, I'm open to discussion about this.
Comment #10
roam2345 commentedBut when you put a dsm() on $cloned_line_item and $coupon to look at their types.... they are always the line items never the coupons?
Comment #11
mrfelton commentedAgreed, the line item that gets passed in to $cloned_line_item is never a commerce_coupon type. Hense why previously the code did absolutely nothing.
Comment #12
pcambraMarking as needs more info as I'm not being able to reproduce this at all, line item type for producs is normally "product", for shipping items is going to be "shipping" and for coupons of fixed amount, "commerce_coupon", you may get "coupon" in older -devs from commerce coupon "core", but definitely not "line item" type line items.
I'm probably getting just pieces of the debug you're doing, I'm going to need much more information to be able to track and fix (if needed) this.
Comment #13
pcambraA copy of that dsm result would be a good start.
Comment #14
roam2345 commentedHere is a dsm result.
Comment #15
roam2345 commentedNot sure what other modules use to build there machine names is there no generic function that deals with that for us?
Comment #16
mrfelton commented@pcambra It seems that the rule that adds the coupon line item to the cart isn't firing correctly on our site - so there is never a commerce_coupon line item type, which would explain the behavior we are seeing. See this screenshot that shows the broken rule: http://cl.ly/1R2D1U1b3J0e0O0J181S
It seems to be failing because it can't find a coupon_reference field. I see that there is a new field type called Coupon Reference, but have no idea what its for, what entity it needs to go on, what is supposed to reference what. Clearly I'm missing some fundamental aspect of how this module is suposed to be used! I'm also confused as to how the % based coupons work, but the fixed price ones dont. I don't have coupon_reference fields on either of the coupon types (fixed or pct), or on any of my products.
Comment #17
pcambraOk, this is starting to make sense, I think we're looking at the wrong place then.
The field coupon reference is created in the line item type coupon, you can see your line item types at
admin/commerce/config/line-items. You should see there the coupon type that should have more or less this look: https://skitch.com/pcambra/8w84u/coupon-commerce-kickstartIf you haven't got this, you've got a problem with your commerce coupon install, as this structure is created on install by commerce_coupon_configure_line_item that commerce invokes when creating the line item type.
Comment #18
roam2345 commentedYup mine does not look like that, http://cl.ly/1x1Q3F0K0P3r312z2l3H and http://cl.ly/0A3i0b2I2V2c2h2n3F03
Comment #19
pcambraI think we've got the problem, not sure how to reproduce though, as if you install from scratch commerce kickstart + commerce coupons "suite", you get the right fields (it'd be useful if you could try that).
What I've would do is to invoke commerce_coupon_configure_line_item manually (be careful with this, I'd do it in a sandbox first) and then you're going to update your ongoing carts (not sure if you're live yet) to get the proper information in the line item.
Comment #20
pcambraBy the way, just commited a machine name feature in both coupon, fixed and pct modules
Comment #21
roam2345 commentedSo I have run commerce_coupon_configure_line_item in a sandbox that ran and added a commerce_coupon_reference to the coupon line item entity. But once I now add a fixed coupon to the cart I get this wonderful ditty.
EntityMetadataWrapperException: Unable to get the data property data as the parent data structure is not set. in EntityStructureWrapper->getPropertyValue() (line 442 of /Users/jucallme/Sites/systemseed/ks_profile/new/build/profiles/ks/modules/contrib/entity/includes/entity.wrapper.inc).
running this get me the site back.. but as soon as i add a coupon again it fries.
Comment #22
pcambraThat's normally being called when getting the property value of an entity, see:
http://drupalcontrib.org/api/drupal/contributions%21entity%21includes%21...
Wondering if we're using "data" property at all in coupons. I'm thinking that's an heritage copy-paste from orders entity type since the beginning. Need to review that.
I think it's better to run the configure line item thing without any coupon in any cart for avoiding issues like this.
Need to work in the uninstall issues as you're probably in need of a reinstall of the coupon suite due those structural issues. Anyways, the configure line item on install has been there from moment 0 I'd say, so it's a really odd problem.
Comment #23
davidwhthomas commentedI had a similar issue when updating to the latest dev versions, I lost the 'commerce_coupon_reference' and other fields on the coupon line item type, resulting in errors creating that line item for fixed amount coupons.
I used an update hook to ensure the fields were set again on the coupon line item type.
After that, I could use the fixed amount coupon type normally.
Quite lengthy update code to ensure the line item fields were all set, but it worked.
Update code currently is:
HTH,
DT
P.S @pcambra, thanks for your hard work on this project, I like the direction it's taking. cheers.
Comment #24
pcambraClosing this, please open new issues with specific problems, bear in mind that we have now an issue to track update problems to beta5