diff --git a/src/app/core/models/basket-feedback/basket-feedback.model.ts b/src/app/core/models/basket-feedback/basket-feedback.model.ts index efbcbda7d5f..bf033f375f6 100644 --- a/src/app/core/models/basket-feedback/basket-feedback.model.ts +++ b/src/app/core/models/basket-feedback/basket-feedback.model.ts @@ -1,5 +1,5 @@ import { LineItem } from 'ish-core/models/line-item/line-item.model'; -import { Product } from 'ish-core/models/product/product.model'; +import { ProductView } from 'ish-core/models/product-view/product-view.model'; export interface BasketFeedback { code: string; @@ -13,6 +13,6 @@ export interface BasketFeedback { } export interface BasketFeedbackView extends BasketFeedback { - product?: Product; + product?: ProductView; lineItem?: LineItem; } diff --git a/src/app/core/models/basket/basket.model.ts b/src/app/core/models/basket/basket.model.ts index 790900611fd..e83cb018379 100644 --- a/src/app/core/models/basket/basket.model.ts +++ b/src/app/core/models/basket/basket.model.ts @@ -7,6 +7,7 @@ import { BasketTotal } from 'ish-core/models/basket-total/basket-total.model'; import { BasketValidationResultType } from 'ish-core/models/basket-validation/basket-validation.model'; import { LineItem, LineItemView } from 'ish-core/models/line-item/line-item.model'; import { Payment } from 'ish-core/models/payment/payment.model'; +import { createProductView } from 'ish-core/models/product-view/product-view.model'; import { VariationProductMaster } from 'ish-core/models/product/product-variation-master.model'; import { VariationProduct } from 'ish-core/models/product/product-variation.model'; import { Product } from 'ish-core/models/product/product.model'; @@ -33,7 +34,7 @@ export interface Basket extends AbstractBasket {} export interface BasketView extends AbstractBasket {} export const createBasketView = memoize( - (basket, products, validationResults, basketInfo): BasketView => { + (basket, products, validationResults, basketInfo, categoryTree): BasketView => { if (!basket) { return; } @@ -43,7 +44,7 @@ export const createBasketView = memoize( lineItems: basket.lineItems ? basket.lineItems.map(li => ({ ...li, - product: products[li.productSKU], + product: createProductView(products[li.productSKU], categoryTree), name: products && products[li.productSKU] ? products[li.productSKU].name : undefined, inStock: products && products[li.productSKU] ? products[li.productSKU].inStock : undefined, availability: products && products[li.productSKU] ? products[li.productSKU].availability : undefined, diff --git a/src/app/core/models/line-item/line-item.model.ts b/src/app/core/models/line-item/line-item.model.ts index 63478430723..297761c6ff8 100644 --- a/src/app/core/models/line-item/line-item.model.ts +++ b/src/app/core/models/line-item/line-item.model.ts @@ -1,7 +1,7 @@ import { BasketFeedback } from 'ish-core/models/basket-feedback/basket-feedback.model'; import { BasketRebate } from 'ish-core/models/basket-rebate/basket-rebate.model'; import { Price } from 'ish-core/models/price/price.model'; -import { Product } from 'ish-core/models/product/product.model'; +import { ProductView } from 'ish-core/models/product-view/product-view.model'; export interface LineItem { id: string; @@ -45,7 +45,7 @@ export interface LineItem { } export interface LineItemView extends LineItem { - product: Product; + product: ProductView; validationError?: BasketFeedback; info?: BasketFeedback; } diff --git a/src/app/core/models/order/order.model.ts b/src/app/core/models/order/order.model.ts index c7e011d92bd..0f4e7b302b3 100644 --- a/src/app/core/models/order/order.model.ts +++ b/src/app/core/models/order/order.model.ts @@ -2,6 +2,7 @@ import { Dictionary } from '@ngrx/entity'; import { memoize } from 'lodash-es'; import { Basket, BasketView } from 'ish-core/models/basket/basket.model'; +import { createProductView } from 'ish-core/models/product-view/product-view.model'; import { VariationProductMaster } from 'ish-core/models/product/product-variation-master.model'; import { VariationProduct } from 'ish-core/models/product/product-variation.model'; import { Product } from 'ish-core/models/product/product.model'; @@ -26,7 +27,7 @@ export interface Order extends Basket, AbstractOrder {} export interface OrderView extends BasketView, AbstractOrder {} export const createOrderView = memoize( - (order, products): OrderView => { + (order, products, categoryTree): OrderView => { if (!order) { return; } @@ -36,7 +37,7 @@ export const createOrderView = memoize( lineItems: order.lineItems ? order.lineItems.map(li => ({ ...li, - product: products ? products[li.productSKU] : undefined, + product: products ? createProductView(products[li.productSKU], categoryTree) : undefined, })) : [], }; diff --git a/src/app/core/store/checkout/basket/basket.selectors.ts b/src/app/core/store/checkout/basket/basket.selectors.ts index 4e7ded81923..8dd3f480633 100644 --- a/src/app/core/store/checkout/basket/basket.selectors.ts +++ b/src/app/core/store/checkout/basket/basket.selectors.ts @@ -4,7 +4,9 @@ import { isEqual } from 'lodash-es'; import { AddressHelper } from 'ish-core/models/address/address.helper'; import { BasketValidationResultType } from 'ish-core/models/basket-validation/basket-validation.model'; import { BasketView, createBasketView } from 'ish-core/models/basket/basket.model'; +import { createProductView } from 'ish-core/models/product-view/product-view.model'; import { getCheckoutState } from 'ish-core/store/checkout/checkout-store'; +import { getCategoryTree } from 'ish-core/store/shopping/categories'; import { getProductEntities } from 'ish-core/store/shopping/products'; import { getLoggedInCustomer } from 'ish-core/store/user'; @@ -16,7 +18,8 @@ const getBasketState = createSelector( export const getBasketValidationResults = createSelector( getBasketState, getProductEntities, - (basket, products): BasketValidationResultType => { + getCategoryTree, + (basket, products, categoryTree): BasketValidationResultType => { if (!basket || !basket.validationResults) { return; } @@ -27,7 +30,7 @@ export const getBasketValidationResults = createSelector( infos: basketResults.infos ? basketResults.infos.map(info => ({ ...info, - product: info.parameters && products[info.parameters.productSku], + product: info.parameters && createProductView(products[info.parameters.productSku], categoryTree), })) : [], errors: basketResults.errors @@ -41,7 +44,10 @@ export const getBasketValidationResults = createSelector( error.parameters && error.parameters.lineItemId && basket.basket.lineItems.find(item => item.id === error.parameters.lineItemId) && - products[basket.basket.lineItems.find(item => item.id === error.parameters.lineItemId).productSKU], + createProductView( + products[basket.basket.lineItems.find(item => item.id === error.parameters.lineItemId).productSKU], + categoryTree + ), })) : [], }; @@ -61,8 +67,9 @@ export const getCurrentBasket = createSelector( getProductEntities, getBasketValidationResults, getBasketInfo, - (basket, products, validationResults, basketInfo): BasketView => - createBasketView(basket.basket, products, validationResults, basketInfo) + getCategoryTree, + (basket, products, validationResults, basketInfo, categoryTree): BasketView => + createBasketView(basket.basket, products, validationResults, basketInfo, categoryTree) ); export const getCurrentBasketId = createSelector( diff --git a/src/app/core/store/orders/orders.selectors.spec.ts b/src/app/core/store/orders/orders.selectors.spec.ts index 5c9950b9f4f..5c6cb5630d8 100644 --- a/src/app/core/store/orders/orders.selectors.spec.ts +++ b/src/app/core/store/orders/orders.selectors.spec.ts @@ -107,7 +107,7 @@ describe('Orders Selectors', () => { expect(loadedOrders[1].documentNo).toEqual(orders[1].documentNo); expect(loadedOrders[1].lineItems).toHaveLength(1); expect(loadedOrders[1].lineItems[0].id).toEqual('test2'); - expect(loadedOrders[1].lineItems[0].product).toEqual({ sku: 'sku' }); + expect(loadedOrders[1].lineItems[0].product).toHaveProperty('sku', 'sku'); }); }); @@ -146,7 +146,7 @@ describe('Orders Selectors', () => { expect(loadedOrder.documentNo).toEqual(orders[0].documentNo); expect(loadedOrder.lineItems).toHaveLength(1); expect(loadedOrder.lineItems[0].id).toEqual('test'); - expect(loadedOrder.lineItems[0].product).toEqual({ sku: 'sku' }); + expect(loadedOrder.lineItems[0].product).toHaveProperty('sku', 'sku'); }); }); diff --git a/src/app/core/store/orders/orders.selectors.ts b/src/app/core/store/orders/orders.selectors.ts index f9297fbf10f..440fe3cbbca 100644 --- a/src/app/core/store/orders/orders.selectors.ts +++ b/src/app/core/store/orders/orders.selectors.ts @@ -2,6 +2,7 @@ import { createSelector } from '@ngrx/store'; import { OrderView, createOrderView } from 'ish-core/models/order/order.model'; import { getCoreState } from 'ish-core/store/core-store'; +import { getCategoryTree } from 'ish-core/store/shopping/categories'; import { getProductEntities } from 'ish-core/store/shopping/products'; import { orderAdapter } from './orders.reducer'; @@ -22,20 +23,25 @@ export const getSelectedOrder = createSelector( getOrderEntities, getSelectedOrderId, getProductEntities, - (entities, id, products): OrderView => (id && entities[id] ? createOrderView(entities[id], products) : undefined) + getCategoryTree, + (entities, id, products, categoryTree): OrderView => + id && entities[id] ? createOrderView(entities[id], products, categoryTree) : undefined ); export const getOrders = createSelector( getOrdersInternal, getProductEntities, - (orders, products): OrderView[] => (!orders ? [] : orders.map(e => createOrderView(e, products))) + getCategoryTree, + (orders, products, categoryTree): OrderView[] => + !orders ? [] : orders.map(e => createOrderView(e, products, categoryTree)) ); export const getOrder = createSelector( getOrdersInternal, getProductEntities, - (entities, products, props: { orderId: string }): OrderView => - createOrderView(entities.find(e => e.id === props.orderId), products) + getCategoryTree, + (entities, products, categoryTree, props: { orderId: string }): OrderView => + createOrderView(entities.find(e => e.id === props.orderId), products, categoryTree) ); export const getOrdersLoading = createSelector(