photos working with categories better now
CI / testsuite (mysql, 8.2, ) (push) Waiting to run Details
CI / testsuite (mysql, 8.4, ) (push) Waiting to run Details
CI / testsuite (sqlite, 8.2, prefer-lowest) (push) Waiting to run Details
CI / Coding Standard & Static Analysis (push) Waiting to run Details

This commit is contained in:
Brandon Shipley 2025-11-01 23:52:49 -07:00
parent dc2f422247
commit f5da89cb19
Signed by: bmfs
GPG Key ID: 14E38571D8BB0DE4
1 changed files with 4 additions and 3 deletions

View File

@ -91,12 +91,15 @@ class ProductPhotosController extends AppController
->first(); ->first();
$path = $product ? $product->id : $path; $path = $product ? $product->id : $path;
} else if ($this->request->getData('product_category_id')) { } 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 $productCategoryPosted = $productPhotosTable->ProductCategories
->find() ->find()
->where([ ->where([
'ProductCategories.internal_id' => $this->request->getData('product_category_id'), $field => $categoryId,
]) ])
->first(); ->first();
$postData['product_category_id'] = $productCategoryPosted->internal_id ?? null;
$path = $productCategoryPosted ? 'categories' : $path; $path = $productCategoryPosted ? 'categories' : $path;
} }
/** /**
@ -120,14 +123,12 @@ class ProductPhotosController extends AppController
$postData['photo_dir'] = $path; $postData['photo_dir'] = $path;
$postData['photo_filename'] = $uuid; $postData['photo_filename'] = $uuid;
$productPhoto = $productPhotosTable->patchEntity($productPhoto, $postData); $productPhoto = $productPhotosTable->patchEntity($productPhoto, $postData);
if ($productPhotosTable->save($productPhoto)) { if ($productPhotosTable->save($productPhoto)) {
$this->Flash->success(__('The product photo has been saved.')); $this->Flash->success(__('The product photo has been saved.'));
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
} }
dd($productPhoto->getErrors());
$this->Flash->error(__('The product photo could not be saved. Please, try again.')); $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; $productCategory = $productPhoto->product_category_id ? $productPhotosTable->ProductCategories->find()->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null;