Closed (fixed)
Project:
Commerce Discount
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
12 Aug 2015 at 16:31 UTC
Updated:
10 Sep 2015 at 11:24 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
rszrama commentedI settled on "Sort order" with a helpful description:
Comment #3
rszrama commentedOk, realized it was going to be much easier to just write this as a patch against Commerce Discount, because I needed to store the sort order on the discount object in order to build the default rule properly. Attached for review.
Comment #5
joelpittetDoes that relate to this at all? https://www.drupal.org/project/commerce_discount_weight
Comment #6
rszrama commentedNice. It does, this approach is just much simpler. : )
Tests failed because tests are failing, not because of the patch, right?
Comment #7
joelpittetTests weren't failing recently, I was quite sure I got them passing... but I've said that before and testbot had managed to prove me wrong(yet Travis and local still have no problem with them)
Comment #8
joelpittet@rszrama test likely failed because you've added a field but the import/export test doesn't have that in it.
Comment #9
rszrama commentedAhh, ok, I'll take a look. : )
Comment #10
rszrama commentedPatch attached with the test fix. If it passes, I'll commit, as I have another patch incoming that will depend on this one. Slap my hand if that's bad. O: )
Comment #11
joelpittetHold up, will that other module do what you need? Maybe we should consider merging them in instead of this patch?
Comment #12
joelpittetI've got a request in with @Goz here #2542362: Merge with commerce_discount
Comment #13
rszrama commentedI imagine it might, but it's rather unnecessary. Why add yet another field to the discount form to manipulate a property of the rule like this? In my opinion, the approach here is superior.
Comment #14
rszrama commentedAdditionally, I wouldn't use a textfield to set rule weights like that module does. This really deserves a numeric field and widget. I don't even see value validation in that module, nor do I see an awareness that the Rules UI, which may be used to edit a compiled rule after the fact, only supports values from -10 to 10.
Comment #15
joelpittetI'll have to take your word for it until I see review the diff, but they are trying to solve the same problem so likely if this solution is better then I'd expect it will conflict with that solution and make it no longer work regardless. Maybe you can talk to @Goz because he works in the same company as you?
Why start at 10?
From -128 to 127. Don't some some people have more than 255 discounts?
I'm guessing this -11 is because of the default 10? Or homage to spinal tap?
Most of these options in drupal are -50 to 50 it seems, but they seem to hit problems of scale if things go bigger. AKA this issue: #1007746: Reordering fails with more than 100 items in a menu Should we adjust?
Comment #16
rszrama commentedSure, I can handle internal communication, and I'm not worried about deprecating an in-development module that has minimal usage. ; )
As I mentioned above, the Rules edit form only supports weights of -10 to 10, so if we support any wider range, it will be worthless once you go to customize the rule. We start at 10 because it's roughly in the middle of the stack - for usability, instead of showing a merchant -10 to 10 on the discount form, we should them 1 to 21. I could've gone 11 so it would build to a weight of 0 for the rule, but 10 just looked nicer (and it has the side effect of ensuring Commerce Discount related pricing rules are evaluated before any others that were created with a default weight of 0 via the pricing rules UI).
I think that covers all of points 1-4.
Comment #17
goz commentedNice i'll test this patch and this differences with commerce_discount_weight.
Rules only supports 20 weights, but it's a very tiny range. Some clients use hundred, may be thousands of discount. So it can be very hard to order discounts with a 20 range.
In this case, the view in commerce_discount_weight is no more usable (it's better to have an internal ordering political than using drag&drop), so i'm not sure it's a good thing to implement it in commerce_discount.
Comment #18
joelpittetI worry because I've been punting similar issues to that module.
Dial it to 11! 0 to 20 seems nicer than blackjack. Could it default to 0(aka rules -10)? Sorry for the silly questions I don't have a picture in my head of how the rules UI works thanks for clarification on the reasoning behind 1-21 = -10 to 10.
If I understand correctly you're mapping 11 to 0 so that in the discount UI it's nicer than the rule's UI?
Comment #19
rszrama commentedYeah, in my mind, you really don't need a priority level for every single discount. It's not likely that 20+ discounts are going to apply to the same order - if so, you might want to dial the merchandising back a little on the site. : P
It's more an issue of when discounts do collide, how do we order them relative to one another. Making use of the -10 to 10 Rules weight does that for us, and it's at least as performant as core Commerce's pricing rules capabilities.
Re: 1 to 21 vs. 0 to 20, we could've gone with that and then just kept the default at 10. I just don't think non-developers are used to counting from 0 vs. counting from 1. It's all about trying to think like a n00b and programming the discount UI to meet their needs, as they're the ones we expect to use this UI anyways.
I didn't default it to the lowest weight out of the box because that's often where we do other things like convert currency or swap in a new base price (cf. Commerce Price Table). We can't prevent someone from doing that, but may as well start 'em in the middle so they know they can sort things up or down.
At the end of the day, the best UI would be drag and drop on the discounts table itself. But so long as we're tied to Rules for execution ordering and still allowing the underlying rules to be overridden, I don't think we have much recourse.
Comment #20
joelpittet@rszrama you're UI points in #19 are all well taken. Drag and Drop would be ideal and maybe we can push for that instead of a half measure?
Maybe pie in the sky(mmmm floating pie): Can the rule's weight's be floats so we can use a default weight for all discounts and sort them within that through a the drag and drop. So '10.000001', '10.000002', etc?
Also a better UI when you have more than 20 rows is something like https://www.drupal.org/project/tabledragextra Which can move things to the top instead of tired and frail scroll & drag fingers.
Comment #21
rszrama commentedI don't think it's worth pursuing in this module, to be honest. We could use whatever value we wanted in our column, but if it's not an integer or it exceeds the bounds of -10 to 10, as soon as the Rule is edited in the Rules UI, our data will mismatch.
What probably would be worth pursuing if it isn't automatic is the addition of a Views field definition to at least display / sort a View by the sort order column. I'm happy to spawn a follow-up for that if need be.
The only reason I was pushing to get just this functionality in is because #2557119: Allow discounts to indicate compatibility with other discounts will also require an update function. Wanted to dependably make it use 7006, but we can always renumber later. I didn't consider this feature too important to not use incremental improvement post commit, fwiw. ; )
Comment #22
rszrama commentedSo, I've since discovered that this module uses some magic capability of Entity API to define its Views definitions. I tested out the sort order field and it works without any additional effort. Nice!
I'm going to go ahead and commit this sucker, and we can improve it even further moving forward. I'm pretty convinced we should stick within the paradigm of the Rules weight system for now, but if a solution should ever arise to expand that module's weight capability, we can revisit this here.