Skip to content

Commit

Permalink
added logic to send "variant" in eec objects when applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
EfficiencyJunky committed Dec 10, 2020
1 parent dbca449 commit 4068d13
Show file tree
Hide file tree
Showing 12 changed files with 700 additions and 225 deletions.
1 change: 1 addition & 0 deletions guide/02_detail/02_gtm_eecDetailObj.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function(){
// may want to add 'productPrice' but this is TBD
'variants': [{
'sku': 'not_added',
'options': 'not_added',
'price': price,
'unlimited': unlimited,
'qtyInStock': qtyInStock, // can be 0 if unlimited is true
Expand Down
9 changes: 9 additions & 0 deletions guide/03_add/02_gtm_eecAddObj.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ function(){
variantAdded.salePrice
) / 100;

var variantOptions = "not_added";
for(var j=0; j < variantAdded.optionValues.length; j++){

variantOptions = (j == 0) ? "" : variantOptions + "|";

variantOptions = variantOptions + variantAdded.optionValues[j].value;
}

var productJSON = {
'productId': newlyAdded.itemId,
'productName': newlyAdded.title,
Expand All @@ -45,6 +53,7 @@ function(){
'variants':
[{
'sku': variantAdded.sku,
'options': variantOptions,
'price': variantPrice.toFixed(2),
'unlimited': variantAdded.unlimited,
'qtyInStock': variantAdded.qtyInStock, // can be 0 if unlimited is true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function(){
'variants':
[{
'sku': rawItem.sku,
'options': variantCookieData.opt,
'price': rawItem.unitPrice.decimalValue,
'unlimited': variantCookieData.unl,
'qtyInStock': variantCookieData.qty,
Expand Down
4 changes: 2 additions & 2 deletions guide/utilities/createEecObjectFromAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ function(){
'id': productJSON[j].productId,
'name': productJSON[j].productName,
'category': productJSON[j].productCategory,
//variant: 'xyz', // need to implement this although the SKU in dimension5 does sort of provide this information already
'brand': {{const - eec brand}}
}

Expand All @@ -49,7 +48,8 @@ function(){
case "remove":
eecProduct['metric1'] = Number(variant.price) * quantity;
case "checkout":
case "purchase":
case "purchase":
eecProduct['variant'] = variant.options;
eecProduct['quantity'] = Math.abs(quantity[j]);
eecProduct['dimension5'] = variant.sku;
case "detail":
Expand Down
1 change: 1 addition & 0 deletions guide/utilities/updateVariantsAddedToCartCookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function(){
var variantDetails = {
'pid': productJSON.productId,
'cat': productJSON.productCategory,
'opt': variantAdded.options,
'unl': variantAdded.unlimited,
'qty': variantAdded.qtyInStock,
'sal': variantAdded.onSale
Expand Down
128 changes: 128 additions & 0 deletions reference/ss_objects/02_product.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// we can find the Static.SQUARESPACE_CONTEXT object by scraping the DOM before the DOM.Ready event
// we can also access this variable AFTER DOM.Ready simply by accessing Static.SQUARESPACE_CONTEXT

var Static = {};

Static["SQUARESPACE_CONTEXT"] = {
"item": {
"title": "regular price unlimited stock product",
"id": "5fcd65ae3ff1011540045eda",
"fullUrl": "/store/regular-price-unlimited-stock-product",
"publicCommentCount": 0,
"commentState": 1,
"recordType": 11
},
"itemId": "5fcd65ae3ff1011540045eda",
"product": {
"variantAttributeNames": [
"size",
"color"
],
"variants": [
{
"id": "53661187-50e4-4aed-af51-40d5c7083afd",
"sku": "SQ8858424",
"price": {
"currencyCode": "USD",
"value": 500,
"decimalValue": "5.00",
"fractionalDigits": 2
},
"salePrice": {
"currencyCode": "USD",
"value": 0,
"decimalValue": "0.00",
"fractionalDigits": 2
},
"onSale": false,
"stock": {
"unlimited": true
},
"attributes": {
"color": "black",
"size": "small"
},
"shippingWeight": {"value": 0,"unit": "POUND"
},
"shippingSize": {"unit": "INCH", "width": 0, "height": 0, "len": 0},
},
{
"id": "2d1324ba-ce05-4def-b88d-fb6dcc5eae66",
"sku": "SQ6393698",
"price": {
"currencyCode": "USD",
"value": 500,
"decimalValue": "5.00",
"fractionalDigits": 2
},
"salePrice": {
"currencyCode": "USD",
"value": 0,
"decimalValue": "0.00",
"fractionalDigits": 2
},
"onSale": false,
"stock": {
"unlimited": true
},
"attributes": {
"color": "white",
"size": "large"
},
"shippingWeight": {"value": 0, "unit": "POUND"},
"shippingSize": {"unit": "INCH", "width": 0, "height": 0, "len": 0},
}
],
"subscribable": false,
"productType": 1
}
};



// this is a version with only one variant and physical dimensions NOT set
Static["SQUARESPACE_CONTEXT"] = {
"item": {
"commentState": 1,
"fullUrl": "/store/moonfall-sticker",
"id": "5eba1a2b98f2a93833214793",
"publicCommentCount": 0,
"recordType": 11,
"title": "MOONFALL sticker"
},
"itemId": "5eba1a2b98f2a93833214793",
"product": {
"productType": 1,
"subscribable": false,
"variantAttributeNames": [
"category"
],
"variants": [
{
"attributes": {
"category": "stickers/individual"
},
"id": "b3b44c1f-ca26-4787-879e-e7da1a3e326e",
"onSale": false,
"price":{
"currencyCode": "USD",
"decimalValue": "6.00",
"fractionalDigits": 2,
"value": 600
},
"salePrice":{
"currencyCode": "USD",
"decimalValue": "0.00",
"fractionalDigits": 2,
"value": 0
},
"shippingSize": {"unit": "INCH", "width": 0, "height": 0, "len": 0},
"shippingWeight": {"value": 0, "unit": "POUND"},
"sku": "SQ7959275",
"stock":{
"unlimited": true
}
}
]
}
};
Loading

2 comments on commit 4068d13

@EfficiencyJunky
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolves issue #4

@EfficiencyJunky
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also resolves issue #1

Please sign in to comment.