Question

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.

Was it helpful?

Solution

After some research I didn't find better option. Solution which I used:

  1. Create new attribute "children_color". New attributes are always visible in REST_API and filtering using search criteria works for them.
  2. Add hook action to update this attribute after save. It collect data from children and put it into configurable product
  3. 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
  4. Add CLI command to fill all existing products with new attribute value.
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top