mhinspeya / module-create-email-variables
Injects custom shipping-method variables (is_pickup / is_shipment) into Magento order, invoice, and credit memo email templates.
Package info
git.modehaus.de/hyvae/mhinspeya-create-email-variables
Type:magento2-module
pkg:composer/mhinspeya/module-create-email-variables
Requires
- mhinspeya/backend-mod: ^1.0
This package is not auto-updated.
Last update: 2026-06-02 12:39:03 UTC
README
A lightweight Magento 2 module that injects custom shipping-method variables into transactional email templates for orders, invoices, and credit memos.
Overview
By default, Magento email templates do not expose a simple flag to distinguish between in-store pickup and regular shipment orders. This module listens to Magento's email transport events and adds two boolean-style variables to the template transport object:
| Variable | Value | Description |
|---|---|---|
is_pickup | 1 | Set when the shipping method is instore_pickup |
is_shipment | 1 | Set for all other shipping methods |
These variables can be used directly in any transactional email template to conditionally show pickup- or shipment-specific content.
Compatibility
| Requirement | Version |
|---|---|
| Magento Open Source / Adobe Commerce | 2.4.8 |
| PHP | 8.4.x |
Installation
Via Composer (recommended)
Add the package as a local path repository in your Magento project's root composer.json:
"repositories": [
{
"type": "path",
"url": "path/to/MHinspeya/CreateEmailVariables"
}
]
Then run:
composer require mhinspeya/module-create-email-variables
bin/magento module:enable MHinspeya_CreateEmailVariables
bin/magento setup:upgrade
bin/magento cache:flush
Manual Installation
- Copy the module directory into
app/code/MHinspeya/CreateEmailVariables/. - Run the following commands from your Magento root:
bin/magento module:enable MHinspeya_CreateEmailVariables
bin/magento setup:upgrade
bin/magento cache:flush
Usage in Email Templates
Once installed, the {{var is_pickup}} and {{var is_shipment}} variables are available in the following email templates:
- Order confirmation (
email_order_set_template_vars_before) - Invoice (
email_invoice_set_template_vars_before) - Credit memo (
email_creditmemo_set_template_vars_before)
Example template snippet
{{if is_pickup}}
<p>Your order is ready for <strong>in-store pickup</strong>. Please bring your order confirmation.</p>
{{else}}
<p>Your order has been shipped. You will receive a tracking number shortly.</p>
{{/if}}
Module Structure
MHinspeya/CreateEmailVariables/
├── Observer/
│ ├── ObserverAddVariablesToOrder.php # Handles order emails
│ ├── ObserverAddVariablesToInvoice.php # Handles invoice emails
│ └── ObserverAddVariablesToCreditmemo.php # Handles credit memo emails
├── etc/
│ ├── events.xml # Event observer registrations
│ └── module.xml # Module declaration
├── composer.json
├── registration.php
└── README.md
Events Observed
| Event | Observer Class |
|---|---|
email_order_set_template_vars_before | ObserverAddVariablesToOrder |
email_invoice_set_template_vars_before | ObserverAddVariablesToInvoice |
email_creditmemo_set_template_vars_before | ObserverAddVariablesToCreditmemo |
Configuration
No additional admin configuration is required. The module works out of the box once enabled.
The shipping method key checked by default is instore_pickup. If your store uses a different shipping method code for in-store pickup, update the comparison string in the relevant observer classes:
// Observer/ObserverAddVariablesToOrder.php (line ~42)
if ($order->getShippingMethod() === 'instore_pickup') {
Development
Code Standards
This module follows Magento 2 coding standards and is compatible with PHP CodeSniffer using the Magento2 ruleset:
phpcs --standard=Magento2 --extensions=php,xml app/code/MHinspeya/CreateEmailVariables/
Running Tests
Currently no automated tests are included. Unit tests for observer logic can be added under a Test/Unit/Observer/ directory following Magento's PHPUnit conventions.
Changelog
1.0.0
- Initial release
- PHP 8.4 compatibility (
declare(strict_types=1), typed returns, strict comparisons) - Magento 2.4.8 compatibility (removed deprecated
setup_version) - Observers for order, invoice, and credit memo email events
- Composer package support
License
Proprietary — Copyright © MHinspeya. All rights reserved.