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.
Just like Promotions in Commerce 2.x, the shipping method config entity should embed configuration for condition plugins.
These conditions accept a shipment entity.
We should implement the following conditions to start with:
- Order total (can we reuse the one from Commerce, pass it $shipment->getOrder()? mglaman might know)
- Destination country (we can add state/province support in a followup)
Other conditions we'll want to have:
- Customer has role ($shipment->getOrder()-.getCustomer())
- Shipment weight (once we add the weight field to the shipment)
Comment | File | Size | Author |
---|---|---|---|
#21 | 2826053-21.patch | 21.24 KB | bojanz |
#15 | interdiff-2826053-9-15.txt | 498 bytes | travis-bradbury |
#15 | allow_shipping_methods-2826053-15.patch | 12.42 KB | travis-bradbury |
#14 | Capture3.PNG | 56.64 KB | SchwebDesign |
Comments
Comment #2
iajay CreditAttribution: iajay commentedAtleast when there is NO shippable product then the Shipping pane should not be visible in checkout
Or is this possible and I am missing something obvious?
Comment #3
klagler CreditAttribution: klagler commented- Total number of ordered items would also be great to have as condition.
Comment #4
bojanz CreditAttribution: bojanz at Centarro commentedThis issue can now proceed, Commerce 8.x-2.x has a new Conditions API, and it's being used on promotions and payment gateways.
Comment #5
bojanz CreditAttribution: bojanz at Centarro commentedInitial untested work. I'll come back to this after I tag beta3 of shipping.
This gives us the order total and customer role conditions. The patch would need to provide a shipment weight condition (written similar to the OrderTotalPrice condition). We can leave a "Shipping address" condition to a followup.
Comment #6
SchwebDesign CreditAttribution: SchwebDesign commentedThanks for your work on this. The order weight (shipment weight?) is our current use case for this, so just wanted to check on any status of this since beta3 was tagged. If it'd be any help, we'll be able to test this thoroughly (with weight condition) to report that it works.
In the meantime, i've added this patch and ran the Drupal update. That looks to have worked well and conditions (customer-billing address and role, and order - total price) are now showing up at:
admin/commerce/config/shipping-methods/add
Comment #7
travis-bradbury CreditAttribution: travis-bradbury at Acro Commerce commentedMy interest was in conditions on the shipping address so I added a condition for it. It's just the OrderBillingAddress from the order module with some find-and-replace.
The #5 worked as expected so I'd call this RTBC except you wanted a shipment weight condition.
Comment #8
Nathaniel CreditAttribution: Nathaniel commented#7 is working for different delivery rates for different zip codes using the shipping address.
Comment #9
travis-bradbury CreditAttribution: travis-bradbury at Acro Commerce commentedI added a shipment weight condition that's similar to the order total price one.
Comment #10
Londova CreditAttribution: Londova commentedIs it possible to add a condition based on quantity?
Comment #11
SchwebDesign CreditAttribution: SchwebDesign commented@Londova, there is a quantity condition.
Thanks so much for the shipping weight condition.
I'm getting this error after initial save of a shipping method with shipping weight condition:
Notice: Undefined index: weight in Drupal\commerce_shipping\Plugin\Commerce\Condition\ShipmentWeight->buildConfigurationForm() (line 40 of modules/contrib/commerce_shipping/src/Plugin/Commerce/Condition/ShipmentWeight.php).
Also, i'm wondering if it's feasible to allow multiple conditions of each type or a range condition.
E.g. I want to enter shipping methods for 30 different non-overlapping weight ranges and the customer's order is the lowest weight, it will show ALL shipping methods to the customer if i use the "Less than or equal to" condition. If I could ALSO add a "greater than" weight condition, the system would just show them the ONE that applies to their order, making things much more user friendly in cart.
Comment #12
SchwebDesign CreditAttribution: SchwebDesign commented@Londova, MY APOLOGIES, there is NOT a quantity condition yet. I could've sworn I saw it, but i was wrong.
Comment #13
travis-bradbury CreditAttribution: travis-bradbury at Acro Commerce commentedNeeds work per #11
Comment #14
SchwebDesign CreditAttribution: SchwebDesign commentedFWIW on further testing I also noticed the initial shipping cost shown in the cart and checkout order summary doesn't seem to follow the conditions.
In my case it shows the rate that would apply for respective weight of a quantity of 1 (although this order has 4) and yet the calculated rates are correct on the left (per my example in #11). My shipping rates only depend on shipping weight conditions... no other conditions, so it theoretically should show the correct lowest rate even in cart. See screenshot attached.
This is the output of Global: Order total (Global: Order total) in the commerce_cart_block and commerce_checkout_order_summary views, I believe. ...or is this a configuration change that needs to be made?
Not sure if this is something reconfigured or perhaps this is a side effect of the error in previous post.
Comment #15
travis-bradbury CreditAttribution: travis-bradbury at Acro Commerce commentedThis fixes the undefined index.
I'm not sure what's up with the issue you have in the screenshot. I don't think it is related to conditions. Does it happen with a brand new order?
Comment #16
SchwebDesign CreditAttribution: SchwebDesign commentedThanks. I can confirm that fixed the error in #11. That said, things behave otherwise the same as outlined above.
Yes, that happens with a brand new order. I tested (drush cr first) removing all items from cart and adding new ones to cart to start over as well logged in.
I don't mean to complicate this thread if this is not related, but to answer your question thoroughly I also then tested as anonymous user and when clicking "Recalculate shipping" got this error in the logs:
This is on Commerce 2.0.0-rc1 installed
Comment #17
AndyD328Thanks for the conditions patch.
Will it have a 'NOT' filter at some point? eg 'is NOT in 'selected countries' to make it easy to filter for international orders.
Comment #18
bojanz CreditAttribution: bojanz at Centarro commentedThere is no plan for NOT support right now. We couldn't figure out a sane UX, decided to roll without it for the immediate future.
Looked at the #15 patch. It's missing tests and schema for the two added conditions (Commerce has some that can be copied). We also need to add the condition operator field (AND/OR), like promotions have.
Comment #19
bojanz CreditAttribution: bojanz at Centarro commentedI'll try to work on some of these points tomorrow. Feel free to reroll in the meantime.
Comment #20
SchwebDesign CreditAttribution: SchwebDesign commentedThanks!
Comment #21
bojanz CreditAttribution: bojanz at Centarro commentedNext iteration.
Adds unit tests, schema. Renames ShipmentShippingAddress to ShipmentAddress. Adds condition_operator (AND/OR support).
Needs an update function for setting the condition_operator, and we're done.
Comment #22
bca-wm CreditAttribution: bca-wm commentedWould it be possible to add a condition for the order contains xxxx product type?
A use case would be having different product types physically stored at different locations, and thus needing different shipment methods/prices to the customer.
Thanks.
Comment #24
bojanz CreditAttribution: bojanz at Centarro commentedCommitted #21 + an update hook. Gave tbradbury commit credit for his work on the individual conditions.
See you in followups for the rest.
Comment #26
heddnThis was committed and not removed from the readme.txt. Was a follow-up ever opened to cleanup the readme?
Comment #27
hsponner CreditAttribution: hsponner at Freely Agency commentedI'd also appreciate the NOT condition as AndyD328 in #17, find it very usefull for international shipping with standard shipping + conditional for few defined countries.