Task 6977 | кастомизировал js логику cdek widget для отображения выбранного пункта ПВЗ. Добавил в файлы темы перезаписанную версию скрипта (защита от обновления и переустановки плагина)

pull/36/head
parent 826fd48617
commit ec954cd75a
  1. 16
      wp-content/themes/cosmopet/global-functions/plugin-override-functions.php
  2. 2
      wp-content/themes/cosmopet/modules/footer/module-controller.php
  3. 139
      wp-content/themes/cosmopet/static/js/cdek-map.js
  4. 6
      wp-content/themes/cosmopet/templates/footer.twig

@ -0,0 +1,16 @@
<?php
add_action('wp_enqueue_scripts', 'override_cdek_widget_script', 100);
function override_cdek_widget_script() {
// Убираем оригинал
wp_dequeue_script('cdek-map');
wp_deregister_script('cdek-map');
// Подключаем свой модифицированный
wp_enqueue_script(
'cdek-map', // тот же handle — это ВАЖНО!
get_stylesheet_directory_uri() . '/static/js/cdek-map.js',
['jquery', 'lodash', 'wp-i18n', 'cdek-widget'], // зависимости, если нужны
'1.0',
true // в футере
);
}

@ -6,7 +6,7 @@ add_filter('timber/context', function($context) {
$context['email_list_ae'] = get_field('email_list_ae', 'options'); $context['email_list_ae'] = get_field('email_list_ae', 'options');
$context['adres'] = get_field('adres', 'options'); $context['adres'] = get_field('adres', 'options');
$context['social'] = get_field('social', 'options'); $context['social'] = get_field('social', 'options');
$context['links'] = get_field('links', 'options'); $context['footer-links'] = get_field('footer-links', 'options');
return $context; return $context;
}); });

@ -0,0 +1,139 @@
( () => {
"use strict";
var e = {
n: t => {
var o = t && t.__esModule ? () => t.default : () => t;
return e.d(o, {
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 h = (e, t, n) => {
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"));
const i = u.parent().children(".cdek-office-info");
if (i.length === 0) {
u.before(o()('<div class="cdek-office-info"></div>').text(n.name));
} else {
i.text(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 (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).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 => {
u = "A" === e.target.tagName ? o()(e.target.parentElement) : o()(e.target),
v(u);
try {
const e = JSON.parse(u.find("script").text());
if (console.debug("[CDEK-MAP] Got points from backend", e),
!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())({
apiKey: window.cdek.key,
popup: !0,
debug: !0,
lang: window.cdek.lang,
defaultLocation: u.data("city"),
officesRaw: e,
hideDeliveryOptions: {
door: !0
},
onChoose: h
}) : (g.updateOfficesRaw(e),
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"))
}
}
))
}
)();

@ -81,9 +81,9 @@
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
{% for item in links %} <a href="/privacy-policy/" class="footer-about__text" target="_blank">Соглашение о конфиденциальности</a>
<a href="{{item.link}}">{{item.name}}</a> <a href="/wp-content/uploads/2025/06/declaration_korm.pdf" class="footer-about__text" target="_blank">Декларация соответствия корма</a>
{% endfor %} <a href="/wp-content/uploads/2025/06/declaration_lakomstva.pdf" class="footer-about__text" target="_blank">Декларация соответствия лакомств</a>
</div> </div>
{% endif %} {% endif %}

Loading…
Cancel
Save