# Save customized products (line item properties)

Keep a product's customizations (a measurement, a lining, an engraving) with the saved item, so it goes back into the cart exactly as it was configured. Includes the event developers use for choices a theme adds in JavaScript.

Source: https://apps.conspireagency.com/wishlist/docs/guides/line-item-properties

Many product pages let a customer customize a product beyond its variants: a curtain's length, a lining, a trim, a monogram. Shopify carries those choices to the cart as **line item properties**, the `properties[...]` fields in the product form, and shows them in the cart and on the order.

A wishlist item saves the same properties. When the customer adds it to the cart later, from the item, from **Add all to cart** or from a shared list, it goes in with every choice it was saved with. The same product saved twice with different choices is two items.

This is part of the [Project planner plan](https://apps.conspireagency.com/wishlist/docs/getting-started/plans-and-billing) (development stores have it free) and works with the V2 **Save to project** button and the classic **Add to wishlist** button. On the Free plan, a customized product is saved as the plain variant, without its choices.

## Most stores need no setup

When a customer clicks the wishlist button on a product page, the app reads the product's add-to-cart form exactly as the browser would submit it:

* every field named `properties[Something]` is saved as the property **Something**
* only the selected option of a radio group or a select counts, and empty fields are left out (Shopify's cart leaves them out too)
* fields placed outside the form and joined to it with the `form="..."` attribute are included
* file uploads are not saved: a wishlist cannot hold a file

If your theme or configurator app writes its choices into the product form as `properties[...]` fields, saved items already carry them.

## Where saved choices show

* **On the wishlist**: under the product name, one line per choice ("Lining: Blackout"). Properties whose name starts with an underscore (`_customized_image`) stay hidden, as they are in Shopify's cart, but are still saved and sent to the cart.
* **In the cart and on the order**: every property, hidden ones included, as if the customer had added the item from the product page.
* **On the PDF**: the visible properties, printed under the product in the same rows as your [PDF metafields](https://apps.conspireagency.com/wishlist/docs/guides/pdf-export).
* **In draft orders created from a wishlist**: every property, as the line's custom attributes.
* **In the admin**: on the wishlist's page, under each product.

## For developers: choices your theme adds in JavaScript

Some themes add properties at the moment of add to cart instead of keeping them in the form (a calculated price note, a pre-order date), or add separate cart lines after the main product (a platform for a bed, a setup fee, rush processing). The app cannot see those, so it asks the page for them.

Just before it saves an item, the app dispatches the event `wishlist:collect-properties` on `document`. Change `event.detail` in a listener, synchronously:

| Field               | What it is                                                                                 |
| ------------------- | ------------------------------------------------------------------------------------------ |
| `detail.form`       | The product's add-to-cart form, or `null` when none was found near the button              |
| `detail.productId`  | The product id, as a string                                                                |
| `detail.variantId`  | The variant being saved, as a string                                                       |
| `detail.quantity`   | The quantity being saved                                                                   |
| `detail.properties` | The properties read from the form, as `{ "Name": "value" }`. Add, change or delete entries |
| `detail.addons`     | An empty array. Push extra cart lines that belong with this item                           |

Each add-on line is `{ variant_id, quantity, properties, title }`:

* `variant_id` (required): the numeric id of the variant to add to the cart
* `quantity` (optional): leave it out and the add-on follows the item's quantity (one platform per bed); give a number for a fixed count (one setup fee)
* `properties` (optional): line item properties for the add-on line
* `title` (optional): what the wishlist and the PDF show for it, for example "Platform: Queen +$450"

When the saved item goes to the cart, the app adds it and its add-on lines in one request, in the order you listed them.

### Example

Add this to a theme JavaScript file, or to a `<script>` in the product template. It mirrors what a theme's own add-to-cart code does for a bed with an optional platform:

```html
<script>
  document.addEventListener('wishlist:collect-properties', function (event) {
    var detail = event.detail;

    // A choice the theme normally appends when the customer adds to cart
    var platform = document.querySelector('.bed-platform-checkbox:checked');
    if (platform) {
      var label = document.querySelector('label[for="' + platform.id + '"]');
      detail.properties['Base Construction'] = label ? label.textContent.trim() : platform.value;

      // The platform is its own product in the cart, one per bed
      if (Number(platform.dataset.price) > 0) {
        detail.addons.push({
          variant_id: platform.dataset.variantId,
          properties: { _is_platform: 'true' },
          title: 'Platform: ' + (label ? label.textContent.trim() : platform.value),
        });
      }
    }
  });
</script>
```

Keep the listener synchronous: the app reads `event.detail` as soon as the event returns. If a listener throws, the browser reports the error and the item is still saved with what the form gave.

### Limits

* Up to 50 properties per item; names up to 255 characters, values up to 2,000. Values are saved as text.
* Up to 10 add-on lines per item.
* Entries over these limits are left out rather than refusing the save.

## Things to know

* **Choices are saved as they were.** If you change a product's options later, saved items keep the values they were saved with.
* **Prices come from the variants.** The wishlist shows the main variant's price; an add-on's price is charged in the cart and on the order, but the wishlist and the PDF show the add-on by its title only, not in their totals.
* **Links between cart lines.** Some themes tie an add-on to its main line with the cart line's key, which only exists once the item is in the cart. An add-on added from a wishlist cannot carry that key, so if your cart drawer groups lines that way, it shows the add-on as its own line.
* **Collection pages** have no product form, so items saved from a collection grid have no properties unless your listener supplies them.

Need a hand wiring up a configurator? Reach out through our [contact form](https://apps.conspireagency.com/wishlist/contact).
