from main app code base

This commit is contained in:
2025-03-27 01:11:41 -07:00
parent b17634c08a
commit d9a59fb82b
18 changed files with 131 additions and 1034 deletions

View File

@@ -9,7 +9,9 @@ use Cake\Core\ContainerInterface;
use Cake\Core\PluginApplicationInterface;
use Cake\Http\MiddlewareQueue;
use Cake\Routing\RouteBuilder;
use CakeProducts\Queue\Task\ProductCategories\CreateTask;
use CakeProducts\Service\CatalogManagerServiceProvider;
use CakeProducts\Service\ExternalCatalogManagerService;
/**
* Plugin for CakeProducts
@@ -90,6 +92,5 @@ class CakeProductsPlugin extends BasePlugin
public function services(ContainerInterface $container): void
{
// Add your services here
$container->addServiceProvider(new CatalogManagerServiceProvider());
}
}

View File

@@ -4,7 +4,15 @@ declare(strict_types=1);
namespace CakeProducts\Controller;
use App\Controller\AppController as BaseController;
use Cake\Log\Log;
class AppController extends BaseController
{
function initialize(): void
{
parent::initialize(); // TODO: Change the autogenerated stub
Log::debug('inside cake products app controlleri initialize');
}
}

View File

@@ -5,7 +5,6 @@ namespace CakeProducts\Controller;
use Cake\Log\Log;
use CakeProducts\Controller\AppController;
use CakeProducts\Service\InternalCatalogManagerService;
/**
* ExternalProductCatalogs Controller
@@ -46,24 +45,18 @@ class ExternalProductCatalogsController extends AppController
*
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
*/
public function add(InternalCatalogManagerService $catalogManagerService)
public function add()
{
$externalProductCatalog = $this->ExternalProductCatalogs->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->createNewExternalCatalog($externalProductCatalog, $postData);
Log::debug(print_r('$result from createNewExternalCatalog', true));
Log::debug(print_r($result, true));
if ($result['result']) {
$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));
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();

View File

@@ -3,12 +3,13 @@ declare(strict_types=1);
namespace CakeProducts\Controller;
use Cake\Core\Configure;
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;
use CakeProducts\Service\CatalogManagerService;
/**
* ProductCatalogs Controller
@@ -37,9 +38,13 @@ class ProductCatalogsController extends AppController
* @return Response|null|void Renders view
* @throws RecordNotFoundException When record not found.
*/
public function view(InternalCatalogManagerService $catalogManagerService, $id = null)
public function view($id = null)
{
$productCatalog = $catalogManagerService->getCatalog($id);
$contain = ['ProductCategories'];
if (Configure::read('CakeProducts.internal.syncExternally', false)) {
$contain[] = 'ExternalProductCatalogs';
}
$productCatalog = $this->ProductCatalogs->get($id, contain: $contain);
$this->set(compact('productCatalog'));
}

View File

@@ -4,8 +4,9 @@ declare(strict_types=1);
namespace CakeProducts\Controller;
use Cake\Log\Log;
use Cake\Utility\Text;
use CakeProducts\Controller\AppController;
use CakeProducts\Service\InternalCatalogManagerService;
use CakeProducts\Service\CatalogManagerService;
/**
* ProductCategories Controller
@@ -35,9 +36,9 @@ class ProductCategoriesController extends AppController
* @return \Cake\Http\Response|null|void Renders view
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function view(InternalCatalogManagerService $catalogManagerService, $id = null)
public function view($id = null)
{
$productCategory = $catalogManagerService->getCategory($id);
$productCategory = $this->ProductCategories->get($id, contain: ['ProductCatalogs', 'ParentProductCategories', 'ChildProductCategories']);
$this->set(compact('productCategory'));
}
@@ -46,18 +47,26 @@ class ProductCategoriesController extends AppController
*
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
*/
public function add(InternalCatalogManagerService $catalogManagerService)
public function add()
{
$productCategory = $this->ProductCategories->newEmptyEntity();
if ($this->request->is('post')) {
$postData = $this->request->getData();
$saveOptions = [
'associated' => [],
];
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']) {
if (!array_key_exists('internal_id', $postData) || !$postData['internal_id']) {
$postData['internal_id'] = Text::uuid();
}
$productCategory = $this->ProductCategories->patchEntity($productCategory, $postData, $saveOptions);
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(), true));
}
if ($this->ProductCategories->save($productCategory, $saveOptions)) {
$this->Flash->success(__('The product category has been saved.'));
return $this->redirect(['action' => 'index']);
@@ -65,7 +74,7 @@ class ProductCategoriesController extends AppController
$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();
$parentProductCategories = $this->ProductCategories->ParentProductCategories->find('treeList', limit: 200)->toArray();
$this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories'));
}
@@ -76,11 +85,12 @@ class ProductCategoriesController extends AppController
* @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)
public function edit($id = null)
{
$productCategory = $this->ProductCategories->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) {
$productCategory = $this->ProductCategories->patchEntity($productCategory, $this->request->getData());
$postData = $this->request->getData();
$productCategory = $this->ProductCategories->patchEntity($productCategory, $postData);
if ($this->ProductCategories->save($productCategory)) {
$this->Flash->success(__('The product category has been saved.'));
@@ -112,4 +122,23 @@ class ProductCategoriesController extends AppController
return $this->redirect(['action' => 'index']);
}
/**
* @return \Cake\Http\Response|null|void Renders view
*/
public function select()
{
$this->ProductCategories->behaviors()->get('Tree')->setConfig([
'scope' => [
'product_catalog_id' => $this->request->getQuery('product_catalog_id', -1),
],
]);
$productCategories = $this->ProductCategories
->find('treeList')
// ->where(['product_catalog_id' => $this->request->getQuery('product_catalog_id', -1)])
->orderBy(['ProductCategories.name'])
->toArray();
$this->set(compact('productCategories'));
}
}

View File

@@ -9,6 +9,7 @@ use Cake\Log\Log;
use CakeProducts\Controller\AppController;
use CakeProducts\Model\Enum\ProductCategoryAttributeTypeId;
use CakeProducts\Model\Table\ProductCategoryAttributesTable;
use CakeProducts\Service\CatalogManagerService;
/**
* ProductCategoryAttributes Controller
@@ -57,18 +58,21 @@ class ProductCategoryAttributesController extends AppController
$productCategoryAttribute = $this->ProductCategoryAttributes->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');
}
Log::debug(print_r('$postData', true));
Log::debug(print_r($postData, true));
$saveOptions = [
'associated' => ['ProductCategoryAttributeOptions'],
'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 ($productCategoryAttribute->getErrors()) {
Log::debug(print_r('$productCategoryAttribute->getErrors() next - failed to save from create new product category attribute', true));
Log::debug(print_r($productCategoryAttribute->getErrors(), true));
}
if ($this->ProductCategoryAttributes->save($productCategoryAttribute, $saveOptions)) {
$this->Flash->success(__('The product category attribute has been saved.'));
@@ -79,7 +83,7 @@ class ProductCategoryAttributesController extends AppController
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();
$productCategories = $this->ProductCategoryAttributes->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all();
$this->set(compact('productCategoryAttribute', 'productCategories'));
}
@@ -118,7 +122,7 @@ class ProductCategoryAttributesController extends AppController
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();
$productCategories = $this->ProductCategoryAttributes->ProductCategories->find('list', limit: 200, keyField: 'internal_id', valueField: 'name')->all();
$this->set(compact('productCategoryAttribute', 'productCategories'));
}

View File

@@ -59,7 +59,7 @@ class ProductsController extends AppController
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();
$productCategories = $this->Products->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name' )->all();
$this->set(compact('product', 'productCategories'));
}