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.
Copy what commerce order is doing and send an optional shipment notification email when shipments are completed.
Comment | File | Size | Author |
---|---|---|---|
#51 | interdiff_45-51.txt | 30.44 KB | jsacksick |
#51 | 2918482-51.patch | 27.17 KB | jsacksick |
| |||
#50 | Screen Shot 2563-09-19 at 16.58.05.png | 30.37 KB | abx |
#50 | Screen Shot 2563-09-19 at 16.57.43.png | 63.32 KB | abx |
#28 | 2918482-28.patch | 17.37 KB | mglaman |
|
Comments
Comment #2
andyg5000Here's a first stab at this.
2 things need to be addressed
* Send the tracking url using tracking_code formatter if available
* Add option to enable/disable this from the shipment type config
Comment #3
andyg5000Adding items above before review :)
Comment #4
andyg5000Ready for review!
Comment #5
andyg5000Comment #6
andyg5000My tracking url (as a link) was formatted incorrectly. Can just specify {{ tracking_code }} when it's formatted as a URL object :)
Comment #7
andyg5000Properties weren't defined. Last update. Promise!
Comment #8
andyg5000Comment #9
p4trizio CreditAttribution: p4trizio at Elicos commented#7 for me is working fine
Comment #10
bojanz CreditAttribution: bojanz at Centarro commentedWe can now significantly reduce the size of this patch thanks to #3017080: Create a service for sending emails to customers.
EDIT: Here's the change record https://www.drupal.org/node/3030431
Comment #11
Nils LoewenComment #12
Nils LoewenI have changed this patch to now use commerce mail service. It is not quite reliable for me yet.
TODO: Tests need to be written to verify final email output contents.
Comment #13
Nils LoewenThe interdiff contains only the new test, which will fail because the email functionality has not yet been introduced.
Comment #15
Nils LoewenTests are failing because of a change in commerce. You can see 2 tests fail for the interdiff but only 1 for patch 13.
Comment #19
sah62 CreditAttribution: sah62 commentedPatch re-roll...
Is anyone else interested in moving this forward? I could sure use this functionality...
Comment #20
sah62 CreditAttribution: sah62 commentedWhat actually causes the email to be sent? I've patched my installation using the patch from #19 and processed an order. I edited the shipment to include the USPS tracking number, saved it, and hit "Send shipment" when done. I went back to the order and hit "Fulfill order". I didn't see any errors, but I didn't see any email - and I checked my server log, too.
Looking at the patch, it creates a subscriber for the "commerce_shipment.ship.post_transition" event. I can't find any code that dispatches that event, though. Did I miss another patch that adds code to dispatch the event, or is this something that's still needed for this patch?
Comment #21
sah62 CreditAttribution: sah62 commentedMinor update to the patch to properly center one of the tables in the twig template...
Can this be moved to "needs review"? I have it installed and it seems to be working fine.
Comment #22
99gs3 CreditAttribution: 99gs3 commentedWe've tested this patch.
Initially did not seem to work. But after reviewing that there's an option to turn this feature on in shipment type all seems to be working well.
Good job and thanks.
Comment #23
sah62 CreditAttribution: sah62 commentedI've deployed this patch on my site and it seems to be working fine.
Comment #24
3CWebDev CreditAttribution: 3CWebDev commentedThe patch is working perfectly for us. Thanks!
Comment #25
mglamanQuick review. Going to work on a reroll.
It looks like the test from #13 went missing.
The entity type manager is not used directly outside of the constructor, we don't need it as a property.
These services aren't used, it seems.
We can use formatPlural for "Item(s)"
Remove the TODO, it's fine to pass as context for anyone altering the mail. We may even want to pass the shipment as a param as well.
We do not need the extra parentheses around the condition.
Seems like the indentation is off for the file.
again, get can use formatPlural utilities
Comment #26
mglaman🙌 IntelliJ's patch tool got the last patch to apply. I made my changes per #25: added the test back, using format plural utilities, removed unused services.
Comment #27
mglamanTests need updating since we added reusable profiles. And I made a syntax whoopsies
Ope.
Comment #28
mglamanThis should fix the test and syntax.
Comment #29
mglamanThere are some phpcs items to fix on commit. I think this is ready to commit.
needs comma
Unused
Comment #30
sah62 CreditAttribution: sah62 commentedI've tested the patch from #28 on my site. It works fine.
Comment #31
Fool2 CreditAttribution: Fool2 commentedLooks good so far. A few things about this feature:
Here's some twig code I've been playing with. I'm not sure it's the right way to go, but it's how I'm overriding the template in my site.
Comment #32
mglaman31.1 good point! We should add this now versus later
32.2 we have format plural logic. That should cover the usage. Is it not for you? We're missing test coverage there as well I think.
On mobile, but worth kicking back to add the action and ensure test coverage
Comment #33
99gs3 CreditAttribution: 99gs3 commentedReceiving the following error on the latest patch.
Drupal\Component\Plugin\Exception\PluginNotFoundException: The "commerce_shipment_type" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 150 of /home/mysite/public_html/core/lib/Drupal/Core/Entity/EntityTypeManager.php).
Did I miss something on the patch?
Comment #34
99gs3 CreditAttribution: 99gs3 commentedTracked the issue down.
We had issues with updating core. We had to perform a manual update which caused commerce to be removed.
We reinstalled commerce 2.16 instead of the dev version.
Patch applied properly but is now receiving the following errors. (understandably it's likely caused by patching 2.16 instead of dev.)
Error: Call to undefined method Drupal\commerce_promotion\Plugin\Commerce\PromotionOffer\OrderPercentageOff::isDisplayInclusive() in Drupal\commerce_shipping\EventSubscriber\PromotionSubscriber->Drupal\commerce_shipping\EventSubscriber\{closure}() (line 119 of /home/mysite/public_html/modules/contrib/commerce_shipping/src/EventSubscriber/PromotionSubscriber.php)
Warning: assert(): assert($offer instanceof ShipmentPromotionOfferInterface) failed in Drupal\commerce_shipping\EventSubscriber\PromotionSubscriber->Drupal\commerce_shipping\EventSubscriber\{closure}() (line 117 of /home/mysite/public_html/modules/contrib/commerce_shipping/src/EventSubscriber/PromotionSubscriber.php)
When trying to install the dev version of commerce and commerce shipping we are now receiving dependency issues.
Problem 1
- drupal/commerce_cart 2.16.0 requires drupal/commerce 2.16.0 -> satisfiable by drupal/commerce[2.16.0] but these conflict with your requirements or minimum-stability.
- drupal/commerce_cart 2.16.0 requires drupal/commerce 2.16.0 -> satisfiable by drupal/commerce[2.16.0] but these conflict with your requirements or minimum-stability.
- drupal/commerce_cart 2.16.0 requires drupal/commerce 2.16.0 -> satisfiable by drupal/commerce[2.16.0] but these conflict with your requirements or minimum-stability.
- Installation request for drupal/commerce_cart (locked at 2.16.0) -> satisfiable by drupal/commerce_cart[2.16.0].
Is it possible to directly modify the composer.lock so we can change module and dependencies to the dev version?
Thanks
Comment #35
kaipipek CreditAttribution: kaipipek commentedIt seems that the email is always sent to anonymous user in English even when default site language is not English and the guest completed the order in another language. Is it the same issue than with order receipt here: https://www.drupal.org/project/commerce/issues/3031195
Comment #36
kaipipek CreditAttribution: kaipipek commentedThere is a bug in the provided template. Shipping item quantity is always returned as integer even when it is a decimal value. Instead of just shipping_item.getQuantity|number_format is should be something like this:
Comment #37
mglamanDecimal value quantities are non-standard. We also use number_format in the default order receipt. Any project utilizing decimal quantities will have to override this template, just like the order receipt template and any other customizations that had to be made.
Comment #38
kaipipek CreditAttribution: kaipipek commentedWhat do you mean decimal value quantities are non-standard? They are standard since Drupal 8. There is no need for additional modules like before.
Comment #39
AmeDSL CreditAttribution: AmeDSL as a volunteer commented#28 works as expected! The only problem is when you place an order as anonymous user, in that case the email come in english (instead of user preferred language). To fix this you can edit /src/EventSubscriber/ShipmentSubscriber.php from line 109 like that:
To be more clear:
Comment #40
AmeDSL CreditAttribution: AmeDSL as a volunteer commentedPatch #28 work on last RC1 release and PHP 7.3. Also work my fix for anonymous user (language) in /src/EventSubscriber/ShipmentSubscriber.php from line 109
Comment #41
AmeDSL CreditAttribution: AmeDSL as a volunteer commentedPatch #28 + language fix for anonymous user, please test it
Comment #42
AmeDSL CreditAttribution: AmeDSL as a volunteer commentedComment #43
dhruva2 CreditAttribution: dhruva2 commentedDoes this patch works with latest commerce 2.19?
Comment #44
sah62 CreditAttribution: sah62 commentedI'm using the patch from #28 with Drupal Commerce 8.x-2.20 and Commerce Shipping 8.x-2.0-rc1. It works fine.
Comment #45
longwaveThanks to everyone who's contributed to this issue, this is a super useful feature.
I have implemented the "Resend notification" button in the operations dropdown on the shipments page, as this was helpful when creating and testing a custom shipment notification email template.
I have also refactored the notification mail into its own ShipmentNotificationMail service, based on the OrderReceiptMail service.
The patch also includes the language changes from #39-41 but the interdiff is from #28.
Comment #46
sah62 CreditAttribution: sah62 commentedThe patch in #45 seems to be working for my normal workflow. The only unexpected thing I noticed was that the "Resend notification" button in the operations dropdown (thanks, this is a nice feature!) is available even when I haven't sent the shipment notification for the first time. I haven't tried to resend a notification yet.
Comment #47
dhruva2 CreditAttribution: dhruva2 commented@Sah it works perfectly for re-sending the notification.
Comment #48
99gs3 CreditAttribution: 99gs3 commentedPatch 45 with Resend notification works perfectly.
However, is it possible to also send a copy to the email addresses that were configured to receive a copy as well?
Thanks
Edit: Looking over the patch, it looks like the BCC email address were included for the new Resend notification feature. However, our tests so far does not receive any email notifications that were resent to customers.
Comment #49
longwaveThe BCC mail is only sent on the original notification, not the resend. This is the same as the order receipt functionality in Commerce Order, the BCC mail is never resent there either.
Comment #50
abx CreditAttribution: abx commentedJust tested it with current dev and it works great. After patched, I need to go into Shipment Type setting to enable " Send customer an email confirmation when shipped" so that the email will automatically send to customer when we click on send button.
Then, we can resend the same email to customer using "Resend notification" button in the Operations.
Comment #51
jsacksick CreditAttribution: jsacksick at Centarro commentedI've been reviewing this today in preparation for the next RC release and made minor adjustments:
Comment #53
jsacksick CreditAttribution: jsacksick at Centarro commentedThanks everyone!! This is now committed!!
Comment #54
tonytheferg CreditAttribution: tonytheferg commentedDoes this support urls for tracking links to different shipping companies tracking pages like usps, ups, and FedEx?
Comment #55
sah62 CreditAttribution: sah62 commentedNo, it doesn't. The tracking code is included in the email, but the code isn't wrapped with an HTML tag to turn it into a hyperlink - and you can't just add the tag to the twig template. To make it work, you need to know which shipping company is being used so that the URL references the right service.
Comment #56
longwaveHowever, if your shipping method plugin implements
SupportsTrackingInterface
and you write thegetTrackingUrl()
method then the linked URL should be passed through to the shipping confirmation email.Comment #57
sah62 CreditAttribution: sah62 commentedThe USPS plugin appears to do both of those things, but I don't see a hyperlink in my shipment notifications. There's just the tracking code. Here's the code for the getTrackingUrl function:
Comment #59
frederico CreditAttribution: frederico commentedThanks sah62, I'll check out your solution. I appreciate you letting us know what worked for you!