use override table trait from cheesecake pluging
CI / testsuite (mysql, 8.1, ) (push) Failing after 0s Details
CI / testsuite (mysql, 8.4, ) (push) Failing after 0s Details
CI / testsuite (pgsql, 8.1, ) (push) Failing after 0s Details
CI / testsuite (pgsql, 8.4, ) (push) Failing after 0s Details
CI / testsuite (sqlite, 8.1, ) (push) Failing after 0s Details
CI / testsuite (sqlite, 8.1, prefer-lowest) (push) Failing after 0s Details
CI / testsuite (sqlite, 8.4, ) (push) Failing after 0s Details
CI / Coding Standard & Static Analysis (push) Failing after 0s Details

This commit is contained in:
Brandon Shipley 2025-06-29 23:07:42 -07:00
parent 5cba7de890
commit 46e68d8c56
Signed by: bmfs
GPG Key ID: 14E38571D8BB0DE4
1 changed files with 52 additions and 14 deletions

View File

@ -4,6 +4,10 @@ declare(strict_types=1);
namespace CakeProducts\Controller;
use App\Controller\AppController;
use Cake\Core\Configure;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
use CheeseCake\Controller\Traits\OverrideTableTrait;
/**
* ProductCategoryVariants Controller
@ -12,6 +16,18 @@ use App\Controller\AppController;
*/
class ProductCategoryVariantsController extends AppController
{
use OverrideTableTrait;
/**
* @return void
*/
public function initialize(): void
{
parent::initialize(); // TODO: Change the autogenerated stub
// $this->_defaultTable = 'CakeProducts.ProductCategoryVariants';
// $this->_tableConfigKey = 'CakeProducts.ProductCategoryVariants.table';
}
/**
* Index method
*
@ -19,7 +35,7 @@ class ProductCategoryVariantsController extends AppController
*/
public function index()
{
$query = $this->ProductCategoryVariants->find()
$query = $this->getTable()->find()
->contain(['ProductCategories', 'Products']);
$productCategoryVariants = $this->paginate($query);
@ -35,7 +51,7 @@ class ProductCategoryVariantsController extends AppController
*/
public function view($id = null)
{
$productCategoryVariant = $this->ProductCategoryVariants->get($id, contain: ['ProductCategories', 'Products']);
$productCategoryVariant = $this->getTable()->get($id, contain: ['ProductCategories', 'Products']);
$this->set(compact('productCategoryVariant'));
}
@ -46,18 +62,20 @@ class ProductCategoryVariantsController extends AppController
*/
public function add()
{
$productCategoryVariant = $this->ProductCategoryVariants->newEmptyEntity();
$productCategoryVariantsTable = $this->getTable();
$productCategoryVariant = $productCategoryVariantsTable->newEmptyEntity();
if ($this->request->is('post')) {
$productCategoryVariant = $this->ProductCategoryVariants->patchEntity($productCategoryVariant, $this->request->getData());
if ($this->ProductCategoryVariants->save($productCategoryVariant)) {
$productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $this->request->getData());
if ($productCategoryVariantsTable->save($productCategoryVariant)) {
$this->Flash->success(__('The product category variant has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The product category variant could not be saved. Please, try again.'));
}
$productCategories = $this->ProductCategoryVariants->ProductCategories->find('list', limit: 200)->all();
$products = $this->ProductCategoryVariants->Products->find('list', limit: 200)->all();
$productCategories = $productCategoryVariantsTable->ProductCategories->find('list')->all();
$products = $productCategoryVariantsTable->Products->find('list')->all();
$this->set(compact('productCategoryVariant', 'productCategories', 'products'));
}
@ -70,18 +88,19 @@ class ProductCategoryVariantsController extends AppController
*/
public function edit($id = null)
{
$productCategoryVariant = $this->ProductCategoryVariants->get($id, contain: []);
$productCategoryVariantsTable = $this->getTable();
$productCategoryVariant = $productCategoryVariantsTable->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) {
$productCategoryVariant = $this->ProductCategoryVariants->patchEntity($productCategoryVariant, $this->request->getData());
if ($this->ProductCategoryVariants->save($productCategoryVariant)) {
$productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $this->request->getData());
if ($productCategoryVariantsTable->save($productCategoryVariant)) {
$this->Flash->success(__('The product category variant has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The product category variant could not be saved. Please, try again.'));
}
$productCategories = $this->ProductCategoryVariants->ProductCategories->find('list', limit: 200)->all();
$products = $this->ProductCategoryVariants->Products->find('list', limit: 200)->all();
$productCategories = $productCategoryVariantsTable->ProductCategories->find('list', limit: 200)->all();
$products = $productCategoryVariantsTable->Products->find('list', limit: 200)->all();
$this->set(compact('productCategoryVariant', 'productCategories', 'products'));
}
@ -95,8 +114,10 @@ class ProductCategoryVariantsController extends AppController
public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$productCategoryVariant = $this->ProductCategoryVariants->get($id);
if ($this->ProductCategoryVariants->delete($productCategoryVariant)) {
$productCategoryVariantsTable = $this->getTable();
$productCategoryVariant = $productCategoryVariantsTable->get($id);
if ($productCategoryVariantsTable->delete($productCategoryVariant)) {
$this->Flash->success(__('The product category variant has been deleted.'));
} else {
$this->Flash->error(__('The product category variant could not be deleted. Please, try again.'));
@ -104,4 +125,21 @@ class ProductCategoryVariantsController extends AppController
return $this->redirect(['action' => 'index']);
}
/**
* Gets the users table instance
*
* @return Table
*/
public function getTable()
{
if ($this->_table instanceof Table) {
return $this->_table;
}
$this->_table = TableRegistry::getTableLocator()->get(
Configure::read('CakeProducts.ProductCategoryVariants.table', 'CakeProducts.ProductCategoryVariants')
);
return $this->_table;
}
}