-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29e0b05
commit a2f6c42
Showing
7 changed files
with
79 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "YOURAPPNAME", | ||
"name": "istore-pixel", | ||
"private": true, | ||
"license": "UNLICENSED", | ||
"scripts": { | ||
|
This file contains 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
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> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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/[email protected]/public/_types/react", | ||
"vtex.render-runtime": "http://vtex.vtexassets.com/_v/public/typings/v1/[email protected]/public/@types/vtex.render-runtime" | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"pixel.APPNAME": { | ||
"pixel.istore-pixel": { | ||
"component": "index" | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"pixels > pixel": "pixel.APPNAME" | ||
"pixels > pixel": "pixel.istore-pixel" | ||
} |