Cart.js is an easy to use shopping-cart system made in JavaScript (Jquery) only.
There are a couple of steps you need to take before you can use cart.js. See this example below.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script src="{path-to-your-file}/Cart.js"></script>This is what your buttons should look like for cart.js to work. Of course you can add your own classes as well
<div class="in-shopping-cart" data-product-id="<?= $product["productId"]; ?>">In Cart</div>$productObject = new Product();
$cart = json_decode($_COOKIE["cart"]);
foreach ($cart as $cartItem){
$product = $productObject->getProductByID($cartItem->productId); <div class="out-of-shopping-cart" data-product-id="<?= $product["productId"]; ?>">Remove</div> <input type="number" value="<?= $cartItem->amount ?>" onchange="updateCart(<?= $cartItem->productId ?>, this.value)">In this example we use php. You can use any language you want as long as you
-
give "data-product-id={id}" the id of the product
-
add the classes from this example
-
have a method that can get a product by id: $productObject->getProductByID({id})