Skip to content

Commit

Permalink
refactor: Remove redundant client side attr token propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
solofeed committed Sep 19, 2024
1 parent 35baa3c commit 5424580
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 18 deletions.
1 change: 0 additions & 1 deletion assets/js/theme/product/recommendations/constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export const NUM_OF_PRODUCTS = 6;
export const EVENT_TYPE = 'detail-page-view';
export const SERVICE_CONFIG_ID = 'others-you-may-like-ctr-serving-config';
export const RECOM_TOKEN_PARAM = 'attributionToken';
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable indent */
import { addQueryParams } from './utils';
import { RECOM_TOKEN_PARAM, NUM_OF_PRODUCTS } from './constants';
import { NUM_OF_PRODUCTS } from './constants';

function renderPrice(node, themeSettings) {
const { price, retailPrice } = node.prices || { price: {} };
Expand All @@ -25,10 +24,10 @@ function renderRestrictToLogin() {
}

function renderCard(node, options) {
const { themeSettings, attributionToken } = options;
const { themeSettings } = options;
const categories = node.categories.edges.map(({ node: cNode }) => cNode.name).join(',');
const productUrl = addQueryParams(node.path, { [RECOM_TOKEN_PARAM]: attributionToken });
const addToCartUrl = addQueryParams(node.addToCartUrl, { [RECOM_TOKEN_PARAM]: attributionToken });
const productUrl = node.path;
const addToCartUrl = node.addToCartUrl;

return `<div class="productCarousel-slide">
<article
Expand Down
3 changes: 1 addition & 2 deletions assets/js/theme/product/recommendations/recommendations.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,12 @@ export default function applyRecommendations(el, options) {
NUM_OF_PRODUCTS,
)
.then((response) => {
const { attributionToken, results: products } = response.data.site.apiExtensions.googleRetailApiPrediction;
const { results: products } = response.data.site.apiExtensions.googleRetailApiPrediction;

injectRecommendations(products, el, {
products,
themeSettings,
productId,
attributionToken,
});
})
.catch(err => {
Expand Down
10 changes: 0 additions & 10 deletions assets/js/theme/product/recommendations/utils.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
export function addQueryParams(url, params = {}) {
const keys = Object.keys(params);
if (!keys.length) return url;
const newParams = keys
.reduce((acc, key) =>
acc.concat([`${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`]), [])
.join('&');
return (url || '').indexOf('?') === -1 ? `${url}?${newParams}` : `${url}&${newParams}`;
}

export function getSizeFromThemeSettings(setting) {
const size = (setting || '').split('x');
return {
Expand Down

0 comments on commit 5424580

Please sign in to comment.