Friday, January 31, 2014

Line Item Properties Fix [a coding post]

Shopify's line item properties are an awesome feature that have exploded the possibilities for product customization in Shopify stores.

However, I've recently noticed that there's a small issue with how some of that information can be displayed in the shop owner's admin. The line breaks are displayed properly in the cart, email notifications, and customer-facing order page. But in the Shopify admin the line breaks are removed.

So, the customer would enter this:
Happy Valentine's Day!
But the shop owner sees:
Happy Valentine's Day! Love, Zak

This doesn't happen with cart attributes, though, so I've come up with a workaround to preserve those line breaks by assigning line item properties to unique cart attributes:

When you cycle through the line item properties to display them on the cart page, you also add them to a hidden cart attribute input element (in this case a textarea element). When the customer checks out, the values are displayed on the Admin Orders page as both line item properties and also cart notes.