0

In Magento 2, I’m try to disable product by custom attribute value.

For exemple if product has attribute "custom_status" = "disabled" then product is no longer available to customers by any path, product grid, search, url etc.

Do you know how to set this up ?

Thanks

0

You can do that real time, but you have to hook into a lot of places (like collection retrieval, repository getList method, product view page, related products, upsells, and maybe a lot of others). Not to mention that you may have third party extensions that use product collections. My advice is to build an observer on the product save that sets the product to disabled when saved and your attribute has the value "disabled".
Or better yet, create a cron that runs periodically and checks for products with status enabled and your custom attribute "disabled" and sets those products to disabled (status attribute).

The drawback for the cron approach is that you may get a short period of time when the product is available even if it shouldn't be. The upside is that it does not matter where your change comes from (import, admin save, anything else), your products will get disabled.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.