Skip to content

Commit 046c481

Browse files
committed
Updated position in recommend
1 parent 18a8021 commit 046c481

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

view/frontend/web/internals/template/recommend/products.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
define([], function () {
22
return {
3-
getItemHtml: function (item, html, addTocart) {
3+
getItemHtml: function (item, html, addTocart, index) {
44
let correctFKey = getCookie('form_key');
55
let action = algoliaConfig.recommend.addToCartParams.action + 'product/' + item.objectID + '/';
66
if(correctFKey != "" && algoliaConfig.recommend.addToCartParams.formKey != correctFKey) {
7-
config.recommend.addToCartParams.formKey = correctFKey;
7+
algoliaConfig.recommend.addToCartParams.formKey = correctFKey;
88
}
9-
this.config = algoliaConfig;
109
this.defaultIndexName = algoliaConfig.indexName + '_products';
1110
return html`<div class="product-details">
12-
<a class="recommend-item product-url" href="${item.url}" data-objectid=${item.objectID} data-index=${this.defaultIndexName}>
11+
<a class="recommend-item product-url" href="${item.url}" data-objectid=${item.objectID} data-position=${item.position} data-index=${this.defaultIndexName}>
1312
<img class="product-img" src="${item.image_url}" alt="${item.name}"/>
1413
<p class="product-name">${item.name}</p>
1514
${addTocart && html`

view/frontend/web/recommend.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ define([
1010
if (typeof algoliaConfig === 'undefined') {
1111
return;
1212
}
13-
13+
1414
return function (config, element) {
1515
algoliaBundle.$(function ($) {
1616
this.defaultIndexName = algoliaConfig.indexName + '_products';
@@ -27,6 +27,12 @@ define([
2727
indexName,
2828
objectIDs: config.algoliObjectId,
2929
maxRecommendations: algoliaConfig.recommend.limitFBTProducts,
30+
transformItems:function (items) {
31+
return items.map((item, index) => ({
32+
...item,
33+
position: index + 1,
34+
}));
35+
},
3036
headerComponent({html}) {
3137
return recommendProductsHtml.getHeaderHtml(html,algoliaConfig.recommend.FBTTitle);
3238
},
@@ -42,6 +48,12 @@ define([
4248
indexName,
4349
objectIDs: config.algoliObjectId,
4450
maxRecommendations: algoliaConfig.recommend.limitRelatedProducts,
51+
transformItems:function (items) {
52+
return items.map((item, index) => ({
53+
...item,
54+
position: index + 1,
55+
}));
56+
},
4557
headerComponent({html}) {
4658
return recommendProductsHtml.getHeaderHtml(html,algoliaConfig.recommend.relatedProductsTitle);
4759
},
@@ -60,6 +72,12 @@ define([
6072
recommendClient,
6173
indexName,
6274
maxRecommendations: algoliaConfig.recommend.limitTrendingItems,
75+
transformItems:function (items) {
76+
return items.map((item, index) => ({
77+
...item,
78+
position: index + 1,
79+
}));
80+
},
6381
headerComponent({html}) {
6482
return recommendProductsHtml.getHeaderHtml(html,algoliaConfig.recommend.trendingItemsTitle);
6583
},
@@ -76,6 +94,12 @@ define([
7694
recommendClient,
7795
indexName,
7896
maxRecommendations: config.numOfTrendsItem ? parseInt(config.numOfTrendsItem) : algoliaConfig.recommend.limitTrendingItems,
97+
transformItems:function (items) {
98+
return items.map((item, index) => ({
99+
...item,
100+
position: index + 1,
101+
}));
102+
},
79103
headerComponent({html}) {
80104
return recommendProductsHtml.getHeaderHtml(html,algoliaConfig.recommend.trendingItemsTitle);
81105
},

0 commit comments

Comments
 (0)