能否修改Shopware订单概览列表设置以添加客户邮箱等自定义数据?
如何修改Shopware订单概览列表,添加预定义外的内容(比如客户邮箱)?
当然可以修改,给你两种可行的方案:
1. 先试试后台可视化配置(部分Shopware版本支持)
- 进Shopware后台,打开订单模块的概览页面
- 点页面右上角的「列设置」按钮(就是调整表格列的图标)
- 在弹出的面板里找「客户邮箱」相关选项,勾选后保存就能显示了
- 要是后台没这个选项,就往下看代码自定义的方法
2. 代码自定义实现(全Shopware 6.x版本通用)
方法一:通过事件订阅扩展订单数据
搞个插件(或者用现有插件),加个事件订阅器,监听OrderListLoadedEvent来把客户邮箱挂到订单数据上:
<?php namespace YourPlugin\Subscriber; use Shopware\Core\Checkout\Order\Event\OrderListLoadedEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class OrderListSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents(): array { return [ OrderListLoadedEvent::class => 'onOrderListLoaded', ]; } public function onOrderListLoaded(OrderListLoadedEvent $event): void { foreach ($event->getOrders() as $order) { $customer = $order->getCustomer(); if ($customer) { $order->addExtension('customer_email', new \Shopware\Core\Framework\Struct\Struct([ 'email' => $customer->getEmail() ])); } } } }
方法二:修改订单列表模板
在插件或主题里覆盖订单列表的Twig模板(路径:src/Resources/views/administration/component/order/list/order-list.html.twig),添上客户邮箱的列:
{# 先在表头加列 #} <th class="sw-data-grid__cell"> {{ 'customer.email'|trans }} </th> {# 再在每行数据里加对应内容 #} <td class="sw-data-grid__cell"> {% if order.extensions.customer_email %} {{ order.extensions.customer_email.email }} {% else %} {{ 'general.notAvailable'|trans }} {% endif %} </td>
方法三:用自定义字段功能曲线救国
- 进后台「设置 > 自定义字段」,建一个关联到订单实体的自定义字段
- 写个小逻辑(比如用事件)把客户邮箱同步到这个自定义字段里
- 最后在订单概览的列设置里勾选这个自定义字段,就能显示了
内容的提问来源于stack exchange,提问作者MweisSW
相关产品推荐
相关产品推荐

