2013-07-23 13:39:23 +00:00
|
|
|
$(document).ready(function () {
|
2014-08-01 15:11:20 +00:00
|
|
|
var $shippingDifferent = $(".oe_website_sale select[name='shipping_id']");
|
|
|
|
$shippingDifferent.change(function (event) {
|
|
|
|
var value = +$shippingDifferent.val();
|
|
|
|
var data = $shippingDifferent.find("option:selected").data();
|
|
|
|
var $snipping = $(".oe_website_sale .js_shipping");
|
|
|
|
var $inputs = $snipping.find("input,select");
|
|
|
|
|
|
|
|
$snipping.toggle(!!value);
|
|
|
|
$inputs.attr("readonly", value <= 0 ? null : "readonly" ).prop("readonly", value <= 0 ? null : "readonly" );
|
|
|
|
|
|
|
|
$inputs.each(function () {
|
|
|
|
$(this).val( data[$(this).attr("name")] || "" );
|
|
|
|
});
|
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
|
|
|
|
$(document).on('mouseup', '.js_publish', function (ev) {
|
|
|
|
$(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-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");
|
|
|
|
$input.val(($link.has(".fa-minus").length ? -1 : 1) + parseFloat($input.val(),10));
|
|
|
|
$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-05-27 07:42:52 +00:00
|
|
|
var $price = $(".oe_price .oe_currency_value");
|
2013-10-03 10:47:01 +00:00
|
|
|
$('form.js_add_cart_json label').on('mouseup', function (ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
var $label = $(ev.currentTarget);
|
|
|
|
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-05-27 07:42:52 +00:00
|
|
|
var $form_var = $('form.js_add_cart_variants');
|
2014-05-28 17:42:15 +00:00
|
|
|
var variant_ids = $form_var.data("attribute_value_ids");
|
2014-05-27 07:42:52 +00:00
|
|
|
$form_var.on('change', 'input, select', function (ev) {
|
|
|
|
var values = [];
|
|
|
|
$form_var.find("label").removeClass("text-muted css_not_available");
|
|
|
|
$form_var.find(".a-submit").removeProp("disabled");
|
2013-10-15 08:27:26 +00:00
|
|
|
|
2014-05-27 07:42:52 +00:00
|
|
|
$form_var.find('input:checked, select').each(function () {
|
|
|
|
values.push(+$(this).val());
|
|
|
|
});
|
|
|
|
var available = false;
|
|
|
|
for (var k in variant_ids) {
|
|
|
|
if (_.isEqual(variant_ids[k][1], values)) {
|
|
|
|
var dec = variant_ids[k][2] % 1;
|
|
|
|
$('input[name="product_id"]').val(variant_ids[k][0]);
|
|
|
|
$price.html(variant_ids[k][2] + (dec < 0.01 ? ".00" : (dec < 1 ? "0" : "") ));
|
|
|
|
available = true;
|
|
|
|
break;
|
2013-10-15 08:27:26 +00:00
|
|
|
}
|
2014-05-27 07:42:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$form_var.find("input:radio, select").each(function () {
|
|
|
|
var id = +$(this).val();
|
|
|
|
var values = [id];
|
|
|
|
$form_var.find(">ul>li:not(:has(input[value='" + id + "'])) input:checked, select").each(function () {
|
|
|
|
values.push(+$(this).val());
|
|
|
|
});
|
|
|
|
for (var k in variant_ids) {
|
|
|
|
if (!_.difference(values, variant_ids[k][1]).length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$(this).parents("label:not(.css_attribute_color):first").addClass("text-muted");
|
|
|
|
$(this).parents("label.css_attribute_color:first").addClass("css_not_available");
|
|
|
|
$(this).find("option[value='" + id + "']").addClass("css_not_available");
|
2013-10-15 08:27:26 +00:00
|
|
|
});
|
2014-05-27 07:42:52 +00:00
|
|
|
|
|
|
|
if (available) {
|
|
|
|
$(".oe_price_h4").removeClass("hidden");
|
|
|
|
$(".oe_not_available").addClass("hidden");
|
|
|
|
} else {
|
|
|
|
$(".oe_price_h4").addClass("hidden");
|
|
|
|
$(".oe_not_available").removeClass("hidden");
|
|
|
|
$form_var.find('input[name="product_id"]').val(0);
|
|
|
|
$form_var.find(".a-submit").prop("disabled", "disabled");
|
|
|
|
}
|
2013-10-15 08:27:26 +00:00
|
|
|
});
|
2014-05-27 07:42:52 +00:00
|
|
|
$form_var.find("input:first").trigger('change');
|
|
|
|
|
|
|
|
|
2013-08-05 12:38:36 +00:00
|
|
|
});
|