@@ -9,7 +9,7 @@ function multiStoreConfig(apiConfig, storeCode) {
9
9
{
10
10
if ( config . magento2 [ 'api_' + storeCode ] ) {
11
11
confCopy = Object . assign ( { } , config . magento2 [ 'api_' + storeCode ] ) // we're to use the specific api configuration - maybe even separate magento instance
12
- }
12
+ }
13
13
confCopy . url = confCopy . url + '/' + storeCode
14
14
} else {
15
15
if ( storeCode ) {
@@ -24,6 +24,12 @@ function getMagentoDefaultConfig(storeCode) {
24
24
return {
25
25
TIME_TO_EXIT : 2000 ,
26
26
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 ,
27
33
PRODUCTS_EXCLUDE_DISABLED : config . catalog . excludeDisabledProducts ,
28
34
MAGENTO_CONSUMER_KEY : apiConfig . consumerKey ,
29
35
MAGENTO_CONSUMER_SECRET : apiConfig . consumerSecret ,
@@ -34,7 +40,7 @@ function getMagentoDefaultConfig(storeCode) {
34
40
REDIS_PORT : config . redis . port ,
35
41
INDEX_NAME : config . elasticsearch . indices [ 0 ] ,
36
42
DATABASE_URL : `${ config . elasticsearch . protocol } ://${ config . elasticsearch . host } :${ config . elasticsearch . port } `
37
- }
43
+ }
38
44
}
39
45
40
46
function exec ( cmd , args , opts ) {
@@ -43,19 +49,19 @@ function exec(cmd, args, opts) {
43
49
child . stdout . on ( 'data' , ( data ) => {
44
50
console . log ( data . toString ( 'utf8' ) ) ;
45
51
} ) ;
46
-
52
+
47
53
child . stderr . on ( 'data' , ( data ) => {
48
54
console . log ( data . toString ( 'utf8' ) ) ;
49
55
} ) ;
50
-
56
+
51
57
child . on ( 'close' , ( code ) => {
52
58
resolve ( code )
53
- } ) ;
59
+ } ) ;
54
60
55
61
child . on ( 'error' , ( error ) => {
56
62
console . error ( error )
57
63
reject ( error )
58
- } ) ;
64
+ } ) ;
59
65
} )
60
66
}
61
67
@@ -107,6 +113,12 @@ program
107
113
program
108
114
. command ( 'import' )
109
115
. 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 )
110
122
. action ( ( cmd ) => {
111
123
let magentoConfig = getMagentoDefaultConfig ( cmd . storeCode )
112
124
@@ -119,82 +131,158 @@ program
119
131
magentoConfig . INDEX_NAME = storeView . elasticsearch . index ;
120
132
}
121
133
}
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
+
123
154
const env = Object . assign ( { } , magentoConfig , process . env ) // use process env as well
124
155
console . log ( '=== The mage2vuestorefront full reindex is about to start. Using the following Magento2 config ===' , magentoConfig )
125
156
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
+ }
132
167
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
+ }
139
181
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' , [
142
189
'--harmony' ,
143
190
'node_modules/mage2vuestorefront/src/cli.js' ,
144
191
'categories' ,
145
192
'--removeNonExistent=true' ,
146
193
'--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
+ } )
190
278
} )
191
- } )
279
+ } )
192
280
} )
193
281
} )
194
282
} )
195
283
} )
196
284
} )
197
- } )
285
+ } ) ;
198
286
199
287
200
288
program
0 commit comments