You can use an Array to store both the shop catalogue as well as which items have been selected by the Reader.
1. Use code like the following in your shop to display a selection of items.
<<set $catalogue to ["milk", "cheese", "bread"]>>\
<<set $cart to []>>\
\
Your cart: @@#cart;<<display "Show Cart">>@@
<<for _i to 0; _i lt $catalogue.length; _i++>>\
<<capture _i>>\
<<link `"buy " + $catalogue[_i]`>>\
<<if not $cart.includes($catalogue[_i])>>\
<<set $cart.push($catalogue[_i])>>\
<<replace "#cart">><<display "Show Cart">><</replace>>
<</if>>\
<</link>>
<</capture>>\
<</for>>\
... the above uses a <<for>> macro to loop the items in the catalogue. it uses the <<capture>> macro
to allow access to the _i variable within the <<link>> macro
's body at time of selection. It uses
Custom Style Markup to define a HTML <span> element with an ID of cart in which we display the contents of the Show Cart passage, and it uses a <<replace>> macro within the links body to refresh the contents of the cart area. The above also uses the <Array>.includes() function to determine if a particular item is already within the cart.
2. The Show Cart passage:
<<for _i to 0; _i lt $cart.length; _i++>>\
<<if _i > 0>><<print ", ">><</if>>\
<<print $cart[_i]>>\
<</for>>\
.. the above loops the current content of the cart variable and displays each item contained within it.