Skip to content

Commit

Permalink
Merge branch 'dev' into 'main'
Browse files Browse the repository at this point in the history
DCONN-78: Support additional API parameters in Recommendations widgets

See merge request engineering/sm/magento-discovery-connector!22
  • Loading branch information
lachire committed Oct 22, 2024
2 parents 512cfbf + f8966ef commit 1f99e39
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 28 deletions.
14 changes: 9 additions & 5 deletions Block/Widget/Recommendation.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,19 @@ public function getWidgetJsonConfig()
} else {
$itemSkus = null;
}

$additionalParams = htmlentities($this->getData('additional_parameters') ?? '');
$this->logger->debug("additional_parameters: ".$additionalParams);
$response = [
'title'=>$this->getData('title'),
'title' => $this->getData('title'),
'widget_id' => $this->getData('rec_widget_id'),
'widget_type' => $this->getData('rec_widget_type'),
'category_id' => $this->getData('category_id'),
'query'=> $this->getData('keyword_query'),
'item_ids'=> $itemSkus,
'products_visible'=> $this->getData('products_visible'),
'products_to_fetch'=> $this->getData('products_to_fetch')
'query' => $this->getData('keyword_query'),
'item_ids' => $itemSkus,
'products_visible' => $this->getData('products_visible'),
'products_to_fetch' => $this->getData('products_to_fetch'),
'additional_parameters' => $additionalParams,
];
return $this->jsonSerializer->serialize($response);
}
Expand Down
6 changes: 6 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.8.2

## Changed

- [`CHANGED`]: Support additional API parameters in Recommendations widgets.

## 1.8.1

## Fixed
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bloomreach/bloomreach-connector-magento",
"description": "Bloomreach connector for autosuggest,collection and product search",
"version": "1.8.1",
"version": "1.8.2",
"type": "magento2-module",
"license": "proprietary",
"authors": [
Expand Down
4 changes: 4 additions & 0 deletions etc/widget.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@
</option>
</options>
</parameter>
<parameter name="additional_parameters" xsi:type="text" required="false" visible="true">
<label translate="true">Additional Parameters</label>
<description>Additional API parameters. For example, "name1=value1&amp;name2=value2"</description>
</parameter>
</parameters>
</widget>
</widgets>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "magento-connector",
"version": "1.8.1",
"version": "1.8.2",
"description": "NPM tools to aid in developing this connector application",
"main": "index.js",
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions view/frontend/web/js/autosuggest.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions view/frontend/web/js/category.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions view/frontend/web/js/events.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions view/frontend/web/js/recommendations.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions view/frontend/web/js/search.js

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions view/frontend/web/js/view/recommendation.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@ define(["uiComponent", "Magento_Customer/js/customer-data","pathwaysRecomSdk"],
getWidgetConfig: function () {
return this.widgetConfig;
},
getWidgetDataAttrs: function () {
const attrs = {
'data-id': this.widgetConfig.widget_id,
'data-type': this.widgetConfig.widget_type,
'data-title': this.getWidgetTitle(),
'data-category-id': this.widgetConfig.category_id,
'data-query': this.widgetConfig.query,
'data-item-ids': this.widgetConfig.item_ids,
'data-user-id': this.getCustomer().uniqueId,
'data-number-of-items-to-show': this.widgetConfig.products_visible,
'data-number-of-items-to-fetch': this.widgetConfig.products_to_fetch,
};
if (this.widgetConfig.additional_parameters) {
//decode html entities except double quotes
attrs['data-additional-params'] = this.widgetConfig.additional_parameters
.replaceAll('&amp;', '&')
.replaceAll('&#039;', "'")
.replaceAll('&lt;', '<')
.replaceAll('&gt;', '>');
}
return attrs;
},
getCustomer: function () {
return this.customer();
},
Expand Down
12 changes: 1 addition & 11 deletions view/frontend/web/template/widget/recommendation.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,7 @@
<div class="widget-blm-recomm-path-wrapper">
<h2 data-bind="text: getWidgetTitle()"></h2>
<div class="blm-recommendations-widget"
data-bind="attr: {
'data-id': getWidgetConfig().widget_id,
'data-type': getWidgetConfig().widget_type,
'data-title': getWidgetTitle(),
'data-category-id': getWidgetConfig().category_id,
'data-query': getWidgetConfig().query,
'data-item-ids': getWidgetConfig().item_ids,
'data-user-id': getCustomer().uniqueId,
'data-number-of-items-to-show': getWidgetConfig().products_visible,
'data-number-of-items-to-fetch': getWidgetConfig().products_to_fetch
}">
data-bind="attr: getWidgetDataAttrs()">
<div afterRender="afterRender">...</div>
</div>
</div>

0 comments on commit 1f99e39

Please sign in to comment.