Skip to content

Commit 808afe2

Browse files
authored
Feature/bloomreach integration mlt (#433)
* Able to get mlt products showing up in products display page * use async await pattern * Adjust the name of mlt function * get rid of prop types * fix typescript errors * Move state and props into new file * Able to place bloomreach product recommendations into storybook * Add product recommendation configs * add a new line * adjust files to use new configurations properly * Change the naming of the component * change the padding of the title * Fix the linking to product recommendations * revert settings to false
1 parent a9c446d commit 808afe2

File tree

12 files changed

+772
-33
lines changed

12 files changed

+772
-33
lines changed

app/src/ep.config.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
"refurl": ""
108108
},
109109
"keywordSearch": {
110-
"enable": true,
110+
"enable": false,
111111
"requestType": "",
112112
"rows": "",
113113
"start": "",
@@ -116,9 +116,17 @@
116116
"searchType": ""
117117
},
118118
"suggestions": {
119-
"enable": true,
119+
"enable": false,
120120
"baseUri": "",
121121
"requestType": ""
122+
},
123+
"moreLikeThis": {
124+
"enable": true,
125+
"requestType": "",
126+
"rows": "",
127+
"start": "",
128+
"facetLimit": "",
129+
"fl": ""
122130
}
123131
},
124132
"GDPR": {

app/src/localization/en-CA.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,5 +325,6 @@
325325
"app-version": "App version",
326326
"components-version": "Components version",
327327
"barcode-scanner": "Barcode scanner",
328-
"scan-barcode": "Scan Barcode"
328+
"scan-barcode": "Scan Barcode",
329+
"more-like-this": "More Like This"
329330
}

app/src/localization/fr-FR.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,5 +326,6 @@
326326
"app-version": "A-p-p- -v-e-r-s-i-o-n",
327327
"components-version": "C-o-m-p-o-n-e-n-t-s- -v-e-r-s-i-o-n",
328328
"barcode-scanner": "B-a-r-c-o-d-e- -s-c-a-n-n-e-r",
329-
"scan-barcode": "S-c-a-n- -B-a-r-c-o-d-e"
329+
"scan-barcode": "S-c-a-n- -B-a-r-c-o-d-e",
330+
"more-like-this": "M-O-R-E- -L-I-K-E- -T-H-I-S"
330331
}

components/src/BloomreachProductListMain/bloomreach.productlist.main.stories.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ storiesOf('BloomreachProductListMain', module)
3030
<MemoryRouter initialEntries={['/']}>{story()}</MemoryRouter>
3131
))
3232
.add('BloomreachProductListMain', () => {
33-
console.log('bloomreach product list main');
3433
const searchResultsModel: BloomreachKeywordSearchLookupResponse = getSearchFromResponse;
3534
const products = searchResultsModel.response ? searchResultsModel.response.docs : [];
3635
return <BloomreachProductListMain productData={products} showCompareButton={false}/>

components/src/BloomreachProductRecommendationsDisplayMain/MockHttpResponses/GET/cortex_itemLookup_response.json

Lines changed: 529 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Copyright © 2019 Elastic Path Software Inc. All rights reserved.
3+
*
4+
* This is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This software is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this license. If not, see
16+
*
17+
* https://www.gnu.org/licenses/
18+
*
19+
*
20+
*/
21+
import React from 'react';
22+
import { storiesOf } from '@storybook/react';
23+
import { MemoryRouter } from 'react-router';
24+
import itemLookupResponse from './MockHttpResponses/GET/cortex_itemLookup_response.json';
25+
26+
import BloomreachProductRecommendationsDisplayMain from './bloomreach.productrecommendations.main';
27+
28+
storiesOf('BloomreachProductRecommendationsDisplayMain', module)
29+
.addDecorator(story => (
30+
<MemoryRouter initialEntries={['/']}>{story()}</MemoryRouter>
31+
))
32+
.add('BloomreachProductRecommendationsDisplayMain', () => {
33+
return (<BloomreachProductRecommendationsDisplayMain cortexProductData={itemLookupResponse}/>);
34+
});
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/**
2+
* Copyright © 2019 Elastic Path Software Inc. All rights reserved.
3+
*
4+
* This is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This software is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this license. If not, see
16+
*
17+
* https://www.gnu.org/licenses/
18+
*
19+
*
20+
*/
21+
22+
import React from 'react';
23+
import { withRouter } from 'react-router';
24+
import intl from 'react-intl-universal';
25+
import ProductListItemMain from '../ProductListItem/productlistitem.main';
26+
import { bloomreachMltSearch } from '../utils/Bloomreach/BloomreachSearchService';
27+
import { BloomreachMltResponse } from '../utils/Bloomreach/types/BloomreachSearchService';
28+
import '../ProductRecommendations/productrecommendations.main.less';
29+
import { BloomreachProductRecommendationsDisplayMainProps, BloomreachProductRecommendationsDisplayMainState } from './types/bloomreach.productrecommendations.main';
30+
31+
class BloomreachProductRecommendationsDisplayMain extends React.Component<BloomreachProductRecommendationsDisplayMainProps, BloomreachProductRecommendationsDisplayMainState> {
32+
constructor(props) {
33+
super(props);
34+
this.state = {
35+
maxItemsInView: 4,
36+
productData: [],
37+
};
38+
}
39+
40+
componentDidMount() {
41+
const { productData } = this.state;
42+
43+
if (productData.length === 0) {
44+
this.fetchBloomreachRecommendedProducts();
45+
}
46+
}
47+
48+
componentWillReceiveProps() {
49+
const { productData } = this.state;
50+
51+
if (productData.length === 0) {
52+
this.fetchBloomreachRecommendedProducts();
53+
}
54+
}
55+
56+
async fetchBloomreachRecommendedProducts() {
57+
const { cortexProductData } = this.props;
58+
const sku = cortexProductData._code[0].code;
59+
60+
const res: BloomreachMltResponse = await bloomreachMltSearch(sku);
61+
62+
this.setState({
63+
productData: res.response ? res.response.docs : [],
64+
});
65+
}
66+
67+
renderProductAssocitationView(productData, maxItemsInView) {
68+
const data = [];
69+
const { itemDetailLink } = this.props;
70+
productData.forEach((element, index) => {
71+
if (index < maxItemsInView && element.pid) {
72+
const cortexSku = element.variants[0].sku_swatch_images[0];
73+
data.push(
74+
<div className="category-item-container card" key={`_${Math.random().toString(36).substr(2, 9)}`}>
75+
<ProductListItemMain productId={cortexSku} itemDetailLink={itemDetailLink} />
76+
</div>,
77+
);
78+
}
79+
});
80+
return data;
81+
}
82+
83+
render() {
84+
const data = [];
85+
const { maxItemsInView, productData } = this.state;
86+
if (productData && productData.length > 0) {
87+
const htmlFor = 'Recommendations';
88+
data.push(
89+
<div className="display" key={htmlFor}>
90+
<label className="control-label" htmlFor={htmlFor}>
91+
{intl.get('more-like-this')}
92+
</label>
93+
<div className="card-deck">
94+
{this.renderProductAssocitationView(productData, maxItemsInView)}
95+
</div>
96+
</div>,
97+
);
98+
}
99+
return (
100+
<div className="product-recomentations-component" data-region="categoryBrowseRegion" key="categoryBrowseRegion">
101+
{data.length > 0 ? <hr /> : ''}
102+
{data}
103+
</div>
104+
);
105+
}
106+
}
107+
108+
export default withRouter(BloomreachProductRecommendationsDisplayMain);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export interface BloomreachProductRecommendationsDisplayMainProps {
2+
cortexProductData: any,
3+
itemDetailLink: any
4+
}
5+
6+
export interface BloomreachProductRecommendationsDisplayMainState {
7+
maxItemsInView: number,
8+
productData: any
9+
}

components/src/ProductDisplayItem/productdisplayitem.main.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { login } from '../utils/AuthService';
2727
import { itemLookup, cortexFetchItemLookupForm } from '../utils/CortexLookup';
2828
import imgMissingHorizontal from '../../../app/src/images/img_missing_horizontal@2x.png';
2929
import ProductRecommendationsDisplayMain from '../ProductRecommendations/productrecommendations.main';
30+
import BloomreachProductRecommendationsDisplayMain from '../BloomreachProductRecommendationsDisplayMain/bloomreach.productrecommendations.main';
3031
import IndiRecommendationsDisplayMain from '../IndiRecommendations/indirecommendations.main';
3132
import BundleConstituentsDisplayMain from '../BundleConstituents/bundleconstituents.main';
3233
import { cortexFetch } from '../utils/Cortex';
@@ -122,6 +123,14 @@ class ProductDisplayItemMain extends React.Component<ProductDisplayItemMainProps
122123
return (localStorage.getItem(`${config.cortexApi.scope}_oAuthRole`) === 'REGISTERED');
123124
}
124125

126+
static RelatedProducts(productData) {
127+
const itemDetailLink = '/itemdetail';
128+
if (Config.bloomreach.moreLikeThis.enable) {
129+
return <BloomreachProductRecommendationsDisplayMain cortexProductData={productData} itemDetailLink={itemDetailLink} />;
130+
}
131+
return <ProductRecommendationsDisplayMain productData={productData} itemDetailLink={itemDetailLink} />;
132+
}
133+
125134
static defaultProps = {
126135
imageUrl: undefined,
127136
dataSet: undefined,
@@ -773,7 +782,7 @@ class ProductDisplayItemMain extends React.Component<ProductDisplayItemMainProps
773782
</div>
774783
</div>
775784
<BundleConstituentsDisplayMain productData={productData} itemDetailLink={itemDetailLink} />
776-
<ProductRecommendationsDisplayMain productData={productData} itemDetailLink={itemDetailLink} />
785+
{ProductDisplayItemMain.RelatedProducts(productData)}
777786
<IndiRecommendationsDisplayMain render={['carousel', 'product']} configuration={Config.indi} keywords={productData._code[0].code} />
778787
</div>
779788
);

components/src/ProductRecommendations/productrecommendations.main.less

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
.control-label {
2828
font-size: 18px;
2929
font-weight: 600;
30-
padding: 20px 0px;
30+
padding-top: 20px;
31+
padding-bottom: 70px
3132
}
3233

3334
.card-deck {

0 commit comments

Comments
 (0)