Skip to content

Commit

Permalink
renaming parents / children even folders
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciframa committed Dec 20, 2024
1 parent 0de4f72 commit 171eead
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Fitmo_backend/app/Http/Controllers/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,36 @@ public function update(Request $request, $id)
}
$parent->name = $request->name;
$parent->save();

//rename their children
$children = Product::where('parent_id', $parent->id)->get();
foreach ($children as $child) {
if (isset($child->color_id)) {
$existingColor = Color::find($child->color_id);
$folderPath .= $child->name . "-" . $existingColor->color_name;
} elseif (isset($child->variant)) {
$folderPath .= $child->name . "-" . $child->variant;
} else {
$folderPath .= $child->name;
}
if (File::exists($folderPath) && File::isDirectory($folderPath)) {
$path = 'products/';

if (isset($existingColor)) {
$path .= $request->name . "-" . $existingColor->color_name;
} elseif (isset($child->variant)) {
$path .= $request->name . "-" . $child->variant;
} else {
$path .= $request->name;
}

rename($folderPath, $path);
}


$child->name = $request->name;
$child->save();
}
}
} else {
$children = Product::where('parent_id', $product->id)->get();
Expand Down

0 comments on commit 171eead

Please sign in to comment.