Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
As soon as a condition is set on a shipping rate, it no longer appears in checkout, no matter what the option is. Tried setting condition to be greater or less than a certain weight, store, etc. and it never appears as an option on shipping page.
Using flat rate shipping options
Commerce 2.0
Drupal 8.4
No messages in log pertaining to this.
Comment | File | Size | Author |
---|---|---|---|
#9 | 2917519-shipping-weight-conditions-not-working-9.patch | 422 bytes | Mirroar |
#6 | commerce_shipping-recalculate_shipping_weight-2917519-6-d8.patch | 462 bytes | mortona2k |
Comments
Comment #2
jasonschweb CreditAttribution: jasonschweb commentedComment #3
mortona2k CreditAttribution: mortona2k commentedThe order price condition seems to work, but order weight isn't working for me.
Comment #4
smartparty CreditAttribution: smartparty commentedHaving the same issue and I've noticed that in ShipmentWeight.php under
public function evaluate(EntityInterface $entity) {
the weight value is empty.If you manually define the weight for the purpose of debugging (i.e.
$weight = new Weight(999, 'g');
) then it works correctly.Comment #5
l_v CreditAttribution: l_v commentedI've same issue: weight condition doesn't work.
Also trying to dump $this->get('weight')->first() al line 244 in Drupal\commerce_shipping\Entity\Shipment return null.
Comment #6
mortona2k CreditAttribution: mortona2k commentedHere's a quick fix that recalculates the weight if empty.
There will be issues if !$this->get('weight')->isEmpty() fails to return true after calling recalculateWeight().
I changed the title to Shipping weight conditions.. hope this is ok.
Comment #7
smartparty CreditAttribution: smartparty commentedDidn't see the wood for the trees with the recalculateWeight function. Thank you, works for me as an easy fix for now.
Comment #8
l_v CreditAttribution: l_v commentedIt seems to works for me too, thank you
Comment #9
Mirroar CreditAttribution: Mirroar at werk21 commentedI've just spent a large amount debugging this problem, and got to the conclusion that the problem is in
Shipment::populateFromProposedShipment()
. The PackerManager uses that function to populate its shipment entities, and since that function just directly sets the shipment items instead of usingShipment::setItems()
. This means that the shipment's weight is never calculated, even though the items are added.I feel it's cleaner to add the call to
Shipment::recalculateWeight()
at that point rather than in getWeight, and it fixes the issue just as well, so I attached a new patch that does that. I guess we still need a test for this, nonetheless.Comment #10
pushhockey CreditAttribution: pushhockey commentedHi Guys,
I have the same issue with weights, thought it was something i had done wrong. Now, my problem is how to apply the patch using composer or manually as i haven't done this before. I have done a google search and read a load of stuff, that, quite frankly is above my paygrade! I feel i need to download cweagans but not sure where to put the file? Then hopefully I can follow the instructions here http://www.anexusit.com/blog/how-to-apply-patches-drupal-8-composer - however there is so much misinformation out there at the moment I wondered if someone could walk me through the steps.
Many thanks for the patch @Mirroar
Comment #11
mortona2k CreditAttribution: mortona2k commented@pushhockey I'd encourage you to look elsewhere instead of asking in this thread. However, what you want to do is add cweagans/composer-patches to your composer file, and add the patch in extra: patches. When you run composer install, you should get composer patches and the patch installed. See the usage example here: https://github.com/cweagans/composer-patches/blob/master/README.md
Comment #12
bojanz CreditAttribution: bojanz at Centarro commentedThank you Mirroar for tracking this down!
Adding a test and and some cleanup.
Comment #14
bojanz CreditAttribution: bojanz at Centarro commentedDone.
Comment #16
Marco van Bemmel CreditAttribution: Marco van Bemmel at Straf Werk commentedWow, mortona2k and Mirroar, thank you so much for these patches. After three years this seems te be an issue again?
I use this module (8.x-2.0-rc2 and/or dev version of 17 march 2021) in combination with Commerce Shipping Weight Tariff, but the shipping-cost based on weight still did not work correctly. After applying patch # 6 and # 9 it all seems to work correct now!
Is there a reason why this piece of code is not added to the module anymore?