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

Commit 251aaed

Browse files
authored
Merge pull request #77 from DivanteLtd/develop
1.2.0 release
2 parents 570873a + c0da46d commit 251aaed

File tree

4 files changed

+46
-20
lines changed

4 files changed

+46
-20
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

config/elastic.schema.index.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"settings": {
3+
"analysis": {
4+
"tokenizer": {
5+
"comma": {
6+
"type": "pattern",
7+
"pattern" : ","
8+
}
9+
},
10+
"analyzer": {
11+
"comma": {
12+
"type": "custom",
13+
"tokenizer": "comma"
14+
}
15+
}
16+
}
17+
}
18+
}

src/lib/elastic.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ function reIndex(db, fromIndexName, toIndexName, next) {
6060
}
6161

6262
function createIndex(db, indexName, next) {
63+
let indexSchema = loadSchema('index');
6364

6465
const step2 = () => {
6566

@@ -69,7 +70,8 @@ function createIndex(db, indexName, next) {
6970
console.dir(res1, { depth: null, colors: true })
7071
db.indices.create(
7172
{
72-
"index": indexName
73+
"index": indexName,
74+
"body": indexSchema
7375
}).then(res2 => {
7476
console.dir(res2, { depth: null, colors: true })
7577
next()
@@ -80,7 +82,8 @@ function createIndex(db, indexName, next) {
8082
}).catch(() => {
8183
db.indices.create(
8284
{
83-
"index": indexName
85+
"index": indexName,
86+
"body": indexSchema
8487
}).then(res2 => {
8588
console.dir(res2, { depth: null, colors: true })
8689
next()

src/lib/taxcalc.js

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
export function updateProductPrices (product, rate, sourcePriceInclTax = false) {
2+
const rateFactor = parseFloat(rate.rate) / 100
23
product.price = parseFloat(product.price)
4+
product.special_price = parseFloat(product.special_price)
35

46
let priceExclTax = product.price
57
if (sourcePriceInclTax) {
6-
priceExclTax = product.price / (1 + (rate.rate / 100))
8+
priceExclTax = product.price / (1 + rateFactor)
79
product.price = priceExclTax
810
}
9-
product.priceInclTax = (priceExclTax + priceExclTax * (parseFloat(rate.rate) / 100))
10-
product.priceTax = (priceExclTax * (parseFloat(rate.rate) / 100))
1111

12-
product.special_price = parseFloat(product.special_price)
12+
product.priceTax = priceExclTax * rateFactor
13+
product.priceInclTax = priceExclTax + product.priceTax
1314

1415
let specialPriceExclTax = product.special_price
1516
if (sourcePriceInclTax) {
16-
specialPriceExclTax = product.special_price / (1 + (rate.rate / 100))
17+
specialPriceExclTax = product.special_price / (1 + rateFactor)
1718
product.special_price = specialPriceExclTax
1819
}
1920

20-
product.specialPriceInclTax = (specialPriceExclTax + specialPriceExclTax * (parseFloat(rate.rate) / 100))
21-
product.specialPriceTax = (specialPriceExclTax * (parseFloat(rate.rate) / 100))
21+
product.specialPriceTax = specialPriceExclTax * rateFactor
22+
product.specialPriceInclTax = specialPriceExclTax + product.specialPriceTax
2223

2324
if (product.special_price && (product.special_price < product.price)) {
2425
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())) {
@@ -44,23 +45,25 @@ export function updateProductPrices (product, rate, sourcePriceInclTax = false)
4445
}
4546
}
4647
configurableChild.price = parseFloat(configurableChild.price)
48+
configurableChild.special_price = parseFloat(configurableChild.special_price)
49+
4750
let priceExclTax = configurableChild.price
4851
if (sourcePriceInclTax) {
49-
priceExclTax = configurableChild.price / (1 + (rate.rate / 100))
52+
priceExclTax = configurableChild.price / (1 + rateFactor)
5053
configurableChild.price = priceExclTax
5154
}
5255

53-
configurableChild.priceInclTax = (priceExclTax + priceExclTax * (parseFloat(rate.rate) / 100))
54-
configurableChild.priceTax = (priceExclTax * (parseFloat(rate.rate) / 100))
56+
configurableChild.priceTax = priceExclTax * rateFactor
57+
configurableChild.priceInclTax = priceExclTax + configurableChild.priceTax
5558

5659
let specialPriceExclTax = configurableChild.special_price
5760
if (sourcePriceInclTax) {
58-
specialPriceExclTax = configurableChild.special_price / (1 + (rate.rate / 100))
61+
specialPriceExclTax = configurableChild.special_price / (1 + rateFactor)
5962
configurableChild.special_price = specialPriceExclTax
6063
}
6164

62-
configurableChild.specialPriceInclTax = (specialPriceExclTax + specialPriceExclTax * (parseFloat(rate.rate) / 100))
63-
configurableChild.specialPriceTax = (specialPriceExclTax * (parseFloat(rate.rate) / 100))
65+
configurableChild.specialPriceTax = specialPriceExclTax * rateFactor
66+
configurableChild.specialPriceInclTax = specialPriceExclTax + configurableChild.specialPriceTax
6467

6568
if (configurableChild.special_price && (configurableChild.special_price < configurableChild.price)) {
6669
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())) {
@@ -79,10 +82,10 @@ export function updateProductPrices (product, rate, sourcePriceInclTax = false)
7982
}
8083

8184
if (configurableChild.priceInclTax < product.priceInclTax || product.price === 0) { // always show the lowest price
82-
product.priceInclTax = parseFloat(configurableChild.priceInclTax)
83-
product.priceTax = parseFloat(configurableChild.priceTax)
84-
product.price = parseFloat(configurableChild.price)
85-
product.special_price = parseFloat(configurableChild.special_price)
85+
product.priceInclTax = configurableChild.priceInclTax
86+
product.priceTax = configurableChild.priceTax
87+
product.price = configurableChild.price
88+
product.special_price = configurableChild.special_price
8689
product.specialPriceInclTax = configurableChild.specialPriceInclTax
8790
product.specialPriceTax = configurableChild.specialPriceTax
8891
product.originalPrice = configurableChild.originalPrice
@@ -92,6 +95,7 @@ export function updateProductPrices (product, rate, sourcePriceInclTax = false)
9295
}
9396
}
9497
}
98+
9599
export function calculateProductTax (product, taxClasses, taxCountry = 'PL', taxRegion = '', sourcePriceInclTax = false) {
96100
let rateFound = false
97101
let taxClass = taxClasses.find((el) => el.product_tax_class_ids.indexOf(parseInt(product.tax_class_id) >= 0))
@@ -107,7 +111,7 @@ export function calculateProductTax (product, taxClasses, taxCountry = 'PL', tax
107111
}
108112
if (!rateFound) {
109113
console.log('No such tax class id: ' + product.tax_class_id + ' or rate not found for ' + taxCountry + ' / ' + taxRegion)
110-
updateProductPrices(product, { rate: 0 })
114+
updateProductPrices(product, {rate: 0})
111115

112116
product.priceInclTax = product.price
113117
product.priceTax = 0

0 commit comments

Comments
 (0)