1(function ($) { 2 $.extend({ 3 AdvanceWooDiscountRules: { 4 form: null, 5 product_id: null, 6 quantity: 0, 7 options: [], 8 target: null, 9 getDynamicDiscountPriceFromCartForm: function($form, $target, $options){ 10 if (typeof $options !== 'undefined') { 11 this.options = $options; 12 } 13 if (typeof $target !== 'undefined') { 14 this.target = $target; 15 } 16 if (typeof $form !== 'undefined' && $form.is('form')) { 17 this.form = $form; 18 } else { 19 this.logError("Incorrect form provided"); 20 } 21 this.product_id = this.getProductIdFromForm(); 22 23 this.quantity = this.getProductQuantityFromForm(); 24 this.getDiscountPriceForProduct(); 25 }, 26 getDiscountPriceForProduct: function () { 27 if(this.product_id === null || this.product_id == 0){ 28 this.logError("Invalid product"); 29 return []; 30 } 31 var data = { 32 action: 'awdr_get_product_discount', 33 product_id: this.product_id, 34 qty: this.quantity, 35 awdr_nonce: awdr_params.nonce, 36 }; 37 if (typeof this.options.custom_price !== 'undefined') { 38 data.custom_price = this.options.custom_price; 39 } 40 var $target = this.target; 41 var $options = this.options; 42 $.ajax({ 43 url: awdr_params.ajaxurl, 44 data: data, 45 type: 'POST', 46 success: function (response) { 47 $(document.body).trigger("advanced_woo_discount_rules_on_get_response_for_dynamic_discount", [ response, $target, $options ]); 48 //return response; 49 }, 50 error: function (response) { 51 } 52 }); 53 }, 54 getProductIdFromForm: function () { 55 var variationIdEl = this.form.find('[name="variation_id"]'); 56 var productIdEl = this.form.find('[name="add-to-cart"]'); 57 58 if (variationIdEl.length) { 59 return parseInt(variationIdEl.val()); 60 } else if (productIdEl.length) { 61 return parseInt(productIdEl.val()); 62 } 63 64 return false; 65 }, 66 getProductQuantityFromForm: function () { 67 var $input = this.form.find('input[name="quantity"]'); 68 if ($input.length === 0) { 69 return 0; 70 } 71 72 return $input.val(); 73 }, 74 logError: function($text) { 75 console.error("Advance discount rule error: %s", $text); 76 } 77 } 78 }); 79})(jQuery); 80
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.