Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // /******** UPDATE HERE ********/
- // // window.siteBaseUrl = "https://shopify-stage.sympl.fr/";
- // const SITE_BASE_URL = "https://shopify-stage.sympl.fr/";
- // /******** END UPDATE ********/
- //
- // const ON_TOP_CSS = "position: relative; z-index: 10000;";
- //
- // // import React from "react";
- // // import ReactDOM from "react-dom";
- // import shopify from "../api/api";
- //
- // var totalOrderWeight = 0;
- //
- // (function() {
- // "use strict";
- // //console.log("A l'intérieur du ScriptTag pour le checkout");
- //
- // var loadingDiv = null,
- // contentBoxDiv = null,
- // selectedRelayPoint = null;
- //
- // var relayPointIFrame = null;
- // var shopifyOrderObject = null;
- // var isRelayPointSelected = false;
- //
- // function launch_everything() {
- // var url_path = window.location.pathname;
- //
- // if (
- // url_path.match(/.*\/checkouts\/.*\/thank_you$/) ||
- // url_path.match(/.*\/orders\/.*$/)
- // ) {
- // modify_order_page();
- // }
- // }
- //
- // function modify_order_page() {
- // add_listener();
- // var shippingMethod = shopifyOrderObject.shipping_lines[0].code;
- // //console.log("shipping: " + shippingMethod);
- // if (Shopify.checkout) {
- // // Les codes de livraison ont le préfixe SYMPL_ pour le module Shopify mais il faut les enlever avant de les envoyer à Sympl.
- // if (
- // shippingMethod &&
- // shippingMethod.length &&
- // shippingMethod.toLowerCase().match(/sympl/) &&
- // shippingMethod.toLowerCase().match(/pickup_point/)
- // ) {
- // shopify
- // .getOrderMetafield(shopifyOrderObject.id)
- // .then(function(jsonResponse) {
- // let existingMetafields = jsonResponse;
- //
- // if (
- // existingMetafields &&
- // existingMetafields.metafields &&
- // existingMetafields.metafields.length
- // ) {
- // for (
- // let metafield_counter = 0;
- // metafield_counter < existingMetafields.metafields.length;
- // metafield_counter++
- // ) {
- // let currentMetafield =
- // existingMetafields.metafields[metafield_counter];
- //
- // if (
- // currentMetafield.namespace == "sympl_data" &&
- // currentMetafield.key == "sympl_relay_point"
- // ) {
- // selectedRelayPoint = JSON.parse(currentMetafield.value);
- // //console.log("Point relais lu: ");
- // //console.log(selectedRelayPoint);
- // isRelayPointSelected = true;
- // }
- // }
- // }
- //
- // if (!isRelayPointSelected) {
- // calculate_order_total_weight();
- // create_information_div();
- // display_first_time_relay_point_pickup_text();
- // } else {
- // display_relay_point_info_text();
- // }
- // });
- // }
- // }
- // }
- //
- // function add_listener() {
- // window.addEventListener("message", process_relay_point_selection, false);
- // }
- //
- // function process_relay_point_selection(event) {
- // if (event.data.messageType == "pickup_point_selected") {
- // selectedRelayPoint = event.data.selectedPickupPoint;
- // display_relay_point_info_text();
- //
- // // Le loadingDiv n'existe pas si on revient sur la page d'une commande.
- // if (loadingDiv) {
- // loadingDiv.style.cssText = "";
- // }
- //
- // remove_relay_point_iframe();
- //
- // // Mise à jour de la commande chez Shopify
- // update_shopify_order(
- // shopifyOrderObject.id,
- // JSON.stringify(selectedRelayPoint)
- // );
- // }
- // }
- //
- // function remove_relay_point_iframe() {
- // delete_dom_element(relayPointIFrame);
- // contentBoxDiv.style.cssText = ON_TOP_CSS;
- // document.body.classList.remove("no-scroll");
- // document.documentElement.classList.remove("no-scroll");
- // }
- //
- // function convert_array_to_query_string(parameters) {
- // let urlStringParameters = [];
- //
- // for (var key in parameters) {
- // urlStringParameters.push(
- // encodeURIComponent(key) + "=" + encodeURIComponent(parameters[key])
- // );
- // }
- //
- // return urlStringParameters.join("&");
- // }
- //
- // function create_information_div(showOnTop = true) {
- // let shopifyContent = document.querySelector(".section > .section__content");
- // contentBoxDiv = document.createElement("div");
- // contentBoxDiv.classList.add("content-box");
- //
- // if (showOnTop) {
- // var styleTag = document.createElement("style");
- // styleTag.innerHTML = ".no-scroll {height: 100%; overflow: hidden;}";
- // document.head.appendChild(styleTag);
- //
- // contentBoxDiv.style.cssText = ON_TOP_CSS;
- // }
- //
- // shopifyContent.insertBefore(contentBoxDiv, shopifyContent.firstChild);
- //
- // if (showOnTop) {
- // loadingDiv = document.createElement("div");
- // loadingDiv.style.cssText =
- // "position: fixed; top: 0; left: 0; bottom: 0; right: 0; z-index: 9999; background-color: black; opacity: 0.8";
- // document.body.appendChild(loadingDiv);
- // }
- // }
- //
- // function display_first_time_relay_point_pickup_text() {
- // contentBoxDiv.innerHTML =
- // '<div class="content-box__row">' +
- // "<h2>Sélectionner un point relais</h2>" +
- // "</div>" +
- // '<div class="content-box__row content-box__row--no-border">' +
- // "<p>Vous avez choisi comme méthode de livraison une livraison à point relais. Vous devez maintenant sélectionner votre point relais.</p>" +
- // "</div>" +
- // '<div class="content-box__row">' +
- // '<button id="sympl-open-relay-point" class="btn step__footer__continue-btn">Choisir un point relais</button>' +
- // "</div>";
- //
- // document.getElementById(
- // "sympl-open-relay-point"
- // ).onclick = show_relay_point_iframe;
- // }
- //
- // function display_relay_point_info_text() {
- // let createdContentDiv = false;
- // let shopifyContent = document.querySelector(".section > .section__content");
- //
- // if (!contentBoxDiv) {
- // contentBoxDiv = document.createElement("div");
- // contentBoxDiv.classList.add("content-box");
- // createdContentDiv = true;
- // }
- //
- // contentBoxDiv.innerHTML =
- // '<div class="content-box__row">' +
- // "<h2>Vous avez choisi le point relais suivant :</h2>" +
- // "</div>" +
- // '<div class="content-box__row content-box__row--no-border">' +
- // "<p>" +
- // "<b>" +
- // selectedRelayPoint.name +
- // "</b><br>" +
- // selectedRelayPoint.street +
- // "<br>" +
- // selectedRelayPoint.postalCode +
- // " " +
- // selectedRelayPoint.city +
- // "</p>" +
- // "<p> </p>" +
- // "</div>";
- //
- // if (createdContentDiv) {
- // shopifyContent.insertBefore(contentBoxDiv, shopifyContent.firstChild);
- // }
- // }
- //
- // function delete_dom_element(element) {
- // if (element.remove !== undefined) {
- // element.remove();
- // } else {
- // element && element.parentNode && element.parentNode.removeChild(element);
- // }
- // }
- //
- // function show_relay_point_iframe(evt) {
- // evt.preventDefault();
- //
- // var msie = document.documentMode;
- // if (msie && msie <= 9) {
- // alert(
- // "Vous utilisez un navigateur obsol\u00e8te. Veuillez mettre \u00e0 jour votre navigateur afin de pouvoir s\u00e9lectionner votre point relais."
- // );
- // return;
- // }
- //
- let iFrameParameters = {
- // address1: shopifyOrderObject.shipping_address.address1,
- // postcode: shopifyOrderObject.shipping_address.zip,
- // city: shopifyOrderObject.shipping_address.city,
- parentProtocol: "https",
- shopDomain: Shopify.Checkout.apiHost,
- // parentHostname: SITE_BASE_URL.replace("https://", "").replace("/", ""),
- // reference: shopifyOrderObject.shipping_address.name,
- // offerCode: shopifyOrderObject.shipping_lines[0].code.replace(
- // "SYMPL_",
- // ""
- // ),
- // weight: totalOrderWeight,
- shopifyOrderId: Shopify.checkout.order_id
- };
- console.log(iFrameParameters);
- //
- // //console.log("Ouverture de la sélection de point relais avec les données suivantes:");
- // //console.log(iFrameParameters);
- //
- // contentBoxDiv.style.cssText = "";
- // let iframe_url =
- // SITE_BASE_URL +
- // "iframe.php?" +
- // convert_array_to_query_string(iFrameParameters);
- // //console.log("iFrame URL:" + iframe_url);
- //
- // relayPointIFrame = document.createElement("iframe");
- // relayPointIFrame.src = iframe_url;
- // relayPointIFrame.id = "sympl_relay_point_map";
- // relayPointIFrame.style.cssText =
- // "position: fixed; top: 0; left: 0; width: 100%; height: 100%; border: 0; z-index: 20000; overflow: hidden; height: 100%; width: 100%";
- // relayPointIFrame.height = "100%";
- // relayPointIFrame.width = "100%";
- // document.body.appendChild(relayPointIFrame);
- // document.body.classList.add("no-scroll");
- // document.documentElement.classList.add("no-scroll");
- // }
- //
- // function update_shopify_order(shopifyOrderId, relayPointData = null) {
- // //console.log("Update shopify order ID: " + shopifyOrderId);
- //
- // if (relayPointData != null) {
- // shopify
- // .addOrderMetafield(
- // shopifyOrderId,
- // "sympl_relay_point",
- // relayPointData,
- // "json_string"
- // )
- // .then(function(responseRelayPointMetaField) {
- // //console.log("Réponse Metafield RelayPoint:");
- // //console.log(responseRelayPointMetaField);
- // return true;
- // });
- // }
- // }
- //
- // function calculate_order_total_weight() {
- // let totalWeight = 0;
- // for (
- // let itemCounter = 0;
- // itemCounter < shopifyOrderObject.line_items.length;
- // itemCounter++
- // ) {
- // totalWeight += shopifyOrderObject.line_items[itemCounter].grams;
- // }
- //
- // // Prevent empty weight
- // if (totalWeight == 0) {
- // totalWeight = 300; // grams
- // }
- //
- // totalOrderWeight = Math.round(totalWeight * 1.15) / 1000; // 115% du poids total pour accommoder l'emballage et / 1000 parce que le poids est en gramme.
- // return totalOrderWeight;
- // }
- //
- // if (Shopify && Shopify.checkout && Shopify.checkout.order_id) {
- // shopify
- // .getOrderMetafield(Shopify.checkout.order_id)
- // .then(function(jsonResponse) {
- // if (jsonResponse && jsonResponse.order) {
- // shopifyOrderObject = jsonResponse.order;
- // launch_everything();
- // }
- // });
- // }
- // })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement