Order printer - line item weight in lbs?

Shopify Partner
27 0 9

I’m trying to modify the default packing slip template included with the Order Printer app to include only info my supplier needs. I’ve made it so far as to remove the pricing/tax columns and adding a SKU to the table, and am attempting to add the line weight (I assume this would be qty of line item * item weight)? 

Here's where two problems start:

  1. In my test invoice, the product is qty 1 of a 1 lb item, but using the variable {{ line_item.grams | weight_with_unit }} , the packing slip line is returning “0.00 kg” .
  2. I’ve also tried to insert at the end, lines with {{ cart.item_count }} and {{ cart.total_weight | weight_with_unit }}, but the item count has no value showing and the total order weight returns “Liquid error: undefined method `/' for nil:NilClass”

As you can see from my code confetti below, my capability begins and ends with trial and error and cut and paste. Am I misusing the weight variables somehow obvious?

Thanks for any help!

 

 

<div style="margin: 0 0 1.5em 0; padding: 1.5em; border: 1px solid black;">
  <h2 style="margin: 0 0 1em 0;">BILLING ADDRESS</h2>
  <strong>{{ shop.name }}</strong><br/>
  {{ shop.owner }}<br/>
  {{ shop.email }}<br/> 
  {{ shop.phone }}<br/>
  {{ shop.address }}<br/>
  {{ shop.city }} {{ shop.province_code }} {{ shop.zip | upcase }}<br/>
</div>

{% if shipping_address %}
<div style="padding: 1.5em; border: 1px solid black;">
  <h2 style="margin: 0 0 1em 0;">SHIPPING ADDRESS</h2>
  <strong>{{ shipping_address.name }}</strong><br/>
  {% if shipping_address.company %}
    {{ shipping_address.company }}<br/>
  {% endif %}
  {{ shipping_address.street }}<br/>
  {{ shipping_address.city }} {{ shipping_address.province_code }} {{ shipping_address.zip | upcase }}<br/>
  {{ shipping_address.country }}
</div>

<h3 style="margin: 0 0 1em 0;">Order Contents</h3>

<table class="table-tabular" style="margin: 0 0 1.5em 0;">
  <thead>
    <tr>
      <th>QTY</th>
      <th>SKU</th>
      <th>ITEM</th>
      <th>SHIP LBS</th>
    </tr>
  </thead>
  <tbody>
    {% for line_item in line_items %}
      <tr>
        <td>{{ line_item.quantity }} x</td>
        <td><b>{{ line_item.sku }}</b></td>
        <td><b>{{ line_item.title }}</b></td>
        <td><b>{{ line_item.grams | weight_with_unit }}</b></td>
    {% endfor %}
  </tbody>
</table>

<h3 style="margin: 0 0 1em 0;">Total item count: {{ cart.item_count }}</h3>
<h3 style="margin: 0 0 1em 0;">Total item lbs: {{ cart.total_weight | weight_with_unit }}</h3>
{% endif %}

 

0 Likes
Shopify Partner
385 0 49

Hello Chad9,

Unfortunately the order printer does not have access to cart as its an order. To get the line item weight, you are already in the right tracks by using {{ line_item.grams }} or {{ line_item.weight }}.

You will also need to calculate the order total item count and the total weight, you can do something like this to do it:

{% assign order_total_weight = 0 %}
{% assign order_total_items = 0 %}
{% for line in line_items %}
    {% assign line_weight = line.weight | times: line.quantity %}
    {% assign order_total_weight = order_total_weight | plus: line_weight %}
    {% assign order_total_items = order_total_items | plus: line.quantity %}
{% endfor %}

and then you can use them with {{ order_total_items }} and {{ order_total_weight | weight_with_unit }}

FYI The products should have had their weights set before the order is generated otherwise the lines will return 0 in old orders.

Hopefully this helps.

Kasimir

"Good design is good business"
1 Like
Shopify Partner
27 0 9

Thank you for your help! The calculated order totals are both working.

I am still stuck with the per-line weights, hoping to have each line sum that item's qty (in lbs not grams)

  • Weights in most products are set as a lb unit (if this matters)
  • If I use the {{ line_item.grams | weight_with_unit }} variable, the result is "0.00 kg" on each line
  • If I use the {{ line_item.weight }} variable, the result is the correct item weight, but in grams

Thanks again for your time

 

<table class="table-tabular" style="margin: 0 0 1.5em 0;">
  <thead>
    <tr>
      <th>QTY</th>
      <th>SKU</th>
      <th>ITEM</th>
      <th>SHIP LBS</th>
    </tr>
  </thead>
  <tbody>
    {% for line_item in line_items %}
      <tr>
        <td>{{ line_item.quantity }} x</td>
        <td><b>{{ line_item.sku }}</b></td>
        <td><b>{{ line_item.title }}</b></td>
        <td><b>{{ line_item.weight }}</b></td>
    {% endfor %}
  </tbody>
</table>

 

0 Likes
Shopify Partner
385 0 49

Hello Chad9,

weight_with_unit returns the shop default weight unit, you can alter this in settings tho. In theory you should be able to do {{ line_item.weight | weight_with_unit: 'lb' }} to convert it to lbs but unfortunately atleast as far as I remember this does not work with order printer.

You could however do a custom math filter to convert it from kgs to lbs something like this would do it:

{{ line_item.weight | times: 2.2046 | divided_by: 1000 | round: 1 | append: ' lb' }}

If you want to have all the line products combined weight (weight * quantity of products bought) you can simply just do something like:

{{ line_item.weight | times: 2.2046 | divided_by: 1000 | times: line_item.quantity | round: 1 | append: ' lb' }}

You can obviously add this to the total weight aswell:

{{ order_total_weight | times: 2.2046 | divided_by: 1000 | round: 1 | append: ' lb' }}

Does this work for you?

Kasimir

"Good design is good business"
0 Likes
New Member
1 0 0

Im not able to help you with your question but i just wanted to say a HUGE thank you for posting this as I had no idea how to add the SKU to my packing slips as I am new to this and this has meant I can now get my packing organised

 

Im so grateful

 

Thank you

0 Likes