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 #77 from DivanteLtd/develop
Browse files Browse the repository at this point in the history
1.2.0 release
  • Loading branch information
pkarw authored Aug 1, 2018
2 parents 570873a + c0da46d commit 251aaed
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 20 deletions.
1 change: 1 addition & 0 deletions config/elastic.schema.index.extension.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
18 changes: 18 additions & 0 deletions config/elastic.schema.index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"settings": {
"analysis": {
"tokenizer": {
"comma": {
"type": "pattern",
"pattern" : ","
}
},
"analyzer": {
"comma": {
"type": "custom",
"tokenizer": "comma"
}
}
}
}
}
7 changes: 5 additions & 2 deletions src/lib/elastic.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function reIndex(db, fromIndexName, toIndexName, next) {
}

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

const step2 = () => {

Expand All @@ -69,7 +70,8 @@ function createIndex(db, indexName, next) {
console.dir(res1, { depth: null, colors: true })
db.indices.create(
{
"index": indexName
"index": indexName,
"body": indexSchema
}).then(res2 => {
console.dir(res2, { depth: null, colors: true })
next()
Expand All @@ -80,7 +82,8 @@ function createIndex(db, indexName, next) {
}).catch(() => {
db.indices.create(
{
"index": indexName
"index": indexName,
"body": indexSchema
}).then(res2 => {
console.dir(res2, { depth: null, colors: true })
next()
Expand Down
40 changes: 22 additions & 18 deletions src/lib/taxcalc.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
export function updateProductPrices (product, rate, sourcePriceInclTax = false) {
const rateFactor = parseFloat(rate.rate) / 100
product.price = parseFloat(product.price)
product.special_price = parseFloat(product.special_price)

let priceExclTax = product.price
if (sourcePriceInclTax) {
priceExclTax = product.price / (1 + (rate.rate / 100))
priceExclTax = product.price / (1 + rateFactor)
product.price = priceExclTax
}
product.priceInclTax = (priceExclTax + priceExclTax * (parseFloat(rate.rate) / 100))
product.priceTax = (priceExclTax * (parseFloat(rate.rate) / 100))

product.special_price = parseFloat(product.special_price)
product.priceTax = priceExclTax * rateFactor
product.priceInclTax = priceExclTax + product.priceTax

let specialPriceExclTax = product.special_price
if (sourcePriceInclTax) {
specialPriceExclTax = product.special_price / (1 + (rate.rate / 100))
specialPriceExclTax = product.special_price / (1 + rateFactor)
product.special_price = specialPriceExclTax
}

product.specialPriceInclTax = (specialPriceExclTax + specialPriceExclTax * (parseFloat(rate.rate) / 100))
product.specialPriceTax = (specialPriceExclTax * (parseFloat(rate.rate) / 100))
product.specialPriceTax = specialPriceExclTax * rateFactor
product.specialPriceInclTax = specialPriceExclTax + product.specialPriceTax

if (product.special_price && (product.special_price < product.price)) {
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())) {
Expand All @@ -44,23 +45,25 @@ export function updateProductPrices (product, rate, sourcePriceInclTax = false)
}
}
configurableChild.price = parseFloat(configurableChild.price)
configurableChild.special_price = parseFloat(configurableChild.special_price)

let priceExclTax = configurableChild.price
if (sourcePriceInclTax) {
priceExclTax = configurableChild.price / (1 + (rate.rate / 100))
priceExclTax = configurableChild.price / (1 + rateFactor)
configurableChild.price = priceExclTax
}

configurableChild.priceInclTax = (priceExclTax + priceExclTax * (parseFloat(rate.rate) / 100))
configurableChild.priceTax = (priceExclTax * (parseFloat(rate.rate) / 100))
configurableChild.priceTax = priceExclTax * rateFactor
configurableChild.priceInclTax = priceExclTax + configurableChild.priceTax

let specialPriceExclTax = configurableChild.special_price
if (sourcePriceInclTax) {
specialPriceExclTax = configurableChild.special_price / (1 + (rate.rate / 100))
specialPriceExclTax = configurableChild.special_price / (1 + rateFactor)
configurableChild.special_price = specialPriceExclTax
}

configurableChild.specialPriceInclTax = (specialPriceExclTax + specialPriceExclTax * (parseFloat(rate.rate) / 100))
configurableChild.specialPriceTax = (specialPriceExclTax * (parseFloat(rate.rate) / 100))
configurableChild.specialPriceTax = specialPriceExclTax * rateFactor
configurableChild.specialPriceInclTax = specialPriceExclTax + configurableChild.specialPriceTax

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

if (configurableChild.priceInclTax < product.priceInclTax || product.price === 0) { // always show the lowest price
product.priceInclTax = parseFloat(configurableChild.priceInclTax)
product.priceTax = parseFloat(configurableChild.priceTax)
product.price = parseFloat(configurableChild.price)
product.special_price = parseFloat(configurableChild.special_price)
product.priceInclTax = configurableChild.priceInclTax
product.priceTax = configurableChild.priceTax
product.price = configurableChild.price
product.special_price = configurableChild.special_price
product.specialPriceInclTax = configurableChild.specialPriceInclTax
product.specialPriceTax = configurableChild.specialPriceTax
product.originalPrice = configurableChild.originalPrice
Expand All @@ -92,6 +95,7 @@ export function updateProductPrices (product, rate, sourcePriceInclTax = false)
}
}
}

export function calculateProductTax (product, taxClasses, taxCountry = 'PL', taxRegion = '', sourcePriceInclTax = false) {
let rateFound = false
let taxClass = taxClasses.find((el) => el.product_tax_class_ids.indexOf(parseInt(product.tax_class_id) >= 0))
Expand All @@ -107,7 +111,7 @@ export function calculateProductTax (product, taxClasses, taxCountry = 'PL', tax
}
if (!rateFound) {
console.log('No such tax class id: ' + product.tax_class_id + ' or rate not found for ' + taxCountry + ' / ' + taxRegion)
updateProductPrices(product, { rate: 0 })
updateProductPrices(product, {rate: 0})

product.priceInclTax = product.price
product.priceTax = 0
Expand Down

0 comments on commit 251aaed

Please sign in to comment.