-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce variation attribute mapping with extended /variations…
… call (#1317) * changed products service to use `extended=true` REST calls for product details and variations * added VariationAttributeMapper to map variation attributes with attributeType and metaData * backwards compatible preparation for distinct variation select displays BREAKING CHANGES: `ProductsService` was changed to use an `extended=true` details and variations call. `VariationAttribute` model was cleaned up and extended (see [Migrations / 3.1 to 3.2](https://github.com/intershop/intershop-pwa/blob/develop/docs/guides/migrations.md#31-to-32) for more details).
- Loading branch information
Showing
14 changed files
with
138 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/app/core/models/product-variation/variation-attribute.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { VariationAttributeType } from './variation-attribute.model'; | ||
|
||
export interface VariationAttributeData { | ||
variationAttributeId: string; | ||
name: string; | ||
value?: VariationAttributeValue; | ||
values?: { | ||
value: VariationAttributeValue; | ||
metadata?: VariationAttributeMetaData; | ||
}[]; | ||
attributeType?: VariationAttributeType; | ||
metadata?: VariationAttributeMetaData; | ||
} | ||
|
||
interface VariationAttributeValue { | ||
name: string; | ||
value: string; | ||
} | ||
|
||
export interface VariationAttributeMetaData { | ||
colorCode?: string; | ||
imagePath?: string; | ||
} |
52 changes: 52 additions & 0 deletions
52
src/app/core/models/product-variation/variation-attribute.mapper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* eslint-disable ish-custom-rules/project-structure */ | ||
import { Injectable } from '@angular/core'; | ||
|
||
import { ImageMapper } from 'ish-core/models/image/image.mapper'; | ||
|
||
import { VariationAttributeData, VariationAttributeMetaData } from './variation-attribute.interface'; | ||
import { VariationAttribute, VariationAttributeType } from './variation-attribute.model'; | ||
|
||
/** | ||
* Maps variation attributes data of HTTP requests to client side model instance. | ||
*/ | ||
@Injectable({ providedIn: 'root' }) | ||
export class VariationAttributeMapper { | ||
constructor(private imageMapper: ImageMapper) {} | ||
|
||
fromData(data: VariationAttributeData[]): VariationAttribute[] { | ||
return data?.map(varAttr => ({ | ||
variationAttributeId: varAttr.variationAttributeId, | ||
name: varAttr.name, | ||
value: varAttr.value.value, | ||
attributeType: varAttr.attributeType, | ||
metaData: this.mapMetaData(varAttr.attributeType, varAttr.metadata), | ||
})); | ||
} | ||
|
||
fromMasterData(variationAttributes: VariationAttributeData[]): VariationAttribute[] { | ||
return variationAttributes | ||
?.map(varAttr => | ||
varAttr.values.map(value => ({ | ||
variationAttributeId: varAttr.variationAttributeId, | ||
name: varAttr.name, | ||
value: value.value.value, | ||
attributeType: varAttr.attributeType, | ||
metaData: this.mapMetaData(varAttr.attributeType, value.metadata), | ||
})) | ||
) | ||
.flat(); | ||
} | ||
|
||
private mapMetaData(attributeType: VariationAttributeType, metaData: VariationAttributeMetaData): string { | ||
switch (attributeType) { | ||
case 'colorCode': | ||
case 'defaultAndColorCode': | ||
return metaData?.colorCode; | ||
case 'swatchImage': | ||
case 'defaultAndSwatchImage': | ||
return this.imageMapper.fromEffectiveUrl(metaData?.imagePath); | ||
default: | ||
return; | ||
} | ||
} | ||
} |
15 changes: 12 additions & 3 deletions
15
src/app/core/models/product-variation/variation-attribute.model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
import { Attribute } from 'ish-core/models/attribute/attribute.model'; | ||
|
||
export interface VariationAttribute extends Attribute<string> { | ||
export interface VariationAttribute { | ||
variationAttributeId: string; | ||
name: string; | ||
value: string; | ||
attributeType: VariationAttributeType; | ||
metaData?: string; | ||
} | ||
|
||
export type VariationAttributeType = | ||
| 'default' | ||
| 'colorCode' | ||
| 'defaultAndColorCode' | ||
| 'swatchImage' | ||
| 'defaultAndSwatchImage'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters