Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoleone committed Jun 26, 2024
1 parent 29e0b05 commit a2f6c42
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 22 deletions.
6 changes: 3 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "YOURAPPNAME",
"vendor": "vtex",
"version": "0.0.1",
"name": "istore-pixel",
"vendor": "dunnesstores",
"version": "0.0.4",
"title": "CHANGEME",
"description": "CHANGEME",
"billingOptions": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "YOURAPPNAME",
"name": "istore-pixel",
"private": true,
"license": "UNLICENSED",
"scripts": {
Expand Down
75 changes: 66 additions & 9 deletions pixel/head.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,68 @@
<script>
(function() {
var appId = "{{settings.gtmId}}";
if (!appId) {
console.error('Warning: No APP NAME ID is defined. Please configure it in the apps admin.');
return
}
(async () => {
try {
console.log("PIXEL RUNNING")
// Utility function to safely get JSON from localStorage
const getLocalStorageJson = (key) => {
const value = window.localStorage.getItem(key);
return value ? JSON.parse(value) : null;
};

// Get query param - ready data
const urlParams = new URLSearchParams(window.location.search);
const iStoreIdParam = urlParams.get('iStoreId');
//console.log("PARAM", iStoreIdParam);

// Get order form id from local storage - ready data
const orderForm = getLocalStorageJson("orderform");
const orderFormId = orderForm?.id;
//console.log("ORDERFORMID", orderFormId);

// Get local storage for iStoreId and iStoreIdOrderFormValue
const iStoreIdValue = window.localStorage.getItem("iStoreId");
const iStoreIdOrderFormValue = window.localStorage.getItem("iStoreIdOrderform");
// console.log("CUSTOM STOREID LOCALSTORAGE", iStoreIdValue);
// console.log("CUSTOM ORDERFORMID LOCALSTORAGE", iStoreIdOrderFormValue);

// Check if iStoreIdValue & iStoreIdOrderFormValue should be updated or not
if (iStoreIdParam != null && iStoreIdParam !== iStoreIdValue) {
window.localStorage.setItem("iStoreId", iStoreIdParam);
window.localStorage.setItem("iStoreIdOrderform", orderFormId);
await setOrderFormCustomField(iStoreIdParam, orderFormId);
}

console.log("DATA", iStoreIdOrderFormValue, "&", orderFormId)
// If new order form, update local storage and custom data
if (iStoreIdOrderFormValue != null && orderFormId !== iStoreIdOrderFormValue) {
window.localStorage.setItem("iStoreIdOrderform", orderFormId);
await setOrderFormCustomField(iStoreIdValue, orderFormId);
}
console.log("AFTER orderform storage set")

// Add script here
})()
</script>
async function setOrderFormCustomField(iStoreId, orderFormId) {
const headers = new Headers({
"Content-Type": "application/json",
"Accept": "application/json"
});

const body = JSON.stringify({ "iStoreId": iStoreId });

const response = await fetch(`/api/checkout/pub/orderForm/${orderFormId}/customData/istore`, {
method: "PUT",
headers: headers,
body: body,
redirect: "follow"
});

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}

const data = await response.json();
console.log("Response from setOrderFormCustomField:", data);
}
} catch (error) {
console.error("Error in script execution:", error);
}
})();
</script>
4 changes: 2 additions & 2 deletions react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"apollo-client": "^2.6.8",
"graphql": "^14.5.4",
"react-intl": "^3.11.0",
"typescript": "3.8.3",
"typescript": "3.9.7",
"vtex.pixel-interfaces": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.pixel-interfaces@1.1.1/public/_types/react",
"vtex.render-runtime": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.124.3/public/@types/vtex.render-runtime"
}
}
}
8 changes: 4 additions & 4 deletions react/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4824,10 +4824,10 @@ type-check@~0.3.2:
dependencies:
prelude-ls "~1.1.2"

typescript@3.8.3:
version "3.8.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061"
integrity sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==
typescript@3.9.7:
version "3.9.7"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.7.tgz#98d600a5ebdc38f40cb277522f12dc800e9e25fa"
integrity sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==

typescript@^3.7.3:
version "3.7.5"
Expand Down
4 changes: 2 additions & 2 deletions store/interfaces.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"pixel.APPNAME": {
"pixel.istore-pixel": {
"component": "index"
}
}
}
2 changes: 1 addition & 1 deletion store/plugins.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"pixels > pixel": "pixel.APPNAME"
"pixels > pixel": "pixel.istore-pixel"
}

0 comments on commit a2f6c42

Please sign in to comment.