$( document ).ready( function() { $( 'head' ).prepend( '' ); $.getScript( '' , function() { sheepla.init({ apikey : '', cultureId : '1049' }); g_sheeplaScripts = true; }); /** checking is ajax request is getting shipping methods if yes then set variable to inform 'complete' callback to load sheepla specials **/ var sheepla_autoLoadSpecials = false; $.ajaxSetup({ beforeSend: function( xhr , settings ) { if( this.url.match( /index\.php\?route=checkout\/payment_method/ )) { if( 'undefined' !== typeof sheepla ) { if( !sheepla.valid_special( false , true ) ) return false; } } else if( this.url.match( /checkout\/shipping_method$/ ) ) { sheepla_autoLoadSpecials = true; } }, complete: function() { if( sheepla_autoLoadSpecials ) { var checkedInput = $( 'input[type="radio"][name="shipping_method"]:checked' ); if( 1 == checkedInput.length ) { sheepla_loadSpecials( checkedInput ); sheepla_autoLoadSpecials = false; } } if( this.url.match( /index\.php\?route=checkout\/confirm/ ) ){ try { var sheeplaVars = $( '[name^="sheepla"]' ); var sheeplaGetData = ''; for( var i = 0; i < sheeplaVars.length; i++ ) { sheeplaGetData += '&' + ( sheeplaVars ).eq( i ).attr( 'name' ) + '=' + $( sheeplaVars ).eq( i ).val(); } $.ajax({ type: 'get', url: 'index.php?route=shipping/sheepla/confirmorder' + sheeplaGetData, cache: false, }); } catch( e ) {} } } }); function sheepla_lockInputs( target ) { $( target ).closest( 'table' ).find( 'input' ).attr( 'disabled' , 'disabled' ); } function sheepla_unlockInputs( target ) { $( target ).closest( 'table' ).find( 'input' ).removeAttr( 'disabled' ); } function sheepla_loadSpecials( targetRadio ) { var radioButton = targetRadio; if( $( radioButton ).attr('value').match( /^sheepla\.[0-9]+$/ ) ) { var data = $( radioButton ).attr( 'value' ).split( '.' ); var sheeplaTemplateId = data[ 1 ]; $.ajax({ url: 'index.php?route=shipping/sheepla/specials', type: 'post', data: { sheepla_template_id: sheeplaTemplateId }, beforeSend: function() { $( '.sheepla_workarea' ).remove(); sheepla_lockInputs( radioButton ); }, success: function( data ) { data = $.trim( data ); data = $.parseJSON( data ); if( undefined !== typeof data.status && 1 === data.status ) { var userWorkareaSelector = null; try { var userWorkareaSelector = eval( '' ); } catch( e ) { userWorkareaSelector = null; } if( null !== userWorkareaSelector && 'undefined' !== typeof userWorkareaSelector && userWorkareaSelector.length ) { $( userWorkareaSelector ).append( '