Skip to content

Commit

Permalink
final fix for editing names
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciframa committed Dec 21, 2024
1 parent e60cfb8 commit c6def6c
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions Fitmo_backend/app/Http/Controllers/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -754,13 +754,6 @@ public function edit($id)
//
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$product = Product::find($id);
Expand Down Expand Up @@ -870,29 +863,9 @@ public function update(Request $request, $id)
$newState->save();
}

if ($product->name != $request->name) {
$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 (isset($request->color_name)) {
$path .= $request->name . "-" . $request->color_name;
} elseif (isset($request->variant)) {
$path .= $request->name . "-" . $request->variant;
} else {
$path .= $request->name;
}

rename($folderPath, $path);
}
//rename folder
if ($product->name != $request->tempName) {
//rename all childrens / parents
if ($request->parent_id != 0) {
$parents = Product::where('id', $request->parent_id)->get();
Expand Down Expand Up @@ -955,6 +928,31 @@ public function update(Request $request, $id)
}
}
} else {
//rename itself
$folderPath = 'products/';

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

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

rename($folderPath, $path);
}

//rename its children
$children = Product::where('parent_id', $product->id)->get();
foreach ($children as $child) {
$folderPath = 'products/';
Expand Down Expand Up @@ -985,6 +983,8 @@ public function update(Request $request, $id)
$child->save();
}
}
} else {
return $product->name . " " . $request->name;
}
// if ($request->parent["category_id"] != 0) {
//
Expand Down

0 comments on commit c6def6c

Please sign in to comment.