Last active
October 19, 2022 09:44
-
-
Save klim2020/c0ac1cfb72ec51e870d76dc3b0b9bae0 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 the_paytype = "{{ order.payment.title }}"; | |
| let contact_data = "{{ order.contact_info }}"; | |
| let body = { | |
| name: name, | |
| phone: phone, | |
| comp_name: name, | |
| the_title: title, | |
| company: name, | |
| email:email, | |
| comments: `Тип доставки: ${orderType} | Контактные данные: ${contact_data} | Тип оплаты: ${the_paytype} | Комментарий: ${the_info}`, | |
| summ:totalSumm, | |
| delivery_type:orderType, | |
| source_id:"магазин modem", | |
| 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 = "za5aya-"+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