Last active
April 2, 2016 13:44
-
-
Save d1i1m1o1n/cbce167297d8e79fe58f to your computer and use it in GitHub Desktop.
For bitrix ajax add to cart action
This file contains hidden or 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
//Добавить товар в корзину | |
$(document).on('click', '.pi__order-bucket, .tovar__bucket, .item-found__bucket', function(e){ | |
e.preventDefault(); | |
var id = $(this).data('id'), | |
price = $(this).data('price'), | |
name = $(this).data('name'), | |
count = $('.product2cart_count_'+id).text(), | |
src = $('.product2cart_img_'+id).attr('src'), | |
bg = ($('.product2cart_img_'+id).hasClass('empty') ? "#fff url("+src+")" : "url("+src+") no-repeat center"); | |
$.ajax({ | |
url: '/catalog/add2cart.php', | |
data: { | |
action: "ADD2BASKET", | |
count: count, | |
id: id, | |
price: price, | |
name: name | |
}, | |
}) | |
.done(function() { | |
//console.log("success"); | |
$.animate_from_to('.product2cart_img_'+id, ".page-header__bucket", { | |
initial_css: { | |
background: bg | |
} | |
}); | |
}) | |
.fail(function() { | |
alert("Ошибка, довар не добавлен в корзину!"); | |
}) | |
.always(function(data) { | |
setTimeout(function() { | |
$('.page-header__bucket').html(data); | |
}, 1000); | |
}); | |
}); | |
//Купить товар в один клик | |
$(document).on('click', '.item-found__click', function(e) { | |
e.preventDefault(); | |
var id = $(this).data('id'), | |
price = $(this).data('price'), | |
name = $(this).data('name'), | |
count = $('.product2cart_count_'+id).text(); | |
window.open("/catalog/add2cart.php?id="+id+"&price="+price+"&name="+name+"&count="+count+"&action=BUY", "_self"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment