Search code examples
phpsymfonyshopwareshopware6

Shopware 6: Don't list products with no price rule for customer group


In Shopware 6 we have a Rule for each customer group. Products then have price rules for these customer groups. Works all good so far, when I login the customer I can see the correct prices. Problem: All products that don't have price rule for the logged in customer/customer-group must NOT be displayed. Even calling them via deeplink or searching for them must be disabled.

I have searched for adding filters to the "ProductListingCollectFilterEvent" and know basically how to add filters. But I have no idea how to implement a filter for my needs...

Does anyone have a tip for me?

Thanks a lot and kind regards.


Solution

  • I now found a solution for my problem. There might be a better way - I don't know.

    I added a custom text field to the products. When prices are updated via API, I keep the allowed group ids in mind and write them to the custom field.

    Then, in the ProductListingCollectFilterEvent I added a filter on the custom field.

    Works for me now. If someone knows a way to directly filter on the product prices, please let me know.

    Thanks a lot!