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

Commit a735184

Browse files
committed
merge master to develop
2 parents 2d1c940 + 5e5249b commit a735184

File tree

10 files changed

+98
-27
lines changed

10 files changed

+98
-27
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ You can run the following command to execute the full import:
127127
```
128128

129129
... or in multistore setup You can run the same command with specified `store-code` parameter
130-
`
131-
``bash
130+
131+
```bash
132132
yarn mage2vs import --store-code=de
133133
```
134134

config/default.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
"orders": {
88
"useServerQueue": false
99
},
10+
"catalog": {
11+
"excludeDisabledProducts": false
12+
},
1013
"elasticsearch": {
1114
"host": "localhost",
1215
"port": 9200,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

config/elastic.schema.category.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"properties": {
3+
"url_key": {"type": "keyword"},
4+
"is_active": {"type": "boolean"},
5+
"product_count": {"type": "integer"},
6+
"parent_id": {"type": "integer"},
7+
"created_at": {
8+
"type": "date",
9+
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
10+
},
11+
"updated_at": {
12+
"type": "date",
13+
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
14+
}
15+
}
16+
}

config/elastic.schema.product.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"properties": {
33
"sku": {"type": "keyword"},
44
"url_key": {"type": "keyword"},
5+
"slug": {"type": "keyword"},
56
"size": {"type": "integer"},
67
"size_options": {"type": "integer"},
78
"price": {"type": "float"},
@@ -42,9 +43,11 @@
4243
"name": {"type": "text"},
4344
"configurable_children": {
4445
"properties": {
46+
"url_key": {"type": "keyword"},
47+
"sku": {"type": "keyword"},
4548
"has_options": {"type": "boolean"},
4649
"price": {"type": "float"},
47-
"sku": {"type": "keyword"}
50+
"special_price": {"type": "float"}
4851
}
4952
},
5053
"configurable_options": {

scripts/mage2vs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function getMagentoDefaultConfig(storeCode) {
3030
SKIP_ATTRIBUTES: false,
3131
SKIP_TAXRULE: false,
3232
SKIP_PRODUCTS: false,
33+
PRODUCTS_EXCLUDE_DISABLED: config.catalog.excludeDisabledProducts,
3334
MAGENTO_CONSUMER_KEY: apiConfig.consumerKey,
3435
MAGENTO_CONSUMER_SECRET: apiConfig.consumerSecret,
3536
MAGENTO_ACCESS_TOKEN: apiConfig.accessToken,

scripts/seo.js

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ const config = require('config')
33
const common = require('../migrations/.common')
44
const es = require('../src/lib/elastic')
55

6+
const fs = require('fs')
7+
const path = require('path')
8+
69
program
710
.command('redirects')
811
.option('-i|--indexName <indexName>', 'name of the Elasticsearch index', config.elasticsearch.indices[0])
912
.option('-f|--oldFormat <oldFormat>', 'use the old format', true)
1013
.option('-s|--size <size>', 'size', 10000)
11-
.action((cmd) => {
14+
.option('-d|--dest <dest>', 'dest', './')
15+
.action(async (cmd) => {
1216
if (!cmd.indexName) {
1317
console.error('error: indexName must be specified');
1418
process.exit(1);
@@ -18,24 +22,28 @@ program
1822
console.log('** Please check the nginx map module options on how to use this map format: https://serverfault.com/a/441517')
1923
console.log('** The urls will be mapped to the new VS Url format. Please make sure You have "products.useMagentoUrlKeys=true" in Your vue-storefront/config/local.json')
2024

21-
es.search(common.db, {
22-
index: cmd.indexName,
23-
type: 'product',
24-
size: cmd.size,
25-
body: {}
26-
}).then(function (resp) {
27-
const hits = resp.hits.hits
25+
try {
26+
const redirects = []
27+
28+
await es.search(common.db, {
29+
index: cmd.indexName,
30+
type: 'product',
31+
size: cmd.size,
32+
body: {}
33+
}).then(function (resp) {
34+
const hits = resp.hits.hits
2835

29-
for (const hit of hits) {
30-
const product = hit._source
31-
if (cmd.oldFormat) {
32-
console.log(`/${product.url_key} /p/${decodeURIComponent(product.sku)}/${product.url_key}/${decodeURIComponent(product.sku)};`)
33-
} else {
34-
console.log(`/${product.url_key} /${product.url_key}/${decodeURIComponent(product.sku)};`)
36+
for (const hit of hits) {
37+
const product = hit._source
38+
if (cmd.oldFormat) {
39+
redirects.push(`/${product.url_key} /p/${decodeURIComponent(product.sku)}/${product.url_key}/${decodeURIComponent(product.sku)};`)
40+
} else {
41+
redirects.push(`/${product.url_key} /${product.url_key}/${decodeURIComponent(product.sku)};`)
42+
}
3543
}
36-
}
44+
})
3745

38-
es.search(common.db, {
46+
await es.search(common.db, {
3947
index: cmd.indexName,
4048
type: 'category',
4149
size: cmd.size,
@@ -45,13 +53,22 @@ program
4553
for (const hit of hits) {
4654
const category = hit._source
4755
if (cmd.oldFormat) {
48-
console.log(`/${category.url_path} /c/${category.url_key};`)
56+
redirects.push(`/${category.url_path} /c/${category.url_key};`)
4957
} else {
50-
console.log(`/${category.url_path} /${category.url_key};`)
58+
redirects.push(`/${category.url_path} /${category.url_key};`)
5159
}
5260
}
5361
})
54-
})
62+
63+
fs.writeFileSync(
64+
path.join(path.resolve(cmd.dest), `${cmd.indexName}-redirects`),
65+
redirects.join('\n')
66+
)
67+
process.exit(0)
68+
} catch (error) {
69+
console.error(error)
70+
process.exit(1)
71+
}
5572
})
5673

5774
program

src/lib/elastic.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ function loadSchema(entityType) {
122122

123123
function putMappings(db, indexName, next) {
124124
let productSchema = loadSchema('product');
125+
let categorySchema = loadSchema('category');
125126
let taxruleSchema = loadSchema('taxrule');
126127
let attributeSchema = loadSchema('attribute');
127128
let pageSchema = loadSchema('page');
@@ -158,8 +159,15 @@ function putMappings(db, indexName, next) {
158159
type: "cms_block",
159160
body: blockSchema
160161
}).then(res5 => {
161-
console.dir(res5, { depth: null, colors: true })
162-
next()
162+
console.dir(res5, { depth: null, colors: true })
163+
db.indices.putMapping({
164+
index: indexName,
165+
type: "category",
166+
body: categorySchema
167+
}).then(res6 => {
168+
console.dir(res6, { depth: null, colors: true })
169+
next()
170+
})
163171
})
164172
})
165173
}).catch(err3 => {

src/lib/taxcalc.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
function isSpecialPriceActive(fromDate, toDate) {
2+
const now = new Date()
3+
fromDate = new Date(fromDate) || false
4+
toDate = new Date(toDate) || false
5+
6+
if (!fromDate && !toDate) {
7+
return true
8+
}
9+
10+
if (fromDate && toDate) {
11+
return fromDate < now && toDate > now
12+
}
13+
14+
if (fromDate && !toDate) {
15+
return fromDate < now
16+
}
17+
18+
if (!fromDate && toDate) {
19+
return toDate > now
20+
}
21+
}
22+
123
export function updateProductPrices (product, rate, sourcePriceInclTax = false) {
224
const rateFactor = parseFloat(rate.rate) / 100
325
product.price = parseFloat(product.price)
@@ -22,7 +44,7 @@ export function updateProductPrices (product, rate, sourcePriceInclTax = false)
2244
product.specialPriceInclTax = specialPriceExclTax + product.specialPriceTax
2345

2446
if (product.special_price && (product.special_price < product.price)) {
25-
if ((product.special_to_date && new Date(product.special_to_date) < new Date()) || (product.special_from_date && new Date(product.special_from_date) > new Date())) {
47+
if (!isSpecialPriceActive(product.special_from_date, product.special_to_date)) {
2648
product.special_price = 0 // out of the dates period
2749
} else {
2850
product.originalPrice = priceExclTax
@@ -67,7 +89,7 @@ export function updateProductPrices (product, rate, sourcePriceInclTax = false)
6789
configurableChild.specialPriceInclTax = specialPriceExclTax + configurableChild.specialPriceTax
6890

6991
if (configurableChild.special_price && (configurableChild.special_price < configurableChild.price)) {
70-
if ((configurableChild.special_to_date && new Date(configurableChild.special_to_date) < new Date()) || (configurableChild.special_from_date && new Date(configurableChild.special_from_date) > new Date())) {
92+
if (!isSpecialPriceActive(configurableChild.special_from_date, configurableChild.special_to_date)) {
7193
configurableChild.special_price = 0 // out of the dates period
7294
} else {
7395
configurableChild.originalPrice = priceExclTax

src/platform/magento2/review.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import AbstractReviewProxy from '../abstract/user'
1+
import AbstractReviewProxy from '../abstract/review'
22
import { multiStoreConfig } from './util'
33
const Magento2Client = require('magento2-rest-client').Magento2Client;
44

0 commit comments

Comments
 (0)