jQuery(document).ready(function() { //выбор валюты пользователем на сайте var currency_choice = $('.currency_choice').val(); $('.cur_usd').hide(); $('.usd').removeAttr("checked"); $('.cur_eur').hide(); $('.eur').removeAttr("checked"); $('.cur_uah').show(); $('.uah').attr("checked","checked"); switch (currency_choice) { case "uah": $('.cur_usd').hide(); $('.usd').removeAttr("checked"); $('.cur_eur').hide(); $('.eur').removeAttr("checked"); $('.cur_uah').show(); $('.uah').attr("checked","checked"); break; case "usd": $('.cur_uah').hide(); $('.uah').removeAttr("checked"); $('.cur_eur').hide(); $('.eur').removeAttr("checked"); $('.cur_usd').show(); $('.usd').attr("checked","checked"); break; case "eur": $('.cur_uah').hide(); $('.uah').removeAttr("checked"); $('.cur_usd').hide(); $('.usd').removeAttr("checked"); $('.cur_eur').show(); $('.eur').attr("checked","checked"); break; } // События при выборе валюты $('.eur').click(function(){ $('.cur_usd, .cur_uah').hide(); $('.cur_eur').show(); jQuery.post('./?page=alohacart_ajax', { act: "save_currency_by", select: 'eur' }, function(data){ //alert(data); } ); }); $('.usd').click(function(){ $('.cur_uah, .cur_eur').hide(); $('.cur_usd').show(); jQuery.post('./?page=alohacart_ajax', { act: "save_currency_by", select: 'usd' }, function(data){ //alert(data); } ); }); $('.uah').click(function(){ $('.cur_usd, .cur_eur').hide(); $('.cur_uah').show(); jQuery.post('./?page=alohacart_ajax', { act: "save_currency_by", select: 'uah' }, function(data){ //alert(data); } ); }); // Add product to cart via AJAX request jQuery("a.alohacart_add_product_link").live('click', function() { pdk_add_loading_style(this); var item_id = jQuery(this).attr('id_article'); var item_quantity = (jQuery('#item-'+item_id+'-quantity').length>0)?jQuery('#item-'+item_id+'-quantity').val():1; var options = {}; jQuery(".size-"+item_id+"-size").each(function(){ var option_name = $(".item_size_span", this).html(); var option_color = $(".item_color_span", this).html(); if (option_name == 0 || option_name == null) {option_name=option_color;} var option_value = $(this).find(".sbSelector").html(); options[option_name] = option_value; }); jQuery.post('./?page=alohacart_ajax', { act: "add_product", id_article: item_id, item_quantity: item_quantity , options: options }, function(data){ if (data) {//alert('echo - '+data); var not_enough_products = jQuery.evalJSON(data).not_enough_products; update_cart(); pdk_remove_loading_style('a.alohacart_add_product_link'); if (not_enough_products) show_dialog('not_enough_products'); else show_dialog('product_added'); } }); }); //change and calculate product quantity $("input[name ^= 'products']").live('change',function() { update_cart('', $(this).attr('data-id_product'), $(this).val()); }); var timer_int; $('.plus').live('click',function() { clearTimeout(timer_int); // очищаем предыдущий таймер var q = $(this).parent().find("input[name ^= 'products']"); q.val(function(index, x){ if(q.attr('max')>=1*x) // не 1+1*x чтоб показывалось сообщение о не достатке товара return 1+1*x; // x is object else return x; }); timer_int = setTimeout(function () { update_cart('', q.attr('data-id_product'), q.val()); }, 500); // 0.5 секунды задержка перед отправлением значения на сервер }); $('.minus').live('click', function() { clearTimeout(timer_int); // очищаем предыдущий таймер var q = $(this).parent().find("input[name ^= 'products']"); q.val(function(index, x){ if(x>1) // должен быть хоть 1 товар, если пставить 0 товар будет удалятся return x-1; // x is object else return x; }); timer_int = setTimeout(function () { update_cart('', q.attr('data-id_product'), q.val()); }, 500); }); // Clear cart via AJAX request jQuery("a.alohacart_clear_cart_link").live('click', function() { pdk_add_loading_style(this); jQuery.post('./?page=alohacart_ajax', { act: "clear_cart" }, function(data){ if (data) { //alert(data); if (data == 'DeleteOK') { jQuery(".alohacart_quantity_display").text('0'); jQuery(".alohacart_price_display").text('0'); update_cart(); pdk_remove_loading_style("a.alohacart_clear_cart_link"); //alert('Корзина пуста!'); show_dialog('cart_empty'); } } }); }); jQuery('.alohacart_cart_block .delete_link').live('click', function(){ update_cart(jQuery(this).attr('data-id_product'), '', ''); }); jQuery('.alohacart_cart_block .quantity').live('change', function(){ update_cart('', jQuery(this).attr('data-id_product'), jQuery(this).val()); }); jQuery('.alohacart_cart_block .composite_quantity').live('change', function(){ update_cart('', '', '', '', jQuery(this).attr('data-id_product'), jQuery(this).val()); }); // Updates cart block via AJAX function update_cart(id_product_delete, id_product_change_quantity, product_change_quantity, id_shipping) { var id_shipping_from_form = jQuery('#form_alohacart_cart_order select#id_shipping option:selected').val(); if (!id_shipping && id_shipping_from_form!=undefined) id_shipping = id_shipping_from_form; pdk_add_loading_style('.alohacart_cart_block'); jQuery.post('plugins/alohacart/formulaires/alohacart_cart_order/cart.php', //?var_mode=calcul { id_product_delete: id_product_delete, id_product_change_quantity: id_product_change_quantity, product_change_quantity: product_change_quantity, id_shipping: id_shipping }, function(data){ if (data) { //alert(data); jQuery('.alohacart_cart_block').html(data); refresh_cart_view(); update_balises(); refresh_shipping(); pdk_remove_loading_style('.alohacart_cart_block'); } }); } // Updated needed balises via AJAX (e.g. cart price) function update_balises() { jQuery.post('./?page=alohacart_ajax', {}, function(data){ if (data) { //alert(data); if (data) { var cart_quantity = jQuery.evalJSON(data).cart_quantity; var cart_price = jQuery.evalJSON(data).cart_price; jQuery(".alohacart_quantity_display").text(cart_quantity); jQuery(".alohacart_price_display").text(cart_price); } } } ); } // Shows or hides cart block according to number of products in the cart function refresh_cart_view() { if (jQuery('.alohacart_cart_block input#num_products').val()>0) { jQuery('.alohacart_cart_order_form_block').show(); jQuery('.alohacart_cart_order_form_empty_block').hide(); } else { jQuery('.alohacart_cart_order_form_block').hide(); jQuery('.alohacart_cart_order_form_empty_block').show(); } } // Hiding and showing payment data /* jQuery('#form_alohacart_cart_order .payment_data').hide(); jQuery('#form_alohacart_cart_order select#id_payment').live('click', function(){ jQuery('#form_alohacart_cart_order .payment_data').hide(); jQuery(this).siblings('.payment_data').show(); });*/ // When shipping method change jQuery('#form_alohacart_cart_order select#id_shipping').live('change', function(){ update_shipping(); //refresh_shipping(); }); update_shipping(); function update_shipping() { id_shipping = jQuery('#form_alohacart_cart_order select#id_shipping option:selected').val(); if (id_shipping != undefined) update_cart('','','',id_shipping); } function refresh_shipping() { id_shipping = jQuery('#form_alohacart_cart_order select#id_shipping option:selected').val(); if (id_shipping != undefined) { pdk_add_loading_style('.alohacart_shipping_block'); jQuery.post('plugins/alohacart/formulaires/alohacart_cart_order/shipping.php', {id_shipping:id_shipping}, function(data) { if (data) { //alert(data); if (data) { jQuery('#form_alohacart_cart_order .alohacart_shipping_block').html(data); pdk_remove_loading_style('.alohacart_shipping_block'); } } } ); } } jQuery('.alohacart_recalculate_cart_link').live('click', function(){ update_cart(); }) // Dialogs BEGIN jQuery('.alohacart_dialog_container a.close').live('click', function() { jQuery('.alohacart_dialog_container').each(function(){ jQuery(this).fadeOut(); }); }) $(window).bind("resize", function(){ $(".alohacart_dialog_container").css("height", $(document).height()); }); // Dialogs END }); function show_dialog(dialog_id) { if (jQuery('.alohacart_dialog_container_'+dialog_id).length == 0) { jQuery('body').append('
'); jQuery('.alohacart_dialog_container_'+dialog_id).load('plugins/alohacart/inc/dialogs/load_dialog.php?dialog='+dialog_id); } jQuery('.alohacart_dialog_container_'+dialog_id).fadeIn().delay(1000).fadeOut(); }