Add items to a shopping cart with Vue? - vue.js

I'm trying to figure out how to implement the shopping cart functionality on a page using Vue.js. I get a list of items from an API call and print them on page load. But I'm stuck trying to add items to my cart. The functionality should include the ability to select a quantity of an item and add it to the cart by clicking the "add to cart" button. So it should allow, directly from the cart, to change quantities and remove items from the cart.

For this kind of situation, use a state management pattern like vuex (or pinia), and it will store your data after route change also.
For more clear context, go through this link:
https://vuex.vuejs.org/

Related

How i can add a button on the cart page that will allow the customer to "Empty The Cart". In bigcommerce

How i can add a button on the cart page that will allow the customer to "Empty The Cart". Script will empty contents of the cart.
you could create the button in the template and use a script to call this endpoint: DeleteACart https://developer.bigcommerce.com/api-reference/store-management/carts/cart/deleteacart, to erase an entire cart.
You don't want to use the management api to do this, because that would require authentication. You need to use the storefront cart api I believe.
You would need to call GET /api/storefront/carts and get the id of the cart, and then call DELETE /api/storefront/delete/{id}.
Alternatively you could mimic the native functionality by looping through all the cart items to build a request for POST /remote/v1/cart/update.
The template file for cart in cornerstone is templates/pages/cart.html

Remove all cart items on log out in stencil bigcommerce

Is there any way to remove all cart items when the user logout? I tried getting all the item ID and looping over it and calling the utils cart remove API on every iteration, but it seems it only remove the first one. Any idea about this?
Instead of looping over each item, I'd recommend calling the storefront cart API delete cart endpoint.
Removing all cart items essentially deletes the cart, so the cart winds up in the same state either way. Here's a link to a tutorial on working with the storefront cart API that might help.

Make user stay on product view after clicking on "Add to Cart"

I'm using Hotcakes Commerce DNN modules and I'd like to know how I can allow the user to stay on the product page after the "Add to Cart" button is clicked. The default behaviour is to redirect the user to the cart page whenever the a product is added to the cart.
The easiest way to make this happen is to modify your viewset to change how the add to cart buttons work. Here's a summary of the required steps:
Add and begin modifying your viewset if you haven't started already.
Modify your \VIEWSETNAME\Views\Products_ProductDetails.cshtml file to change the add to cart action from a post, to an AJAX link. This will allow you to add products to cart directly using a link, but keep you on the page.
If you're using the Mini Cart, refresh the page using JS so that it updates appropriately.
Please note that this option won't work well if your products have choices. If this is the case, you should instead allow your customers to be directed to the cart page, and use a parameter there to determine whether or not you redirect back to the product page.

How to implement "Add To Cart" button in bigcommerce

i am setting up my store on bigcommerce, i want to implement add to cart button on my custom home page can anyone tell me how can i add "Add to cart button" on three blocks below slider(In celebrate, bags, weddings section)? This is my store link http://eveningbags1.mybigcommerce.com/
Usually the best way to make an add to cart button on other pages or from other websites is to take the link the Bigcommerce uses for Category/Brand/Search pages. Works like this
site.com/cart.php?action=add&product_id={product_id}
To add a specific option/sku/variation to the cart, use this format
site.com/cart.php?action=add&sku={sku}
Thanks to #Alyss for the sku info

BigCommerce Add Products To Cart API

I'm just setting up my first BigCommerce store, and I'd like to know if I can use their API to add products to a shopper's cart and forward them to the checkout page programmatically?
The problem I'm trying to solve is creation of bundles of products in the store. I need to have each product in a bundle show up as a separate line item and sku on the order, but BigCommerce does not natively support this. The next best thing I can think of is to send the user to a specially crafted php page that will add the constituent parts to their cart, then forward them to the checkout page.
Am I barking up the wrong tree? Is there a simple way to do this that I've missed?
You can use the Cart api to
- Create cart
https://developer.bigcommerce.com/api/v3/cart.html#post-carts
and use the created cart id to
Generate cart URL
https://developer.bigcommerce.com/api/v3/cart.html#post-carts-cartid-redirect_urls
Then you can move the user to this url