maxcode / module-tracking-links
EN: Sends customers to the carrier's own tracking page from the shipment e-mail and the tracking page of a Magento 2 store, even when the tracking number was entered by hand. FR : Envoie les clients vers la page de suivi du transporteur depuis l'e-mail d'expédition et la page de suivi d'une boutique
Package info
github.com/eBusiness360/module-tracking-links
Type:magento2-module
pkg:composer/maxcode/module-tracking-links
Requires
- php: ~8.2.0||~8.3.0||~8.4.0
- magento/framework: ^103.0
- magento/module-config: *
- magento/module-sales: *
- magento/module-shipping: *
- magento/module-store: *
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
English · Français
Maxcode Tracking Links for Magento 2
Send customers to the carrier's own tracking page, even when the tracking number was typed by hand. Free, no core override, a few lines of configuration.
The problem
When a shipment is created with a carrier that Magento does not know (a "custom" carrier: the carrier name and the tracking number are typed by hand), Magento has nothing to link to. The shipment e-mail sends the customer to a page that only repeats the carrier name and the number, and in the customer account the number is shown as plain text.
What it does
- Shipment e-mail: the "tracking number" link goes straight to the carrier's tracking page.
- Tracking page (
shipping/tracking/popup, also reached from older e-mails): a Track my parcel at … button above the details. - Customer account and guest order view > Shipments: the tracking number becomes a link, with an optional hint such as enter the delivery postcode.
- One table of carriers in the configuration: the name to look for, the address with
{number}(and{postcode}), an optional number format, an optional message. Set per default, website or store view. Presets for GEODIS, GLS and Chronopost. - Safe fallback: no matching line, or a number that does not match the format, and the customer keeps Magento's own tracking page. Nothing breaks.
- Checked on save: the address must be http(s) and contain
{number}; the regular expression must be valid. - No core override, no JavaScript, no CSS of its own on the storefront (see For developers).
- Translated into English and French. Unit tests included.
Installation
composer require maxcode/module-tracking-links bin/magento module:enable Maxcode_TrackingLinks bin/magento setup:upgrade bin/magento setup:di:compile bin/magento setup:static-content:deploy -f bin/magento cache:flush
The static content step is only for the small stylesheet of the admin table.
Requirements: Magento Open Source or Adobe Commerce 2.4.x, PHP 8.2 or later. Tested on Magento Open Source 2.4.8-p5 with PHP 8.4.
Configuration
Go to Stores > Configuration > Sales > Shipping Settings > Tracking links. One row per carrier:
| Column | Role |
|---|---|
| Name | text looked for in the carrier title of the shipment (case ignored) |
| Button name | label shown to the customer ("Track my parcel at GLS") |
| URL | tracking address; {number} is replaced by the tracking number, {postcode} by the delivery postcode |
| Number format | optional regular expression; a number that does not match falls back to the Magento tracking page |
| Message | optional hint, for example Enter the delivery postcode on the carrier page |
The first row whose name is contained in the carrier title (and whose number format matches, if given) is used.
Good to know. Carriers that ask for the postcode (GEODIS, for instance) do not take it in the address: the customer types it on the carrier page. Use the message to say so. Addresses of carrier tracking pages are not under the module's control: check them from time to time.
For developers
| Piece | Role |
|---|---|
Model/LinkResolver |
picks the row for a carrier title and number, builds the address |
Model/TrackLinkProvider |
gives the link of a Magento track (title, carrier, delivery postcode, store view) |
Plugin/EmailTrackingUrl |
afterGetUrl on Magento\Sales\Block\DataProviders\Email\Shipment\TrackingUrl (shipment e-mail link) |
view/frontend/layout/shipping_tracking_popup.xml |
the button, in front of the tracking details |
view/frontend/templates/shipping/items.phtml |
the account shipments list, attached to the block shipment_items by sales_order_shipment and sales_guest_shipment |
No CSS of its own on the storefront. The module uses Magento's native classes (action track,
action primary, order-tracking, actions-toolbar, table-wrapper…) and adds optional hooks:
.maxcode-tracking-link (the tracking number link), .maxcode-tracking-links__hint (the hint) and
.maxcode-tracking-links__button (the button on the tracking page). Whatever your theme does for the
native classes applies; style the hooks only to differ. Only the admin table has a stylesheet.
Copied template. items.phtml is a copy of Magento_Shipping::items.phtml. If your theme or another
module overrides the same block template, theirs wins and the link will not appear in the account:
merge the few lines that differ (the isCustom() branch and the links) into yours. After a Magento
upgrade, compare the copy with the new core template.
Themes without RequireJS (Breeze). Magento opens "Track this shipment", "Track all shipments" and "Track
your order" in a window with its popupWindow widget. Breeze does not provide it, so those links
(href="#") do nothing. The template of this module uses real links (target="_blank") for the ones it
owns; the two others come from Magento_Shipping::tracking/link.phtml, which a Breeze theme should override
the same way.
E-mail. The tracking number link of the shipment e-mail is rewritten without touching the template. To
also show the hint (for example the postcode to type), read the block argument maxcode_tracking_links in
your Magento_Sales::email/shipment/track.phtml.
To stop using the module, run bin/magento module:disable Maxcode_TrackingLinks: Magento's own pages and
links come back. Nothing is written to the database apart from the configuration.
Changelog
See CHANGELOG.md.
License and support
Free for any number of Magento installations that you own or operate. You receive the full source code and may adapt it to your needs; redistribution is not allowed. See LICENSE (free-module EULA).
Provided as is, without support or update commitment. For questions and paid services: ebusiness360.fr.