allow for extending the table class more easily - catalogs & categories
	
		
			
	
		
	
	
		
			
				
	
				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
							
								
									9e5df45f59
								
							
						
					
					
						commit
						3f45e46f31
					
				|  | @ -7,6 +7,8 @@ use Cake\Core\Configure; | ||||||
| use Cake\Datasource\Exception\RecordNotFoundException; | use Cake\Datasource\Exception\RecordNotFoundException; | ||||||
| use Cake\Http\Response; | use Cake\Http\Response; | ||||||
| use Cake\Log\Log; | use Cake\Log\Log; | ||||||
|  | use Cake\ORM\Table; | ||||||
|  | use Cake\ORM\TableRegistry; | ||||||
| use CakeProducts\Controller\AppController; | use CakeProducts\Controller\AppController; | ||||||
| use CakeProducts\Model\Table\ProductCatalogsTable; | use CakeProducts\Model\Table\ProductCatalogsTable; | ||||||
| use CakeProducts\Service\CatalogManagerService; | use CakeProducts\Service\CatalogManagerService; | ||||||
|  | @ -18,6 +20,8 @@ use CakeProducts\Service\CatalogManagerService; | ||||||
|  */ |  */ | ||||||
| class ProductCatalogsController extends AppController | class ProductCatalogsController extends AppController | ||||||
| { | { | ||||||
|  |     protected ?Table $_productCatalogsTable = null; | ||||||
|  | 
 | ||||||
|     /** |     /** | ||||||
|      * Index method |      * Index method | ||||||
|      * |      * | ||||||
|  | @ -25,7 +29,7 @@ class ProductCatalogsController extends AppController | ||||||
|      */ |      */ | ||||||
|     public function index() |     public function index() | ||||||
|     { |     { | ||||||
|         $query = $this->ProductCatalogs->find(); |         $query = $this->getProductCatalogsTable()->find(); | ||||||
|         $productCatalogs = $this->paginate($query); |         $productCatalogs = $this->paginate($query); | ||||||
| 
 | 
 | ||||||
|         $this->set(compact('productCatalogs')); |         $this->set(compact('productCatalogs')); | ||||||
|  | @ -44,7 +48,7 @@ class ProductCatalogsController extends AppController | ||||||
|         if (Configure::read('CakeProducts.internal.syncExternally', false)) { |         if (Configure::read('CakeProducts.internal.syncExternally', false)) { | ||||||
|             $contain[] = 'ExternalProductCatalogs'; |             $contain[] = 'ExternalProductCatalogs'; | ||||||
|         } |         } | ||||||
|         $productCatalog = $this->ProductCatalogs->get($id, contain: $contain); |         $productCatalog = $this->getProductCatalogsTable()->get($id, contain: $contain); | ||||||
|         $this->set(compact('productCatalog')); |         $this->set(compact('productCatalog')); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -55,10 +59,11 @@ class ProductCatalogsController extends AppController | ||||||
|      */ |      */ | ||||||
|     public function add() |     public function add() | ||||||
|     { |     { | ||||||
|         $productCatalog = $this->ProductCatalogs->newEmptyEntity(); |         $productCatalogsTable = $this->getProductCatalogsTable(); | ||||||
|  |         $productCatalog = $productCatalogsTable->newEmptyEntity(); | ||||||
|         if ($this->request->is('post')) { |         if ($this->request->is('post')) { | ||||||
|             $productCatalog = $this->ProductCatalogs->patchEntity($productCatalog, $this->request->getData()); |             $productCatalog = $productCatalogsTable->patchEntity($productCatalog, $this->request->getData()); | ||||||
|             if ($this->ProductCatalogs->save($productCatalog)) { |             if ($productCatalogsTable->save($productCatalog)) { | ||||||
|                 $this->Flash->success(__('The product catalog has been saved.')); |                 $this->Flash->success(__('The product catalog has been saved.')); | ||||||
| 
 | 
 | ||||||
|                 return $this->redirect(['action' => 'index']); |                 return $this->redirect(['action' => 'index']); | ||||||
|  | @ -81,10 +86,11 @@ class ProductCatalogsController extends AppController | ||||||
|      */ |      */ | ||||||
|     public function edit($id = null) |     public function edit($id = null) | ||||||
|     { |     { | ||||||
|         $productCatalog = $this->ProductCatalogs->get($id, contain: []); |         $productCatalogsTable = $this->getProductCatalogsTable(); | ||||||
|  |         $productCatalog = $productCatalogsTable->get($id, contain: []); | ||||||
|         if ($this->request->is(['patch', 'post', 'put'])) { |         if ($this->request->is(['patch', 'post', 'put'])) { | ||||||
|             $productCatalog = $this->ProductCatalogs->patchEntity($productCatalog, $this->request->getData()); |             $productCatalog = $productCatalogsTable->patchEntity($productCatalog, $this->request->getData()); | ||||||
|             if ($this->ProductCatalogs->save($productCatalog)) { |             if ($productCatalogsTable->save($productCatalog)) { | ||||||
|                 $this->Flash->success(__('The product catalog has been saved.')); |                 $this->Flash->success(__('The product catalog has been saved.')); | ||||||
| 
 | 
 | ||||||
|                 return $this->redirect(['action' => 'index']); |                 return $this->redirect(['action' => 'index']); | ||||||
|  | @ -104,8 +110,9 @@ class ProductCatalogsController extends AppController | ||||||
|     public function delete($id = null) |     public function delete($id = null) | ||||||
|     { |     { | ||||||
|         $this->request->allowMethod(['post', 'delete']); |         $this->request->allowMethod(['post', 'delete']); | ||||||
|         $productCatalog = $this->ProductCatalogs->get($id); |         $productCatalogsTable = $this->getProductCatalogsTable(); | ||||||
|         if ($this->ProductCatalogs->delete($productCatalog)) { |         $productCatalog = $productCatalogsTable->get($id); | ||||||
|  |         if ($productCatalogsTable->delete($productCatalog)) { | ||||||
|             $this->Flash->success(__('The product catalog has been deleted.')); |             $this->Flash->success(__('The product catalog has been deleted.')); | ||||||
|         } else { |         } else { | ||||||
|             $this->Flash->error(__('The product catalog could not be deleted. Please, try again.')); |             $this->Flash->error(__('The product catalog could not be deleted. Please, try again.')); | ||||||
|  | @ -113,4 +120,19 @@ class ProductCatalogsController extends AppController | ||||||
| 
 | 
 | ||||||
|         return $this->redirect(['action' => 'index']); |         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; | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -3,7 +3,10 @@ declare(strict_types=1); | ||||||
| 
 | 
 | ||||||
| namespace CakeProducts\Controller; | namespace CakeProducts\Controller; | ||||||
| 
 | 
 | ||||||
|  | use Cake\Core\Configure; | ||||||
| use Cake\Log\Log; | use Cake\Log\Log; | ||||||
|  | use Cake\ORM\Table; | ||||||
|  | use Cake\ORM\TableRegistry; | ||||||
| use Cake\Utility\Text; | use Cake\Utility\Text; | ||||||
| use CakeProducts\Controller\AppController; | use CakeProducts\Controller\AppController; | ||||||
| use CakeProducts\Service\CatalogManagerService; | use CakeProducts\Service\CatalogManagerService; | ||||||
|  | @ -15,6 +18,22 @@ use CakeProducts\Service\CatalogManagerService; | ||||||
|  */ |  */ | ||||||
| class ProductCategoriesController extends AppController | class ProductCategoriesController extends AppController | ||||||
| { | { | ||||||
|  |     protected ?Table $_productCategoriesTable = null; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Gets the users table instance | ||||||
|  |      * | ||||||
|  |      * @return Table | ||||||
|  |      */ | ||||||
|  |     public function getProductCategoriesTable() | ||||||
|  |     { | ||||||
|  |         if ($this->_productCategoriesTable instanceof Table) { | ||||||
|  |             return $this->_productCategoriesTable; | ||||||
|  |         } | ||||||
|  |         $this->_productCategoriesTable = TableRegistry::getTableLocator()->get(Configure::read('ProductCategories.table', 'CakeProducts.ProductCategories')); | ||||||
|  | 
 | ||||||
|  |         return $this->_productCategoriesTable; | ||||||
|  |     } | ||||||
|     /** |     /** | ||||||
|      * Index method |      * Index method | ||||||
|      * |      * | ||||||
|  | @ -22,7 +41,7 @@ class ProductCategoriesController extends AppController | ||||||
|      */ |      */ | ||||||
|     public function index() |     public function index() | ||||||
|     { |     { | ||||||
|         $query = $this->ProductCategories->find() |         $query = $this->getProductCategoriesTable()->find() | ||||||
|             ->contain(['ProductCatalogs', 'ParentProductCategories']); |             ->contain(['ProductCatalogs', 'ParentProductCategories']); | ||||||
|         $productCategories = $this->paginate($query); |         $productCategories = $this->paginate($query); | ||||||
| 
 | 
 | ||||||
|  | @ -38,7 +57,7 @@ class ProductCategoriesController extends AppController | ||||||
|      */ |      */ | ||||||
|     public function view($id = null) |     public function view($id = null) | ||||||
|     { |     { | ||||||
|         $productCategory = $this->ProductCategories->get($id, contain: ['ProductCatalogs', 'ParentProductCategories', 'ChildProductCategories']); |         $productCategory = $this->getProductCategoriesTable()->get($id, contain: ['ProductCatalogs', 'ParentProductCategories', 'ChildProductCategories']); | ||||||
|         $this->set(compact('productCategory')); |         $this->set(compact('productCategory')); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -49,7 +68,8 @@ class ProductCategoriesController extends AppController | ||||||
|      */ |      */ | ||||||
|     public function add() |     public function add() | ||||||
|     { |     { | ||||||
|         $productCategory = $this->ProductCategories->newEmptyEntity(); |         $productCategoriesTable = $this->getProductCategoriesTable(); | ||||||
|  |         $productCategory = $productCategoriesTable->newEmptyEntity(); | ||||||
|         if ($this->request->is('post')) { |         if ($this->request->is('post')) { | ||||||
|             $postData = $this->request->getData(); |             $postData = $this->request->getData(); | ||||||
|             $saveOptions = [ |             $saveOptions = [ | ||||||
|  | @ -61,7 +81,7 @@ class ProductCategoriesController extends AppController | ||||||
|             if (!array_key_exists('internal_id', $postData) || !$postData['internal_id']) { |             if (!array_key_exists('internal_id', $postData) || !$postData['internal_id']) { | ||||||
|                 $postData['internal_id'] = Text::uuid(); |                 $postData['internal_id'] = Text::uuid(); | ||||||
|             } |             } | ||||||
|             $productCategory = $this->ProductCategories->patchEntity($productCategory, $postData, $saveOptions); |             $productCategory = $productCategoriesTable->patchEntity($productCategory, $postData, $saveOptions); | ||||||
|             if ($productCategory->getErrors()) { |             if ($productCategory->getErrors()) { | ||||||
|                 Log::debug(print_r('$productCategory->getErrors() next - failed to save from create new product category', true)); |                 Log::debug(print_r('$productCategory->getErrors() next - failed to save from create new product category', true)); | ||||||
|                 Log::debug(print_r($productCategory->getErrors(), true)); |                 Log::debug(print_r($productCategory->getErrors(), true)); | ||||||
|  | @ -73,8 +93,8 @@ class ProductCategoriesController extends AppController | ||||||
|             } |             } | ||||||
|             $this->Flash->error(__('The product category could not be saved. Please, try again.')); |             $this->Flash->error(__('The product category could not be saved. Please, try again.')); | ||||||
|         } |         } | ||||||
|         $productCatalogs = $this->ProductCategories->ProductCatalogs->find('list', limit: 200)->all(); |         $productCatalogs = $productCategoriesTable->ProductCatalogs->find('list', limit: 200)->all(); | ||||||
|         $parentProductCategories = $this->ProductCategories->ParentProductCategories->find('treeList', limit: 200)->toArray(); |         $parentProductCategories = $productCategoriesTable->ParentProductCategories->find('treeList', limit: 200)->toArray(); | ||||||
|         $this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories')); |         $this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories')); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -87,19 +107,20 @@ class ProductCategoriesController extends AppController | ||||||
|      */ |      */ | ||||||
|     public function edit($id = null) |     public function edit($id = null) | ||||||
|     { |     { | ||||||
|         $productCategory = $this->ProductCategories->get($id, contain: []); |         $productCategoriesTable = $this->getProductCategoriesTable(); | ||||||
|  |         $productCategory = $productCategoriesTable->get($id, contain: []); | ||||||
|         if ($this->request->is(['patch', 'post', 'put'])) { |         if ($this->request->is(['patch', 'post', 'put'])) { | ||||||
|             $postData = $this->request->getData(); |             $postData = $this->request->getData(); | ||||||
|             $productCategory = $this->ProductCategories->patchEntity($productCategory, $postData); |             $productCategory = $productCategoriesTable->patchEntity($productCategory, $postData); | ||||||
|             if ($this->ProductCategories->save($productCategory)) { |             if ($productCategoriesTable->save($productCategory)) { | ||||||
|                 $this->Flash->success(__('The product category has been saved.')); |                 $this->Flash->success(__('The product category has been saved.')); | ||||||
| 
 | 
 | ||||||
|                 return $this->redirect(['action' => 'index']); |                 return $this->redirect(['action' => 'index']); | ||||||
|             } |             } | ||||||
|             $this->Flash->error(__('The product category could not be saved. Please, try again.')); |             $this->Flash->error(__('The product category could not be saved. Please, try again.')); | ||||||
|         } |         } | ||||||
|         $productCatalogs = $this->ProductCategories->ProductCatalogs->find('list', limit: 200)->all(); |         $productCatalogs = $productCategoriesTable->ProductCatalogs->find('list', limit: 200)->all(); | ||||||
|         $parentProductCategories = $this->ProductCategories->ParentProductCategories->find('list', limit: 200)->all(); |         $parentProductCategories = $productCategoriesTable->ParentProductCategories->find('list', limit: 200)->all(); | ||||||
|         $this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories')); |         $this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories')); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -113,8 +134,10 @@ class ProductCategoriesController extends AppController | ||||||
|     public function delete($id = null) |     public function delete($id = null) | ||||||
|     { |     { | ||||||
|         $this->request->allowMethod(['post', 'delete']); |         $this->request->allowMethod(['post', 'delete']); | ||||||
|         $productCategory = $this->ProductCategories->get($id); |         $productCategoriesTable = $this->getProductCategoriesTable(); | ||||||
|         if ($this->ProductCategories->delete($productCategory)) { | 
 | ||||||
|  |         $productCategory = $productCategoriesTable->get($id); | ||||||
|  |         if ($productCategoriesTable->delete($productCategory)) { | ||||||
|             $this->Flash->success(__('The product category has been deleted.')); |             $this->Flash->success(__('The product category has been deleted.')); | ||||||
|         } else { |         } else { | ||||||
|             $this->Flash->error(__('The product category could not be deleted. Please, try again.')); |             $this->Flash->error(__('The product category could not be deleted. Please, try again.')); | ||||||
|  | @ -128,12 +151,13 @@ class ProductCategoriesController extends AppController | ||||||
|      */ |      */ | ||||||
|     public function select() |     public function select() | ||||||
|     { |     { | ||||||
|         $this->ProductCategories->behaviors()->get('Tree')->setConfig([ |         $productCategoriesTable = $this->getProductCategoriesTable(); | ||||||
|  |         $productCategoriesTable->behaviors()->get('Tree')->setConfig([ | ||||||
|             'scope' => [ |             'scope' => [ | ||||||
|                 'product_catalog_id' => $this->request->getQuery('product_catalog_id', -1), |                 'product_catalog_id' => $this->request->getQuery('product_catalog_id', -1), | ||||||
|             ], |             ], | ||||||
|         ]); |         ]); | ||||||
|         $productCategories = $this->ProductCategories |         $productCategories = $productCategoriesTable | ||||||
|             ->find('treeList') |             ->find('treeList') | ||||||
| //            ->where(['product_catalog_id' => $this->request->getQuery('product_catalog_id', -1)])
 | //            ->where(['product_catalog_id' => $this->request->getQuery('product_catalog_id', -1)])
 | ||||||
|             ->orderBy(['ProductCategories.name']) |             ->orderBy(['ProductCategories.name']) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue