Skip to content

Commit

Permalink
fix: variation select "Not Available" flag in case of one variation a…
Browse files Browse the repository at this point in the history
…ttribute
  • Loading branch information
Sebastian-Haehnlein committed May 19, 2020
1 parent 7b8e1bf commit 0229788
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
13 changes: 3 additions & 10 deletions src/app/core/models/product-variation/product-variation.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { groupBy } from 'lodash-es';
import { VariationProductMasterView, VariationProductView } from 'ish-core/models/product-view/product-view.model';
import { objectToArray } from 'ish-core/utils/functions';

import { VariationAttribute } from './variation-attribute.model';
import { VariationOptionGroup } from './variation-option-group.model';
import { VariationSelectOption } from './variation-select-option.model';
import { VariationSelection } from './variation-selection.model';
Expand All @@ -17,18 +16,10 @@ export class ProductVariationHelper {
// TODO: Refactor this to a more functional style
private static alternativeCombinationCheck(option: VariationSelectOption, product: VariationProductView): boolean {
let quality: number;
const selectedProductAttributes: VariationAttribute[] = [];
const perfectMatchQuality = product.variableVariationAttributes.length;

// remove option related attribute type since it should not be involved in combination check.
for (const attribute of product.variableVariationAttributes) {
if (attribute.variationAttributeId !== option.type) {
selectedProductAttributes.push(attribute);
}
}

// loop all selected product attributes ignoring the ones related to currently checked option.
for (const selectedAttribute of selectedProductAttributes) {
for (const selectedAttribute of product.variableVariationAttributes) {
// loop all possible variations
for (const variation of product.variations()) {
quality = 0;
Expand All @@ -41,11 +32,13 @@ export class ProductVariationHelper {
attribute.value === selectedAttribute.value
) {
quality += 1;
continue;
}

// increment quality if variation attribute matches currently checked option.
if (attribute.variationAttributeId === option.type && attribute.value === option.value) {
quality += 1;
continue;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
[formControlName]="group.id"
[attr.data-testing-id]="group.id"
>
<option *ngFor="let option of group.options" [value]="option.value">
{{ option.label }}
<ng-container *ngIf="option.alternativeCombination">
- {{ 'product.available_in_different_configuration' | translate }}
</ng-container>
</option>
<ng-container *ngFor="let option of group.options">
<option *ngIf="!option.alternativeCombination || variationOptions.length > 1" [value]="option.value">
{{ option.label }}
<ng-container *ngIf="option.alternativeCombination">
- {{ 'product.available_in_different_configuration' | translate }}
</ng-container>
</option>
</ng-container>
</select>
</div>
</div>
Expand Down

0 comments on commit 0229788

Please sign in to comment.