1 $(document).ready(function () {
2 $('.oe_website_sale #add_to_cart, .oe_website_sale #products_grid .a-submit')
4 .removeClass('a-submit')
5 .click(function (event) {
6 var $form = $(this).closest('form');
7 var quantity = parseFloat($form.find('input[name="add_qty"]').val() || 1);
8 var product_id = parseInt($form.find('input[type="hidden"][name="product_id"], input[type="radio"][name="product_id"]:checked').first().val(),10);
9 event.preventDefault();
10 openerp.jsonRpc("/shop/modal", 'call', {
11 'product_id': product_id,
13 context: openerp.website.get_context()
15 }).then(function (modal) {
16 var $modal = $(modal);
18 $modal.find('img:first').attr("src", "/website/image/product.product/" + product_id + "/image");
20 $modal.appendTo($form)
22 .on('hidden.bs.modal', function () {
26 $modal.on('click', '.a-submit', function () {
29 url: '/shop/cart/update_option',
30 success: function (quantity) {
31 if (!$a.hasClass('js_goto_shop')) {
32 window.location.href = window.location.href.replace(/shop([\/?].*)?$/, "shop/cart");
34 var $q = $(".my_cart_quantity");
35 $q.parent().parent().removeClass("hidden", !quantity);
36 $q.html(quantity).hide().fadeIn(600);
42 $modal.on("click", "a.js_add, a.js_remove", function (event) {
43 event.preventDefault();
44 var $parent = $(this).parents('.js_product:first');
45 $parent.find("a.js_add, span.js_remove").toggleClass("hidden");
46 $parent.find("input.js_optional_same_quantity").val( $(this).hasClass("js_add") ? 1 : 0 );
47 var $remove = $parent.find(".js_remove");
50 $modal.on("change", "input.js_quantity", function (event) {
51 var qty = parseFloat($(this).val());
53 $(".js_remove .js_items").addClass("hidden");
54 $(".js_remove .js_item").removeClass("hidden");
56 $(".js_remove .js_items").removeClass("hidden").text($(".js_remove .js_items").text().replace(/[0-9.,]+/, qty));
57 $(".js_remove .js_item").addClass("hidden");
61 $modal.find('input[name="add_qty"]').val(quantity).change();
62 $('ul.js_add_cart_variants').each(function () {
63 $('input.js_variant_change, select.js_variant_change', this).first().trigger('change');