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.
It would be nice to be able to use the shipping address as a condition on the order entity as well. For example Payment methods could be restricted using this. This was my use case since we don't want to have a manual "Invoice" payment method available globally, but only in the orgin country.
Comment | File | Size | Author |
---|---|---|---|
#11 | 3067035-11.patch | 10.99 KB | jsacksick |
|
Comments
Comment #2
Lukas von BlarerHere is a first patch.
Currently the condition can only take the first shipment into account.
Comment #3
flocondetoileattached the same patch with some small improvements:
- removed unused declarations
- typo fix about $order vs $shipment
- prevent a fatal error if order's shipments are empty.
Comment #4
dwkitchen CreditAttribution: dwkitchen at Centarro for Liip commentedUpdating to align with #3170419: Move all Shipping Conditions to the Shipping Category
Needs test before acceptance - can probably be replicated from
commerce/modules/order/tests/src/Unit/Plugin/Commerce/Condition/OrderBillingAddressTest.php
Comment #5
khiminrm CreditAttribution: khiminrm at Centarro commentedAdded tests.
Comment #6
khiminrm CreditAttribution: khiminrm at Centarro commentedadded missed ShipmentAddressOrder.php file in #5
Comment #7
khiminrm CreditAttribution: khiminrm at Centarro commentedComment #8
jsacksick CreditAttribution: jsacksick at Centarro commentedI've been thinking about this... And actually, we could provide this from Commerce directly.
The problem is, we already have a condition for the shipment, that adds a "Shipping address" condition under the "Customer" category (which means, on the shipping methods admin, we'll end up with a duplicate "Shipping address" condition.
Commerce could offer an OrderShippingAddress plugin (or eventually reuse the same plugin for both the billing & the shipping address, using a deriver.
Commerce has a
collectProfiles()
method on orders, that is what we should be using, and not get the address from the first shipment.Comment #9
jsacksick CreditAttribution: jsacksick at Centarro commentedComment #10
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedSo I better understand the "Shipping address" condition under Customer applies to the billing address?
Without the patch I get the following:
I am currently trying to restrict to a zip code.
If the billing zipcode that I enter is in the allowed zip code but the shipping zip code is not in the allowed, shipping is still allowed.
Comment #11
jsacksick CreditAttribution: jsacksick at Centarro commentedI worked on the new condition. The problem is... I'm no longer sur why we actually need this :), since the Commerce shipping module provides a condition already?
Comment #12
jsacksick CreditAttribution: jsacksick at Centarro commentedRefreshed my memory, commerce_shipping provides a condition that works for shipments.
Comment #13
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedUnder customer there is a shipping address condition.
Is that shipping condition applied to a customer, a person who has already purchased and has a saved shipping address on file? Can it be applied to anonymous users?
I do not know enough about the Customer shipping condition to know why this patch is needed. Or why the current customer shipping condition cannot provide a solution to what the person who posted this issue wanted.
Can anyone provide a little more guidance?
Comment #15
jsacksick CreditAttribution: jsacksick at Centarro commentedWent ahead and committed the patch.