Przeglądaj źródła

feat(core): Collections can control inheritance of filters

Relates to #1382. This commit introduces a new property on the Collection entity & GraphQL type -
`inheritFilters`. When set to `true` (the default), behaviour is the same as before - a Collection's
filters will be composed of its own filters, plus those of all ancestors up to the root.

Setting to `false` allows you to nest a Collection and set up filters which act completely
independently of the parent filters. This allows much more flexibility in setting up category
hierarchies.

BREAKING CHANGE: The new `inheritFilters` property on the Collection entity will require a DB
migration.
Michael Bromley 3 lat temu
rodzic
commit
5d4206fabe

+ 4 - 0
packages/asset-server-plugin/e2e/graphql/generated-e2e-asset-server-plugin-types.ts

@@ -356,6 +356,7 @@ export type Collection = Node & {
     featuredAsset?: Maybe<Asset>;
     filters: Array<ConfigurableOperation>;
     id: Scalars['ID'];
+    inheritFilters: Scalars['Boolean'];
     isPrivate: Scalars['Boolean'];
     languageCode?: Maybe<LanguageCode>;
     name: Scalars['String'];
@@ -381,6 +382,7 @@ export type CollectionFilterParameter = {
     createdAt?: InputMaybe<DateOperators>;
     description?: InputMaybe<StringOperators>;
     id?: InputMaybe<IdOperators>;
+    inheritFilters?: InputMaybe<BooleanOperators>;
     isPrivate?: InputMaybe<BooleanOperators>;
     languageCode?: InputMaybe<StringOperators>;
     name?: InputMaybe<StringOperators>;
@@ -597,6 +599,7 @@ export type CreateCollectionInput = {
     customFields?: InputMaybe<Scalars['JSON']>;
     featuredAssetId?: InputMaybe<Scalars['ID']>;
     filters: Array<ConfigurableOperationInput>;
+    inheritFilters?: InputMaybe<Scalars['Boolean']>;
     isPrivate?: InputMaybe<Scalars['Boolean']>;
     parentId?: InputMaybe<Scalars['ID']>;
     translations: Array<CreateCollectionTranslationInput>;
@@ -4734,6 +4737,7 @@ export type UpdateCollectionInput = {
     featuredAssetId?: InputMaybe<Scalars['ID']>;
     filters?: InputMaybe<Array<ConfigurableOperationInput>>;
     id: Scalars['ID'];
+    inheritFilters?: InputMaybe<Scalars['Boolean']>;
     isPrivate?: InputMaybe<Scalars['Boolean']>;
     parentId?: InputMaybe<Scalars['ID']>;
     translations?: InputMaybe<Array<UpdateCollectionTranslationInput>>;

+ 4 - 0
packages/common/src/generated-types.ts

@@ -356,6 +356,7 @@ export type Collection = Node & {
   featuredAsset?: Maybe<Asset>;
   filters: Array<ConfigurableOperation>;
   id: Scalars['ID'];
+  inheritFilters: Scalars['Boolean'];
   isPrivate: Scalars['Boolean'];
   languageCode?: Maybe<LanguageCode>;
   name: Scalars['String'];
@@ -383,6 +384,7 @@ export type CollectionFilterParameter = {
   createdAt?: InputMaybe<DateOperators>;
   description?: InputMaybe<StringOperators>;
   id?: InputMaybe<IdOperators>;
+  inheritFilters?: InputMaybe<BooleanOperators>;
   isPrivate?: InputMaybe<BooleanOperators>;
   languageCode?: InputMaybe<StringOperators>;
   name?: InputMaybe<StringOperators>;
@@ -610,6 +612,7 @@ export type CreateCollectionInput = {
   customFields?: InputMaybe<Scalars['JSON']>;
   featuredAssetId?: InputMaybe<Scalars['ID']>;
   filters: Array<ConfigurableOperationInput>;
+  inheritFilters?: InputMaybe<Scalars['Boolean']>;
   isPrivate?: InputMaybe<Scalars['Boolean']>;
   parentId?: InputMaybe<Scalars['ID']>;
   translations: Array<CreateCollectionTranslationInput>;
@@ -4989,6 +4992,7 @@ export type UpdateCollectionInput = {
   featuredAssetId?: InputMaybe<Scalars['ID']>;
   filters?: InputMaybe<Array<ConfigurableOperationInput>>;
   id: Scalars['ID'];
+  inheritFilters?: InputMaybe<Scalars['Boolean']>;
   isPrivate?: InputMaybe<Scalars['Boolean']>;
   parentId?: InputMaybe<Scalars['ID']>;
   translations?: InputMaybe<Array<UpdateCollectionTranslationInput>>;

+ 140 - 48
packages/core/e2e/collection.e2e-spec.ts

@@ -1405,6 +1405,7 @@ describe('Collection resolver', () => {
                     'USB Cable',
                     'Tripod',
                     'Hat',
+                    'Boots',
                 ]);
             });
 
@@ -1566,59 +1567,150 @@ describe('Collection resolver', () => {
             });
         });
 
-        it('filter inheritance of nested collections (issue #158)', async () => {
-            const { createCollection: pearElectronics } = await adminClient.query<
-                Codegen.CreateCollectionSelectVariantsMutation,
-                Codegen.CreateCollectionSelectVariantsMutationVariables
-            >(CREATE_COLLECTION_SELECT_VARIANTS, {
-                input: {
-                    parentId: electronicsCollection.id,
-                    translations: [
-                        {
-                            languageCode: LanguageCode.en,
-                            name: 'pear electronics',
-                            description: '',
-                            slug: 'pear-electronics',
-                        },
-                    ],
-                    filters: [
-                        {
-                            code: facetValueCollectionFilter.code,
-                            arguments: [
-                                {
-                                    name: 'facetValueIds',
-                                    value: `["${getFacetValueId('pear')}"]`,
-                                },
-                                {
-                                    name: 'containsAny',
-                                    value: `false`,
-                                },
-                            ],
-                        },
-                    ],
-                } as CreateCollectionInput,
+        describe('filter inheritance', () => {
+            let clothesCollectionId: string;
+
+            it('filter inheritance of nested collections (issue #158)', async () => {
+                const { createCollection: pearElectronics } = await adminClient.query<
+                    Codegen.CreateCollectionSelectVariantsMutation,
+                    Codegen.CreateCollectionSelectVariantsMutationVariables
+                >(CREATE_COLLECTION_SELECT_VARIANTS, {
+                    input: {
+                        parentId: electronicsCollection.id,
+                        translations: [
+                            {
+                                languageCode: LanguageCode.en,
+                                name: 'pear electronics',
+                                description: '',
+                                slug: 'pear-electronics',
+                            },
+                        ],
+                        filters: [
+                            {
+                                code: facetValueCollectionFilter.code,
+                                arguments: [
+                                    {
+                                        name: 'facetValueIds',
+                                        value: `["${getFacetValueId('pear')}"]`,
+                                    },
+                                    {
+                                        name: 'containsAny',
+                                        value: `false`,
+                                    },
+                                ],
+                            },
+                        ],
+                    } as CreateCollectionInput,
+                });
+
+                await awaitRunningJobs(adminClient, 5000);
+
+                const result = await adminClient.query<
+                    Codegen.GetCollectionProductsQuery,
+                    Codegen.GetCollectionProductsQueryVariables
+                >(GET_COLLECTION_PRODUCT_VARIANTS, { id: pearElectronics.id });
+                expect(result.collection!.productVariants.items.map(i => i.name)).toEqual([
+                    'Laptop 13 inch 8GB',
+                    'Laptop 15 inch 8GB',
+                    'Laptop 13 inch 16GB',
+                    'Laptop 15 inch 16GB',
+                    'Curvy Monitor 24 inch',
+                    'Curvy Monitor 27 inch',
+                    'Gaming PC i7-8700 240GB SSD',
+                    'Instant Camera',
+                    // no "Hat"
+                ]);
             });
 
-            await awaitRunningJobs(adminClient, 5000);
+            it('child collection with no inheritance', async () => {
+                const { createCollection: clothesCollection } = await adminClient.query<
+                    Codegen.CreateCollectionSelectVariantsMutation,
+                    Codegen.CreateCollectionSelectVariantsMutationVariables
+                >(CREATE_COLLECTION_SELECT_VARIANTS, {
+                    input: {
+                        parentId: electronicsCollection.id,
+                        translations: [
+                            {
+                                languageCode: LanguageCode.en,
+                                name: 'clothes',
+                                description: '',
+                                slug: 'clothes',
+                            },
+                        ],
+                        inheritFilters: false,
+                        filters: [
+                            {
+                                code: facetValueCollectionFilter.code,
+                                arguments: [
+                                    {
+                                        name: 'facetValueIds',
+                                        value: `["${getFacetValueId('clothing')}"]`,
+                                    },
+                                    {
+                                        name: 'containsAny',
+                                        value: `false`,
+                                    },
+                                ],
+                            },
+                        ],
+                    } as CreateCollectionInput,
+                });
 
-            const result = await adminClient.query<
-                Codegen.GetCollectionProductsQuery,
-                Codegen.GetCollectionProductsQueryVariables
-            >(GET_COLLECTION_PRODUCT_VARIANTS, { id: pearElectronics.id });
-            expect(result.collection!.productVariants.items.map(i => i.name)).toEqual([
-                'Laptop 13 inch 8GB',
-                'Laptop 15 inch 8GB',
-                'Laptop 13 inch 16GB',
-                'Laptop 15 inch 16GB',
-                'Curvy Monitor 24 inch',
-                'Curvy Monitor 27 inch',
-                'Gaming PC i7-8700 240GB SSD',
-                'Instant Camera',
-                // no "Hat"
-            ]);
+                await awaitRunningJobs(adminClient, 5000);
+
+                clothesCollectionId = clothesCollection.id;
+
+                const result = await adminClient.query<
+                    Codegen.GetCollectionProductsQuery,
+                    Codegen.GetCollectionProductsQueryVariables
+                >(GET_COLLECTION_PRODUCT_VARIANTS, { id: clothesCollection.id });
+                expect(result.collection!.productVariants.items.map(i => i.name)).toEqual(['Hat', 'Boots']);
+            });
+
+            it('grandchild collection with inheritance (root -> no inherit -> inherit', async () => {
+                const { createCollection: footwearCollection } = await adminClient.query<
+                    Codegen.CreateCollectionSelectVariantsMutation,
+                    Codegen.CreateCollectionSelectVariantsMutationVariables
+                >(CREATE_COLLECTION_SELECT_VARIANTS, {
+                    input: {
+                        parentId: clothesCollectionId,
+                        translations: [
+                            {
+                                languageCode: LanguageCode.en,
+                                name: 'footwear',
+                                description: '',
+                                slug: 'footwear',
+                            },
+                        ],
+                        inheritFilters: true,
+                        filters: [
+                            {
+                                code: facetValueCollectionFilter.code,
+                                arguments: [
+                                    {
+                                        name: 'facetValueIds',
+                                        value: `["${getFacetValueId('footwear')}"]`,
+                                    },
+                                    {
+                                        name: 'containsAny',
+                                        value: `false`,
+                                    },
+                                ],
+                            },
+                        ],
+                    } as CreateCollectionInput,
+                });
+
+                await awaitRunningJobs(adminClient, 5000);
+
+                const result = await adminClient.query<
+                    Codegen.GetCollectionProductsQuery,
+                    Codegen.GetCollectionProductsQueryVariables
+                >(GET_COLLECTION_PRODUCT_VARIANTS, { id: footwearCollection.id });
+                expect(result.collection!.productVariants.items.map(i => i.name)).toEqual(['Boots']);
+            });
         });
     });
-
     describe('Product collections property', () => {
         it('returns all collections to which the Product belongs', async () => {
             const result = await adminClient.query<

+ 24 - 23
packages/core/e2e/fixtures/e2e-products-collections.csv

@@ -1,23 +1,24 @@
-name            , slug            , description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   , assets                             , facets                                             , optionGroups      , optionValues        , sku          , price   , taxCategory , stockOnHand , trackInventory , variantAssets , variantFacets
-Laptop          , laptop          , "Now equipped with seventh-generation Intel Core processors, Laptop is snappier than ever. From daily tasks like launching apps and opening files to more advanced computing, you can power through your day thanks to faster SSDs and Turbo Boost processing up to 3.6GHz."                                                                                                                                                                                                                  , derick-david-409858-unsplash.jpg   , category:electronics|category:computers|brand:pear , "screen size|RAM" , "13 inch|8GB"       , L2201308     , 1299.00 , standard    , 0           , false          ,               ,
-                ,                 ,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ,                                    ,                                                    ,                   , "15 inch|8GB"       , L2201508     , 1399.00 , standard    , 0           , false          ,               ,
-                ,                 ,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ,                                    ,                                                    ,                   , "13 inch|16GB"      , L2201316     , 2199.00 , standard    , 0           , false          ,               ,
-                ,                 ,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ,                                    ,                                                    ,                   , "15 inch|16GB"      , L2201516     , 2299.00 , standard    , 0           , false          ,               ,
-Curvy Monitor   , curvy-monitor   , "Discover a truly immersive viewing experience with this monitor curved more deeply than any other. Wrapping around your field of vision the 1,800 R screencreates a wider field of view, enhances depth perception, and minimises peripheral distractions to draw you deeper in to your content."                                                                                                                                                                                            , alexandru-acea-686569-unsplash.jpg , category:electronics|category:computers|brand:bell , monitor size      , 24 inch             , C24F390      , 143.74  , standard    , 0           , false          ,               ,
-                ,                 ,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ,                                    ,                                                    ,                   , 27 inch             , C27F390      , 169.94  , standard    , 0           , false          ,               ,
-Gaming PC       , gaming-pc       , "This pc is optimised for gaming, and is also VR ready. The Intel Core-i7 CPU and High Performance GPU give the computer the raw power it needs to function at a high level."                                                                                                                                                                                                                                                                                                                 , florian-olivo-1166419-unsplash.jpg , category:electronics|category:computers            , "cpu|HDD"         , "i7-8700|240GB SSD" , CGS480VR1063 , 1087.20 , standard    , 0           , false          ,               ,
-                ,                 ,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ,                                    ,                                                    ,                   , "R7-2700|240GB SSD" , CGS480VR1064 , 1099.95 , standard    , 0           , false          ,               ,
-                ,                 ,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ,                                    ,                                                    ,                   , "i7-8700|120GB SSD" , CGS480VR1065 , 931.20  , standard    , 0           , false          ,               ,
-                ,                 ,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ,                                    ,                                                    ,                   , "R7-2700|120GB SSD" , CGS480VR1066 , 949.20  , standard    , 0           , false          ,               ,
-Hard Drive      , hard-drive      , "Boost your PC storage with this internal hard drive, designed just for desktop and all-in-one PCs."                                                                                                                                                                                                                                                                                                                                                                                          , vincent-botta-736919-unsplash.jpg  , category:electronics|category:computers            , "HDD capacity"    , 1TB                 , IHD455T1     , 37.99   , standard    , 0           , false          ,               ,
-                ,                 ,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ,                                    ,                                                    ,                   , 2TB                 , IHD455T2     , 53.74   , standard    , 0           , false          ,               ,
-                ,                 ,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ,                                    ,                                                    ,                   , 3TB                 , IHD455T3     , 78.96   , standard    , 0           , false          ,               ,
-                ,                 ,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ,                                    ,                                                    ,                   , 4TB                 , IHD455T4     , 92.99   , standard    , 0           , false          ,               ,
-                ,                 ,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ,                                    ,                                                    ,                   , 6TB                 , IHD455T6     , 134.35  , standard    , 0           , false          ,               ,
-Clacky Keyboard , clacky-keyboard , "Let all your colleagues know that you are typing on this exclusive, colorful klicky-klacky keyboard. Huge travel on each keypress ensures maximum klack on each and every keystroke."                                                                                                                                                                                                                                                                                                        ,                                    , category:electronics|category:computers            ,                   ,                     , A4TKLA45535  , 74.89   , standard    , 0           , false          ,               ,
-USB Cable       , usb-cable       , "Solid conductors eliminate strand-interaction distortion and reduce jitter. As the surface is made of high-purity silver, the performance is very close to that of a solid silver cable, but priced much closer to solid copper cable."                                                                                                                                                                                                                                                      ,                                    , category:electronics|category:computers            ,                   ,                     , USBCIN01.5MI , 69.00   , standard    , 0           , false          ,               ,
-Instant Camera  , instant-camera  , "With its nostalgic design and simple point-and-shoot functionality, the Instant Camera is the perfect pick to get started with instant photography."                                                                                                                                                                                                                                                                                                                                         ,                                    , category:electronics|category:photo                ,                   ,                     , IC22MWDD     , 174.99  , standard    , 0           , false          ,               , brand:pear
-Camera Lens     , camera-lens     , "This lens is a Di type lens using an optical system with improved multi-coating designed to function with digital SLR cameras as well as film cameras."                                                                                                                                                                                                                                                                                                                                      ,                                    , category:electronics|category:photo                ,                   ,                     , B0012UUP02   , 104.00  , standard    , 0           , false          ,               ,
-Tripod          , tripod          , "Capture vivid, professional-style photographs with help from this lightweight tripod. The adjustable-height tripod makes it easy to achieve reliable stability and score just the right angle when going after that award-winning shot."                                                                                                                                                                                                                                                     ,                                    , category:electronics|category:photo|brand:bell     ,                   ,                     , B00XI87KV8   , 14.98   , standard    , 0           , false          ,               ,
-SLR Camera      , slr-camera      , "Retro styled, portable in size and built around a powerful 24-megapixel APS-C CMOS sensor, this digital camera is the ideal companion for creative everyday photography. Packed full of high spec features such as an advanced hybrid autofocus system able to keep pace with even the most active subjects, a speedy 6fps continuous-shooting mode, high-resolution electronic viewfinder and intuitive swivelling touchscreen, it brings professional image making into everyone’s grasp." ,                                    , category:electronics|category:photo|brand:bell     ,                   ,                     , B07D75V44S   , 521.00  , standard    , 0           , false          ,               ,
-Hat             , hat             , "A fetching hat."                                                                                                                                                                                                                                                                                                                                                                                                                                                                             ,                                    , category:clothing|style:casual                     ,                   ,                     , B07D75V44S   , 23.99   , standard    , 0           , false          ,               , brand:pear
+name           ,slug           ,description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  ,assets                            ,facets                                            ,optionGroups     ,optionValues       ,sku         ,price  ,taxCategory,stockOnHand,trackInventory,variantAssets,variantFacets
+Laptop         ,laptop         ,"Now equipped with seventh-generation Intel Core processors, Laptop is snappier than ever. From daily tasks like launching apps and opening files to more advanced computing, you can power through your day thanks to faster SSDs and Turbo Boost processing up to 3.6GHz."                                                                                                                                                                                                                 ,derick-david-409858-unsplash.jpg  ,category:electronics|category:computers|brand:pear,"screen size|RAM","13 inch|8GB"      ,L2201308    ,1299.00,standard   ,0          ,false         ,             ,
+               ,               ,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             ,                                  ,                                                  ,                 ,"15 inch|8GB"      ,L2201508    ,1399.00,standard   ,0          ,false         ,             ,
+               ,               ,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             ,                                  ,                                                  ,                 ,"13 inch|16GB"     ,L2201316    ,2199.00,standard   ,0          ,false         ,             ,
+               ,               ,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             ,                                  ,                                                  ,                 ,"15 inch|16GB"     ,L2201516    ,2299.00,standard   ,0          ,false         ,             ,
+Curvy Monitor  ,curvy-monitor  ,"Discover a truly immersive viewing experience with this monitor curved more deeply than any other. Wrapping around your field of vision the 1,800 R screencreates a wider field of view, enhances depth perception, and minimises peripheral distractions to draw you deeper in to your content."                                                                                                                                                                                           ,alexandru-acea-686569-unsplash.jpg,category:electronics|category:computers|brand:bell,monitor size     ,24 inch            ,C24F390     ,143.74 ,standard   ,0          ,false         ,             ,
+               ,               ,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             ,                                  ,                                                  ,                 ,27 inch            ,C27F390     ,169.94 ,standard   ,0          ,false         ,             ,
+Gaming PC      ,gaming-pc      ,"This pc is optimised for gaming, and is also VR ready. The Intel Core-i7 CPU and High Performance GPU give the computer the raw power it needs to function at a high level."                                                                                                                                                                                                                                                                                                                ,florian-olivo-1166419-unsplash.jpg,category:electronics|category:computers           ,"cpu|HDD"        ,"i7-8700|240GB SSD",CGS480VR1063,1087.20,standard   ,0          ,false         ,             ,
+               ,               ,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             ,                                  ,                                                  ,                 ,"R7-2700|240GB SSD",CGS480VR1064,1099.95,standard   ,0          ,false         ,             ,
+               ,               ,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             ,                                  ,                                                  ,                 ,"i7-8700|120GB SSD",CGS480VR1065,931.20 ,standard   ,0          ,false         ,             ,
+               ,               ,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             ,                                  ,                                                  ,                 ,"R7-2700|120GB SSD",CGS480VR1066,949.20 ,standard   ,0          ,false         ,             ,
+Hard Drive     ,hard-drive     ,"Boost your PC storage with this internal hard drive, designed just for desktop and all-in-one PCs."                                                                                                                                                                                                                                                                                                                                                                                         ,vincent-botta-736919-unsplash.jpg ,category:electronics|category:computers           ,"HDD capacity"   ,1TB                ,IHD455T1    ,37.99  ,standard   ,0          ,false         ,             ,
+               ,               ,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             ,                                  ,                                                  ,                 ,2TB                ,IHD455T2    ,53.74  ,standard   ,0          ,false         ,             ,
+               ,               ,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             ,                                  ,                                                  ,                 ,3TB                ,IHD455T3    ,78.96  ,standard   ,0          ,false         ,             ,
+               ,               ,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             ,                                  ,                                                  ,                 ,4TB                ,IHD455T4    ,92.99  ,standard   ,0          ,false         ,             ,
+               ,               ,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             ,                                  ,                                                  ,                 ,6TB                ,IHD455T6    ,134.35 ,standard   ,0          ,false         ,             ,
+Clacky Keyboard,clacky-keyboard,"Let all your colleagues know that you are typing on this exclusive, colorful klicky-klacky keyboard. Huge travel on each keypress ensures maximum klack on each and every keystroke."                                                                                                                                                                                                                                                                                                       ,                                  ,category:electronics|category:computers           ,                 ,                   ,A4TKLA45535 ,74.89  ,standard   ,0          ,false         ,             ,
+USB Cable      ,usb-cable      ,"Solid conductors eliminate strand-interaction distortion and reduce jitter. As the surface is made of high-purity silver, the performance is very close to that of a solid silver cable, but priced much closer to solid copper cable."                                                                                                                                                                                                                                                     ,                                  ,category:electronics|category:computers           ,                 ,                   ,USBCIN01.5MI,69.00  ,standard   ,0          ,false         ,             ,
+Instant Camera ,instant-camera ,"With its nostalgic design and simple point-and-shoot functionality, the Instant Camera is the perfect pick to get started with instant photography."                                                                                                                                                                                                                                                                                                                                        ,                                  ,category:electronics|category:photo               ,                 ,                   ,IC22MWDD    ,174.99 ,standard   ,0          ,false         ,             ,brand:pear
+Camera Lens    ,camera-lens    ,"This lens is a Di type lens using an optical system with improved multi-coating designed to function with digital SLR cameras as well as film cameras."                                                                                                                                                                                                                                                                                                                                     ,                                  ,category:electronics|category:photo               ,                 ,                   ,B0012UUP02  ,104.00 ,standard   ,0          ,false         ,             ,
+Tripod         ,tripod         ,"Capture vivid, professional-style photographs with help from this lightweight tripod. The adjustable-height tripod makes it easy to achieve reliable stability and score just the right angle when going after that award-winning shot."                                                                                                                                                                                                                                                    ,                                  ,category:electronics|category:photo|brand:bell    ,                 ,                   ,B00XI87KV8  ,14.98  ,standard   ,0          ,false         ,             ,
+SLR Camera     ,slr-camera     ,"Retro styled, portable in size and built around a powerful 24-megapixel APS-C CMOS sensor, this digital camera is the ideal companion for creative everyday photography. Packed full of high spec features such as an advanced hybrid autofocus system able to keep pace with even the most active subjects, a speedy 6fps continuous-shooting mode, high-resolution electronic viewfinder and intuitive swivelling touchscreen, it brings professional image making into everyone’s grasp.",                                  ,category:electronics|category:photo|brand:bell    ,                 ,                   ,B07D75V44S  ,521.00 ,standard   ,0          ,false         ,             ,
+Hat            ,hat            ,"A fetching hat."                                                                                                                                                                                                                                                                                                                                                                                                                                                                            ,                                  ,category:clothing|style:casual                    ,                 ,                   ,B07D75V44S  ,23.99  ,standard   ,0          ,false         ,             ,brand:pear
+Boots          ,boots          ,"Tough boots."                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ,                                  ,category:clothing|category:footwear               ,                 ,                   ,B122992     ,75.45  ,standard   ,0          ,false         ,             ,

+ 4 - 0
packages/core/e2e/graphql/generated-e2e-admin-types.ts

@@ -356,6 +356,7 @@ export type Collection = Node & {
     featuredAsset?: Maybe<Asset>;
     filters: Array<ConfigurableOperation>;
     id: Scalars['ID'];
+    inheritFilters: Scalars['Boolean'];
     isPrivate: Scalars['Boolean'];
     languageCode?: Maybe<LanguageCode>;
     name: Scalars['String'];
@@ -381,6 +382,7 @@ export type CollectionFilterParameter = {
     createdAt?: InputMaybe<DateOperators>;
     description?: InputMaybe<StringOperators>;
     id?: InputMaybe<IdOperators>;
+    inheritFilters?: InputMaybe<BooleanOperators>;
     isPrivate?: InputMaybe<BooleanOperators>;
     languageCode?: InputMaybe<StringOperators>;
     name?: InputMaybe<StringOperators>;
@@ -597,6 +599,7 @@ export type CreateCollectionInput = {
     customFields?: InputMaybe<Scalars['JSON']>;
     featuredAssetId?: InputMaybe<Scalars['ID']>;
     filters: Array<ConfigurableOperationInput>;
+    inheritFilters?: InputMaybe<Scalars['Boolean']>;
     isPrivate?: InputMaybe<Scalars['Boolean']>;
     parentId?: InputMaybe<Scalars['ID']>;
     translations: Array<CreateCollectionTranslationInput>;
@@ -4734,6 +4737,7 @@ export type UpdateCollectionInput = {
     featuredAssetId?: InputMaybe<Scalars['ID']>;
     filters?: InputMaybe<Array<ConfigurableOperationInput>>;
     id: Scalars['ID'];
+    inheritFilters?: InputMaybe<Scalars['Boolean']>;
     isPrivate?: InputMaybe<Scalars['Boolean']>;
     parentId?: InputMaybe<Scalars['ID']>;
     translations?: InputMaybe<Array<UpdateCollectionTranslationInput>>;

+ 1 - 0
packages/core/src/api/schema/admin-api/collection-admin.type.graphql

@@ -1,3 +1,4 @@
 type Collection implements Node {
     isPrivate: Boolean!
+    inheritFilters: Boolean!
 }

+ 2 - 0
packages/core/src/api/schema/admin-api/collection.api.graphql

@@ -48,6 +48,7 @@ input CreateCollectionInput {
     featuredAssetId: ID
     assetIds: [ID!]
     parentId: ID
+    inheritFilters: Boolean
     filters: [ConfigurableOperationInput!]!
     translations: [CreateCollectionTranslationInput!]!
 }
@@ -58,6 +59,7 @@ input UpdateCollectionInput {
     featuredAssetId: ID
     parentId: ID
     assetIds: [ID!]
+    inheritFilters: Boolean
     filters: [ConfigurableOperationInput!]
     translations: [UpdateCollectionTranslationInput!]
 }

+ 5 - 0
packages/core/src/entity/collection/collection.entity.ts

@@ -66,6 +66,11 @@ export class Collection
 
     @Column('simple-json') filters: ConfigurableOperation[];
 
+    /**
+     * @since 2.0.0
+     */
+    @Column({ default: true }) inheritFilters: boolean;
+
     @ManyToMany(type => ProductVariant, productVariant => productVariant.collections)
     @JoinTable()
     productVariants: ProductVariant[];

+ 19 - 6
packages/core/src/service/services/collection.service.ts

@@ -471,12 +471,7 @@ export class CollectionService implements OnModuleInit {
         collection: Collection,
         applyToChangedVariantsOnly = true,
     ): Promise<ID[]> {
-        const ancestorFilters = await this.getAncestors(collection.id).then(ancestors =>
-            ancestors.reduce(
-                (filters, c) => [...filters, ...(c.filters || [])],
-                [] as ConfigurableOperation[],
-            ),
-        );
+        const ancestorFilters = await this.getAncestorFilters(collection);
         const preIds = await this.getCollectionProductVariantIds(collection);
         collection.productVariants = await this.getFilteredProductVariants([
             ...ancestorFilters,
@@ -507,6 +502,24 @@ export class CollectionService implements OnModuleInit {
         }
     }
 
+    /**
+     * Gets all filters of ancestor Collections while respecting the `inheritFilters` setting of each.
+     * As soon as `inheritFilters === false` is encountered, the collected filters are returned.
+     */
+    private async getAncestorFilters(collection: Collection): Promise<ConfigurableOperation[]> {
+        const ancestorFilters: ConfigurableOperation[] = [];
+        if (collection.inheritFilters) {
+            const ancestors = await this.getAncestors(collection.id);
+            for (const ancestor of ancestors) {
+                ancestorFilters.push(...ancestor.filters);
+                if (ancestor.inheritFilters === false) {
+                    return ancestorFilters;
+                }
+            }
+        }
+        return ancestorFilters;
+    }
+
     /**
      * Applies the CollectionFilters and returns an array of ProductVariant entities which match.
      */

+ 4 - 0
packages/elasticsearch-plugin/e2e/graphql/generated-e2e-elasticsearch-plugin-types.ts

@@ -356,6 +356,7 @@ export type Collection = Node & {
     featuredAsset?: Maybe<Asset>;
     filters: Array<ConfigurableOperation>;
     id: Scalars['ID'];
+    inheritFilters: Scalars['Boolean'];
     isPrivate: Scalars['Boolean'];
     languageCode?: Maybe<LanguageCode>;
     name: Scalars['String'];
@@ -381,6 +382,7 @@ export type CollectionFilterParameter = {
     createdAt?: InputMaybe<DateOperators>;
     description?: InputMaybe<StringOperators>;
     id?: InputMaybe<IdOperators>;
+    inheritFilters?: InputMaybe<BooleanOperators>;
     isPrivate?: InputMaybe<BooleanOperators>;
     languageCode?: InputMaybe<StringOperators>;
     name?: InputMaybe<StringOperators>;
@@ -597,6 +599,7 @@ export type CreateCollectionInput = {
     customFields?: InputMaybe<Scalars['JSON']>;
     featuredAssetId?: InputMaybe<Scalars['ID']>;
     filters: Array<ConfigurableOperationInput>;
+    inheritFilters?: InputMaybe<Scalars['Boolean']>;
     isPrivate?: InputMaybe<Scalars['Boolean']>;
     parentId?: InputMaybe<Scalars['ID']>;
     translations: Array<CreateCollectionTranslationInput>;
@@ -4734,6 +4737,7 @@ export type UpdateCollectionInput = {
     featuredAssetId?: InputMaybe<Scalars['ID']>;
     filters?: InputMaybe<Array<ConfigurableOperationInput>>;
     id: Scalars['ID'];
+    inheritFilters?: InputMaybe<Scalars['Boolean']>;
     isPrivate?: InputMaybe<Scalars['Boolean']>;
     parentId?: InputMaybe<Scalars['ID']>;
     translations?: InputMaybe<Array<UpdateCollectionTranslationInput>>;

+ 4 - 0
packages/payments-plugin/e2e/graphql/generated-admin-types.ts

@@ -356,6 +356,7 @@ export type Collection = Node & {
     featuredAsset?: Maybe<Asset>;
     filters: Array<ConfigurableOperation>;
     id: Scalars['ID'];
+    inheritFilters: Scalars['Boolean'];
     isPrivate: Scalars['Boolean'];
     languageCode?: Maybe<LanguageCode>;
     name: Scalars['String'];
@@ -381,6 +382,7 @@ export type CollectionFilterParameter = {
     createdAt?: InputMaybe<DateOperators>;
     description?: InputMaybe<StringOperators>;
     id?: InputMaybe<IdOperators>;
+    inheritFilters?: InputMaybe<BooleanOperators>;
     isPrivate?: InputMaybe<BooleanOperators>;
     languageCode?: InputMaybe<StringOperators>;
     name?: InputMaybe<StringOperators>;
@@ -597,6 +599,7 @@ export type CreateCollectionInput = {
     customFields?: InputMaybe<Scalars['JSON']>;
     featuredAssetId?: InputMaybe<Scalars['ID']>;
     filters: Array<ConfigurableOperationInput>;
+    inheritFilters?: InputMaybe<Scalars['Boolean']>;
     isPrivate?: InputMaybe<Scalars['Boolean']>;
     parentId?: InputMaybe<Scalars['ID']>;
     translations: Array<CreateCollectionTranslationInput>;
@@ -4734,6 +4737,7 @@ export type UpdateCollectionInput = {
     featuredAssetId?: InputMaybe<Scalars['ID']>;
     filters?: InputMaybe<Array<ConfigurableOperationInput>>;
     id: Scalars['ID'];
+    inheritFilters?: InputMaybe<Scalars['Boolean']>;
     isPrivate?: InputMaybe<Scalars['Boolean']>;
     parentId?: InputMaybe<Scalars['ID']>;
     translations?: InputMaybe<Array<UpdateCollectionTranslationInput>>;

Plik diff jest za duży
+ 0 - 0
schema-admin.json


Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików