Skip to content

Commit

Permalink
products fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciframa committed Dec 8, 2024
1 parent 1ad1d3f commit 40144fa
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Fitmo_backend/app/Http/Controllers/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,19 @@ public function update(Request $request, $id)
$newProductCategories->save();
}
}
//Get childrens
$children = Product::where('parent_id', $product->id)->get();
$productCategoriesOfThisProduct = ProductCategory::where('product_id', $product->id)->get();
foreach ($children as $child) {
// get productCategories and make them for this product aswell
ProductCategory::where('product_id', $child->id)->delete();
foreach ($productCategoriesOfThisProduct as $productCategory) {
$newProductCategories = new ProductCategory();
$newProductCategories->product_id = $child->id;
$newProductCategories->category_id = $productCategory->category_id;
}
}

$product->parent_id = $request->parent_id;

$product->variant = $request->variant;
Expand Down

0 comments on commit 40144fa

Please sign in to comment.