From ccda0b660347a0ab08003a21ab1628d1697968c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4hnlein?= Date: Fri, 7 Feb 2020 13:33:02 +0100 Subject: [PATCH] feat: localized product attributes #91 closes: #91 --- .../models/product/product.mapper.spec.ts | 20 +++++++++++++++++++ src/app/core/models/product/product.mapper.ts | 6 +++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/app/core/models/product/product.mapper.spec.ts b/src/app/core/models/product/product.mapper.spec.ts index 6cc4b16a52..2f34605104 100644 --- a/src/app/core/models/product/product.mapper.spec.ts +++ b/src/app/core/models/product/product.mapper.spec.ts @@ -114,6 +114,26 @@ describe('Product Mapper', () => { expect(product.type).toEqual('RetailSet'); expect(ProductHelper.isRetailSet(product)).toBeTrue(); }); + + it('should return attributes or detailed product attributes when PRODUCT_DETAIL_ATTRIBUTES enabled', () => { + const p1: Product = productMapper.fromData({ + sku: '1', + attributes: [{ name: 'Graphics', type: 'String', value: 'NVIDIA Quadro K2200' }], + } as ProductData); + const p2: Product = productMapper.fromData(({ + sku: '1', + attributes: [{ name: 'Graphics', type: 'String', value: 'NVIDIA Quadro K2200' }], + attributeGroups: { + PRODUCT_DETAIL_ATTRIBUTES: { + attributes: [{ name: 'Grafikkarte', type: 'String', value: 'NVIDIA Quadro K2200' }], + }, + }, + } as unknown) as ProductData); + expect(p1).toBeTruthy(); + expect(p1.attributes).toEqual([{ name: 'Graphics', type: 'String', value: 'NVIDIA Quadro K2200' }]); + expect(p2).toBeTruthy(); + expect(p2.attributes).toEqual([{ name: 'Grafikkarte', type: 'String', value: 'NVIDIA Quadro K2200' }]); + }); }); describe('fromStubData', () => { diff --git a/src/app/core/models/product/product.mapper.ts b/src/app/core/models/product/product.mapper.ts index e12cd64842..57dd587aa1 100644 --- a/src/app/core/models/product/product.mapper.ts +++ b/src/app/core/models/product/product.mapper.ts @@ -188,7 +188,11 @@ export class ProductMapper { minOrderQuantity: data.minOrderQuantity || 1, packingUnit: data.packingUnit, maxOrderQuantity: data.maxOrderQuantity || 100, - attributes: data.attributes, + attributes: + (data.attributeGroups && + data.attributeGroups.PRODUCT_DETAIL_ATTRIBUTES && + data.attributeGroups.PRODUCT_DETAIL_ATTRIBUTES.attributes) || + data.attributes, attributeGroups: data.attributeGroups, images: this.imageMapper.fromImages(data.images), listPrice: filterPrice(data.listPrice),