Skip to content

Commit 61226c8

Browse files
authored
Merge pull request #1363 from algolia/update/MAGE-649
Updated position in Recommend listing
2 parents 81d62d6 + e750500 commit 61226c8

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ define([], function () {
88
}
99
this.defaultIndexName = algoliaConfig.indexName + '_products';
1010
return html`<div class="product-details">
11-
<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}>
1212
<img class="product-img" src="${item.image_url}" alt="${item.name}"/>
1313
<p class="product-name">${item.name}</p>
1414
${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)