* Getting a delivery price
3114 * @param {object} params A set of parameters used to calculate the delivery price 3115 * @param {string} params.projectId project id 3116 * @param {string} params.postalCode postal code 3117 * @param {string} params.serviceId service id 3118 * @param {string} [params.pickupPointId] pickup point id 3119 * @param {Function} params.onDone callback function on success 3120 * @param {Function} [params.onFail] callback function on fail 3122 getDeliveryPrice: function (params) { 3123 tcart__hideDeliveryPrice(); 3124 tcart__blockSubmitButton(); 3128 var itemsCount = window.tcart.total || 0; 3129 if (itemsCount === undefined || itemsCount < 1) { 3132 window.t_delivery__browserLang === 'RU' 3133 ? 'добавьте в корзину хотя бы один товар' 3134 : 'add at least one product' 3140 var cartAmount = window.tcart.prodamount || 0; 3141 if (window.tcart.prodamount_withdiscount || window.tcart.prodamount_withdiscount === 0) { 3142 cartAmount = window.tcart.prodamount_withdiscount; 3144 window.t_cart__discounts && 3145 window.t_cart__discounts.length > 0 && 3146 typeof window.tcart.prodamount_withdyndiscount !== 'undefined' 3148 cartAmount = window.tcart.prodamount_withdyndiscount; 3151 var products = this.removeEmptyOrDeletedProducts(); 3154 action: 'calculate', 3155 projectId: params.projectId, 3156 postalCode: params.postalCode, 3157 deliveryId: params.serviceId, 3158 currency: this.deliveryState.currencyCode, 3159 itemsCount: itemsCount, 3160 cartAmount: cartAmount, 3161 pickupPointId: params.pickupPointId, 3163 guid: this.deliveryState.cityGuid || 0, 3166 if (window.tcart?.delivery) { 3168 city: window.tcart.delivery.city || '', 3169 street: window.tcart.delivery.street || '', 3170 house: window.tcart.delivery.house || '', 3174 dataObj = JSON.stringify(dataObj); 3176 var xhr = new XMLHttpRequest(); 3177 xhr.onload = function () { 3178 if (xhr.readyState === xhr.DONE && xhr.status === 200) { 3179 params.onDone(JSON.parse(xhr.responseText)); 3182 tcart__updateDelivery(); 3185 if (typeof params.onFail === 'function') { 3186 const onError = function (error) { 3187 xhr.isTimeout = error.type === 'timeout'; 3190 xhr.ontimeout = onError; 3191 xhr.onerror = onError; 3195 if (!that.endpointDelivery) { 3196 that.endpointDelivery = '.tildacdn.com'; 3198 xhr.open('POST', 'https://delivery' + that.endpointDelivery + '/cart-api/'); 3199 xhr.timeout = 30000;