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 9a028b9 commit e60cfb8
Showing 1 changed file with 74 additions and 71 deletions.
145 changes: 74 additions & 71 deletions Fitmo_backend/app/Http/Controllers/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -869,60 +869,93 @@ public function update(Request $request, $id)
$newState->topProduct = (int)filter_var($request->topProduct, FILTER_VALIDATE_BOOLEAN);
$newState->save();
}
$folderPath = 'products/';

if (isset($existingColor)) {
$folderPath .= $productOriginalName . "-" . $originalColorName;
} elseif (isset($productOriginalVariant)) {
$folderPath .= $productOriginalName . "-" . $productOriginalVariant;
} else {
$folderPath .= $productOriginalName;
}
if (File::exists($folderPath) && File::isDirectory($folderPath)) {
$path = 'products/';
if ($product->name != $request->name) {
$folderPath = 'products/';

if (isset($request->color_name)) {
$path .= $request->name . "-" . $request->color_name;
} elseif (isset($request->variant)) {
$path .= $request->name . "-" . $request->variant;
if (isset($existingColor)) {
$folderPath .= $productOriginalName . "-" . $originalColorName;
} elseif (isset($productOriginalVariant)) {
$folderPath .= $productOriginalName . "-" . $productOriginalVariant;
} else {
$path .= $request->name;
$folderPath .= $productOriginalName;
}
if (File::exists($folderPath) && File::isDirectory($folderPath)) {
$path = 'products/';

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

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

rename($folderPath, $path);
}
$parent->name = $request->name;
$parent->save();
if (isset($existingColor)) {
$path .= $request->name . "-" . $existingColor->color_name;
} elseif (isset($parent->variant)) {
$path .= $request->name . "-" . $parent->variant;
} else {
$path .= $request->name;
}

rename($folderPath, $path);
}
$parent->name = $request->name;
$parent->save();

//rename their children
$children = Product::where('parent_id', $parent->id)->get();
foreach ($children as $child) {
$folderPath = 'products/';
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);
}

//rename their children
$children = Product::where('parent_id', $parent->id)->get();

$child->name = $request->name;
$child->save();
}
}
} else {
$children = Product::where('parent_id', $product->id)->get();
foreach ($children as $child) {
$folderPath = 'products/';
if (isset($child->color_id)) {
Expand Down Expand Up @@ -952,36 +985,6 @@ public function update(Request $request, $id)
$child->save();
}
}
} else {
$children = Product::where('parent_id', $product->id)->get();
foreach ($children as $child) {
$folderPath = 'products/';
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();
}
}
// if ($request->parent["category_id"] != 0) {
//
Expand Down

0 comments on commit e60cfb8

Please sign in to comment.