Vue Shopping Cart – VueJS Shopping Cart – vue js e-commerce
In this Post We Will Explain About is Vue Shopping Cart – VueJS Shopping Cart – vue js e-commerce With Example and Demo.Welcome on Pakainfo.com – Vue Shopping Cart, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Creating an Online Shopping Cart Mechanism in vue js Example
In this post we will show you Best way to implement Vue Shopping Cart, hear for simple shopping cart in vue js source code with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.
VueJS Shopping Cart Application
In this Example,First of all Add or Inluce External Libs Like as a(jQuery, css etc..), and then create a simple index.php or index.html page.After that crate a simple javascript file like as a index.js or main.js, It is also add your web-application First Header Part to some priorty set.After that Include your relavant CSS Class.
index.html
Vue.js Shopping Cart Step By step Vue Shopping Cart Application
index.js
//@TODO NOTIFICATIONS Vue.component('Items', { ready: function () { var self = this; document.addEventListener("keydown", function(e) { if (self.showModal && e.keyCode == 37) { self.changeProductInModal("prev"); } else if (self.showModal && e.keyCode == 39) { self.changeProductInModal("next"); } else if (self.showModal && e.keyCode == 27) { self.hideModal(); } }); }, template: "Items
" + "" + "" + "" + "" + "" + "{{ item.item }}" + "{{ item.item_desc }}" + "{{ item.item_price | currency }}" + "" + "", props: ['itemData', 'cart', 'live_tax', 'sub_total_cart', 'total_cart'], data: function() { return { showModal: false, data_model: {}, liveAmount_modal: 1, timeout: "", mousestop: "" } }, methods: { Cart_toAdd: function(item) { var found = false; for (var i = 0; i < vue.cart.length; i++) { if (vue.cart[i].sku === item.sku) { var newProduct = vue.cart[i]; newProduct.item_qty = newProduct.item_qty + 1; vue.cart.$set(i, newProduct); //console.log("DUPLICATE", vue.cart[i].item + "'s item_qty is now: " + vue.cart[i].item_qty); found = true; break; } } if(!found) { item.item_qty = 1; vue.cart.push(item); } vue.sub_total_cart = vue.sub_total_cart + item.item_price; vue.total_cart = vue.sub_total_cart + (vue.live_tax * vue.sub_total_cart); vue.liveCheckout = true; }, modalAddToCart: function(data_model) { var self = this; for(var i = 0; i < self.liveAmount_modal; i++) { self.Cart_toAdd(data_model); } self.liveAmount_modal = 1; }, viewItems: function(item) { var self = this; //self.data_model = item; self.data_model = (JSON.parse(JSON.stringify(item))); self.showModal = true; }, changeProductInModal: function(direction) { var self = this, productsLength = vue.itemData.length, currentProduct = self.data_model.sku, newProductId, newProduct; if(direction === "next") { newProductId = currentProduct + 1; if(currentProduct >= productsLength) { newProductId = 1; } } else if(direction === "prev") { newProductId = currentProduct - 1; if(newProductId === 0) { newProductId = productsLength; } } //console.log(direction, newProductId); for (var i = 0; i < productsLength; i++) { if (vue.itemData[i].sku === newProductId) { self.viewItems(vue.itemData[i]); } } }, hideModal: function() { //hide modal and empty modal data var self = this; self.data_model = {}; self.showModal = false; }, changeImage: function(image) { var self = this; self.data_model.image = image; }, imageMouseOver: function(event) { event.target.style.transform = "scale(2)"; }, imageMouseMove: function(event) { var self = this; event.target.style.transform = "scale(2)"; self.timeout = setTimeout(function() { event.target.style.transformOrigin = ((event.pageX - event.target.getBoundingClientRect().left) / event.target.getBoundingClientRect().width) * 100 + '% ' + ((event.pageY - event.target.getBoundingClientRect().top - window.pageYOffset) / event.target.getBoundingClientRect().height) * 100 + "%"; }, 50); self.mouseStop = setTimeout(function() { event.target.style.transformOrigin = ((event.pageX - event.target.getBoundingClientRect().left) / event.target.getBoundingClientRect().width) * 100 + '% ' + ((event.pageY - event.target.getBoundingClientRect().top - window.pageYOffset) / event.target.getBoundingClientRect().height) * 100 + "%"; }, 100); }, imageMouseOut: function(event) { event.target.style.transform = "scale(1)"; } } }); Vue.component('cart', { template: '" + "" + "" + "" + "" + "" + "" + "" + "" + "{{ data_model.item }}" + "{{ data_model.item_desc }}" + "{{ data_model.item_details }}" + "{{ data_model.item_price | currency }}
" + "" + "" + "" + "' + ' {{ cart | live_size_cart }} ' + '' + '' + '' + '
' + ' ' + '' + ' ' + ' {{ cart[$index].item_qty }} ' + '' + ' {{ cart[$index] | customPluralize }} ' + '{{ item.item_price | currency }} ' + '' + '' + '
{{ sub_total_cart | currency }}
' + '' + '', props: ['liveCheckout', 'cart', 'live_size_cart', 'sub_total_cart', 'live_tax', 'total_cart'], data: function() { return { cartShow: false } }, filters: { customPluralize: function(cart) { var item_newname; if(cart.item_qty > 1) { if(cart.item === "angular") { item_newname = cart.item + "es"; } else if(cart.item === "vuejs") { item_newname = cart.item + "ies"; item_newname = item_newname.replace("y", ""); } else { item_newname = cart.item + "s"; } return item_newname; } return cart.item; }, live_size_cart: function(cart) { var live_size_cart = 0; for (var i = 0; i < cart.length; i++) { live_size_cart += cart[i].item_qty; } return live_size_cart; } }, methods: { deleteItem: function(item) { vue.cart.$remove(item); vue.sub_total_cart = vue.sub_total_cart - (item.item_price * item.item_qty); vue.total_cart = vue.sub_total_cart + (vue.live_tax * vue.sub_total_cart); if(vue.cart.length <= 0) { vue.liveCheckout = false; } }, clearCart: function() { vue.cart = []; vue.sub_total_cart = 0; vue.total_cart = 0; vue.liveCheckout = false; this.cartShow = false; }, changeQty: function(item, direction) { var qtyChange; for (var i = 0; i < vue.cart.length; i++) { if (vue.cart[i].sku === item.sku) { var newProduct = vue.cart[i]; if(direction === "incriment") { newProduct.item_qty = newProduct.item_qty + 1; vue.cart.$set(i, newProduct); } else { newProduct.item_qty = newProduct.item_qty - 1; if(newProduct.item_qty == 0) { vue.cart.$remove(newProduct); } else { vue.cart.$set(i, newProduct); } } } } if(direction === "incriment") { vue.sub_total_cart = vue.sub_total_cart + item.item_price; } else { vue.sub_total_cart = vue.sub_total_cart - item.item_price; } vue.total_cart = vue.sub_total_cart + (vue.live_tax * vue.sub_total_cart); if(vue.cart.length <= 0) { vue.liveCheckout = false; } }, propagateCheckout: function() { vue.$dispatch("checkoutRequest"); } } }); Vue.component('checkout-area', { template: "Checkout Area
" + '' + ' {{ cart | live_size_cart }} ' + '' + "' + '' + '
' + '' + ' ' + '' + '' + 'SKU ' + 'Name ' + 'Description ' + 'Amount ' + 'Price ' + '' + ' ' + //'' + '{{ item.sku }} ' + '{{ item.item }} ' + '{{ item.item_desc }} ' + '{{ cart[$index].item_qty }} ' + '{{ item.item_price | currency }} ' + '' + ' ' + '' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + '' + ' ' + ' ' + ' Subtotal: ' + '' + ' {{ sub_total_cart | currency }}
' + ' ' + '' + ' ' + ' ' + ' Tax: ' + '' + ' {{ total_cart - sub_total_cart | currency }}
' + ' ' + '' + '' + ' ' + ' ' + ' Total: ' + '' + ' {{ total_cart | currency }}
" + "" + "" + "" + "", props: ['cart', 'live_size_cart', 'sub_total_cart', 'live_tax', 'total_cart'], data: function() { return { showModal: false } }, filters: { customPluralize: function(cart) { var item_newname; if(cart.item_qty > 1) { item_newname = cart.item + "s"; return item_newname; } return cart.item; }, live_size_cart: function(cart) { var live_size_cart = 0; for (var i = 0; i < cart.length; i++) { live_size_cart += cart[i].item_qty; } return live_size_cart; } }, methods: { deleteItem: function(item) { vue.cart.$remove(item); vue.sub_total_cart = vue.sub_total_cart - (item.item_price * item.item_qty); vue.total_cart = vue.sub_total_cart + (vue.live_tax * vue.sub_total_cart); if(vue.cart.length <= 0) { vue.liveCheckout = false; } }, checkoutModal: function() { var self = this; self.showModal = true; console.log("CHECKOUT", self.total_cart); }, hideModal: function() { var self = this; self.showModal = false; } }, events: { "checkoutRequest": function() { var self = this; self.checkoutModal(); } } }); Vue.config.debug = false; var vue = new Vue({ el: "#vue", data: { itemData: [ { sku: 1, item: "angular", image: "https://www.pakainfo.com/w3free/img/angular.jpg", images: [ { image: "https://www.pakainfo.com/w3free/img/angular.jpg" }, { image: "https://www.pakainfo.com/w3free/img/angular.jpg" }, { image: "https://www.pakainfo.com/w3free/img/angular.jpg" }, { image: "https://www.pakainfo.com/w3free/img/angular.jpg" } ], item_desc: "In this post, live24u is a angular", item_details: "In this post, live24u is blog post some information on monkies would step by step. In this post, live24u angular done seent some shit.", item_price: 15.50 }, { sku: 2, item: "Kitten", image: "https://www.pakainfo.com/w3free/img/angular.jpg", item_desc: "In this post, live24u is a kitten", item_details: "In this post, live24u is blog post some information on kittens would step by step. Shout out kittens for being adorable.", item_price: 100 }, { sku: 3, item: "vuejs", image: "https://www.pakainfo.com/w3free/img/angular.jpg", item_desc: "In this post, live24u is a vuejs", item_details: "In this post, live24u is blog post some information on vuejs would step by step. Damn nature, you vuejs.", item_price: 15 }, { sku: 4, item: "vuejs", image: "https://www.pakainfo.com/w3free/img/angular.jpg", item_desc: "In this post, live24u is a puppy", item_details: "In this post, live24u is blog post some information on puppies would step by step. Shout out puppies for being adorable.", item_price: 5 }, { sku: 5, item: "Apple", image: "https://www.pakainfo.com/w3free/img/angular.jpg", item_desc: "In this post, live24u is an apple", item_details: "In this post, live24u is blog post some information on apples would step by step. Shout out apples for being implementation.", item_price: 1 }, { sku: 6, item: "Orange", image: "https://www.pakainfo.com/w3free/img/angular.jpg", item_desc: "In this post, live24u is an orange", item_details: "In this post, live24u is blog post some information on oranges would step by step. Shout out oranges for being implementation.", item_price: 1.1 }, { sku: 7, item: "angular", image: "https://www.pakainfo.com/w3free/img/angular.jpg", item_desc: "In this post, live24u is a peach", item_details: "In this post, live24u is blog post some information on peaches would step by step. Shout out peaches for being implementation.", item_price: 1.5 }, { sku: 8, item: "Mango", image: "https://www.pakainfo.com/w3free/img/angular.jpg", item_desc: "In this post, live24u is a mango", item_details: "In this post, live24u is blog post some information on mangos would step by step. Shout out mangos for being implementation.", item_price: 2 }, { sku: 9, item: "Cognac", image: "https://www.pakainfo.com/w3free/img/angular.jpg", item_desc: "In this post, live24u is a glass of cognac", item_details: "In this post, live24u is blog post some information on cognac would step by step. I'm like hey whats up, hello.", item_price: 17.38 }, { sku: 10, item: "Chain", image: "https://www.pakainfo.com/w3free/img/angular.jpg", item_desc: "In this post, live24u is a chain", item_details: "In this post, live24u is blog post some item_details on chains would step by step. 2Chainz but I got me a few on.", item_price: 17.38 } ], liveCheckout: false, cart: [], sub_total_cart: 0, live_tax: 0.065, total_cart: 0 }, events: { "checkoutRequest": function() { vue.$broadcast("checkoutRequest"); } } });Checkout
" + "We accept:
" + "Subtotal: {{ sub_total_cart | currency }}
" + "Tax: {{ total_cart - sub_total_cart | currency }} " + "
" + "Total: {{ total_cart | currency }}
In this post, live24u is blog post our payment processor goes" + "You are Most welcome in my youtube Channel Please shubscibe my channel. and give me feedBackMore Details......
Angularjs ExampleI hope you have Got What is simple ecommerce shopping cart vue js with PHP And how it works.I would Like to have FeaeBack From My Blog(Pakainfo.com) readers.Your Valuable FeedBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.