Skip to content

Commit bff7652

Browse files
committed
[sc-9613] fetch related_items API based on blockId
1 parent edcfc67 commit bff7652

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/apifetch.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ var executeApiFetch = function(apiHostname, sitekey, type, settings, cb, fuzzyRe
146146
}
147147

148148
}
149+
api = 'https://' + apiHostname + '/v1/' + apiPath + '/' + sitekey + '?term=' + kw + qs;
149150
}
150151

151152
// Suggest
@@ -154,6 +155,7 @@ var executeApiFetch = function(apiHostname, sitekey, type, settings, cb, fuzzyRe
154155
qs = settingToQueryParam(settings.suggestionsSize, 'size') +
155156
settingToQueryParam(settings.lang, 'lang');
156157
kw = settings.suggestionsPrefix;
158+
api = 'https://' + apiHostname + '/v1/' + apiPath + '/' + sitekey + '?term=' + kw + qs;
157159
}
158160

159161
// Autocomplete
@@ -162,18 +164,19 @@ var executeApiFetch = function(apiHostname, sitekey, type, settings, cb, fuzzyRe
162164
qs = settingToQueryParam(settings.autocomplete.field, 'source') +
163165
settingToQueryParam(settings.autocomplete.size, 'size');
164166
kw = settings.autocomplete.prefix;
167+
api = 'https://' + apiHostname + '/v1/' + apiPath + '/' + sitekey + '?term=' + kw + qs;
165168
}
166169

167170
else if (type === 'recommend') {
168-
apiPath = 'recommendations';
169-
qs = settingToQueryParam(recommendOptions.itemId, 'itemId');
171+
if (recommendOptions.type === 'RELATED_ITEMS') {
172+
apiPath = 'recommendations/index/' + sitekey + '/block/' + recommendOptions.blockId;
173+
} else if (recommendOptions.type === 'FREQUENTLY_BOUGHT_TOGETHER') {
174+
qs = settingToQueryParam(recommendOptions.itemId, 'itemId');
175+
apiPath = 'recommendations/' + sitekey + '?configurationKey=' + recommendOptions.configurationKey + qs;
176+
}
177+
api = 'https://' + apiHostname + '/v1/' + apiPath;
170178
}
171179

172-
// Execute API call
173-
api = type === 'recommend' ?
174-
'https://' + apiHostname + '/v1/' + apiPath + '/' + sitekey + '?configurationKey=' + recommendOptions.configurationKey + qs :
175-
'https://' + apiHostname + '/v1/' + apiPath + '/' + sitekey + '?term=' + kw + qs;
176-
177180
apiInstance.get(api)
178181
.then(function(response) {
179182
var json = response.data;

0 commit comments

Comments
 (0)