jQuery(document).ready(function() { //выбор валюты пользователем на сайте var currency_choice = $('.currency_choice').val(); 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 (article-item.html) 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('.data_this').val(); options[option_name] = option_value; }); /* jQuery(".option-"+item_id).each(function(){ var option_name = $(".item_size_span", this).html(); var option_value = $(this).attr('option_name'); options[option_name] = option_value; alert(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'); } }); }); //Delete product from cart (cart.html) jQuery('.alohacart_cart_block .delete_link').live('click', function(){ update_cart(jQuery(this).attr('data-id_product'), '', ''); }); //Update quantity (cart.html) jQuery('.alohacart_cart_block .quantity').live('change', function(){ update_cart('', jQuery(this).attr('data-id_product'), parseInt(jQuery(this).val())); }); //Для составных товаров, не тестировали(!!!) jQuery('.alohacart_cart_block .composite_quantity').live('change', function(){ update_cart('', '', '', '', jQuery(this).attr('name'), jQuery(this).val()); }); //Для спиннера var timer_int; $('.plus').live('click',function() { clearTimeout(timer_int); // очищаем предыдущий таймер var item = jQuery(this).prevAll(".item_quantity").attr('data-id_product'); var qnty = 1 + parseInt(jQuery(this).prevAll(".item_quantity").val()); timer_int = setTimeout(function () { update_cart('', item, qnty); }, 100); }); $('.minus').live('click', function() { clearTimeout(timer_int); // очищаем предыдущий таймер var item = jQuery(this).prevAll(".item_quantity").attr('data-id_product'); var qnty = -1 + parseInt(jQuery(this).prevAll(".item_quantity").val()); if(qnty == 0) { qnty = 1; } timer_int = setTimeout(function () { update_cart('', item, qnty); }, 100); }); // 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) { if (data == 'DeleteOK') { jQuery(".alohacart_items_display").text('0'); jQuery(".alohacart_quantity_display").text('0'); jQuery(".alohacart_price_display").text('0'); update_cart(); pdk_remove_loading_style("a.alohacart_clear_cart_link"); show_dialog('cart_empty'); } } }); }); // Updates cart form 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 input.shipping:radio:checked').val(); if (!id_shipping && id_shipping_from_form!=undefined) { id_shipping = id_shipping_from_form; } pdk_add_loading_style('.alohacart_cart_block'); jQuery.post('plug-ins/alohacart/formulaires/alohacart_cart_order/cart.php', { 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; var cart_items = jQuery.evalJSON(data).cart_items; jQuery(".alohacart_items_display").text(cart_items); 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 input.shipping').live('click', function(){ update_shipping(); }); update_shipping(); function update_shipping() { id_shipping = jQuery('#form_alohacart_cart_order input.shipping:radio:checked').val(); if (id_shipping != undefined) update_cart('','','',id_shipping); } function refresh_shipping() { id_shipping = jQuery('#form_alohacart_cart_order input.shipping:radio:checked').val(); if (id_shipping != undefined) { pdk_add_loading_style('.alohacart_shipping_block'); jQuery.post('plug-ins/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 .close').live('click', function() { jQuery('.alohacart_dialog_container_product_added').stop().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('plug-ins/alohacart/inc/dialogs/load_dialog.php?dialog='+dialog_id); } jQuery('.alohacart_dialog_container_'+dialog_id).fadeIn().delay(30000).fadeOut(); }