content logo

Bootstrap Cards:

Bootstrap Demo Store with Local Storage

If you have a store website, you should add a demo of your products before displaying them. This can be so useful for you. In this post, we have provided a code that contains different cards for store websites. This is the Bootstrap Demo Store with Local Storage with functional performance. By using this Bootstrap Shopping Cart, you can easily represent your products’ demo before showing it. As a result, more people tend to use that product and are interested in it. So, you can use the Bootstrap Store Card Code and attract customers before shopping.

We have prepared the preview of this code below. By looking at the following preview, you realize that the Bootstrap Shopping List Card has a white background and you can apply it on your simple website. There are two photos of the products and you can see their name below the picture. This Bootstrap Shop Storage has a blue button with white writing. The blue field is used for adding that product to the cart. Plus, you can see that product’s price in the same field. If you click on this blue field, you will face an alert that shows the product in the cart. Then, it is placed at the bottom of the page with its price.

#

Bootstrap Shopping Cart

#

Bootstrap Store Card Code

#

Bootstrap Shopping List Card

#

Bootstrap Shop Storage

<!-- This script got from frontendfreecode.com -->
<div class="container">
    <div class="row">
        <div class="col">
            <div class="card" style="width: 15rem;margin-bottom:15px;">
                <img src="http://frontendfreecode.com/img/red-shoe.jpg" class="card-img-top" alt="...">
                <div class="card-body">
                    <h5 class="card-title">Red Shoe</h5>
                    <p class="card-text">This is a red shoe :)</p>
                    <a href="#" class="btn btn-primary" id="liveToastRedBtn" onclick="addToCart('RedShoe')">Add to Cart: €60</a>
                </div>
            </div>
        </div>
        <div class="col">
            <div class="card" style="width: 15rem;15rem;margin-bottom:15px;">
                <img src="http://frontendfreecode.com/img/green-shoe.jpg" class="card-img-top" alt="...">
                <div class="card-body">
                    <h5 class="card-title">Green Shoe</h5>
                    <p class="card-text">This is a green shoe :)</p>
                    <a href="#" class="btn btn-primary" id="liveToastGreenBtn" onclick="addToCart('GreenShoe')">Add to Cart: €50</a>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col">
            <ul class="list-group" id="cart" width:30px;>
                <!-- <li><img src="item.image" alt=""><span>item.name</span><span>item.price</span></li> -->
            </ul>
        </div>
    </div>
</div>
<div class="position-fixed bottom-0 end-0 p-3" style="z-index: 11">
    <div class="toast" role="alert" aria-live="assertive" aria-atomic="true" id="liveToastGreen">
        <div class="toast-header">
            <svg class="bd-placeholder-img rounded me-2" width="20" height="20" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" preserveAspectRatio="xMidYMid slice" focusable="false">
                <rect width="100%" height="100%" fill="#00ff00"></rect>
            </svg>
            <strong class="me-auto">Green</strong>
            <small>Now now</small>
            <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
        </div>
        <div class="toast-body">
            Just added to cart.
        </div>
    </div>
</div>
<div class="position-fixed bottom-0 end-0 p-3" style="z-index: 11">
    <div class="toast" role="alert" aria-live="assertive" aria-atomic="true" id="liveToastRed">
        <div class="toast-header">
            <svg class="bd-placeholder-img rounded me-2" width="20" height="20" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" preserveAspectRatio="xMidYMid slice" focusable="false">
                <rect width="100%" height="100%" fill="#ff0000"></rect>
            </svg>
            <strong class="me-auto">Red Shoe</strong>
            <small>Now now</small>
            <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
        </div>
        <div class="toast-body">
            Just added to cart.
        </div>
    </div>
</div><a style="font-size: 8pt; text-decoration: none" target="_blank" href="http://frontendfreecode.com">Free Frontend</a>
                                                                            
.img-width{
    width:50px!important;
}
var toastTriggerR = document.getElementById("liveToastRedBtn");
var toastTriggerG = document.getElementById("liveToastGreenBtn");
var toastLiveExampleG = document.getElementById("liveToastGreen");
var toastLiveExampleR = document.getElementById("liveToastRed");
if (toastTriggerR) {
    toastTriggerR.addEventListener("click", function () {
        var toast = new bootstrap.Toast(toastLiveExampleR);
        toast.show();
    });
}
if (toastTriggerG) {
    toastTriggerG.addEventListener("click", function () {
        var toast = new bootstrap.Toast(toastLiveExampleG);
        toast.show();
    });
}
let cart = [];
if (localStorage.cart) {
    cart = JSON.parse(localStorage.cart);
}
displayCart();
function displayCart() {
    const ul = document.getElementById("cart");
    ul.innerHTML = "";
    const cartItems = cart.map((item) => {
        const cartItem = document.createElement("li");
        cartItem.setAttribute(
            "class",
            "list-group-item d-flex justify-content-between align-items-center"
        );
        // image
        const imageItem = document.createElement("img");
        imageItem.setAttribute("src", item.image);
        imageItem.setAttribute("class", "img-width img-fluid");
        // name
        const nameItem = document.createElement("span");
        nameItem.innerHTML = item.name;
        // price
        const priceItem = document.createElement("span");
        priceItem.setAttribute("class", "badge bg-primary rounded-pill");
        priceItem.innerHTML = item.price;
        cartItem.appendChild(imageItem);
        cartItem.appendChild(nameItem);
        cartItem.appendChild(priceItem);
        ul.appendChild(cartItem);
    });
    console.log(cart);
    // Store
    localStorage.cart = JSON.stringify(cart);
}
function addToCart(shoe) {
    if (shoe === "GreenShoe") {
        cart.push({
            name: "green shoe",
            price: 50,
            image:
                "http://frontendfreecode.com/img/green-shoe.jpg"
        });
    } else {
        cart.push({
            name: "red shoe",
            price: 60,
            image:
                "http://frontendfreecode.com/img/red-shoe.jpg"
        });
    }
    displayCart();
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- This script got from frontendfreecode.com -->

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<style>
.img-width{
    width:50px!important;
}

</style>

</head>
<body>
<div class="container">
    <div class="row">
        <div class="col">
            <div class="card" style="width: 15rem;margin-bottom:15px;">
                <img src="http://frontendfreecode.com/img/red-shoe.jpg" class="card-img-top" alt="...">
                <div class="card-body">
                    <h5 class="card-title">Red Shoe</h5>
                    <p class="card-text">This is a red shoe :)</p>
                    <a href="#" class="btn btn-primary" id="liveToastRedBtn" onclick="addToCart('RedShoe')">Add to Cart: €60</a>
                </div>
            </div>
        </div>
        <div class="col">
            <div class="card" style="width: 15rem;15rem;margin-bottom:15px;">
                <img src="http://frontendfreecode.com/img/green-shoe.jpg" class="card-img-top" alt="...">
                <div class="card-body">
                    <h5 class="card-title">Green Shoe</h5>
                    <p class="card-text">This is a green shoe :)</p>
                    <a href="#" class="btn btn-primary" id="liveToastGreenBtn" onclick="addToCart('GreenShoe')">Add to Cart: €50</a>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col">
            <ul class="list-group" id="cart" width:30px;>
                <!-- <li><img src="item.image" alt=""><span>item.name</span><span>item.price</span></li> -->
            </ul>
        </div>
    </div>
</div>
<div class="position-fixed bottom-0 end-0 p-3" style="z-index: 11">
    <div class="toast" role="alert" aria-live="assertive" aria-atomic="true" id="liveToastGreen">
        <div class="toast-header">
            <svg class="bd-placeholder-img rounded me-2" width="20" height="20" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" preserveAspectRatio="xMidYMid slice" focusable="false">
                <rect width="100%" height="100%" fill="#00ff00"></rect>
            </svg>
            <strong class="me-auto">Green</strong>
            <small>Now now</small>
            <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
        </div>
        <div class="toast-body">
            Just added to cart.
        </div>
    </div>
</div>
<div class="position-fixed bottom-0 end-0 p-3" style="z-index: 11">
    <div class="toast" role="alert" aria-live="assertive" aria-atomic="true" id="liveToastRed">
        <div class="toast-header">
            <svg class="bd-placeholder-img rounded me-2" width="20" height="20" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" preserveAspectRatio="xMidYMid slice" focusable="false">
                <rect width="100%" height="100%" fill="#ff0000"></rect>
            </svg>
            <strong class="me-auto">Red Shoe</strong>
            <small>Now now</small>
            <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
        </div>
        <div class="toast-body">
            Just added to cart.
        </div>
    </div>
</div><div id="bcl"><a style="font-size:8pt;text-decoration:none;" href="http://www.devanswer.com">Free Frontend</a></div>
<script>
var toastTriggerR = document.getElementById("liveToastRedBtn");
var toastTriggerG = document.getElementById("liveToastGreenBtn");
var toastLiveExampleG = document.getElementById("liveToastGreen");
var toastLiveExampleR = document.getElementById("liveToastRed");
if (toastTriggerR) {
    toastTriggerR.addEventListener("click", function () {
        var toast = new bootstrap.Toast(toastLiveExampleR);
        toast.show();
    });
}
if (toastTriggerG) {
    toastTriggerG.addEventListener("click", function () {
        var toast = new bootstrap.Toast(toastLiveExampleG);
        toast.show();
    });
}
let cart = [];
if (localStorage.cart) {
    cart = JSON.parse(localStorage.cart);
}
displayCart();
function displayCart() {
    const ul = document.getElementById("cart");
    ul.innerHTML = "";
    const cartItems = cart.map((item) => {
        const cartItem = document.createElement("li");
        cartItem.setAttribute(
            "class",
            "list-group-item d-flex justify-content-between align-items-center"
        );
        // image
        const imageItem = document.createElement("img");
        imageItem.setAttribute("src", item.image);
        imageItem.setAttribute("class", "img-width img-fluid");
        // name
        const nameItem = document.createElement("span");
        nameItem.innerHTML = item.name;
        // price
        const priceItem = document.createElement("span");
        priceItem.setAttribute("class", "badge bg-primary rounded-pill");
        priceItem.innerHTML = item.price;
        cartItem.appendChild(imageItem);
        cartItem.appendChild(nameItem);
        cartItem.appendChild(priceItem);
        ul.appendChild(cartItem);
    });
    console.log(cart);
    // Store
    localStorage.cart = JSON.stringify(cart);
}
function addToCart(shoe) {
    if (shoe === "GreenShoe") {
        cart.push({
            name: "green shoe",
            price: 50,
            image:
                "http://frontendfreecode.com/img/green-shoe.jpg"
        });
    } else {
        cart.push({
            name: "red shoe",
            price: 60,
            image:
                "http://frontendfreecode.com/img/red-shoe.jpg"
        });
    }
    displayCart();
}
</script>

</body>
</html>
Preview