photos working with categories better now
This commit is contained in:
parent
dc2f422247
commit
f5da89cb19
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue