# Shopping cart functionality with variable

**URL:** <https://community.weweb.io/t/shopping-cart-functionality-with-variable/2299>\
**Category:** How do I?\
**Created:** [April 14, 2023, 11:32am UTC](https://community.weweb.io/t/shopping-cart-functionality-with-variable/2299 "2023-04-14T11:32:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ou.side](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/ou.side/32/2586_2.png) [@ou.side](https://community.weweb.io/u/ou.side)\
**Post date:** [April 14, 2023, 11:32am UTC](https://community.weweb.io/t/shopping-cart-functionality-with-variable/2299/1 "2023-04-14T11:32:37Z")

</div>

I want to users can add product to cart without regestration. I believe variables are a good fit for this purpose but i cant create action that adding +1 item from collection list to variable by clik on button into collection item.

There is no quantity,one item can only be purchased in one copy, so i want just add and delete products from cart and be able to display this products in cart and use them for checkout.

Please help me to solve this issue. I would really appreciate your help and any advice you can offer. Thank you in advance for your time and effort!

---

<div class="post-metadata">

**Author:** ![ou.side](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/ou.side/32/2586_2.png) [@ou.side](https://community.weweb.io/u/ou.side)\
**Post date:** [April 14, 2023, 11:41am UTC](https://community.weweb.io/t/shopping-cart-functionality-with-variable/2299/2 "2023-04-14T11:41:11Z")

</div>

I tried to use arrows and objects for variableas, but I have problems with displaying list of data from variable…

---

<div class="post-metadata">

**Author:** ![dorilama](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/dorilama/32/10403_2.png) [@dorilama](https://community.weweb.io/u/dorilama)\
**Post date:** [April 14, 2023, 12:01pm UTC](https://community.weweb.io/t/shopping-cart-functionality-with-variable/2299/3 "2023-04-14T12:01:09Z")

</div>

There are many ways to do this.  
[this](https://community.weweb.io/t/add-to-cart-button/866/2) is one example (it’s with quantities but it’s the same principle)

Another simple way would be to have an array as variable to keep track of the products, and then use [array functions](https://docs.weweb.io/formulas/array.html) to add/remove a product. Keep in mind that in this case you want to store a simple value like a string in the array.

---

<div class="post-metadata">

**Author:** ![ou.side](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/ou.side/32/2586_2.png) [@ou.side](https://community.weweb.io/u/ou.side)\
**Post date:** [April 14, 2023, 12:56pm UTC](https://community.weweb.io/t/shopping-cart-functionality-with-variable/2299/4 "2023-04-14T12:56:39Z")

</div>

I am trying to do it the array way, but only one product is displayed. Could you suggest what I’m doing wrong?  
Uploading: Screenshot\_1.png…  
Uploading: Screenshot\_2.png…  
Uploading: Screenshot\_3.png…  
Uploading: Screenshot\_4.png…  
Uploading: Screenshot\_85.png…

---

<div class="post-metadata">

**Author:** ![ou.side](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/ou.side/32/2586_2.png) [@ou.side](https://community.weweb.io/u/ou.side)\
**Post date:** [April 14, 2023, 12:57pm UTC](https://community.weweb.io/t/shopping-cart-functionality-with-variable/2299/5 "2023-04-14T12:57:51Z")

</div>

![Screenshot_1](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/e/e6337b9774522e24104ddeca4ba6bf0bd7d2fdd3.png)  
 ![Screenshot_2](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/3/3e660eef8d026679610ae2b382e58d56c44e8337.png)  
 ![Screenshot_3](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/c/cd7d9607b9311f566438b85f6f111142b7fbf734.png)  
 ![Screenshot_85](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/3/3d42dbd9e258fd8a1b94a31507c439bee80345e2.png)  
 ![Screenshot_4](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/e/e0443ef346dc52f17e0d05fb09c0cff0c2aeaf81.png)

---

<div class="post-metadata">

**Author:** ![dorilama](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/dorilama/32/10403_2.png) [@dorilama](https://community.weweb.io/u/dorilama)\
**Post date:** [April 14, 2023, 9:23pm UTC](https://community.weweb.io/t/shopping-cart-functionality-with-variable/2299/6 "2023-04-14T21:23:20Z")

</div>

The simplest way of doying this, if you don’t need quantities, is, as I said, an array of ids (strings).  
It looks like you are creating an array of arrays of strings.  
To add a product insert the id at the beginning.  
To remove a product replace the whole array and use the “remove” function as described in the docs.  
In the end you want something like `["prod-id-1","prod-id-2"]` and use the id to lookup the product data.
