Выберите город пункта выдачи

Нажмите для загрузки карты

Связаться в WhatsApp
// purchase по обычной странице успеха /order/?ORDER_ID=... (function(){ try { var u = new URL(location.href); var orderId = u.searchParams.get("ORDER_ID"); if (orderId) sendPurchase(orderId); } catch(e){} })(); // ---------- FIX "Купить в 1 клик": не уходим на script.php, отправляем AJAX ---------- document.addEventListener('submit', function(e){ var form = e.target; if (!form || form.id !== 'one_click_buy_form') return; e.preventDefault(); e.stopImmediatePropagation(); if (form.__oneclick_sending) return; form.__oneclick_sending = true; var action = form.getAttribute('action') || '/bitrix/components/aspro/oneclickbuy.optimus/script.php'; fetch(action, { method: 'POST', body: new FormData(form), credentials: 'same-origin' }) .then(function(r){ return r.text(); }) .then(function(t){ var obj = null; try { obj = JSON.parse(t); } catch(e) {} if (obj && obj.result === "Y" && obj.message) { sendPurchase(obj.message); // obj.message = ORDER_ID } // закрываем модалку (Aspro jqm) var w = form.closest('.jqmWindow') || form.closest('.jqmWindow.popup') || form.closest('.jqmWindow'); var closeBtn = (w && w.querySelector('.jqmClose')) || document.querySelector('.jqmClose'); if (closeBtn) closeBtn.click(); form.__oneclick_sending = false; }) .catch(function(){ form.__oneclick_sending = false; }); }, true); // ---------- CART VIEW (просмотр корзины) ---------- function sendCartView(){ if (window.__YM_CART_VIEW_SENT) return; window.__YM_CART_VIEW_SENT = true; fetch("/ajax/ym_basket.php", { credentials: "same-origin" }) .then(function(r){ return r.json(); }) .then(function(data){ if (!data || !data.ok || !data.products || !data.products.length) return; window.dataLayer.push({ ecommerce: { currencyCode: "RUB", checkout: { actionField: { step: 1 }, products: data.products } } }); setTimeout(function(){ try { if (typeof ym === "function") { ym(88261505, "reachGoal", "basket_view", {total: data.total, items: data.products.length}); } } catch(e){} }, 0); }) .catch(function(){}); } (function(){ if (location.pathname.indexOf("/basket") === 0) { sendCartView(); } })(); // XHR hook — ловим факт успешного добавления (function(){ var origOpen = XMLHttpRequest.prototype.open; var origSend = XMLHttpRequest.prototype.send; XMLHttpRequest.prototype.open = function(method, url){ this.__ym_url = url; this.__ym_method = method; return origOpen.apply(this, arguments); }; XMLHttpRequest.prototype.send = function(){ this.addEventListener('loadend', function(){ try{ var url = String(this.__ym_url || ''); // 1) add в корзину (как было) if (this.status >= 200 && this.status < 400 && isBasketRequest(url)) { flushPendingAdd(); } // 2) purchase для "1 клик" (НО УЖЕ НЕ ВНУТРИ if корзины!) if (this.status >= 200 && this.status < 400 && url.includes('/bitrix/components/aspro/oneclickbuy.optimus/script.php')) { var text = (this.responseText || '').toString(); var obj = null; try { obj = JSON.parse(text); } catch(e) {} if (obj && obj.result === "Y" && obj.message) { sendPurchase(obj.message); // obj.message = ORDER_ID } } } catch(e){} }); return origSend.apply(this, arguments); }; })(); // fetch hook — если добавление через fetch (function(){ if (!window.fetch) return; var origFetch = window.fetch; window.fetch = function(input, init){ var url = (typeof input === 'string') ? input : (input && input.url ? input.url : ''); return origFetch.apply(this, arguments).then(function(res){ try{ if (res && res.ok && isBasketRequest(url)) flushPendingAdd(); } catch(e){} return res; }); }; })(); })();