-
-
Save adardesign/17c7e3c629a30db13965 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
adrma.session.getSession.done(function gotSession(session) { | |
var buyNowButton, | |
productInfoContainer = $(".product-info-container"); | |
if (productInfoContainer.find(".vipProduct").length) { | |
//WEB-31841 | |
return; | |
} | |
if (session.cartCount === 0) { | |
productInfoContainer.find(".add-to-cart").after('<button class="radius add-to-cart button primary-dark action" data-action="silentAddToCart" type="button">Buy Now</button>'); | |
buyNowButton = productInfoContainer.find("[data-action='silentAddToCart']"); | |
} | |
}); | |
var failHandler = function(response) { | |
if (response.messages) { | |
adrma.notify.renderApiMessages(response); | |
} else { | |
adrma.notify.add({ | |
html: "Sorry, There was a error adding this item to the cart" | |
}); | |
} | |
}; | |
var updateBuyNowButton = function(data) { | |
var buyNowButton = $(".product-info-container").find("[data-action='silentAddToCart']"); | |
if (data.cartCount && buyNowButton.length) { | |
buyNowButton.remove(); | |
} | |
} | |
adrma.actions.add({ | |
silentAddToCart: function(e, jThis) { | |
adrma.atc.addToCart(jThis, { | |
silent: true | |
}).done(function(response) { | |
if (response.status === "success") { | |
location.href = "https://www.adorama.com/als.mvc/nspc/revised"; | |
} else { | |
failHandler(response) | |
} | |
}).fail(function(response) { | |
failHandler(response); | |
}); | |
} | |
}); | |
/*unified add to cart subscribe*/ | |
$.subscribe("cart/addedItem", function(e, response) { | |
updateBuyNowButton(response.data); | |
}); | |
/*AD add to cart subscribe*/ | |
$.subscribe("addToCart", function addToCarthandler(e, data) { | |
updateBuyNowButton(data); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment