Created
October 15, 2022 20:59
-
-
Save klim2020/2509c291ab4564d18fe6609d49fb30ab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- отправка десктопа --> | |
| <script> | |
| document.addEventListener("DOMContentLoaded", function(event) { | |
| let title = "{{ resources['client_order_title'] }} №{{ order.id }}"//Заявка номер 111 | |
| let name = "{{ order.user_name }}"//Alexey | |
| let email = "{{ order.email }}";//Alexey | |
| let orderType = "{{ order.delivery.title }}";//Доставка по Киеву | |
| let phone = "{{ order.phone }}";//8097785445 | |
| let deliverySumm = "{{ order.delivery_fee | money }}".replace(/\s/g, '');//8097785445 | |
| let totalSumm = "{{ order.products_price | money }}".replace(/\s/g, '');//8097785445 | |
| let the_info = "{{ order.additional_info }}"; | |
| let body = { | |
| name: name, | |
| phone: phone, | |
| comp_name: name, | |
| the_title: title, | |
| company: name, | |
| email:email, | |
| comments: `тип доставки - ${orderType}, цена доставки - ${deliverySumm}+ общая сумма заказа - ${totalSumm}\n комментарий: ${the_info}`, | |
| summ:totalSumm, | |
| delivery_type:orderType, | |
| source_id:"тестовый магазин", | |
| products:[] | |
| } | |
| {% for item in order.cart.items %} | |
| let sku = "{{ item.product.articul }}"; | |
| if (sku==""){ | |
| const regex = /\/([^\/]+)$/gm; | |
| // Alternative syntax using RegExp constructor | |
| // const regex = new RegExp('\\/([^\\/]+)$', 'gm') | |
| const str = `{{ item.product.url }}`; | |
| let m; | |
| while ((m = regex.exec(str)) !== null) { | |
| // This is necessary to avoid infinite loops with zero-width matches | |
| if (m.index === regex.lastIndex) { | |
| regex.lastIndex++; | |
| } | |
| sku = "test-"+m[1]; | |
| } | |
| } | |
| body.products.push({ | |
| name:"{{ item.product.title }}", | |
| sku:sku, | |
| price:parseInt("{{ item.total_price | money }}".replace(/ /g, "")), | |
| amount:{{item.quantity}} | |
| }); | |
| {% endfor %} | |
| /*$('.cart-tbl tbody tr').each(function(a,e){ | |
| let ptitle = $(this).find('.c-ttl').text().replace(/(\r\n|\n|\r)/gm, ""); | |
| let pprice = parseInt($(this).find('.c-price').text().replace(/ /g, "")); | |
| let pamount = $(this).find('.c-amount').text(); | |
| body.products.push({ | |
| title:ptitle, | |
| sku:"no-sku", | |
| price:pprice, | |
| amount:pamount | |
| }) | |
| })*/ | |
| var myHeaders = new Headers(); | |
| myHeaders.append("Content-Type", "application/json"); | |
| var requestOptions = { | |
| method: 'POST', | |
| headers: myHeaders, | |
| body: JSON.stringify(body), | |
| redirect: 'follow' | |
| }; | |
| fetch("https://microservice.forest.kiev.ua/sendtocrm", requestOptions) | |
| .then(response => response.text()) | |
| .then(result => alert('замовлення успiшно поставлено в чергу')) | |
| .catch(error => alert('сталася помилка при оформленнi замовленнorder.emailя')); | |
| }) | |
| </script> | |
| <!-- !jnghfdrf --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment