Needs work
Project:
Commerce Discount
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
27 May 2015 at 21:07 UTC
Updated:
19 Mar 2018 at 15:00 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
adamgerthel commentedComment #2
joelpittetIt doesn't need to know which discount?
Comment #3
adamgerthel commentedGood question. Not in my use case (see #2496085: Deny coupon if discount is applied) but maybe for others. Hmm.. I guess it could be useful for determining which discount/coupon is the best, but that's extremely complicated since you can add free products etc. It'll be hard to programmatically find our which is most valued by the customer. Or did you have something else in mind?
Comment #4
joelpittetWas thinking leave yours as default but provide an optional list parameter for discount references to check for?
It could be more complicated granted but that may cover off a few more use-cases, eh?
Comment #5
joelpittetComment #6
joelpittetI've turned on the automated testing so we should probably add tests once the feature is decided.
Comment #7
adamgerthel commentedI've never written a test, that'll be interesting :)
I can add an optional discount list but calculating the most beneficial discount is way over my league, and in my opinion a bit more than what this issue/feature is for isn't it?
Comment #8
joelpittet"Most beneficial discount" is totally out of scope but interesting.
Tests aren't to hard there are lots of tests you can rip off in there already. Maybe give it a try and if you want just pseudo code the test and I can try and help write one.
Comment #9
adamgerthel commentedUpdated patch with support for product discounts. Apparently only order discounts get referenced by
commerce_discounts. The condition now also loops through all price components and searches for discount components.No tests have been added yet.
Comment #10
joelpittetNit: needs a comma at the end of each array item on it's own line. Coding Standards
Is there any case where this check wouldn't suffice on it's own? And if not, do we also need to check each line item's components as well then?
NIT: true to TRUE and false to FALSE for coding standards.
NIT: 'und' needs to be LANGUAGE_NONE constant please.
That's an interesting approach:) We've mostly been looping the components for this kind of check.
And lastly, this could totally use a test or two to make sure it's working and keeps working but I do like the idea and willing to commit it as I've heard this requested before regarding coupons.
Comment #11
adamgerthel commentedUpdated patch with fixes from #10:
Still no tests, I guess I need some starting point as to how to write one.
Comment #12
adamgerthel commentedComment #13
mglamanJust a thought, why not:
strpos($value['name'], 'discount|') !== FALSEAlso, not sure how we could test the Rules integration, beyond forcing this file to be included and manually testing the function?
Comment #14
goz commentedMay be https://www.drupal.org/project/commerce_discount_cumulative could help you ?
It's built from another way. You do not define a condition : "Do not apply if another discount is already applied", but add cumulative option to each discount, so "Do not apply another discount after this discount", or "Remove other discounts, and only take this one".
If you really want "Do not apply if another discount is already applied", may be cumulative module can be updated to take care of this.
Comment #15
adamgerthel commented@Goz interesting approach and def. useful. But how would it be used to prevent discounts and coupons from being combined?
And - wouldn't the changes in this issue's patch be useful to your module?
Comment #16
goz commentedDo you really needs to put condition on coupon and not on discount ?
To my point of view, coupon is used to activate a discount, and it's the discount which should be configured to not be applied if another discount is used.
I think there is an issue in the way you are solving this issue right now. Each time cart is rebuilt, discounts are reseted and applied again, ordered by the rules weight.
* Create discount A + coupon with : "Do not apply if another discount is already applied" condition
* Create a discount B
If you apply coupon on your cart, i think both discounts will apply since discount B is created before discount A.
I create a module : https://www.drupal.org/project/commerce_discount_weight to handle discounts weight in discount edit form.
With commerce discount cumulative, you can only use 3 ways (also based on discount weight) :
* Allow to apply discounts after this discount
* Do not apply other discounts after this one (but keep previous)
* Do not apply other discounts after this one and remove previous
So, does adding "Do not apply this discount if another discount is already applied" option on discount (linked to you coupon) can match and solve your case ?
Comment #17
adamgerthel commentedHave you tried my implementation? I use it when the user tries to add a coupon code in the checkout process. It def. should work even if there are multiple discounts added already. What I did in my use case is that I disallow the coupon and notify the users that he/she couldn't add the coupon because there's already a discount on the order.
In either case, this issue is not necessarily about preventing multiple discounts, it's used in order to see if an order is discounted. That's something that could be used in many different scenarios.
Comment #18
rszrama commentedPlease check out #2496051: Add rules condition that checks if order has discount and the API function it adds, commerce_discount_get_discounts_applied_to_price(). This inspects any price field to determine what discount related price components it contains. One thing it will not do is let you differentiate between discounts applied to an order vs. a product, but a condition based on this function could.
(Note: the reason I took that route instead of depending on the commerce_discounts field is because product level discounts still needed to be able to specify incompatibility with order level discounts.)
@AdamGerthel, the compatibility system alone may satisfy your initial requirements, regardless of whether or not we had a standalone condition for determining if an order was already discounted. Give it a whirl! : )
Comment #19
torgospizza@rszrama: Your link is one back to this issue :)
Comment #20
rszrama commentedlol, I do that all the time. : P
Correct link: #2557119: Allow discounts to indicate compatibility with other discounts
Comment #21
adamgerthel commented@GoZ:
I see, I'm actually using v1 of Commerce Coupon so there's no connection there between discounts and coupons.
@rszrama:
Your patch looks useful, but how would it be used in my use-case in regards to coupons? Even if I were using v2 of Commerce Coupon, it's still possible to have coupons that have no relation at all to any discount.
The way I see it is this: Most real life coupons have a small text on them that say something like "Cannot be used in combination with other offers". And that's basically what I've created.
Now - if we go back to where this whole issue started, then that's only one use case for this Rules condition. I'm sure there could be others as well though. Rules compatibility is always useful.
Comment #22
rszrama commentedI'm not sure what you mean. In the latest version of Discount / Coupon, coupons and discounts are always tied together. You even create coupon codes using IEF in the discount add / edit form. I can't imagine there will be any work on branches that aren't the latest branch at this point in time.
Comment #23
adamgerthel commented@rsrama This patch is for Commerce Discount and not for Commerce Coupon, so I didn't consider that, and I didn't know that v2 of Discount had changed that much.
Comment #24
rszrama commentedAhh, yeah, no worries. I was imprecise in my comment - Commerce Coupon 2.x is the latest version that should be used over 1.x, and it works with the latest release of Commerce Discount 1.x as I described above. I'll be working to get maintainer access on the Commerce Coupon project to fix up the messaging and recommended version ASAP.
Comment #25
mbatterton commented#11 Patch works really well (thank you @AdamGerthel) until we updated the module. Is there any chance of rolling this into the next version of comerce Comerce Discounts for D7.