bring into standalone plugin for distribution
This commit is contained in:
10
src/Controller/AppController.php
Normal file
10
src/Controller/AppController.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Controller;
|
||||
|
||||
use App\Controller\AppController as BaseController;
|
||||
|
||||
class AppController extends BaseController
|
||||
{
|
||||
}
|
||||
110
src/Controller/ExternalProductCatalogsController.php
Normal file
110
src/Controller/ExternalProductCatalogsController.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Controller;
|
||||
|
||||
use Cake\Log\Log;
|
||||
use CakeProducts\Controller\AppController;
|
||||
|
||||
/**
|
||||
* ExternalProductCatalogs Controller
|
||||
*
|
||||
* @property \CakeProducts\Model\Table\ExternalProductCatalogsTable $ExternalProductCatalogs
|
||||
*/
|
||||
class ExternalProductCatalogsController extends AppController
|
||||
{
|
||||
/**
|
||||
* Index method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$query = $this->ExternalProductCatalogs->find()
|
||||
->contain(['ProductCatalogs']);
|
||||
$externalProductCatalogs = $this->paginate($query);
|
||||
|
||||
$this->set(compact('externalProductCatalogs'));
|
||||
}
|
||||
|
||||
/**
|
||||
* View method
|
||||
*
|
||||
* @param string|null $id External Product Catalog id.
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
*/
|
||||
public function view($id = null)
|
||||
{
|
||||
$externalProductCatalog = $this->ExternalProductCatalogs->get($id, contain: ['ProductCatalogs']);
|
||||
$this->set(compact('externalProductCatalog'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$externalProductCatalog = $this->ExternalProductCatalogs->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
$externalProductCatalog = $this->ExternalProductCatalogs->patchEntity($externalProductCatalog, $this->request->getData());
|
||||
if ($this->ExternalProductCatalogs->save($externalProductCatalog)) {
|
||||
$this->Flash->success(__('The external product catalog has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
Log::debug(print_r('$externalProductCatalog->getErrors() next - failed /add', true));
|
||||
Log::debug(print_r($externalProductCatalog->getErrors(), true));
|
||||
$this->Flash->error(__('The external product catalog could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCatalogs = $this->ExternalProductCatalogs->ProductCatalogs->find('list', limit: 200)->all();
|
||||
$this->set(compact('externalProductCatalog', 'productCatalogs'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit method
|
||||
*
|
||||
* @param string|null $id External Product Catalog 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)
|
||||
{
|
||||
$externalProductCatalog = $this->ExternalProductCatalogs->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$externalProductCatalog = $this->ExternalProductCatalogs->patchEntity($externalProductCatalog, $this->request->getData());
|
||||
if ($this->ExternalProductCatalogs->save($externalProductCatalog)) {
|
||||
$this->Flash->success(__('The external product catalog has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
Log::debug(print_r('$externalProductCatalog->getErrors() next - failed /edit', true));
|
||||
Log::debug(print_r($externalProductCatalog->getErrors(), true));
|
||||
$this->Flash->error(__('The external product catalog could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCatalogs = $this->ExternalProductCatalogs->ProductCatalogs->find('list', limit: 200)->all();
|
||||
$this->set(compact('externalProductCatalog', 'productCatalogs'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete method
|
||||
*
|
||||
* @param string|null $id External Product Catalog 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']);
|
||||
$externalProductCatalog = $this->ExternalProductCatalogs->get($id);
|
||||
if ($this->ExternalProductCatalogs->delete($externalProductCatalog)) {
|
||||
$this->Flash->success(__('The external product catalog has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The external product catalog could not be deleted. Please, try again.'));
|
||||
}
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
}
|
||||
111
src/Controller/ProductCatalogsController.php
Normal file
111
src/Controller/ProductCatalogsController.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Controller;
|
||||
|
||||
use Cake\Datasource\Exception\RecordNotFoundException;
|
||||
use Cake\Http\Response;
|
||||
use Cake\Log\Log;
|
||||
use CakeProducts\Controller\AppController;
|
||||
use CakeProducts\Model\Table\ProductCatalogsTable;
|
||||
use CakeProducts\Service\InternalCatalogManagerService;
|
||||
|
||||
/**
|
||||
* ProductCatalogs Controller
|
||||
*
|
||||
* @property ProductCatalogsTable $ProductCatalogs
|
||||
*/
|
||||
class ProductCatalogsController extends AppController
|
||||
{
|
||||
/**
|
||||
* Index method
|
||||
*
|
||||
* @return Response|null|void Renders view
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$query = $this->ProductCatalogs->find();
|
||||
$productCatalogs = $this->paginate($query);
|
||||
|
||||
$this->set(compact('productCatalogs'));
|
||||
}
|
||||
|
||||
/**
|
||||
* View method
|
||||
*
|
||||
* @param string|null $id Product Catalog id.
|
||||
* @return Response|null|void Renders view
|
||||
* @throws RecordNotFoundException When record not found.
|
||||
*/
|
||||
public function view(InternalCatalogManagerService $catalogManagerService, $id = null)
|
||||
{
|
||||
$productCatalog = $catalogManagerService->getCatalog($id);
|
||||
$this->set(compact('productCatalog'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add method
|
||||
*
|
||||
* @return Response|null|void Redirects on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$productCatalog = $this->ProductCatalogs->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
$productCatalog = $this->ProductCatalogs->patchEntity($productCatalog, $this->request->getData());
|
||||
if ($this->ProductCatalogs->save($productCatalog)) {
|
||||
$this->Flash->success(__('The product catalog has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
Log::debug('failed to save new product catalog errors next');
|
||||
Log::debug(print_r('$productCatalog->getErrors()', true));
|
||||
Log::debug(print_r($productCatalog->getErrors(), true));
|
||||
|
||||
$this->Flash->error(__('The product catalog could not be saved. Please, try again.'));
|
||||
}
|
||||
$this->set(compact('productCatalog'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit method
|
||||
*
|
||||
* @param string|null $id Product Catalog id.
|
||||
* @return Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
* @throws RecordNotFoundException When record not found.
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
$productCatalog = $this->ProductCatalogs->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$productCatalog = $this->ProductCatalogs->patchEntity($productCatalog, $this->request->getData());
|
||||
if ($this->ProductCatalogs->save($productCatalog)) {
|
||||
$this->Flash->success(__('The product catalog has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
$this->Flash->error(__('The product catalog could not be saved. Please, try again.'));
|
||||
}
|
||||
$this->set(compact('productCatalog'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete method
|
||||
*
|
||||
* @param string|null $id Product Catalog id.
|
||||
* @return Response|null Redirects to index.
|
||||
* @throws RecordNotFoundException When record not found.
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productCatalog = $this->ProductCatalogs->get($id);
|
||||
if ($this->ProductCatalogs->delete($productCatalog)) {
|
||||
$this->Flash->success(__('The product catalog has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product catalog could not be deleted. Please, try again.'));
|
||||
}
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
}
|
||||
115
src/Controller/ProductCategoriesController.php
Normal file
115
src/Controller/ProductCategoriesController.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Controller;
|
||||
|
||||
use Cake\Log\Log;
|
||||
use CakeProducts\Controller\AppController;
|
||||
use CakeProducts\Service\InternalCatalogManagerService;
|
||||
|
||||
/**
|
||||
* ProductCategories Controller
|
||||
*
|
||||
* @property \CakeProducts\Model\Table\ProductCategoriesTable $ProductCategories
|
||||
*/
|
||||
class ProductCategoriesController extends AppController
|
||||
{
|
||||
/**
|
||||
* Index method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$query = $this->ProductCategories->find()
|
||||
->contain(['ProductCatalogs', 'ParentProductCategories']);
|
||||
$productCategories = $this->paginate($query);
|
||||
|
||||
$this->set(compact('productCategories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* View method
|
||||
*
|
||||
* @param string|null $id Product Category id.
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
*/
|
||||
public function view(InternalCatalogManagerService $catalogManagerService, $id = null)
|
||||
{
|
||||
$productCategory = $catalogManagerService->getCategory($id);
|
||||
$this->set(compact('productCategory'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add(InternalCatalogManagerService $catalogManagerService)
|
||||
{
|
||||
$productCategory = $this->ProductCategories->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
$postData = $this->request->getData();
|
||||
if ($this->request->getSession()->read('Auth.User.id')) {
|
||||
$postData['created_by'] = $this->request->getSession()->read('Auth.User.id');
|
||||
}
|
||||
$result = $catalogManagerService->createNewCategory($productCategory, $postData);
|
||||
Log::debug(print_r('$result from createNewCategory', true));
|
||||
Log::debug(print_r($result, true));
|
||||
if ($result['result']) {
|
||||
$this->Flash->success(__('The product category has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
$this->Flash->error(__('The product category could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCatalogs = $this->ProductCategories->ProductCatalogs->find('list', limit: 200)->all();
|
||||
$parentProductCategories = $this->ProductCategories->ParentProductCategories->find('list', limit: 200)->all();
|
||||
$this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit method
|
||||
*
|
||||
* @param string|null $id Product Category 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(InternalCatalogManagerService $catalogManagerService, $id = null)
|
||||
{
|
||||
$productCategory = $this->ProductCategories->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$productCategory = $this->ProductCategories->patchEntity($productCategory, $this->request->getData());
|
||||
if ($this->ProductCategories->save($productCategory)) {
|
||||
$this->Flash->success(__('The product category has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
$this->Flash->error(__('The product category could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCatalogs = $this->ProductCategories->ProductCatalogs->find('list', limit: 200)->all();
|
||||
$parentProductCategories = $this->ProductCategories->ParentProductCategories->find('list', limit: 200)->all();
|
||||
$this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete method
|
||||
*
|
||||
* @param string|null $id Product Category 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']);
|
||||
$productCategory = $this->ProductCategories->get($id);
|
||||
if ($this->ProductCategories->delete($productCategory)) {
|
||||
$this->Flash->success(__('The product category has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product category could not be deleted. Please, try again.'));
|
||||
}
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
}
|
||||
48
src/Controller/ProductCategoryAttributeOptionsController.php
Normal file
48
src/Controller/ProductCategoryAttributeOptionsController.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Controller;
|
||||
|
||||
use Cake\Log\Log;
|
||||
use CakeProducts\Controller\AppController;
|
||||
|
||||
/**
|
||||
* ProductCategoryAttributeOptions Controller
|
||||
*
|
||||
* @property \CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable $ProductCategoryAttributeOptions
|
||||
*/
|
||||
class ProductCategoryAttributeOptionsController extends AppController
|
||||
{
|
||||
/**
|
||||
* Add method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
Log::debug('inside product category attribute options controller add');
|
||||
|
||||
$productCategoryAttributeOption = $this->ProductCategoryAttributeOptions->newEmptyEntity();
|
||||
$this->set(compact('productCategoryAttributeOption'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete method
|
||||
*
|
||||
* @param string|null $id Product Category Attribute Option 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']);
|
||||
$productCategoryAttributeOption = $this->ProductCategoryAttributeOptions->get($id);
|
||||
if ($this->ProductCategoryAttributeOptions->delete($productCategoryAttributeOption)) {
|
||||
$this->Flash->success(__('The product category attribute option has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product category attribute option could not be deleted. Please, try again.'));
|
||||
}
|
||||
|
||||
return $this->redirect(['controller' => 'ProductCategoryAttributes', 'action' => 'view', $productCategoryAttributeOption->product_category_attribute_id]);
|
||||
}
|
||||
}
|
||||
144
src/Controller/ProductCategoryAttributesController.php
Normal file
144
src/Controller/ProductCategoryAttributesController.php
Normal file
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Controller;
|
||||
|
||||
use Cake\Datasource\Exception\RecordNotFoundException;
|
||||
use Cake\Http\Response;
|
||||
use Cake\Log\Log;
|
||||
use CakeProducts\Controller\AppController;
|
||||
use CakeProducts\Model\Enum\ProductCategoryAttributeTypeId;
|
||||
use CakeProducts\Model\Table\ProductCategoryAttributesTable;
|
||||
|
||||
/**
|
||||
* ProductCategoryAttributes Controller
|
||||
*
|
||||
* @property ProductCategoryAttributesTable $ProductCategoryAttributes
|
||||
*/
|
||||
class ProductCategoryAttributesController extends AppController
|
||||
{
|
||||
/**
|
||||
* Index method
|
||||
*
|
||||
* @return Response|null|void Renders view
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$query = $this->ProductCategoryAttributes->find()
|
||||
->contain(['ProductCategories']);
|
||||
$productCategoryAttributes = $this->paginate($query);
|
||||
|
||||
$this->set(compact('productCategoryAttributes'));
|
||||
}
|
||||
|
||||
/**
|
||||
* View method
|
||||
*
|
||||
* @param string|null $id Product Category Attribute id.
|
||||
* @return Response|null|void Renders view
|
||||
* @throws RecordNotFoundException When record not found.
|
||||
*/
|
||||
public function view($id = null)
|
||||
{
|
||||
$productCategoryAttribute = $this->ProductCategoryAttributes->get($id, contain: [
|
||||
'ProductCategories',
|
||||
'ProductCategoryAttributeOptions',
|
||||
]);
|
||||
$this->set(compact('productCategoryAttribute'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add method
|
||||
*
|
||||
* @return Response|null|void Redirects on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$productCategoryAttribute = $this->ProductCategoryAttributes->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
$postData = $this->request->getData();
|
||||
$saveOptions = [
|
||||
'associated' => ['ProductCategoryAttributeOptions'],
|
||||
];
|
||||
Log::debug(print_r('$postData', true));
|
||||
Log::debug(print_r($postData, true));
|
||||
// if ($this->request->getData('attribute_type_id') != ProductCategoryAttributeTypeId::Constrained) {
|
||||
// $saveOptions['associated'] = [];
|
||||
// $postData['product_category_attribute_options'] = [];
|
||||
// }
|
||||
Log::debug(print_r('$postData', true));
|
||||
Log::debug(print_r($postData, true));
|
||||
$productCategoryAttribute = $this->ProductCategoryAttributes->patchEntity($productCategoryAttribute, $postData, $saveOptions);
|
||||
if ($this->ProductCategoryAttributes->save($productCategoryAttribute, $saveOptions)) {
|
||||
$this->Flash->success(__('The product category attribute has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
Log::debug('failed to save new product category attribute errors next');
|
||||
Log::debug(print_r('$productCategoryAttribute->getErrors()', true));
|
||||
Log::debug(print_r($productCategoryAttribute->getErrors(), true));
|
||||
$this->Flash->error(__('The product category attribute could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategories = $this->ProductCategoryAttributes->ProductCategories->find('list', limit: 200)->all();
|
||||
$this->set(compact('productCategoryAttribute', 'productCategories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit method
|
||||
*
|
||||
* @param string|null $id Product Category Attribute id.
|
||||
* @return Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
* @throws RecordNotFoundException When record not found.
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
$productCategoryAttribute = $this->ProductCategoryAttributes->get($id, contain: ['ProductCategoryAttributeOptions']);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$postData = $this->request->getData();
|
||||
$saveOptions = [
|
||||
'associated' => ['ProductCategoryAttributeOptions'],
|
||||
];
|
||||
Log::debug(print_r('$postData', true));
|
||||
Log::debug(print_r($postData, true));
|
||||
// if ($this->request->getData('attribute_type_id') != ProductCategoryAttributeTypeId::Constrained) {
|
||||
// $saveOptions['associated'] = [];
|
||||
// $postData['product_category_attribute_options'] = [];
|
||||
// }
|
||||
Log::debug(print_r('$postData', true));
|
||||
Log::debug(print_r($postData, true));
|
||||
$productCategoryAttribute = $this->ProductCategoryAttributes->patchEntity($productCategoryAttribute, $postData, $saveOptions);
|
||||
|
||||
if ($this->ProductCategoryAttributes->save($productCategoryAttribute, $saveOptions)) {
|
||||
$this->Flash->success(__('The product category attribute has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
Log::debug('failed to save product category attribute on edit errors next');
|
||||
Log::debug(print_r('$productCategoryAttribute->getErrors()', true));
|
||||
Log::debug(print_r($productCategoryAttribute->getErrors(), true));
|
||||
$this->Flash->error(__('The product category attribute could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategories = $this->ProductCategoryAttributes->ProductCategories->find('list', limit: 200)->all();
|
||||
$this->set(compact('productCategoryAttribute', 'productCategories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete method
|
||||
*
|
||||
* @param string|null $id Product Category Attribute id.
|
||||
* @return Response|null Redirects to index.
|
||||
* @throws RecordNotFoundException When record not found.
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productCategoryAttribute = $this->ProductCategoryAttributes->get($id);
|
||||
if ($this->ProductCategoryAttributes->delete($productCategoryAttribute)) {
|
||||
$this->Flash->success(__('The product category attribute has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product category attribute could not be deleted. Please, try again.'));
|
||||
}
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
}
|
||||
110
src/Controller/ProductsController.php
Normal file
110
src/Controller/ProductsController.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Controller;
|
||||
|
||||
use Cake\Log\Log;
|
||||
use CakeProducts\Controller\AppController;
|
||||
|
||||
/**
|
||||
* Products Controller
|
||||
*
|
||||
* @property \CakeProducts\Model\Table\ProductsTable $Products
|
||||
*/
|
||||
class ProductsController extends AppController
|
||||
{
|
||||
/**
|
||||
* Index method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$query = $this->Products->find()
|
||||
->contain(['ProductCategories']);
|
||||
$products = $this->paginate($query);
|
||||
|
||||
$this->set(compact('products'));
|
||||
}
|
||||
|
||||
/**
|
||||
* View method
|
||||
*
|
||||
* @param string|null $id Product id.
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
*/
|
||||
public function view($id = null)
|
||||
{
|
||||
$product = $this->Products->get($id, contain: ['ProductCategories']);
|
||||
$this->set(compact('product'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$product = $this->Products->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
$product = $this->Products->patchEntity($product, $this->request->getData());
|
||||
if ($this->Products->save($product)) {
|
||||
$this->Flash->success(__('The product has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
Log::debug(print_r('$product->getErrors() next - failed in products/add', true));
|
||||
Log::debug(print_r($product->getErrors(), true));
|
||||
$this->Flash->error(__('The product could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategories = $this->Products->ProductCategories->find('list', limit: 200)->all();
|
||||
$this->set(compact('product', 'productCategories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit method
|
||||
*
|
||||
* @param string|null $id Product 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)
|
||||
{
|
||||
$product = $this->Products->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$product = $this->Products->patchEntity($product, $this->request->getData());
|
||||
if ($this->Products->save($product)) {
|
||||
$this->Flash->success(__('The product has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
Log::debug(print_r('$product->getErrors() next - failed in products/edit', true));
|
||||
Log::debug(print_r($product->getErrors(), true));
|
||||
$this->Flash->error(__('The product could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategories = $this->Products->ProductCategories->find('list', limit: 200)->all();
|
||||
$this->set(compact('product', 'productCategories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete method
|
||||
*
|
||||
* @param string|null $id Product 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']);
|
||||
$product = $this->Products->get($id);
|
||||
if ($this->Products->delete($product)) {
|
||||
$this->Flash->success(__('The product has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product could not be deleted. Please, try again.'));
|
||||
}
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user