Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. blackMonday: function(){
  2.       var cart = this.cart.model,
  3.           $discountNotice = $('.discount-notice > .discount-container');
  4.  
  5.       var currentTier;
  6.       var newTier = currentTier;
  7.  
  8.       // Remove the cookie and show the notice if hidden
  9.       function clearDiscountCookie() {
  10.         document.cookie = "no_discount_notice=false";
  11.         if ( !$('.discount-notice').hasClass('visible') ) {
  12.           $('.discount-notice').addClass('visible');
  13.         }
  14.       }
  15.  
  16.       // Listen to your cart when it's calling for you, listen to your cart there's nothing else you can do!
  17.       this.listenTo(cart, "change", function(){
  18.         // Less than 99
  19.         if(cart.get('total_price') < 9900){
  20.             $discountNotice.html('<p>Your Cart Total is <span>'  + Shopify.formatMoney(cart.get('total_price')) + '</span> - spend ' + (Shopify.formatMoney(9900 - cart.get('total_price'))) + ' more to receive <span>$15 off!</span></p>');
  21.             currentTier = 0;
  22.             if ( newTier != currentTier ) {
  23.               clearDiscountCookie();
  24.             }
  25.         }
  26.         // Between 99 and 150
  27.         else if ( cart.get('total_price') >= 9900 && cart.get('total_price') < 15000 ){
  28.             $discountNotice.html('<p>Hoorah! Receive $15 by using the discount code <span>H15</span> at the checkout — or spend ' + (Shopify.formatMoney(15000 - cart.get('total_price'))) + ' more for <span>$25 off!</span></p>');
  29.             currentTier = 1;
  30.             if ( newTier != currentTier ) {
  31.               clearDiscountCookie();
  32.             }
  33.         }
  34.         // Between 150 and 300
  35.         else if ( cart.get('total_price') >= 15000 && cart.get('total_price') < 30000 ){
  36.             $discountNotice.html('<p>Look at you go! Receive $25 by the using discount code <span>H25</span> at the checkout — or spend ' + (Shopify.formatMoney(30000 - cart.get('total_price'))) + ' more for <span>$60 off!</span></p>');
  37.             currentTier = 2;
  38.             if ( newTier != currentTier ) {
  39.               clearDiscountCookie();
  40.             }
  41.         }
  42.         // Over 300
  43.         else if ( cart.get('total_price') >= 30000 ){
  44.             $discountNotice.html('<p>Great success! Use discount code <span>H60</span> at the checkout for <span>$60 off!</span></p>');
  45.             currentTier = 3;
  46.             if ( newTier != currentTier ) {
  47.               clearDiscountCookie();
  48.             }
  49.         }
  50.       });
  51.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement