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

WooCommerce订单分析页归因统计渲染异常问题求助

问题概述
  • 需求:修改analytics-report-orders.js文件,覆盖WooCommerce的Analytics/Orders页面,展示所有订单归因的汇总数据。
  • 初始方案局限:从Rows获取数据受每页25条限制,getSummary仅能返回25条订单归因,因此改为在getRowsContent中统计归因信息。
  • 当前核心问题:数据统计与渲染同步冲突——读取并添加数据到列表的同时执行渲染操作无法生效,在getRowsContent的return内打印日志能看到更新后的列表,但无法同步渲染当前数据。

相关代码

constructor (){... , this.attributionCounts= {};this.processedOrderIds = new Set();}
getRowsContent(e) {
    const { query: t } = this.props,
        o = (0, d.getPersistedQuery)(t),
        c = (0, b.O3)("dateFormat", _.defaultTableDateFormat),
        { render: a, getCurrencyConfig: s } = this.context;
    this.attributionCounts = {};
    this.processedOrderIds = new Set();

    for (const order of e.slice(0, t.per_page)) {
        const {
            order_id: p,
            net_total: m,
            extended_info: v = {}
        } = order,
            { attribution } = v;

        if (attribution && attribution.origin && !this.processedOrderIds.has(p)) {
            const origin = attribution.origin;
            if (!this.attributionCounts[origin]) {
                this.attributionCounts[origin] = { count: 0, total: 0 };
            }
            this.attributionCounts[origin].count += 1;
            this.attributionCounts[origin].total += m;
            this.processedOrderIds.add(p);
        }
    }

    return (0, m.map)(e, (e) => {
        const {
            currency: t,
            date: n,
            net_total: m,
            num_items_sold: _,
            order_id: p,
            order_number: w,
            parent_id: h,
            status: f,
            customer_type: y,
        } = e,
            v = e.extended_info || {},
            { coupons: g, customer: S, products: C } = v,
            x = C.sort((e, t) => t.quantity - e.quantity).map((e) => ({
                label: e.name,
                quantity: e.quantity,
                href: (0, d.getNewPath)(o, "/analytics/products", {
                    filter: "single_product",
                    products: e.id,
                }),
            })),
            k = g.map((e) => ({
                label: e.code,
                href: (0, d.getNewPath)(o, "/analytics/coupons", {
                    filter: "single_coupon",
                    coupons: e.id,
                }),
            }));
        
        return [...];

        var E;
    });
}
getSummary(e) {
    const {
        orders_count: t = 0,
        total_customers: o = 0,
        products: r = 0,
        num_items_sold: c = 0,
        coupons_count: a = 0,
        net_revenue: s = 0,
        attribution = this.attributionCounts
    } = e,

        { formatAmount: n, getCurrencyConfig: m } = this.context,
        i = m();
    const attributionSummary = Object.keys(this.attributionCounts).map(origin => {
        const { count, total } = this.attributionCounts[origin];
        return {
            label: `R$ ${total.toFixed(2)}`,
            value: `${origin} (${count})`,
        };
    });


    const summary = [consts on "e"];
    return [...summary, ...attributionSummary];
}
render() {
    const { query: e, filters: t, advancedFilters: o } = this.props;
    return (0, r.createElement)(w.Z, {
        endpoint: "orders",
        getHeadersContent: this.getHeadersContent,
        getRowsContent: this.getRowsContent,
        getSummary: this.getSummary,
        summaryFields: [
            "orders_count",
            "total_customers",
            "products",
            "num_items_sold",
            "coupons_count",
            "net_revenue",
            
        ],
        query: e,
        tableQuery: { extended_info: !0 },
        title: (0, l.__)("Orders", "woocommerce"),
        columnPrefsKey: "orders_report_columns",
        filters: t,
        advancedFilters: o,
    });
}

内容的提问来源于stack exchange,提问作者Matheus Padilha

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 08:57:13