“Add product to watchlist” button in the product box
Insert the form into the product box, outside the “go to product detail view” form.{{ var $cActionWatchListItemAdd = $wsActions.create("WatchListItemAdd") }}
{{ var $cActionWatchListItemDelete = $wsActions.create("WatchListItemDelete") }}
{{ var $cProductIsInWatchList = false }}
{{ var $cWatchListItemId = "" }}
{{ foreach $cWatchListItem in $wsWatchList.items }}
{{ if $cWatchListItem.product.id == $cProduct.id }}
{{ $cProductIsInWatchList = true}}
{{ $cWatchListItemId = $cWatchListItem.id }}
{{ /if }}
{{ /foreach }}
<div>
...
<form action="{{= $wsViews.current.url() }}" method="post">
<input type="hidden" name="wsact" value="{{= $cBasketAdd.id }}">
<input type="hidden" name="wscsrf" value="{{= $cBasketAdd.csrf }}">
<input type="hidden" name="wstarget" value="{{= $wsViews.current.url() }}">
<input type="hidden" name="productId" value="{{= $cProduct.id }}">
</form>
...
<form id="wsFormWatchlist-{{= $cProduct.id }}" method="post" action="{{= $wsViews.current.url() }}" ws-ajax-form>
<input type="hidden" name="wsReplaceIds" value="wsFormWatchlist-{{= $cProduct.id }},wsMemolistEntries,wsMemolistOffcanvasContent">
<input type="hidden" name="wscsrf" value="{{= $cActionWatchListItemAdd.csrf }}">
<input type="hidden" name="wstarget" value="{{= $wsViews.current.url() }}">
<input type="hidden" name="productId" value="{{= $cProduct.id }}">
{{ if $cProductIsInWatchList }}
<input type="hidden" name="wsact" value="{{= $cActionWatchListItemDelete.id }}">
<input type="hidden" name="watchListItemId" value="{{= $cWatchListItemId }}">
{{ else }}
<input type="hidden" name="wsact" value="{{= $cActionWatchListItemAdd.id }}">
{{ /if }}
<button type="submit">
{{ if $cProductIsInWatchList }}
Product is on the watchlist
{{ else }}
Add to watchlist
{{ /if }}
</button>
</form>
...
</div>
Button in the header
Clicking the button loads the watchlist in the offcanvas.<button type="button" title="Watchlist" data-bs-toggle="offcanvas" data-bs-target="#wsMemolistOffcanvas">
Watchlist
<span id="wsMemolistEntries">
{{ if $wsWatchList.items }}{{= $wsWatchList.items | len }}{{ /if }}
</span>
</button>
Offcanvas watchlist
<div class="offcanvas offcanvas-end" tabindex="-1" id="wsMemolistOffcanvas">
<div class="offcanvas-header">
<p>Watchlist</p>
<button type="button" data-bs-dismiss="offcanvas">Close</button>
</div>
<div class="offcanvas-body">
<div id="wsMemolistOffcanvasContent">
{{ if $wsWatchList.items }}
{{ foreach $cProduct in $wsWatchList.items }}
{{ var $cProductDelete = $wsActions.create("WatchListItemDelete", tag = $cProduct.id) }}
<a href="{{= $wsViews.url('Product', {productId: $cProduct.product.id}) }}">
<img src="{{= $cProduct.product.custom.image.normal | ifNull(static('images/noImageThumbnail.jpg')) }}">
</a>
{{= $cProduct.product.name }}
{{ if $cProduct.product.variantSelection }}
{{ foreach $cVarAttr in $cProduct.product.variantSelection | keys }}
{{= $cVarAttr}}: {{= $cProduct.product.variantSelection[$cVarAttr] }}
{{ /foreach }}
{{ /if }}
{{= $cProduct.product.price | currency }}
<form id="wsFormWatchlistDeleteProductOffcanvas-{{= $cProduct.id }}" action="{{= $wsViews.current.url() }}" method="post" ws-ajax-form>
<input type="hidden" name="wsReplaceIds" value="wsFormWatchlist-{{= $cProduct.product.id }},wsWatchlistWrapper,wsMemolistEntries,wsMemolistOffcanvasContent">
<input type="hidden" name="wscsrf" value="{{= $cProductDelete.csrf }}">
<input type="hidden" name="wsact" value="{{= $cProductDelete.id }}">
<input type="hidden" name="wstarget" value="{{= $wsViews.current.url() }}">
<input type="hidden" name="productId" value="{{= $cProduct.product.id }}">
<input type="hidden" name="watchListItemId" value="{{= $cProduct.id }}">
<button type="submit">Remove from watchlist</button>
</form>
{{ /foreach }}
<a href="{{= $wsViews.viewUrl('account/watchlist.htm') }}">View watchlist</a>
{{ else }}
You have no products on the watchlist!
{{ /if }}
</div>
</div>
</div>
