Vue Shopping Cart – VueJS Shopping Cart – vue js e-commerce

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: '
' + ' {{ 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 }} ' + '
' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + //'' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
SKUNameDescriptionAmountPrice
{{ 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 }}

' + '
' + "

You are Most welcome in my youtube Channel Please shubscibe my channel. and give me feedBackMore Details......
Angularjs Example

Example

I 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.

Leave a Comment