定制 mhinspeya/module-create-email-variables 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mhinspeya/module-create-email-variables

Composer 安装命令:

composer require mhinspeya/module-create-email-variables

包简介

Injects custom shipping-method variables (is_pickup / is_shipment) into Magento order, invoice, and credit memo email templates.

README 文档

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:

VariableValueDescription
is_pickup1Set when the shipping method is instore_pickup
is_shipment1Set 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

RequirementVersion
Magento Open Source / Adobe Commerce2.4.8
PHP8.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

  1. Copy the module directory into app/code/MHinspeya/CreateEmailVariables/.
  2. 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

EventObserver Class
email_order_set_template_vars_beforeObserverAddVariablesToOrder
email_invoice_set_template_vars_beforeObserverAddVariablesToInvoice
email_creditmemo_set_template_vars_beforeObserverAddVariablesToCreditmemo

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.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2026-06-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固