複数個購入時の代金表示について

AI-generated summary

明細表テンプレートで、複数購入時の「小計」が「価格×数量」にならず、単価だけが表示される不具合についての質問。添付画像とLiquidコードが共有され、final_line_price、order.line_items_subtotal_price、order.total_price などが期待どおり表示されない原因が問われた。

主な論点:
・order.line_items を先にループして final_price / final_line_price を代入しているため、各行商品ではなく最後の商品の値を参照している可能性がある。
・回答では、少なくとも小計表示については final_price(単価)に line_item.quantity(数量)を掛けて算出する方法が提案された。times は乗算フィルタ。

提示された対応例:
・{% assign a = final_price %}
・{% assign b = line_item.quantity %}
・{{ a | times:b | money }}

結論として、質問者は提案に感謝を述べており、小計表示の件はひとまず解決した様子。一方で、商品金額合計や合計金額がなぜ正しく出ないかの詳細検証は会話内では未解決のまま。

設定 > 配送と配達 > 明細表 > 明細表のテンプレートにて、明細票を作成しています。

後述のように組んでいるのですが、「小計」が 価格 × 数量の計算結果にならず、単体価格が表示されてしまいます。(添付画像の表を参照ください)

購入した数量は表示されているのに、final_line_priceを使っても表示されないのはなぜでしょうか?

また、「商品金額合計」や「合計金額」も正しく表示されないのは、なぜでしょうか?

間違っている部分などを教えていただければ幸いです。よろしくお願いします。

{% assign final_price = nil %}
        {% assign final_line_price = nil %}
        {% for item in order.line_items %}
          {% assign final_price = item.final_price %}
          {% assign final_line_price = item.final_line_price %}
        {% endfor %}

        {% for line_item in line_items_in_shipment %}
          
            
              {% if line_item.image != blank %}
                
              {% endif %}
            
            {{ line_item.title }}
            
              {% if final_price %}
                {{ final_price | money }}
              {% endif %}
            {{ line_item.quantity }}
            
              {% if final_line_price %}
                {{ final_line_price | money }}
              {% endif %}
          
        {% endfor %}

      <table>

        
          
            <tr>

              <th>

商品金額合計

</th>

              <td>

                {{ order.line_items_subtotal_price | money }}
              

</td>

            </tr>

            <tr>

              <th>

送料

</th>

              <td>

{{ order.shipping_price | money }}

</td>

            </tr>

            <tr>

              <th>

合計金額

</th>

              <td>

{{ order.total_price | money  }}

</td>

            </tr>

            
          
        
      </table>

単価 × 数量 で小計を算出してみてはどうでしょうか。

{% assign a = final_price %}
{% assign b = line_item.quantity %}

小計 {{ a | times:b | money }}

ありがとうございます!