Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Adding line_item.properties to URL

Adding line_item.properties to URL

silversorensen
Shopify Partner
7 0 9

Hi,


This code: 

{% liquid assign reorder_url = '' for line_item in order.line_items assign reorder_url = reorder_url | append: line_item.variant_id | append: ':' | append: line_item.quantity | append: ',' endfor -%} <a href="/cart/{{ reorder_url }}" class="yourbuttonclass" style="background: cornflowerblue; color: white; padding: 10px; text-decoration: none">Reorder</a>

 

from https://www.froonze.com/blog/how-reorder-products-in-shopify

 

works to create a REORDER button on the order page of Classic customer accounts.
It generates a URL that includes the variant ID and the quantity and takes you to the checkout so the customer can easily reorder the same things as they had before.

 

How can I add line item properties to this?

 

I'm looking forward to feedback on this.

Thank you!

-silver

Reply 1 (1)

tim
Shopify Partner
3911 394 1435

Not sure if it's possible with cart permalinks as used in that tutorial.

 

But you can add to cart with URL like

/cart/add.js?id=XXX&quantity=YYY&properties[ZZZ]=AAA&properties[BBB]=CCC&id=... 

 

So the code to start with can be like:

 

{% capture parameters -%}
  {%- for li in order.line_items -%}
    id={{ li.variant_id }}&quantity={{ li.quantity }}
      {%- for p in li.properties %}
        &properties[{{ p.first }}]={{ p.last }}
      {%- endfor -%}
  {%- endfor -%}
{%- endcapture %}
{% assign url = routes.cart_add_url | append: "?" | append: parameters | url_escape %}

{{ 'Reorder' | link_to: url, class: 'reorder-button'  }}

 

 

Would need testing though.

 

Caveats -- if you have file attachments in properties, this most probably would not work.

If you have big orders with long properties, this would not work either since URL will grow too long for browsers to process.

 

Ideally, you'd need some JS, or, with liquid  create a hidden cart form which will be submitted by the reorder button or create this form out of the products list there.

If my post is helpful, consider liking it -- it will help others with similar problem to find a solution.
I can be reached via e-mail tairli@yahoo.com