Packing slip - alphabetical sorting for items

HallofComics
Visitor
1 0 2

Hello,

Does anyone know of a way to have the items on the packing slips or invoices sort in an alphabetical order?  We can have up to 100+ items in an order and have been unsuccessful in finding a solution through Shopify.

 

Thank you,

Ryan

Replies 10 (10)

NativePlantsU
Tourist
3 0 2

Don’t know if op is still looking for help, but I found this question when I was looking for the answer myself and wanted to post the answer for other people looking for it.
I don’t know HTML, and Shopify helpfully suggested I borrow money from them to pay an expert for one line of code. Luckily, I am related to a coder who fiddled with it until we got it working! I think Shopify’s default packing slip code is the same regardless of theme, so hopefully this will work for everyone.

 

Replace the line 

{% for line_item in line_items_in_shipment %}

with these lines 

{% assign sorted-list= line_items_in_shipment | sort: "title" %}
{% for line_item in sorted-list in line_items_in_shipment %} 

 

Hope this helps someone else!

 

gfachler
Shopify Partner
10 1 6

This did not work for me. I modified the code and the following did work:

 

In your packing slip template, find the line:

{% for line_item in line_items_in_shipment %}

 

and replace it with

 

{% assign lineitems = line_items_in_shipment | sort: "title" %}
{% for line_item in lineitems %} 

LCaraway
Visitor
2 0 0

This code worked for me, but I have a further question. Now that I have my packing slips sorted by title, is there anyway to further sort by "color" or "Option1 Value?"

RoxanneWilson
Tourist
8 0 3

Where do we find the original code to edit?

I do not have packing slip under templates in my theme

NativePlantsU
Tourist
3 0 2

It's not in the theme code, you have to go through settings to find it. Go to Settings -> Shipping and Delivery -> Edit Packing Slip Template. Should be line 97 or thereabouts.

RoxanneWilson
Tourist
8 0 3

Ah yes, right!! Thank you it is working now.

NativePlantsU
Tourist
3 0 2

I wonder if theme does affect it then? Double checked the code I posted and that is what is working for me. Good to know I should try your if that ever changes! Thanks for posting!

APaule
Visitor
2 0 0

Brilliant, thanks!  This just made my day 🙂

WindItUp
Tourist
3 0 1

This worked and it is awesome!  Thank you.  The only thing is there is now more space between items...can't see where that would be coming from.  Eventually a lot of paper will be consumed.  Anyone have any ideas?

WindItUp
Tourist
3 0 1

The spacing issue is worse than I thought.  When the packing slip carries over to a second page, items are lost because they 'print' outside the printable margin.  

 

Anyone have any ideas how to compress the items list?!