GitHub

DaffCompositeProductFacade

import { DaffCompositeProductFacade } from '@daffodil/product-composite/state'

A facade for interacting with the composite product state. Exposes many parts of the state for easy access and allows dispatching of actions.

@Injectable()
class DaffCompositeProductFacade<<T extends DaffProduct = DaffProduct>>  implements DaffCompositeProductFacadeInterface {
  compositeProductSelectors: DaffCompositeProductAllSelectors<T> = getDaffCompositeProductSelectors<T>()
  hasDiscount: (priceRange: DaffPriceRange) => boolean = productPriceRangeHasDiscount
  hasPriceRange: (priceRange: DaffPriceRange) => boolean = productPriceRangeHasPriceRange

  getRequiredItemPricesForConfiguration(
    id: T["id"]
    configuration?: Dictionary<DaffCompositeConfigurationItem>
  ): Observable<DaffPriceRange>
  getOptionalItemPricesForConfiguration(
    id: T["id"]
    configuration?: Dictionary<DaffCompositeConfigurationItem>
  ): Observable<DaffPriceRange>
  getPricesAsCurrentlyConfigured(id: T["id"]): Observable<DaffPriceRange>
  getAppliedOptions(id: T["id"]): Observable<Dictionary<DaffCompositeProductItemOption>>
  getDiscountAmount(id: T["id"]): Observable<number>
  getDiscountPercent(id: T["id"]): Observable<number>
  isItemRequired(
    id: T["id"]
    item_id: string
  ): any
  dispatch(action: Action<string>): void
}

Properties

compositeProductSelectors
DaffCompositeProductAllSelectors<T>
DefaultgetDaffCompositeProductSelectors<T>()
Description
hasDiscount
(priceRange: DaffPriceRange) => boolean
DefaultproductPriceRangeHasDiscount
Description

Returns whether a DaffPriceRange has a discount.

hasPriceRange
(priceRange: DaffPriceRange) => boolean
DefaultproductPriceRangeHasPriceRange
Description

Returns whether the min and max prices of a DaffPriceRange are different.

() Methods

getRequiredItemPricesForConfiguration
Observable<DaffPriceRange>

Get a DaffPriceRange for a composite product based on the configuration provided excluding unselected, optional item prices.

Parameters
Parameterid: T["id"]
Description
Parameterconfiguration: Dictionary<DaffCompositeConfigurationItem>
Description
getOptionalItemPricesForConfiguration
Observable<DaffPriceRange>

Get the broadest possible DaffPriceRange for a composite product based on the configuration provided including optional item prices.

Parameters
Parameterid: T["id"]
Description
Parameterconfiguration: Dictionary<DaffCompositeConfigurationItem>
Description
getPricesAsCurrentlyConfigured
Observable<DaffPriceRange>

Get the DaffPriceRange for a composite product based on the current configuration of selected item options in redux state and excluding unselected, optional item prices.

Parameters
Parameterid: T["id"]
Description
getAppliedOptions
Observable<Dictionary<DaffCompositeProductItemOption>>

Returns the applied options for a composite product.

Parameters
Parameterid: T["id"]
Description
getDiscountAmount
Observable<number>

Returns the discount amount of a composite product based on the current configuration of the selected item options in redux state and excluding unselected, optional item prices. Will return undefined if all required options are not chosen.

Parameters
Parameterid: T["id"]
Description
getDiscountPercent
Observable<number>

Returns the discount percent of a composite product based on the current configuration of the selected item options in redux state and excluding unselected, optional item prices. Will return undefined if all required options are not chosen. Note: This percent is computed client-side and should be treated as an estimate rather than an exact value.

Parameters
Parameterid: T["id"]
Description
isItemRequired
any

Returns whether the item of a composite product is required.

Parameters
Parameterid: T["id"]
Description
Parameteritem_id: string
Description
dispatch
void
Parameters
Parameteraction: Action
Description