Skip to content

Ability to populate list fields when using an add items form (wishlist/items/add) #168

Description

@thisisjamessmith

What are you trying to do?

I'm using Wishlist in Craft Commerce for saved orders functionality. I might have missed a more obvious way of doing this, so apologies in advance! I simply need each saved order (wishlist) to know the total order value. I was hoping to be able to pass the order value into a field stored against the wishlist, but it seems that I can't do this in a single step when using the wishlist/items/add action, as fields passed there apply to the items rather than the list.

My form looks something like this - the problem is the fields[savedOrderTotal] hidden field, which is a custom field held against the list.

<form method="post">
	<input type="hidden" name="action" value="wishlist/items/add">
	{{ redirectInput('account/saved-orders') }}
	{{ csrfInput() }}
	<input type="hidden" name="listType" value="quote">
	<input type="hidden" name="newList" value="1">
	<input type="hidden" name="fields[savedOrderTotal]" value="{{ cart.itemSubtotalAsCurrency }}">

	{% for item in cart.lineItems|filter(item => item is not null) %}
		<input type="hidden" name="items[{{ item.id }}][fields][productUrl]" value="{{ item.snapshot.product.url }}">
		<input type="hidden" name="items[{{ item.id }}][fields][itemQty]" value="{{ item.qty }}">
		<input type="hidden" name="items[{{ item.id }}][fields][itemSku]" value="{{ item.sku }}">

		<input type="hidden" name="items[{{ item.id }}][elementId]" value="{{ item.purchasable.id }}">
		<input type="hidden" name="items[{{ item.id }}][elementSiteId]" value="1">

		<input type="hidden" name="items[{{ item.id }}][fields][itemPrice]" value="{{ item.onPromotion ? item.salePriceAsCurrency : item.priceAsCurrency }}">
	{% endfor %}

	<button>Save for later</button>
</form>

What's your proposed solution?

Perhaps allow for populating any arbitrary list field with

<input type="hidden" name="listFields[listFieldHandle]">

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions