The variations just unset from the $product->variations and still exist in a DB.

Comments

drugan created an issue. See original summary.

  • drugan committed 728cb4b on 8.x-1.x
    Issue #3027034: Delete variations" action does not actually deletes...
drugan’s picture

For some reasons the $variation->delete(); statement has disappeared :).

So, to delete orphaned variations on an existing product just check in any variation on the product/N/variations page and apply Delete variations actions action. If there were some orphaned variations then the warning will appear. Just press the CANCEL AND BACK button and you are done with the cleanup work.

The things a little more complicated if you've already deleted a product with orphaned variations. If you are totally sure that ALL (!sic) your variations must have a parent product then execute the code below:

foreach (\Drupal::entityTypeManager()->getStorage('commerce_product_variation')->loadMultiple() as $variation) {
  if (!$variation->getProduct()) {
    $variation->delete();
  }
}
drugan’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.