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

Commit

Permalink
Merge pull request #182 from DivanteLtd/develop
Browse files Browse the repository at this point in the history
Release 1.8
  • Loading branch information
patzick authored Feb 7, 2019
2 parents 5e5249b + a735184 commit 58a8888
Show file tree
Hide file tree
Showing 6 changed files with 7,146 additions and 7,042 deletions.
220 changes: 154 additions & 66 deletions scripts/mage2vs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function multiStoreConfig(apiConfig, storeCode) {
{
if (config.magento2['api_' + storeCode]) {
confCopy = Object.assign({}, config.magento2['api_' + storeCode]) // we're to use the specific api configuration - maybe even separate magento instance
}
}
confCopy.url = confCopy.url + '/' + storeCode
} else {
if (storeCode) {
Expand All @@ -24,6 +24,12 @@ function getMagentoDefaultConfig(storeCode) {
return {
TIME_TO_EXIT: 2000,
PRODUCTS_SPECIAL_PRICES: true,
SKIP_REVIEWS: false,
SKIP_CATEGORIES: false,
SKIP_PRODUCTCATEGORIES: false,
SKIP_ATTRIBUTES: false,
SKIP_TAXRULE: false,
SKIP_PRODUCTS: false,
PRODUCTS_EXCLUDE_DISABLED: config.catalog.excludeDisabledProducts,
MAGENTO_CONSUMER_KEY: apiConfig.consumerKey,
MAGENTO_CONSUMER_SECRET: apiConfig.consumerSecret,
Expand All @@ -34,7 +40,7 @@ function getMagentoDefaultConfig(storeCode) {
REDIS_PORT: config.redis.port,
INDEX_NAME: config.elasticsearch.indices[0],
DATABASE_URL: `${config.elasticsearch.protocol}://${config.elasticsearch.host}:${config.elasticsearch.port}`
}
}
}

function exec(cmd, args, opts) {
Expand All @@ -43,19 +49,19 @@ function exec(cmd, args, opts) {
child.stdout.on('data', (data) => {
console.log(data.toString('utf8'));
});

child.stderr.on('data', (data) => {
console.log(data.toString('utf8'));
});

child.on('close', (code) => {
resolve(code)
});
});

child.on('error', (error) => {
console.error(error)
reject(error)
});
});
})
}

Expand Down Expand Up @@ -107,6 +113,12 @@ program
program
.command('import')
.option('--store-code <storeCode>', 'storeCode in multistore setup', null)
.option('--skip-reviews <skipReviews>', 'skip import of reviews', false)
.option('--skip-categories <skipCategories>', 'skip import of categories', false)
.option('--skip-productcategories <skipProductcategories>', 'skip import of productcategories', false)
.option('--skip-attributes <skipAttributes>', 'skip import of attributes', false)
.option('--skip-taxrule <skipTaxrule>', 'skip import of taxrule', false)
.option('--skip-products <skipProducts>', 'skip import of products', false)
.action((cmd) => {
let magentoConfig = getMagentoDefaultConfig(cmd.storeCode)

Expand All @@ -119,82 +131,158 @@ program
magentoConfig.INDEX_NAME = storeView.elasticsearch.index;
}
}


if (cmd.skipReviews) {
magentoConfig.SKIP_REVIEWS = true;
}
if (cmd.skipCategories) {
magentoConfig.SKIP_CATEGORIES = true;
}
if (cmd.skipProductcategories) {
magentoConfig.SKIP_PRODUCTCATEGORIES = true;
}
if (cmd.skipAttributes) {
magentoConfig.SKIP_ATTRIBUTES = true;
}
if (cmd.skipTaxrule) {
magentoConfig.SKIP_TAXRULE = true;
}
if (cmd.skipProducts) {
magentoConfig.SKIP_PRODUCTS = true;
}

const env = Object.assign({}, magentoConfig, process.env) // use process env as well
console.log('=== The mage2vuestorefront full reindex is about to start. Using the following Magento2 config ===', magentoConfig)

console.log(' == CREATING NEW DATABASE ==')
exec('node', [
'scripts/db.js',
'new',
`--indexName=${env.INDEX_NAME}`
], { env: env, shell: true }).then((res) => {
let createDbPromise = function() {

console.log(' == CREATING NEW DATABASE ==')
return exec('node', [
'scripts/db.js',
'new',
`--indexName=${env.INDEX_NAME}`
], { env: env, shell: true })

}

console.log(' == REVIEWS IMPORTER ==')
exec('node', [
'--harmony',
'node_modules/mage2vuestorefront/src/cli.js',
'reviews'
], { env: env, shell: true }).then((res) => {
let importReviewsPromise = function() {
if (magentoConfig.SKIP_REVIEWS ) {
return Promise.resolve();
}
else {
console.log(' == REVIEWS IMPORTER ==');
return exec('node', [
'--harmony',
'node_modules/mage2vuestorefront/src/cli.js',
'reviews'
], {env: env, shell: true})
}
}

console.log(' == CATEGORIES IMPORTER ==')
exec('node', [
let importCategoriesPromise = function() {
if (magentoConfig.SKIP_CATEGORIES ) {
return Promise.resolve();
}
else {
console.log(' == CATEGORIES IMPORTER ==');
return exec('node', [
'--harmony',
'node_modules/mage2vuestorefront/src/cli.js',
'categories',
'--removeNonExistent=true',
'--extendedCategories=true'
], { env: env, shell: true }).then((res) => {

console.log(' == PRODUCT-CATEGORIES IMPORTER ==')
exec('node', [
'--harmony',
'node_modules/mage2vuestorefront/src/cli.js',
'productcategories'
], { env: env, shell: true }).then((res) => {

console.log(' == ATTRIBUTES IMPORTER ==')
exec('node', [
'--harmony',
'node_modules/mage2vuestorefront/src/cli.js',
'attributes',
'--removeNonExistent=true'
], { env: env, shell: true }).then((res) => {

console.log(' == TAXRULE IMPORTER ==')
exec('node', [
'--harmony',
'node_modules/mage2vuestorefront/src/cli.js',
'taxrule',
'--removeNonExistent=true'
], { env: env, shell: true }).then((res) => {

console.log(' == PRODUCTS IMPORTER ==')
exec('node', [
'--harmony',
'node_modules/mage2vuestorefront/src/cli.js',
'products',
'--removeNonExistent=true',
'--partitions=1'
], { env: env, shell: true }).then((res) => {

console.log(' == REINDEXING DATABASE ==')
exec('node', [
'scripts/db.js',
'rebuild',
`--indexName=${env.INDEX_NAME}`
], { env: env, shell: true }).then((res) => {
console.log('Done! Bye Bye!')
process.exit(0)
});
], { env: env, shell: true })
}
}

let importProductcategoriesPromise = function() {
if (magentoConfig.SKIP_PRODUCTCATEGORIES ) {
return Promise.resolve();
}
else {
console.log(' == PRODUCT-CATEGORIES IMPORTER ==');
return exec('node', [
'--harmony',
'node_modules/mage2vuestorefront/src/cli.js',
'productcategories'
], { env: env, shell: true })
}
}

let importAttributesPromise = function() {
if (magentoConfig.SKIP_ATTRIBUTES ) {
return Promise.resolve();
}
else {
console.log(' == ATTRIBUTES IMPORTER ==');
return exec('node', [
'--harmony',
'node_modules/mage2vuestorefront/src/cli.js',
'attributes',
'--removeNonExistent=true'
], { env: env, shell: true })
}
}

let importTaxrulePromise = function() {
if (magentoConfig.SKIP_TAXRULE ) {
return Promise.resolve();
}
else {
console.log(' == TAXRULE IMPORTER ==');
return exec('node', [
'--harmony',
'node_modules/mage2vuestorefront/src/cli.js',
'taxrule',
'--removeNonExistent=true'
], { env: env, shell: true })
}
}

let importProductsPromise = function() {
if (magentoConfig.SKIP_PRODUCTS ) {
return Promise.resolve();
}
else {
console.log(' == PRODUCTS IMPORTER ==');
return exec('node', [
'--harmony',
'node_modules/mage2vuestorefront/src/cli.js',
'products',
'--removeNonExistent=true',
'--partitions=1'
], { env: env, shell: true })
}
}

let reindexPromise = function() {
console.log(' == REINDEXING DATABASE ==')
return exec('node', [
'scripts/db.js',
'rebuild',
`--indexName=${env.INDEX_NAME}`
], {env: env, shell: true})
}

createDbPromise().then( () => {
importReviewsPromise().then( () => {
importCategoriesPromise().then( () => {
importProductcategoriesPromise().then( () => {
importAttributesPromise().then(() => {
importTaxrulePromise().then(() => {
importProductsPromise().then (() => {
reindexPromise().then( () => {
console.log('Done! Bye Bye!')
process.exit(0)
})
})
})
})
})
})
})
})
})
})
});


program
Expand Down
8 changes: 6 additions & 2 deletions src/lib/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ export async function resize (buffer, width, height) {
const transformer = sharp(buffer);

if (width || height) {
transformer.resize(width, height).max().withoutEnlargement();
const options = {
withoutEnlargement: true,
fit: sharp.fit.inside
}
transformer.resize(width, height, options)
}

return transformer.toBuffer();
Expand Down Expand Up @@ -61,4 +65,4 @@ export async function crop (buffer, width, height, x, y) {
} catch (err) {
console.log(err);
}
}
}
42 changes: 24 additions & 18 deletions src/platform/magento2/o2m.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,12 @@ function processSingleOrder(orderData, config, job, done, logger = console) {
let mappedBillingRegion = 0

api.directory.countries().then((countryList) => {
if (shippingAddr.region_id > 0) {
mappedShippingRegion = { regionId: shippingAddr.region_id, regionCode: shippingAddr.region_code }
} else {
mappedShippingRegion = countryMapper.mapCountryRegion(countryList, shippingAddr.country_id, shippingAddr.region_code ? shippingAddr.region_code : shippingAddr.region)
if (typeof shippingAddr !== 'undefined' && shippingAddr !== null) {
if (shippingAddr.region_id > 0) {
mappedShippingRegion = { regionId: shippingAddr.region_id, regionCode: shippingAddr.region_code }
} else {
mappedShippingRegion = countryMapper.mapCountryRegion(countryList, shippingAddr.country_id, shippingAddr.region_code ? shippingAddr.region_code : shippingAddr.region)
}
}

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

const shippingAddressInfo = { // sum up totals
"addressInformation": {
"shippingAddress": {
"countryId": shippingAddr.country_id,
"street": shippingAddr.street,
"telephone": shippingAddr.telephone,
"postcode": shippingAddr.postcode,
"city": shippingAddr.city,
"firstname": shippingAddr.firstname,
"lastname": shippingAddr.lastname,
"email": shippingAddr.email,
"regionId": mappedShippingRegion.regionId,
"regionCode": mappedShippingRegion.regionCode,
"company": shippingAddr.company
},

"billingAddress": {
"countryId": billingAddr.country_id,
"street": billingAddr.street,
Expand All @@ -197,6 +185,24 @@ function processSingleOrder(orderData, config, job, done, logger = console) {
}
}

if (typeof shippingAddr !== 'undefined' && shippingAddr !== null) {
shippingAddressInfo["addressInformation"]["shippingAddress"] = {
"countryId": shippingAddr.country_id,
"street": shippingAddr.street,
"telephone": shippingAddr.telephone,
"postcode": shippingAddr.postcode,
"city": shippingAddr.city,
"firstname": shippingAddr.firstname,
"lastname": shippingAddr.lastname,
"email": shippingAddr.email,
"regionId": mappedShippingRegion.regionId,
"regionCode": mappedShippingRegion.regionCode,
"company": shippingAddr.company
}
} else {
shippingAddressInfo["addressInformation"]["shippingAddress"] = shippingAddressInfo["addressInformation"]["billingAddress"]
}

logger.info(THREAD_ID + '< Billing info', billingAddressInfo)
api.cart.billingAddress(null, cartId, billingAddressInfo, isThisAuthOrder).then((result) => {
logger.info(THREAD_ID + '< Billing address assigned', result)
Expand Down
Loading

0 comments on commit 58a8888

Please sign in to comment.