Skip to content

Commit

Permalink
fix: do not display "add to cart" button if product has no price (#1657)
Browse files Browse the repository at this point in the history
* handled via product context display properties
  • Loading branch information
shauke committed May 16, 2024
1 parent 0e4f96e commit 2732de4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
39 changes: 39 additions & 0 deletions src/app/core/facades/product-context.facade.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,45 @@ describe('Product Context Facade', () => {
`);
});
});

describe('add to basket handling', () => {
let product: ProductView;

beforeEach(() => {
product = {
sku: '123',
completenessLevel: ProductCompletenessLevel.Detail,
available: true,
} as ProductView;

when(shoppingFacade.product$(anything(), anything())).thenReturn(of(product));

context.set('sku', () => '123');
});

it('should set "addToBasket" to "false" for a product without a price', () => {
expect(context.get('displayProperties', 'addToBasket')).toMatchInlineSnapshot(`false`);
});

it('should set "addToBasket" to "true" for a product with price', () => {
context.set('prices', () => ({ salePrice: PriceHelper.empty() }));
expect(context.get('displayProperties', 'addToBasket')).toMatchInlineSnapshot(`true`);
});

it('should set "addToBasket" to "true" for a retail set independend from a price', () => {
when(shoppingFacade.product$(anything(), anything())).thenReturn(
of({
sku: '456',
completenessLevel: ProductCompletenessLevel.Detail,
type: 'RetailSet',
available: true,
} as ProductView)
);
context.set('sku', () => '456');

expect(context.get('displayProperties', 'addToBasket')).toMatchInlineSnapshot(`true`);
});
});
});

describe('Product Context Facade', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export class ProductContextDisplayPropertiesService implements ExternalDisplayPr
context$: Observable<Pick<ProductContext, 'product' | 'prices'>>
): Observable<Partial<ProductContextDisplayProperties<false>>> {
return context$.pipe(
map(({ product }) => {
map(({ product, prices }) => {
const canBeOrdered = !ProductHelper.isMasterProduct(product) && product?.available;

const canBeOrderedWithPrice = canBeOrdered && (!!prices?.salePrice || ProductHelper.isRetailSet(product));
const canBeOrderedNotRetail = canBeOrdered && !ProductHelper.isRetailSet(product);

const calc = {
Expand All @@ -30,7 +30,7 @@ export class ProductContextDisplayPropertiesService implements ExternalDisplayPr
canBeOrderedNotRetail &&
Number.isInteger(product?.readyForShipmentMin) &&
Number.isInteger(product?.readyForShipmentMax),
addToBasket: canBeOrdered,
addToBasket: canBeOrderedWithPrice,
addToWishlist: !ProductHelper.isMasterProduct(product),
addToOrderTemplate: canBeOrdered,
addToCompare: !ProductHelper.isMasterProduct(product),
Expand Down

0 comments on commit 2732de4

Please sign in to comment.