Search code examples
shopware6

When and why are the attributes `propertyIds` and `categoryIds` in the product-response


I am doing a simple search on some products using the api-endpoint {{endpoint}}/api/search/product. What i sometimes see is that there are some products, where the attributes propertyIds and categoryIds are null, while there are sometimes products where these properties are not null.

However: All the examples have actual categories and properties assigned and are visible through other attributes.

My question is: What is the reason for this and how do this values get populated?

                "minPurchase": 1,
                "purchaseUnit": null,
                "referenceUnit": null,
                "shippingFree": false,
                "purchasePrices": null,
                "markAsTopseller": null,
                "weight": null,
                "width": null,
                "height": null,
                "length": null,
                "releaseDate": null,
                "ratingAverage": null,
                "categoryTree": null,
                "propertyIds": null,
                "optionIds": null,
                "streamIds": null,
                "tagIds": null,
                "categoryIds": null,
                "childCount": null,

Example for one with Ids:

                 "b8a475de8b284e17b0ff4dba3729deff"
                ],
                "propertyIds": [
                    "2c3257b006e240369ab32334096bca40",
                    "521eab63f64a47ae9f51801d57b4a0ae",
                    "6322d1a7de254bec8fe813d4dae43e97",
                    "8253d82499b44fdfbcea4f0238ba3258",
                    "a8c03127e8644749814ee6ca0f71cba7",
                    "b5b467f25ff3402ebbd4264b785153ec",
                    "d37c8640fd43427795365dae9cb750da"
                ],
                "optionIds": null,
                "streamIds": null,
                "tagIds": null,
                "categoryIds": [
                    "4c84f6cacaa7417fa18524d78156c9e4",
                    "b8a475de8b284e17b0ff4dba3729deff"
                ],
                "childCount": 5,
                "customFieldSetSelectionActive": null,
                "sales": 0,

Solution

  • In Shopware there's the concept of indexing frequently read but rarely written data. This may for example be the count of variants for a product or, what you were wondering about, the IDs of associated entities. The indexed data is then updated whenever you update the entity, e.g. the product.

    The idea is that unless you update the entity, that indexed data would never change and it is therefore safe to store it right with the entity in its table.

    Let's say you then want to evaluate if a product has more than a certain count of variants, is part of a category or has certain properties. Then, instead of doing executing costly database queries to count rows or having a bunch of SQL joins to associated data, you can use these pre-indexed fields for your evaluation.

    If you think that you're missing some data that should've been indexed, you can use the CLI command bin/console dal:refresh:index.