_defaultTable = 'CakeProducts.ProductCatalogs'; // $this->_tableConfigKey = 'CakeProducts.ProductCatalogs.table'; } /** * Index method * * @return Response|null|void Renders view */ public function index() { $query = $this->getTable()->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($id = null) { $contain = ['ProductCategories']; if (Configure::read('CakeProducts.internal.syncExternally', false)) { $contain[] = 'ExternalProductCatalogs'; } $productCatalog = $this->getTable()->get($id, contain: $contain); $this->set(compact('productCatalog')); } /** * Add method * * @return Response|null|void Redirects on successful add, renders view otherwise. */ public function add() { $productCatalogsTable = $this->getTable(); $productCatalog = $productCatalogsTable->newEmptyEntity(); if ($this->request->is('post')) { $productCatalog = $productCatalogsTable->patchEntity($productCatalog, $this->request->getData()); if ($productCatalogsTable->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) { $productCatalogsTable = $this->getTable(); $productCatalog = $productCatalogsTable->get($id, contain: []); if ($this->request->is(['patch', 'post', 'put'])) { $productCatalog = $productCatalogsTable->patchEntity($productCatalog, $this->request->getData()); if ($productCatalogsTable->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']); $productCatalogsTable = $this->getTable(); $productCatalog = $productCatalogsTable->get($id); if ($productCatalogsTable->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']); } /** * 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.ProductCatalogs.table', 'CakeProducts.ProductCatalogs') ); return $this->_table; } }