Commit 628b9686 authored by Jonathan Sacksick's avatar Jonathan Sacksick
Browse files

Issue #3325807 by kishan@lnwebworks, jsacksick: Ensure the variation reference...

Issue #3325807 by kishan@lnwebworks, jsacksick: Ensure the variation reference is not lost when reordering variations with the same weight in the admin.
parent 915efe1e
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -242,8 +242,18 @@ class ProductVariationListBuilder extends EntityListBuilder implements FormInter
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $variations = $this->product->getVariations();
    $new_variations = [];
    $variation_groups = [];
    // Multiple variations can have the same weight, group the variations per
    // weight, and then iterate on variation groups below to reassign a correct
    // weight.
    foreach ($form_state->getValue('variations') as $id => $value) {
      $new_variations[$value['weight']] = $variations[$this->variationDeltas[$id]];
      $variation_groups[$value['weight']][] = $variations[$this->variationDeltas[$id]];
    }
    ksort($variation_groups);
    foreach ($variation_groups as $variations) {
      foreach ($variations as $variation) {
        $new_variations[] = $variation;
      }
    }
    $this->product->setVariations($new_variations);
    $this->product->save();