1 2 3const ShopInstance = new (function () { 4 5 const calculators = new Map(); 6 calculators.set('+', (a, b) => a + b); 7 calculators.set('-', (a, b) => a - b); 8 calculators.set('*', (a, b) => a * b); 9 10 this.cardOptions = function ($card) 11 { 12 const product_id = +$card.find('input.product_id').val(); 13 const product_count = +$card.find('.number__input').val(); 14 15 16 let metaPrice = Number($card.find('.js-card-price').first().val()); 17 18 let $active = $card.find('.form-check-wrap .form-check.active, .form-check-general .form-check.active'); 19 20 let price = Number($active.find('.form-check-price').val()); 21 let weight = ($active.find('.form-check-weight').val() ?? '').toString().trim() || null; 22 23// åñëè íåò öåíû èç âàðèàíòîâ áåðåì èç calc_code 24 if (!Number.isFinite(price) && Number.isFinite(metaPrice)) { 25 price = metaPrice; 26 weight = null; // âàæíî: â ôèêñ-öåíå âåñà áûòü íå äîëæíî 27 } 28 // let $active = $card.find('.form-check-wrap .form-check.active'); 29 // const price = Number($active.find('.form-check-price').val()); const weight = $active.find('.form-check-weight').val(); 30 // let price = Number($active.find('.form-check-price').val()); 31 // 32 // let weight = $active.find('.form-check-weight').val(); 33 // if (!Number.isFinite(price) ) { 34 // price = Number($card.find('.js-card-price').first().val()); 35 // weight = null; 36 // } 37 38 let $activeOne = $card.find('.form-check-one.active'); 39 const value = Number($activeOne.find(`[data-wieget="${weight}"]`).val()); 40 const formula = $activeOne.find('.form-check-one-formula').val(); 41 42 const options = { 43 product_id, 44 product_count, 45 price, 46 weight, 47 calculate: { 48 value, 49 formula 50 } 51 }; 52 53 // console.debug("options", options); 54 55 return options; 56 } 57 58 this.calcCardPrice = function ($card) 59 { 60 const {price, calculate} = this.cardOptions($card); 61 62 const {value, formula} = calculate; 63 64 let calculated = ""; 65 if (value && calculators.has(formula)) 66 { 67 calculated = calculators.get(formula)(price, value); 68 } 69 else 70 { 71 // Âåðîÿòíî ðàñ÷¸ò íå òðåáóåòñÿ â äàííîì ñëó÷àå (íóæíû äîïîëíèòåëüíûå äàííûå äëÿ òî÷íîãî îïðåäåëåíèÿ) 72 if (price.toString() !== "NaN") calculated = price; 73 } 74 75 if (calculated !== "") $card.find('.price-detail-wrap .num').text(calculated); 76 }; 77 78 this.elementCardOptions = function ($element) { 79 let $card = $element.closest('.card-body'); 80 return { 81 $card: $card, 82 options: ShopInstance.cardOptions($card) 83 }; 84 } 85 86 this.serverAction = function (action, payload = {}) 87 { 88 console.debug(payload); 89 90 return $.ajax({ 91 type: 'POST', 92 url: '/CMS/dev/mp/ajax/mp_shop.php?action=' + action, 93 data: payload, 94 dataType: 'json', 95 async: true, 96 }); 97 }; 98 99}); 100 101 102$(document).ready(function () { 103 104 105 // select all thumbnails 106 const galleryThumbnail = document.querySelectorAll(".thumbnails-list li"); 107 // select featured 108 const galleryFeatured = document.querySelector(".product-gallery-featured img"); 109 110 // loop all items 111 galleryThumbnail.forEach((item) => { 112 item.addEventListener("mouseover", function () { 113 galleryFeatured.src = item.children[0].src; 114 }); 115 }); 116 117 // show popover 118 let popoverRetries = 0; 119 120 function initPopover() { 121 if ($.fn.popover) { 122 $(".main-questions").popover('show'); 123 return; 124 } 125 126 if (popoverRetries < 10) { 127 popoverRetries++; 128 setTimeout(initPopover, 300); 129 } 130 } 131 132 initPopover(); 133 $('body') 134 .on('click', '.basket-btn', function () { 135 136 const {options} = ShopInstance.elementCardOptions($(this)); 137 138 // let product_id = $(this).next('input.product_id').val(); 139 // $input = $(this).parent('.button_wrap').find('.number__input'); 140 // let product_count = Number($input.val()); 141 142 ShopInstance.serverAction('addProduct', { 143 product_id: options.product_id, 144 product_count: options.product_count, 145 params: { 146 weight: { 147 value: options.weight, 148 price: options.price, 149 }, 150 }, 151 // vector_price: options.price, 152 // // vector_unit_val: options.weight, 153 // vector_general_descriptor: 'weight', 154 // vector_label: options.weight, 155 }) 156 .done(function (response) { 157 ///let b_count = Number( $('#basket_count').text() ); 158 $('#basket_count').text(response.count).addClass('basket_animete'); 159 160 $('.basket_animete').animate({fontSize: '22px'}, 100, function () { 161 $('.basket_animete').animate({fontSize: '16px'}, 80, function () { 162 $('#basket_count').removeClass('.basket_animete'); 163 }); 164 }); 165 }) 166 }) 167 .on('click', '.delete-product', function(){ 168 let product_id = $(this).parents('tr').attr('data-product-id'); 169 ShopInstance.serverAction('deleteProduct', {product_id}) 170 .done(() => window.location.reload(true)); 171 }) 172 .on('click', '.minus-product', function(){ 173 let product_id = $(this).parents('tr').attr('data-product-id'); 174 ShopInstance.serverAction('minusProduct', {product_id}) 175 .done(() => window.location.reload(true)); 176 }) 177 .on('click', '.plus-product', function(){ 178 let product_id = $(this).parents('tr').attr('data-product-id'); 179 ShopInstance.serverAction('plusProduct', {product_id}) 180 .done(() => window.location.reload(true)); 181 }) 182 .on('click', '.input-number__add', function(){ 183 $input = $(this).parent('.product__quantity').children('.number__input'); 184 let product_count = Number($input.val()); 185 $input.val(product_count + 1); 186 }) 187 .on('click', '.input-number__sub', function(){ 188 $input = $(this).parent('.product__quantity').children('.number__input'); 189 let product_count = Number($input.val()); 190 if(product_count === 1) return; 191 $input.val(product_count - 1); 192 }) 193 .on('click', '#plus-product', function () { 194 let $quantity = $('#quantity'); 195 $quantity.val(Number($quantity.val()) + 1); 196 }) 197 .on('click', '#minus-product', function () { 198 let $quantity = $('#quantity'); 199 let qnt = Number($quantity.val()); 200 if (qnt === 1) return; 201 $quantity.val(qnt - 1); 202 }) 203 .on('click', '.form-check-wrap .form-check', function () { 204 let $card = $(this).closest('.card-body'); 205 $card.find('.form-check-wrap .form-check').removeClass('active'); 206 $(this).addClass('active'); 207 ShopInstance.calcCardPrice($card); 208 }) 209 .on('click', '.form-check-one', function () { 210 let $card = $(this).closest('.card-body'); 211 $card.find('.form-check-one').removeClass('active'); 212 $(this).addClass('active'); 213 ShopInstance.calcCardPrice($card); 214 }) 215 .on('change', '.form-check-general .custom-control-input', function () { 216 // !!! 217 let $card = $(this).closest('.card-body'); 218 $card.find('.form-check').removeClass('active'); 219 $el = $(this).parents('.form-check').addClass('active'); 220 let price = $el.find('.form-check-price').val(); 221 $('.price-detail-wrap .num').text(price); 222 }); 223 224 // $('.card-body').each(function () { 225 // ShopInstance.calcCardPrice($(this)); 226 // }); 227});
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.