@daffodil/product-composite 0.66.0 → 0.67.0
Sign up to get free protection for your applications and to get access to all the features.
- package/{esm2020 → esm2022}/driver/in-memory/in-memory.module.mjs +5 -5
- package/{esm2020 → esm2022}/driver/magento/composite-product-driver.module.mjs +5 -5
- package/{esm2020 → esm2022}/driver/magento/testing/factories/bundle/bundle-item-option.factory.mjs +5 -5
- package/{esm2020 → esm2022}/driver/magento/testing/factories/bundle/bundle-item.factory.mjs +5 -5
- package/{esm2020 → esm2022}/driver/magento/testing/factories/bundle/bundle.factory.mjs +5 -5
- package/{esm2020 → esm2022}/driver/testing/testing.module.mjs +5 -5
- package/{esm2020 → esm2022}/routing/effects/product-page.effects.mjs +6 -6
- package/{esm2020 → esm2022}/routing/module.mjs +7 -7
- package/{esm2020 → esm2022}/routing/services/query-param.service.mjs +6 -6
- package/{esm2020 → esm2022}/state/composite-product-state.module.mjs +7 -7
- package/{esm2020 → esm2022}/state/facades/composite-product/composite-product.facade.mjs +5 -5
- package/{esm2020 → esm2022}/state/testing/mock-composite-product-facade.mjs +4 -4
- package/{esm2020 → esm2022}/state/testing/product-testing.module.mjs +7 -7
- package/{esm2020 → esm2022}/testing/factories/composite-product-item-option.factory.mjs +5 -5
- package/{esm2020 → esm2022}/testing/factories/composite-product-item.factory.mjs +5 -5
- package/{esm2020 → esm2022}/testing/factories/composite-product.factory.mjs +5 -5
- package/{fesm2020 → fesm2022}/daffodil-product-composite-driver-in-memory.mjs +4 -4
- package/{fesm2015 → fesm2022}/daffodil-product-composite-driver-in-memory.mjs.map +1 -1
- package/{fesm2015 → fesm2022}/daffodil-product-composite-driver-magento-testing.mjs +12 -12
- package/{fesm2020 → fesm2022}/daffodil-product-composite-driver-magento-testing.mjs.map +1 -1
- package/{fesm2020 → fesm2022}/daffodil-product-composite-driver-magento.mjs +4 -4
- package/{fesm2020 → fesm2022}/daffodil-product-composite-driver-magento.mjs.map +1 -1
- package/{fesm2020 → fesm2022}/daffodil-product-composite-driver-testing.mjs +4 -4
- package/{fesm2015 → fesm2022}/daffodil-product-composite-driver-testing.mjs.map +1 -1
- package/{fesm2020 → fesm2022}/daffodil-product-composite-routing.mjs +16 -16
- package/{fesm2020 → fesm2022}/daffodil-product-composite-routing.mjs.map +1 -1
- package/{fesm2015 → fesm2022}/daffodil-product-composite-state-testing.mjs +9 -9
- package/{fesm2015 → fesm2022}/daffodil-product-composite-state-testing.mjs.map +1 -1
- package/{fesm2020 → fesm2022}/daffodil-product-composite-state.mjs +10 -10
- package/{fesm2020 → fesm2022}/daffodil-product-composite-state.mjs.map +1 -1
- package/{fesm2020 → fesm2022}/daffodil-product-composite-testing.mjs +12 -12
- package/{fesm2020 → fesm2022}/daffodil-product-composite-testing.mjs.map +1 -1
- package/models/selection-payload.type.d.ts +1 -1
- package/package.json +1 -1
- package/state/actions/composite-product.actions.d.ts +1 -1
- package/state/reducers/ensure-items.meta-reducer.d.ts +1 -1
- package/fesm2015/daffodil-product-composite-driver-in-memory.mjs +0 -41
- package/fesm2015/daffodil-product-composite-driver-magento-testing.mjs.map +0 -1
- package/fesm2015/daffodil-product-composite-driver-magento.mjs +0 -141
- package/fesm2015/daffodil-product-composite-driver-magento.mjs.map +0 -1
- package/fesm2015/daffodil-product-composite-driver-testing.mjs +0 -41
- package/fesm2015/daffodil-product-composite-routing.mjs +0 -156
- package/fesm2015/daffodil-product-composite-routing.mjs.map +0 -1
- package/fesm2015/daffodil-product-composite-state.mjs +0 -520
- package/fesm2015/daffodil-product-composite-state.mjs.map +0 -1
- package/fesm2015/daffodil-product-composite-testing.mjs +0 -108
- package/fesm2015/daffodil-product-composite-testing.mjs.map +0 -1
- package/fesm2015/daffodil-product-composite.mjs.map +0 -1
- package/fesm2020/daffodil-product-composite-driver-in-memory.mjs.map +0 -1
- package/fesm2020/daffodil-product-composite-driver-magento-testing.mjs +0 -103
- package/fesm2020/daffodil-product-composite-driver-testing.mjs.map +0 -1
- package/fesm2020/daffodil-product-composite-state-testing.mjs +0 -70
- package/fesm2020/daffodil-product-composite-state-testing.mjs.map +0 -1
- package/fesm2020/daffodil-product-composite.mjs +0 -25
- /package/{esm2020 → esm2022}/daffodil-product-composite.mjs +0 -0
- /package/{esm2020 → esm2022}/driver/in-memory/daffodil-product-composite-driver-in-memory.mjs +0 -0
- /package/{esm2020 → esm2022}/driver/in-memory/index.mjs +0 -0
- /package/{esm2020 → esm2022}/driver/in-memory/public_api.mjs +0 -0
- /package/{esm2020 → esm2022}/driver/magento/daffodil-product-composite-driver-magento.mjs +0 -0
- /package/{esm2020 → esm2022}/driver/magento/fragments/bundled-product.mjs +0 -0
- /package/{esm2020 → esm2022}/driver/magento/index.mjs +0 -0
- /package/{esm2020 → esm2022}/driver/magento/models/bundled-product.mjs +0 -0
- /package/{esm2020 → esm2022}/driver/magento/models/public_api.mjs +0 -0
- /package/{esm2020 → esm2022}/driver/magento/public_api.mjs +0 -0
- /package/{esm2020 → esm2022}/driver/magento/testing/daffodil-product-composite-driver-magento-testing.mjs +0 -0
- /package/{esm2020 → esm2022}/driver/magento/testing/factories/public_api.mjs +0 -0
- /package/{esm2020 → esm2022}/driver/magento/testing/index.mjs +0 -0
- /package/{esm2020 → esm2022}/driver/magento/testing/public_api.mjs +0 -0
- /package/{esm2020 → esm2022}/driver/magento/transforms/bundled-product-transformers.mjs +0 -0
- /package/{esm2020 → esm2022}/driver/magento/transforms/public_api.mjs +0 -0
- /package/{esm2020 → esm2022}/driver/testing/daffodil-product-composite-driver-testing.mjs +0 -0
- /package/{esm2020 → esm2022}/driver/testing/index.mjs +0 -0
- /package/{esm2020 → esm2022}/driver/testing/public_api.mjs +0 -0
- /package/{esm2020 → esm2022}/helpers/build-selection-payload.mjs +0 -0
- /package/{esm2020 → esm2022}/helpers/public_api.mjs +0 -0
- /package/{esm2020 → esm2022}/index.mjs +0 -0
- /package/{esm2020 → esm2022}/models/composite-configuration-item.mjs +0 -0
- /package/{esm2020 → esm2022}/models/composite-product-item.mjs +0 -0
- /package/{esm2020 → esm2022}/models/composite-product.mjs +0 -0
- /package/{esm2020 → esm2022}/models/public_api.mjs +0 -0
- /package/{esm2020 → esm2022}/models/selection-payload.type.mjs +0 -0
- /package/{esm2020 → esm2022}/public_api.mjs +0 -0
- /package/{esm2020 → esm2022}/routing/config/default.mjs +0 -0
- /package/{esm2020 → esm2022}/routing/config/interface.mjs +0 -0
- /package/{esm2020 → esm2022}/routing/config/public_api.mjs +0 -0
- /package/{esm2020 → esm2022}/routing/config/token.mjs +0 -0
- /package/{esm2020 → esm2022}/routing/daffodil-product-composite-routing.mjs +0 -0
- /package/{esm2020 → esm2022}/routing/effects/public_api.mjs +0 -0
- /package/{esm2020 → esm2022}/routing/index.mjs +0 -0
- /package/{esm2020 → esm2022}/routing/public_api.mjs +0 -0
- /package/{esm2020 → esm2022}/state/actions/composite-product.actions.mjs +0 -0
- /package/{esm2020 → esm2022}/state/actions/public_api.mjs +0 -0
- /package/{esm2020 → esm2022}/state/daffodil-product-composite-state.mjs +0 -0
- /package/{esm2020 → esm2022}/state/facades/composite-product/composite-product-facade.interface.mjs +0 -0
- /package/{esm2020 → esm2022}/state/facades/public_api.mjs +0 -0
- /package/{esm2020 → esm2022}/state/helpers/ensure-items.mjs +0 -0
- /package/{esm2020 → esm2022}/state/helpers/public_api.mjs +0 -0
- /package/{esm2020 → esm2022}/state/index.mjs +0 -0
- /package/{esm2020 → esm2022}/state/public_api.mjs +0 -0
- /package/{esm2020 → esm2022}/state/reducers/composite-product-entities/composite-product-entities-reducer-adapter.mjs +0 -0
- /package/{esm2020 → esm2022}/state/reducers/composite-product-entities/composite-product-entities.reducer.mjs +0 -0
- /package/{esm2020 → esm2022}/state/reducers/composite-product-entities/composite-product-entity.mjs +0 -0
- /package/{esm2020 → esm2022}/state/reducers/composite-product-reducers-state.interface.mjs +0 -0
- /package/{esm2020 → esm2022}/state/reducers/composite-product-reducers.mjs +0 -0
- /package/{esm2020 → esm2022}/state/reducers/composite-product-store-feature-key.mjs +0 -0
- /package/{esm2020 → esm2022}/state/reducers/ensure-items.meta-reducer.mjs +0 -0
- /package/{esm2020 → esm2022}/state/reducers/injection-tokens/extra.token.mjs +0 -0
- /package/{esm2020 → esm2022}/state/reducers/injection-tokens/public_api.mjs +0 -0
- /package/{esm2020 → esm2022}/state/reducers/injection-tokens/reducers.token.mjs +0 -0
- /package/{esm2020 → esm2022}/state/reducers/public_api.mjs +0 -0
- /package/{esm2020 → esm2022}/state/selectors/all.selector.mjs +0 -0
- /package/{esm2020 → esm2022}/state/selectors/composite-product/composite-product.selectors.mjs +0 -0
- /package/{esm2020 → esm2022}/state/selectors/composite-product-entities/composite-product-entities.selectors.mjs +0 -0
- /package/{esm2020 → esm2022}/state/selectors/feature.selector.mjs +0 -0
- /package/{esm2020 → esm2022}/state/selectors/public_api.mjs +0 -0
- /package/{esm2020 → esm2022}/state/testing/daffodil-product-composite-state-testing.mjs +0 -0
- /package/{esm2020 → esm2022}/state/testing/index.mjs +0 -0
- /package/{esm2020 → esm2022}/state/testing/public_api.mjs +0 -0
- /package/{esm2020 → esm2022}/testing/daffodil-product-composite-testing.mjs +0 -0
- /package/{esm2020 → esm2022}/testing/factories/public_api.mjs +0 -0
- /package/{esm2020 → esm2022}/testing/index.mjs +0 -0
- /package/{esm2020 → esm2022}/testing/public_api.mjs +0 -0
- /package/{fesm2015 → fesm2022}/daffodil-product-composite.mjs +0 -0
- /package/{fesm2020 → fesm2022}/daffodil-product-composite.mjs.map +0 -0
@@ -1,520 +0,0 @@
|
|
1
|
-
import * as i0 from '@angular/core';
|
2
|
-
import { Injectable, InjectionToken, inject, NgModule } from '@angular/core';
|
3
|
-
import * as i1 from '@ngrx/store';
|
4
|
-
import { defaultMemoize, createFeatureSelector, createSelector, select, combineReducers, StoreModule } from '@ngrx/store';
|
5
|
-
import { DaffProductTypeEnum, productPriceRangeHasDiscount, productPriceRangeHasPriceRange } from '@daffodil/product';
|
6
|
-
import { daffAdd, daffMultiply, daffDivide, daffSubtract } from '@daffodil/core';
|
7
|
-
import { getDaffProductEntitiesSelectors, DaffProductPageActionTypes, DaffProductActionTypes, DaffBestSellersActionTypes, DaffProductGridActionTypes, DaffProductLoadSuccess, DaffProductPageLoadSuccess, daffProductProvideMetaReducers } from '@daffodil/product/state';
|
8
|
-
import { createEntityAdapter } from '@ngrx/entity';
|
9
|
-
import { daffComposeReducers } from '@daffodil/core/state';
|
10
|
-
|
11
|
-
/**
|
12
|
-
* Action types for Composite Product Actions.
|
13
|
-
*/
|
14
|
-
var DaffCompositeProductActionTypes;
|
15
|
-
(function (DaffCompositeProductActionTypes) {
|
16
|
-
DaffCompositeProductActionTypes["CompositeProductApplyOptionAction"] = "[Composite Product] Composite Product Apply Option Action";
|
17
|
-
})(DaffCompositeProductActionTypes || (DaffCompositeProductActionTypes = {}));
|
18
|
-
/**
|
19
|
-
* Applies a product option to a particular composite product.
|
20
|
-
*
|
21
|
-
* @param id - Id of the Composite Product
|
22
|
-
* @param itemId - Id of the product item.
|
23
|
-
* @param optionId - Id of the option of the product item that is chosen.
|
24
|
-
*/
|
25
|
-
class DaffCompositeProductApplyOption {
|
26
|
-
constructor(id, itemId, optionId, qty) {
|
27
|
-
this.id = id;
|
28
|
-
this.itemId = itemId;
|
29
|
-
this.optionId = optionId;
|
30
|
-
this.qty = qty;
|
31
|
-
this.type = DaffCompositeProductActionTypes.CompositeProductApplyOptionAction;
|
32
|
-
}
|
33
|
-
}
|
34
|
-
|
35
|
-
/**
|
36
|
-
* Composite Product Item Options Adapter for changing/overwriting entity state.
|
37
|
-
*/
|
38
|
-
class DaffCompositeProductAppliedOptionsEntitiesAdapter {
|
39
|
-
constructor() {
|
40
|
-
/**
|
41
|
-
* @docs-private
|
42
|
-
*/
|
43
|
-
this._adapter = createEntityAdapter();
|
44
|
-
}
|
45
|
-
/**
|
46
|
-
* Gets the initial entity state.
|
47
|
-
*/
|
48
|
-
getInitialState() {
|
49
|
-
return this._adapter.getInitialState();
|
50
|
-
}
|
51
|
-
/**
|
52
|
-
* Get the entity selectors.
|
53
|
-
*/
|
54
|
-
getSelectors() {
|
55
|
-
return this._adapter.getSelectors();
|
56
|
-
}
|
57
|
-
/**
|
58
|
-
* Upserts the given composite products into state.
|
59
|
-
*/
|
60
|
-
upsertProducts(state, ...products) {
|
61
|
-
return this._adapter.upsertMany(this.mapOptionsEntities(products), state);
|
62
|
-
}
|
63
|
-
;
|
64
|
-
/**
|
65
|
-
* Apply the specified option for the given composite product item.
|
66
|
-
*/
|
67
|
-
applyOption(state, productId, itemId, optionId, qty) {
|
68
|
-
return this._adapter.upsertOne({
|
69
|
-
id: productId,
|
70
|
-
items: Object.assign(Object.assign({}, state.entities[productId].items), { [itemId]: {
|
71
|
-
value: optionId,
|
72
|
-
qty: qty !== null && qty !== void 0 ? qty : 1,
|
73
|
-
} }),
|
74
|
-
}, state);
|
75
|
-
}
|
76
|
-
/**
|
77
|
-
* @docs-private
|
78
|
-
*/
|
79
|
-
mapOptionsEntities(products) {
|
80
|
-
return products.filter(product => product.type === DaffProductTypeEnum.Composite)
|
81
|
-
.map(product => this.buildCompositeProductAppliedOptionsEntity(product));
|
82
|
-
}
|
83
|
-
/**
|
84
|
-
* @docs-private
|
85
|
-
*/
|
86
|
-
buildCompositeProductAppliedOptionsEntity(product) {
|
87
|
-
return {
|
88
|
-
id: product.id,
|
89
|
-
items: product.items.reduce((acc, item) => (Object.assign(Object.assign({}, acc), { [item.id]: this.getDefaultOption(item) })), {}),
|
90
|
-
};
|
91
|
-
}
|
92
|
-
/**
|
93
|
-
* Sets the default item option to the specified default option if it is in stock.
|
94
|
-
* Does not set a default option if a default is not specified.
|
95
|
-
* Does not set a default option but does set a default qty if the default is out of stock.
|
96
|
-
*
|
97
|
-
* @param item a DaffCompositeProductItem
|
98
|
-
* @docs-private
|
99
|
-
*/
|
100
|
-
getDefaultOption(item) {
|
101
|
-
const defaultOptionIndex = item.options.findIndex(option => option.is_default);
|
102
|
-
if (defaultOptionIndex > -1) {
|
103
|
-
return {
|
104
|
-
value: item.options[defaultOptionIndex].in_stock ? item.options[defaultOptionIndex].id : null,
|
105
|
-
qty: item.options[defaultOptionIndex].quantity,
|
106
|
-
};
|
107
|
-
}
|
108
|
-
else {
|
109
|
-
return { value: null, qty: null };
|
110
|
-
}
|
111
|
-
}
|
112
|
-
}
|
113
|
-
/**
|
114
|
-
* Gets the composite product entity adapter singleton.
|
115
|
-
*/
|
116
|
-
const daffCompositeProductAppliedOptionsEntitiesAdapter = defaultMemoize(() => new DaffCompositeProductAppliedOptionsEntitiesAdapter()).memoized;
|
117
|
-
|
118
|
-
const DAFF_COMPOSITE_PRODUCT_STORE_FEATURE_KEY = 'daffCompositeProduct';
|
119
|
-
|
120
|
-
/**
|
121
|
-
* A function that returns a selector for the composite product feature state.
|
122
|
-
*/
|
123
|
-
const getDaffCompositeProductFeatureSelector = (() => {
|
124
|
-
let cache;
|
125
|
-
return () => cache = cache
|
126
|
-
? cache
|
127
|
-
: { selectCompositeProductState: createFeatureSelector(DAFF_COMPOSITE_PRODUCT_STORE_FEATURE_KEY) };
|
128
|
-
})();
|
129
|
-
|
130
|
-
const createCompositeProductAppliedOptionsEntitiesSelectors = () => {
|
131
|
-
const { selectCompositeProductState, } = getDaffCompositeProductFeatureSelector();
|
132
|
-
const { selectProduct, } = getDaffProductEntitiesSelectors();
|
133
|
-
const adapterSelectors = daffCompositeProductAppliedOptionsEntitiesAdapter().getSelectors();
|
134
|
-
const selectCompositeProductAppliedOptionsEntitiesState = createSelector(selectCompositeProductState, (state) => state.compositeProductOptions);
|
135
|
-
const selectCompositeProductIds = createSelector(selectCompositeProductAppliedOptionsEntitiesState, adapterSelectors.selectIds);
|
136
|
-
const selectCompositeProductAppliedOptionsEntities = createSelector(selectCompositeProductAppliedOptionsEntitiesState, adapterSelectors.selectEntities);
|
137
|
-
const selectCompositeProductTotal = createSelector(selectCompositeProductAppliedOptionsEntitiesState, adapterSelectors.selectTotal);
|
138
|
-
const selectCompositeProductAppliedOptions = defaultMemoize((id) => createSelector(selectProduct(id), selectCompositeProductAppliedOptionsEntitiesState, (product, appliedOptions) => {
|
139
|
-
if (product.type !== DaffProductTypeEnum.Composite) {
|
140
|
-
return undefined;
|
141
|
-
}
|
142
|
-
return product.items.reduce((acc, item) => (Object.assign(Object.assign({}, acc), { [item.id]: appliedOptions.entities[product.id].items[item.id].value ? Object.assign(Object.assign({}, item.options.find(option => option.id === appliedOptions.entities[product.id].items[item.id].value)), { quantity: appliedOptions.entities[product.id].items[item.id].qty }) : null })), {});
|
143
|
-
})).memoized;
|
144
|
-
const selectIsCompositeProductItemRequired = defaultMemoize((id, item_id) => createSelector(selectProduct(id), (product) => {
|
145
|
-
if (product.type !== DaffProductTypeEnum.Composite) {
|
146
|
-
return undefined;
|
147
|
-
}
|
148
|
-
const productItem = product.items.find(item => item.id === item_id);
|
149
|
-
return productItem ? productItem.required : null;
|
150
|
-
})).memoized;
|
151
|
-
return {
|
152
|
-
selectCompositeProductAppliedOptionsEntitiesState,
|
153
|
-
selectCompositeProductIds,
|
154
|
-
selectCompositeProductAppliedOptionsEntities,
|
155
|
-
selectCompositeProductTotal,
|
156
|
-
selectCompositeProductAppliedOptions,
|
157
|
-
selectIsCompositeProductItemRequired,
|
158
|
-
};
|
159
|
-
};
|
160
|
-
/**
|
161
|
-
* A function that returns all selectors related to composite product applied option entities.
|
162
|
-
* Returns {@link DaffCompositeProductEntitiesMemoizedSelectors}.
|
163
|
-
*/
|
164
|
-
const getDaffCompositeProductEntitiesSelectors = (() => {
|
165
|
-
let cache;
|
166
|
-
return () => cache = cache
|
167
|
-
? cache
|
168
|
-
: createCompositeProductAppliedOptionsEntitiesSelectors();
|
169
|
-
})();
|
170
|
-
|
171
|
-
const createCompositeProductSelectors = () => {
|
172
|
-
const { selectProduct, } = getDaffProductEntitiesSelectors();
|
173
|
-
const { selectCompositeProductAppliedOptionsEntities, } = getDaffCompositeProductEntitiesSelectors();
|
174
|
-
const selectCompositeProductRequiredItemPricesForConfiguration = defaultMemoize((id, configuration) => createSelector(selectProduct(id), (product) => {
|
175
|
-
if (product.type !== DaffProductTypeEnum.Composite) {
|
176
|
-
return undefined;
|
177
|
-
}
|
178
|
-
const appliedOptions = configuration ? getAppliedOptionsForConfiguration(product, configuration) : {};
|
179
|
-
return {
|
180
|
-
minPrice: getMinPricesForConfiguration(product, appliedOptions),
|
181
|
-
maxPrice: getMaxPricesForConfiguration(product, appliedOptions),
|
182
|
-
};
|
183
|
-
})).memoized;
|
184
|
-
const selectCompositeProductOptionalItemPricesForConfiguration = defaultMemoize((id, configuration) => createSelector(selectProduct(id), (product) => {
|
185
|
-
if (product.type !== DaffProductTypeEnum.Composite) {
|
186
|
-
return undefined;
|
187
|
-
}
|
188
|
-
const appliedOptions = configuration ? getAppliedOptionsForConfiguration(product, configuration) : {};
|
189
|
-
return {
|
190
|
-
minPrice: getMinPricesForConfiguration(product, appliedOptions),
|
191
|
-
maxPrice: getMaxPricesForConfigurationIncludingOptionalItems(product, appliedOptions),
|
192
|
-
};
|
193
|
-
})).memoized;
|
194
|
-
const selectCompositeProductPricesAsCurrentlyConfigured = defaultMemoize((id) => createSelector(selectProduct(id), selectCompositeProductAppliedOptionsEntities, (product, appliedOptionsEntities) => { var _a; return selectCompositeProductRequiredItemPricesForConfiguration(id, ((_a = appliedOptionsEntities[id]) === null || _a === void 0 ? void 0 : _a.items) || null).projector(product); })).memoized;
|
195
|
-
const selectCompositeProductDiscountAmount = defaultMemoize((id) => createSelector(selectProduct(id), selectCompositeProductAppliedOptionsEntities, (product, appliedOptionsEntities) => {
|
196
|
-
if (product.type !== DaffProductTypeEnum.Composite) {
|
197
|
-
return undefined;
|
198
|
-
}
|
199
|
-
const appliedConfigurationItem = appliedOptionsEntities[product.id].items;
|
200
|
-
if (product.items.filter(item => item.required && appliedConfigurationItem[item.id].value === null).length > 0) {
|
201
|
-
return undefined;
|
202
|
-
}
|
203
|
-
const appliedOptions = getAppliedOptionsForConfiguration(product, appliedConfigurationItem);
|
204
|
-
return product.items.reduce((acc, item) => { var _a, _b; return ((_b = (_a = appliedOptions[item.id]) === null || _a === void 0 ? void 0 : _a.discount) === null || _b === void 0 ? void 0 : _b.amount) ? daffAdd(acc, daffMultiply(appliedOptions[item.id].discount.amount, appliedOptions[item.id].quantity)) : acc; }, product.discount.amount);
|
205
|
-
})).memoized;
|
206
|
-
const selectCompositeProductDiscountPercent = defaultMemoize((id) => createSelector(selectProduct(id), selectCompositeProductAppliedOptionsEntities, (product, appliedOptionsEntities) => {
|
207
|
-
if (product.type !== DaffProductTypeEnum.Composite) {
|
208
|
-
return undefined;
|
209
|
-
}
|
210
|
-
const appliedOptions = appliedOptionsEntities[product.id].items;
|
211
|
-
if (product.items.filter(item => item.required && appliedOptions[item.id].value === null).length > 0) {
|
212
|
-
return undefined;
|
213
|
-
}
|
214
|
-
const prices = getMinPricesForConfiguration(product, getAppliedOptionsForConfiguration(product, appliedOptions));
|
215
|
-
return daffMultiply(daffDivide(daffSubtract(prices.originalPrice, prices.discountedPrice), prices.originalPrice), 100);
|
216
|
-
})).memoized;
|
217
|
-
return {
|
218
|
-
selectCompositeProductRequiredItemPricesForConfiguration,
|
219
|
-
selectCompositeProductOptionalItemPricesForConfiguration,
|
220
|
-
selectCompositeProductPricesAsCurrentlyConfigured,
|
221
|
-
selectCompositeProductDiscountAmount,
|
222
|
-
selectCompositeProductDiscountPercent,
|
223
|
-
};
|
224
|
-
};
|
225
|
-
/**
|
226
|
-
* A function that returns all selectors related to the composite product feature.
|
227
|
-
*
|
228
|
-
* Returns {@link DaffCompositeProductMemoizedSelectors}.
|
229
|
-
*/
|
230
|
-
const getDaffCompositeProductPriceSelectors = (() => {
|
231
|
-
let cache;
|
232
|
-
return () => cache = cache
|
233
|
-
? cache
|
234
|
-
: createCompositeProductSelectors();
|
235
|
-
})();
|
236
|
-
/**
|
237
|
-
* The minimum price of an item is zero if the item is optional.
|
238
|
-
*
|
239
|
-
* @param item DaffCompositeProductItem
|
240
|
-
*/
|
241
|
-
function getMinimumRequiredCompositeItemPrice(item, qty) {
|
242
|
-
return item.required ? daffMultiply(Math.min(...item.options.map(option => option.price)), qty) : 0;
|
243
|
-
}
|
244
|
-
/**
|
245
|
-
* The maximum price for an item is zero if the item is optional.
|
246
|
-
*
|
247
|
-
* @param item DaffCompositeProductItem
|
248
|
-
*/
|
249
|
-
function getMaximumRequiredCompositeItemPrice(item, qty) {
|
250
|
-
return item.required ? daffMultiply(Math.max(...item.options.map(option => option.price)), qty) : 0;
|
251
|
-
}
|
252
|
-
/**
|
253
|
-
* The minimum discounted price of an item is zero if the item is optional.
|
254
|
-
*
|
255
|
-
* @param item DaffCompositeProductItem
|
256
|
-
*/
|
257
|
-
function getMinimumRequiredCompositeItemDiscountedPrice(item, qty) {
|
258
|
-
return item.required ? daffMultiply(Math.min(...item.options.map(getDiscountedPrice)), qty) : 0;
|
259
|
-
}
|
260
|
-
/**
|
261
|
-
* The maximum discounted price of an item is zero if the item is optional.
|
262
|
-
*
|
263
|
-
* @param item DaffCompositeProductItem
|
264
|
-
*/
|
265
|
-
function getMaximumRequiredCompositeItemDiscountedPrice(item, qty) {
|
266
|
-
return item.required ? daffMultiply(Math.max(...item.options.map(getDiscountedPrice)), qty) : 0;
|
267
|
-
}
|
268
|
-
/**
|
269
|
-
* Gets the minimum prices of a composite product for the configuration provided excluding unselected, optional item prices.
|
270
|
-
*
|
271
|
-
* @param product a DaffCompositeProduct
|
272
|
-
* @param appliedOptions a Dictionary<DaffCompositeProductItemOption> that determines the current configuration of the composite product.
|
273
|
-
*/
|
274
|
-
function getMinPricesForConfiguration(product, appliedOptions) {
|
275
|
-
return {
|
276
|
-
discountedPrice: product.items.reduce((acc, item) => daffAdd(acc, appliedOptionHasId(appliedOptions[item.id]) ?
|
277
|
-
daffMultiply(getDiscountedPrice(appliedOptions[item.id]), appliedOptions[item.id].quantity) :
|
278
|
-
getMinimumRequiredCompositeItemDiscountedPrice(item, getOptionQty(appliedOptions[item.id]))), getDiscountedPrice(product)),
|
279
|
-
discount: { amount: null, percent: null },
|
280
|
-
originalPrice: product.items.reduce((acc, item) => daffAdd(acc, appliedOptionHasId(appliedOptions[item.id]) ?
|
281
|
-
daffMultiply(appliedOptions[item.id].price, appliedOptions[item.id].quantity) :
|
282
|
-
getMinimumRequiredCompositeItemPrice(item, getOptionQty(appliedOptions[item.id]))), product.price),
|
283
|
-
};
|
284
|
-
}
|
285
|
-
/**
|
286
|
-
* Gets the maximum prices of a composite product for the configuration provided excluding unselected, optional item prices.
|
287
|
-
*
|
288
|
-
* @param product a DaffCompositeProduct
|
289
|
-
* @param appliedOptions a Dictionary<DaffCompositeProductItemOption> that determines the current configuration of the composite product.
|
290
|
-
*/
|
291
|
-
function getMaxPricesForConfiguration(product, appliedOptions) {
|
292
|
-
return {
|
293
|
-
discountedPrice: product.items.reduce((acc, item) => daffAdd(acc, appliedOptionHasId(appliedOptions[item.id]) ?
|
294
|
-
daffMultiply(getDiscountedPrice(appliedOptions[item.id]), appliedOptions[item.id].quantity) :
|
295
|
-
getMaximumRequiredCompositeItemDiscountedPrice(item, getOptionQty(appliedOptions[item.id]))), getDiscountedPrice(product)),
|
296
|
-
discount: { amount: null, percent: null },
|
297
|
-
originalPrice: product.items.reduce((acc, item) => daffAdd(acc, appliedOptionHasId(appliedOptions[item.id]) ?
|
298
|
-
daffMultiply(appliedOptions[item.id].price, appliedOptions[item.id].quantity) :
|
299
|
-
getMaximumRequiredCompositeItemPrice(item, getOptionQty(appliedOptions[item.id]))), product.price),
|
300
|
-
};
|
301
|
-
}
|
302
|
-
function getDiscountedPrice(product) {
|
303
|
-
return product.discount ? daffSubtract(product.price, product.discount.amount) : product.price;
|
304
|
-
}
|
305
|
-
/**
|
306
|
-
* Gets the maximum prices of a composite product including optional item prices.
|
307
|
-
*
|
308
|
-
* @param product a DaffCompositeProduct
|
309
|
-
*/
|
310
|
-
function getMaxPricesForConfigurationIncludingOptionalItems(product, appliedOptions) {
|
311
|
-
return {
|
312
|
-
discountedPrice: product.items.reduce((acc, item) => daffAdd(acc, appliedOptionHasId(appliedOptions[item.id]) ?
|
313
|
-
daffMultiply(getDiscountedPrice(appliedOptions[item.id]), appliedOptions[item.id].quantity) :
|
314
|
-
appliedOptionHasQty(appliedOptions[item.id]) ?
|
315
|
-
daffMultiply(Math.max(...item.options.map(getDiscountedPrice)), appliedOptions[item.id].quantity) :
|
316
|
-
Math.max(...item.options.map(getDiscountedPrice))), getDiscountedPrice(product)),
|
317
|
-
discount: { amount: null, percent: null },
|
318
|
-
originalPrice: product.items.reduce((acc, item) => daffAdd(acc, appliedOptionHasId(appliedOptions[item.id]) ?
|
319
|
-
daffMultiply(appliedOptions[item.id].price, appliedOptions[item.id].quantity) :
|
320
|
-
appliedOptionHasQty(appliedOptions[item.id]) ?
|
321
|
-
daffMultiply(Math.max(...item.options.map(option => option.price)), appliedOptions[item.id].quantity) :
|
322
|
-
Math.max(...item.options.map(option => option.price))), product.price),
|
323
|
-
};
|
324
|
-
}
|
325
|
-
/**
|
326
|
-
* Takes a product and a set of option configurations and convert it into a dictionary of the full option objects.
|
327
|
-
*
|
328
|
-
* @param product a DaffCompositeProduct
|
329
|
-
* @param configuration a Dictionary<DaffCompositeConfigurationItem> used to build the appliedOptions object.
|
330
|
-
*/
|
331
|
-
function getAppliedOptionsForConfiguration(product, configuration) {
|
332
|
-
return product.items.reduce((acc, item) => (Object.assign(Object.assign({}, acc), { [item.id]: configuration[item.id] ? Object.assign(Object.assign({}, item.options.find(option => option.id === configuration[item.id].value)), { quantity: (configuration[item.id].qty === null || configuration[item.id].qty === undefined) ? 1 : configuration[item.id].qty }) : null })), {});
|
333
|
-
}
|
334
|
-
function appliedOptionHasId(appliedOption) {
|
335
|
-
return !!(appliedOption === null || appliedOption === void 0 ? void 0 : appliedOption.id);
|
336
|
-
}
|
337
|
-
function getOptionQty(appliedOption) {
|
338
|
-
return appliedOptionHasQty(appliedOption) ? appliedOption.quantity : 1;
|
339
|
-
}
|
340
|
-
function appliedOptionHasQty(appliedOption) {
|
341
|
-
return (appliedOption === null || appliedOption === void 0 ? void 0 : appliedOption.quantity) !== null && (appliedOption === null || appliedOption === void 0 ? void 0 : appliedOption.quantity) !== undefined;
|
342
|
-
}
|
343
|
-
|
344
|
-
/**
|
345
|
-
* A function that returns all selectors in the composite product feature area.
|
346
|
-
* Returns {@link DaffCompositeProductAllSelectors}.
|
347
|
-
*/
|
348
|
-
const getDaffCompositeProductSelectors = () => (Object.assign(Object.assign({}, getDaffCompositeProductEntitiesSelectors()), getDaffCompositeProductPriceSelectors()));
|
349
|
-
|
350
|
-
/**
|
351
|
-
* A facade for interacting with the composite product state.
|
352
|
-
* Exposes many parts of the state for easy access and allows dispatching of actions.
|
353
|
-
*
|
354
|
-
* @inheritdoc
|
355
|
-
*/
|
356
|
-
class DaffCompositeProductFacade {
|
357
|
-
constructor(store) {
|
358
|
-
this.store = store;
|
359
|
-
this.compositeProductSelectors = getDaffCompositeProductSelectors();
|
360
|
-
this.hasDiscount = productPriceRangeHasDiscount;
|
361
|
-
this.hasPriceRange = productPriceRangeHasPriceRange;
|
362
|
-
}
|
363
|
-
getRequiredItemPricesForConfiguration(id, configuration) {
|
364
|
-
return this.store.pipe(select(this.compositeProductSelectors.selectCompositeProductRequiredItemPricesForConfiguration(id, configuration)));
|
365
|
-
}
|
366
|
-
getOptionalItemPricesForConfiguration(id, configuration) {
|
367
|
-
return this.store.pipe(select(this.compositeProductSelectors.selectCompositeProductOptionalItemPricesForConfiguration(id, configuration)));
|
368
|
-
}
|
369
|
-
getPricesAsCurrentlyConfigured(id) {
|
370
|
-
return this.store.pipe(select(this.compositeProductSelectors.selectCompositeProductPricesAsCurrentlyConfigured(id)));
|
371
|
-
}
|
372
|
-
getAppliedOptions(id) {
|
373
|
-
return this.store.pipe(select(this.compositeProductSelectors.selectCompositeProductAppliedOptions(id)));
|
374
|
-
}
|
375
|
-
getDiscountAmount(id) {
|
376
|
-
return this.store.pipe(select(this.compositeProductSelectors.selectCompositeProductDiscountAmount(id)));
|
377
|
-
}
|
378
|
-
getDiscountPercent(id) {
|
379
|
-
return this.store.pipe(select(this.compositeProductSelectors.selectCompositeProductDiscountPercent(id)));
|
380
|
-
}
|
381
|
-
isItemRequired(id, item_id) {
|
382
|
-
return this.store.pipe(select(this.compositeProductSelectors.selectIsCompositeProductItemRequired(id, item_id)));
|
383
|
-
}
|
384
|
-
dispatch(action) {
|
385
|
-
this.store.dispatch(action);
|
386
|
-
}
|
387
|
-
}
|
388
|
-
/** @nocollapse */ DaffCompositeProductFacade.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: DaffCompositeProductFacade, deps: [{ token: i1.Store }], target: i0.ɵɵFactoryTarget.Injectable });
|
389
|
-
/** @nocollapse */ DaffCompositeProductFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: DaffCompositeProductFacade, providedIn: 'root' });
|
390
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: DaffCompositeProductFacade, decorators: [{
|
391
|
-
type: Injectable,
|
392
|
-
args: [{
|
393
|
-
providedIn: 'root',
|
394
|
-
}]
|
395
|
-
}], ctorParameters: function () { return [{ type: i1.Store }]; } });
|
396
|
-
|
397
|
-
/**
|
398
|
-
* Reducer function that catches actions and changes/overwrites composite product entities state.
|
399
|
-
*
|
400
|
-
* @param state current State of the redux store
|
401
|
-
* @param action ProductGrid, BestSellers, Product, or Composite Product actions
|
402
|
-
* @returns Product entities state
|
403
|
-
*/
|
404
|
-
function daffCompositeProductEntitiesReducer(state = daffCompositeProductAppliedOptionsEntitiesAdapter().getInitialState(), action) {
|
405
|
-
const adapter = daffCompositeProductAppliedOptionsEntitiesAdapter();
|
406
|
-
switch (action.type) {
|
407
|
-
case DaffProductGridActionTypes.ProductGridLoadSuccessAction:
|
408
|
-
case DaffBestSellersActionTypes.BestSellersLoadSuccessAction:
|
409
|
-
return adapter.upsertProducts(state, ...action.payload);
|
410
|
-
case DaffProductActionTypes.ProductLoadSuccessAction:
|
411
|
-
case DaffProductPageActionTypes.ProductPageLoadSuccessAction:
|
412
|
-
return adapter.upsertProducts(state, ...action.payload.products);
|
413
|
-
case DaffCompositeProductActionTypes.CompositeProductApplyOptionAction:
|
414
|
-
return adapter.applyOption(state, action.id, action.itemId, action.optionId, action.qty);
|
415
|
-
default:
|
416
|
-
return state;
|
417
|
-
}
|
418
|
-
}
|
419
|
-
|
420
|
-
/**
|
421
|
-
* Returns state values from all composite product related reducers.
|
422
|
-
*/
|
423
|
-
const daffCompositeProductReducers = {
|
424
|
-
compositeProductOptions: daffCompositeProductEntitiesReducer,
|
425
|
-
};
|
426
|
-
|
427
|
-
/**
|
428
|
-
* A token to hold the injectable extra reducers.
|
429
|
-
*
|
430
|
-
* Prefer using {@link daffProductCompositeProvideExtraReducers}.
|
431
|
-
*/
|
432
|
-
const DAFF_PRODUCT_COMPOSITE_EXTRA_REDUCERS = new InjectionToken('DAFF_PRODUCT_COMPOSITE_EXTRA_REDUCERS', { factory: () => [] });
|
433
|
-
/**
|
434
|
-
* Provides additional reducers that run after the standard Daffodil cart reducers.
|
435
|
-
*
|
436
|
-
* ```ts
|
437
|
-
* providers: [
|
438
|
-
* ...daffProductCompositeProvideExtraReducers(
|
439
|
-
* myReducer1,
|
440
|
-
* myReducer2
|
441
|
-
* )
|
442
|
-
* ]
|
443
|
-
* ```
|
444
|
-
*/
|
445
|
-
function daffProductCompositeProvideExtraReducers(...reducers) {
|
446
|
-
return reducers.map(reducer => ({
|
447
|
-
provide: DAFF_PRODUCT_COMPOSITE_EXTRA_REDUCERS,
|
448
|
-
useValue: reducer,
|
449
|
-
multi: true,
|
450
|
-
}));
|
451
|
-
}
|
452
|
-
|
453
|
-
/**
|
454
|
-
* Maps a list of products, ensuring that the composite products have a list of items.
|
455
|
-
* If the incoming items is empty or nully, the items from state are intentionally used instead.
|
456
|
-
*/
|
457
|
-
function daffProductCompositeEnsureItems(state, products) {
|
458
|
-
return products.map((product) => {
|
459
|
-
var _a, _b;
|
460
|
-
return product.type === DaffProductTypeEnum.Composite
|
461
|
-
? Object.assign(Object.assign({}, product), { items: product.items.length > 0
|
462
|
-
? product.items
|
463
|
-
: (_b = (_a = state.products.entities[product.id]) === null || _a === void 0 ? void 0 : _a.items) !== null && _b !== void 0 ? _b : [] }) : product;
|
464
|
-
});
|
465
|
-
}
|
466
|
-
|
467
|
-
function daffProductCompositeEnsureItemsMetaReducer(reducer) {
|
468
|
-
return (state, action) => {
|
469
|
-
switch (action.type) {
|
470
|
-
case DaffProductPageActionTypes.ProductPageLoadSuccessAction:
|
471
|
-
return reducer(state, new DaffProductPageLoadSuccess(Object.assign(Object.assign({}, action.payload), { products: daffProductCompositeEnsureItems(state, action.payload.products) })));
|
472
|
-
case DaffProductActionTypes.ProductLoadSuccessAction:
|
473
|
-
return reducer(state, new DaffProductLoadSuccess(Object.assign(Object.assign({}, action.payload), { products: daffProductCompositeEnsureItems(state, action.payload.products) })));
|
474
|
-
default:
|
475
|
-
return reducer(state, action);
|
476
|
-
}
|
477
|
-
};
|
478
|
-
}
|
479
|
-
|
480
|
-
/**
|
481
|
-
* An internal token to hold the Daffodil composite product reducers.
|
482
|
-
* Includes the extra and standard reducers.
|
483
|
-
*
|
484
|
-
* @docs-private
|
485
|
-
*/
|
486
|
-
const DAFF_PRODUCT_COMPOSITE_REDUCERS = new InjectionToken('DAFF_PRODUCT_COMPOSITE_REDUCERS', {
|
487
|
-
factory: () => daffComposeReducers([
|
488
|
-
combineReducers(daffCompositeProductReducers),
|
489
|
-
...inject(DAFF_PRODUCT_COMPOSITE_EXTRA_REDUCERS),
|
490
|
-
]),
|
491
|
-
});
|
492
|
-
|
493
|
-
/**
|
494
|
-
* A module that provides the default reducers and effects for composite product redux state.
|
495
|
-
*/
|
496
|
-
class DaffCompositeProductStateModule {
|
497
|
-
}
|
498
|
-
/** @nocollapse */ DaffCompositeProductStateModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: DaffCompositeProductStateModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
499
|
-
/** @nocollapse */ DaffCompositeProductStateModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: DaffCompositeProductStateModule, imports: [i1.StoreFeatureModule] });
|
500
|
-
/** @nocollapse */ DaffCompositeProductStateModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: DaffCompositeProductStateModule, providers: [
|
501
|
-
...daffProductProvideMetaReducers(daffProductCompositeEnsureItemsMetaReducer),
|
502
|
-
], imports: [StoreModule.forFeature(DAFF_COMPOSITE_PRODUCT_STORE_FEATURE_KEY, DAFF_PRODUCT_COMPOSITE_REDUCERS)] });
|
503
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: DaffCompositeProductStateModule, decorators: [{
|
504
|
-
type: NgModule,
|
505
|
-
args: [{
|
506
|
-
imports: [
|
507
|
-
StoreModule.forFeature(DAFF_COMPOSITE_PRODUCT_STORE_FEATURE_KEY, DAFF_PRODUCT_COMPOSITE_REDUCERS),
|
508
|
-
],
|
509
|
-
providers: [
|
510
|
-
...daffProductProvideMetaReducers(daffProductCompositeEnsureItemsMetaReducer),
|
511
|
-
],
|
512
|
-
}]
|
513
|
-
}] });
|
514
|
-
|
515
|
-
/**
|
516
|
-
* Generated bundle index. Do not edit.
|
517
|
-
*/
|
518
|
-
|
519
|
-
export { DAFF_COMPOSITE_PRODUCT_STORE_FEATURE_KEY, DAFF_PRODUCT_COMPOSITE_EXTRA_REDUCERS, DaffCompositeProductActionTypes, DaffCompositeProductAppliedOptionsEntitiesAdapter, DaffCompositeProductApplyOption, DaffCompositeProductFacade, DaffCompositeProductStateModule, daffCompositeProductAppliedOptionsEntitiesAdapter, daffCompositeProductReducers, daffProductCompositeEnsureItems, daffProductCompositeProvideExtraReducers, getDaffCompositeProductEntitiesSelectors, getDaffCompositeProductFeatureSelector, getDaffCompositeProductPriceSelectors, getDaffCompositeProductSelectors };
|
520
|
-
//# sourceMappingURL=daffodil-product-composite-state.mjs.map
|