variant options coming along - add test passing

This commit is contained in:
2025-07-05 20:48:40 -07:00
parent 5adc791c20
commit 59a38758e9
11 changed files with 110 additions and 24 deletions

View File

@@ -5,6 +5,7 @@ namespace CakeProducts\Controller;
use App\Controller\AppController;
use Cake\Core\Configure;
use Cake\Log\Log;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
use CheeseCake\Controller\Traits\OverrideTableTrait;
@@ -66,12 +67,23 @@ class ProductCategoryVariantsController extends AppController
$productCategoryVariant = $productCategoryVariantsTable->newEmptyEntity();
if ($this->request->is('post')) {
$productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $this->request->getData());
$postData = $this->request->getData();
if ($this->request->getSession()->read('Auth.User.id')) {
$postData['created_by'] = $this->request->getSession()->read('Auth.User.id');
}
$saveOptions = [
'associated' => [
'ProductCategoryVariantOptions'
],
];
$productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $postData, $saveOptions);
if ($productCategoryVariantsTable->save($productCategoryVariant)) {
$this->Flash->success(__('The product category variant has been saved.'));
return $this->redirect(['action' => 'index']);
}
Log::debug('print_r($productCategoryVariant->getErrors(), true) failed to save in product category variants add');
Log::debug(print_r($productCategoryVariant->getErrors(), true));
$this->Flash->error(__('The product category variant could not be saved. Please, try again.'));
}
$productCategories = $productCategoryVariantsTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all();