Order Printer - Refunded Items

Solved
Highlighted
Explorer
55 0 49

We're using Order Printer for both pick lists and packing slips. Luckily we have only one fulfillment center and we rarely ahve to do multiple fulfillments on an order, but occasionally we do have to refund an item before shipping. When I print through Order Printer, it still lists all items, including those that have been refunded.

 

I know with the Shopify native Packing Slip template, you can omit items based on which fulfillment they're in, but Order Printer prints the entire order, and not the individual fulfillments. So is it possible add an "if..." or "unless..." statement to NOT print the items that have been refunded?

0 Likes
Highlighted

This is an accepted solution.

Hey Jason,

 

It is possible, but takes some calculation in your template to work out which items have been refunded, and then to adjust the quantity to work out how many remain after the refunds. You would need to find this line in your template:

 

{% for line_item in line_items %}

And just ABOVE that line, add the following:

 

    {% assign refunded_items = "" %}
    {% for refund in refunds %}
      {% for refund_line_item in refund.refund_line_items %}
        {% assign refunded_items = refunded_items | append: refund_line_item.line_item_id | append: ':' | append: refund_line_item.quantity | append: ','%}
      {% endfor %}
    {% endfor %}
    {% assign refunded_items_array = refunded_items | split: ',' %}

Then just BELOW the line mentioned, add the following:

 

      {% assign line_item_id = line_item.id | append: '' %}
      {% if refunded_items contains line_item_id %}
        {% for refunded_item in refunded_items_array %}
          {% assign split_refunded_item = refunded_item | split: ':'%}
          {% if split_refunded_item.first == line_item_id %}
            {% assign non_refunded_quantity = line_item.quantity | minus: split_refunded_item.last %}
          {% endif %}
        {% endfor %}
      {% endif %}
      {% if non_refunded_quantity == 0 %}{% continue %}{% endif %}

And finally, find this code in your template, which shows the quantity of items:

 

{{ line_item.quantity }}

And replace it with:

 

{{ non_refunded_quantity }}

Which is the recalculated quantity after refunds.

 

So it's a pretty big change to your template code. If you don't want to go through that, then I can recommend taking a look at my Order Printer Templates app. All of our Packing Slip templates have this built in, so you can customize and get this without messing with any code yourself. Templates are a one-time purchase, so no ongoing costs. https://apps.shopify.com/order-printer-templates

 

Hope it helps!
Bjorn

 

Order Printer Templates by FORSBERG+two

Bjorn Forsberg | FORSBERG+two | Award-winning Shopify Apps since 2011
1 Like
Highlighted
Explorer
55 0 49

Thanks for the reply, Bjorn, particularly seeing as the info you provided is in competition with your product.

 

I'm going to have to dig into your code a bit. I followed your steps and it didn't work, but we've already tweaked the template, so that may be the reason. I'm pretty comfortable playing with the Liquid code, but I'm not familiar with the specific objects you use.

0 Likes
Highlighted
Explorer
55 0 49

So I figured out part of the problem...

 

You don't assign the non_refunded_quantity variable with a value outside of the if statement that runs when the line_item_id has been refunded. In other words, if it hasn't been refunded, it has no quantity in your code. I added an else statement to do that before the endif.

 

 

0 Likes
Highlighted
Explorer
55 0 49

Yep. That did it! Thank you, Bjorn. I'm marking your response as the accepted solution.

 

All I did was add two lines between your final endfor and endif:

 

      {% else %}
        {% assign non_refunded_quantity = line_item.quantity %}

 

0 Likes
Highlighted

Hey Jason,

 

Glad I could help! And you are totally right, I missed a line in my copy paste. It seems I cannot update my answer above (once it's accepted) so below is the full 2nd snippet needed in case others come across this post later :)

 

{% assign non_refunded_quantity = line_item.quantity %}
{% assign line_item_id = line_item.id | append: '' %}
{% if refunded_items contains line_item_id %}
  {% for refunded_item in refunded_items_array %}
    {% assign split_refunded_item = refunded_item | split: ':'%}
    {% if split_refunded_item.first == line_item_id %}
      {% assign non_refunded_quantity = line_item.quantity | minus: split_refunded_item.last %}
    {% endif %}
  {% endfor %}
{% endif %}
{% if non_refunded_quantity == 0 %}{% continue %}{% endif %}


Kind regards,

Bjorn

Bjorn Forsberg | FORSBERG+two | Award-winning Shopify Apps since 2011
0 Likes
Highlighted
New Member
4 0 0

Hi

There is a slightly straightforward solution to this.  Search for the below code

{% for line_item in line_items %}

Add the below if construct 

{% if line_item.quantity > 0 %}

and close the if construct before the For loop

{{% endif %}} 


hope this helps

0 Likes