Skip to content
This repository was archived by the owner on May 28, 2023. It is now read-only.

Commit d2109d5

Browse files
author
cewald
committed
Merge remote-tracking branch 'upstream/develop' into bugfix/build-path-with-src
2 parents c98ec18 + 530f420 commit d2109d5

File tree

6 files changed

+52
-19
lines changed

6 files changed

+52
-19
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- Add url module - @gibkigonzo (#3942)
1212
- The `response_format` query parameter to the `/api/catalog` endpoint. Currently there is just one additional format supported: `response_format=compact`. When used, the response format got optimized by: a) remapping the results, removing the `_source` from the `hits.hits`; b) compressing the JSON fields names according to the `config.products.fieldsToCompact`; c) removing the JSON fields from the `product.configurable_children` when their values === parent product values; overall response size reduced over -70% - @pkarw
1313
- The support for `SearchQuery` instead of the ElasticSearch DSL as for the input to `/api/catalog` - using `storefront-query-builder` package - @pkarw - https://github.com/DivanteLtd/vue-storefront/issues/2167
14+
- Add ElasticSearch client support for HTTP authentication - @cewald (#397)
1415

1516
### Fixed
1617
- add es7 support for map url module and fixed default index for es config - @gibkigonzo
@@ -22,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2223

2324
- Fixed some smaller issues with graphql so that it is now working again with the fronted - #350
2425
- Replaced the old `crop` function call which has been removed from Sharp image processor - @grimasod (#381)
26+
- Add product processor to new URL mapper endpoint #401 - @cewald (#401, #403)
2527
- Add fallback for `sourcePriceInclTax` and `finalPriceInclTax` in `magento1` platform - @cewald (#398)
2628

2729

config/default.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"index": "vue_storefront_catalog",
2323
"port": 9200,
2424
"protocol": "http",
25+
"requestTimeout": 5000,
2526
"min_score": 0.01,
2627
"indices": [
2728
"vue_storefront_catalog",

src/api/url/map.ts

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { Router } from 'express';
2-
import { apiStatus, getCurrentStoreView, getCurrentStoreCode } from '../../lib/util';
1+
import { Router } from 'express'
2+
import { apiStatus, getCurrentStoreView, getCurrentStoreCode } from '../../lib/util'
33
import { getClient as getElasticClient } from '../../lib/elastic'
4-
import get from 'lodash/get';
4+
import ProcessorFactory from '../../processor/factory'
5+
import get from 'lodash/get'
56

67
const adjustQueryForOldES = ({ config }) => {
78
const searchedEntities = get(config, 'urlModule.map.searchedEntities', [])
@@ -73,7 +74,7 @@ const map = ({ config }) => {
7374
router.post('/', async (req, res) => {
7475
const { url, excludeFields, includeFields } = req.body
7576
if (!url) {
76-
return apiStatus(res, 'Missing url', 500);
77+
return apiStatus(res, 'Missing url', 500)
7778
}
7879

7980
const indexName = getCurrentStoreView(getCurrentStoreCode(req)).elasticsearch.index
@@ -86,16 +87,35 @@ const map = ({ config }) => {
8687

8788
try {
8889
const esResponse = await getElasticClient(config).search(esQuery)
89-
const result = get(esResponse, 'body.hits.hits[0]', null)
90+
let result = get(esResponse, 'body.hits.hits[0]', null)
9091

9192
if (result && checkFieldValueEquality({ config, result, value: req.body.url })) {
92-
return res.json(adjustResultType({ result, config, indexName }))
93-
}
93+
result = adjustResultType({ result, config, indexName })
94+
if (result._type === 'product') {
95+
const factory = new ProcessorFactory(config)
96+
let resultProcessor = factory.getAdapter('product', indexName, req, res)
97+
if (!resultProcessor) {
98+
resultProcessor = factory.getAdapter('default', indexName, req, res)
99+
}
94100

95-
res.json(null)
101+
resultProcessor
102+
.process(esResponse.body.hits.hits, null)
103+
.then(pResult => {
104+
pResult = pResult.map(h => Object.assign(h, { _score: h._score }))
105+
return res.json(pResult[0])
106+
}).catch((err) => {
107+
console.error(err)
108+
return res.json()
109+
})
110+
} else {
111+
return res.json(result)
112+
}
113+
} else {
114+
return res.json(null)
115+
}
96116
} catch (err) {
97117
console.error(err)
98-
return apiStatus(res, new Error('ES search error'), 500);
118+
return apiStatus(res, new Error('ES search error'), 500)
99119
}
100120
})
101121

src/lib/elastic.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,16 @@ function getHits (result) {
7474
}
7575

7676
function getClient (config) {
77-
const esConfig = { // as we're runing tax calculation and other data, we need a ES indexer
78-
node: `${config.elasticsearch.protocol}://${config.elasticsearch.host}:${config.elasticsearch.port}`,
79-
apiVersion: config.elasticsearch.apiVersion,
80-
requestTimeout: 5000
81-
}
77+
let { host, port, protocol, apiVersion, requestTimeout } = config.elasticsearch
78+
const node = `${protocol}://${host}:${port}`
79+
80+
let auth
8281
if (config.elasticsearch.user) {
83-
esConfig.auth = config.elasticsearch.user + ':' + config.elasticsearch.password
82+
const { user, password } = config.elasticsearch
83+
auth = { username: user, password }
8484
}
85-
return new es.Client(esConfig)
85+
86+
return new es.Client({ node, auth, apiVersion, requestTimeout })
8687
}
8788

8889
function putAlias (db, originalName, aliasName, next) {

src/models/order.schema.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ exports.default = {
140140
},
141141
sameAsBilling: {
142142
type: 'number'
143+
},
144+
save_address: {
145+
type: 'number'
143146
}
144147
}
145148
},
@@ -203,6 +206,9 @@ exports.default = {
203206
},
204207
sameAsBilling: {
205208
type: 'number'
209+
},
210+
save_address: {
211+
type: 'number'
206212
}
207213
}
208214
}

src/platform/magento2/o2m.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ function processSingleOrder (orderData, config, job, done, logger = console) {
158158
'regionCode': mappedBillingRegion.regionCode,
159159
'regionId': mappedBillingRegion.regionId,
160160
'company': billingAddr.company,
161-
'vatId': billingAddr.vat_id
161+
'vatId': billingAddr.vat_id,
162+
'save_in_address_book': billingAddr.save_address
162163
}
163164
}
164165

@@ -177,7 +178,8 @@ function processSingleOrder (orderData, config, job, done, logger = console) {
177178
'regionCode': mappedBillingRegion.regionCode,
178179
'region': billingAddr.region,
179180
'company': billingAddr.company,
180-
'vatId': billingAddr.vat_id
181+
'vatId': billingAddr.vat_id,
182+
'save_in_address_book': billingAddr.save_address
181183
},
182184
'shippingMethodCode': orderData.addressInformation.shipping_method_code,
183185
'shippingCarrierCode': orderData.addressInformation.shipping_carrier_code,
@@ -198,7 +200,8 @@ function processSingleOrder (orderData, config, job, done, logger = console) {
198200
'regionId': mappedShippingRegion.regionId,
199201
'regionCode': mappedShippingRegion.regionCode,
200202
'region': shippingAddr.region,
201-
'company': shippingAddr.company
203+
'company': shippingAddr.company,
204+
'save_in_address_book': shippingAddr.save_address
202205
}
203206
} else {
204207
shippingAddressInfo['addressInformation']['shippingAddress'] = shippingAddressInfo['addressInformation']['billingAddress']

0 commit comments

Comments
 (0)