diff --git a/wp-content/themes/cosmopet/global-functions/multilang-functions.php b/wp-content/themes/cosmopet/global-functions/multilang-functions.php index a43c8d8..3eb1761 100644 --- a/wp-content/themes/cosmopet/global-functions/multilang-functions.php +++ b/wp-content/themes/cosmopet/global-functions/multilang-functions.php @@ -1803,41 +1803,51 @@ pll_register_string('Запомнить меня', 'Запомнить меня' add_action('wp_head', function () { if (function_exists('pll_current_language')) { $lang = pll_current_language(); +$translations = [ + 'en' => [ + 'name_required' => 'The name is required.', + 'email_invalid' => 'Email is incorrect.', + 'phone_invalid' => 'The phone number is incorrect.', + 'error_coupon_empty' => 'Please enter the coupon code.', + 'error_coupon_invalid' => 'Error! The coupon code is invalid or does not exist.', + 'error_generic' => 'An error occurred. Please try again.', + 'shipping_method_error' => 'No pickup point selected for delivery.', + 'shipping_address_error' => 'Delivery address not provided', + 'email_taken_error' => 'This email is already registered. Please log in or provide a different email.', + 'phone_number_error' => 'Incorrect phone number entered.', + 'shipping_method_missing' => 'No delivery method selected. Please check your address or contact the site administration for help.', + 'change_address' => 'Change address', + 'shipping_updated' => 'Shipping methods will be updated during checkout.', + 'coupon_applied' => 'Coupon applied: ', + + // 🔽 Новые строки из JS + 'Choose pick-up' => 'Choose pick-up', + 'Re-select pick-up' => 'Re-select pick-up', + 'There are no CDEK pick-up points available in this direction, please select another delivery method' => + 'There are no CDEK pick-up points available in this direction, please select another delivery method' + ], + 'ru' => [ + 'name_required' => 'Поле имени обязательно для заполнения.', + 'email_invalid' => 'Введите корректный email.', + 'phone_invalid' => 'Введите корректный номер телефона.', + 'error_coupon_empty' => 'Пожалуйста, введите код купона.', + 'error_coupon_invalid' => 'Ошибка! Промокод введен неверно или не существует.', + 'error_generic' => 'Произошла ошибка. Попробуйте ещё раз.', + 'shipping_method_error' => 'Не выбран ПВЗ для доставки заказа.', + 'shipping_address_error' => 'Не указан адрес доставки', + 'email_taken_error' => 'Этот email уже зарегистрирован. Войдите в свой аккаунт или укажите другой E-mail.', + 'phone_number_error' => 'Неправильно введен номер', + 'shipping_method_missing' => 'Не выбран метод доставки. Пожалуйста перепроверьте ваш адрес или обратитесь за помощью к администрации сайта.', + 'change_address' => 'Изменить адрес', + 'shipping_updated' => 'Методы доставки будут обновлены в процессе оформления заказа.', + 'coupon_applied' => 'Применен промокод: ', + 'Choose pick-up' => 'Выбрать пункт выдачи', + 'Re-select pick-up' => 'Выбрать другой пункт выдачи', + 'There are no CDEK pick-up points available in this direction, please select another delivery method' => + 'В этом направлении нет доступных пунктов выдачи CDEK, пожалуйста, выберите другой способ доставки' + ] +]; - $translations = [ - 'en' => [ - 'name_required' => 'The name is required.', - 'email_invalid' => 'Email is incorrect.', - 'phone_invalid' => 'The phone number is incorrect.', - 'error_coupon_empty' => 'Please enter the coupon code.', - 'error_coupon_invalid' => 'Error! The coupon code is invalid or does not exist.', - 'error_generic' => 'An error occurred. Please try again.', - 'shipping_method_error' => 'No pickup point selected for delivery.', - 'shipping_address_error' => 'Delivery address not provided', - 'email_taken_error' => 'This email is already registered. Please log in or provide a different email.', - 'phone_number_error' => 'Incorrect phone number entered.', - 'shipping_method_missing' => 'No delivery method selected. Please check your address or contact the site administration for help.', - 'change_address' => 'Change address', - 'shipping_updated' => 'Shipping methods will be updated during checkout.', - 'coupon_applied' => 'Coupon applied: ' - ], - 'ru' => [ - 'name_required' => 'Поле имени обязательно для заполнения.', - 'email_invalid' => 'Введите корректный email.', - 'phone_invalid' => 'Введите корректный номер телефона.', - 'error_coupon_empty' => 'Пожалуйста, введите код купона.', - 'error_coupon_invalid' => 'Ошибка! Промокод введен неверно или не существует.', - 'error_generic' => 'Произошла ошибка. Попробуйте ещё раз.', - 'shipping_method_error' => 'Не выбран ПВЗ для доставки заказа.', - 'shipping_address_error' => 'Не указан адрес доставки', - 'email_taken_error' => 'Этот email уже зарегистрирован. Войдите в свой аккаунт или укажите другой E-mail.', - 'phone_number_error' => 'Неправильно введен номер', - 'shipping_method_missing' => 'Не выбран метод доставки. Пожалуйста перепроверьте ваш адрес или обратитесь за помощью к администрации сайта.', - 'change_address' => 'Изменить адрес', - 'shipping_updated' => 'Методы доставки будут обновлены в процессе оформления заказа.', - 'coupon_applied' => 'Применен промокод: ' - ] - ]; $current_translations = $translations[$lang] ?? $translations['en']; diff --git a/wp-content/themes/cosmopet/modules/shop/components/checkout/assets/css/checkout.css b/wp-content/themes/cosmopet/modules/shop/components/checkout/assets/css/checkout.css index 13f7168..5db41ee 100644 --- a/wp-content/themes/cosmopet/modules/shop/components/checkout/assets/css/checkout.css +++ b/wp-content/themes/cosmopet/modules/shop/components/checkout/assets/css/checkout.css @@ -585,6 +585,7 @@ .form-agreement__check{ display: flex; align-items: center; + margin-top: 1rem; } .form-agreement__square{ width: 18px; diff --git a/wp-content/themes/cosmopet/static/js/cdek-map.js b/wp-content/themes/cosmopet/static/js/cdek-map.js index 77581ad..d90c76c 100644 --- a/wp-content/themes/cosmopet/static/js/cdek-map.js +++ b/wp-content/themes/cosmopet/static/js/cdek-map.js @@ -1,4 +1,11 @@ -( () => { +/* + +Start: cdek-map.js +Перезапись стандартного скрипта от cdek плагина для подключения дополнительной логики обработчиков + +*/ + +(() => { "use strict"; var e = { n: t => { @@ -7,114 +14,107 @@ a: o }), o - } - , + }, d: (t, o) => { for (var n in o) e.o(o, n) && !e.o(t, n) && Object.defineProperty(t, n, { enumerable: !0, get: o[n] }) - } - , + }, o: (e, t) => Object.prototype.hasOwnProperty.call(e, t) }; const t = window.jQuery; var o = e.n(t); const n = window.CDEKWidget; var i = e.n(n); - const c = window.wp.i18n - , d = window.lodash - , r = o()("#billing_city") - , a = o()("#shipping_city") - , l = "aria-small"; + const c = window.wp.i18n, + d = window.lodash, + r = o()("#billing_city"), + a = o()("#shipping_city"), + l = "aria-small"; const h = (e, t, n) => { - console.log("Widget object:", g); - console.log("g.close is", typeof g.close); + console.log("Widget object:", g); + console.log("g.close is", typeof g.close); - o()(".cdek-office-code").val(n.code); - u.find("a").html((0, c.__)("Re-select pick-up", "cdekdelivery")); + o()(".cdek-office-code").val(n.code); + u.find("a").html(window.langData.translations["Re-select pick-up"] || "Re-select pick-up"); - const i = u.parent().children(".cdek-office-info"); - if (i.length === 0) { - u.before(o()('
').text(n.name)); - } else { - i.text(n.name); - } + const i = u.parent().children(".cdek-office-info"); + if (i.length === 0) { + u.before(o()('').text(n.name)); + } else { + i.text(n.name); + } - o()("#pvz_inp").val(n.name); + o()("#pvz_inp").val(n.name); - if (g && typeof g.close === "function") { - g.close(); - } else { - console.warn("g.close is not available, trying fallback"); - o()(".cdek-widget__popup-close").click(); // альтернатива - } + if (g && typeof g.close === "function") { + g.close(); + } else { + console.warn("g.close is not available, trying fallback"); + o()(".cdek-widget__popup-close").click(); // альтернатива + } - if (window.cdek.saver !== undefined) { - o().post(window.cdek.saver, { - code: n.code - }); - } -}; + if (window.cdek.saver !== undefined) { + o().post(window.cdek.saver, { + code: n.code + }); + } + }; let s, p, u, g = null; "" === (r.val() || "") && "" === (a.val() || "") || (console.debug("[CDEK-MAP] City has value, initiating checkout update"), - o()(document.body).trigger("update_checkout")); - const v = (e, t=null) => { - if (console.debug("[CDEK-MAP] Removing selected office info"), - o()(".cdek-office-info").remove(), - e.find("a").html((0, - c.__)("Choose pick-up", "cdekdelivery")), - o()(".cdek-office-code").val(""), - null !== g && g.clearSelection(), - "string" == typeof t) { - console.debug("[CDEK-MAP] Rendering error message"); - const e = o()(".open-pvz-btn"); - e.prev().text(t), - e.remove() - } - } - , f = (0, - d.debounce)(( () => { - "" !== (o()("#ship-to-different-address-checkbox").is(":checked") ? a.val() : r.val()) && (console.debug("[CDEK-MAP] City or postcode changed, initiating checkout update"), - void 0 !== window.cdek.saver && o().post(window.cdek.saver, { - code: null - }), - o()(document.body).trigger("update_checkout")) - } - ), 500) - , b = new ResizeObserver((e => { - for (const t of e) - "contentRect"in t && "target"in t && (t.contentRect.width < 160 ? p && (p = !1, - s = !0) : p || (p = !0, - s = !0), - s && (p ? t.target.hasAttribute(l) && t.target.removeAttribute(l) : t.target.hasAttribute(l) || t.target.setAttribute(l, ""), - s = !1)) - } - )); + o()(document.body).trigger("update_checkout")); + const v = (e, t = null) => { + if (console.debug("[CDEK-MAP] Removing selected office info"), + o()(".cdek-office-info").remove(), + e.find("a").html(window.langData.translations["Choose pick-up"] || "Choose pick-up"), + o()(".cdek-office-code").val(""), + null !== g && g.clearSelection(), + "string" == typeof t) { + console.debug("[CDEK-MAP] Rendering error message"); + const e = o()(".open-pvz-btn"); + e.prev().text(t), + e.remove() + } + }, + f = (0, + d.debounce)((() => { + "" !== (o()("#ship-to-different-address-checkbox").is(":checked") ? a.val() : r.val()) && (console.debug("[CDEK-MAP] City or postcode changed, initiating checkout update"), + void 0 !== window.cdek.saver && o().post(window.cdek.saver, { + code: null + }), + o()(document.body).trigger("update_checkout")) + }), 500), + b = new ResizeObserver((e => { + for (const t of e) + "contentRect" in t && "target" in t && (t.contentRect.width < 160 ? p && (p = !1, + s = !0) : p || (p = !0, + s = !0), + s && (p ? t.target.hasAttribute(l) && t.target.removeAttribute(l) : t.target.hasAttribute(l) || t.target.setAttribute(l, ""), + s = !1)) + })); - o()(document.body).on("input", "#billing_city, #billing_postcode, #shipping_city, #shipping_postcode", f).on("updated_checkout", ( () => { + o()(document.body).on("input", "#billing_city, #billing_postcode, #shipping_city, #shipping_postcode", f).on("updated_checkout", (() => { const e = document.querySelector(".open-pvz-btn"); null !== g && (console.debug("[CDEK-MAP] Clearing widget selection"), - g.clearSelection()), - e && (s = !1, - p = !0, - b.observe(e)) - } - )).on("change", ".shipping_method", ( () => o()(document.body).trigger("update_checkout"))).on("click", ".open-pvz-btn", null, (e => { + g.clearSelection()), + e && (s = !1, + p = !0, + b.observe(e)) + })).on("change", ".shipping_method", (() => o()(document.body).trigger("update_checkout"))).on("click", ".open-pvz-btn", null, (e => { u = "A" === e.target.tagName ? o()(e.target.parentElement) : o()(e.target), - v(u); + v(u); try { const e = JSON.parse(u.find("script").text()); if (console.debug("[CDEK-MAP] Got points from backend", e), - !e.length) + !e.length) return console.warn("[CDEK-MAP] Backend points are empty"), - void v(u, (0, - c.__)("There are no CDEK pick-up points available in this direction, please select another delivery method", "cdekdelivery")); - null === g ? g = new (i())({ + void v(u, window.langData.translations["There are no CDEK pick-up points available in this direction, please select another delivery method"] || "There are no CDEK pick-up points available in this direction, please select another delivery method"); + null === g ? g = new(i())({ apiKey: window.cdek.key, popup: !0, debug: !0, @@ -126,14 +126,11 @@ }, onChoose: h }) : (g.updateOfficesRaw(e), - g.updateLocation(u.data("city"))), - g.open() + g.updateLocation(u.data("city"))), + g.open() } catch (e) { console.error("[CDEK-MAP] SyntaxError during points parse"), - v(u, (0, - c.__)("There are no CDEK pick-up points available in this direction, please select another delivery method", "cdekdelivery")) + v(u, window.langData.translations["There are no CDEK pick-up points available in this direction, please select another delivery method"] || "There are no CDEK pick-up points available in this direction, please select another delivery method") } - } - )) -} -)(); + })) +})(); diff --git a/wp-content/themes/cosmopet/templates/shop/checkout.twig b/wp-content/themes/cosmopet/templates/shop/checkout.twig index 410f9b1..73b823d 100644 --- a/wp-content/themes/cosmopet/templates/shop/checkout.twig +++ b/wp-content/themes/cosmopet/templates/shop/checkout.twig @@ -21,12 +21,12 @@