Last active
December 11, 2015 04:59
-
-
Save nmanousos/4549391 to your computer and use it in GitHub Desktop.
Radiance quick-add
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
<script> | |
$(function() { | |
$('.product-grid-item').append('<a href="/cart" style="margin-top:5px;" class="btn quick-add">Add to Cart</a>') | |
$('.quick-add').click(function(e){ | |
e.preventDefault(); | |
var quick_add_item = this | |
if($(quick_add_item).text() == 'View cart') { | |
window.location = $(quick_add_item).attr('href') | |
} else { | |
var quick_add_id = $(this).parent().attr('id').split('product-').join('') | |
var hostname = document.location.hostname; | |
var protocol = document.location.protocol; | |
$.ajax({ | |
type: 'POST', | |
url: protocol+'//'+hostname+'/cart/add.js?quantity=1&id='+quick_add_id, | |
dataType: 'json', | |
success: function(){ | |
$(quick_add_item).text('View cart') | |
} | |
}) | |
} | |
}) | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment