primary sku photo working with janky toggle workaround but w/e lol

This commit is contained in:
2025-11-01 16:10:48 -07:00
parent 41c5f7169e
commit b145e901ef
9 changed files with 226 additions and 10 deletions

View File

@@ -11,7 +11,6 @@ use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
use CakeProducts\Controller\AppController;
use CheeseCake\Controller\Traits\OverrideTableTrait;
;
use CakeProducts\Model\Enum\ProductCategoryAttributeTypeId;
use CakeProducts\Model\Table\ProductCategoryAttributesTable;

View File

@@ -74,8 +74,8 @@ class ProductPhotosController extends AppController
$product = $productPhotosTable->Products->get($this->request->getData('product_id'));
$path = $product->id;
if ($this->request->getData('product_sku_id')) {
$productSku = $productPhotosTable->ProductSkus->get($this->request->getData('product_sku_id'));
$path .= DS . 'skus' . DS . $productSku->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;
}
/**
* @var UploadedFileInterface $photoObject
@@ -98,14 +98,13 @@ class ProductPhotosController extends AppController
$postData['product_category_id'] = $product->product_category_id ?? null;
$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->product_category_id);
// dd(print_r($productPhoto->getErrors(), true));
$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;