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

Commit 093d393

Browse files
authored
Merge pull request #420 from DivanteLtd/hotfix/v1.11.1
Hotfix/v1.11.1
2 parents 875ed27 + 24f95a8 commit 093d393

File tree

11 files changed

+82
-56
lines changed

11 files changed

+82
-56
lines changed

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [1.11.1] - 2020.03.17
8+
9+
### Added
10+
- Add save address on place order - @lucasqm (#394)
11+
- Add ElasticSearch client support for HTTP authentication - @cewald (#397)
12+
- Add error handling for catalog and add header 'X-VS-Cache-Tags' to response - @gibkigonzo
13+
14+
### Fixed
15+
- Add fallback for `sourcePriceInclTax` and `finalPriceInclTax` in `magento1` platform - @cewald (#398)
16+
- Add default ES index to config and update `getStockList` - @gibkigonzo (#405)
17+
- Makes elastic-stock extension compatible with both ES5 and ES7. Allows for stock fetch of configurable children that is set as "Not Visible Individually" - @didkan (#410)
18+
19+
720
## [1.11.0] - 2019.12.20
821

922
### Fixed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Then, please do change the `config/local.json` to start using the new Elastic AP
8585
```json
8686
"elasticsearch": {
8787
"host": "localhost",
88+
"index": "vue_storefront_catalog",
8889
"port": 9200,
8990
"protocol": "http",
9091
"min_score": 0.01,

config/default.json

+2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
},
2020
"elasticsearch": {
2121
"host": "localhost",
22+
"index": "vue_storefront_catalog",
2223
"port": 9200,
2324
"protocol": "http",
25+
"requestTimeout": 5000,
2426
"min_score": 0.01,
2527
"indices": [
2628
"vue_storefront_catalog",

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-storefront-api",
3-
"version": "1.11.0",
3+
"version": "1.11.1",
44
"private": true,
55
"description": "vue-storefront API and data services",
66
"main": "dist",

src/api/catalog.js

+35-36
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import ProcessorFactory from '../processor/factory';
44
import { adjustBackendProxyUrl } from '../lib/elastic'
55
import cache from '../lib/cache-instance'
66
import { sha3_224 } from 'js-sha3'
7+
import { apiError } from '../lib/util';
78

89
function _cacheStorageHandler (config, result, hash, tags) {
910
if (config.server.useOutputCache && cache) {
@@ -86,43 +87,41 @@ export default ({config, db}) => function (req, res, body) {
8687
body: requestBody,
8788
json: true,
8889
auth: auth
89-
}, (_err, _res, _resBody) => { // TODO: add caching layer to speed up SSR? How to invalidate products (checksum on the response BEFORE processing it)
90-
if (_resBody && _resBody.hits && _resBody.hits.hits) { // we're signing up all objects returned to the client to be able to validate them when (for example order)
91-
const factory = new ProcessorFactory(config)
92-
const tagsArray = []
93-
if (config.server.useOutputCache && cache) {
94-
const tagPrefix = entityType[0].toUpperCase() // first letter of entity name: P, T, A ...
95-
tagsArray.push(entityType)
96-
_resBody.hits.hits.map(item => {
97-
if (item._source.id) { // has common identifier
98-
tagsArray.push(`${tagPrefix}${item._source.id}`)
99-
}
100-
})
101-
}
102-
103-
let resultProcessor = factory.getAdapter(entityType, indexName, req, res)
104-
105-
if (!resultProcessor) { resultProcessor = factory.getAdapter('default', indexName, req, res) } // get the default processor
106-
107-
if (entityType === 'product') {
108-
resultProcessor.process(_resBody.hits.hits, groupId).then((result) => {
109-
_resBody.hits.hits = result
110-
_cacheStorageHandler(config, _resBody, reqHash, tagsArray)
111-
res.json(_resBody);
112-
}).catch((err) => {
113-
console.error(err)
114-
})
115-
} else {
116-
resultProcessor.process(_resBody.hits.hits).then((result) => {
117-
_resBody.hits.hits = result
118-
_cacheStorageHandler(config, _resBody, reqHash, tagsArray)
119-
res.json(_resBody);
120-
}).catch((err) => {
121-
console.error(err)
122-
})
90+
}, async (_err, _res, _resBody) => { // TODO: add caching layer to speed up SSR? How to invalidate products (checksum on the response BEFORE processing it)
91+
if (_err || _resBody.error) {
92+
apiError(res, _err || _resBody.error);
93+
return
94+
}
95+
try {
96+
if (_resBody && _resBody.hits && _resBody.hits.hits) { // we're signing up all objects returned to the client to be able to validate them when (for example order)
97+
const factory = new ProcessorFactory(config)
98+
const tagsArray = []
99+
if (config.server.useOutputCache && cache) {
100+
const tagPrefix = entityType[0].toUpperCase() // first letter of entity name: P, T, A ...
101+
tagsArray.push(entityType)
102+
_resBody.hits.hits.map(item => {
103+
if (item._source.id) { // has common identifier
104+
tagsArray.push(`${tagPrefix}${item._source.id}`)
105+
}
106+
})
107+
const cacheTags = tagsArray.join(' ')
108+
res.setHeader('X-VS-Cache-Tags', cacheTags)
109+
}
110+
111+
let resultProcessor = factory.getAdapter(entityType, indexName, req, res)
112+
113+
if (!resultProcessor) { resultProcessor = factory.getAdapter('default', indexName, req, res) } // get the default processor
114+
115+
const productGroupId = entityType === 'product' ? groupId : undefined
116+
const result = await resultProcessor.process(_resBody.hits.hits, productGroupId)
117+
_resBody.hits.hits = result
118+
_cacheStorageHandler(config, _resBody, reqHash, tagsArray)
119+
res.json(_resBody);
120+
} else { // no cache storage if no results from Elastic
121+
res.json(_resBody);
123122
}
124-
} else { // no cache storage if no results from Elastic
125-
res.json(_resBody);
123+
} catch (err) {
124+
apiError(res, err);
126125
}
127126
});
128127
}

src/api/extensions/elastic-stock/index.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { apiStatus, getCurrentStoreView, getCurrentStoreCode } from '../../../lib/util';
2-
import { getClient as getElasticClient, adjustQuery } from '../../../lib/elastic'
2+
import { getClient as getElasticClient, adjustQuery, getHits } from '../../../lib/elastic'
33
import { Router } from 'express';
44
const bodybuilder = require('bodybuilder')
55

@@ -12,14 +12,13 @@ module.exports = ({
1212
const getStockList = (storeCode, skus) => {
1313
let storeView = getCurrentStoreView(storeCode)
1414
const esQuery = adjustQuery({
15-
index: storeView.elasticsearch.indexName, // current index name
15+
index: storeView.elasticsearch.index, // current index name
1616
type: 'product',
1717
_source_includes: ['stock'],
18-
body: bodybuilder().filter('terms', 'visibility', [2, 3, 4]).andFilter('term', 'status', 1).andFilter('terms', 'sku', skus).build()
18+
body: bodybuilder().filter('term', 'status', 1).andFilter('terms', 'sku', skus).build()
1919
}, 'product', config)
2020
return getElasticClient(config).search(esQuery).then((products) => { // we're always trying to populate cache - when online
21-
console.log(products)
22-
return products.hits.hits.map(el => { return el._source.stock })
21+
return getHits(products).map(el => { return el._source.stock })
2322
}).catch(err => {
2423
console.error(err)
2524
})

src/lib/elastic.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,16 @@ function getHits (result) {
6868
}
6969

7070
function getClient (config) {
71-
const esConfig = { // as we're runing tax calculation and other data, we need a ES indexer
72-
node: `${config.elasticsearch.protocol}://${config.elasticsearch.host}:${config.elasticsearch.port}`,
73-
apiVersion: config.elasticsearch.apiVersion,
74-
requestTimeout: 5000
75-
}
71+
let { host, port, protocol, apiVersion, requestTimeout } = config.elasticsearch
72+
const node = `${protocol}://${host}:${port}`
73+
74+
let auth
7675
if (config.elasticsearch.user) {
77-
esConfig.auth = config.elasticsearch.user + ':' + config.elasticsearch.password
76+
const { user, password } = config.elasticsearch
77+
auth = { username: user, password }
7878
}
79-
return new es.Client(esConfig)
79+
80+
return new es.Client({ node, auth, apiVersion, requestTimeout })
8081
}
8182

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

src/lib/util.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,10 @@ export function apiStatus (res, result = 'OK', code = 200, meta = null) {
8383
* @param {number} [code=200] Status code to send on success
8484
* @param {json} [result='OK'] Text message or result information object
8585
*/
86-
export function apiError (res, errorObj, code = 500) {
87-
return apiStatus(res, errorObj.errorMessage ? errorObj.errorMessage : errorObj, errorObj.code ? errorObj.code : 500)
86+
export function apiError (res, errorObj) {
87+
const errorCode = errorObj.code || errorObj.status || 500
88+
const errorMessage = errorObj.errorMessage || errorObj
89+
return apiStatus(res, errorMessage, errorCode)
8890
}
8991

9092
export function encryptToken (textToken, secret) {

src/models/order.schema.js

+6
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/magento1/tax.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class TaxProxy extends AbstractTaxProxy {
2323
if (store.elasticsearch.index === indexName) {
2424
taxRegion = store.tax.defaultRegion
2525
taxCountry = store.tax.defaultCountry
26-
sourcePriceInclTax = store.tax.sourcePriceIncludesTax
27-
finalPriceInclTax = store.tax.finalPriceIncludesTax
26+
sourcePriceInclTax = store.tax.sourcePriceIncludesTax || null
27+
finalPriceInclTax = store.tax.finalPriceIncludesTax || null
2828
this._storeConfigTax = store.tax
2929
break;
3030
}

src/platform/magento2/o2m.js

+6-3
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)