Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Update the Stores field definition for promotions to allow users to specify "all stores" by not selecting any specific stores. When loading available promotions, promotions for "all stores" will be available in all stores.
Essentially, we are changing the definition of the stores field for promotions from a list of stores for which the promotion is valid to a limiting condition.
From:
The stores for which the promotion is valid.
To:
Limit promotion availability to selected stores.
Comment | File | Size | Author |
---|---|---|---|
#26 | 3006403-26.patch | 10.42 KB | jsacksick |
| |||
#22 | interdiff_21-22.txt | 1.01 KB | jsacksick |
#22 | 3006403-22.patch | 10.42 KB | jsacksick |
| |||
#20 | Edit_promotion.png | 13.86 KB | lisastreeter |
#20 | Add_promotion.png | 19.93 KB | lisastreeter |
Comments
Comment #2
lisastreeter CreditAttribution: lisastreeter at Centarro commentedComment #3
lisastreeter CreditAttribution: lisastreeter at Centarro commentedComment #4
mglamanWe don't need to invoke the field definition manager.
We could just do something like this
We really just need the entity field definition cache to be rebuilt
Comment #5
lisastreeter CreditAttribution: lisastreeter at Centarro commentedUpdated the patch to remove the field definition update.
Comment #6
lisastreeter CreditAttribution: lisastreeter at Centarro commentedCurrent patch does not work for promotions with coupons. Didn't realize there was separate availability logic for promotions with coupons vs. promotions without. Working on a fix to the logic plus test coverage now.
Comment #7
lisastreeter CreditAttribution: lisastreeter at Centarro commentedUpdated the logic in Promotion::available() method for all stores option. Added test coverage to CouponTest and PromotionAvailabilityTest.
Comment #8
lisastreeter CreditAttribution: lisastreeter at Centarro commentedComment #9
lisastreeter CreditAttribution: lisastreeter at Centarro for E.C. Barton & Co commentedRerolled patch.
Comment #10
lisastreeter CreditAttribution: lisastreeter at Centarro for E.C. Barton & Co commentedRerolled patch again
Comment #11
jsacksick CreditAttribution: jsacksick at Centarro commentedTwo comments:
The following
// An empty update flushes caches, forcing block_rebuild() to run.
is weird? I don't really understand what's the relationship between the empty update hook andblock_rebuild()
?Also, I'm wondering if we shouldn't hide the "stores", behind a checkbox. It's probably unclear as is whether the promotion is available to all stores, no?
Comment #12
jsacksick CreditAttribution: jsacksick at Centarro commentedShouldn't the update hook contain the following instead?
Comment #13
mglamanThere are no storage changes. Just definition updates to the label and required, which requires a field cache rebuild. So maybe we should just call that in post_update with EntityFieldManager
Comment #14
mglamanSo "Limit to specific stores", check that. Then show the entity reference. Otherwise it defaults to all stores. Kind of like specifying and end datetime?
Comment #15
jsacksick CreditAttribution: jsacksick at Centarro commentedExactly, though a bit unsure about the label itself, but I like the idea of being explicit in the UI.
Comment #16
jsacksick CreditAttribution: jsacksick at Centarro commentedAlso, posting what was discussed on Slack regarding the empty update, we probably simply need the following:
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
This is clearer and more explicit (haven't tested though).
Comment #17
jsacksick CreditAttribution: jsacksick at Centarro commentedThe attached patch addresses the previous comments.
The stores checkboxes are now hidden behind a "Limit to specific stores" checkbox.
The
EntitySelectWidget
was modified to generically support hiding the checkboxes/autocomplete behind a checkbox.The update hook simply clears the cached field definitions.
I haven't really reviewed the tests closely, focused on making these 2 changes.
This is how it looks now:
Comment #18
jsacksick CreditAttribution: jsacksick at Centarro commentedAttaching an interdiff.
Comment #19
jsacksick CreditAttribution: jsacksick at Centarro commentedI wonder if we shouldn't add a margin to the checkbox, because currently it looks like the checkbox belongs to the order types.
Comment #20
lisastreeter CreditAttribution: lisastreeter at Centarro for E.C. Barton & Co commented@jacksick Yes, I noticed the checkbox looking like an order type. I think it might be better to have the "Stores" label above the checkbox.
Also, when I went back to edit an existing promotion, the checkbox disappeared:
I deleted those stores from the text box. When I submitted the form, I got an error:
Notice: Undefined index: target_id in Drupal\commerce\Plugin\Field\FieldWidget\EntitySelectWidget->massageFormValues() (line 166 of modules/contrib/commerce/src/Plugin/Field/FieldWidget/EntitySelectWidget.php).
It did make the update, and then the checkbox reappeared.
I get the same error if I check the checkbox but then neglect to enter any stores.
Comment #21
jsacksick CreditAttribution: jsacksick at Centarro commentedThis is actually by design (copied logic used for the end date), the checkbox #access is set to FALSE whent the field has a value.
I added a margin to the checkbox, I can't really reperoduce the warning, but the attached patch should do the trick.
Instead of the margin, might be better to output the checkbox under the "Stores", but it's still bettr than it was with the margin.
Comment #22
jsacksick CreditAttribution: jsacksick at Centarro commentedThe change in
massageFormValues()
was problematic, it is fixed.Also keep the checkbox when a promotion references stores already, it feels weird to have it disapear.
Comment #23
jsacksick CreditAttribution: jsacksick at Centarro commentedRather than "Limit to specific stores", I think I'm more in favor of "Restrict to specific stores", thoughts?
Comment #24
mglaman+1 to Restrict to specific stores. Limit feels weird. Restrict is more forward.
Comment #25
lisastreeter CreditAttribution: lisastreeter at Centarro for E.C. Barton & Co commentedI agree. "Restrict to specific stores" is better.
The increased spacing between the order types and the checkbox is good, and I like that the checkbox does not disappear now. I do not mind the "Stores" after the checkbox at all now.
Also, I've tried various combinations of the checkbox, adding, deleting stores. No error messages, and all the updates worked properly.
Comment #26
jsacksick CreditAttribution: jsacksick at Centarro commentedUpdated the label, is it good to go now? RTBC? :p
Comment #28
jsacksick CreditAttribution: jsacksick at Centarro commentedWent ahead and committed the patch! Thanks everyone!!
Comment #29
mglaman🥳 beautiful, three years in the making