Skip to content

Commit

Permalink
feat(core): Facet:value pairs can be used in InitialData collection def
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Feb 15, 2021
1 parent 61fc6c7 commit 2dc7f15
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const initialData: InitialData = {
* `defaultZone`: Sets the default shipping & tax zone for the default Channel. The zone must correspond to a value of `zone` set in the `countries` array.
* `taxRates`: For each item, a new [TaxCategory]({{< relref "tax-category" >}}) is created, and then a [TaxRate]({{< relref "tax-rate" >}}) is created for each unique zone defined in the `countries` array.
* `shippingMethods`: Allows simple flat-rate [ShippingMethods]({{< relref "shipping-method" >}}) to be defined.
* `collections`: Allows Collections to be created. Currently only collections based on facet values can be created (`code: 'facet-value-filter'`). The `assetPaths` and `facetValueNames` value must correspond to a values specified in the products csv file.
* `collections`: Allows Collections to be created. Currently, only collections based on facet values can be created (`code: 'facet-value-filter'`). The `assetPaths` and `facetValueNames` value must correspond to a values specified in the products csv file. The name should match the value specified in the product csv file (or can be a normalized - lower-case & hyphenated - version thereof). If there are FacetValues in multiple Facets with the same name, the facet may be specified with a colon delimiter, e.g. `brand:apple`, `flavour: apple`.

## Populating The Server

Expand Down
16 changes: 15 additions & 1 deletion packages/core/src/data-import/providers/populator/populator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,21 @@ export class Populator {
switch (filter.code) {
case 'facet-value-filter':
const facetValueIds = filter.args.facetValueNames
.map(name => allFacetValues.find(fv => fv.name === name))
.map(name =>
allFacetValues.find(fv => {
let facetName;
let valueName;
if (name.includes(':')) {
[facetName, valueName] = name.split(':');
return (
(fv.name === valueName || fv.code === valueName) &&
(fv.facet.name === facetName || fv.facet.code === facetName)
);
} else {
return fv.name === valueName || fv.code === valueName;
}
}),
)
.filter(notNullOrUndefined)
.map(fv => fv.id);
return {
Expand Down

0 comments on commit 2dc7f15

Please sign in to comment.