1/** 2 * frontend script 3 * @version 1.1.3 4 */ 5jQuery(document).ready(function($){ 6 7 8// change in variations 9 // run this on load 10 setTimeout(function(){ 11 $('body').find('.evovo_variation_types').each(function(){ 12 $(this).find('select').trigger('change'); 13 }); 14 },200); 15 16 $('body').on('change','.evovo_variation_types select', function (){ 17 SECTION = $(this).closest('.evotx_ticket_purchase_section'); 18 19 rDATA = SECTION.evotx_get_data(); 20 21 evovo_data = SECTION.evotx_get_custom_data('evovo_data'); 22 evovo_data = evovo_data.evovo_data; 23 EVOROW = $(this).closest('.evorow'); 24 25 26 DATA_var = all_variations = evovo_data.v;// all variations 27 28 new_variation_id = false; 29 new_variation_price = evovo_data.defp; 30 new_variation_max_qty = 'na'; 31 new_variation_data = ''; 32 33 // reset hidables 34 SECTION.find('.evotx_hidable_section').show(); 35 36 37 evovo_data['vart'] = {}; 38 selected_options = {}; 39 selected_options['var_ids'] = {}; 40 41 SECTION.find('.evovo_variation_types select').each(function(){ 42 evovo_data.vart[ $(this).attr('name')] = $(this).val(); 43 }); 44 45 const selected_vars = evovo_data.vart; 46 47 //console.log(selected_vars); 48 //console.log(all_variations); 49 50 51 // each variation type 52 _m_var_id = false; 53 _m_var_id_all = false; 54 55 // run through each variation to find a match for all 56 $.each(all_variations, function(var_id, data){ 57 58 var match_count = 0; 59 60 if( _m_var_id ) return; // if a matching variation id is already set stop loop 61 if( !('variations' in data) ) return; // skip no variations data variation 62 63 const variation_type_count = Object.keys(data.variations).length ; 64 65 // run through each variation type 66 $.each( data.variations , function( vtid, vval){ 67 68 var _this_match = false; 69 70 // run through selected values and see if it matches 71 // if selected values does not have this variation type 72 if( !( vtid in selected_vars ) ) return; 73 74 if( selected_vars[vtid] == vval ) _this_match = true; 75 if( selected_vars[vtid] != vval ) _this_match = false; 76 if( selected_vars[vtid] == 'All' ) _this_match = true; // select val = all 77 if( vval == 'All' ) _this_match = true; // variation vt = all 78 79 if( _this_match ) match_count++; 80 81 }); 82 83 // see if this variation have all matching variation types to selected values 84 if( match_count == variation_type_count ){ 85 // set matching variation id 86 _m_var_id = var_id; 87 return; 88 } 89 }); 90 91 92 // if matching variation ID is set 93 if(_m_var_id != false){ 94 new_variation_price = DATA_var[_m_var_id].regular_price; 95 new_variation_id = _m_var_id; 96 new_variation_max_qty = parseInt(DATA_var[_m_var_id].stock); 97 new_variation_data = DATA_var[_m_var_id]; 98 } 99 100 101 // if there is no matching variation 102 if(!new_variation_id){ 103 SECTION.find('.evotx_add_to_cart_bottom').addClass('outofstock'); 104 SECTION.find('.evovo_price_options').hide(); 105 SECTION.evotx_show_msg({'status':'bad','msg':'tvo2','hide_hidables':false}); 106 return false; 107 } 108 109 // set new variation id 110 selected_options['var_ids'][new_variation_id] = 1; 111 selected_options['vart'] = evovo_data['vart']; 112 113 // check for stock status 114 Current_outofstock = false; 115 if(new_variation_data && new_variation_data.stock_status=='outofstock'){Current_outofstock=true;} 116 if(new_variation_data && new_variation_data.stock=='0'){Current_outofstock=true;} 117 118 if(Current_outofstock){ 119 SECTION.find('.evotx_add_to_cart_bottom').addClass('outofstock'); 120 SECTION.find('.evovo_price_options').hide(); 121 SECTION.evotx_show_msg({'status':'bad','msg':'tvo3','hide_hidables':false}); 122 }else{ 123 SECTION.find('.evotx_add_to_cart_bottom').removeClass('outofstock').show(); 124 SECTION.find('.evovo_price_options').show(); 125 SECTION.evotx_hide_msg(); 126 } 127 128 formatted_price = get_format_price( parseFloat(new_variation_price), SECTION); 129 130 // set new values 131 SECTION.evotx_set_select_data( 'evovo', selected_options ); 132 SECTION.evotx_set_custom_data('evovo_data', evovo_data); 133 SECTION.find('.tx_price_line .value').html(formatted_price).data('sp',new_variation_price ); 134 135 // update remaining stock if enabled 136 if( rDATA.event_data && rDATA.event_data.showRem && new_variation_max_qty != 'na'){ 137 SECTION_remaining = SECTION.find('.evotx_remaining'); 138 SECTION_remaining.find('span span').html(new_variation_max_qty); 139 140 if( rDATA.event_data.showRem !== false){ 141 SECTION_remaining.show(); 142 }else{ 143 SECTION_remaining.hide(); 144 } 145 } 146 147 // stock quantity modifitcations 148 QTY_SECTION = SECTION.find('.evotx_quantity'); 149 QTY_SECTION.find('input').data('max', new_variation_max_qty); 150 Set_stock_val = QTY_SECTION.find('input').val(); 151 152 // set remainging tickets 153 if( !isNaN(new_variation_max_qty ) ){ 154 SECTION.find('.evotx_remaining').show(); 155 SECTION.find('.evotx_remaining_stock span').html( new_variation_max_qty ); 156 }else{ 157 SECTION.find('.evotx_remaining').hide(); 158 } 159 160 161 // if current qty is greater than max stock 162 if(new_variation_max_qty != 'na' && Set_stock_val > new_variation_max_qty){ 163 QTY_SECTION.find('input').val(new_variation_max_qty); 164 QTY_SECTION.find('em').html(new_variation_max_qty); 165 166 }else if(Set_stock_val < new_variation_max_qty){// new max is higher than old qty 167 QTY_SECTION.find('b.plu').removeClass('reached'); 168 } 169 170 $('body').trigger('evotx_calculate_total', [SECTION]); 171 172 });
173 174// Individual Variations 175 $('body').on('click','.evovo_var_types_ind .evovo_addremove',function(){ 176 calculate_var_price( $(this) ); 177 }); 178 179 function calculate_var_price(SPAN){ 180 SPAN = $(SPAN); 181 P = SPAN.closest('p'); 182 SECTION = SPAN.closest('.evotx_ticket_purchase_section'); 183 evovo_data = SECTION.evotx_get_custom_data('evovo_data'); 184 DATA = evovo_data.evovo_data; 185 DATA_vt = DATA['v']; 186 187 DATA['prices'] = SECTION.find('.price.tx_price_line input').data('prices'); 188 if( DATA['prices'] == '' ) DATA['prices'] = {}; 189 190 var total_var_price = 0; 191 192 selected_options = {}; 193 selected_options['var_ids'] = {}; 194 195 // all selected variation types 196 SECTION.find('.evovo_var_types_ind').each(function(){ 197 QTY = $(this).find('input').val(); 198 vid = $(this).data('vid'); 199 DATA.prices[ vid ] = {}; 200 201 if( QTY == '0' || QTY === undefined) return true; 202 203 selected_options['var_ids'][vid] = QTY; 204 205 DATA.prices[ vid ]['price'] = DATA_vt[vid].regular_price; 206 DATA.prices[ vid ]['qty'] = QTY; 207 DATA.prices[ vid ]['variations'] = DATA_vt[vid]['variations']; 208 DATA.prices[ vid ]['type'] = 'ind_variation'; 209 210 total_var_price += DATA_vt[vid].regular_price * QTY; 211 212 }); 213 214 // console.log(DATA); 215 SECTION.evotx_set_select_data( 'evovo', selected_options ); 216 SECTION.evotx_set_custom_data('evovo_data', DATA); 217 218 SECTION.find('.price.tx_price_line span.value').html( get_format_price(total_var_price, SECTION) ); 219 SECTION.find('.price.tx_price_line input').data('prices', DATA.prices ); 220 221 $('body').trigger('evotx_calculate_total', [SECTION]); 222 223 } 224 225// maximum quantity override
226 $('body').on('evotx_before_qty_changed',function(event, MAX, OBJ){ 227 return; 228 }); 229 230// Price options 231 $('body').on('click','.evovo_price_option .evovo_addremove',function(){ 232 if(!$(this).hasClass('evotx_qty_change')) calculate_price_options( $(this) ); 233 }); 234 235 $('body').on('evotx_qty_changed', function(event, NEWQTY, MAX, OBJ){ 236 calculate_price_options( OBJ ); 237 }); 238 239 function calculate_price_options(SPAN){ 240 // check if this is multiple of single 241 SPAN = $(SPAN); 242 243 // stop if its not evovo quantity changer 244 if(!SPAN.hasClass('evovo_addremove')) return false; 245 246 MULT = ( SPAN.hasClass('evotx_qty_change'))? true: false; 247 248 P = SPAN.closest('p'); 249 SECTION = SPAN.closest('.evotx_ticket_purchase_section'); 250 pOptions = SECTION.find('.evovo_price_options'); 251 evovo_data = SECTION.evotx_get_custom_data('evovo_data'); 252 DATA = evovo_data.evovo_data; 253 DATA_po = DATA.po; 254 255 // if PO uncorrelated tix qty 256 uncor_qty = evovo_data.po_uncor_qty == 'yes'? true:false; 257 258 DATA['prices'] = SECTION.find('.price.tx_price_line input').data('prices'); 259 if( DATA['prices'] == '' ) DATA['prices'] = {}; 260 QTY = 0; 261 262 // add or remove 263 if( !MULT){ 264 if(P.hasClass('add')){ 265 P.removeClass('add').addClass('added'); 266 P.find('input').val('1'); 267 }else{ 268 P.removeClass('added').addClass('add'); 269 P.find('input').val('0'); 270 } 271 } 272 HTML = HTML_extra = ''; 273 selected_options = {}; 274 selected_options['options'] = {}; 275 276 // all selected price options 277 if( pOptions.find('p.evovo_price_option').length > 0){ 278 pOptions.find('p.evovo_price_option').each(function(index){ 279 280 if( $(this).hasClass('soldout') ) return; 281 282 pMULT = $(this).hasClass('mult')? true: false; 283 po_id = $(this).data('poid'); 284 if( po_id === undefined) return; 285 286 DATA.prices[ po_id ] = {}; 287 288 QTY = parseInt($(this).find('input').val()); 289 290 if( QTY < 1) return; 291 292 // pass POs to other_data 293 selected_options['options'][ po_id ] = QTY; 294 295 DATA.prices[ po_id ]['type'] = 'price_option';// identify this price option add 296 DATA.prices[ po_id ]['price'] = DATA_po[po_id].regular_price; 297 DATA.prices[ po_id ]['qty'] = QTY; 298 DATA.prices[ po_id ]['uncor'] = uncor_qty; // uncorrelated to tix qty 299 DATA.prices[ po_id ]['pt'] = ('pricing_type' in DATA_po[po_id]) ? DATA_po[po_id].pricing_type:'include'; 300 301 total_price = DATA_po[po_id].regular_price * QTY; 302 303 formatted_total_price = get_format_price( total_price, SECTION); 304 305 code = "<p class='evotx_item_price_line'><span class='evotx_label'>"+ DATA_po[po_id].name + "<em>"+ (QTY>1? 'x'+QTY:'') +"</em></span><span class='value'>" + formatted_total_price + "</span></p>"; 306 307 ( DATA.prices[ po_id ]['pt'] == 'extra') ? HTML_extra += code : HTML += code; 308 }); 309 310 // set the selected price options data 311 SPAN.evotx_set_select_data( 'evovo', selected_options ); 312 } 313 314 //console.log(DATA); 315 316 SECTION.find('.evovo_price_option_prices_container').html(HTML); 317 SECTION.find('.evovo_price_option_prices_container_extra').html(HTML_extra); 318 SECTION.evotx_set_custom_data('evovo_data', DATA); 319 SECTION.find('.price.tx_price_line input').data('prices',DATA.prices); 320 321 $('body').trigger('evotx_calculate_total', [SECTION]); 322 } 323 324// FYI: add to cart is using tickets addon script 325 326// GET format the price 327 function get_format_price(price, SECTION){ 328 329 // price format data 330 PF = SECTION.find('.evotx_data').data('pf'); 331 332 totalPrice = price.toFixed(PF.numDec); // number of decimals 333 htmlPrice = totalPrice.toString().replace('.', PF.decSep); 334 335 if(PF.thoSep.length > 0) { 336 htmlPrice = _addThousandSep(htmlPrice, PF.thoSep); 337 } 338 if(PF.curPos == 'right') { 339 htmlPrice = htmlPrice + PF.currencySymbol; 340 } 341 else if(PF.curPos == 'right_space') { 342 htmlPrice = htmlPrice + ' ' + PF.currencySymbol; 343 } 344 else if(PF.curPos == 'left_space') { 345 htmlPrice = PF.currencySymbol + ' ' + htmlPrice; 346 } 347 else { 348 htmlPrice = PF.currencySymbol + htmlPrice; 349 } 350 return htmlPrice; 351 } 352 function _addThousandSep(n, thoSep){ 353 var rx= /(\d+)(\d{3})/; 354 return String(n).replace(/^\d+/, function(w){ 355 while(rx.test(w)){ 356 w= w.replace(rx, '$1'+thoSep+'$2'); 357 } 358 return w; 359 }); 360 }; 361 362 363// ADDONS -> Booking 364 $('body').on('evobo_block_prices_loaded', function(event,eventRow, data, ajaxdataa){ 365 366 $(eventRow).find('.evovo_variation_types select').trigger('change'); 367 368 return; 369 370 371 });
372 373});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.