function p(val) { console.info(val); } var val; function get() { getNovaPoshtaCity(); } function getNovaPoshtaCity() { $( "#order_city_novaposhta" ).autocomplete({ source: function( request, response ) { $.ajax({ url: '/ajax/get_cities', data : { term : request.term }, scriptCharset: "utf-8", type : "POST", dataType: 'json', success: function( data ) { if( val == 1 ) { response( data ); $('#loading_city').addClass('display_none'); $('.owner_city .description').addClass('display_none'); } }, error: function() { console.info('error'); } }) .fail(function() { $( '.order_city_novaposhta .description' ).removeClass('display_none'); $( "#order_city_novaposhta" ).val(''); $('#loading_city').addClass('display_none'); }); $('#loading_city').removeClass('display_none'); }, minLength: 2, select: function( event, ui ) { $( "#order_city_novaposhta" ).val( ui.item.value ); $( "#order_city_ref" ).val( ui.item.ref ); $('#loading_city').addClass('display_none'); getNovaPoshtaOffice( ui.item.value ); return false; } }); } function getNovaPoshtaOffice( city ) { $('#loading_office').removeClass('display_none'); $.ajax( { url: '/ajax/get_offices/', data : { 'city' : city }, type : "POST", dataType: 'json', success: function (data) { var html = ''; if( data ) { for( var i in data ) { html += ''; } $('#store_address').html(html); $('#loading_office').addClass('display_none'); var option = $('select#store_address option:selected').data('store_ref'); $( "#order_store_address_ref").val($('select#store_address option:selected').data('store_ref')); $('#store_address').on( 'click', function() { $( "#order_store_address_ref").val($('select#store_address option:selected').data('store_ref')); }); } }, error: function() { console.info('error'); } }); } function add_item_for_compare( check, item_id ) { $.ajax( { url: '/ajax/add_item_for_compare', data : { 'check' : check, 'item_id' : item_id }, type : "POST", dataType: 'json', success: function (data) { var html = ''; if( data.length == 0 ) { $('.compare_wrapper').empty(); } else { var count = 0; html += '
Список порівняння
'+ '
'+ '
Список порівняння
'+ '
' $('.compare_wrapper').html(html); $('.compare').html('Список порівняння '+count+''); $('.compare').click(function(e) { e.preventDefault(); $('.compare_list').toggle(); }); } }, error: function(data, err) { console.error(data); console.error('error: ' + err); } }); } function change_items( next_page, block_class, news_id ) { console.log( next_page+', '+block_class+', '+news_id); $.ajax( { url: '/change_top_items/', data : { 'block_class' : block_class, 'next_page' : next_page, 'news_id' : news_id }, type : "POST", dataType: 'json', success: function (data) { var html = ''; if( data.length ) { for( var i in data ) { html += '
'+ '
'+ ''+ ''+data[i]['title']+''+ ''+ '
'+ '
'+ ''+ '

'+data[i]['title']+'

'+ '
'+ '
'+ '
'+ '
ціна від ' + ''+parseFloat(data[i]['price2']).toFixed(2)+' грн
'+ ''+ '
'+ '
'; } $('.'+block_class+' .items').html(html); $('.one_item_compare').on( 'change', function() { var check = 0; var item_id = $(this).find('input').val(); if( $(this).find('input').prop('checked') ) { check = 1; } add_item_for_compare( check, item_id ); }); } }, error: function() { console.info('error'); } }); } function change_similar_items( catalog_id, group_id, similar ) { $.ajax( { url: '/change_similar_items', data : { //'item_id' : item_id, 'catalog_id' : catalog_id, 'group_id' : group_id, 'similar' : similar }, type : "POST", dataType: 'json', success: function (data) { var html = ''; for( var i in data ) { html += '
'+ '
'+ ( data[i]['is_new'] == 1 ? '
'+ 'Новинки'+ '
' : '' )+ ( data[i]['is_top'] == 1 ? '
'+ 'Топ продаж'+ '
' : '' )+ '
'+ '
'+ ''+ ''+data[i]['title']+''+ ''+ '
'+ '
'+ ''+ '

'+data[i]['title']+'

'+ '
'+ '
'+ '
'+ '

'+data[i]['description']+'

'+ '
'+ '
'+ '
ціна від '+parseFloat(data[i]['price']).toFixed(2)+' грн
'+ ''+ '
'+ ''+ ''+ '
'+ '
'+ '
'; } $('.other_items .items').html(html); $('.one_item_compare').on( 'change', function() { var check = 0; var item_id = $(this).find('input').val(); if( $(this).find('input').prop('checked') ) { check = 1; } add_item_for_compare( check, item_id ); }); }, error: function() { console.info('error1'); } }); } function change_price( value1, value2 ) { var sort_params = $('.sort_params').val(); var a_href = $('input.current_url').val(); var href = 'price-'+value1+'-'+value2; var alias = a_href+'--'+href; if( sort_params != 0 ) { alias = alias.replace( /\/\-\-/,'\/')+'/sort-'+sort_params; } $('.price_ok').attr( 'href', alias.replace( /\/\-\-/,'\/' ) ); } function add_to_basket( item_id, count_items ) { $.ajax({ url: '/basket/add_item', data : { 'item_id' : item_id, 'count_items' : count_items }, type : "POST", dataType: 'json', success: function (data) { if( data == '0' ) { /*Confirm('Такий товар вже є у кошику', 'Кошик', function(yes) { if(yes) { document.location='/basket'; } });*/ } else { $('.basket_number a').html(data); } }, error: function() { console.info('error'); } }); } function change_count_basket( item_id, count_items ) { $.ajax({ url: '/basket/change_count_basket', data : { 'item_id' : item_id, 'count_items' : count_items }, type : "POST", dataType: 'json', success: function (data) { }, error: function() { console.info('error'); } }); } $(document).ready(function() { /////////////////////////////////////////////////////////////////////// checkTotalPeice(); $('.content_wrapper_header_menu').on( 'click', '.thumbs', function(e) { e.preventDefault(); $.cookie('view', 'thumbs'); $('#content .subcategory_list').addClass('subcategory'); $('#content div').removeClass('subcategory_list'); $(this).addClass('active'); $(this).parent().find('.lists').removeClass('active'); }); $('.content_wrapper_header_menu').on( 'click', '.lists', function(e) { e.preventDefault(); $.cookie('view', 'lists'); $('#content .subcategory').addClass('subcategory_list'); $('#content div').removeClass('subcategory'); $(this).addClass('active'); $(this).parent().find('.thumbs').removeClass('active'); }); /////////////////////////////////////////////////////////////////////// function contentSliderSlide() { $('.content_items').find('.content_arrow_right').each(function(){ var block_class = $(this).parent().parent().parent().data('class'); var current_page = parseInt( $('.'+block_class+' .page_number').text() ); var max_page = $(this).parent().find('span.max_page').text(); var news_id = $(this).parent().parent().parent().data('news_id') ? parseInt( $(this).parent().parent().parent().data('news_id') ) : '0'; //p(block_class); if( current_page < max_page ) { var next_page = current_page + 1; $('.'+block_class+' .page_number').text( next_page, block_class); change_items( next_page, block_class, news_id ); } else { var next_page = 1; $('.'+block_class+' .page_number').text( next_page, block_class); change_items( next_page, block_class, news_id ); } }) } //setInterval(contentSliderSlide,10000); $('.content_items').on( 'click', '.content_arrow_right', function(e) { e.preventDefault(); var block_class = $(this).parent().parent().parent().data('class'); var current_page = parseInt( $('.'+block_class+' .page_number').text() ); var max_page = $(this).parent().find('span.max_page').text(); var news_id = $(this).parent().parent().parent().data('news_id') ? parseInt( $(this).parent().parent().parent().data('news_id') ) : '0'; //p(block_class); if( current_page < max_page ) { var next_page = current_page + 1; $('.'+block_class+' .page_number').text( next_page, block_class); change_items( next_page, block_class, news_id ); } else { var next_page = 1; $('.'+block_class+' .page_number').text( next_page, block_class); change_items( next_page, block_class, news_id ); } }); $('.content_items').on( 'click', '.content_arrow_left', function(e) { e.preventDefault(); var block_class = $(this).parent().parent().parent().data('class'); var current_page = parseInt( $('.'+block_class+' .page_number').text() ); var news_id = $(this).parent().parent().parent().data('news_id') ? parseInt( $(this).parent().parent().parent().data('news_id') ) : '0'; if( current_page > 1 ) { var next_page = current_page - 1; $('.'+block_class+' .page_number').text( next_page, block_class); change_items( next_page, block_class, news_id ); } }); /////////////////////////////////////////////////////////////////////// $('.plus ').on( 'click', function(e) { e.preventDefault(); var count = parseInt($(this).parent().find('.count_input input').val()) + 1; var item_id = $(this).parent().find('.count_input input').data('item_id'); change_count_basket( item_id, count ); $(this).parent().find('.count_input input').val(count); if( $(this).parent().hasClass('order_third_column') ) { var price = parseFloat( $(this).parent().parent().find('.order_second_column').find('span').html() ); var total = price*count; if( total%1 !== 0 ) { total = total.toFixed(1); } $(this).parent().parent().find('.order_fourth_column').find('span.price').html( total ); var total_sum = 0; $('.order_second_column .price').each(function() { total_sum = total_sum + parseFloat( $(this).parent().parent().find('.order_fourth_column').find('span.price').html() ); //total_sum = total_sum.toFixed(1); $('.order_last span.price').html(total_sum.toFixed(1)); checkTotalPeice(); }); } }); $('.minus ').on( 'click', function(e) { e.preventDefault(); var count_ = parseInt($(this).parent().find('.count_input input').val()); var count = count_ - 1; var item_id = $(this).parent().find('.count_input input').data('item_id'); change_count_basket( item_id, count ); if( count_ > 1 ) { $(this).parent().find('.count_input input').val(count); if( $(this).parent().hasClass('order_third_column') ) { var price = parseFloat( $(this).parent().parent().find('.order_second_column').find('span').html() ); var total = price*count; if( total%1 !== 0 ) { total = total.toFixed(1); } $(this).parent().parent().find('.order_fourth_column').find('span.price').html( total ); var total_sum = 0; $('.order_second_column .price').each(function() { total_sum = total_sum + parseFloat( $(this).parent().parent().find('.order_fourth_column').find('span.price').html() ); $('.order_last span.price').html(total_sum.toFixed(1)); checkTotalPeice(); }); } } }); $('.count_input input').on( 'keyup', function(e) { e.preventDefault(); var count = $(this).val(); var item_id = $(this).data('item_id'); //p(count); change_count_basket( item_id, count ); if( count > 1 ) { if( $(this).parent().parent().hasClass('order_third_column') ) { var price = parseFloat( $(this).parent().parent().parent().find('.order_second_column').find('span').html() ); var total = price*count; if( total%1 !== 0 ) { total = total.toFixed(1); } $(this).parent().parent().parent().find('.order_fourth_column').find('span.price').html( total ); var total_sum = 0; $('.order_second_column .price').each(function() { total_sum = total_sum + parseFloat( $(this).parent().parent().parent().find('.order_fourth_column').find('span.price').html() ); $('.order_last span.price').html(total_sum.toFixed(1)); checkTotalPeice(); }); } } }); function checkTotalPeice(){ var val = $('span[id=total_price]').html(); if(val>100){ $('.min_price_message').css("display", "none"); } else { $('.min_price_message').css("display", "block"); } } $('#send_order').click(function(e) { e.preventDefault(); var val = $('span[id=total_price]').html(); console.log(val); if (val<100) { Confirm_low(' Мінімальна сума замовлення складає 100 гривень. Замовте ще!', 'Кошик', function (yes) { if (yes) { document.location = '/'; } }) } else { $('form[name=order_add]').submit(); } }); /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// $('.item').on( 'click', '.group_sizes', function(e) { if( $(this).hasClass( 'not_exist' ) ) { return false; } e.preventDefault(); var item_id = $(this).data('item_id'); var catalog_id = $(this).data('catalog_id'); var group_alias = $(this).data('group_alias'); $(this).parent().find('a.group_sizes').removeClass('active'); $(this).addClass('active'); $.ajax( { url: '/change_with_size', data : { 'item_id' : item_id, 'catalog_id' : catalog_id, 'group_alias' : group_alias }, type : "POST", dataType: 'json', success: function (data) { var html = data['html']; /* for( var i in data ) { html += '
'+ '
ціна ' + '' + '
'+ '
'+ ((data[i]['status_real']!=2)?'придбати':'')+ '
'+ '
'+ ''+ ''+ ''+ ''+ '
'+ '
'+ '
'; for( var j in data[i]['filters'] ) { html += ''+ data[i]['filters'][j]['value_value'] +''; } html += '
'; $('.item_images .thumbnails').html(data[i]['image']); $('.presence_status').html(data[i]['status']); $('.properties_article').html(data[i]['product_id']); $('.colors').html(data[i]['color']); } */ $('.item_images .thumbnails').html(data['image']); $('.presence_status').html(data['status']); $('.properties_article').html(data['product_id']); $('.colors').html(data['color']); $('.change_with_size').html(html); $('.thumbnail').iLightBox( { skin: 'metro-black', path: 'horizontal', maxScale: 1.3, overlay: { opacity: .8 }, styles: { nextOffsetX: 75, nextOpacity: .55, prevOffsetX: 75, prevOpacity: .55 }, thumbnails: { normalOpacity: .9, activeOpacity: 1 }, controls: { thumbnail: 1, arrows: 1 } }); $('#show_confirm').click(function(e) { var inStock = $('#stock').data('stock'); console.log(inStock); e.preventDefault(); if (!inStock) { var count_items = $('.count_input .count_items').val(); add_to_basket(item_id, count_items); Confirm('Ви замовляєте товар, який на сьогоднішній день
відсутній на складі. Будь ласка,
узгодьте термін доставки даного товару.', 'Кошик', function (yes) { if (yes) { document.location = '/basket'; } }) } else { var count_items = $('.count_input .count_items').val(); add_to_basket(item_id, count_items); Confirm('Ви додали товар до кошика', 'Кошик', function (yes) { if (yes) { document.location = '/basket'; } }) } }); }, error: function() { console.info('error'); } }); }); $('.group_sizes:first').click(); /////////////////////////////////////////////////////////////////////// $('.item').on( 'click', '.change_with_color', function(e) { e.preventDefault(); var item_id = $(this).data('item_id'); var type_id = $(this).data('type_id'); var subtype_id = $(this).data('subtype_id'); var group_id = $(this).data('group_id'); var group_alias = $(this).data('group_alias'); var color_id = $(this).data('color_id'); var current_item_size = $('.current_item_size').val(); $('.change_with_color a').removeClass('active'); $('.change_with_color a').css('border-color', '#e2e2e2'); $(this).find('a').addClass('active'); $.ajax( { url: '/change_with_color', data : { 'item_id' : item_id, 'type_id' : type_id, 'subtype_id' : subtype_id, 'group_id' : group_id, 'group_alias' : group_alias, 'color_id' : color_id, 'current_item_size' : current_item_size }, type : "POST", dataType: 'json', success: function (data) { var html = ''; for( var i in data ) { html += '
'+ '
ціна '+ parseFloat(data[i]['price2']).toFixed(2) +' грн
'+ '
'+ 'придбати'+ '
'+ '
'+ ''+ ''+ ''+ ''+ '
'+ '
'+ '
'; for( var j in data[i]['filters'] ) { html += ''+ data[i]['filters'][j]['value_value'] +''; } html += '
'; $('.item_images .thumbnails').html(data[i]['image']); $('.presence_status').html(data[i]['status']); $('.properties_article').html(data[i]['product_id']); $('.colors').html(data[i]['color']); $('.packing_images').html(data[i]['sizes']); $('.item_properties').html(data[i]['properties']); if( $('.change_with_color a').hasClass('active') ) { $('.change_with_color a.active').css('border-color', data[i]['absolute_color']); } } $('.change_with_size').html(html); $('#show_confirm').click(function(e) { var inStock = $('#stock').data('stock'); console.log(inStock); e.preventDefault(); if (!inStock) { var count_items = $('.count_input .count_items').val(); add_to_basket(item_id, count_items); Confirm('Ви замовляєте товар, який на сьогоднішній день
відсутній на складі, будь ласка, після замовлення
узгодьте термін доставки товару.', 'Кошик', function (yes) { if (yes) { document.location = '/basket'; } }) } else { var count_items = $('.count_input .count_items').val(); add_to_basket(item_id, count_items); Confirm('Ви додали товар до кошика', 'Кошик', function (yes) { if (yes) { document.location = '/basket'; } }) } }); }, error: function() { console.info('error'); } }); }); /////////////////////////////////////////////////////////////////////// $('#profiler span.profiler-sql-show').on( 'click', function(e) { e.preventDefault() if( $('#profiler-sql').is( ':visible' ) ) { $('#profiler-sql').hide(); } else { $('#profiler-sql').show(); } } ); /////////////////////////////////////////////////////////////////////// function dialogue(content, title) { content = $('
', { 'class': 'dialogue clearfix' }).append(content); $.iLightBox([ { URL: content, type: "html", title: (title) ? title : null } ], { skin: 'light ilightbox-dialogue', minScale: 1, innerToolbar: true, overlay: { blur: false }, controls: { fullscreen: false }, callback: { // Hide the iLightBox when any buttons in the dialogue are clicked onRender: function(api) { $('.btn', api.currentElement).click(function(){ $('.btn', api.currentElement).unbind('click'); api.hide(); }); }, // Hide the iLightBox when any buttons in the dialogue are clicked onShow: function(api) { $('.btn-primary', api.currentElement).focus(); } } }); } function videoConfirm(callback){ var message = $('
', { html: '' }), cancel = $('