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
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:
parent
5cba7de890
commit
46e68d8c56
|
@ -4,6 +4,10 @@ declare(strict_types=1);
|
||||||
namespace CakeProducts\Controller;
|
namespace CakeProducts\Controller;
|
||||||
|
|
||||||
use App\Controller\AppController;
|
use App\Controller\AppController;
|
||||||
|
use Cake\Core\Configure;
|
||||||
|
use Cake\ORM\Table;
|
||||||
|
use Cake\ORM\TableRegistry;
|
||||||
|
use CheeseCake\Controller\Traits\OverrideTableTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ProductCategoryVariants Controller
|
* ProductCategoryVariants Controller
|
||||||
|
@ -12,6 +16,18 @@ use App\Controller\AppController;
|
||||||
*/
|
*/
|
||||||
class ProductCategoryVariantsController extends 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
|
* Index method
|
||||||
*
|
*
|
||||||
|
@ -19,7 +35,7 @@ class ProductCategoryVariantsController extends AppController
|
||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$query = $this->ProductCategoryVariants->find()
|
$query = $this->getTable()->find()
|
||||||
->contain(['ProductCategories', 'Products']);
|
->contain(['ProductCategories', 'Products']);
|
||||||
$productCategoryVariants = $this->paginate($query);
|
$productCategoryVariants = $this->paginate($query);
|
||||||
|
|
||||||
|
@ -35,7 +51,7 @@ class ProductCategoryVariantsController extends AppController
|
||||||
*/
|
*/
|
||||||
public function view($id = null)
|
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'));
|
$this->set(compact('productCategoryVariant'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,18 +62,20 @@ class ProductCategoryVariantsController extends AppController
|
||||||
*/
|
*/
|
||||||
public function add()
|
public function add()
|
||||||
{
|
{
|
||||||
$productCategoryVariant = $this->ProductCategoryVariants->newEmptyEntity();
|
$productCategoryVariantsTable = $this->getTable();
|
||||||
|
|
||||||
|
$productCategoryVariant = $productCategoryVariantsTable->newEmptyEntity();
|
||||||
if ($this->request->is('post')) {
|
if ($this->request->is('post')) {
|
||||||
$productCategoryVariant = $this->ProductCategoryVariants->patchEntity($productCategoryVariant, $this->request->getData());
|
$productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $this->request->getData());
|
||||||
if ($this->ProductCategoryVariants->save($productCategoryVariant)) {
|
if ($productCategoryVariantsTable->save($productCategoryVariant)) {
|
||||||
$this->Flash->success(__('The product category variant has been saved.'));
|
$this->Flash->success(__('The product category variant has been saved.'));
|
||||||
|
|
||||||
return $this->redirect(['action' => 'index']);
|
return $this->redirect(['action' => 'index']);
|
||||||
}
|
}
|
||||||
$this->Flash->error(__('The product category variant could not be saved. Please, try again.'));
|
$this->Flash->error(__('The product category variant could not be saved. Please, try again.'));
|
||||||
}
|
}
|
||||||
$productCategories = $this->ProductCategoryVariants->ProductCategories->find('list', limit: 200)->all();
|
$productCategories = $productCategoryVariantsTable->ProductCategories->find('list')->all();
|
||||||
$products = $this->ProductCategoryVariants->Products->find('list', limit: 200)->all();
|
$products = $productCategoryVariantsTable->Products->find('list')->all();
|
||||||
$this->set(compact('productCategoryVariant', 'productCategories', 'products'));
|
$this->set(compact('productCategoryVariant', 'productCategories', 'products'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,18 +88,19 @@ class ProductCategoryVariantsController extends AppController
|
||||||
*/
|
*/
|
||||||
public function edit($id = null)
|
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'])) {
|
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||||
$productCategoryVariant = $this->ProductCategoryVariants->patchEntity($productCategoryVariant, $this->request->getData());
|
$productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $this->request->getData());
|
||||||
if ($this->ProductCategoryVariants->save($productCategoryVariant)) {
|
if ($productCategoryVariantsTable->save($productCategoryVariant)) {
|
||||||
$this->Flash->success(__('The product category variant has been saved.'));
|
$this->Flash->success(__('The product category variant has been saved.'));
|
||||||
|
|
||||||
return $this->redirect(['action' => 'index']);
|
return $this->redirect(['action' => 'index']);
|
||||||
}
|
}
|
||||||
$this->Flash->error(__('The product category variant could not be saved. Please, try again.'));
|
$this->Flash->error(__('The product category variant could not be saved. Please, try again.'));
|
||||||
}
|
}
|
||||||
$productCategories = $this->ProductCategoryVariants->ProductCategories->find('list', limit: 200)->all();
|
$productCategories = $productCategoryVariantsTable->ProductCategories->find('list', limit: 200)->all();
|
||||||
$products = $this->ProductCategoryVariants->Products->find('list', limit: 200)->all();
|
$products = $productCategoryVariantsTable->Products->find('list', limit: 200)->all();
|
||||||
$this->set(compact('productCategoryVariant', 'productCategories', 'products'));
|
$this->set(compact('productCategoryVariant', 'productCategories', 'products'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,8 +114,10 @@ class ProductCategoryVariantsController extends AppController
|
||||||
public function delete($id = null)
|
public function delete($id = null)
|
||||||
{
|
{
|
||||||
$this->request->allowMethod(['post', 'delete']);
|
$this->request->allowMethod(['post', 'delete']);
|
||||||
$productCategoryVariant = $this->ProductCategoryVariants->get($id);
|
$productCategoryVariantsTable = $this->getTable();
|
||||||
if ($this->ProductCategoryVariants->delete($productCategoryVariant)) {
|
|
||||||
|
$productCategoryVariant = $productCategoryVariantsTable->get($id);
|
||||||
|
if ($productCategoryVariantsTable->delete($productCategoryVariant)) {
|
||||||
$this->Flash->success(__('The product category variant has been deleted.'));
|
$this->Flash->success(__('The product category variant has been deleted.'));
|
||||||
} else {
|
} else {
|
||||||
$this->Flash->error(__('The product category variant could not be deleted. Please, try again.'));
|
$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']);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue