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

Zen Cart商品列表页属性价格显示问题:SQL语句修改需求

Zen Cart 商品列表页全属性价格显示调整方案

需求:让商品列表页无论商品属性是否为「仅显示/只读」,都能展示价格。当前只有标记为「仅显示/只读」的商品能显示价格,其他属性的商品无法显示价格。

原代码中,SQL语句的AND attributes_display_only != 0是控制仅查询「仅显示/只读」属性的条件,尝试移除该条件后所有价格都不再显示,解决方案如下:

问题分析

移除attributes_display_only != 0后价格全消失,大概率是两个原因:

  • 后续处理查询结果的代码中,只对attributes_display_only != 0的记录执行了价格显示逻辑
  • attributes_price_base_included=1这个条件过滤掉了非「仅显示/只读」属性的记录(这类属性的attributes_price_base_included字段值可能为0)

修改步骤

  1. 调整SQL查询条件
    将原SQL中的AND attributes_display_only != 0删除,同时根据业务需求调整attributes_price_base_included的条件:

    • 如果需要包含所有价格是否包含在基础价里的属性,将AND attributes_price_base_included=1改为AND attributes_price_base_included IN (0,1)
    • 如果业务不需要这个过滤条件,直接删除AND attributes_price_base_included=1

    修改后的SQL示例:

    $sql = "SELECT options_id, price_prefix, options_values_price,
                    attributes_display_only, attributes_price_base_included,
             CAST(CONCAT(price_prefix, options_values_price) AS decimal(15,4)) AS value
             FROM " . TABLE_PRODUCTS_ATTRIBUTES . "
             WHERE products_id = " . (int)$product_id . "
             AND attributes_price_base_included IN (0,1)
             ORDER BY options_id, value";
    $results = $db->Execute($sql);
    
    $the_options_id = 'x';
    $the_base_price = 0;
    
  2. 检查后续结果处理代码
    找到处理$results查询结果的循环代码,比如类似下面的结构:

    while (!$results->EOF) {
        if ($results->fields['attributes_display_only'] != 0) {
            // 这里是价格显示的逻辑代码
        }
        $results->MoveNext();
    }
    

    将其中的if ($results->fields['attributes_display_only'] != 0)判断删除,确保所有属性记录都会执行价格显示逻辑。

验证

修改完成后,测试两种属性的商品是否都能正常显示价格,根据实际业务场景调整细节即可。

内容的提问来源于stack exchange,提问作者C Reyes

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 20:02:46