Advertisement
destpat

Untitled

Aug 23rd, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.97 KB | None | 0 0
  1. // /******** UPDATE HERE ********/
  2. // // window.siteBaseUrl = "https://shopify-stage.sympl.fr/";
  3. // const SITE_BASE_URL = "https://shopify-stage.sympl.fr/";
  4. // /******** END UPDATE ********/
  5. //
  6. // const ON_TOP_CSS = "position: relative; z-index: 10000;";
  7. //
  8. // // import React from "react";
  9. // // import ReactDOM from "react-dom";
  10. // import shopify from "../api/api";
  11. //
  12. // var totalOrderWeight = 0;
  13. //
  14. // (function() {
  15. // "use strict";
  16. // //console.log("A l'intérieur du ScriptTag pour le checkout");
  17. //
  18. // var loadingDiv = null,
  19. // contentBoxDiv = null,
  20. // selectedRelayPoint = null;
  21. //
  22. // var relayPointIFrame = null;
  23. // var shopifyOrderObject = null;
  24. // var isRelayPointSelected = false;
  25. //
  26. // function launch_everything() {
  27. // var url_path = window.location.pathname;
  28. //
  29. // if (
  30. // url_path.match(/.*\/checkouts\/.*\/thank_you$/) ||
  31. // url_path.match(/.*\/orders\/.*$/)
  32. // ) {
  33. // modify_order_page();
  34. // }
  35. // }
  36. //
  37. // function modify_order_page() {
  38. // add_listener();
  39. // var shippingMethod = shopifyOrderObject.shipping_lines[0].code;
  40. // //console.log("shipping: " + shippingMethod);
  41. // if (Shopify.checkout) {
  42. // // Les codes de livraison ont le préfixe SYMPL_ pour le module Shopify mais il faut les enlever avant de les envoyer à Sympl.
  43. // if (
  44. // shippingMethod &&
  45. // shippingMethod.length &&
  46. // shippingMethod.toLowerCase().match(/sympl/) &&
  47. // shippingMethod.toLowerCase().match(/pickup_point/)
  48. // ) {
  49. // shopify
  50. // .getOrderMetafield(shopifyOrderObject.id)
  51. // .then(function(jsonResponse) {
  52. // let existingMetafields = jsonResponse;
  53. //
  54. // if (
  55. // existingMetafields &&
  56. // existingMetafields.metafields &&
  57. // existingMetafields.metafields.length
  58. // ) {
  59. // for (
  60. // let metafield_counter = 0;
  61. // metafield_counter < existingMetafields.metafields.length;
  62. // metafield_counter++
  63. // ) {
  64. // let currentMetafield =
  65. // existingMetafields.metafields[metafield_counter];
  66. //
  67. // if (
  68. // currentMetafield.namespace == "sympl_data" &&
  69. // currentMetafield.key == "sympl_relay_point"
  70. // ) {
  71. // selectedRelayPoint = JSON.parse(currentMetafield.value);
  72. // //console.log("Point relais lu: ");
  73. // //console.log(selectedRelayPoint);
  74. // isRelayPointSelected = true;
  75. // }
  76. // }
  77. // }
  78. //
  79. // if (!isRelayPointSelected) {
  80. // calculate_order_total_weight();
  81. // create_information_div();
  82. // display_first_time_relay_point_pickup_text();
  83. // } else {
  84. // display_relay_point_info_text();
  85. // }
  86. // });
  87. // }
  88. // }
  89. // }
  90. //
  91. // function add_listener() {
  92. // window.addEventListener("message", process_relay_point_selection, false);
  93. // }
  94. //
  95. // function process_relay_point_selection(event) {
  96. // if (event.data.messageType == "pickup_point_selected") {
  97. // selectedRelayPoint = event.data.selectedPickupPoint;
  98. // display_relay_point_info_text();
  99. //
  100. // // Le loadingDiv n'existe pas si on revient sur la page d'une commande.
  101. // if (loadingDiv) {
  102. // loadingDiv.style.cssText = "";
  103. // }
  104. //
  105. // remove_relay_point_iframe();
  106. //
  107. // // Mise à jour de la commande chez Shopify
  108. // update_shopify_order(
  109. // shopifyOrderObject.id,
  110. // JSON.stringify(selectedRelayPoint)
  111. // );
  112. // }
  113. // }
  114. //
  115. // function remove_relay_point_iframe() {
  116. // delete_dom_element(relayPointIFrame);
  117. // contentBoxDiv.style.cssText = ON_TOP_CSS;
  118. // document.body.classList.remove("no-scroll");
  119. // document.documentElement.classList.remove("no-scroll");
  120. // }
  121. //
  122. // function convert_array_to_query_string(parameters) {
  123. // let urlStringParameters = [];
  124. //
  125. // for (var key in parameters) {
  126. // urlStringParameters.push(
  127. // encodeURIComponent(key) + "=" + encodeURIComponent(parameters[key])
  128. // );
  129. // }
  130. //
  131. // return urlStringParameters.join("&");
  132. // }
  133. //
  134. // function create_information_div(showOnTop = true) {
  135. // let shopifyContent = document.querySelector(".section > .section__content");
  136. // contentBoxDiv = document.createElement("div");
  137. // contentBoxDiv.classList.add("content-box");
  138. //
  139. // if (showOnTop) {
  140. // var styleTag = document.createElement("style");
  141. // styleTag.innerHTML = ".no-scroll {height: 100%; overflow: hidden;}";
  142. // document.head.appendChild(styleTag);
  143. //
  144. // contentBoxDiv.style.cssText = ON_TOP_CSS;
  145. // }
  146. //
  147. // shopifyContent.insertBefore(contentBoxDiv, shopifyContent.firstChild);
  148. //
  149. // if (showOnTop) {
  150. // loadingDiv = document.createElement("div");
  151. // loadingDiv.style.cssText =
  152. // "position: fixed; top: 0; left: 0; bottom: 0; right: 0; z-index: 9999; background-color: black; opacity: 0.8";
  153. // document.body.appendChild(loadingDiv);
  154. // }
  155. // }
  156. //
  157. // function display_first_time_relay_point_pickup_text() {
  158. // contentBoxDiv.innerHTML =
  159. // '<div class="content-box__row">' +
  160. // "<h2>Sélectionner un point relais</h2>" +
  161. // "</div>" +
  162. // '<div class="content-box__row content-box__row--no-border">' +
  163. // "<p>Vous avez choisi comme méthode de livraison une livraison à point relais. Vous devez maintenant sélectionner votre point relais.</p>" +
  164. // "</div>" +
  165. // '<div class="content-box__row">' +
  166. // '<button id="sympl-open-relay-point" class="btn step__footer__continue-btn">Choisir un point relais</button>' +
  167. // "</div>";
  168. //
  169. // document.getElementById(
  170. // "sympl-open-relay-point"
  171. // ).onclick = show_relay_point_iframe;
  172. // }
  173. //
  174. // function display_relay_point_info_text() {
  175. // let createdContentDiv = false;
  176. // let shopifyContent = document.querySelector(".section > .section__content");
  177. //
  178. // if (!contentBoxDiv) {
  179. // contentBoxDiv = document.createElement("div");
  180. // contentBoxDiv.classList.add("content-box");
  181. // createdContentDiv = true;
  182. // }
  183. //
  184. // contentBoxDiv.innerHTML =
  185. // '<div class="content-box__row">' +
  186. // "<h2>Vous avez choisi le point relais suivant&nbsp;:</h2>" +
  187. // "</div>" +
  188. // '<div class="content-box__row content-box__row--no-border">' +
  189. // "<p>" +
  190. // "<b>" +
  191. // selectedRelayPoint.name +
  192. // "</b><br>" +
  193. // selectedRelayPoint.street +
  194. // "<br>" +
  195. // selectedRelayPoint.postalCode +
  196. // " " +
  197. // selectedRelayPoint.city +
  198. // "</p>" +
  199. // "<p>&nbsp;</p>" +
  200. // "</div>";
  201. //
  202. // if (createdContentDiv) {
  203. // shopifyContent.insertBefore(contentBoxDiv, shopifyContent.firstChild);
  204. // }
  205. // }
  206. //
  207. // function delete_dom_element(element) {
  208. // if (element.remove !== undefined) {
  209. // element.remove();
  210. // } else {
  211. // element && element.parentNode && element.parentNode.removeChild(element);
  212. // }
  213. // }
  214. //
  215. // function show_relay_point_iframe(evt) {
  216. // evt.preventDefault();
  217. //
  218. // var msie = document.documentMode;
  219. // if (msie && msie <= 9) {
  220. // alert(
  221. // "Vous utilisez un navigateur obsol\u00e8te. Veuillez mettre \u00e0 jour votre navigateur afin de pouvoir s\u00e9lectionner votre point relais."
  222. // );
  223. // return;
  224. // }
  225. //
  226. let iFrameParameters = {
  227. // address1: shopifyOrderObject.shipping_address.address1,
  228. // postcode: shopifyOrderObject.shipping_address.zip,
  229. // city: shopifyOrderObject.shipping_address.city,
  230. parentProtocol: "https",
  231. shopDomain: Shopify.Checkout.apiHost,
  232. // parentHostname: SITE_BASE_URL.replace("https://", "").replace("/", ""),
  233. // reference: shopifyOrderObject.shipping_address.name,
  234. // offerCode: shopifyOrderObject.shipping_lines[0].code.replace(
  235. // "SYMPL_",
  236. // ""
  237. // ),
  238. // weight: totalOrderWeight,
  239. shopifyOrderId: Shopify.checkout.order_id
  240. };
  241. console.log(iFrameParameters);
  242. //
  243. // //console.log("Ouverture de la sélection de point relais avec les données suivantes:");
  244. // //console.log(iFrameParameters);
  245. //
  246. // contentBoxDiv.style.cssText = "";
  247. // let iframe_url =
  248. // SITE_BASE_URL +
  249. // "iframe.php?" +
  250. // convert_array_to_query_string(iFrameParameters);
  251. // //console.log("iFrame URL:" + iframe_url);
  252. //
  253. // relayPointIFrame = document.createElement("iframe");
  254. // relayPointIFrame.src = iframe_url;
  255. // relayPointIFrame.id = "sympl_relay_point_map";
  256. // relayPointIFrame.style.cssText =
  257. // "position: fixed; top: 0; left: 0; width: 100%; height: 100%; border: 0; z-index: 20000; overflow: hidden; height: 100%; width: 100%";
  258. // relayPointIFrame.height = "100%";
  259. // relayPointIFrame.width = "100%";
  260. // document.body.appendChild(relayPointIFrame);
  261. // document.body.classList.add("no-scroll");
  262. // document.documentElement.classList.add("no-scroll");
  263. // }
  264. //
  265. // function update_shopify_order(shopifyOrderId, relayPointData = null) {
  266. // //console.log("Update shopify order ID: " + shopifyOrderId);
  267. //
  268. // if (relayPointData != null) {
  269. // shopify
  270. // .addOrderMetafield(
  271. // shopifyOrderId,
  272. // "sympl_relay_point",
  273. // relayPointData,
  274. // "json_string"
  275. // )
  276. // .then(function(responseRelayPointMetaField) {
  277. // //console.log("Réponse Metafield RelayPoint:");
  278. // //console.log(responseRelayPointMetaField);
  279. // return true;
  280. // });
  281. // }
  282. // }
  283. //
  284. // function calculate_order_total_weight() {
  285. // let totalWeight = 0;
  286. // for (
  287. // let itemCounter = 0;
  288. // itemCounter < shopifyOrderObject.line_items.length;
  289. // itemCounter++
  290. // ) {
  291. // totalWeight += shopifyOrderObject.line_items[itemCounter].grams;
  292. // }
  293. //
  294. // // Prevent empty weight
  295. // if (totalWeight == 0) {
  296. // totalWeight = 300; // grams
  297. // }
  298. //
  299. // totalOrderWeight = Math.round(totalWeight * 1.15) / 1000; // 115% du poids total pour accommoder l'emballage et / 1000 parce que le poids est en gramme.
  300. // return totalOrderWeight;
  301. // }
  302. //
  303. // if (Shopify && Shopify.checkout && Shopify.checkout.order_id) {
  304. // shopify
  305. // .getOrderMetafield(Shopify.checkout.order_id)
  306. // .then(function(jsonResponse) {
  307. // if (jsonResponse && jsonResponse.order) {
  308. // shopifyOrderObject = jsonResponse.order;
  309. // launch_everything();
  310. // }
  311. // });
  312. // }
  313. // })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement