getProductCatalogsTable()->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->getProductCatalogsTable()->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->getProductCatalogsTable(); $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->getProductCatalogsTable(); $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->getProductCatalogsTable(); $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 getProductCatalogsTable() { if ($this->_productCatalogsTable instanceof Table) { return $this->_productCatalogsTable; } $this->_productCatalogsTable = TableRegistry::getTableLocator()->get(Configure::read('ProductCatalogs.table', 'CakeProducts.ProductCatalogs')); return $this->_productCatalogsTable; } }