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

Commit 58a8888

Browse files
authored
Merge pull request #182 from DivanteLtd/develop
Release 1.8
2 parents 5e5249b + a735184 commit 58a8888

File tree

6 files changed

+7146
-7042
lines changed

6 files changed

+7146
-7042
lines changed

scripts/mage2vs.js

Lines changed: 154 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function multiStoreConfig(apiConfig, storeCode) {
99
{
1010
if (config.magento2['api_' + storeCode]) {
1111
confCopy = Object.assign({}, config.magento2['api_' + storeCode]) // we're to use the specific api configuration - maybe even separate magento instance
12-
}
12+
}
1313
confCopy.url = confCopy.url + '/' + storeCode
1414
} else {
1515
if (storeCode) {
@@ -24,6 +24,12 @@ function getMagentoDefaultConfig(storeCode) {
2424
return {
2525
TIME_TO_EXIT: 2000,
2626
PRODUCTS_SPECIAL_PRICES: true,
27+
SKIP_REVIEWS: false,
28+
SKIP_CATEGORIES: false,
29+
SKIP_PRODUCTCATEGORIES: false,
30+
SKIP_ATTRIBUTES: false,
31+
SKIP_TAXRULE: false,
32+
SKIP_PRODUCTS: false,
2733
PRODUCTS_EXCLUDE_DISABLED: config.catalog.excludeDisabledProducts,
2834
MAGENTO_CONSUMER_KEY: apiConfig.consumerKey,
2935
MAGENTO_CONSUMER_SECRET: apiConfig.consumerSecret,
@@ -34,7 +40,7 @@ function getMagentoDefaultConfig(storeCode) {
3440
REDIS_PORT: config.redis.port,
3541
INDEX_NAME: config.elasticsearch.indices[0],
3642
DATABASE_URL: `${config.elasticsearch.protocol}://${config.elasticsearch.host}:${config.elasticsearch.port}`
37-
}
43+
}
3844
}
3945

4046
function exec(cmd, args, opts) {
@@ -43,19 +49,19 @@ function exec(cmd, args, opts) {
4349
child.stdout.on('data', (data) => {
4450
console.log(data.toString('utf8'));
4551
});
46-
52+
4753
child.stderr.on('data', (data) => {
4854
console.log(data.toString('utf8'));
4955
});
50-
56+
5157
child.on('close', (code) => {
5258
resolve(code)
53-
});
59+
});
5460

5561
child.on('error', (error) => {
5662
console.error(error)
5763
reject(error)
58-
});
64+
});
5965
})
6066
}
6167

@@ -107,6 +113,12 @@ program
107113
program
108114
.command('import')
109115
.option('--store-code <storeCode>', 'storeCode in multistore setup', null)
116+
.option('--skip-reviews <skipReviews>', 'skip import of reviews', false)
117+
.option('--skip-categories <skipCategories>', 'skip import of categories', false)
118+
.option('--skip-productcategories <skipProductcategories>', 'skip import of productcategories', false)
119+
.option('--skip-attributes <skipAttributes>', 'skip import of attributes', false)
120+
.option('--skip-taxrule <skipTaxrule>', 'skip import of taxrule', false)
121+
.option('--skip-products <skipProducts>', 'skip import of products', false)
110122
.action((cmd) => {
111123
let magentoConfig = getMagentoDefaultConfig(cmd.storeCode)
112124

@@ -119,82 +131,158 @@ program
119131
magentoConfig.INDEX_NAME = storeView.elasticsearch.index;
120132
}
121133
}
122-
134+
135+
if (cmd.skipReviews) {
136+
magentoConfig.SKIP_REVIEWS = true;
137+
}
138+
if (cmd.skipCategories) {
139+
magentoConfig.SKIP_CATEGORIES = true;
140+
}
141+
if (cmd.skipProductcategories) {
142+
magentoConfig.SKIP_PRODUCTCATEGORIES = true;
143+
}
144+
if (cmd.skipAttributes) {
145+
magentoConfig.SKIP_ATTRIBUTES = true;
146+
}
147+
if (cmd.skipTaxrule) {
148+
magentoConfig.SKIP_TAXRULE = true;
149+
}
150+
if (cmd.skipProducts) {
151+
magentoConfig.SKIP_PRODUCTS = true;
152+
}
153+
123154
const env = Object.assign({}, magentoConfig, process.env) // use process env as well
124155
console.log('=== The mage2vuestorefront full reindex is about to start. Using the following Magento2 config ===', magentoConfig)
125156

126-
console.log(' == CREATING NEW DATABASE ==')
127-
exec('node', [
128-
'scripts/db.js',
129-
'new',
130-
`--indexName=${env.INDEX_NAME}`
131-
], { env: env, shell: true }).then((res) => {
157+
let createDbPromise = function() {
158+
159+
console.log(' == CREATING NEW DATABASE ==')
160+
return exec('node', [
161+
'scripts/db.js',
162+
'new',
163+
`--indexName=${env.INDEX_NAME}`
164+
], { env: env, shell: true })
165+
166+
}
132167

133-
console.log(' == REVIEWS IMPORTER ==')
134-
exec('node', [
135-
'--harmony',
136-
'node_modules/mage2vuestorefront/src/cli.js',
137-
'reviews'
138-
], { env: env, shell: true }).then((res) => {
168+
let importReviewsPromise = function() {
169+
if (magentoConfig.SKIP_REVIEWS ) {
170+
return Promise.resolve();
171+
}
172+
else {
173+
console.log(' == REVIEWS IMPORTER ==');
174+
return exec('node', [
175+
'--harmony',
176+
'node_modules/mage2vuestorefront/src/cli.js',
177+
'reviews'
178+
], {env: env, shell: true})
179+
}
180+
}
139181

140-
console.log(' == CATEGORIES IMPORTER ==')
141-
exec('node', [
182+
let importCategoriesPromise = function() {
183+
if (magentoConfig.SKIP_CATEGORIES ) {
184+
return Promise.resolve();
185+
}
186+
else {
187+
console.log(' == CATEGORIES IMPORTER ==');
188+
return exec('node', [
142189
'--harmony',
143190
'node_modules/mage2vuestorefront/src/cli.js',
144191
'categories',
145192
'--removeNonExistent=true',
146193
'--extendedCategories=true'
147-
], { env: env, shell: true }).then((res) => {
148-
149-
console.log(' == PRODUCT-CATEGORIES IMPORTER ==')
150-
exec('node', [
151-
'--harmony',
152-
'node_modules/mage2vuestorefront/src/cli.js',
153-
'productcategories'
154-
], { env: env, shell: true }).then((res) => {
155-
156-
console.log(' == ATTRIBUTES IMPORTER ==')
157-
exec('node', [
158-
'--harmony',
159-
'node_modules/mage2vuestorefront/src/cli.js',
160-
'attributes',
161-
'--removeNonExistent=true'
162-
], { env: env, shell: true }).then((res) => {
163-
164-
console.log(' == TAXRULE IMPORTER ==')
165-
exec('node', [
166-
'--harmony',
167-
'node_modules/mage2vuestorefront/src/cli.js',
168-
'taxrule',
169-
'--removeNonExistent=true'
170-
], { env: env, shell: true }).then((res) => {
171-
172-
console.log(' == PRODUCTS IMPORTER ==')
173-
exec('node', [
174-
'--harmony',
175-
'node_modules/mage2vuestorefront/src/cli.js',
176-
'products',
177-
'--removeNonExistent=true',
178-
'--partitions=1'
179-
], { env: env, shell: true }).then((res) => {
180-
181-
console.log(' == REINDEXING DATABASE ==')
182-
exec('node', [
183-
'scripts/db.js',
184-
'rebuild',
185-
`--indexName=${env.INDEX_NAME}`
186-
], { env: env, shell: true }).then((res) => {
187-
console.log('Done! Bye Bye!')
188-
process.exit(0)
189-
});
194+
], { env: env, shell: true })
195+
}
196+
}
197+
198+
let importProductcategoriesPromise = function() {
199+
if (magentoConfig.SKIP_PRODUCTCATEGORIES ) {
200+
return Promise.resolve();
201+
}
202+
else {
203+
console.log(' == PRODUCT-CATEGORIES IMPORTER ==');
204+
return exec('node', [
205+
'--harmony',
206+
'node_modules/mage2vuestorefront/src/cli.js',
207+
'productcategories'
208+
], { env: env, shell: true })
209+
}
210+
}
211+
212+
let importAttributesPromise = function() {
213+
if (magentoConfig.SKIP_ATTRIBUTES ) {
214+
return Promise.resolve();
215+
}
216+
else {
217+
console.log(' == ATTRIBUTES IMPORTER ==');
218+
return exec('node', [
219+
'--harmony',
220+
'node_modules/mage2vuestorefront/src/cli.js',
221+
'attributes',
222+
'--removeNonExistent=true'
223+
], { env: env, shell: true })
224+
}
225+
}
226+
227+
let importTaxrulePromise = function() {
228+
if (magentoConfig.SKIP_TAXRULE ) {
229+
return Promise.resolve();
230+
}
231+
else {
232+
console.log(' == TAXRULE IMPORTER ==');
233+
return exec('node', [
234+
'--harmony',
235+
'node_modules/mage2vuestorefront/src/cli.js',
236+
'taxrule',
237+
'--removeNonExistent=true'
238+
], { env: env, shell: true })
239+
}
240+
}
241+
242+
let importProductsPromise = function() {
243+
if (magentoConfig.SKIP_PRODUCTS ) {
244+
return Promise.resolve();
245+
}
246+
else {
247+
console.log(' == PRODUCTS IMPORTER ==');
248+
return exec('node', [
249+
'--harmony',
250+
'node_modules/mage2vuestorefront/src/cli.js',
251+
'products',
252+
'--removeNonExistent=true',
253+
'--partitions=1'
254+
], { env: env, shell: true })
255+
}
256+
}
257+
258+
let reindexPromise = function() {
259+
console.log(' == REINDEXING DATABASE ==')
260+
return exec('node', [
261+
'scripts/db.js',
262+
'rebuild',
263+
`--indexName=${env.INDEX_NAME}`
264+
], {env: env, shell: true})
265+
}
266+
267+
createDbPromise().then( () => {
268+
importReviewsPromise().then( () => {
269+
importCategoriesPromise().then( () => {
270+
importProductcategoriesPromise().then( () => {
271+
importAttributesPromise().then(() => {
272+
importTaxrulePromise().then(() => {
273+
importProductsPromise().then (() => {
274+
reindexPromise().then( () => {
275+
console.log('Done! Bye Bye!')
276+
process.exit(0)
277+
})
190278
})
191-
})
279+
})
192280
})
193281
})
194282
})
195283
})
196284
})
197-
})
285+
});
198286

199287

200288
program

src/lib/image.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ export async function resize (buffer, width, height) {
2626
const transformer = sharp(buffer);
2727

2828
if (width || height) {
29-
transformer.resize(width, height).max().withoutEnlargement();
29+
const options = {
30+
withoutEnlargement: true,
31+
fit: sharp.fit.inside
32+
}
33+
transformer.resize(width, height, options)
3034
}
3135

3236
return transformer.toBuffer();
@@ -61,4 +65,4 @@ export async function crop (buffer, width, height, x, y) {
6165
} catch (err) {
6266
console.log(err);
6367
}
64-
}
68+
}

src/platform/magento2/o2m.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,12 @@ function processSingleOrder(orderData, config, job, done, logger = console) {
132132
let mappedBillingRegion = 0
133133

134134
api.directory.countries().then((countryList) => {
135-
if (shippingAddr.region_id > 0) {
136-
mappedShippingRegion = { regionId: shippingAddr.region_id, regionCode: shippingAddr.region_code }
137-
} else {
138-
mappedShippingRegion = countryMapper.mapCountryRegion(countryList, shippingAddr.country_id, shippingAddr.region_code ? shippingAddr.region_code : shippingAddr.region)
135+
if (typeof shippingAddr !== 'undefined' && shippingAddr !== null) {
136+
if (shippingAddr.region_id > 0) {
137+
mappedShippingRegion = { regionId: shippingAddr.region_id, regionCode: shippingAddr.region_code }
138+
} else {
139+
mappedShippingRegion = countryMapper.mapCountryRegion(countryList, shippingAddr.country_id, shippingAddr.region_code ? shippingAddr.region_code : shippingAddr.region)
140+
}
139141
}
140142

141143
if (billingAddr.region_id > 0) {
@@ -163,20 +165,6 @@ function processSingleOrder(orderData, config, job, done, logger = console) {
163165

164166
const shippingAddressInfo = { // sum up totals
165167
"addressInformation": {
166-
"shippingAddress": {
167-
"countryId": shippingAddr.country_id,
168-
"street": shippingAddr.street,
169-
"telephone": shippingAddr.telephone,
170-
"postcode": shippingAddr.postcode,
171-
"city": shippingAddr.city,
172-
"firstname": shippingAddr.firstname,
173-
"lastname": shippingAddr.lastname,
174-
"email": shippingAddr.email,
175-
"regionId": mappedShippingRegion.regionId,
176-
"regionCode": mappedShippingRegion.regionCode,
177-
"company": shippingAddr.company
178-
},
179-
180168
"billingAddress": {
181169
"countryId": billingAddr.country_id,
182170
"street": billingAddr.street,
@@ -197,6 +185,24 @@ function processSingleOrder(orderData, config, job, done, logger = console) {
197185
}
198186
}
199187

188+
if (typeof shippingAddr !== 'undefined' && shippingAddr !== null) {
189+
shippingAddressInfo["addressInformation"]["shippingAddress"] = {
190+
"countryId": shippingAddr.country_id,
191+
"street": shippingAddr.street,
192+
"telephone": shippingAddr.telephone,
193+
"postcode": shippingAddr.postcode,
194+
"city": shippingAddr.city,
195+
"firstname": shippingAddr.firstname,
196+
"lastname": shippingAddr.lastname,
197+
"email": shippingAddr.email,
198+
"regionId": mappedShippingRegion.regionId,
199+
"regionCode": mappedShippingRegion.regionCode,
200+
"company": shippingAddr.company
201+
}
202+
} else {
203+
shippingAddressInfo["addressInformation"]["shippingAddress"] = shippingAddressInfo["addressInformation"]["billingAddress"]
204+
}
205+
200206
logger.info(THREAD_ID + '< Billing info', billingAddressInfo)
201207
api.cart.billingAddress(null, cartId, billingAddressInfo, isThisAuthOrder).then((result) => {
202208
logger.info(THREAD_ID + '< Billing address assigned', result)

0 commit comments

Comments
 (0)