A user is attempting to create a packing slip template that displays and sorts line items by SKU, but the sorting functionality isn’t working despite the SKU values displaying correctly.
The Problem:
SKU column displays properly in the invoice/packing slip
Sort by SKU parameter (sort: "sku") fails to reorder items
Code uses {% assign lineitems = unfulfilled_line_items | sort: "sku" %} but iterates over line_items instead
Proposed Solution:
The variable name mismatch is identified as the likely cause
The assign statement creates lineitems (or unfulfilled_line_items) but the for-loop references line_items
Fix: Either remove underscores to match variable names, or ensure the for-loop iterates over the correctly assigned variable
Alternative approach: Use {% assign sorted_line_items = line_items | sort: 'sku' %} then loop through sorted_line_items
Status: A solution was provided several months after the original post, suggesting the variable naming inconsistency needs correction for the sort filter to function properly.
Summarized with AI on November 11.
AI used: claude-sonnet-4-5-20250929.
I am editing an invoice to make a packing slip with order details. It is all working except, I cannot get it to sort by SKU. Any ideas what I am doing wrong?
{% assign lineitems = unfulfilled_line_items | sort: "sku" %}
{% for line_item in line_items %}
{% endfor %}
If you want to adjust your code, remove the _ from the {% for line_item in line_items %} so it matches the assign tag you gave it {% assign lineitems = unfulfilled_line_items | sort: “sku” %}