From f5da89cb198b7c129f1899952a6b6f4400e70289 Mon Sep 17 00:00:00 2001 From: Brandon Shipley Date: Sat, 1 Nov 2025 23:52:49 -0700 Subject: [PATCH] photos working with categories better now --- src/Controller/ProductPhotosController.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Controller/ProductPhotosController.php b/src/Controller/ProductPhotosController.php index be6c113..c792c46 100644 --- a/src/Controller/ProductPhotosController.php +++ b/src/Controller/ProductPhotosController.php @@ -91,12 +91,15 @@ class ProductPhotosController extends AppController ->first(); $path = $product ? $product->id : $path; } else if ($this->request->getData('product_category_id')) { + $categoryId = $this->request->getData('product_category_id'); + $field = is_integer($categoryId) ? 'ProductCategories.id' : 'ProductCategories.internal_id'; $productCategoryPosted = $productPhotosTable->ProductCategories ->find() ->where([ - 'ProductCategories.internal_id' => $this->request->getData('product_category_id'), + $field => $categoryId, ]) ->first(); + $postData['product_category_id'] = $productCategoryPosted->internal_id ?? null; $path = $productCategoryPosted ? 'categories' : $path; } /** @@ -120,14 +123,12 @@ class ProductPhotosController extends AppController $postData['photo_dir'] = $path; $postData['photo_filename'] = $uuid; - $productPhoto = $productPhotosTable->patchEntity($productPhoto, $postData); if ($productPhotosTable->save($productPhoto)) { $this->Flash->success(__('The product photo has been saved.')); return $this->redirect(['action' => 'index']); } - dd($productPhoto->getErrors()); $this->Flash->error(__('The product photo could not be saved. Please, try again.')); } $productCategory = $productPhoto->product_category_id ? $productPhotosTable->ProductCategories->find()->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null;