wip product category variants
This commit is contained in:
107
src/Controller/ProductCategoryVariantsController.php
Normal file
107
src/Controller/ProductCategoryVariantsController.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Controller;
|
||||
|
||||
use App\Controller\AppController;
|
||||
|
||||
/**
|
||||
* ProductCategoryVariants Controller
|
||||
*
|
||||
* @property \App\Model\Table\ProductCategoryVariantsTable $ProductCategoryVariants
|
||||
*/
|
||||
class ProductCategoryVariantsController extends AppController
|
||||
{
|
||||
/**
|
||||
* Index method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$query = $this->ProductCategoryVariants->find()
|
||||
->contain(['ProductCategories', 'Products']);
|
||||
$productCategoryVariants = $this->paginate($query);
|
||||
|
||||
$this->set(compact('productCategoryVariants'));
|
||||
}
|
||||
|
||||
/**
|
||||
* View method
|
||||
*
|
||||
* @param string|null $id Product Category Variant id.
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
*/
|
||||
public function view($id = null)
|
||||
{
|
||||
$productCategoryVariant = $this->ProductCategoryVariants->get($id, contain: ['ProductCategories', 'Products']);
|
||||
$this->set(compact('productCategoryVariant'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$productCategoryVariant = $this->ProductCategoryVariants->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
$productCategoryVariant = $this->ProductCategoryVariants->patchEntity($productCategoryVariant, $this->request->getData());
|
||||
if ($this->ProductCategoryVariants->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();
|
||||
$this->set(compact('productCategoryVariant', 'productCategories', 'products'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit method
|
||||
*
|
||||
* @param string|null $id Product Category Variant id.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
$productCategoryVariant = $this->ProductCategoryVariants->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$productCategoryVariant = $this->ProductCategoryVariants->patchEntity($productCategoryVariant, $this->request->getData());
|
||||
if ($this->ProductCategoryVariants->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();
|
||||
$this->set(compact('productCategoryVariant', 'productCategories', 'products'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete method
|
||||
*
|
||||
* @param string|null $id Product Category Variant id.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productCategoryVariant = $this->ProductCategoryVariants->get($id);
|
||||
if ($this->ProductCategoryVariants->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.'));
|
||||
}
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user