You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Shopware6如何在前端订单概览页面实现订单状态过滤

订单状态过滤功能实现方案

现有代码问题排查

你当前代码存在两处核心错误导致过滤逻辑不生效:

  • 已提前提取订单状态到orderState变量,但判断条件错误使用了order.type(该字段存储订单类型,和状态无关)
  • 状态值in_progress未加引号,Twig会将其识别为未定义变量而非字符串常量,导致判断逻辑失效

修正后可直接使用的代码

{% block page_account_orders_overview %}
<div class="account-orders-overview">
    {% block page_account_orders_table %}
        {% block page_account_orders_table_body %}
            {% for order in page.orders %}
                {# 提取订单状态技术名 #}
                {% set orderState = order.stateMachineState.technicalName %}
                {# 正确按状态过滤,注意字符串加引号 #}
                {% if orderState == 'in_progress' %}
                <div class="table order-table"
                     data-order-detail-loader="true">
                    {% sw_include '@Storefront/storefront/page/account/quotationorder-history/quotationorder-item.html.twig' %}
                </div>
                {% endif %}
            {% endfor %}
        {% endblock %}
    {% endblock %}
</div>
{% endblock %}

扩展用法

如果需要同时过滤多个状态,可使用Twig的in运算符实现多条件匹配:

{# 同时展示处理中、待发货状态的订单 #}
{% if orderState in ['in_progress', 'shipped_pending'] %}

注:你需要确认Shopware后台配置的订单状态技术名和判断条件里的字符串完全匹配,常见默认状态技术名包括open(待处理)、in_progress(处理中)、shipped(已发货)、cancelled(已取消)、completed(已完成)。

内容的提问来源于stack exchange,提问作者babita verma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 08:36:03