@symbolic/lib
Advanced tools
Comparing version 1.0.222 to 1.0.223
{ | ||
"name": "@symbolic/lib", | ||
"version": "1.0.222", | ||
"version": "1.0.223", | ||
"description": "plain js utilities", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -5,6 +5,6 @@ import memo from '../memo'; | ||
export default function __getHelper({shouldMemo}, {priceFor, productPricingRuleVersionFor}) { | ||
function calculatePriceForInstance({productInstance}, dependencies) { | ||
function calculatePriceForInstance({productInstance, productOrder}, dependencies) { | ||
const {productsById, productPricingRulesById} = dependencies; | ||
const {expressions} = productPricingRuleVersionFor({productInstance}, {productsById, productPricingRulesById}); | ||
const {expressions} = productPricingRuleVersionFor({productInstance, productOrder}, {productsById, productPricingRulesById}); | ||
const product = productsById[productInstance.productId]; | ||
@@ -11,0 +11,0 @@ |
@@ -9,3 +9,3 @@ import dinero from "dinero.js"; | ||
var allProductsPrices = _.map(productInstances, (productInstance) => dinero({amount: calculatePriceForInstance({productInstance}, dependencies)})); | ||
var allProductsPrices = _.map(productInstances, (productInstance) => dinero({amount: calculatePriceForInstance({productInstance, productOrder}, dependencies)})); | ||
@@ -12,0 +12,0 @@ var orderSubTotal = _.reduce(allProductsPrices, (sum, n) => sum.add(n), dinero({amount: 0})).getAmount(); |
@@ -5,3 +5,3 @@ import _ from 'lodash'; | ||
export default function __getHelper() { | ||
return function productPricingRuleVersionFor({productInstance, productPricingRule}, dependencies) { | ||
return function productPricingRuleVersionFor({productInstance, productPricingRule, productOrder}, dependencies) { | ||
if (productInstance.productId === -1) return {expressions: []}; | ||
@@ -19,9 +19,15 @@ else { | ||
var productPricingRuleVersionsCreatedBeforeProductInstance = _.filter(productPricingRule.versions, (version) => { | ||
return moment(version.created).isSameOrBefore(productInstance.created); | ||
var effectivePricingDate = moment().format('YYYY-MM-DD HH:mm:ss'); | ||
if (productOrder) effectivePricingDate = _.get(productOrder, 'effectivePricingDate', productOrder.created); | ||
var productPricingRuleVersionsCreatedBeforeEffectivePricingDate = _.filter(productPricingRule.versions, (version) => { | ||
return moment(version.created).isSameOrBefore(effectivePricingDate); | ||
}); | ||
return _.last(productPricingRuleVersionsCreatedBeforeProductInstance); | ||
return _.last(_.sortBy(_.map(productPricingRuleVersionsCreatedBeforeEffectivePricingDate, (version) => { | ||
return {...version, createdUnixTimestamp: moment(version.created).unix()} | ||
}), ['createdUnixTimestamp'])); | ||
} | ||
}; | ||
} |
Sorry, the diff of this file is too big to display
153656
2954