Magento 2 - Use search criteria to find configurable using attribute of their children
-
15-04-2021 - |
Вопрос
I have product X which is configurable. To product X I have assigned product Y and Z as simple ones.
Both simple has attribute "Color". Now product Y has color: 123, product Z has color: 456. Both have also visibility as "non visible individually".
I'd like to search product X using in search criteria value 123 or 456 and kind of field "color".
Is it possible? Do you know any tip how can I reach it?
I am using Magento 2.4 and want to get data by REST API.
Решение
After some research I didn't find better option. Solution which I used:
- Create new attribute "children_color". New attributes are always visible in REST_API and filtering using search criteria works for them.
- Add hook action to update this attribute after save. It collect data from children and put it into configurable product
- Add cron task which update that attribute in new products. I couldn't do it in hook, because there was problem with saving data and access to configurable children. I set only flag "need_update" to 1. Then I get all "need_update" via Cron and update them. Generally this point can be also used for update if you want to have better performance
- Add CLI command to fill all existing products with new attribute value.
Не связан с magento.stackexchange