I need to unpublish all "active" (published status == TRUE) products and products variations before every import of actual assortment on my site. How to do it programmatically? I see 2 ways to do this:
- via a direct query to the database.
- via entytyQuery methodes: 2.1. create an array of ids of all products with the „status“ field == 1 (smth like that: $products_ids = Drupal::entityQuery('commerce_product')->condition('status', 1)->execute();) 2.2. iterate over the given array, changing all the „status“ fields to the value 0 and for each product getting its variations and assign them to the „status“ fields the value 0 (iterate over them in the subcycle).
thank you in advance for your help!
PS the quantity of products (with products variations) ~ 25 000 - 30 000 sku