2013-07-23 13:39:23 +00:00
|
|
|
$(document).ready(function () {
|
|
|
|
$('.oe_ecommerce').on('click', '.oe_product .btn, .oe_product_detail .btn', function (e) {
|
2013-07-01 16:12:47 +00:00
|
|
|
var $button = $(e.currentTarget);
|
2013-07-23 13:39:23 +00:00
|
|
|
var $product = $button.parents('.oe_product:first, .oe_product_detail:first');
|
2013-07-01 16:12:47 +00:00
|
|
|
var link = $button.hasClass('btn-inverse') ? '/shop/remove_cart' : '/shop/add_cart';
|
2013-07-23 13:39:23 +00:00
|
|
|
var $add = $product.find('.btn-success,.btn-primary');
|
|
|
|
var $remove = $product.find('.btn-inverse');
|
2013-07-01 16:12:47 +00:00
|
|
|
|
2013-07-02 12:06:25 +00:00
|
|
|
$.get(link, {'product_id': $button.data('id')}, function (result) {
|
|
|
|
var result = JSON.parse(result);
|
|
|
|
var quantity = parseInt(result.quantity);
|
2013-07-23 13:39:23 +00:00
|
|
|
$add.find('.oe_quantity')
|
|
|
|
.html(quantity);
|
|
|
|
$add.toggleClass('btn-primary', !quantity)
|
|
|
|
.toggleClass('btn-success', !!quantity);
|
2013-07-02 12:06:25 +00:00
|
|
|
$remove.toggleClass('oe_hidden', !quantity);
|
2013-07-23 13:39:23 +00:00
|
|
|
if ($('.oe_mycart').size() && !quantity) {
|
|
|
|
$product.remove()
|
2013-07-02 12:06:25 +00:00
|
|
|
}
|
|
|
|
$('.oe_ecommerce .oe_total').replaceWith(''+result.totalHTML);
|
2013-07-01 16:12:47 +00:00
|
|
|
});
|
|
|
|
});
|
2013-07-16 09:36:24 +00:00
|
|
|
|
|
|
|
|
2013-07-23 13:39:23 +00:00
|
|
|
var $checkout = $(".oe_ecommerce .oe_checkout");
|
|
|
|
$(".oe_ecommerce input[name='shipping_different']").change(function() {
|
|
|
|
$(".oe_ecommerce .js_shipping").toggle();
|
|
|
|
});
|
|
|
|
$(".oe_ecommerce .js_error_payment").click(function(e) {
|
|
|
|
var values = {};
|
2013-07-23 15:16:07 +00:00
|
|
|
$checkout.find(".js_inputs:not(:hidden) input:not(:checkbox), .js_inputs:not(:hidden) select, .js_signin_modal input").each(function() {
|
2013-07-23 13:39:23 +00:00
|
|
|
values[$(this).attr("name")] = $(this).val();
|
|
|
|
});
|
|
|
|
$checkout.find("input").css("border", "");
|
|
|
|
$.post('/shop/confirm_order', values, function (result) {
|
|
|
|
var result = JSON.parse(result);
|
2013-07-24 09:42:18 +00:00
|
|
|
console.log(result);
|
2013-07-23 13:39:23 +00:00
|
|
|
if (result.error.length) {
|
|
|
|
$inputs = $checkout.find("input[name='" + result.error.join("'], input[name='") + "']");
|
|
|
|
$inputs.css("border", "1px solid #dd0000");
|
|
|
|
$inputs.first().focus();
|
2013-07-23 16:13:19 +00:00
|
|
|
}
|
|
|
|
if (result.validation) {
|
2013-07-23 13:39:23 +00:00
|
|
|
var $form = $(e.currentTarget).parent().find("input[name='submit']").click();
|
2013-07-24 09:42:18 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
window.location.href = "/shop/confirmed";
|
|
|
|
}, 0);
|
2013-07-23 13:39:23 +00:00
|
|
|
}
|
|
|
|
});
|
2013-07-16 09:36:24 +00:00
|
|
|
});
|
2013-07-01 16:12:47 +00:00
|
|
|
});
|