2013-07-23 13:39:23 +00:00
|
|
|
$(document).ready(function () {
|
2014-06-25 12:03:23 +00:00
|
|
|
$('.oe_website_sale').each(function () {
|
|
|
|
var oe_website_sale = this;
|
|
|
|
|
|
|
|
var $shippingDifferent = $("input[name='shipping_different']", oe_website_sale);
|
2013-11-13 18:43:03 +00:00
|
|
|
if ($shippingDifferent.is(':checked')) {
|
2014-06-25 12:03:23 +00:00
|
|
|
$(".js_shipping", oe_website_sale).show();
|
2013-11-13 18:43:03 +00:00
|
|
|
}
|
|
|
|
$shippingDifferent.change(function () {
|
2014-06-25 12:03:23 +00:00
|
|
|
$(".js_shipping", oe_website_sale).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-25 12:03:23 +00:00
|
|
|
$(oe_website_sale).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-06-25 12:03:23 +00:00
|
|
|
$(oe_website_sale).on("change", ".oe_cart input.js_quantity", 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);
|
2014-06-25 09:31:39 +00:00
|
|
|
var line_id = parseInt($input.data('line-id'),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-06-25 09:31:39 +00:00
|
|
|
'line_id': line_id,
|
2014-05-02 14:01:52 +00:00
|
|
|
'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-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-06-25 09:31:39 +00:00
|
|
|
|
2014-02-21 17:28:16 +00:00
|
|
|
$input.val(data.quantity);
|
2014-06-25 09:31:39 +00:00
|
|
|
$('.js_quantity[data-line-id='+line_id+']').val(data.quantity).html(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
|
2014-06-25 12:03:23 +00:00
|
|
|
$(oe_website_sale).on('click', 'a.js_add_cart_json', 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-06-25 12:03:23 +00:00
|
|
|
$('.a-submit', oe_website_sale).off('click').on('click', function () {
|
2014-02-01 20:47:41 +00:00
|
|
|
$(this).closest('form').submit();
|
|
|
|
});
|
2014-06-25 12:03:23 +00:00
|
|
|
$('.form.js_attributes input, form.js_attributes select', oe_website_sale).on('change', function () {
|
2014-05-27 07:42:52 +00:00
|
|
|
$(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-25 12:03:23 +00:00
|
|
|
$('form.js_add_cart_json label', oe_website_sale).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
|
2014-06-25 12:03:23 +00:00
|
|
|
$('.css_attribute_color input', oe_website_sale).on('change', function (ev) {
|
2014-06-03 13:38:11 +00:00
|
|
|
$('.css_attribute_color').removeClass("active");
|
|
|
|
$('.css_attribute_color:has(input:checked)').addClass("active");
|
|
|
|
});
|
2013-10-03 10:47:01 +00:00
|
|
|
|
2014-06-19 08:53:30 +00:00
|
|
|
function price_to_str(price) {
|
|
|
|
price = Math.round(price * 100) / 100;
|
|
|
|
var dec = Math.round((price % 1) * 100);
|
|
|
|
return price + (dec ? '' : '.0') + (dec%10 ? '' : '0');
|
|
|
|
}
|
|
|
|
|
2014-06-25 12:03:23 +00:00
|
|
|
$(oe_website_sale).on('change', 'input.js_variant_change, select.js_variant_change', function (ev) {
|
2014-06-12 14:58:44 +00:00
|
|
|
var $ul = $(this).parents('ul.js_add_cart_variants:first');
|
2014-06-25 09:31:39 +00:00
|
|
|
var $parent = $ul.closest('.js_product');
|
2014-06-24 15:37:13 +00:00
|
|
|
var $product_id = $parent.find('input.product_id').first();
|
2014-06-19 08:53:30 +00:00
|
|
|
var $price = $parent.find(".oe_price:first .oe_currency_value");
|
|
|
|
var $default_price = $parent.find(".oe_default_price:first .oe_currency_value");
|
2014-06-12 14:58:44 +00:00
|
|
|
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-19 08:53:30 +00:00
|
|
|
$price.html(price_to_str(variant_ids[k][2]));
|
|
|
|
$default_price.html(price_to_str(variant_ids[k][3]));
|
|
|
|
$default_price.parent().toggle(variant_ids[k][3]-variant_ids[k][2]>0.2);
|
2014-06-12 14:58:44 +00:00
|
|
|
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-25 09:31:39 +00:00
|
|
|
$input.closest("label").addClass("css_not_available");
|
2014-06-12 14:58:44 +00:00
|
|
|
$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-24 15:37:13 +00:00
|
|
|
$product_id.val(product_id);
|
2014-06-12 14:58:44 +00:00
|
|
|
$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-24 15:37:13 +00:00
|
|
|
$product_id.val(0);
|
2014-06-12 14:58:44 +00:00
|
|
|
$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-25 12:03:23 +00:00
|
|
|
$('ul.js_add_cart_variants', oe_website_sale).each(function () {
|
2014-06-12 14:58:44 +00:00
|
|
|
$('input.js_variant_change, select.js_variant_change', this).first().trigger('change');
|
|
|
|
});
|
|
|
|
|
2014-06-25 12:03:23 +00:00
|
|
|
$(oe_website_sale).on('change', "select[name='country_id']", function () {
|
2014-06-17 09:33:28 +00:00
|
|
|
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();
|
2014-06-25 12:03:23 +00:00
|
|
|
$(oe_website_sale).on('change', "select[name='shipping_country_id']", function () {
|
2014-06-17 09:33:28 +00:00
|
|
|
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();
|
2014-06-25 12:03:23 +00:00
|
|
|
});
|
2013-08-05 12:38:36 +00:00
|
|
|
});
|