category id not null but product id can be null same with sku id - product photos
This commit is contained in:
@@ -71,11 +71,33 @@ class ProductPhotosController extends AppController
|
||||
$postData = $this->request->getData();
|
||||
$postData['id'] = $uuid;
|
||||
$baseDir = Configure::readOrFail('CakeProducts.photos.directory');
|
||||
$product = $productPhotosTable->Products->get($this->request->getData('product_id'));
|
||||
$path = $product->id;
|
||||
$path = '';
|
||||
if ($this->request->getData('product_sku_id')) {
|
||||
$productSku = $productPhotosTable->ProductSkus->find()->where(['ProductSkus.id' => $this->request->getData('product_sku_id'), 'ProductSkus.product_id' => $product->id])->first();
|
||||
$path = $productSku ? $path . DS . 'skus' . DS . $productSku->id : $path;
|
||||
$productSku = $productPhotosTable->ProductSkus
|
||||
->find()
|
||||
->contain(['Products', 'Products.ProductCategories'])
|
||||
->where([
|
||||
'ProductSkus.id' => $this->request->getData('product_sku_id'),
|
||||
])
|
||||
->first();
|
||||
$path = $productSku ? $productSku->product_id . DS . 'skus' . DS . $productSku->id : $path;
|
||||
} else if ($this->request->getData('product_id')) {
|
||||
$product = $productPhotosTable->Products
|
||||
->find()
|
||||
->contain(['ProductCategories'])
|
||||
->where([
|
||||
'Products.id' => $this->request->getData('product_id'),
|
||||
])
|
||||
->first();
|
||||
$path = $product ? $product->id : $path;
|
||||
} else if ($this->request->getData('product_category_id')) {
|
||||
$productCategoryPosted = $productPhotosTable->ProductCategories
|
||||
->find()
|
||||
->where([
|
||||
'ProductCategories.internal_id' => $this->request->getData('product_category_id'),
|
||||
])
|
||||
->first();
|
||||
$path = $productCategoryPosted ? 'categories' : $path;
|
||||
}
|
||||
/**
|
||||
* @var UploadedFileInterface $photoObject
|
||||
@@ -95,7 +117,7 @@ class ProductPhotosController extends AppController
|
||||
if (!file_exists($destination)) {
|
||||
throw new ForbiddenException('Failed to move the uploaded image to the appropriate folder. Please try again.');
|
||||
}
|
||||
$postData['product_category_id'] = $product->product_category_id ?? null;
|
||||
|
||||
$postData['photo_dir'] = $path;
|
||||
$postData['photo_filename'] = $uuid;
|
||||
|
||||
@@ -105,6 +127,7 @@ class ProductPhotosController extends AppController
|
||||
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user