2013-07-23 13:39:23 +00:00
|
|
|
$(document).ready(function () {
|
2013-11-13 18:43:03 +00:00
|
|
|
var $shippingDifferent = $(".oe_website_sale input[name='shipping_different']");
|
|
|
|
if ($shippingDifferent.is(':checked')) {
|
|
|
|
$(".oe_website_sale .js_shipping").show();
|
|
|
|
}
|
|
|
|
$shippingDifferent.change(function () {
|
2013-08-13 10:39:48 +00:00
|
|
|
$(".oe_website_sale .js_shipping").toggle();
|
2013-07-23 13:39:23 +00:00
|
|
|
});
|
2013-08-08 14:23:41 +00:00
|
|
|
|
2013-09-02 15:54:31 +00:00
|
|
|
// change for css
|
2014-06-13 13:50:08 +00:00
|
|
|
$(document).on('mouseup touchend', '.js_publish', function (ev) {
|
2013-09-02 15:54:31 +00:00
|
|
|
$(ev.currentTarget).parents(".thumbnail").toggleClass("disabled");
|
|
|
|
});
|
2013-09-03 08:28:14 +00:00
|
|
|
|
2014-01-30 23:39:51 +00:00
|
|
|
$(".oe_website_sale .oe_cart input.js_quantity").change(function () {
|
2013-09-03 12:34:38 +00:00
|
|
|
var $input = $(this);
|
2013-12-31 13:21:00 +00:00
|
|
|
var value = parseInt($input.val(), 10);
|
2013-09-10 11:51:59 +00:00
|
|
|
if (isNaN(value)) value = 0;
|
2014-02-21 17:28:16 +00:00
|
|
|
openerp.jsonRpc("/shop/cart/update_json", 'call', {
|
2014-05-02 14:01:52 +00:00
|
|
|
'line_id': parseInt($input.data('line-id'),10),
|
|
|
|
'product_id': parseInt($input.data('product-id'),10),
|
2014-02-21 17:28:16 +00:00
|
|
|
'set_qty': value})
|
2013-09-26 14:07:50 +00:00
|
|
|
.then(function (data) {
|
2014-02-21 17:28:16 +00:00
|
|
|
if (!data.quantity) {
|
2013-10-03 11:04:11 +00:00
|
|
|
location.reload();
|
2014-02-06 14:07:46 +00:00
|
|
|
return;
|
2013-09-26 14:07:50 +00:00
|
|
|
}
|
2014-06-17 12:23:15 +00:00
|
|
|
if (data.option_ids.length) {
|
|
|
|
_.each(data.option_ids, function (line_id) {
|
|
|
|
$(".js_quantity[data-line-id="+line_id+"]").text(data.quantity);
|
|
|
|
});
|
|
|
|
}
|
2014-02-25 12:57:36 +00:00
|
|
|
var $q = $(".my_cart_quantity");
|
|
|
|
$q.parent().parent().removeClass("hidden", !data.quantity);
|
|
|
|
$q.html(data.cart_quantity).hide().fadeIn(600);
|
2014-02-21 17:28:16 +00:00
|
|
|
$input.val(data.quantity);
|
2014-02-25 12:57:36 +00:00
|
|
|
$("#cart_total").replaceWith(data['website_sale.total']);
|
2013-09-26 14:07:50 +00:00
|
|
|
});
|
2013-09-04 08:49:58 +00:00
|
|
|
});
|
2013-11-13 18:43:03 +00:00
|
|
|
|
2013-09-03 12:34:38 +00:00
|
|
|
// hack to add and rome from cart with json
|
2013-10-02 16:28:10 +00:00
|
|
|
$('.oe_website_sale a.js_add_cart_json').on('click', function (ev) {
|
2013-09-03 12:34:38 +00:00
|
|
|
ev.preventDefault();
|
2013-09-26 14:07:50 +00:00
|
|
|
var $link = $(ev.currentTarget);
|
2014-02-21 17:28:16 +00:00
|
|
|
var $input = $link.parent().parent().find("input");
|
2014-06-13 10:47:54 +00:00
|
|
|
var min = parseFloat($input.data("min") || 0);
|
|
|
|
var max = parseFloat($input.data("max") || Infinity);
|
2014-06-12 14:58:44 +00:00
|
|
|
var quantity = ($link.has(".fa-minus").length ? -1 : 1) + parseFloat($input.val(),10);
|
2014-06-13 10:47:54 +00:00
|
|
|
$input.val(quantity > min ? (quantity < max ? quantity : max) : min);
|
|
|
|
$('input[name="'+$input.attr("name")+'"]').val(quantity > min ? (quantity < max ? quantity : max) : min);
|
2014-02-21 17:28:16 +00:00
|
|
|
$input.change();
|
2013-09-03 12:34:38 +00:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2014-02-01 20:47:41 +00:00
|
|
|
$('.a-submit').on('click', function () {
|
|
|
|
$(this).closest('form').submit();
|
|
|
|
});
|
2014-05-27 07:42:52 +00:00
|
|
|
$('form.js_attributes input, form.js_attributes select').on('change', function () {
|
|
|
|
$(this).closest("form").submit();
|
|
|
|
});
|
2014-02-01 20:47:41 +00:00
|
|
|
|
2013-10-03 10:47:01 +00:00
|
|
|
// change price when they are variants
|
2014-06-13 13:50:08 +00:00
|
|
|
$('form.js_add_cart_json label').on('mouseup touchend', function (ev) {
|
2014-06-12 14:58:44 +00:00
|
|
|
var $label = $(this);
|
|
|
|
var $price = $label.parents("form:first").find(".oe_price .oe_currency_value");
|
2013-10-03 10:47:01 +00:00
|
|
|
if (!$price.data("price")) {
|
2013-10-16 15:08:37 +00:00
|
|
|
$price.data("price", parseFloat($price.text()));
|
2013-10-03 10:47:01 +00:00
|
|
|
}
|
2014-05-27 07:42:52 +00:00
|
|
|
var value = $price.data("price") + parseFloat($label.find(".badge span").text() || 0);
|
|
|
|
var dec = value % 1;
|
|
|
|
$price.html(value + (dec < 0.01 ? ".00" : (dec < 1 ? "0" : "") ));
|
2013-10-03 10:47:01 +00:00
|
|
|
});
|
2014-06-03 13:38:11 +00:00
|
|
|
// hightlight selected color
|
|
|
|
$('.css_attribute_color input').on('change', function (ev) {
|
|
|
|
$('.css_attribute_color').removeClass("active");
|
|
|
|
$('.css_attribute_color:has(input:checked)').addClass("active");
|
|
|
|
});
|
2013-10-03 10:47:01 +00:00
|
|
|
|
2014-06-12 14:58:44 +00:00
|
|
|
$('input.js_variant_change, select.js_variant_change').change(function (ev) {
|
|
|
|
var $ul = $(this).parents('ul.js_add_cart_variants:first');
|
|
|
|
var $parent = $ul.parents('.js_product:first');
|
|
|
|
var $porduct_id = $parent.find('input.product_id, input.optional_product_id').first();
|
|
|
|
var $price = $parent.find(".oe_price .oe_currency_value:first");
|
|
|
|
var variant_ids = $ul.data("attribute_value_ids");
|
2014-05-27 07:42:52 +00:00
|
|
|
var values = [];
|
2014-06-12 14:58:44 +00:00
|
|
|
$parent.find('input.js_variant_change:checked, select.js_variant_change').each(function () {
|
2014-05-27 07:42:52 +00:00
|
|
|
values.push(+$(this).val());
|
|
|
|
});
|
2014-06-12 14:58:44 +00:00
|
|
|
|
|
|
|
$parent.find("label").removeClass("text-muted css_not_available");
|
|
|
|
|
|
|
|
var product_id = false;
|
2014-05-27 07:42:52 +00:00
|
|
|
for (var k in variant_ids) {
|
|
|
|
if (_.isEqual(variant_ids[k][1], values)) {
|
2014-06-16 08:53:34 +00:00
|
|
|
var dec = Math.round((variant_ids[k][2] % 1) * 100);
|
2014-06-12 14:58:44 +00:00
|
|
|
$price.html(variant_ids[k][2] + (dec ? '' : '.0') + (dec%10 ? '' : '0'));
|
|
|
|
product_id = variant_ids[k][0];
|
2014-05-27 07:42:52 +00:00
|
|
|
break;
|
2013-10-15 08:27:26 +00:00
|
|
|
}
|
2014-05-27 07:42:52 +00:00
|
|
|
}
|
|
|
|
|
2014-06-12 14:58:44 +00:00
|
|
|
$parent.find("input.js_variant_change:radio, select.js_variant_change").each(function () {
|
|
|
|
var $input = $(this);
|
|
|
|
var id = +$input.val();
|
2014-05-27 07:42:52 +00:00
|
|
|
var values = [id];
|
2014-06-12 14:58:44 +00:00
|
|
|
|
|
|
|
$parent.find("ul:not(:has(input.js_variant_change[value='" + id + "'])) input.js_variant_change:checked, select").each(function () {
|
2014-05-27 07:42:52 +00:00
|
|
|
values.push(+$(this).val());
|
|
|
|
});
|
2014-06-12 14:58:44 +00:00
|
|
|
|
2014-05-27 07:42:52 +00:00
|
|
|
for (var k in variant_ids) {
|
|
|
|
if (!_.difference(values, variant_ids[k][1]).length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-06-12 14:58:44 +00:00
|
|
|
$input.parents("label:first").addClass("css_not_available");
|
|
|
|
$input.find("option[value='" + id + "']").addClass("css_not_available");
|
2013-10-15 08:27:26 +00:00
|
|
|
});
|
2014-05-27 07:42:52 +00:00
|
|
|
|
2014-06-12 14:58:44 +00:00
|
|
|
if (product_id) {
|
2014-06-13 07:32:28 +00:00
|
|
|
$parent.removeClass("css_not_available");
|
2014-06-12 14:58:44 +00:00
|
|
|
$porduct_id.val(product_id);
|
|
|
|
$parent.find(".js_check_product").removeAttr("disabled");
|
2014-05-27 07:42:52 +00:00
|
|
|
} else {
|
2014-06-13 07:32:28 +00:00
|
|
|
$parent.addClass("css_not_available");
|
2014-06-12 14:58:44 +00:00
|
|
|
$porduct_id.val(0);
|
|
|
|
$parent.find(".js_check_product").attr("disabled", "disabled");
|
2014-05-27 07:42:52 +00:00
|
|
|
}
|
2013-10-15 08:27:26 +00:00
|
|
|
});
|
2014-06-12 14:58:44 +00:00
|
|
|
$('ul.js_add_cart_variants').each(function () {
|
|
|
|
$('input.js_variant_change, select.js_variant_change', this).first().trigger('change');
|
|
|
|
});
|
|
|
|
|
2014-06-13 11:59:28 +00:00
|
|
|
$('#modal_optional_products').on('show.bs.modal', function () {
|
|
|
|
var $confirm = $('#product_confirmation .js_attributes');
|
|
|
|
if (!$confirm.size()) return;
|
|
|
|
$confirm.empty();
|
|
|
|
$('.js_add_cart_variants:first ul:first > li').each(function () {
|
|
|
|
var $li = $(this);
|
|
|
|
var $span = $("<div><span></span>: <span></span></div>");
|
2014-06-16 08:53:34 +00:00
|
|
|
var attr = $li.children().first().text();
|
|
|
|
var value = $li.find("label:has(input:checked) span:first").text();
|
|
|
|
if (!/\S/.test(value)) {
|
|
|
|
value = $li.find("label:has(input:checked) input").attr("title");
|
|
|
|
}
|
|
|
|
$span.children().first().text( attr );
|
|
|
|
$span.children().last().text( value );
|
2014-06-13 11:59:28 +00:00
|
|
|
$confirm.append($span);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-06-13 10:31:41 +00:00
|
|
|
$("a.js_add, a.js_remove").click(function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
var $parent = $(this).parents('.js_product:first');
|
|
|
|
$parent.find("a.js_add, span.js_remove").toggleClass("hidden");
|
|
|
|
$parent.find("input.js_optional_same_quantity").val( $(this).hasClass("js_add") ? 1 : 0 );
|
2014-06-16 08:53:34 +00:00
|
|
|
var $remove = $parent.find(".js_remove");
|
|
|
|
});
|
|
|
|
|
|
|
|
$("input.js_quantity").change(function (event) {
|
|
|
|
var qty = parseFloat($(this).val());
|
|
|
|
if (qty === 1) {
|
|
|
|
$(".js_remove .js_items").addClass("hidden");
|
|
|
|
$(".js_remove .js_item").removeClass("hidden");
|
|
|
|
} else {
|
|
|
|
$(".js_remove .js_items").removeClass("hidden").text($(".js_remove .js_items").text().replace(/[0-9.,]+/, qty));
|
|
|
|
$(".js_remove .js_item").addClass("hidden");
|
|
|
|
}
|
2014-06-13 10:31:41 +00:00
|
|
|
});
|
2014-06-16 08:53:34 +00:00
|
|
|
|
2014-06-13 10:31:41 +00:00
|
|
|
|
2014-06-12 14:58:44 +00:00
|
|
|
$('#product_detail form[action^="/shop/cart/update"] .a-submit').off("click").click(function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
var $link = $(this);
|
|
|
|
var $form = $link.parents("form:first");
|
2014-06-13 10:47:54 +00:00
|
|
|
var quantity = parseInt($('input[name="add_qty"]:last').val() || 1, 10);
|
2014-06-12 14:58:44 +00:00
|
|
|
var defs = [];
|
|
|
|
$link.attr('disabled', 'disabled');
|
|
|
|
$.when.apply($.when, defs).then(function () {
|
2014-06-13 10:31:41 +00:00
|
|
|
if ($link.hasClass("js_goto_shop")) {
|
|
|
|
$form.prepend('<input type="hidden" name="goto_shop" value="1"/>');
|
|
|
|
}
|
2014-06-12 14:58:44 +00:00
|
|
|
$form.submit();
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
2014-05-27 07:42:52 +00:00
|
|
|
|
2014-06-17 09:33:28 +00:00
|
|
|
|
|
|
|
$(".oe_website_sale select[name='country_id']").change(function () {
|
|
|
|
var $select = $("select[name='state_id']");
|
|
|
|
$select.find("option:not(:first)").hide();
|
|
|
|
var nb = $select.find("option[data-country_id="+($(this).val() || 0)+"]").show().size();
|
|
|
|
$select.parent().toggle(nb>1);
|
|
|
|
}).change();
|
|
|
|
$(".oe_website_sale select[name='shipping_country_id']").change(function () {
|
|
|
|
var $select = $("select[name='shipping_state_id']");
|
|
|
|
$select.find("option:not(:first)").hide();
|
|
|
|
var nb = $select.find("option[data-country_id="+($(this).val() || 0)+"]").show().size();
|
|
|
|
$select.parent().toggle(nb>1);
|
|
|
|
}).change();
|
|
|
|
|
2013-08-05 12:38:36 +00:00
|
|
|
});
|