composer update + load more dev dependencies for code quality, checkstyle fix
This commit is contained in:
+34
-38
@@ -13,9 +13,9 @@ use Cake\Routing\RouteBuilder;
|
||||
/**
|
||||
* Plugin for CakeProducts
|
||||
*/
|
||||
class CakeProductsPlugin extends BasePlugin
|
||||
{
|
||||
/**
|
||||
class CakeProductsPlugin extends BasePlugin {
|
||||
|
||||
/**
|
||||
* Load all the plugin configuration and bootstrap logic.
|
||||
*
|
||||
* The host application is provided as an argument. This allows you to load
|
||||
@@ -24,11 +24,10 @@ class CakeProductsPlugin extends BasePlugin
|
||||
* @param \Cake\Core\PluginApplicationInterface $app The host application
|
||||
* @return void
|
||||
*/
|
||||
public function bootstrap(PluginApplicationInterface $app): void
|
||||
{
|
||||
}
|
||||
public function bootstrap(PluginApplicationInterface $app): void {
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add routes for the plugin.
|
||||
*
|
||||
* If your plugin has many routes and you would like to isolate them into a separate file,
|
||||
@@ -37,57 +36,54 @@ class CakeProductsPlugin extends BasePlugin
|
||||
* @param \Cake\Routing\RouteBuilder $routes The route builder to update.
|
||||
* @return void
|
||||
*/
|
||||
public function routes(RouteBuilder $routes): void
|
||||
{
|
||||
$routes->plugin(
|
||||
'CakeProducts',
|
||||
['path' => '/cake-products'],
|
||||
function (RouteBuilder $builder) {
|
||||
// Add custom routes here
|
||||
public function routes(RouteBuilder $routes): void {
|
||||
$routes->plugin(
|
||||
'CakeProducts',
|
||||
['path' => '/cake-products'],
|
||||
function (RouteBuilder $builder) {
|
||||
// Add custom routes here
|
||||
|
||||
$builder->fallbacks();
|
||||
}
|
||||
);
|
||||
parent::routes($routes);
|
||||
}
|
||||
$builder->fallbacks();
|
||||
},
|
||||
);
|
||||
parent::routes($routes);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add middleware for the plugin.
|
||||
*
|
||||
* @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to update.
|
||||
* @return \Cake\Http\MiddlewareQueue
|
||||
*/
|
||||
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
|
||||
{
|
||||
// Add your middlewares here
|
||||
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue {
|
||||
// Add your middlewares here
|
||||
|
||||
return $middlewareQueue;
|
||||
}
|
||||
return $middlewareQueue;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add commands for the plugin.
|
||||
*
|
||||
* @param \Cake\Console\CommandCollection $commands The command collection to update.
|
||||
* @return \Cake\Console\CommandCollection
|
||||
*/
|
||||
public function console(CommandCollection $commands): CommandCollection
|
||||
{
|
||||
// Add your commands here
|
||||
public function console(CommandCollection $commands): CommandCollection {
|
||||
// Add your commands here
|
||||
|
||||
$commands = parent::console($commands);
|
||||
$commands = parent::console($commands);
|
||||
|
||||
return $commands;
|
||||
}
|
||||
return $commands;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Register application container services.
|
||||
*
|
||||
* @link https://book.cakephp.org/4/en/development/dependency-injection.html#dependency-injection
|
||||
* @param \Cake\Core\ContainerInterface $container The Container to update.
|
||||
* @return void
|
||||
* @link https://book.cakephp.org/4/en/development/dependency-injection.html#dependency-injection
|
||||
*/
|
||||
public function services(ContainerInterface $container): void
|
||||
{
|
||||
// Add your services here
|
||||
}
|
||||
public function services(ContainerInterface $container): void {
|
||||
// Add your services here
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,5 @@ namespace CakeProducts\Controller;
|
||||
|
||||
use App\Controller\AppController as BaseController;
|
||||
|
||||
class AppController extends BaseController
|
||||
{
|
||||
class AppController extends BaseController {
|
||||
}
|
||||
|
||||
@@ -3,130 +3,122 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Controller;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Log\Log;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\ORM\TableRegistry;
|
||||
|
||||
/**
|
||||
* ExternalProductCatalogs Controller
|
||||
*
|
||||
* @property \CakeProducts\Model\Table\ExternalProductCatalogsTable $ExternalProductCatalogs
|
||||
*/
|
||||
class ExternalProductCatalogsController extends AppController
|
||||
{
|
||||
class ExternalProductCatalogsController extends AppController {
|
||||
|
||||
// use OverrideTableTrait;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
public function initialize(): void {
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
// $this->_defaultTable = 'CakeProducts.ExternalProductCatalogs';
|
||||
// $this->_tableConfigKey = 'CakeProducts.ExternalProductCatalogs.table';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Index method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$query = $this->ExternalProductCatalogs->find()
|
||||
->contain(['ProductCatalogs']);
|
||||
$externalProductCatalogs = $this->paginate($query);
|
||||
public function index() {
|
||||
$query = $this->ExternalProductCatalogs->find()
|
||||
->contain(['ProductCatalogs']);
|
||||
$externalProductCatalogs = $this->paginate($query);
|
||||
|
||||
$this->set(compact('externalProductCatalogs'));
|
||||
}
|
||||
$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.
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function view($id = null)
|
||||
{
|
||||
$externalProductCatalog = $this->ExternalProductCatalogs->get($id, contain: ['ProductCatalogs']);
|
||||
$this->set(compact('externalProductCatalog'));
|
||||
}
|
||||
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')) {
|
||||
$saveOptions = [
|
||||
'associated' => [
|
||||
'ExternalProductCatalogsProductCatalogs',
|
||||
],
|
||||
];
|
||||
$postData = $this->request->getData();
|
||||
Log::debug(print_r('$postData', true));
|
||||
Log::debug(print_r($postData, true));
|
||||
$externalProductCatalog = $this->ExternalProductCatalogs->patchEntity($externalProductCatalog, $postData, $saveOptions);
|
||||
if ($this->ExternalProductCatalogs->save($externalProductCatalog, $saveOptions)) {
|
||||
$this->Flash->success(__('The external product catalog has been saved.'));
|
||||
public function add() {
|
||||
$externalProductCatalog = $this->ExternalProductCatalogs->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
$saveOptions = [
|
||||
'associated' => [
|
||||
'ExternalProductCatalogsProductCatalogs',
|
||||
],
|
||||
];
|
||||
$postData = $this->request->getData();
|
||||
Log::debug(print_r('$postData', true));
|
||||
Log::debug(print_r($postData, true));
|
||||
$externalProductCatalog = $this->ExternalProductCatalogs->patchEntity($externalProductCatalog, $postData, $saveOptions);
|
||||
if ($this->ExternalProductCatalogs->save($externalProductCatalog, $saveOptions)) {
|
||||
$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'));
|
||||
}
|
||||
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.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
*/
|
||||
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.'));
|
||||
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'));
|
||||
}
|
||||
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.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
*/
|
||||
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.'));
|
||||
}
|
||||
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']);
|
||||
}
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,49 +3,45 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Controller;
|
||||
|
||||
use Cake\Datasource\Exception\RecordNotFoundException;
|
||||
use Cake\Http\Response;
|
||||
use Cake\Log\Log;
|
||||
|
||||
/**
|
||||
* ExternalProductCatalogsProductCatalogs Controller
|
||||
*
|
||||
*/
|
||||
class ExternalProductCatalogsProductCatalogsController extends AppController
|
||||
{
|
||||
/**
|
||||
class ExternalProductCatalogsProductCatalogsController extends AppController {
|
||||
|
||||
/**
|
||||
* Add method
|
||||
*
|
||||
* @return Response|null|void Redirects on successful add, renders view otherwise.
|
||||
* @return \Cake\Http\Response|voidRedirects|null on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
Log::debug('inside external product catalogs product catalogs controller add');
|
||||
$productCatalogs = $this->ExternalProductCatalogsProductCatalogs->ProductCatalogs->find('list')->toArray();
|
||||
$this->set(compact( 'productCatalogs'));
|
||||
}
|
||||
public function add() {
|
||||
Log::debug('inside external product catalogs product catalogs controller add');
|
||||
$productCatalogs = $this->ExternalProductCatalogsProductCatalogs->ProductCatalogs->find('list')->toArray();
|
||||
$this->set(compact('productCatalogs'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Delete method
|
||||
*
|
||||
* @param string|null $id Customers Contact id.
|
||||
* @return Response|null Redirects to index.
|
||||
* @throws RecordNotFoundException When record not found.
|
||||
* @return Response|null Redirects to index.
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$externalProductCatalogProductCatalog = $this->ExternalProductCatalogsProductCatalogs->get($id);
|
||||
if ($this->ExternalProductCatalogsProductCatalogs->delete($externalProductCatalogProductCatalog)) {
|
||||
$this->Flash->success(__('The customers contact has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The customers contact could not be deleted. Please, try again.'));
|
||||
}
|
||||
public function delete($id = null) {
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$externalProductCatalogProductCatalog = $this->ExternalProductCatalogsProductCatalogs->get($id);
|
||||
if ($this->ExternalProductCatalogsProductCatalogs->delete($externalProductCatalogProductCatalog)) {
|
||||
$this->Flash->success(__('The customers contact has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The customers contact could not be deleted. Please, try again.'));
|
||||
}
|
||||
|
||||
return $this->redirect($this->referer([
|
||||
'controller' => 'ExternalProductCatalogs',
|
||||
'action' => 'view',
|
||||
$externalProductCatalogProductCatalog->external_product_catalog_id,
|
||||
]));
|
||||
}
|
||||
|
||||
return $this->redirect($this->referer([
|
||||
'controller' => 'ExternalProductCatalogs',
|
||||
'action' => 'view',
|
||||
$externalProductCatalogProductCatalog->external_product_catalog_id,
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,126 +4,116 @@ 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 Cake\ORM\Table;
|
||||
use Cake\ORM\TableRegistry;
|
||||
use CakeProducts\Model\Table\ProductCatalogsTable;
|
||||
|
||||
/**
|
||||
* ProductCatalogs Controller
|
||||
*
|
||||
* @property ProductCatalogsTable $ProductCatalogs
|
||||
* @property \CakeProducts\Model\Table\ProductCatalogsTable $ProductCatalogs
|
||||
*/
|
||||
class ProductCatalogsController extends AppController
|
||||
{
|
||||
/**
|
||||
class ProductCatalogsController extends AppController {
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
public function initialize(): void {
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
// $this->_defaultTable = 'CakeProducts.ProductCatalogs';
|
||||
// $this->_tableConfigKey = 'CakeProducts.ProductCatalogs.table';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Index method
|
||||
*
|
||||
* @return Response|null|void Renders view
|
||||
* @return \Cake\Http\Response|voidRenders|null view
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$query = $this->ProductCatalogs->find();
|
||||
$productCatalogs = $this->paginate($query);
|
||||
public function index() {
|
||||
$query = $this->ProductCatalogs->find();
|
||||
$productCatalogs = $this->paginate($query);
|
||||
|
||||
$this->set(compact('productCatalogs'));
|
||||
}
|
||||
$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.
|
||||
* @return Response|null|void Renders view
|
||||
*/
|
||||
public function view($id = null)
|
||||
{
|
||||
$contain = ['ProductCategories'];
|
||||
if (Configure::read('CakeProducts.internal.syncExternally', false)) {
|
||||
$contain[] = 'ExternalProductCatalogs';
|
||||
}
|
||||
$productCatalog = $this->ProductCatalogs->get($id, contain: $contain);
|
||||
$this->set(compact('productCatalog'));
|
||||
}
|
||||
public function view($id = null) {
|
||||
$contain = ['ProductCategories'];
|
||||
if (Configure::read('CakeProducts.internal.syncExternally', false)) {
|
||||
$contain[] = 'ExternalProductCatalogs';
|
||||
}
|
||||
$productCatalog = $this->ProductCatalogs->get($id, contain: $contain);
|
||||
$this->set(compact('productCatalog'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add method
|
||||
*
|
||||
* @return Response|null|void Redirects on successful add, renders view otherwise.
|
||||
* @return \Cake\Http\Response|voidRedirects|null on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$productCatalogsTable = $this->ProductCatalogs;
|
||||
$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.'));
|
||||
public function add() {
|
||||
$productCatalogsTable = $this->ProductCatalogs;
|
||||
$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));
|
||||
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'));
|
||||
}
|
||||
$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.
|
||||
* @return Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
$productCatalogsTable = $this->ProductCatalogs;
|
||||
$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.'));
|
||||
public function edit($id = null) {
|
||||
$productCatalogsTable = $this->ProductCatalogs;
|
||||
$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'));
|
||||
}
|
||||
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.
|
||||
* @return Response|null Redirects to index.
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productCatalogsTable = $this->ProductCatalogs;
|
||||
$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.'));
|
||||
}
|
||||
public function delete($id = null) {
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productCatalogsTable = $this->ProductCatalogs;
|
||||
$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']);
|
||||
}
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Controller;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Log\Log;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\ORM\TableRegistry;
|
||||
use Cake\Utility\Text;
|
||||
|
||||
/**
|
||||
@@ -14,163 +11,157 @@ use Cake\Utility\Text;
|
||||
*
|
||||
* @property \CakeProducts\Model\Table\ProductCategoriesTable $ProductCategories
|
||||
*/
|
||||
class ProductCategoriesController extends AppController
|
||||
{
|
||||
/**
|
||||
class ProductCategoriesController extends AppController {
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
public function initialize(): void {
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
// $this->_defaultTable = 'CakeProducts.ProductCategories';
|
||||
// $this->_tableConfigKey = 'CakeProducts.ProductCategories.table';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Index method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$query = $this->ProductCategories->find()
|
||||
->contain(['ProductCatalogs', 'ParentProductCategories']);
|
||||
$productCategories = $this->paginate($query);
|
||||
public function index() {
|
||||
$query = $this->ProductCategories->find()
|
||||
->contain(['ProductCatalogs', 'ParentProductCategories']);
|
||||
$productCategories = $this->paginate($query);
|
||||
|
||||
$this->set(compact('productCategories'));
|
||||
}
|
||||
$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.
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function view($id = null)
|
||||
{
|
||||
$productCategory = $this->ProductCategories->get($id, contain: [
|
||||
'ProductCatalogs',
|
||||
'ParentProductCategories',
|
||||
'ChildProductCategories',
|
||||
'ProductCategoryAttributes',
|
||||
'ProductCategoryAttributes.ProductCategoryAttributeOptions',
|
||||
'PrimaryProductPhotos',
|
||||
]);
|
||||
public function view($id = null) {
|
||||
$productCategory = $this->ProductCategories->get($id, contain: [
|
||||
'ProductCatalogs',
|
||||
'ParentProductCategories',
|
||||
'ChildProductCategories',
|
||||
'ProductCategoryAttributes',
|
||||
'ProductCategoryAttributes.ProductCategoryAttributeOptions',
|
||||
'PrimaryProductPhotos',
|
||||
]);
|
||||
|
||||
$productCategoryAttributes = $this->ProductCategories->ProductCategoryAttributes->getAllCategoryAttributesForCategoryId($productCategory->internal_id);
|
||||
$this->set(compact('productCategory', 'productCategoryAttributes'));
|
||||
}
|
||||
$productCategoryAttributes = $this->ProductCategories->ProductCategoryAttributes->getAllCategoryAttributesForCategoryId($productCategory->internal_id);
|
||||
$this->set(compact('productCategory', 'productCategoryAttributes'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$productCategoriesTable = $this->ProductCategories;
|
||||
$productCategory = $productCategoriesTable->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');
|
||||
}
|
||||
if (!array_key_exists('internal_id', $postData) || !$postData['internal_id']) {
|
||||
$postData['internal_id'] = Text::uuid();
|
||||
}
|
||||
$productCategory = $productCategoriesTable->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.'));
|
||||
public function add() {
|
||||
$productCategoriesTable = $this->ProductCategories;
|
||||
$productCategory = $productCategoriesTable->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');
|
||||
}
|
||||
if (!array_key_exists('internal_id', $postData) || !$postData['internal_id']) {
|
||||
$postData['internal_id'] = Text::uuid();
|
||||
}
|
||||
$productCategory = $productCategoriesTable->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']);
|
||||
}
|
||||
$this->Flash->error(__('The product category could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCatalogs = $productCategoriesTable->ProductCatalogs->find('list', limit: 200)->all();
|
||||
$parentProductCategories = $productCategoriesTable->ParentProductCategories->find('treeList', limit: 200)->toArray();
|
||||
$this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories'));
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
$this->Flash->error(__('The product category could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCatalogs = $productCategoriesTable->ProductCatalogs->find('list', limit: 200)->all();
|
||||
$parentProductCategories = $productCategoriesTable->ParentProductCategories->find('treeList', limit: 200)->toArray();
|
||||
$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.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
$productCategoriesTable = $this->ProductCategories;
|
||||
$productCategory = $productCategoriesTable->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$postData = $this->request->getData();
|
||||
$productCategory = $productCategoriesTable->patchEntity($productCategory, $postData);
|
||||
if ($productCategoriesTable->save($productCategory)) {
|
||||
$this->Flash->success(__('The product category has been saved.'));
|
||||
public function edit($id = null) {
|
||||
$productCategoriesTable = $this->ProductCategories;
|
||||
$productCategory = $productCategoriesTable->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$postData = $this->request->getData();
|
||||
$productCategory = $productCategoriesTable->patchEntity($productCategory, $postData);
|
||||
if ($productCategoriesTable->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 = $productCategoriesTable->ProductCatalogs->find('list', limit: 200)->all();
|
||||
$parentProductCategories = $productCategoriesTable->ParentProductCategories->find('list', limit: 200)->all();
|
||||
$this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories'));
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
$this->Flash->error(__('The product category could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCatalogs = $productCategoriesTable->ProductCatalogs->find('list', limit: 200)->all();
|
||||
$parentProductCategories = $productCategoriesTable->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.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productCategoriesTable = $this->ProductCategories;
|
||||
public function delete($id = null) {
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productCategoriesTable = $this->ProductCategories;
|
||||
|
||||
$productCategory = $productCategoriesTable->get($id);
|
||||
$productCategory = $productCategoriesTable->get($id);
|
||||
// $productCategoriesTable->behaviors()->get('Tree')->setConfig([
|
||||
// 'scope' => [
|
||||
// 'product_catalog_id' => $productCategory->product_catalog_id,
|
||||
// ],
|
||||
// ]);
|
||||
if ($productCategoriesTable->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.'));
|
||||
}
|
||||
if ($productCategoriesTable->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']);
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function select()
|
||||
{
|
||||
$productCategoriesTable = $this->ProductCategories;
|
||||
$productCategoriesTable->behaviors()->get('Tree')->setConfig([
|
||||
'scope' => [
|
||||
'product_catalog_id' => $this->request->getQuery('product_catalog_id', -1),
|
||||
],
|
||||
]);
|
||||
$productCategoriesQ = $this->request->getQuery('form', 'product_category') === 'product' ?
|
||||
$productCategoriesTable->find('treeList', keyPath: 'internal_id', valuePath: 'name') :
|
||||
$productCategoriesTable->find('treeList');
|
||||
public function select() {
|
||||
$productCategoriesTable = $this->ProductCategories;
|
||||
$productCategoriesTable->behaviors()->get('Tree')->setConfig([
|
||||
'scope' => [
|
||||
'product_catalog_id' => $this->request->getQuery('product_catalog_id', -1),
|
||||
],
|
||||
]);
|
||||
$productCategoriesQ = $this->request->getQuery('form', 'product_category') === 'product' ?
|
||||
$productCategoriesTable->find('treeList', keyPath: 'internal_id', valuePath: 'name') :
|
||||
$productCategoriesTable->find('treeList');
|
||||
|
||||
$productCategories = $productCategoriesQ
|
||||
->orderBy(['ProductCategories.name'])
|
||||
->toArray();
|
||||
$productCategories = $productCategoriesQ
|
||||
->orderBy(['ProductCategories.name'])
|
||||
->toArray();
|
||||
|
||||
$this->set(compact('productCategories'));
|
||||
}
|
||||
|
||||
$this->set(compact('productCategories'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,60 +3,55 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Controller;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Log\Log;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\ORM\TableRegistry;
|
||||
|
||||
/**
|
||||
* ProductCategoryAttributeOptions Controller
|
||||
*
|
||||
* @property \CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable $ProductCategoryAttributeOptions
|
||||
*/
|
||||
class ProductCategoryAttributeOptionsController extends AppController
|
||||
{
|
||||
/**
|
||||
class ProductCategoryAttributeOptionsController extends AppController {
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
public function initialize(): void {
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
// $this->_defaultTable = 'CakeProducts.ProductCategoryAttributeOptions';
|
||||
// $this->_tableConfigKey = 'CakeProducts.ProductCategoryAttributeOptions.table';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 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');
|
||||
public function add() {
|
||||
Log::debug('inside product category attribute options controller add');
|
||||
|
||||
$productCategoryAttributeOption = $this->ProductCategoryAttributeOptions->newEmptyEntity();
|
||||
$this->set(compact('productCategoryAttributeOption'));
|
||||
}
|
||||
$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.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productCategoryAttributeOptionsTable = $this->ProductCategoryAttributeOptions;
|
||||
public function delete($id = null) {
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productCategoryAttributeOptionsTable = $this->ProductCategoryAttributeOptions;
|
||||
|
||||
$productCategoryAttributeOption = $productCategoryAttributeOptionsTable->get($id);
|
||||
if ($productCategoryAttributeOptionsTable->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.'));
|
||||
}
|
||||
$productCategoryAttributeOption = $productCategoryAttributeOptionsTable->get($id);
|
||||
if ($productCategoryAttributeOptionsTable->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]);
|
||||
}
|
||||
|
||||
return $this->redirect(['controller' => 'ProductCategoryAttributes', 'action' => 'view', $productCategoryAttributeOption->product_category_attribute_id]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,172 +3,159 @@ 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 Cake\ORM\Table;
|
||||
use Cake\ORM\TableRegistry;
|
||||
use CakeProducts\Model\Enum\ProductCategoryAttributeTypeId;
|
||||
use CakeProducts\Model\Table\ProductCategoryAttributesTable;
|
||||
|
||||
/**
|
||||
* ProductCategoryAttributes Controller
|
||||
*
|
||||
* @property ProductCategoryAttributesTable $ProductCategoryAttributes
|
||||
* @property \CakeProducts\Model\Table\ProductCategoryAttributesTable $ProductCategoryAttributes
|
||||
*/
|
||||
class ProductCategoryAttributesController extends AppController
|
||||
{
|
||||
/**
|
||||
class ProductCategoryAttributesController extends AppController {
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
public function initialize(): void {
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
// $this->_defaultTable = 'CakeProducts.ProductCategoryAttributes';
|
||||
// $this->_tableConfigKey = 'CakeProducts.ProductCategoryAttributes.table';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Index method
|
||||
*
|
||||
* @return Response|null|void Renders view
|
||||
* @return \Cake\Http\Response|voidRenders|null view
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$query = $this->ProductCategoryAttributes->find()
|
||||
->contain(['ProductCategories']);
|
||||
$productCategoryAttributes = $this->paginate($query);
|
||||
public function index() {
|
||||
$query = $this->ProductCategoryAttributes->find()
|
||||
->contain(['ProductCategories']);
|
||||
$productCategoryAttributes = $this->paginate($query);
|
||||
|
||||
$this->set(compact('productCategoryAttributes'));
|
||||
}
|
||||
$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.
|
||||
* @return Response|null|void Renders view
|
||||
*/
|
||||
public function view($id = null)
|
||||
{
|
||||
$productCategoryAttribute = $this->ProductCategoryAttributes->get($id, contain: [
|
||||
'ProductCategories',
|
||||
'ProductCategoryAttributeOptions',
|
||||
]);
|
||||
public function view($id = null) {
|
||||
$productCategoryAttribute = $this->ProductCategoryAttributes->get($id, contain: [
|
||||
'ProductCategories',
|
||||
'ProductCategoryAttributeOptions',
|
||||
]);
|
||||
|
||||
$this->set(compact('productCategoryAttribute'));
|
||||
}
|
||||
$this->set(compact('productCategoryAttribute'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add method
|
||||
*
|
||||
* @return Response|null|void Redirects on successful add, renders view otherwise.
|
||||
* @return \Cake\Http\Response|voidRedirects|null on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$productCategoryAttributesTable = $this->ProductCategoryAttributes;
|
||||
$productCategoryAttribute = $productCategoryAttributesTable->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'
|
||||
],
|
||||
];
|
||||
$productCategoryAttribute = $productCategoryAttributesTable->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 ($productCategoryAttributesTable->save($productCategoryAttribute, $saveOptions)) {
|
||||
$this->Flash->success(__('The product category attribute has been saved.'));
|
||||
public function add() {
|
||||
$productCategoryAttributesTable = $this->ProductCategoryAttributes;
|
||||
$productCategoryAttribute = $productCategoryAttributesTable->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',
|
||||
],
|
||||
];
|
||||
$productCategoryAttribute = $productCategoryAttributesTable->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 ($productCategoryAttributesTable->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 = $productCategoryAttributesTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all();
|
||||
$this->set(compact('productCategoryAttribute', 'productCategories'));
|
||||
}
|
||||
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 = $productCategoryAttributesTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->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.
|
||||
* @return Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
$productCategoryAttributesTable = $this->ProductCategoryAttributes;
|
||||
$productCategoryAttribute = $productCategoryAttributesTable->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));
|
||||
public function edit($id = null) {
|
||||
$productCategoryAttributesTable = $this->ProductCategoryAttributes;
|
||||
$productCategoryAttribute = $productCategoryAttributesTable->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 = $productCategoryAttributesTable->patchEntity($productCategoryAttribute, $postData, $saveOptions);
|
||||
Log::debug(print_r('$postData', true));
|
||||
Log::debug(print_r($postData, true));
|
||||
$productCategoryAttribute = $productCategoryAttributesTable->patchEntity($productCategoryAttribute, $postData, $saveOptions);
|
||||
|
||||
if ($productCategoryAttributesTable->save($productCategoryAttribute, $saveOptions)) {
|
||||
$this->Flash->success(__('The product category attribute has been saved.'));
|
||||
if ($productCategoryAttributesTable->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 = $productCategoryAttributesTable->ProductCategories->find('list', limit: 200, keyField: 'internal_id', valueField: 'name')->all();
|
||||
$this->set(compact('productCategoryAttribute', 'productCategories'));
|
||||
}
|
||||
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 = $productCategoryAttributesTable->ProductCategories->find('list', limit: 200, keyField: 'internal_id', valueField: 'name')->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.
|
||||
* @return Response|null Redirects to index.
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
public function delete($id = null) {
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
|
||||
$productCategoryAttributesTable = $this->ProductCategoryAttributes;
|
||||
$productCategoryAttribute = $productCategoryAttributesTable->get($id);
|
||||
if ($productCategoryAttributesTable->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.'));
|
||||
}
|
||||
$productCategoryAttributesTable = $this->ProductCategoryAttributes;
|
||||
$productCategoryAttribute = $productCategoryAttributesTable->get($id);
|
||||
if ($productCategoryAttributesTable->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']);
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form()
|
||||
{
|
||||
$productCategories = $this->ProductCategoryAttributes->getAllCategoryAttributesForCategoryId($this->request->getQuery('product_category_id', '-1'));
|
||||
public function form() {
|
||||
$productCategories = $this->ProductCategoryAttributes->getAllCategoryAttributesForCategoryId($this->request->getQuery('product_category_id', '-1'));
|
||||
|
||||
$this->set(compact('productCategories'));
|
||||
}
|
||||
|
||||
$this->set(compact('productCategories'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,158 +3,150 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Controller;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Log\Log;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\ORM\TableRegistry;
|
||||
|
||||
/**
|
||||
* ProductCategoryVariants Controller
|
||||
*
|
||||
* @property \App\Model\Table\ProductCategoryVariantsTable $ProductCategoryVariants
|
||||
*/
|
||||
class ProductCategoryVariantsController extends AppController
|
||||
{
|
||||
/**
|
||||
class ProductCategoryVariantsController extends AppController {
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
public function initialize(): void {
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
// $this->_defaultTable = 'CakeProducts.ProductCategoryVariants';
|
||||
// $this->_tableConfigKey = 'CakeProducts.ProductCategoryVariants.table';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Index method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$query = $this->ProductCategoryVariants->find()
|
||||
->contain(['ProductCategories', 'Products', 'ProductCategoryVariantOptions']);
|
||||
$productCategoryVariants = $this->paginate($query);
|
||||
public function index() {
|
||||
$query = $this->ProductCategoryVariants->find()
|
||||
->contain(['ProductCategories', 'Products', 'ProductCategoryVariantOptions']);
|
||||
$productCategoryVariants = $this->paginate($query);
|
||||
|
||||
$this->set(compact('productCategoryVariants'));
|
||||
}
|
||||
$this->set(compact('productCategoryVariants'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* View method
|
||||
*
|
||||
* @param string|null $id Product Category Variant id.
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function view($id = null)
|
||||
{
|
||||
$productCategoryVariant = $this->ProductCategoryVariants->get($id, contain: [
|
||||
'ProductCategories',
|
||||
'Products',
|
||||
'ProductCategoryVariantOptions',
|
||||
]);
|
||||
$this->set(compact('productCategoryVariant'));
|
||||
}
|
||||
public function view($id = null) {
|
||||
$productCategoryVariant = $this->ProductCategoryVariants->get($id, contain: [
|
||||
'ProductCategories',
|
||||
'Products',
|
||||
'ProductCategoryVariantOptions',
|
||||
]);
|
||||
$this->set(compact('productCategoryVariant'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$productCategoryVariantsTable = $this->ProductCategoryVariants;
|
||||
public function add() {
|
||||
$productCategoryVariantsTable = $this->ProductCategoryVariants;
|
||||
|
||||
$productCategoryVariant = $productCategoryVariantsTable->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');
|
||||
}
|
||||
$saveOptions = [
|
||||
'associated' => [
|
||||
'ProductCategoryVariantOptions'
|
||||
],
|
||||
];
|
||||
$productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $postData, $saveOptions);
|
||||
if ($productCategoryVariantsTable->save($productCategoryVariant, $saveOptions)) {
|
||||
$this->Flash->success(__('The product category variant has been saved.'));
|
||||
$productCategoryVariant = $productCategoryVariantsTable->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');
|
||||
}
|
||||
$saveOptions = [
|
||||
'associated' => [
|
||||
'ProductCategoryVariantOptions',
|
||||
],
|
||||
];
|
||||
$productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $postData, $saveOptions);
|
||||
if ($productCategoryVariantsTable->save($productCategoryVariant, $saveOptions)) {
|
||||
$this->Flash->success(__('The product category variant has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
Log::debug('print_r($productCategoryVariant->getErrors(), true) failed to save in product category variants add');
|
||||
Log::debug(print_r($productCategoryVariant->getErrors(), true));
|
||||
$this->Flash->error(__('The product category variant could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategories = $productCategoryVariantsTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all();
|
||||
$products = $productCategoryVariantsTable->Products->find('list')->all();
|
||||
$this->set(compact('productCategoryVariant', 'productCategories', 'products'));
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
Log::debug('print_r($productCategoryVariant->getErrors(), true) failed to save in product category variants add');
|
||||
Log::debug(print_r($productCategoryVariant->getErrors(), true));
|
||||
$this->Flash->error(__('The product category variant could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategories = $productCategoryVariantsTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all();
|
||||
$products = $productCategoryVariantsTable->Products->find('list')->all();
|
||||
$this->set(compact('productCategoryVariant', 'productCategories', 'products'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Edit method
|
||||
*
|
||||
* @param string|null $id Product Category Variant id.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
$productCategoryVariantsTable = $this->ProductCategoryVariants;
|
||||
$productCategoryVariant = $productCategoryVariantsTable->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$postData = $this->request->getData();
|
||||
public function edit($id = null) {
|
||||
$productCategoryVariantsTable = $this->ProductCategoryVariants;
|
||||
$productCategoryVariant = $productCategoryVariantsTable->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$postData = $this->request->getData();
|
||||
// if ($this->request->getSession()->read('Auth.User.id')) {
|
||||
// $postData['created_by'] = $this->request->getSession()->read('Auth.User.id');
|
||||
// }
|
||||
$postData = $productCategoryVariant->is_system_variant ? ['product_category_variant_options' => $this->request->getData('product_category_variant_options')] : $postData;
|
||||
$saveOptions = [
|
||||
'fields' => $productCategoryVariant->is_system_variant ? [
|
||||
'product_category_variant_options',
|
||||
] : [
|
||||
'name',
|
||||
'product_category_id',
|
||||
'enabled',
|
||||
'product_category_variant_options',
|
||||
],
|
||||
'associated' => [
|
||||
'ProductCategoryVariantOptions'
|
||||
],
|
||||
];
|
||||
$productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $postData, $saveOptions);
|
||||
$postData = $productCategoryVariant->is_system_variant ? ['product_category_variant_options' => $this->request->getData('product_category_variant_options')] : $postData;
|
||||
$saveOptions = [
|
||||
'fields' => $productCategoryVariant->is_system_variant ? [
|
||||
'product_category_variant_options',
|
||||
] : [
|
||||
'name',
|
||||
'product_category_id',
|
||||
'enabled',
|
||||
'product_category_variant_options',
|
||||
],
|
||||
'associated' => [
|
||||
'ProductCategoryVariantOptions',
|
||||
],
|
||||
];
|
||||
$productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $postData, $saveOptions);
|
||||
// dd($postData);
|
||||
if ($productCategoryVariantsTable->save($productCategoryVariant, $saveOptions)) {
|
||||
$this->Flash->success(__('The product category variant has been saved.'));
|
||||
if ($productCategoryVariantsTable->save($productCategoryVariant, $saveOptions)) {
|
||||
$this->Flash->success(__('The product category variant has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
// dd($productCategoryVariant->getErrors());
|
||||
$this->Flash->error(__('The product category variant could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategories = $productCategoryVariantsTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all();
|
||||
$products = isset($productCategoryVariant->product_category_id) ? $productCategoryVariantsTable->Products->find('list', limit: 200)->where(['product_category_id' => $productCategoryVariant->product_category_id])->all() : [];
|
||||
$this->set(compact('productCategoryVariant', 'productCategories', 'products'));
|
||||
}
|
||||
$this->Flash->error(__('The product category variant could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategories = $productCategoryVariantsTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all();
|
||||
$products = isset($productCategoryVariant->product_category_id) ? $productCategoryVariantsTable->Products->find('list', limit: 200)->where(['product_category_id' => $productCategoryVariant->product_category_id])->all() : [];
|
||||
$this->set(compact('productCategoryVariant', 'productCategories', 'products'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Delete method
|
||||
*
|
||||
* @param string|null $id Product Category Variant id.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productCategoryVariantsTable = $this->ProductCategoryVariants;
|
||||
public function delete($id = null) {
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productCategoryVariantsTable = $this->ProductCategoryVariants;
|
||||
|
||||
$productCategoryVariant = $productCategoryVariantsTable->get($id);
|
||||
if ($productCategoryVariantsTable->delete($productCategoryVariant)) {
|
||||
$this->Flash->success(__('The product category variant has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product category variant could not be deleted. Please, try again.'));
|
||||
}
|
||||
$productCategoryVariant = $productCategoryVariantsTable->get($id);
|
||||
if ($productCategoryVariantsTable->delete($productCategoryVariant)) {
|
||||
$this->Flash->success(__('The product category variant has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product category variant could not be deleted. Please, try again.'));
|
||||
}
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,209 +6,201 @@ namespace CakeProducts\Controller;
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Datasource\Exception\RecordNotFoundException;
|
||||
use Cake\Http\Exception\ForbiddenException;
|
||||
use Cake\Http\Response;
|
||||
use Cake\Utility\Text;
|
||||
use CakeProducts\Model\Table\ProductPhotosTable;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
|
||||
/**
|
||||
* ProductPhotos Controller
|
||||
*
|
||||
* @property ProductPhotosTable $ProductPhotos
|
||||
* @property \CakeProducts\Model\Table\ProductPhotosTable $ProductPhotos
|
||||
*/
|
||||
class ProductPhotosController extends AppController
|
||||
{
|
||||
/**
|
||||
class ProductPhotosController extends AppController {
|
||||
|
||||
/**
|
||||
* Index method
|
||||
*
|
||||
* @return Response|null|void Renders view
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$query = $this->ProductPhotos->find()
|
||||
->contain(['Products', 'ProductSkus', 'ProductCategories']);
|
||||
$productPhotos = $this->paginate($query);
|
||||
public function index() {
|
||||
$query = $this->ProductPhotos->find()
|
||||
->contain(['Products', 'ProductSkus', 'ProductCategories']);
|
||||
$productPhotos = $this->paginate($query);
|
||||
|
||||
$this->set(compact('productPhotos'));
|
||||
}
|
||||
$this->set(compact('productPhotos'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* View method
|
||||
*
|
||||
* @param string|null $id Product Photo id.
|
||||
* @return Response|null|void Renders view
|
||||
* @throws RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function view($id = null)
|
||||
{
|
||||
$productPhoto = $this->ProductPhotos->get($id, contain: ['Products', 'ProductSkus', 'ProductCategories']);
|
||||
$this->set(compact('productPhoto'));
|
||||
}
|
||||
public function view($id = null) {
|
||||
$productPhoto = $this->ProductPhotos->get($id, contain: ['Products', 'ProductSkus', 'ProductCategories']);
|
||||
$this->set(compact('productPhoto'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add method
|
||||
*
|
||||
* @return Response|null|void Redirects on successful add, renders view otherwise.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$productPhotosTable = $this->ProductPhotos;
|
||||
$productPhoto = $productPhotosTable->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
if (!$this->request->getData('photo')) {
|
||||
$this->Flash->error('Photo is required. Nothing was uploaded. Please try again.');
|
||||
$productCategory = $productPhoto->product_category_id ? $productPhotosTable->ProductCategories->find()->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null;
|
||||
$productCatalogs = $productPhotosTable->ProductCategories->ProductCatalogs->find('list')->toArray();
|
||||
$this->set(compact('productPhoto', 'productCatalogs', 'productCategory'));
|
||||
public function add() {
|
||||
$productPhotosTable = $this->ProductPhotos;
|
||||
$productPhoto = $productPhotosTable->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
if (!$this->request->getData('photo')) {
|
||||
$this->Flash->error('Photo is required. Nothing was uploaded. Please try again.');
|
||||
$productCategory = $productPhoto->product_category_id ? $productPhotosTable->ProductCategories->find()->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null;
|
||||
$productCatalogs = $productPhotosTable->ProductCategories->ProductCatalogs->find('list')->toArray();
|
||||
$this->set(compact('productPhoto', 'productCatalogs', 'productCategory'));
|
||||
|
||||
return;
|
||||
}
|
||||
$uuid = Text::uuid();
|
||||
$postData = $this->request->getData();
|
||||
$postData['id'] = $uuid;
|
||||
$baseDir = Configure::readOrFail('CakeProducts.photos.directory');
|
||||
$path = '';
|
||||
if ($this->request->getData('product_sku_id')) {
|
||||
$productSku = $productPhotosTable->ProductSkus
|
||||
->find()
|
||||
->contain(['Products', 'Products.ProductCategories'])
|
||||
->where([
|
||||
'ProductSkus.id' => $this->request->getData('product_sku_id'),
|
||||
])
|
||||
->first();
|
||||
$path = $productSku ? $productSku->product_id . DS . 'skus' . DS . $productSku->id : $path;
|
||||
return;
|
||||
}
|
||||
$uuid = Text::uuid();
|
||||
$postData = $this->request->getData();
|
||||
$postData['id'] = $uuid;
|
||||
$baseDir = Configure::readOrFail('CakeProducts.photos.directory');
|
||||
$path = '';
|
||||
if ($this->request->getData('product_sku_id')) {
|
||||
$productSku = $productPhotosTable->ProductSkus
|
||||
->find()
|
||||
->contain(['Products', 'Products.ProductCategories'])
|
||||
->where([
|
||||
'ProductSkus.id' => $this->request->getData('product_sku_id'),
|
||||
])
|
||||
->first();
|
||||
$path = $productSku ? $productSku->product_id . DS . 'skus' . DS . $productSku->id : $path;
|
||||
|
||||
$postData['product_id'] = $productSku->product->id ?? null;
|
||||
$postData['product_category_id'] = $productSku->product->product_category->internal_id ?? null;
|
||||
} else if ($this->request->getData('product_id')) {
|
||||
$product = $productPhotosTable->Products
|
||||
->find()
|
||||
->contain(['ProductCategories'])
|
||||
->where([
|
||||
'Products.id' => $this->request->getData('product_id'),
|
||||
])
|
||||
->first();
|
||||
$path = $product ? $product->id : $path;
|
||||
$postData['product_category_id'] = $product->product_category->internal_id ?? null;
|
||||
$postData['product_id'] = $productSku->product->id ?? null;
|
||||
$postData['product_category_id'] = $productSku->product->product_category->internal_id ?? null;
|
||||
} else if ($this->request->getData('product_id')) {
|
||||
$product = $productPhotosTable->Products
|
||||
->find()
|
||||
->contain(['ProductCategories'])
|
||||
->where([
|
||||
'Products.id' => $this->request->getData('product_id'),
|
||||
])
|
||||
->first();
|
||||
$path = $product ? $product->id : $path;
|
||||
$postData['product_category_id'] = $product->product_category->internal_id ?? null;
|
||||
|
||||
} else if ($this->request->getData('product_category_id')) {
|
||||
$categoryId = $this->request->getData('product_category_id');
|
||||
// @link https://developer.wordpress.org/reference/functions/wp_is_uuid/
|
||||
$regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/';
|
||||
$field = preg_match($regex, $categoryId) ? 'ProductCategories.internal_id' : 'ProductCategories.id';
|
||||
$productCategoryPosted = $productPhotosTable->ProductCategories
|
||||
->find()
|
||||
->where([
|
||||
$field => $categoryId,
|
||||
])
|
||||
->first();
|
||||
$postData['product_category_id'] = $productCategoryPosted->internal_id ?? null;
|
||||
$path = $productCategoryPosted ? 'categories' : $path;
|
||||
}
|
||||
/**
|
||||
* @var UploadedFileInterface $photoObject
|
||||
} else if ($this->request->getData('product_category_id')) {
|
||||
$categoryId = $this->request->getData('product_category_id');
|
||||
// @link https://developer.wordpress.org/reference/functions/wp_is_uuid/
|
||||
$regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/';
|
||||
$field = preg_match($regex, $categoryId) ? 'ProductCategories.internal_id' : 'ProductCategories.id';
|
||||
$productCategoryPosted = $productPhotosTable->ProductCategories
|
||||
->find()
|
||||
->where([
|
||||
$field => $categoryId,
|
||||
])
|
||||
->first();
|
||||
$postData['product_category_id'] = $productCategoryPosted->internal_id ?? null;
|
||||
$path = $productCategoryPosted ? 'categories' : $path;
|
||||
}
|
||||
/**
|
||||
* @var \Psr\Http\Message\UploadedFileInterface $photoObject
|
||||
*/
|
||||
$photoObject = $this->request->getData('photo');
|
||||
$ext = substr(strtolower($photoObject->getClientFilename()), -4);
|
||||
$ext = str_starts_with($ext, '.') ? substr($ext, 1) : $ext;
|
||||
$allowedFileTypes = ['png', 'jpeg', 'jpg'];
|
||||
if (!in_array($ext, $allowedFileTypes)) {
|
||||
throw new ForbiddenException('Invalid file type. Only PNG and JPG types are allowed.');
|
||||
}
|
||||
$photoObject = $this->request->getData('photo');
|
||||
$ext = substr(strtolower($photoObject->getClientFilename()), -4);
|
||||
$ext = str_starts_with($ext, '.') ? substr($ext, 1) : $ext;
|
||||
$allowedFileTypes = ['png', 'jpeg', 'jpg'];
|
||||
if (!in_array($ext, $allowedFileTypes)) {
|
||||
throw new ForbiddenException('Invalid file type. Only PNG and JPG types are allowed.');
|
||||
}
|
||||
|
||||
$fullPath = $baseDir . $path;
|
||||
if (!file_exists($fullPath)) {
|
||||
if (!mkdir($fullPath, 0777, true)) {
|
||||
throw new ForbiddenException('Failed to create the required folders. Please check the folder permissions and try again.');
|
||||
}
|
||||
}
|
||||
$destination = $fullPath . DS . $uuid . '.' . $ext;
|
||||
$fullPath = $baseDir . $path;
|
||||
if (!file_exists($fullPath)) {
|
||||
if (!mkdir($fullPath, 0777, true)) {
|
||||
throw new ForbiddenException('Failed to create the required folders. Please check the folder permissions and try again.');
|
||||
}
|
||||
}
|
||||
$destination = $fullPath . DS . $uuid . '.' . $ext;
|
||||
|
||||
// Existing files with the same name will be replaced.
|
||||
$photoObject->moveTo($destination);
|
||||
if (!file_exists($destination)) {
|
||||
throw new ForbiddenException('Failed to move the uploaded image to the appropriate folder. Please try again.');
|
||||
}
|
||||
// Existing files with the same name will be replaced.
|
||||
$photoObject->moveTo($destination);
|
||||
if (!file_exists($destination)) {
|
||||
throw new ForbiddenException('Failed to move the uploaded image to the appropriate folder. Please try again.');
|
||||
}
|
||||
|
||||
$postData['photo_dir'] = $path;
|
||||
$postData['photo_filename'] = $uuid . '.' . $ext;
|
||||
$postData['photo_dir'] = $path;
|
||||
$postData['photo_filename'] = $uuid . '.' . $ext;
|
||||
// dd($postData);
|
||||
|
||||
$productPhoto = $productPhotosTable->patchEntity($productPhoto, $postData);
|
||||
if ($productPhotosTable->save($productPhoto)) {
|
||||
$this->Flash->success(__('The product photo has been saved.'));
|
||||
$productPhoto = $productPhotosTable->patchEntity($productPhoto, $postData);
|
||||
if ($productPhotosTable->save($productPhoto)) {
|
||||
$this->Flash->success(__('The product photo has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
// dd($productPhoto->getErrors());
|
||||
$this->Flash->error(__('The product photo could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategory = $productPhoto->product_category_id ? $productPhotosTable->ProductCategories->find()->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null;
|
||||
$productCatalogs = $productPhotosTable->ProductCategories->ProductCatalogs->find('list')->toArray();
|
||||
$this->set(compact('productPhoto', 'productCatalogs', 'productCategory'));
|
||||
}
|
||||
$this->Flash->error(__('The product photo could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategory = $productPhoto->product_category_id ? $productPhotosTable->ProductCategories->find()->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null;
|
||||
$productCatalogs = $productPhotosTable->ProductCategories->ProductCatalogs->find('list')->toArray();
|
||||
$this->set(compact('productPhoto', 'productCatalogs', 'productCategory'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Edit method
|
||||
*
|
||||
* @param string|null $id Product Photo id.
|
||||
* @return Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
* @throws RecordNotFoundException When record not found.
|
||||
* @return Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
$productPhotosTable = $this->ProductPhotos;
|
||||
$productPhoto = $productPhotosTable->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$postData = $this->request->getData();
|
||||
public function edit($id = null) {
|
||||
$productPhotosTable = $this->ProductPhotos;
|
||||
$productPhoto = $productPhotosTable->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$postData = $this->request->getData();
|
||||
|
||||
$productPhoto = $productPhotosTable->patchEntity($productPhoto, $postData);
|
||||
if ($productPhotosTable->save($productPhoto)) {
|
||||
$this->Flash->success(__('The product photo has been saved.'));
|
||||
$productPhoto = $productPhotosTable->patchEntity($productPhoto, $postData);
|
||||
if ($productPhotosTable->save($productPhoto)) {
|
||||
$this->Flash->success(__('The product photo has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
$this->Flash->error(__('The product photo could not be saved. Please, try again.'));
|
||||
}
|
||||
$products = $productPhotosTable->Products->find('list', limit: 200)->all();
|
||||
$productSkus = $productPhotosTable->ProductSkus->find('list', limit: 200)->all();
|
||||
$this->set(compact('productPhoto', 'products', 'productSkus'));
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
$this->Flash->error(__('The product photo could not be saved. Please, try again.'));
|
||||
}
|
||||
$products = $productPhotosTable->Products->find('list', limit: 200)->all();
|
||||
$productSkus = $productPhotosTable->ProductSkus->find('list', limit: 200)->all();
|
||||
$this->set(compact('productPhoto', 'products', 'productSkus'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Delete method
|
||||
*
|
||||
* @param string|null $id Product Photo id.
|
||||
* @return Response|null Redirects to index.
|
||||
* @throws RecordNotFoundException When record not found.
|
||||
* @return Response|null Redirects to index.
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productPhotosTable = $this->ProductPhotos;
|
||||
public function delete($id = null) {
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productPhotosTable = $this->ProductPhotos;
|
||||
|
||||
$productPhoto = $productPhotosTable->get($id);
|
||||
if ($productPhotosTable->delete($productPhoto)) {
|
||||
$this->Flash->success(__('The product photo has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product photo could not be deleted. Please, try again.'));
|
||||
}
|
||||
$productPhoto = $productPhotosTable->get($id);
|
||||
if ($productPhotosTable->delete($productPhoto)) {
|
||||
$this->Flash->success(__('The product photo has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product photo could not be deleted. Please, try again.'));
|
||||
}
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @param $id
|
||||
* @return Response
|
||||
*/
|
||||
public function image($id = null)
|
||||
{
|
||||
$productPhoto = $this->ProductPhotos->get($id);
|
||||
public function image($id = null) {
|
||||
$productPhoto = $this->ProductPhotos->get($id);
|
||||
|
||||
$fullPath = Configure::readOrFail('CakeProducts.photos.directory') . $productPhoto->photo_dir . DS . $productPhoto->photo_filename;
|
||||
$fullPath = Configure::readOrFail('CakeProducts.photos.directory') . $productPhoto->photo_dir . DS . $productPhoto->photo_filename;
|
||||
|
||||
return $this->response->withFile($fullPath, [
|
||||
'download' => $this->request->getQuery('download', false) === '1',
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->response->withFile($fullPath, [
|
||||
'download' => $this->request->getQuery('download', false) === '1'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,240 +12,235 @@ use function BenTools\CartesianProduct\combinations;
|
||||
*
|
||||
* @property \CakeProducts\Model\Table\ProductSkusTable $ProductSkus
|
||||
*/
|
||||
class ProductSkusController extends AppController
|
||||
{
|
||||
/**
|
||||
class ProductSkusController extends AppController {
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
public function initialize(): void {
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
// $this->_defaultTable = 'CakeProducts.ProductSkus';
|
||||
// $this->_tableConfigKey = 'CakeProducts.ProductSkus.table';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Index method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$query = $this->ProductSkus->find()
|
||||
->contain(['Products']);
|
||||
$productSkus = $this->paginate($query);
|
||||
public function index() {
|
||||
$query = $this->ProductSkus->find()
|
||||
->contain(['Products']);
|
||||
$productSkus = $this->paginate($query);
|
||||
|
||||
$this->set(compact('productSkus'));
|
||||
}
|
||||
$this->set(compact('productSkus'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* View method
|
||||
*
|
||||
* @param string|null $id Product Skus id.
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function view($id = null)
|
||||
{
|
||||
$productSku = $this->ProductSkus->get($id, contain: [
|
||||
'Products',
|
||||
'ProductSkuVariantValues',
|
||||
'ProductSkuVariantValues.ProductVariants',
|
||||
'ProductSkuVariantValues.ProductVariants.ProductCategoryVariants',
|
||||
'ProductSkuVariantValues.ProductCategoryVariantOptions',
|
||||
]);
|
||||
$this->set(compact('productSku'));
|
||||
}
|
||||
public function view($id = null) {
|
||||
$productSku = $this->ProductSkus->get($id, contain: [
|
||||
'Products',
|
||||
'ProductSkuVariantValues',
|
||||
'ProductSkuVariantValues.ProductVariants',
|
||||
'ProductSkuVariantValues.ProductVariants.ProductCategoryVariants',
|
||||
'ProductSkuVariantValues.ProductCategoryVariantOptions',
|
||||
]);
|
||||
$this->set(compact('productSku'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add($productId = null)
|
||||
{
|
||||
$toGetCartesianProductsFrom = [];
|
||||
$productSkus = [];
|
||||
$product = $this->ProductSkus->Products->get($productId, contain: [
|
||||
'ProductSkus',
|
||||
'ProductSkus.ProductSkuVariantValues',
|
||||
'ProductVariants',
|
||||
'ProductVariants.ProductCategoryVariants',
|
||||
'ProductVariants.ProductCategoryVariants.ProductCategoryVariantOptions',
|
||||
]);
|
||||
$existingProductSkus = Hash::combine($product->product_skus ?? [], '{n}.id', '{n}');
|
||||
$existingProductSkusForMapping = Hash::combine($product->product_skus ?? [], '{n}.id', '{n}.product_sku_variant_values');
|
||||
$existingSkusForCartesianComparison = [];
|
||||
foreach ($existingProductSkusForMapping as $existingProductSkuId => $existingProductSku) {
|
||||
$existingSkusForCartesianComparison[$existingProductSkuId] = Hash::combine($existingProductSku, '{n}.product_variant_id', '{n}.product_category_variant_option_id');
|
||||
}
|
||||
$productVariants = isset($product->product_variants) ? $product->product_variants : [];
|
||||
public function add($productId = null) {
|
||||
$toGetCartesianProductsFrom = [];
|
||||
$productSkus = [];
|
||||
$product = $this->ProductSkus->Products->get($productId, contain: [
|
||||
'ProductSkus',
|
||||
'ProductSkus.ProductSkuVariantValues',
|
||||
'ProductVariants',
|
||||
'ProductVariants.ProductCategoryVariants',
|
||||
'ProductVariants.ProductCategoryVariants.ProductCategoryVariantOptions',
|
||||
]);
|
||||
$existingProductSkus = Hash::combine($product->product_skus ?? [], '{n}.id', '{n}');
|
||||
$existingProductSkusForMapping = Hash::combine($product->product_skus ?? [], '{n}.id', '{n}.product_sku_variant_values');
|
||||
$existingSkusForCartesianComparison = [];
|
||||
foreach ($existingProductSkusForMapping as $existingProductSkuId => $existingProductSku) {
|
||||
$existingSkusForCartesianComparison[$existingProductSkuId] = Hash::combine($existingProductSku, '{n}.product_variant_id', '{n}.product_category_variant_option_id');
|
||||
}
|
||||
$productVariants = $product->product_variants ?? [];
|
||||
// dd($productVariants);
|
||||
$productVariantsMapping = Hash::combine($productVariants, '{n}.product_category_variant.id', '{n}.id');
|
||||
$productCategoryVariants = Hash::extract($productVariants, '{n}.product_category_variant');
|
||||
$productVariantsMapping = Hash::combine($productVariants, '{n}.product_category_variant.id', '{n}.id');
|
||||
$productCategoryVariants = Hash::extract($productVariants, '{n}.product_category_variant');
|
||||
// dd($productCategoryVariants);
|
||||
$optionMapping = Hash::combine($productCategoryVariants, '{n}.product_category_variant_options.{n}.id', '{n}.product_category_variant_options.{n}.variant_value');
|
||||
$optionMapping = Hash::combine($productCategoryVariants, '{n}.product_category_variant_options.{n}.id', '{n}.product_category_variant_options.{n}.variant_value');
|
||||
// dd($optionMapping);
|
||||
|
||||
$variantNameMapping = Hash::combine($productCategoryVariants, '{n}.id', '{n}.name');
|
||||
$variantNameMapping = Hash::combine($productCategoryVariants, '{n}.id', '{n}.name');
|
||||
// dd($variantNameMapping);
|
||||
|
||||
foreach ($productCategoryVariants as $productCategoryVariant) {
|
||||
$options = Hash::extract($productCategoryVariant['product_category_variant_options'] ?? [], '{n}.id');
|
||||
$toGetCartesianProductsFrom[$productVariantsMapping[$productCategoryVariant['id']]] = $options;
|
||||
}
|
||||
foreach ($productCategoryVariants as $productCategoryVariant) {
|
||||
$options = Hash::extract($productCategoryVariant['product_category_variant_options'] ?? [], '{n}.id');
|
||||
$toGetCartesianProductsFrom[$productVariantsMapping[$productCategoryVariant['id']]] = $options;
|
||||
}
|
||||
// dd($toGetCartesianProductsFrom);
|
||||
|
||||
$numSkusToAdd = count(combinations($toGetCartesianProductsFrom));
|
||||
for ($i = 0; $i < $numSkusToAdd; $i++) {
|
||||
$productSkus[$i] = $this->ProductSkus->newEmptyEntity();
|
||||
}
|
||||
$this->set(compact(
|
||||
'product',
|
||||
'productSkus',
|
||||
'productCategoryVariants',
|
||||
'productVariantsMapping',
|
||||
'toGetCartesianProductsFrom',
|
||||
'optionMapping',
|
||||
'variantNameMapping',
|
||||
'numSkusToAdd',
|
||||
'existingProductSkus',
|
||||
'existingSkusForCartesianComparison'
|
||||
));
|
||||
$numSkusToAdd = count(combinations($toGetCartesianProductsFrom));
|
||||
for ($i = 0; $i < $numSkusToAdd; $i++) {
|
||||
$productSkus[$i] = $this->ProductSkus->newEmptyEntity();
|
||||
}
|
||||
$this->set(compact(
|
||||
'product',
|
||||
'productSkus',
|
||||
'productCategoryVariants',
|
||||
'productVariantsMapping',
|
||||
'toGetCartesianProductsFrom',
|
||||
'optionMapping',
|
||||
'variantNameMapping',
|
||||
'numSkusToAdd',
|
||||
'existingProductSkus',
|
||||
'existingSkusForCartesianComparison',
|
||||
));
|
||||
|
||||
if ($this->request->is('post')) {
|
||||
$postedSkus = $this->request->getData();
|
||||
$saveOptions = [
|
||||
'fields' => [
|
||||
'product_id',
|
||||
'sku',
|
||||
'barcode',
|
||||
'price',
|
||||
'cost',
|
||||
'product_sku_variant_values',
|
||||
'created',
|
||||
'modified',
|
||||
'enabled',
|
||||
'default_sku',
|
||||
],
|
||||
'associated' => [
|
||||
'ProductSkuVariantValues' => [
|
||||
'fields' => [
|
||||
'product_variant_id',
|
||||
'product_category_variant_option_id',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
$finalPostData = [];
|
||||
$postedSkus = Hash::insert($postedSkus, '{n}.product_id', $productId);
|
||||
if ($this->request->is('post')) {
|
||||
$postedSkus = $this->request->getData();
|
||||
$saveOptions = [
|
||||
'fields' => [
|
||||
'product_id',
|
||||
'sku',
|
||||
'barcode',
|
||||
'price',
|
||||
'cost',
|
||||
'product_sku_variant_values',
|
||||
'created',
|
||||
'modified',
|
||||
'enabled',
|
||||
'default_sku',
|
||||
],
|
||||
'associated' => [
|
||||
'ProductSkuVariantValues' => [
|
||||
'fields' => [
|
||||
'product_variant_id',
|
||||
'product_category_variant_option_id',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
$finalPostData = [];
|
||||
$postedSkus = Hash::insert($postedSkus, '{n}.product_id', $productId);
|
||||
|
||||
foreach ($postedSkus as $postedSkuCnt => $postedSku) {
|
||||
if (!isset($postedSku['sku']) || !$postedSku['sku']) {
|
||||
unset($productSkus[$postedSkuCnt]);
|
||||
foreach ($postedSkus as $postedSkuCnt => $postedSku) {
|
||||
if (!isset($postedSku['sku']) || !$postedSku['sku']) {
|
||||
unset($productSkus[$postedSkuCnt]);
|
||||
|
||||
continue;
|
||||
}
|
||||
$finalPostData[$postedSkuCnt] = $postedSku;
|
||||
}
|
||||
if (!$productSkus || !$postedSkus) {
|
||||
$this->Flash->error('Nothing to save! Add at least one SKU next time.');
|
||||
continue;
|
||||
}
|
||||
$finalPostData[$postedSkuCnt] = $postedSku;
|
||||
}
|
||||
if (!$productSkus || !$postedSkus) {
|
||||
$this->Flash->error('Nothing to save! Add at least one SKU next time.');
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
// dd($finalPostData);
|
||||
$productSkus = $this->ProductSkus->patchEntities($productSkus, $finalPostData, $saveOptions);
|
||||
$errors = [];
|
||||
$successes = [];
|
||||
foreach ($productSkus as $productSkuToSave) {
|
||||
$productSkus = $this->ProductSkus->patchEntities($productSkus, $finalPostData, $saveOptions);
|
||||
$errors = [];
|
||||
$successes = [];
|
||||
foreach ($productSkus as $productSkuToSave) {
|
||||
// dd($productSkuToSave);
|
||||
|
||||
if (!$this->ProductSkus->save($productSkuToSave, $saveOptions)) {
|
||||
Log::debug(print_r('$productSkuToSave->getErrors()', true));
|
||||
Log::debug(print_r($productSkuToSave->getErrors(), true));
|
||||
dd($productSkuToSave->getErrors());
|
||||
continue;
|
||||
}
|
||||
$successes[] = $productSkuToSave;
|
||||
}
|
||||
if (!$this->ProductSkus->save($productSkuToSave, $saveOptions)) {
|
||||
Log::debug(print_r('$productSkuToSave->getErrors()', true));
|
||||
Log::debug(print_r($productSkuToSave->getErrors(), true));
|
||||
dd($productSkuToSave->getErrors());
|
||||
|
||||
if ($successes) {
|
||||
$this->Flash->success(__(count($successes) . ' New SKUs have been saved.'));
|
||||
continue;
|
||||
}
|
||||
$successes[] = $productSkuToSave;
|
||||
}
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
if ($successes) {
|
||||
$this->Flash->success(__(count($successes) . ' New SKUs have been saved.'));
|
||||
|
||||
$this->Flash->error(__('The product SKU(s) could not be saved. Please, try again.'));
|
||||
}
|
||||
$this->set(compact(
|
||||
'productSkus'
|
||||
));
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
|
||||
/**
|
||||
$this->Flash->error(__('The product SKU(s) could not be saved. Please, try again.'));
|
||||
}
|
||||
$this->set(compact(
|
||||
'productSkus',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit method
|
||||
*
|
||||
* @param string|null $id Product Skus id.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
$productSku = $this->ProductSkus->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$postData = $this->request->getData();
|
||||
$saveOptions = [
|
||||
'associated' => [],
|
||||
];
|
||||
// Log::debug(print_r('$postData', true));
|
||||
public function edit($id = null) {
|
||||
$productSku = $this->ProductSkus->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$postData = $this->request->getData();
|
||||
$saveOptions = [
|
||||
'associated' => [],
|
||||
];
|
||||
// Log::debug(print_r('$postData', true));
|
||||
// Log::debug(print_r($postData, true));
|
||||
// Log::debug(print_r('$saveOptions', true));
|
||||
// Log::debug(print_r($saveOptions, true));
|
||||
$productSku = $this->ProductSkus->patchEntity($productSku, $postData, $saveOptions);
|
||||
if ($this->ProductSkus->save($productSku)) {
|
||||
$this->Flash->success(__('The product skus has been saved.'));
|
||||
$productSku = $this->ProductSkus->patchEntity($productSku, $postData, $saveOptions);
|
||||
if ($this->ProductSkus->save($productSku)) {
|
||||
$this->Flash->success(__('The product skus has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
Log::debug(print_r('$productSku->getErrors() next - failed in productSkus/edit', true));
|
||||
Log::debug(print_r($productSku->getErrors(), true));
|
||||
$this->Flash->error(__('The product skus could not be saved. Please, try again.'));
|
||||
}
|
||||
$products = $this->ProductSkus->Products->find('list', limit: 200)->all();
|
||||
$this->set(compact('productSku', 'products'));
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
Log::debug(print_r('$productSku->getErrors() next - failed in productSkus/edit', true));
|
||||
Log::debug(print_r($productSku->getErrors(), true));
|
||||
$this->Flash->error(__('The product skus could not be saved. Please, try again.'));
|
||||
}
|
||||
$products = $this->ProductSkus->Products->find('list', limit: 200)->all();
|
||||
$this->set(compact('productSku', 'products'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Delete method
|
||||
*
|
||||
* @param string|null $id Product Skus id.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productSku = $this->ProductSkus->get($id);
|
||||
if ($this->ProductSkus->delete($productSku)) {
|
||||
$this->Flash->success(__('The product skus has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product skus could not be deleted. Please, try again.'));
|
||||
}
|
||||
public function delete($id = null) {
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productSku = $this->ProductSkus->get($id);
|
||||
if ($this->ProductSkus->delete($productSku)) {
|
||||
$this->Flash->success(__('The product skus has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product skus could not be deleted. Please, try again.'));
|
||||
}
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function select()
|
||||
{
|
||||
$productSkus = $this->ProductSkus
|
||||
->find('list')
|
||||
->where(['product_id' => $this->request->getQuery('product_id', '-1')])
|
||||
->orderBy(['sku'])
|
||||
->toArray();
|
||||
public function select() {
|
||||
$productSkus = $this->ProductSkus
|
||||
->find('list')
|
||||
->where(['product_id' => $this->request->getQuery('product_id', '-1')])
|
||||
->orderBy(['sku'])
|
||||
->toArray();
|
||||
|
||||
$this->set(compact('productSkus'));
|
||||
}
|
||||
|
||||
$this->set(compact('productSkus'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,109 +10,105 @@ use Cake\Log\Log;
|
||||
*
|
||||
* @property \App\Model\Table\ProductVariantsTable $ProductVariants
|
||||
*/
|
||||
class ProductVariantsController extends AppController
|
||||
{
|
||||
/**
|
||||
class ProductVariantsController extends AppController {
|
||||
|
||||
/**
|
||||
* Index method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$query = $this->ProductVariants->find()
|
||||
->contain(['ProductCategoryVariants', 'Products']);
|
||||
$productVariants = $this->paginate($query);
|
||||
public function index() {
|
||||
$query = $this->ProductVariants->find()
|
||||
->contain(['ProductCategoryVariants', 'Products']);
|
||||
$productVariants = $this->paginate($query);
|
||||
|
||||
$this->set(compact('productVariants'));
|
||||
}
|
||||
$this->set(compact('productVariants'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* View method
|
||||
*
|
||||
* @param string|null $id Product Variant id.
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function view($id = null)
|
||||
{
|
||||
$productVariant = $this->ProductVariants->get($id, contain: ['ProductCategoryVariants', 'Products']);
|
||||
$this->set(compact('productVariant'));
|
||||
}
|
||||
public function view($id = null) {
|
||||
$productVariant = $this->ProductVariants->get($id, contain: ['ProductCategoryVariants', 'Products']);
|
||||
$this->set(compact('productVariant'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add($productId)
|
||||
{
|
||||
$product = $this->ProductVariants->Products->get($productId);
|
||||
$productVariant = $this->ProductVariants->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
$saveOptions = [];
|
||||
$postData = $this->request->getData();
|
||||
$productCategoryVariant = $this->ProductVariants->ProductCategoryVariants->get($this->request->getData('product_category_variant_id', '-1'));
|
||||
$postData['name'] = $productCategoryVariant->name;
|
||||
$postData['product_id'] = $productId;
|
||||
$productVariant = $this->ProductVariants->patchEntity($productVariant, $postData);
|
||||
if ($this->ProductVariants->save($productVariant)) {
|
||||
$this->Flash->success(__('The product variant has been saved.'));
|
||||
public function add($productId) {
|
||||
$product = $this->ProductVariants->Products->get($productId);
|
||||
$productVariant = $this->ProductVariants->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
$saveOptions = [];
|
||||
$postData = $this->request->getData();
|
||||
$productCategoryVariant = $this->ProductVariants->ProductCategoryVariants->get($this->request->getData('product_category_variant_id', '-1'));
|
||||
$postData['name'] = $productCategoryVariant->name;
|
||||
$postData['product_id'] = $productId;
|
||||
$productVariant = $this->ProductVariants->patchEntity($productVariant, $postData);
|
||||
if ($this->ProductVariants->save($productVariant)) {
|
||||
$this->Flash->success(__('The product variant has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
|
||||
Log::debug(print_r('$productVariant->getErrors()', true));
|
||||
Log::debug(print_r($productVariant->getErrors(), true));
|
||||
$this->Flash->error(__('The product variant could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategoryVariants = $this->ProductVariants->ProductCategoryVariants
|
||||
->find('list', limit: 200)
|
||||
->where(['product_category_id' => $product->product_category_id])
|
||||
->toArray();
|
||||
$this->set(compact('productVariant', 'productCategoryVariants', 'product'));
|
||||
}
|
||||
Log::debug(print_r('$productVariant->getErrors()', true));
|
||||
Log::debug(print_r($productVariant->getErrors(), true));
|
||||
$this->Flash->error(__('The product variant could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategoryVariants = $this->ProductVariants->ProductCategoryVariants
|
||||
->find('list', limit: 200)
|
||||
->where(['product_category_id' => $product->product_category_id])
|
||||
->toArray();
|
||||
$this->set(compact('productVariant', 'productCategoryVariants', 'product'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Edit method
|
||||
*
|
||||
* @param string|null $id Product Variant id.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
$productVariant = $this->ProductVariants->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$productVariant = $this->ProductVariants->patchEntity($productVariant, $this->request->getData());
|
||||
if ($this->ProductVariants->save($productVariant)) {
|
||||
$this->Flash->success(__('The product variant has been saved.'));
|
||||
public function edit($id = null) {
|
||||
$productVariant = $this->ProductVariants->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$productVariant = $this->ProductVariants->patchEntity($productVariant, $this->request->getData());
|
||||
if ($this->ProductVariants->save($productVariant)) {
|
||||
$this->Flash->success(__('The product variant has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
$this->Flash->error(__('The product variant could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategoryVariants = $this->ProductVariants->ProductCategoryVariants->find('list', limit: 200)->all();
|
||||
$products = $this->ProductVariants->Products->find('list', limit: 200)->all();
|
||||
$this->set(compact('productVariant', 'productCategoryVariants', 'products'));
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
$this->Flash->error(__('The product variant could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategoryVariants = $this->ProductVariants->ProductCategoryVariants->find('list', limit: 200)->all();
|
||||
$products = $this->ProductVariants->Products->find('list', limit: 200)->all();
|
||||
$this->set(compact('productVariant', 'productCategoryVariants', 'products'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Delete method
|
||||
*
|
||||
* @param string|null $id Product Variant id.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productVariant = $this->ProductVariants->get($id);
|
||||
if ($this->ProductVariants->delete($productVariant)) {
|
||||
$this->Flash->success(__('The product variant has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product variant could not be deleted. Please, try again.'));
|
||||
}
|
||||
public function delete($id = null) {
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productVariant = $this->ProductVariants->get($id);
|
||||
if ($this->ProductVariants->delete($productVariant)) {
|
||||
$this->Flash->success(__('The product variant has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product variant could not be deleted. Please, try again.'));
|
||||
}
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,211 +3,202 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Controller;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Log\Log;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\ORM\TableRegistry;
|
||||
|
||||
/**
|
||||
* Products Controller
|
||||
*
|
||||
* @property \CakeProducts\Model\Table\ProductsTable $Products
|
||||
*/
|
||||
class ProductsController extends AppController
|
||||
{
|
||||
/**
|
||||
class ProductsController extends AppController {
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
public function initialize(): void {
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
// $this->_defaultTable = 'CakeProducts.Products';
|
||||
// $this->_tableConfigKey = 'CakeProducts.Products.table';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Index method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$query = $this->Products->find()
|
||||
->contain(['ProductCategories']);
|
||||
$products = $this->paginate($query);
|
||||
public function index() {
|
||||
$query = $this->Products->find()
|
||||
->contain(['ProductCategories']);
|
||||
$products = $this->paginate($query);
|
||||
|
||||
$this->set(compact('products'));
|
||||
}
|
||||
$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.
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function view($id = null)
|
||||
{
|
||||
$product = $this->Products->get($id, contain: [
|
||||
'ProductCategories',
|
||||
'ProductAttributes',
|
||||
'ProductAttributes.ProductCategoryAttributes',
|
||||
'ProductAttributes.ProductCategoryAttributeOptions',
|
||||
'ProductVariants',
|
||||
'ProductVariants.ProductCategoryVariants',
|
||||
'ProductVariants.ProductCategoryVariants.ProductCategoryVariantOptions',
|
||||
'ProductSkus',
|
||||
'ProductPhotos',
|
||||
]);
|
||||
$this->set(compact('product'));
|
||||
}
|
||||
public function view($id = null) {
|
||||
$product = $this->Products->get($id, contain: [
|
||||
'ProductCategories',
|
||||
'ProductAttributes',
|
||||
'ProductAttributes.ProductCategoryAttributes',
|
||||
'ProductAttributes.ProductCategoryAttributeOptions',
|
||||
'ProductVariants',
|
||||
'ProductVariants.ProductCategoryVariants',
|
||||
'ProductVariants.ProductCategoryVariants.ProductCategoryVariantOptions',
|
||||
'ProductSkus',
|
||||
'ProductPhotos',
|
||||
]);
|
||||
$this->set(compact('product'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$productsTable = $this->Products;
|
||||
$product = $productsTable->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
$postData = $this->request->getData();
|
||||
$saveOptions = [
|
||||
'associated' => ['ProductAttributes'],
|
||||
];
|
||||
Log::debug(print_r('$postData', true));
|
||||
Log::debug(print_r($postData, true));
|
||||
Log::debug(print_r('$saveOptions', true));
|
||||
Log::debug(print_r($saveOptions, true));
|
||||
$productVariantsData = [];
|
||||
if (isset($postData['product_variants']) && $postData['product_variants']) {
|
||||
foreach ($postData['product_variants'] as $postedProductVariant) {
|
||||
if (!isset($postedProductVariant['enabled']) || !$postedProductVariant['enabled'] || !isset($postedProductVariant['product_category_variant_id'])) {
|
||||
continue;
|
||||
}
|
||||
$existingVariant = $this->Products->ProductCategories->ProductCategoryVariants->get($postedProductVariant['product_category_variant_id'], contain: ['ProductCategoryVariantOptions']);
|
||||
$optionsData = [];
|
||||
foreach ($existingVariant->product_category_variant_options as $existingOption) {
|
||||
$optionsData[] = [
|
||||
'variant_value' => $existingOption->variant_value,
|
||||
'variant_label' => $existingOption->variant_label ?? null,
|
||||
'enabled' => $existingOption->enabled,
|
||||
];
|
||||
}
|
||||
$tmpVariantData = [
|
||||
'name' => $existingVariant->name,
|
||||
'product_category_variant_id' => $postedProductVariant['product_category_variant_id'],
|
||||
'enabled' => true,
|
||||
'product_category_variant_options' => $optionsData,
|
||||
];
|
||||
$productVariantsData[] = $tmpVariantData;
|
||||
}
|
||||
}
|
||||
if ($productVariantsData) {
|
||||
$saveOptions['fields'] = [
|
||||
'name',
|
||||
'product_category_id',
|
||||
'product_type_id',
|
||||
'product_attributes',
|
||||
'product_category_variants'
|
||||
];
|
||||
$saveOptions['associated']['ProductCategoryVariants'] = [
|
||||
'fields' => [
|
||||
'name',
|
||||
'enabled',
|
||||
'product_category_variant_options',
|
||||
]
|
||||
];
|
||||
$saveOptions['associated'][] = 'ProductCategoryVariants.ProductCategoryVariantOptions';
|
||||
$postData['product_category_variants'] = $productVariantsData;
|
||||
}
|
||||
$product = $productsTable->patchEntity($product, $postData, $saveOptions);
|
||||
if ($productsTable->save($product, $saveOptions)) {
|
||||
$this->Flash->success(__('The product has been saved.'));
|
||||
public function add() {
|
||||
$productsTable = $this->Products;
|
||||
$product = $productsTable->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
$postData = $this->request->getData();
|
||||
$saveOptions = [
|
||||
'associated' => ['ProductAttributes'],
|
||||
];
|
||||
Log::debug(print_r('$postData', true));
|
||||
Log::debug(print_r($postData, true));
|
||||
Log::debug(print_r('$saveOptions', true));
|
||||
Log::debug(print_r($saveOptions, true));
|
||||
$productVariantsData = [];
|
||||
if (isset($postData['product_variants']) && $postData['product_variants']) {
|
||||
foreach ($postData['product_variants'] as $postedProductVariant) {
|
||||
if (!isset($postedProductVariant['enabled']) || !$postedProductVariant['enabled'] || !isset($postedProductVariant['product_category_variant_id'])) {
|
||||
continue;
|
||||
}
|
||||
$existingVariant = $this->Products->ProductCategories->ProductCategoryVariants->get($postedProductVariant['product_category_variant_id'], contain: ['ProductCategoryVariantOptions']);
|
||||
$optionsData = [];
|
||||
foreach ($existingVariant->product_category_variant_options as $existingOption) {
|
||||
$optionsData[] = [
|
||||
'variant_value' => $existingOption->variant_value,
|
||||
'variant_label' => $existingOption->variant_label ?? null,
|
||||
'enabled' => $existingOption->enabled,
|
||||
];
|
||||
}
|
||||
$tmpVariantData = [
|
||||
'name' => $existingVariant->name,
|
||||
'product_category_variant_id' => $postedProductVariant['product_category_variant_id'],
|
||||
'enabled' => true,
|
||||
'product_category_variant_options' => $optionsData,
|
||||
];
|
||||
$productVariantsData[] = $tmpVariantData;
|
||||
}
|
||||
}
|
||||
if ($productVariantsData) {
|
||||
$saveOptions['fields'] = [
|
||||
'name',
|
||||
'product_category_id',
|
||||
'product_type_id',
|
||||
'product_attributes',
|
||||
'product_category_variants',
|
||||
];
|
||||
$saveOptions['associated']['ProductCategoryVariants'] = [
|
||||
'fields' => [
|
||||
'name',
|
||||
'enabled',
|
||||
'product_category_variant_options',
|
||||
],
|
||||
];
|
||||
$saveOptions['associated'][] = 'ProductCategoryVariants.ProductCategoryVariantOptions';
|
||||
$postData['product_category_variants'] = $productVariantsData;
|
||||
}
|
||||
$product = $productsTable->patchEntity($product, $postData, $saveOptions);
|
||||
if ($productsTable->save($product, $saveOptions)) {
|
||||
$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.'));
|
||||
}
|
||||
$productCategory = $product->product_category_id ? $productsTable->ProductCategories->find()->where(['internal_id' => $product->product_category_id])->first() : null;
|
||||
$productCatalogs = $productsTable->ProductCategories->ProductCatalogs->find('list')->toArray();
|
||||
$this->set(compact('product', 'productCatalogs', 'productCategory'));
|
||||
}
|
||||
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.'));
|
||||
}
|
||||
$productCategory = $product->product_category_id ? $productsTable->ProductCategories->find()->where(['internal_id' => $product->product_category_id])->first() : null;
|
||||
$productCatalogs = $productsTable->ProductCategories->ProductCatalogs->find('list')->toArray();
|
||||
$this->set(compact('product', 'productCatalogs', 'productCategory'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 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.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
$productsTable = $this->Products;
|
||||
$product = $productsTable->get($id, contain: [
|
||||
'ProductAttributes',
|
||||
'ProductAttributes.ProductCategoryAttributes',
|
||||
'ProductAttributes.ProductCategoryAttributes.ProductCategoryAttributeOptions',
|
||||
]);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$saveOptions = [
|
||||
'associated' => ['ProductAttributes'],
|
||||
];
|
||||
$product = $productsTable->patchEntity($product, $this->request->getData(), $saveOptions);
|
||||
if ($productsTable->save($product)) {
|
||||
$this->Flash->success(__('The product has been saved.'));
|
||||
public function edit($id = null) {
|
||||
$productsTable = $this->Products;
|
||||
$product = $productsTable->get($id, contain: [
|
||||
'ProductAttributes',
|
||||
'ProductAttributes.ProductCategoryAttributes',
|
||||
'ProductAttributes.ProductCategoryAttributes.ProductCategoryAttributeOptions',
|
||||
]);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$saveOptions = [
|
||||
'associated' => ['ProductAttributes'],
|
||||
];
|
||||
$product = $productsTable->patchEntity($product, $this->request->getData(), $saveOptions);
|
||||
if ($productsTable->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.'));
|
||||
}
|
||||
$productCategory = $product->product_category_id ? $productsTable->ProductCategories->find()->where(['internal_id' => $product->product_category_id])->first() : null;
|
||||
$productCatalogs = $productsTable->ProductCategories->ProductCatalogs->find('list')->toArray();
|
||||
$this->set(compact('product', 'productCatalogs', 'productCategory'));
|
||||
}
|
||||
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.'));
|
||||
}
|
||||
$productCategory = $product->product_category_id ? $productsTable->ProductCategories->find()->where(['internal_id' => $product->product_category_id])->first() : null;
|
||||
$productCatalogs = $productsTable->ProductCategories->ProductCatalogs->find('list')->toArray();
|
||||
$this->set(compact('product', 'productCatalogs', 'productCategory'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 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.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
public function delete($id = null) {
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
|
||||
$productsTable = $this->Products;
|
||||
$product = $productsTable->get($id);
|
||||
if ($productsTable->delete($product)) {
|
||||
$this->Flash->success(__('The product has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product could not be deleted. Please, try again.'));
|
||||
}
|
||||
$productsTable = $this->Products;
|
||||
$product = $productsTable->get($id);
|
||||
if ($productsTable->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']);
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function select()
|
||||
{
|
||||
$productsTable = $this->Products;
|
||||
$productCategory = $productsTable->ProductCategories->find()
|
||||
->where(['id' => $this->request->getQuery('product_category_id', '-1')])
|
||||
->first();
|
||||
$products = $productsTable
|
||||
->find('list')
|
||||
->where(['product_category_id' => $productCategory->internal_id ?? '-1'])
|
||||
->orderBy(['Products.name'])
|
||||
->toArray();
|
||||
public function select() {
|
||||
$productsTable = $this->Products;
|
||||
$productCategory = $productsTable->ProductCategories->find()
|
||||
->where(['id' => $this->request->getQuery('product_category_id', '-1')])
|
||||
->first();
|
||||
$products = $productsTable
|
||||
->find('list')
|
||||
->where(['product_category_id' => $productCategory->internal_id ?? '-1'])
|
||||
->orderBy(['Products.name'])
|
||||
->toArray();
|
||||
|
||||
$this->set(compact('products'));
|
||||
}
|
||||
|
||||
$this->set(compact('products'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,7 @@
|
||||
|
||||
namespace CakeProducts\Model\Behavior;
|
||||
|
||||
use ArrayObject;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Event\EventInterface;
|
||||
use Cake\ORM\Behavior;
|
||||
use LogicException;
|
||||
use Tools\Model\Behavior\ToggleBehavior;
|
||||
|
||||
/**
|
||||
@@ -21,37 +17,38 @@ use Tools\Model\Behavior\ToggleBehavior;
|
||||
*/
|
||||
class SecondToggleBehavior extends ToggleBehavior {
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default config
|
||||
*
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
protected array $_defaultConfig = [
|
||||
'field' => 'primary',
|
||||
'on' => 'afterSave', // afterSave (without transactions) or beforeSave (with transactions)
|
||||
'scopeFields' => [],
|
||||
'scope' => [],
|
||||
'findOrder' => null, // null = autodetect modified/created, false to disable
|
||||
'implementedMethods' => [], // to prevent conflict with public toggleField method
|
||||
];
|
||||
protected array $_defaultConfig = [
|
||||
'field' => 'primary',
|
||||
'on' => 'afterSave', // afterSave (without transactions) or beforeSave (with transactions)
|
||||
'scopeFields' => [],
|
||||
'scope' => [],
|
||||
'findOrder' => null, // null = autodetect modified/created, false to disable
|
||||
'implementedMethods' => [], // to prevent conflict with public toggleField method
|
||||
];
|
||||
|
||||
/**
|
||||
/**
|
||||
* @param \Cake\Datasource\EntityInterface $entity
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function buildConditions(EntityInterface $entity) {
|
||||
$conditions = $this->getConfig('scope');
|
||||
$scopeFields = (array)$this->getConfig('scopeFields');
|
||||
protected function buildConditions(EntityInterface $entity) {
|
||||
$conditions = $this->getConfig('scope');
|
||||
$scopeFields = (array)$this->getConfig('scopeFields');
|
||||
|
||||
foreach ($scopeFields as $scopeField) {
|
||||
if ($entity->get($scopeField) === null) {
|
||||
continue;
|
||||
}
|
||||
$conditions[$scopeField] = $entity->get($scopeField);
|
||||
}
|
||||
foreach ($scopeFields as $scopeField) {
|
||||
if ($entity->get($scopeField) === null) {
|
||||
continue;
|
||||
}
|
||||
$conditions[$scopeField] = $entity->get($scopeField);
|
||||
}
|
||||
// dd($conditions);
|
||||
|
||||
return $conditions;
|
||||
}
|
||||
return $conditions;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,11 +2,7 @@
|
||||
|
||||
namespace CakeProducts\Model\Behavior;
|
||||
|
||||
use ArrayObject;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Event\EventInterface;
|
||||
use Cake\ORM\Behavior;
|
||||
use LogicException;
|
||||
use Tools\Model\Behavior\ToggleBehavior;
|
||||
|
||||
/**
|
||||
@@ -21,37 +17,38 @@ use Tools\Model\Behavior\ToggleBehavior;
|
||||
*/
|
||||
class ThirdToggleBehavior extends ToggleBehavior {
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default config
|
||||
*
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
protected array $_defaultConfig = [
|
||||
'field' => 'primary',
|
||||
'on' => 'afterSave', // afterSave (without transactions) or beforeSave (with transactions)
|
||||
'scopeFields' => [],
|
||||
'scope' => [],
|
||||
'findOrder' => null, // null = autodetect modified/created, false to disable
|
||||
'implementedMethods' => [], // to prevent conflict with public toggleField method
|
||||
];
|
||||
protected array $_defaultConfig = [
|
||||
'field' => 'primary',
|
||||
'on' => 'afterSave', // afterSave (without transactions) or beforeSave (with transactions)
|
||||
'scopeFields' => [],
|
||||
'scope' => [],
|
||||
'findOrder' => null, // null = autodetect modified/created, false to disable
|
||||
'implementedMethods' => [], // to prevent conflict with public toggleField method
|
||||
];
|
||||
|
||||
/**
|
||||
/**
|
||||
* @param \Cake\Datasource\EntityInterface $entity
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function buildConditions(EntityInterface $entity) {
|
||||
$conditions = $this->getConfig('scope');
|
||||
$scopeFields = (array)$this->getConfig('scopeFields');
|
||||
protected function buildConditions(EntityInterface $entity) {
|
||||
$conditions = $this->getConfig('scope');
|
||||
$scopeFields = (array)$this->getConfig('scopeFields');
|
||||
|
||||
foreach ($scopeFields as $scopeField) {
|
||||
if ($entity->get($scopeField) === null) {
|
||||
continue;
|
||||
}
|
||||
$conditions[$scopeField] = $entity->get($scopeField);
|
||||
}
|
||||
foreach ($scopeFields as $scopeField) {
|
||||
if ($entity->get($scopeField) === null) {
|
||||
continue;
|
||||
}
|
||||
$conditions[$scopeField] = $entity->get($scopeField);
|
||||
}
|
||||
// dd($conditions);
|
||||
|
||||
return $conditions;
|
||||
}
|
||||
return $conditions;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\I18n\DateTime;
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
@@ -12,15 +11,15 @@ use Cake\ORM\Entity;
|
||||
* @property int $id
|
||||
* @property string $base_url
|
||||
* @property string $api_url
|
||||
* @property DateTime $created
|
||||
* @property DateTime|null $deleted
|
||||
* @property \Cake\I18n\DateTime $created
|
||||
* @property \Cake\I18n\DateTime|null $deleted
|
||||
*
|
||||
* @property ProductCatalog[] $product_catalogs
|
||||
* @property ExternalProductCatalogsProductCatalog[] $external_product_catalogs_product_catalogs
|
||||
*/
|
||||
class ExternalProductCatalog extends Entity
|
||||
{
|
||||
/**
|
||||
class ExternalProductCatalog extends Entity {
|
||||
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
@@ -29,14 +28,15 @@ class ExternalProductCatalog extends Entity
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'base_url' => true,
|
||||
'api_url' => true,
|
||||
'created' => true,
|
||||
'deleted' => true,
|
||||
'enabled' => true,
|
||||
protected array $_accessible = [
|
||||
'base_url' => true,
|
||||
'api_url' => true,
|
||||
'created' => true,
|
||||
'deleted' => true,
|
||||
'enabled' => true,
|
||||
|
||||
// entities
|
||||
'external_product_catalogs_product_catalogs' => true,
|
||||
];
|
||||
|
||||
// entities
|
||||
'external_product_catalogs_product_catalogs' => true,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\I18n\DateTime;
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
@@ -12,16 +11,16 @@ use Cake\ORM\Entity;
|
||||
* @property int $id
|
||||
* @property string $external_product_catalog_id
|
||||
* @property string $product_catalog_id
|
||||
* @property DateTime $created
|
||||
* @property \Cake\I18n\DateTime $created
|
||||
* @property bool $enabled
|
||||
* @property DateTime|null $deleted
|
||||
* @property \Cake\I18n\DateTime|null $deleted
|
||||
*
|
||||
* @property ExternalProductCatalog $external_product_catalog
|
||||
* @property ProductCatalog $product_catalog
|
||||
*/
|
||||
class ExternalProductCatalogsProductCatalog extends Entity
|
||||
{
|
||||
/**
|
||||
class ExternalProductCatalogsProductCatalog extends Entity {
|
||||
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
@@ -30,15 +29,16 @@ class ExternalProductCatalogsProductCatalog extends Entity
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'external_product_catalog_id' => true,
|
||||
'product_catalog_id' => true,
|
||||
'created' => true,
|
||||
'enabled' => true,
|
||||
'deleted' => true,
|
||||
protected array $_accessible = [
|
||||
'external_product_catalog_id' => true,
|
||||
'product_catalog_id' => true,
|
||||
'created' => true,
|
||||
'enabled' => true,
|
||||
'deleted' => true,
|
||||
|
||||
// entities
|
||||
'external_product_catalog' => true,
|
||||
'product_catalog' => true,
|
||||
];
|
||||
|
||||
// entities
|
||||
'external_product_catalog' => true,
|
||||
'product_catalog' => true,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -3,9 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\I18n\DateTime;
|
||||
use Cake\ORM\Entity;
|
||||
use CakeProducts\Model\Enum\ProductProductTypeId;
|
||||
|
||||
/**
|
||||
* Product Entity
|
||||
@@ -13,17 +11,16 @@ use CakeProducts\Model\Enum\ProductProductTypeId;
|
||||
* @property string $id
|
||||
* @property string $name
|
||||
* @property string $product_category_id
|
||||
* @property ProductProductTypeId $product_type_id
|
||||
* @property DateTime|null $deleted
|
||||
* @property \CakeProducts\Model\Enum\ProductProductTypeId $product_type_id
|
||||
* @property \Cake\I18n\DateTime|null $deleted
|
||||
*
|
||||
* @property ProductCategory $product_category
|
||||
* @property ProductAttribute[] $product_attributes
|
||||
* @property ProductCategoryVariant[] $product_category_variants
|
||||
*
|
||||
*/
|
||||
class Product extends Entity
|
||||
{
|
||||
/**
|
||||
class Product extends Entity {
|
||||
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
@@ -32,16 +29,17 @@ class Product extends Entity
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'name' => true,
|
||||
'product_category_id' => true,
|
||||
'product_type_id' => true,
|
||||
'deleted' => true,
|
||||
protected array $_accessible = [
|
||||
'name' => true,
|
||||
'product_category_id' => true,
|
||||
'product_type_id' => true,
|
||||
'deleted' => true,
|
||||
|
||||
// entities
|
||||
'product_category' => false,
|
||||
'product_attributes' => true,
|
||||
'product_category_variants' => true,
|
||||
'primary_product_photo' => true,
|
||||
];
|
||||
|
||||
// entities
|
||||
'product_category' => false,
|
||||
'product_attributes' => true,
|
||||
'product_category_variants' => true,
|
||||
'primary_product_photo' => true,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\I18n\DateTime;
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
@@ -14,15 +13,15 @@ use Cake\ORM\Entity;
|
||||
* @property string $product_category_attribute_id
|
||||
* @property string|null $attribute_value
|
||||
* @property string|null $product_category_attribute_option_id
|
||||
* @property DateTime|null $deleted
|
||||
* @property \Cake\I18n\DateTime|null $deleted
|
||||
*
|
||||
* @property Product $product
|
||||
* @property ProductCategoryAttribute $product_category_attribute
|
||||
* @property ProductCategoryAttributeOption $product_category_attribute_option
|
||||
*/
|
||||
class ProductAttribute extends Entity
|
||||
{
|
||||
/**
|
||||
class ProductAttribute extends Entity {
|
||||
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
@@ -31,16 +30,17 @@ class ProductAttribute extends Entity
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'product_id' => true,
|
||||
'product_category_attribute_id' => true,
|
||||
'attribute_value' => true,
|
||||
'product_category_attribute_option_id' => true,
|
||||
'deleted' => true,
|
||||
protected array $_accessible = [
|
||||
'product_id' => true,
|
||||
'product_category_attribute_id' => true,
|
||||
'attribute_value' => true,
|
||||
'product_category_attribute_option_id' => true,
|
||||
'deleted' => true,
|
||||
|
||||
// entities
|
||||
'product' => false,
|
||||
'product_category_attribute' => false,
|
||||
'product_category_attribute_option' => false,
|
||||
];
|
||||
|
||||
// entities
|
||||
'product' => false,
|
||||
'product_category_attribute' => false,
|
||||
'product_category_attribute_option' => false,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\I18n\DateTime;
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
@@ -13,14 +12,14 @@ use Cake\ORM\Entity;
|
||||
* @property string $name
|
||||
* @property string|null $catalog_description
|
||||
* @property bool $enabled
|
||||
* @property DateTime|null $deleted
|
||||
* @property \Cake\I18n\DateTime|null $deleted
|
||||
*
|
||||
* @property ProductCategory[] $product_categories
|
||||
* @property ExternalProductCatalog[] $external_product_catalogs
|
||||
*/
|
||||
class ProductCatalog extends Entity
|
||||
{
|
||||
/**
|
||||
class ProductCatalog extends Entity {
|
||||
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
@@ -29,14 +28,15 @@ class ProductCatalog extends Entity
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'name' => true,
|
||||
'catalog_description' => true,
|
||||
'enabled' => true,
|
||||
'deleted' => true,
|
||||
protected array $_accessible = [
|
||||
'name' => true,
|
||||
'catalog_description' => true,
|
||||
'enabled' => true,
|
||||
'deleted' => true,
|
||||
|
||||
// entities
|
||||
'product_categories' => true,
|
||||
'external_product_catalogs' => true,
|
||||
];
|
||||
|
||||
// entities
|
||||
'product_categories' => true,
|
||||
'external_product_catalogs' => true,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -3,9 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\I18n\DateTime;
|
||||
use Cake\ORM\Entity;
|
||||
use CakeProducts\Model\Enum\ProductProductTypeId;
|
||||
|
||||
/**
|
||||
* ProductCategory Entity
|
||||
@@ -19,16 +17,16 @@ use CakeProducts\Model\Enum\ProductProductTypeId;
|
||||
* @property int $lft
|
||||
* @property int $rght
|
||||
* @property bool $enabled
|
||||
* @property DateTime|null $deleted
|
||||
* @property ProductProductTypeId|null $default_product_type_id
|
||||
* @property \Cake\I18n\DateTime|null $deleted
|
||||
* @property \CakeProducts\Model\Enum\ProductProductTypeId|null $default_product_type_id
|
||||
*
|
||||
* @property \CakeProducts\Model\Entity\ProductCatalog $product_catalog
|
||||
* @property \CakeProducts\Model\Entity\ParentProductCategory $parent_product_category
|
||||
* @property \CakeProducts\Model\Entity\ChildProductCategory[] $child_product_categories
|
||||
*/
|
||||
class ProductCategory extends Entity
|
||||
{
|
||||
/**
|
||||
class ProductCategory extends Entity {
|
||||
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
@@ -37,22 +35,23 @@ class ProductCategory extends Entity
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'product_catalog_id' => true,
|
||||
'internal_id' => true,
|
||||
'name' => true,
|
||||
'category_description' => true,
|
||||
'default_product_type_id' => true,
|
||||
'parent_id' => true,
|
||||
'lft' => true,
|
||||
'rght' => true,
|
||||
'enabled' => true,
|
||||
'deleted' => true,
|
||||
protected array $_accessible = [
|
||||
'product_catalog_id' => true,
|
||||
'internal_id' => true,
|
||||
'name' => true,
|
||||
'category_description' => true,
|
||||
'default_product_type_id' => true,
|
||||
'parent_id' => true,
|
||||
'lft' => true,
|
||||
'rght' => true,
|
||||
'enabled' => true,
|
||||
'deleted' => true,
|
||||
|
||||
// entities
|
||||
'product_catalog' => true,
|
||||
'parent_product_category' => true,
|
||||
'child_product_categories' => true,
|
||||
'primary_product_photo' => true,
|
||||
];
|
||||
|
||||
// entities
|
||||
'product_catalog' => true,
|
||||
'parent_product_category' => true,
|
||||
'child_product_categories' => true,
|
||||
'primary_product_photo' => true,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\I18n\DateTime;
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
@@ -14,14 +13,14 @@ use Cake\ORM\Entity;
|
||||
* @property string|null $product_category_id
|
||||
* @property int $attribute_type_id
|
||||
* @property bool $enabled
|
||||
* @property DateTime|null $deleted
|
||||
* @property \Cake\I18n\DateTime|null $deleted
|
||||
*
|
||||
* @property ProductCategory $product_category
|
||||
* @property ProductCategoryAttributeOption[] $product_category_attribute_options
|
||||
*/
|
||||
class ProductCategoryAttribute extends Entity
|
||||
{
|
||||
/**
|
||||
class ProductCategoryAttribute extends Entity {
|
||||
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
@@ -30,15 +29,16 @@ class ProductCategoryAttribute extends Entity
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'name' => true,
|
||||
'product_category_id' => true,
|
||||
'attribute_type_id' => true,
|
||||
'enabled' => true,
|
||||
'deleted' => true,
|
||||
protected array $_accessible = [
|
||||
'name' => true,
|
||||
'product_category_id' => true,
|
||||
'attribute_type_id' => true,
|
||||
'enabled' => true,
|
||||
'deleted' => true,
|
||||
|
||||
// entities
|
||||
'product_category' => true,
|
||||
'product_category_attribute_options' => true,
|
||||
];
|
||||
|
||||
// entities
|
||||
'product_category' => true,
|
||||
'product_category_attribute_options' => true,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\I18n\DateTime;
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
@@ -14,13 +13,13 @@ use Cake\ORM\Entity;
|
||||
* @property string $attribute_value
|
||||
* @property string $attribute_label
|
||||
* @property bool $enabled
|
||||
* @property DateTime|null $deleted
|
||||
* @property \Cake\I18n\DateTime|null $deleted
|
||||
*
|
||||
* @property ProductCategoryAttribute $product_category_attribute
|
||||
*/
|
||||
class ProductCategoryAttributeOption extends Entity
|
||||
{
|
||||
/**
|
||||
class ProductCategoryAttributeOption extends Entity {
|
||||
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
@@ -29,14 +28,15 @@ class ProductCategoryAttributeOption extends Entity
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'product_category_attribute_id' => true,
|
||||
'attribute_value' => true,
|
||||
'attribute_label' => true,
|
||||
'enabled' => true,
|
||||
'deleted' => true,
|
||||
protected array $_accessible = [
|
||||
'product_category_attribute_id' => true,
|
||||
'attribute_value' => true,
|
||||
'attribute_label' => true,
|
||||
'enabled' => true,
|
||||
'deleted' => true,
|
||||
|
||||
// entities
|
||||
'product_category_attribute' => true,
|
||||
];
|
||||
|
||||
// entities
|
||||
'product_category_attribute' => true,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
@@ -16,12 +15,12 @@ use Cake\ORM\Entity;
|
||||
* @property bool $enabled
|
||||
* @property bool $is_system_variant
|
||||
*
|
||||
* @property ProductCategory|EntityInterface $product_category
|
||||
* @property ProductCategoryVariantOption[]|EntityInterface[] $product_category_variant_options
|
||||
* @property ProductCategory|\Cake\Datasource\EntityInterface $product_category
|
||||
* @property ProductCategoryVariantOption[]|\Cake\Datasource\EntityInterface[] $product_category_variant_options
|
||||
*/
|
||||
class ProductCategoryVariant extends Entity
|
||||
{
|
||||
/**
|
||||
class ProductCategoryVariant extends Entity {
|
||||
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
@@ -30,16 +29,17 @@ class ProductCategoryVariant extends Entity
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'name' => true,
|
||||
'product_category_id' => true,
|
||||
'product_id' => true,
|
||||
'enabled' => true,
|
||||
'is_system_variant' => true,
|
||||
protected array $_accessible = [
|
||||
'name' => true,
|
||||
'product_category_id' => true,
|
||||
'product_id' => true,
|
||||
'enabled' => true,
|
||||
'is_system_variant' => true,
|
||||
|
||||
// entities
|
||||
'product_category' => false,
|
||||
'product' => false,
|
||||
'product_category_variant_options' => true,
|
||||
];
|
||||
|
||||
// entities
|
||||
'product_category' => false,
|
||||
'product' => false,
|
||||
'product_category_variant_options' => true,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ use Cake\ORM\Entity;
|
||||
*
|
||||
* @property \App\Model\Entity\ProductCategoryVariant $product_category_variant
|
||||
*/
|
||||
class ProductCategoryVariantOption extends Entity
|
||||
{
|
||||
/**
|
||||
class ProductCategoryVariantOption extends Entity {
|
||||
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
@@ -28,14 +28,15 @@ class ProductCategoryVariantOption extends Entity
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'product_category_variant_id' => true,
|
||||
'variant_value' => true,
|
||||
'created' => true,
|
||||
'modified' => true,
|
||||
'deleted' => true,
|
||||
protected array $_accessible = [
|
||||
'product_category_variant_id' => true,
|
||||
'variant_value' => true,
|
||||
'created' => true,
|
||||
'modified' => true,
|
||||
'deleted' => true,
|
||||
|
||||
// entities
|
||||
'product_category_variant' => false,
|
||||
];
|
||||
|
||||
// entities
|
||||
'product_category_variant' => false,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\I18n\DateTime;
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
@@ -20,17 +19,17 @@ use Cake\ORM\Entity;
|
||||
* @property bool $primary_sku_photo
|
||||
* @property int $photo_position
|
||||
* @property bool $enabled
|
||||
* @property DateTime $created
|
||||
* @property DateTime|null $modified
|
||||
* @property DateTime|null $deleted
|
||||
* @property \Cake\I18n\DateTime $created
|
||||
* @property \Cake\I18n\DateTime|null $modified
|
||||
* @property \Cake\I18n\DateTime|null $deleted
|
||||
*
|
||||
* @property Product|null $product
|
||||
* @property ProductSku|null $product_sku
|
||||
* @property ProductCategory $product_category
|
||||
*/
|
||||
class ProductPhoto extends Entity
|
||||
{
|
||||
/**
|
||||
class ProductPhoto extends Entity {
|
||||
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
@@ -39,24 +38,25 @@ class ProductPhoto extends Entity
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'product_id' => true,
|
||||
'product_sku_id' => true,
|
||||
'product_category_id' => true,
|
||||
'photo_dir' => true,
|
||||
'photo_filename' => true,
|
||||
'primary_photo' => true,
|
||||
'primary_category_photo' => true,
|
||||
'primary_sku_photo' => true,
|
||||
'photo_position' => true,
|
||||
'enabled' => true,
|
||||
'created' => true,
|
||||
'modified' => true,
|
||||
'deleted' => true,
|
||||
protected array $_accessible = [
|
||||
'product_id' => true,
|
||||
'product_sku_id' => true,
|
||||
'product_category_id' => true,
|
||||
'photo_dir' => true,
|
||||
'photo_filename' => true,
|
||||
'primary_photo' => true,
|
||||
'primary_category_photo' => true,
|
||||
'primary_sku_photo' => true,
|
||||
'photo_position' => true,
|
||||
'enabled' => true,
|
||||
'created' => true,
|
||||
'modified' => true,
|
||||
'deleted' => true,
|
||||
|
||||
// entities
|
||||
'product' => false,
|
||||
'product_sku' => false,
|
||||
'product_category' => false,
|
||||
];
|
||||
|
||||
// entities
|
||||
'product' => false,
|
||||
'product_sku' => false,
|
||||
'product_category' => false,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\I18n\DateTime;
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
@@ -15,17 +14,17 @@ use Cake\ORM\Entity;
|
||||
* @property string|null $barcode
|
||||
* @property string|null $price
|
||||
* @property string|null $cost
|
||||
* @property DateTime $created
|
||||
* @property DateTime|null $modified
|
||||
* @property DateTime|null $deleted
|
||||
* @property \Cake\I18n\DateTime $created
|
||||
* @property \Cake\I18n\DateTime|null $modified
|
||||
* @property \Cake\I18n\DateTime|null $deleted
|
||||
* @property bool $default_sku
|
||||
*
|
||||
* @property Product $product
|
||||
* @property ProductSkuVariantValue[] $product_sku_variant_values
|
||||
*/
|
||||
class ProductSku extends Entity
|
||||
{
|
||||
/**
|
||||
class ProductSku extends Entity {
|
||||
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
@@ -34,19 +33,20 @@ class ProductSku extends Entity
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'product_id' => true,
|
||||
'sku' => true,
|
||||
'barcode' => true,
|
||||
'price' => true,
|
||||
'cost' => true,
|
||||
'created' => true,
|
||||
'modified' => true,
|
||||
'deleted' => true,
|
||||
'default_sku' => true,
|
||||
protected array $_accessible = [
|
||||
'product_id' => true,
|
||||
'sku' => true,
|
||||
'barcode' => true,
|
||||
'price' => true,
|
||||
'cost' => true,
|
||||
'created' => true,
|
||||
'modified' => true,
|
||||
'deleted' => true,
|
||||
'default_sku' => true,
|
||||
|
||||
// entities
|
||||
'product' => false,
|
||||
'product_sku_variant_values' => true,
|
||||
];
|
||||
|
||||
// entities
|
||||
'product' => false,
|
||||
'product_sku_variant_values' => true,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ use Cake\ORM\Entity;
|
||||
* @property ProductCategoryVariant $product_category_variant
|
||||
* @property ProductCategoryVariantOption $product_category_variant_option
|
||||
*/
|
||||
class ProductSkuVariantValue extends Entity
|
||||
{
|
||||
/**
|
||||
class ProductSkuVariantValue extends Entity {
|
||||
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
@@ -28,14 +28,15 @@ class ProductSkuVariantValue extends Entity
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'product_sku_id' => true,
|
||||
'product_variant_id' => true,
|
||||
'product_category_variant_option_id' => true,
|
||||
protected array $_accessible = [
|
||||
'product_sku_id' => true,
|
||||
'product_variant_id' => true,
|
||||
'product_category_variant_option_id' => true,
|
||||
|
||||
// entities
|
||||
'product_sku' => true,
|
||||
'product_variant' => true,
|
||||
'product_category_variant_option' => true,
|
||||
];
|
||||
|
||||
// entities
|
||||
'product_sku' => true,
|
||||
'product_variant' => true,
|
||||
'product_category_variant_option' => true,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ use Cake\ORM\Entity;
|
||||
* @property \App\Model\Entity\ProductCategoryVariant $product_category_variant
|
||||
* @property \App\Model\Entity\Product $product
|
||||
*/
|
||||
class ProductVariant extends Entity
|
||||
{
|
||||
/**
|
||||
class ProductVariant extends Entity {
|
||||
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
@@ -28,12 +28,13 @@ class ProductVariant extends Entity
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'name' => true,
|
||||
'product_category_variant_id' => true,
|
||||
'product_id' => true,
|
||||
'enabled' => true,
|
||||
'product_category_variant' => true,
|
||||
'product' => true,
|
||||
];
|
||||
protected array $_accessible = [
|
||||
'name' => true,
|
||||
'product_category_variant_id' => true,
|
||||
'product_id' => true,
|
||||
'enabled' => true,
|
||||
'product_category_variant' => true,
|
||||
'product' => true,
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
@@ -5,18 +5,10 @@ namespace CakeProducts\Model\Table;
|
||||
|
||||
use ArrayObject;
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Datasource\ResultSetInterface;
|
||||
use Cake\Event\EventInterface;
|
||||
use Cake\ORM\Association\BelongsTo;
|
||||
use Cake\ORM\Behavior\TimestampBehavior;
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog;
|
||||
use Closure;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
/**
|
||||
* ExternalProductCatalogsProductCatalogs Model
|
||||
@@ -24,15 +16,15 @@ use Psr\SimpleCache\CacheInterface;
|
||||
* @property ExternalProductCatalogsTable&BelongsTo $ExternalProductCatalogs
|
||||
* @property ProductCatalogsTable&BelongsTo $ProductCatalogs
|
||||
*
|
||||
* @method ExternalProductCatalogsProductCatalog newEmptyEntity()
|
||||
* @method ExternalProductCatalogsProductCatalog newEntity(array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog newEmptyEntity()
|
||||
* @method \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog newEntity()
|
||||
* @method array<ExternalProductCatalogsProductCatalog> newEntities(array $data, array $options = [])
|
||||
* @method ExternalProductCatalogsProductCatalog get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
|
||||
* @method ExternalProductCatalogsProductCatalog findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method ExternalProductCatalogsProductCatalog patchEntity(EntityInterface $entity, array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog get()
|
||||
* @method \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog findOrCreate()
|
||||
* @method \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog patchEntity()
|
||||
* @method array<ExternalProductCatalogsProductCatalog> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method ExternalProductCatalogsProductCatalog|false save(EntityInterface $entity, array $options = [])
|
||||
* @method ExternalProductCatalogsProductCatalog saveOrFail(EntityInterface $entity, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog saveOrFail()
|
||||
* @method iterable<ExternalProductCatalogsProductCatalog>|ResultSetInterface<ExternalProductCatalogsProductCatalog>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ExternalProductCatalogsProductCatalog>|ResultSetInterface<ExternalProductCatalogsProductCatalog> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<ExternalProductCatalogsProductCatalog>|ResultSetInterface<ExternalProductCatalogsProductCatalog>|false deleteMany(iterable $entities, array $options = [])
|
||||
@@ -40,86 +32,86 @@ use Psr\SimpleCache\CacheInterface;
|
||||
*
|
||||
* @mixin TimestampBehavior
|
||||
*/
|
||||
class ExternalProductCatalogsProductCatalogsTable extends Table
|
||||
{
|
||||
/**
|
||||
class ExternalProductCatalogsProductCatalogsTable extends Table {
|
||||
|
||||
/**
|
||||
* Initialize method
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('external_product_catalogs_product_catalogs');
|
||||
$this->setDisplayField('external_product_catalog_id');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setTable('external_product_catalogs_product_catalogs');
|
||||
$this->setDisplayField('external_product_catalog_id');
|
||||
$this->setPrimaryKey('id');
|
||||
|
||||
$this->addBehavior('Timestamp');
|
||||
$this->addBehavior('Timestamp');
|
||||
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ExternalProductCatalogsProductCatalogs.entity', 'CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog')
|
||||
);
|
||||
$this->belongsTo('ExternalProductCatalogs', [
|
||||
'className' => 'CakeProducts.ExternalProductCatalogs',
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ExternalProductCatalogsProductCatalogs.entity', 'CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog'),
|
||||
);
|
||||
$this->belongsTo('ExternalProductCatalogs', [
|
||||
'className' => 'CakeProducts.ExternalProductCatalogs',
|
||||
// 'foreignKey' => 'external_product_catalog_id',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
$this->belongsTo('ProductCatalogs', [
|
||||
'className' => 'CakeProducts.ProductCatalogs',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
$this->belongsTo('ProductCatalogs', [
|
||||
'className' => 'CakeProducts.ProductCatalogs',
|
||||
// 'foreignKey' => 'product_catalog_id',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
|
||||
$this->addBehavior('Muffin/Trash.Trash');
|
||||
}
|
||||
$this->addBehavior('Muffin/Trash.Trash');
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param Validator $validator Validator instance.
|
||||
* @return Validator
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->uuid('external_product_catalog_id')
|
||||
->notEmptyString('external_product_catalog_id');
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->uuid('external_product_catalog_id')
|
||||
->notEmptyString('external_product_catalog_id');
|
||||
|
||||
$validator
|
||||
->uuid('product_catalog_id')
|
||||
->notEmptyString('product_catalog_id');
|
||||
$validator
|
||||
->uuid('product_catalog_id')
|
||||
->notEmptyString('product_catalog_id');
|
||||
|
||||
$validator
|
||||
->boolean('enabled');
|
||||
$validator
|
||||
->boolean('enabled');
|
||||
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
|
||||
return $validator;
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
public function beforeMarshal(EventInterface $event, ArrayObject $data, ArrayObject $options)
|
||||
{
|
||||
if (!isset($data['enabled'])) {
|
||||
$data['enabled'] = false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function beforeMarshal(EventInterface $event, ArrayObject $data, ArrayObject $options) {
|
||||
if (!isset($data['enabled'])) {
|
||||
$data['enabled'] = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param RulesChecker $rules The rules object to be modified.
|
||||
* @return RulesChecker
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
public function buildRules(RulesChecker $rules): RulesChecker {
|
||||
// $rules->add($rules->existsIn(['external_product_catalog_id'], 'ExternalProductCatalogs'), ['errorField' => 'external_product_catalog_id']);
|
||||
// $rules->add($rules->existsIn(['product_catalog_id'], 'ProductCatalogs'), ['errorField' => 'product_catalog_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
return $rules;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,32 +4,24 @@ declare(strict_types=1);
|
||||
namespace CakeProducts\Model\Table;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Datasource\ResultSetInterface;
|
||||
use Cake\ORM\Association\BelongsTo;
|
||||
use Cake\ORM\Behavior\TimestampBehavior;
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use CakeProducts\Model\Entity\ExternalProductCatalog;
|
||||
use Closure;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
/**
|
||||
* ExternalProductCatalogs Model
|
||||
*
|
||||
* @property ProductCatalogsTable&BelongsTo $ProductCatalogs
|
||||
*
|
||||
* @method ExternalProductCatalog newEmptyEntity()
|
||||
* @method ExternalProductCatalog newEntity(array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ExternalProductCatalog newEmptyEntity()
|
||||
* @method \CakeProducts\Model\Entity\ExternalProductCatalog newEntity()
|
||||
* @method array<ExternalProductCatalog> newEntities(array $data, array $options = [])
|
||||
* @method ExternalProductCatalog get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
|
||||
* @method ExternalProductCatalog findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method ExternalProductCatalog patchEntity(EntityInterface $entity, array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ExternalProductCatalog get()
|
||||
* @method \CakeProducts\Model\Entity\ExternalProductCatalog findOrCreate()
|
||||
* @method \CakeProducts\Model\Entity\ExternalProductCatalog patchEntity()
|
||||
* @method array<ExternalProductCatalog> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method ExternalProductCatalog|false save(EntityInterface $entity, array $options = [])
|
||||
* @method ExternalProductCatalog saveOrFail(EntityInterface $entity, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ExternalProductCatalog saveOrFail()
|
||||
* @method iterable<ExternalProductCatalog>|ResultSetInterface<ExternalProductCatalog>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ExternalProductCatalog>|ResultSetInterface<ExternalProductCatalog> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<ExternalProductCatalog>|ResultSetInterface<ExternalProductCatalog>|false deleteMany(iterable $entities, array $options = [])
|
||||
@@ -37,81 +29,79 @@ use Psr\SimpleCache\CacheInterface;
|
||||
*
|
||||
* @mixin TimestampBehavior
|
||||
*/
|
||||
class ExternalProductCatalogsTable extends Table
|
||||
{
|
||||
/**
|
||||
class ExternalProductCatalogsTable extends Table {
|
||||
|
||||
/**
|
||||
* Initialize method
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('external_product_catalogs');
|
||||
$this->setDisplayField('base_url');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setTable('external_product_catalogs');
|
||||
$this->setDisplayField('base_url');
|
||||
$this->setPrimaryKey('id');
|
||||
|
||||
$this->addBehavior('Timestamp');
|
||||
$this->addBehavior('Timestamp');
|
||||
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ExternalProductCatalogs.entity', 'CakeProducts\Model\Entity\ExternalProductCatalog')
|
||||
);
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ExternalProductCatalogs.entity', 'CakeProducts\Model\Entity\ExternalProductCatalog'),
|
||||
);
|
||||
|
||||
$this->belongsToMany('ProductCatalogs', [
|
||||
'through' => 'ExternalProductCatalogsProductCatalogs',
|
||||
'className' => 'CakeProducts.ProductCatalogs',
|
||||
]);
|
||||
$this->belongsToMany('ProductCatalogs', [
|
||||
'through' => 'ExternalProductCatalogsProductCatalogs',
|
||||
'className' => 'CakeProducts.ProductCatalogs',
|
||||
]);
|
||||
|
||||
$this->hasMany('ExternalProductCatalogsProductCatalogs', [
|
||||
'foreignKey' => 'external_product_catalog_id',
|
||||
'className' => 'CakeProducts.ExternalProductCatalogsProductCatalogs',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ExternalProductCatalogsProductCatalogs', [
|
||||
'foreignKey' => 'external_product_catalog_id',
|
||||
'className' => 'CakeProducts.ExternalProductCatalogsProductCatalogs',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
|
||||
$this->addBehavior('Muffin/Trash.Trash');
|
||||
}
|
||||
$this->addBehavior('Muffin/Trash.Trash');
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param Validator $validator Validator instance.
|
||||
* @return Validator
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->scalar('base_url')
|
||||
->maxLength('base_url', 255)
|
||||
->requirePresence('base_url', 'create')
|
||||
->notEmptyString('base_url');
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->scalar('base_url')
|
||||
->maxLength('base_url', 255)
|
||||
->requirePresence('base_url', 'create')
|
||||
->notEmptyString('base_url');
|
||||
// ->url('base_url');
|
||||
|
||||
$validator
|
||||
->scalar('api_url')
|
||||
->maxLength('api_url', 255)
|
||||
->requirePresence('api_url', 'create')
|
||||
->notEmptyString('api_url');
|
||||
$validator
|
||||
->scalar('api_url')
|
||||
->maxLength('api_url', 255)
|
||||
->requirePresence('api_url', 'create')
|
||||
->notEmptyString('api_url');
|
||||
// ->url('api_url');
|
||||
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
|
||||
return $validator;
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param RulesChecker $rules The rules object to be modified.
|
||||
* @return RulesChecker
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
return $rules;
|
||||
}
|
||||
public function buildRules(RulesChecker $rules): RulesChecker {
|
||||
return $rules;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,88 +29,86 @@ use Cake\Validation\Validator;
|
||||
* @method iterable<\App\Model\Entity\ProductAttribute>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\ProductAttribute>|false deleteMany(iterable $entities, array $options = [])
|
||||
* @method iterable<\App\Model\Entity\ProductAttribute>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\ProductAttribute> deleteManyOrFail(iterable $entities, array $options = [])
|
||||
*/
|
||||
class ProductAttributesTable extends Table
|
||||
{
|
||||
/**
|
||||
class ProductAttributesTable extends Table {
|
||||
|
||||
/**
|
||||
* Initialize method
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('product_attributes');
|
||||
$this->setDisplayField('id');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setTable('product_attributes');
|
||||
$this->setDisplayField('id');
|
||||
$this->setPrimaryKey('id');
|
||||
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductAttributes.entity', 'CakeProducts\Model\Entity\ProductAttribute')
|
||||
);
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductAttributes.entity', 'CakeProducts\Model\Entity\ProductAttribute'),
|
||||
);
|
||||
|
||||
$this->belongsTo('Products', [
|
||||
'foreignKey' => 'product_id',
|
||||
'className' => 'CakeProducts.Products',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
$this->belongsTo('ProductCategoryAttributes', [
|
||||
'foreignKey' => 'product_category_attribute_id',
|
||||
'className' => 'CakeProducts.ProductCategoryAttributes',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
$this->belongsTo('ProductCategoryAttributeOptions', [
|
||||
'foreignKey' => 'product_category_attribute_option_id',
|
||||
'className' => 'CakeProducts.ProductCategoryAttributeOptions',
|
||||
]);
|
||||
$this->belongsTo('Products', [
|
||||
'foreignKey' => 'product_id',
|
||||
'className' => 'CakeProducts.Products',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
$this->belongsTo('ProductCategoryAttributes', [
|
||||
'foreignKey' => 'product_category_attribute_id',
|
||||
'className' => 'CakeProducts.ProductCategoryAttributes',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
$this->belongsTo('ProductCategoryAttributeOptions', [
|
||||
'foreignKey' => 'product_category_attribute_option_id',
|
||||
'className' => 'CakeProducts.ProductCategoryAttributeOptions',
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->uuid('product_id')
|
||||
->notEmptyString('product_id');
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->uuid('product_id')
|
||||
->notEmptyString('product_id');
|
||||
|
||||
$validator
|
||||
->uuid('product_category_attribute_id')
|
||||
->notEmptyString('product_category_attribute_id');
|
||||
$validator
|
||||
->uuid('product_category_attribute_id')
|
||||
->notEmptyString('product_category_attribute_id');
|
||||
|
||||
$validator
|
||||
->scalar('attribute_value')
|
||||
->maxLength('attribute_value', 255)
|
||||
->allowEmptyString('attribute_value');
|
||||
$validator
|
||||
->scalar('attribute_value')
|
||||
->maxLength('attribute_value', 255)
|
||||
->allowEmptyString('attribute_value');
|
||||
|
||||
$validator
|
||||
->uuid('product_category_attribute_option_id')
|
||||
->allowEmptyString('product_category_attribute_option_id');
|
||||
$validator
|
||||
->uuid('product_category_attribute_option_id')
|
||||
->allowEmptyString('product_category_attribute_option_id');
|
||||
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
|
||||
return $validator;
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
|
||||
$rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']);
|
||||
$rules->add($rules->existsIn(['product_category_attribute_option_id'], 'ProductCategoryAttributeOptions'), ['errorField' => 'product_category_attribute_option_id']);
|
||||
public function buildRules(RulesChecker $rules): RulesChecker {
|
||||
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
|
||||
$rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']);
|
||||
$rules->add($rules->existsIn(['product_category_attribute_option_id'], 'ProductCategoryAttributeOptions'), ['errorField' => 'product_category_attribute_option_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,106 +4,98 @@ declare(strict_types=1);
|
||||
namespace CakeProducts\Model\Table;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Datasource\ResultSetInterface;
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use CakeProducts\Model\Entity\ProductCatalog;
|
||||
use Closure;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
/**
|
||||
* ProductCatalogs Model
|
||||
*
|
||||
* @method ProductCatalog newEmptyEntity()
|
||||
* @method ProductCatalog newEntity(array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCatalog newEmptyEntity()
|
||||
* @method \CakeProducts\Model\Entity\ProductCatalog newEntity()
|
||||
* @method array<ProductCatalog> newEntities(array $data, array $options = [])
|
||||
* @method ProductCatalog get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
|
||||
* @method ProductCatalog findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method ProductCatalog patchEntity(EntityInterface $entity, array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCatalog get()
|
||||
* @method \CakeProducts\Model\Entity\ProductCatalog findOrCreate()
|
||||
* @method \CakeProducts\Model\Entity\ProductCatalog patchEntity()
|
||||
* @method array<ProductCatalog> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method ProductCatalog|false save(EntityInterface $entity, array $options = [])
|
||||
* @method ProductCatalog saveOrFail(EntityInterface $entity, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCatalog saveOrFail()
|
||||
* @method iterable<ProductCatalog>|ResultSetInterface<ProductCatalog>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCatalog>|ResultSetInterface<ProductCatalog> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCatalog>|ResultSetInterface<ProductCatalog>|false deleteMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCatalog>|ResultSetInterface<ProductCatalog> deleteManyOrFail(iterable $entities, array $options = [])
|
||||
*/
|
||||
class ProductCatalogsTable extends Table
|
||||
{
|
||||
/**
|
||||
class ProductCatalogsTable extends Table {
|
||||
|
||||
/**
|
||||
* Initialize method
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('product_catalogs');
|
||||
$this->setDisplayField('name');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setTable('product_catalogs');
|
||||
$this->setDisplayField('name');
|
||||
$this->setPrimaryKey('id');
|
||||
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductCatalogs.entity', 'CakeProducts\Model\Entity\ProductCatalog')
|
||||
);
|
||||
$this->hasMany('ProductCategories', [
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
]);
|
||||
$this->belongsToMany('ExternalProductCatalogs', [
|
||||
'through' => 'ExternalProductCatalogsProductCatalogs',
|
||||
'className' => 'CakeProducts.ExternalProductCatalogs',
|
||||
]);
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductCatalogs.entity', 'CakeProducts\Model\Entity\ProductCatalog'),
|
||||
);
|
||||
$this->hasMany('ProductCategories', [
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
]);
|
||||
$this->belongsToMany('ExternalProductCatalogs', [
|
||||
'through' => 'ExternalProductCatalogsProductCatalogs',
|
||||
'className' => 'CakeProducts.ExternalProductCatalogs',
|
||||
]);
|
||||
|
||||
$this->addBehavior('Muffin/Trash.Trash');
|
||||
}
|
||||
$this->addBehavior('Muffin/Trash.Trash');
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param Validator $validator Validator instance.
|
||||
* @return Validator
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->scalar('name')
|
||||
->maxLength('name', 255)
|
||||
->requirePresence('name', 'create')
|
||||
->notEmptyString('name')
|
||||
->add('name', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']);
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->scalar('name')
|
||||
->maxLength('name', 255)
|
||||
->requirePresence('name', 'create')
|
||||
->notEmptyString('name')
|
||||
->add('name', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']);
|
||||
|
||||
$validator
|
||||
->scalar('catalog_description')
|
||||
->maxLength('catalog_description', 255)
|
||||
->allowEmptyString('catalog_description');
|
||||
$validator
|
||||
->scalar('catalog_description')
|
||||
->maxLength('catalog_description', 255)
|
||||
->allowEmptyString('catalog_description');
|
||||
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
->requirePresence('enabled', 'create')
|
||||
->notEmptyString('enabled');
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
->requirePresence('enabled', 'create')
|
||||
->notEmptyString('enabled');
|
||||
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
|
||||
return $validator;
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param RulesChecker $rules The rules object to be modified.
|
||||
* @return RulesChecker
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
$rules->add($rules->isUnique(['name']), ['errorField' => 'name']);
|
||||
public function buildRules(RulesChecker $rules): RulesChecker {
|
||||
$rules->add($rules->isUnique(['name']), ['errorField' => 'name']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,18 +6,10 @@ namespace CakeProducts\Model\Table;
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Database\Type\EnumType;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Datasource\ResultSetInterface;
|
||||
use Cake\ORM\Association\BelongsTo;
|
||||
use Cake\ORM\Association\HasMany;
|
||||
use Cake\ORM\Behavior\TreeBehavior;
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use CakeProducts\Model\Entity\ProductCategory;
|
||||
use CakeProducts\Model\Enum\ProductProductTypeId;
|
||||
use Closure;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
/**
|
||||
* ProductCategories Model
|
||||
@@ -26,14 +18,14 @@ use Psr\SimpleCache\CacheInterface;
|
||||
* @property ProductCategoriesTable&BelongsTo $ParentProductCategories
|
||||
* @property ProductCategoriesTable&HasMany $ChildProductCategories
|
||||
*
|
||||
* @method ProductCategory newEmptyEntity()
|
||||
* @method ProductCategory newEntity(array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategory newEmptyEntity()
|
||||
* @method \CakeProducts\Model\Entity\ProductCategory newEntity()
|
||||
* @method array<ProductCategory> newEntities(array $data, array $options = [])
|
||||
* @method ProductCategory get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
|
||||
* @method ProductCategory findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method ProductCategory patchEntity(EntityInterface $entity, array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategory get()
|
||||
* @method \CakeProducts\Model\Entity\ProductCategory findOrCreate()
|
||||
* @method \CakeProducts\Model\Entity\ProductCategory patchEntity()
|
||||
* @method array<ProductCategory> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method ProductCategory saveOrFail(EntityInterface $entity, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategory saveOrFail()
|
||||
* @method iterable<ProductCategory>|ResultSetInterface<ProductCategory>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategory>|ResultSetInterface<ProductCategory> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategory>|ResultSetInterface<ProductCategory>|false deleteMany(iterable $entities, array $options = [])
|
||||
@@ -41,175 +33,171 @@ use Psr\SimpleCache\CacheInterface;
|
||||
*
|
||||
* @mixin TreeBehavior
|
||||
*/
|
||||
class ProductCategoriesTable extends Table
|
||||
{
|
||||
/**
|
||||
class ProductCategoriesTable extends Table {
|
||||
|
||||
/**
|
||||
* Current scope for Tree behavior - per catalog
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $treeCatalogId;
|
||||
protected $treeCatalogId;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Initialize method
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
$this->treeCatalogId = 1;
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
$this->treeCatalogId = 1;
|
||||
|
||||
$this->setTable('product_categories');
|
||||
$this->setDisplayField('name');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductCategories.entity', 'CakeProducts\Model\Entity\ProductCategory')
|
||||
);
|
||||
$this->addBehavior('Tree', [
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->setTable('product_categories');
|
||||
$this->setDisplayField('name');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductCategories.entity', 'CakeProducts\Model\Entity\ProductCategory'),
|
||||
);
|
||||
$this->addBehavior('Tree', [
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
|
||||
$this->belongsTo('ProductCatalogs', [
|
||||
'foreignKey' => 'product_catalog_id',
|
||||
'joinType' => 'INNER',
|
||||
'className' => 'CakeProducts.ProductCatalogs',
|
||||
]);
|
||||
$this->belongsTo('ParentProductCategories', [
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
'foreignKey' => 'parent_id',
|
||||
]);
|
||||
$this->hasMany('ChildProductCategories', [
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
'foreignKey' => 'parent_id',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ProductCategoryAttributes', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'className' => 'CakeProducts.ProductCategoryAttributes',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ProductCategoryVariants', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'className' => 'CakeProducts.ProductCategoryVariants',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('Products', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'className' => 'CakeProducts.Products',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ProductPhotos', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'className' => 'CakeProducts.ProductPhotos',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasOne('PrimaryProductPhotos', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'conditions' => ['PrimaryProductPhotos.primary_category_photo' => true],
|
||||
'className' => 'CakeProducts.ProductPhotos',
|
||||
'dependent' => true,
|
||||
]);
|
||||
$this->belongsTo('ProductCatalogs', [
|
||||
'foreignKey' => 'product_catalog_id',
|
||||
'joinType' => 'INNER',
|
||||
'className' => 'CakeProducts.ProductCatalogs',
|
||||
]);
|
||||
$this->belongsTo('ParentProductCategories', [
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
'foreignKey' => 'parent_id',
|
||||
]);
|
||||
$this->hasMany('ChildProductCategories', [
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
'foreignKey' => 'parent_id',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ProductCategoryAttributes', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'className' => 'CakeProducts.ProductCategoryAttributes',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ProductCategoryVariants', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'className' => 'CakeProducts.ProductCategoryVariants',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('Products', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'className' => 'CakeProducts.Products',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ProductPhotos', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'className' => 'CakeProducts.ProductPhotos',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasOne('PrimaryProductPhotos', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'conditions' => ['PrimaryProductPhotos.primary_category_photo' => true],
|
||||
'className' => 'CakeProducts.ProductPhotos',
|
||||
'dependent' => true,
|
||||
]);
|
||||
|
||||
$this->getSchema()->setColumnType('default_product_type_id', EnumType::from(ProductProductTypeId::class));
|
||||
$this->getSchema()->setColumnType('default_product_type_id', EnumType::from(ProductProductTypeId::class));
|
||||
|
||||
$this->behaviors()->Tree->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]);
|
||||
$this->addBehavior('Muffin/Trash.Trash');
|
||||
}
|
||||
$this->behaviors()->Tree->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]);
|
||||
$this->addBehavior('Muffin/Trash.Trash');
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param Validator $validator Validator instance.
|
||||
* @return Validator
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->uuid('product_catalog_id')
|
||||
->notEmptyString('product_catalog_id');
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->uuid('product_catalog_id')
|
||||
->notEmptyString('product_catalog_id');
|
||||
|
||||
$validator
|
||||
->scalar('name')
|
||||
->maxLength('name', 255)
|
||||
->requirePresence('name', 'create')
|
||||
->notEmptyString('name');
|
||||
$validator
|
||||
->scalar('name')
|
||||
->maxLength('name', 255)
|
||||
->requirePresence('name', 'create')
|
||||
->notEmptyString('name');
|
||||
|
||||
$validator
|
||||
->scalar('category_description')
|
||||
->allowEmptyString('category_description');
|
||||
$validator
|
||||
->scalar('category_description')
|
||||
->allowEmptyString('category_description');
|
||||
|
||||
$validator
|
||||
->integer('parent_id')
|
||||
->allowEmptyString('parent_id');
|
||||
$validator
|
||||
->integer('parent_id')
|
||||
->allowEmptyString('parent_id');
|
||||
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
->notEmptyString('enabled');
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
->notEmptyString('enabled');
|
||||
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
|
||||
$validator
|
||||
->integer('default_product_type_id')
|
||||
->allowEmptyString('default_product_type_id');
|
||||
$validator
|
||||
->integer('default_product_type_id')
|
||||
->allowEmptyString('default_product_type_id');
|
||||
|
||||
return $validator;
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param RulesChecker $rules The rules object to be modified.
|
||||
* @return RulesChecker
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
$rules->add($rules->isUnique(['product_catalog_id', 'name']), ['errorField' => 'product_catalog_id']);
|
||||
$rules->add($rules->existsIn(['product_catalog_id'], 'ProductCatalogs'), ['errorField' => 'product_catalog_id']);
|
||||
$rules->add($rules->existsIn(['parent_id'], 'ParentProductCategories'), ['errorField' => 'parent_id']);
|
||||
public function buildRules(RulesChecker $rules): RulesChecker {
|
||||
$rules->add($rules->isUnique(['product_catalog_id', 'name']), ['errorField' => 'product_catalog_id']);
|
||||
$rules->add($rules->existsIn(['product_catalog_id'], 'ProductCatalogs'), ['errorField' => 'product_catalog_id']);
|
||||
$rules->add($rules->existsIn(['parent_id'], 'ParentProductCategories'), ['errorField' => 'parent_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $catalogId
|
||||
/**
|
||||
* @param string $catalogId
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setConfigureCatalogId(string $catalogId)
|
||||
{
|
||||
$this->treeCatalogId = $catalogId;
|
||||
$this->behaviors()->Tree->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]);
|
||||
}
|
||||
public function setConfigureCatalogId(string $catalogId) {
|
||||
$this->treeCatalogId = $catalogId;
|
||||
$this->behaviors()->Tree->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EntityInterface $entity
|
||||
/**
|
||||
* @param \Cake\Datasource\EntityInterface $entity
|
||||
* @param array $options
|
||||
*
|
||||
* @return EntityInterface|false
|
||||
* @return \Cake\Datasource\EntityInterface|false
|
||||
*/
|
||||
public function save(EntityInterface $entity, array $options = []): EntityInterface|false
|
||||
{
|
||||
$this->behaviors()->get('Tree')->setConfig([
|
||||
'scope' => [
|
||||
'product_catalog_id' => $entity->product_catalog_id,
|
||||
],
|
||||
]);
|
||||
public function save(EntityInterface $entity, array $options = []): EntityInterface|false {
|
||||
$this->behaviors()->get('Tree')->setConfig([
|
||||
'scope' => [
|
||||
'product_catalog_id' => $entity->product_catalog_id,
|
||||
],
|
||||
]);
|
||||
|
||||
return parent::save($entity, $options);
|
||||
}
|
||||
|
||||
return parent::save($entity, $options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,112 +4,103 @@ declare(strict_types=1);
|
||||
namespace CakeProducts\Model\Table;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Datasource\ResultSetInterface;
|
||||
use Cake\ORM\Association\BelongsTo;
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use CakeProducts\Model\Entity\ProductCategoryAttributeOption;
|
||||
use Closure;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
/**
|
||||
* ProductCategoryAttributeOptions Model
|
||||
*
|
||||
* @property ProductCategoryAttributesTable&BelongsTo $ProductCategoryAttributes
|
||||
*
|
||||
* @method ProductCategoryAttributeOption newEmptyEntity()
|
||||
* @method ProductCategoryAttributeOption newEntity(array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption newEmptyEntity()
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption newEntity()
|
||||
* @method array<ProductCategoryAttributeOption> newEntities(array $data, array $options = [])
|
||||
* @method ProductCategoryAttributeOption get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
|
||||
* @method ProductCategoryAttributeOption findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method ProductCategoryAttributeOption patchEntity(EntityInterface $entity, array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption get()
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption findOrCreate()
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption patchEntity()
|
||||
* @method array<ProductCategoryAttributeOption> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method ProductCategoryAttributeOption|false save(EntityInterface $entity, array $options = [])
|
||||
* @method ProductCategoryAttributeOption saveOrFail(EntityInterface $entity, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption saveOrFail()
|
||||
* @method iterable<ProductCategoryAttributeOption>|ResultSetInterface<ProductCategoryAttributeOption>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategoryAttributeOption>|ResultSetInterface<ProductCategoryAttributeOption> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategoryAttributeOption>|ResultSetInterface<ProductCategoryAttributeOption>|false deleteMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategoryAttributeOption>|ResultSetInterface<ProductCategoryAttributeOption> deleteManyOrFail(iterable $entities, array $options = [])
|
||||
*/
|
||||
class ProductCategoryAttributeOptionsTable extends Table
|
||||
{
|
||||
/**
|
||||
class ProductCategoryAttributeOptionsTable extends Table {
|
||||
|
||||
/**
|
||||
* Initialize method
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('product_category_attribute_options');
|
||||
$this->setDisplayField('attribute_value');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setTable('product_category_attribute_options');
|
||||
$this->setDisplayField('attribute_value');
|
||||
$this->setPrimaryKey('id');
|
||||
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductCategoryAttributeOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryAttributeOption')
|
||||
);
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductCategoryAttributeOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryAttributeOption'),
|
||||
);
|
||||
|
||||
$this->belongsTo('ProductCategoryAttributes', [
|
||||
'foreignKey' => 'product_category_attribute_id',
|
||||
'joinType' => 'INNER',
|
||||
'className' => 'CakeProducts.ProductCategoryAttributes',
|
||||
]);
|
||||
$this->belongsTo('ProductCategoryAttributes', [
|
||||
'foreignKey' => 'product_category_attribute_id',
|
||||
'joinType' => 'INNER',
|
||||
'className' => 'CakeProducts.ProductCategoryAttributes',
|
||||
]);
|
||||
|
||||
$this->addBehavior('Muffin/Trash.Trash');
|
||||
}
|
||||
$this->addBehavior('Muffin/Trash.Trash');
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param Validator $validator Validator instance.
|
||||
* @return Validator
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->uuid('product_category_attribute_id')
|
||||
->notEmptyString('product_category_attribute_id');
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->uuid('product_category_attribute_id')
|
||||
->notEmptyString('product_category_attribute_id');
|
||||
|
||||
$validator
|
||||
->scalar('attribute_value')
|
||||
->maxLength('attribute_value', 255)
|
||||
->requirePresence('attribute_value', 'create')
|
||||
->notEmptyString('attribute_value');
|
||||
$validator
|
||||
->scalar('attribute_value')
|
||||
->maxLength('attribute_value', 255)
|
||||
->requirePresence('attribute_value', 'create')
|
||||
->notEmptyString('attribute_value');
|
||||
|
||||
$validator
|
||||
->scalar('attribute_label')
|
||||
->maxLength('attribute_label', 255)
|
||||
->requirePresence('attribute_label', 'create')
|
||||
->notEmptyString('attribute_label');
|
||||
$validator
|
||||
->scalar('attribute_label')
|
||||
->maxLength('attribute_label', 255)
|
||||
->requirePresence('attribute_label', 'create')
|
||||
->notEmptyString('attribute_label');
|
||||
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
->notEmptyString('enabled');
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
->notEmptyString('enabled');
|
||||
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
|
||||
return $validator;
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param RulesChecker $rules The rules object to be modified.
|
||||
* @return RulesChecker
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
$rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']);
|
||||
$rules->add($rules->isUnique(['attribute_value', 'product_category_attribute_id']));
|
||||
public function buildRules(RulesChecker $rules): RulesChecker {
|
||||
$rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']);
|
||||
$rules->add($rules->isUnique(['attribute_value', 'product_category_attribute_id']));
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,146 +5,141 @@ namespace CakeProducts\Model\Table;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Database\Type\EnumType;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Datasource\ResultSetInterface;
|
||||
use Cake\ORM\Association\BelongsTo;
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use CakeProducts\Model\Entity\ProductCategoryAttribute;
|
||||
use CakeProducts\Model\Enum\ProductCategoryAttributeTypeId;
|
||||
use Closure;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
/**
|
||||
* ProductCategoryAttributes Model
|
||||
*
|
||||
* @property ProductCategoriesTable&BelongsTo $ProductCategories
|
||||
*
|
||||
* @method ProductCategoryAttribute newEmptyEntity()
|
||||
* @method ProductCategoryAttribute newEntity(array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryAttribute newEmptyEntity()
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryAttribute newEntity()
|
||||
* @method array<ProductCategoryAttribute> newEntities(array $data, array $options = [])
|
||||
* @method ProductCategoryAttribute get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
|
||||
* @method ProductCategoryAttribute findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method ProductCategoryAttribute patchEntity(EntityInterface $entity, array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryAttribute get()
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryAttribute findOrCreate()
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryAttribute patchEntity()
|
||||
* @method array<ProductCategoryAttribute> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method ProductCategoryAttribute|false save(EntityInterface $entity, array $options = [])
|
||||
* @method ProductCategoryAttribute saveOrFail(EntityInterface $entity, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryAttribute saveOrFail()
|
||||
* @method iterable<ProductCategoryAttribute>|ResultSetInterface<ProductCategoryAttribute>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategoryAttribute>|ResultSetInterface<ProductCategoryAttribute> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategoryAttribute>|ResultSetInterface<ProductCategoryAttribute>|false deleteMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategoryAttribute>|ResultSetInterface<ProductCategoryAttribute> deleteManyOrFail(iterable $entities, array $options = [])
|
||||
*/
|
||||
class ProductCategoryAttributesTable extends Table
|
||||
{
|
||||
/**
|
||||
class ProductCategoryAttributesTable extends Table {
|
||||
|
||||
/**
|
||||
* Initialize method
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('product_category_attributes');
|
||||
$this->setDisplayField('name');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setTable('product_category_attributes');
|
||||
$this->setDisplayField('name');
|
||||
$this->setPrimaryKey('id');
|
||||
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductCategoryAttributes.entity', 'CakeProducts\Model\Entity\ProductCategoryAttribute')
|
||||
);
|
||||
$this->belongsTo('ProductCategories', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
]);
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductCategoryAttributes.entity', 'CakeProducts\Model\Entity\ProductCategoryAttribute'),
|
||||
);
|
||||
$this->belongsTo('ProductCategories', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
]);
|
||||
|
||||
$this->hasMany('ProductCategoryAttributeOptions', [
|
||||
'foreignKey' => 'product_category_attribute_id',
|
||||
'className' => 'CakeProducts.ProductCategoryAttributeOptions',
|
||||
'saveStrategy' => 'replace',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->getSchema()->setColumnType('attribute_type_id', EnumType::from(ProductCategoryAttributeTypeId::class));
|
||||
$this->hasMany('ProductCategoryAttributeOptions', [
|
||||
'foreignKey' => 'product_category_attribute_id',
|
||||
'className' => 'CakeProducts.ProductCategoryAttributeOptions',
|
||||
'saveStrategy' => 'replace',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->getSchema()->setColumnType('attribute_type_id', EnumType::from(ProductCategoryAttributeTypeId::class));
|
||||
|
||||
$this->addBehavior('Muffin/Trash.Trash');
|
||||
}
|
||||
$this->addBehavior('Muffin/Trash.Trash');
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param Validator $validator Validator instance.
|
||||
* @return Validator
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->scalar('name')
|
||||
->maxLength('name', 255)
|
||||
->requirePresence('name', 'create')
|
||||
->notEmptyString('name');
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->scalar('name')
|
||||
->maxLength('name', 255)
|
||||
->requirePresence('name', 'create')
|
||||
->notEmptyString('name');
|
||||
|
||||
$validator
|
||||
->uuid('product_category_id')
|
||||
->allowEmptyString('product_category_id');
|
||||
$validator
|
||||
->uuid('product_category_id')
|
||||
->allowEmptyString('product_category_id');
|
||||
|
||||
$validator
|
||||
->integer('attribute_type_id')
|
||||
->requirePresence('attribute_type_id', 'create')
|
||||
->notEmptyString('attribute_type_id');
|
||||
$validator
|
||||
->integer('attribute_type_id')
|
||||
->requirePresence('attribute_type_id', 'create')
|
||||
->notEmptyString('attribute_type_id');
|
||||
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
->requirePresence('enabled', 'create')
|
||||
->notEmptyString('enabled');
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
->requirePresence('enabled', 'create')
|
||||
->notEmptyString('enabled');
|
||||
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
|
||||
return $validator;
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param RulesChecker $rules The rules object to be modified.
|
||||
* @return RulesChecker
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
$rules->add($rules->isUnique(['name', 'product_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'name']);
|
||||
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
|
||||
public function buildRules(RulesChecker $rules): RulesChecker {
|
||||
$rules->add($rules->isUnique(['name', 'product_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'name']);
|
||||
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SelectQuery $query
|
||||
/**
|
||||
* @param \Cake\ORM\Query\SelectQuery $query
|
||||
* @param string $internalCategoryId
|
||||
*
|
||||
* @return array|\Cake\ORM\Query|SelectQuery
|
||||
* @return \Cake\ORM\Query|\Cake\ORM\Query\SelectQuery|array
|
||||
*/
|
||||
public function findAllCategoryAttributesForCategoryId(SelectQuery $query, string $internalCategoryId)
|
||||
{
|
||||
$category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail();
|
||||
public function findAllCategoryAttributesForCategoryId(SelectQuery $query, string $internalCategoryId) {
|
||||
$category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail();
|
||||
|
||||
$this->ProductCategories->behaviors()->get('Tree')->setConfig([
|
||||
'scope' => [
|
||||
'product_catalog_id' => $category->product_catalog_id ?? 1,
|
||||
],
|
||||
]);
|
||||
$this->ProductCategories->behaviors()->get('Tree')->setConfig([
|
||||
'scope' => [
|
||||
'product_catalog_id' => $category->product_catalog_id ?? 1,
|
||||
],
|
||||
]);
|
||||
|
||||
return $this->ProductCategories
|
||||
->find('path', for: $category->id)
|
||||
->contain(['ProductCategoryAttributes', 'ProductCategoryAttributes.ProductCategoryAttributeOptions']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $internalCategoryId
|
||||
* @return array|array[]|\Cake\Datasource\EntityInterface[]
|
||||
*/
|
||||
public function getAllCategoryAttributesForCategoryId(string $internalCategoryId) {
|
||||
return $this->find('allCategoryAttributesForCategoryId', $internalCategoryId)->toArray();
|
||||
}
|
||||
|
||||
return $this->ProductCategories
|
||||
->find('path', for: $category->id)
|
||||
->contain(['ProductCategoryAttributes', 'ProductCategoryAttributes.ProductCategoryAttributeOptions']);
|
||||
}
|
||||
public function getAllCategoryAttributesForCategoryId(string $internalCategoryId)
|
||||
{
|
||||
return $this->find('allCategoryAttributesForCategoryId', $internalCategoryId)->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,33 +4,24 @@ declare(strict_types=1);
|
||||
namespace CakeProducts\Model\Table;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use CakeProducts\Model\Entity\ProductCategoryVariantOption;
|
||||
use CakeProducts\Model\Table\ProductCategoryVariantsTable;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Datasource\ResultSetInterface;
|
||||
use Cake\ORM\Association\BelongsTo;
|
||||
use Cake\ORM\Behavior\TimestampBehavior;
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use Closure;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
/**
|
||||
* ProductCategoryVariantOptions Model
|
||||
*
|
||||
* @property ProductCategoryVariantsTable&BelongsTo $ProductCategoryVariants
|
||||
*
|
||||
* @method ProductCategoryVariantOption newEmptyEntity()
|
||||
* @method ProductCategoryVariantOption newEntity(array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryVariantOption newEmptyEntity()
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryVariantOption newEntity()
|
||||
* @method array<ProductCategoryVariantOption> newEntities(array $data, array $options = [])
|
||||
* @method ProductCategoryVariantOption get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
|
||||
* @method ProductCategoryVariantOption findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method ProductCategoryVariantOption patchEntity(EntityInterface $entity, array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryVariantOption get()
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryVariantOption findOrCreate()
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryVariantOption patchEntity()
|
||||
* @method array<ProductCategoryVariantOption> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method ProductCategoryVariantOption|false save(EntityInterface $entity, array $options = [])
|
||||
* @method ProductCategoryVariantOption saveOrFail(EntityInterface $entity, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryVariantOption saveOrFail()
|
||||
* @method iterable<ProductCategoryVariantOption>|ResultSetInterface<ProductCategoryVariantOption>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategoryVariantOption>|ResultSetInterface<ProductCategoryVariantOption> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategoryVariantOption>|ResultSetInterface<ProductCategoryVariantOption>|false deleteMany(iterable $entities, array $options = [])
|
||||
@@ -38,75 +29,73 @@ use Psr\SimpleCache\CacheInterface;
|
||||
*
|
||||
* @mixin TimestampBehavior
|
||||
*/
|
||||
class ProductCategoryVariantOptionsTable extends Table
|
||||
{
|
||||
/**
|
||||
class ProductCategoryVariantOptionsTable extends Table {
|
||||
|
||||
/**
|
||||
* Initialize method
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('product_category_variant_options');
|
||||
$this->setDisplayField('variant_value');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setTable('product_category_variant_options');
|
||||
$this->setDisplayField('variant_value');
|
||||
$this->setPrimaryKey('id');
|
||||
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductCategoryVariantOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryVariantOption')
|
||||
);
|
||||
$this->addBehavior('Timestamp');
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductCategoryVariantOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryVariantOption'),
|
||||
);
|
||||
$this->addBehavior('Timestamp');
|
||||
|
||||
$this->belongsTo('ProductCategoryVariants', [
|
||||
'foreignKey' => 'product_category_variant_id',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
}
|
||||
$this->belongsTo('ProductCategoryVariants', [
|
||||
'foreignKey' => 'product_category_variant_id',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param Validator $validator Validator instance.
|
||||
* @return Validator
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->uuid('product_category_variant_id')
|
||||
->notEmptyString('product_category_variant_id');
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->uuid('product_category_variant_id')
|
||||
->notEmptyString('product_category_variant_id');
|
||||
|
||||
$validator
|
||||
->scalar('variant_value')
|
||||
->maxLength('variant_value', 255)
|
||||
->requirePresence('variant_value', 'create')
|
||||
->notEmptyString('variant_value');
|
||||
$validator
|
||||
->scalar('variant_value')
|
||||
->maxLength('variant_value', 255)
|
||||
->requirePresence('variant_value', 'create')
|
||||
->notEmptyString('variant_value');
|
||||
|
||||
$validator
|
||||
->scalar('variant_label')
|
||||
->maxLength('variant_label', 255)
|
||||
->allowEmptyString('variant_label');
|
||||
$validator
|
||||
->scalar('variant_label')
|
||||
->maxLength('variant_label', 255)
|
||||
->allowEmptyString('variant_label');
|
||||
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
|
||||
return $validator;
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param RulesChecker $rules The rules object to be modified.
|
||||
* @return RulesChecker
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
$rules->add($rules->existsIn(['product_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']);
|
||||
$rules->add($rules->isUnique(['variant_value', 'product_category_variant_id']));
|
||||
public function buildRules(RulesChecker $rules): RulesChecker {
|
||||
$rules->add($rules->existsIn(['product_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']);
|
||||
$rules->add($rules->isUnique(['variant_value', 'product_category_variant_id']));
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,17 +4,10 @@ declare(strict_types=1);
|
||||
namespace CakeProducts\Model\Table;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Datasource\ResultSetInterface;
|
||||
use Cake\ORM\Association\BelongsTo;
|
||||
use Cake\ORM\Query;
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use CakeProducts\Model\Entity\ProductCategoryVariant;
|
||||
use Closure;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
/**
|
||||
* ProductCategoryVariants Model
|
||||
@@ -22,143 +15,139 @@ use Psr\SimpleCache\CacheInterface;
|
||||
* @property ProductCategoriesTable&BelongsTo $ProductCategories
|
||||
* @property ProductsTable&BelongsTo $Products
|
||||
*
|
||||
* @method ProductCategoryVariant newEmptyEntity()
|
||||
* @method ProductCategoryVariant newEntity(array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryVariant newEmptyEntity()
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryVariant newEntity()
|
||||
* @method array<ProductCategoryVariant> newEntities(array $data, array $options = [])
|
||||
* @method ProductCategoryVariant get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
|
||||
* @method ProductCategoryVariant findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method ProductCategoryVariant patchEntity(EntityInterface $entity, array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryVariant get()
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryVariant findOrCreate()
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryVariant patchEntity()
|
||||
* @method array<ProductCategoryVariant> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method ProductCategoryVariant|false save(EntityInterface $entity, array $options = [])
|
||||
* @method ProductCategoryVariant saveOrFail(EntityInterface $entity, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryVariant saveOrFail()
|
||||
* @method iterable<ProductCategoryVariant>|ResultSetInterface<ProductCategoryVariant>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategoryVariant>|ResultSetInterface<ProductCategoryVariant> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategoryVariant>|ResultSetInterface<ProductCategoryVariant>|false deleteMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategoryVariant>|ResultSetInterface<ProductCategoryVariant> deleteManyOrFail(iterable $entities, array $options = [])
|
||||
*/
|
||||
class ProductCategoryVariantsTable extends Table
|
||||
{
|
||||
/**
|
||||
class ProductCategoryVariantsTable extends Table {
|
||||
|
||||
/**
|
||||
* Initialize method
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('product_category_variants');
|
||||
$this->setDisplayField('name');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setTable('product_category_variants');
|
||||
$this->setDisplayField('name');
|
||||
$this->setPrimaryKey('id');
|
||||
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductCategoryVariants.entity', 'CakeProducts\Model\Entity\ProductCategoryVariant')
|
||||
);
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductCategoryVariants.entity', 'CakeProducts\Model\Entity\ProductCategoryVariant'),
|
||||
);
|
||||
|
||||
$this->belongsTo('ProductCategories', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
]);
|
||||
$this->belongsTo('Products', [
|
||||
'foreignKey' => 'product_id',
|
||||
'className' => 'CakeProducts.Products',
|
||||
]);
|
||||
$this->hasMany('ProductCategoryVariantOptions', [
|
||||
'foreignKey' => 'product_category_variant_id',
|
||||
'className' => 'CakeProducts.ProductCategoryVariantOptions',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
'saveStrategy' => 'replace',
|
||||
]);
|
||||
$this->belongsTo('ProductCategories', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
]);
|
||||
$this->belongsTo('Products', [
|
||||
'foreignKey' => 'product_id',
|
||||
'className' => 'CakeProducts.Products',
|
||||
]);
|
||||
$this->hasMany('ProductCategoryVariantOptions', [
|
||||
'foreignKey' => 'product_category_variant_id',
|
||||
'className' => 'CakeProducts.ProductCategoryVariantOptions',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
'saveStrategy' => 'replace',
|
||||
]);
|
||||
|
||||
$this->hasMany('ProductVariants', [
|
||||
'foreignKey' => 'product_category_variant_id',
|
||||
'className' => 'CakeProducts.ProductVariants',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
}
|
||||
$this->hasMany('ProductVariants', [
|
||||
'foreignKey' => 'product_category_variant_id',
|
||||
'className' => 'CakeProducts.ProductVariants',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param Validator $validator Validator instance.
|
||||
* @return Validator
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->scalar('name')
|
||||
->maxLength('name', 255)
|
||||
->requirePresence('name', 'create')
|
||||
->notEmptyString('name');
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->scalar('name')
|
||||
->maxLength('name', 255)
|
||||
->requirePresence('name', 'create')
|
||||
->notEmptyString('name');
|
||||
|
||||
$validator
|
||||
->uuid('product_category_id')
|
||||
->allowEmptyString('product_category_id');
|
||||
$validator
|
||||
->uuid('product_category_id')
|
||||
->allowEmptyString('product_category_id');
|
||||
|
||||
$validator
|
||||
->uuid('product_id')
|
||||
->allowEmptyString('product_id');
|
||||
$validator
|
||||
->uuid('product_id')
|
||||
->allowEmptyString('product_id');
|
||||
|
||||
$validator
|
||||
->boolean('is_system_variant')
|
||||
->allowEmptyString('is_system_variant');
|
||||
$validator
|
||||
->boolean('is_system_variant')
|
||||
->allowEmptyString('is_system_variant');
|
||||
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
->requirePresence('enabled', 'create')
|
||||
->notEmptyString('enabled');
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
->requirePresence('enabled', 'create')
|
||||
->notEmptyString('enabled');
|
||||
|
||||
return $validator;
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param RulesChecker $rules The rules object to be modified.
|
||||
* @return RulesChecker
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
$rules->add($rules->isUnique(['name', 'product_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_category_id']);
|
||||
$rules->add($rules->isUnique(['name', 'product_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_id']);
|
||||
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
|
||||
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
|
||||
public function buildRules(RulesChecker $rules): RulesChecker {
|
||||
$rules->add($rules->isUnique(['name', 'product_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_category_id']);
|
||||
$rules->add($rules->isUnique(['name', 'product_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_id']);
|
||||
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
|
||||
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SelectQuery $query
|
||||
/**
|
||||
* @param \Cake\ORM\Query\SelectQuery $query
|
||||
* @param string $internalCategoryId
|
||||
*
|
||||
* @return array|Query|SelectQuery
|
||||
* @return Query|\Cake\ORM\Query\SelectQuery|array
|
||||
*/
|
||||
public function findAllCategoryVariantsForCategoryId(SelectQuery $query, string $internalCategoryId)
|
||||
{
|
||||
$category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail();
|
||||
public function findAllCategoryVariantsForCategoryId(SelectQuery $query, string $internalCategoryId) {
|
||||
$category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail();
|
||||
|
||||
$this->ProductCategories->behaviors()->get('Tree')->setConfig([
|
||||
'scope' => [
|
||||
'product_catalog_id' => $category->product_catalog_id ?? 1,
|
||||
],
|
||||
]);
|
||||
$this->ProductCategories->behaviors()->get('Tree')->setConfig([
|
||||
'scope' => [
|
||||
'product_catalog_id' => $category->product_catalog_id ?? 1,
|
||||
],
|
||||
]);
|
||||
|
||||
return $this->ProductCategories
|
||||
->find('path', for: $category->id)
|
||||
->contain(['ProductCategoryVariants']);
|
||||
}
|
||||
return $this->ProductCategories
|
||||
->find('path', for: $category->id)
|
||||
->contain(['ProductCategoryVariants']);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @param string $internalCategoryId
|
||||
* @return array
|
||||
*/
|
||||
public function getAllCategoryVariantsForCategoryId(string $internalCategoryId)
|
||||
{
|
||||
return $this->find('allCategoryVariantsForCategoryId', $internalCategoryId)->toArray();
|
||||
}
|
||||
public function getAllCategoryVariantsForCategoryId(string $internalCategoryId) {
|
||||
return $this->find('allCategoryVariantsForCategoryId', $internalCategoryId)->toArray();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,16 +4,9 @@ declare(strict_types=1);
|
||||
namespace CakeProducts\Model\Table;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Datasource\ResultSetInterface;
|
||||
use Cake\ORM\Association\BelongsTo;
|
||||
use Cake\ORM\Behavior\TimestampBehavior;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use CakeProducts\Model\Entity\ProductPhoto;
|
||||
use Closure;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
/**
|
||||
* ProductPhotos Model
|
||||
@@ -21,15 +14,15 @@ use Psr\SimpleCache\CacheInterface;
|
||||
* @property ProductsTable&BelongsTo $Products
|
||||
* @property ProductSkusTable&BelongsTo $ProductSkus
|
||||
*
|
||||
* @method ProductPhoto newEmptyEntity()
|
||||
* @method ProductPhoto newEntity(array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductPhoto newEmptyEntity()
|
||||
* @method \CakeProducts\Model\Entity\ProductPhoto newEntity()
|
||||
* @method array<ProductPhoto> newEntities(array $data, array $options = [])
|
||||
* @method ProductPhoto get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
|
||||
* @method ProductPhoto findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method ProductPhoto patchEntity(EntityInterface $entity, array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductPhoto get()
|
||||
* @method \CakeProducts\Model\Entity\ProductPhoto findOrCreate()
|
||||
* @method \CakeProducts\Model\Entity\ProductPhoto patchEntity()
|
||||
* @method array<ProductPhoto> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method ProductPhoto|false save(EntityInterface $entity, array $options = [])
|
||||
* @method ProductPhoto saveOrFail(EntityInterface $entity, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductPhoto saveOrFail()
|
||||
* @method iterable<ProductPhoto>|ResultSetInterface<ProductPhoto>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductPhoto>|ResultSetInterface<ProductPhoto> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductPhoto>|ResultSetInterface<ProductPhoto>|false deleteMany(iterable $entities, array $options = [])
|
||||
@@ -37,136 +30,134 @@ use Psr\SimpleCache\CacheInterface;
|
||||
*
|
||||
* @mixin TimestampBehavior
|
||||
*/
|
||||
class ProductPhotosTable extends Table
|
||||
{
|
||||
/**
|
||||
class ProductPhotosTable extends Table {
|
||||
|
||||
/**
|
||||
* Initialize method
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('product_photos');
|
||||
$this->setDisplayField('photo_filename');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setTable('product_photos');
|
||||
$this->setDisplayField('photo_filename');
|
||||
$this->setPrimaryKey('id');
|
||||
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductPhotos.entity', 'CakeProducts\Model\Entity\ProductPhoto')
|
||||
);
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductPhotos.entity', 'CakeProducts\Model\Entity\ProductPhoto'),
|
||||
);
|
||||
|
||||
$this->addBehavior('Timestamp');
|
||||
$this->addBehavior('Timestamp');
|
||||
|
||||
$this->addBehavior('Tools.Toggle', [
|
||||
'field' => 'primary_category_photo',
|
||||
'scopeFields' => ['product_category_id'],
|
||||
'scope' => [
|
||||
'deleted IS' => null,
|
||||
],
|
||||
]);
|
||||
$this->addBehavior('CakeProducts.SecondToggle', [
|
||||
'field' => 'primary_photo',
|
||||
'scopeFields' => ['product_id'],
|
||||
'scope' => [
|
||||
'deleted IS' => null,
|
||||
'product_id IS NOT' => null,
|
||||
],
|
||||
]);
|
||||
$this->addBehavior('CakeProducts.ThirdToggle', [
|
||||
'field' => 'primary_sku_photo',
|
||||
'scopeFields' => ['product_sku_id'],
|
||||
'scope' => [
|
||||
'deleted IS' => null,
|
||||
'product_sku_id IS NOT' => null,
|
||||
],
|
||||
]);
|
||||
$this->belongsTo('Products', [
|
||||
'foreignKey' => 'product_id',
|
||||
'joinType' => 'LEFT',
|
||||
'className' => 'CakeProducts.Products',
|
||||
]);
|
||||
$this->addBehavior('Tools.Toggle', [
|
||||
'field' => 'primary_category_photo',
|
||||
'scopeFields' => ['product_category_id'],
|
||||
'scope' => [
|
||||
'deleted IS' => null,
|
||||
],
|
||||
]);
|
||||
$this->addBehavior('CakeProducts.SecondToggle', [
|
||||
'field' => 'primary_photo',
|
||||
'scopeFields' => ['product_id'],
|
||||
'scope' => [
|
||||
'deleted IS' => null,
|
||||
'product_id IS NOT' => null,
|
||||
],
|
||||
]);
|
||||
$this->addBehavior('CakeProducts.ThirdToggle', [
|
||||
'field' => 'primary_sku_photo',
|
||||
'scopeFields' => ['product_sku_id'],
|
||||
'scope' => [
|
||||
'deleted IS' => null,
|
||||
'product_sku_id IS NOT' => null,
|
||||
],
|
||||
]);
|
||||
$this->belongsTo('Products', [
|
||||
'foreignKey' => 'product_id',
|
||||
'joinType' => 'LEFT',
|
||||
'className' => 'CakeProducts.Products',
|
||||
]);
|
||||
|
||||
$this->belongsTo('ProductCategories', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'joinType' => 'INNER',
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
]);
|
||||
$this->belongsTo('ProductCategories', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'joinType' => 'INNER',
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
]);
|
||||
|
||||
$this->belongsTo('ProductSkus', [
|
||||
'foreignKey' => 'product_sku_id',
|
||||
'joinType' => 'LEFT',
|
||||
'className' => 'CakeProducts.ProductSkus',
|
||||
]);
|
||||
}
|
||||
$this->belongsTo('ProductSkus', [
|
||||
'foreignKey' => 'product_sku_id',
|
||||
'joinType' => 'LEFT',
|
||||
'className' => 'CakeProducts.ProductSkus',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param Validator $validator Validator instance.
|
||||
* @return Validator
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->uuid('product_id')
|
||||
->allowEmptyString('product_id');
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->uuid('product_id')
|
||||
->allowEmptyString('product_id');
|
||||
|
||||
$validator
|
||||
->uuid('product_sku_id')
|
||||
->allowEmptyString('product_sku_id');
|
||||
$validator
|
||||
->uuid('product_sku_id')
|
||||
->allowEmptyString('product_sku_id');
|
||||
|
||||
$validator
|
||||
->uuid('product_category_id')
|
||||
->requirePresence('product_category_id', 'create')
|
||||
->notEmptyString('product_category_id');
|
||||
$validator
|
||||
->uuid('product_category_id')
|
||||
->requirePresence('product_category_id', 'create')
|
||||
->notEmptyString('product_category_id');
|
||||
|
||||
$validator
|
||||
->scalar('photo_dir')
|
||||
->maxLength('photo_dir', 255)
|
||||
->requirePresence('photo_dir', 'create')
|
||||
->notEmptyString('photo_dir');
|
||||
$validator
|
||||
->scalar('photo_dir')
|
||||
->maxLength('photo_dir', 255)
|
||||
->requirePresence('photo_dir', 'create')
|
||||
->notEmptyString('photo_dir');
|
||||
|
||||
$validator
|
||||
->scalar('photo_filename')
|
||||
->maxLength('photo_filename', 255)
|
||||
->requirePresence('photo_filename', 'create')
|
||||
->notEmptyString('photo_filename');
|
||||
$validator
|
||||
->scalar('photo_filename')
|
||||
->maxLength('photo_filename', 255)
|
||||
->requirePresence('photo_filename', 'create')
|
||||
->notEmptyString('photo_filename');
|
||||
|
||||
$validator
|
||||
->boolean('primary_photo')
|
||||
->notEmptyString('primary_photo');
|
||||
$validator
|
||||
->boolean('primary_photo')
|
||||
->notEmptyString('primary_photo');
|
||||
|
||||
$validator
|
||||
->integer('photo_position')
|
||||
->notEmptyString('photo_position');
|
||||
$validator
|
||||
->integer('photo_position')
|
||||
->notEmptyString('photo_position');
|
||||
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
->notEmptyString('enabled');
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
->notEmptyString('enabled');
|
||||
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
|
||||
return $validator;
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param RulesChecker $rules The rules object to be modified.
|
||||
* @return RulesChecker
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
|
||||
$rules->add($rules->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']);
|
||||
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
|
||||
public function buildRules(RulesChecker $rules): RulesChecker {
|
||||
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
|
||||
$rules->add($rules->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']);
|
||||
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,16 +3,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Table;
|
||||
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Datasource\ResultSetInterface;
|
||||
use Cake\ORM\Association\BelongsTo;
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use CakeProducts\Model\Entity\ProductSkuVariantValue;
|
||||
use Closure;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
/**
|
||||
* ProductSkuVariantValues Model
|
||||
@@ -21,92 +14,90 @@ use Psr\SimpleCache\CacheInterface;
|
||||
* @property ProductCategoryVariantsTable&BelongsTo $ProductCategoryVariants
|
||||
* @property ProductCategoryVariantOptionsTable&BelongsTo $ProductCategoryVariantOptions
|
||||
*
|
||||
* @method ProductSkuVariantValue newEmptyEntity()
|
||||
* @method ProductSkuVariantValue newEntity(array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductSkuVariantValue newEmptyEntity()
|
||||
* @method \CakeProducts\Model\Entity\ProductSkuVariantValue newEntity()
|
||||
* @method array<ProductSkuVariantValue> newEntities(array $data, array $options = [])
|
||||
* @method ProductSkuVariantValue get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
|
||||
* @method ProductSkuVariantValue findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method ProductSkuVariantValue patchEntity(EntityInterface $entity, array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductSkuVariantValue get()
|
||||
* @method \CakeProducts\Model\Entity\ProductSkuVariantValue findOrCreate()
|
||||
* @method \CakeProducts\Model\Entity\ProductSkuVariantValue patchEntity()
|
||||
* @method array<ProductSkuVariantValue> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method ProductSkuVariantValue|false save(EntityInterface $entity, array $options = [])
|
||||
* @method ProductSkuVariantValue saveOrFail(EntityInterface $entity, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductSkuVariantValue saveOrFail()
|
||||
* @method iterable<ProductSkuVariantValue>|ResultSetInterface<ProductSkuVariantValue>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductSkuVariantValue>|ResultSetInterface<ProductSkuVariantValue> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductSkuVariantValue>|ResultSetInterface<ProductSkuVariantValue>|false deleteMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductSkuVariantValue>|ResultSetInterface<ProductSkuVariantValue> deleteManyOrFail(iterable $entities, array $options = [])
|
||||
*/
|
||||
class ProductSkuVariantValuesTable extends Table
|
||||
{
|
||||
/**
|
||||
class ProductSkuVariantValuesTable extends Table {
|
||||
|
||||
/**
|
||||
* Initialize method
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('product_sku_variant_values');
|
||||
$this->setDisplayField('id');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setTable('product_sku_variant_values');
|
||||
$this->setDisplayField('id');
|
||||
$this->setPrimaryKey('id');
|
||||
|
||||
$this->belongsTo('ProductSkus', [
|
||||
'className' => 'CakeProducts.ProductSkus',
|
||||
'foreignKey' => 'product_sku_id',
|
||||
'propertyName' => 'product_sku',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
$this->belongsTo('ProductVariants', [
|
||||
'className' => 'CakeProducts.ProductVariants',
|
||||
'foreignKey' => 'product_variant_id',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
$this->belongsTo('ProductCategoryVariantOptions', [
|
||||
'className' => 'CakeProducts.ProductCategoryVariantOptions',
|
||||
'foreignKey' => 'product_category_variant_option_id',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
}
|
||||
$this->belongsTo('ProductSkus', [
|
||||
'className' => 'CakeProducts.ProductSkus',
|
||||
'foreignKey' => 'product_sku_id',
|
||||
'propertyName' => 'product_sku',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
$this->belongsTo('ProductVariants', [
|
||||
'className' => 'CakeProducts.ProductVariants',
|
||||
'foreignKey' => 'product_variant_id',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
$this->belongsTo('ProductCategoryVariantOptions', [
|
||||
'className' => 'CakeProducts.ProductCategoryVariantOptions',
|
||||
'foreignKey' => 'product_category_variant_option_id',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param Validator $validator Validator instance.
|
||||
* @return Validator
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->uuid('product_sku_id')
|
||||
->notEmptyString('product_sku_id');
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->uuid('product_sku_id')
|
||||
->notEmptyString('product_sku_id');
|
||||
|
||||
$validator
|
||||
->uuid('product_variant_id')
|
||||
->notEmptyString('product_variant_id');
|
||||
$validator
|
||||
->uuid('product_variant_id')
|
||||
->notEmptyString('product_variant_id');
|
||||
|
||||
$validator
|
||||
->uuid('product_category_variant_option_id')
|
||||
->notEmptyString('product_category_variant_option_id');
|
||||
$validator
|
||||
->uuid('product_category_variant_option_id')
|
||||
->notEmptyString('product_category_variant_option_id');
|
||||
|
||||
return $validator;
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param RulesChecker $rules The rules object to be modified.
|
||||
* @return RulesChecker
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
$rules->add($rules->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']);
|
||||
public function buildRules(RulesChecker $rules): RulesChecker {
|
||||
$rules->add($rules->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']);
|
||||
|
||||
// @TODO why not working?? causing tests to fail / associated variant values not saving on product-skus/add
|
||||
$rules->add($rules->existsIn(['product_variant_id'], 'ProductVariants'), ['errorField' => 'product_variant_id']);
|
||||
$rules->add($rules->existsIn(['product_category_variant_option_id'], 'ProductCategoryVariantOptions'), ['errorField' => 'product_category_variant_option_id']);
|
||||
// @TODO why not working?? causing tests to fail / associated variant values not saving on product-skus/add
|
||||
$rules->add($rules->existsIn(['product_variant_id'], 'ProductVariants'), ['errorField' => 'product_variant_id']);
|
||||
$rules->add($rules->existsIn(['product_category_variant_option_id'], 'ProductCategoryVariantOptions'), ['errorField' => 'product_category_variant_option_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,33 +4,24 @@ declare(strict_types=1);
|
||||
namespace CakeProducts\Model\Table;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use CakeProducts\Model\Table\ProductsTable;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Datasource\ResultSetInterface;
|
||||
use Cake\ORM\Association\BelongsTo;
|
||||
use Cake\ORM\Behavior\TimestampBehavior;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use CakeProducts\Model\Entity\ProductSku;
|
||||
use Closure;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
/**
|
||||
* ProductSkus Model
|
||||
*
|
||||
* @property ProductsTable&BelongsTo $Products
|
||||
*
|
||||
* @method ProductSku newEmptyEntity()
|
||||
* @method ProductSku newEntity(array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductSku newEmptyEntity()
|
||||
* @method \CakeProducts\Model\Entity\ProductSku newEntity()
|
||||
* @method array<ProductSku> newEntities(array $data, array $options = [])
|
||||
* @method ProductSku get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
|
||||
* @method ProductSku findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method ProductSku patchEntity(EntityInterface $entity, array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductSku get()
|
||||
* @method \CakeProducts\Model\Entity\ProductSku findOrCreate()
|
||||
* @method \CakeProducts\Model\Entity\ProductSku patchEntity()
|
||||
* @method array<ProductSku> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method ProductSku|false save(EntityInterface $entity, array $options = [])
|
||||
* @method ProductSku saveOrFail(EntityInterface $entity, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductSku saveOrFail()
|
||||
* @method iterable<ProductSku>|ResultSetInterface<ProductSku>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductSku>|ResultSetInterface<ProductSku> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductSku>|ResultSetInterface<ProductSku>|false deleteMany(iterable $entities, array $options = [])
|
||||
@@ -38,114 +29,112 @@ use Psr\SimpleCache\CacheInterface;
|
||||
*
|
||||
* @mixin TimestampBehavior
|
||||
*/
|
||||
class ProductSkusTable extends Table
|
||||
{
|
||||
/**
|
||||
class ProductSkusTable extends Table {
|
||||
|
||||
/**
|
||||
* Initialize method
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('product_skus');
|
||||
$this->setDisplayField('sku');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setTable('product_skus');
|
||||
$this->setDisplayField('sku');
|
||||
$this->setPrimaryKey('id');
|
||||
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductSkus.entity', 'CakeProducts\Model\Entity\ProductSku')
|
||||
);
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductSkus.entity', 'CakeProducts\Model\Entity\ProductSku'),
|
||||
);
|
||||
|
||||
$this->addBehavior('Timestamp');
|
||||
$this->addBehavior('Tools.Toggle', [
|
||||
'field' => 'default_sku',
|
||||
'scopeFields' => ['product_id'],
|
||||
'scope' => [
|
||||
'deleted IS' => null,
|
||||
],
|
||||
]);
|
||||
$this->addBehavior('Timestamp');
|
||||
$this->addBehavior('Tools.Toggle', [
|
||||
'field' => 'default_sku',
|
||||
'scopeFields' => ['product_id'],
|
||||
'scope' => [
|
||||
'deleted IS' => null,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->belongsTo('Products', [
|
||||
'className' => 'CakeProducts.Products',
|
||||
'foreignKey' => 'product_id',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
$this->belongsTo('Products', [
|
||||
'className' => 'CakeProducts.Products',
|
||||
'foreignKey' => 'product_id',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
|
||||
$this->hasMany('ProductSkuVariantValues', [
|
||||
'foreignKey' => 'product_sku_id',
|
||||
'className' => 'CakeProducts.ProductSkuVariantValues',
|
||||
'saveStrategy' => 'replace',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ProductSkuVariantValues', [
|
||||
'foreignKey' => 'product_sku_id',
|
||||
'className' => 'CakeProducts.ProductSkuVariantValues',
|
||||
'saveStrategy' => 'replace',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
|
||||
$this->hasMany('ProductPhotos', [
|
||||
'foreignKey' => 'product_sku_id',
|
||||
'className' => 'CakeProducts.ProductPhotos',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ProductPhotos', [
|
||||
'foreignKey' => 'product_sku_id',
|
||||
'className' => 'CakeProducts.ProductPhotos',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
|
||||
$this->hasOne('PrimaryProductPhotos', [
|
||||
'foreignKey' => 'product_sku_id',
|
||||
'conditions' => ['PrimaryProductPhotos.primary_photo' => true],
|
||||
'className' => 'CakeProducts.ProductPhotos',
|
||||
'dependent' => true,
|
||||
]);
|
||||
}
|
||||
$this->hasOne('PrimaryProductPhotos', [
|
||||
'foreignKey' => 'product_sku_id',
|
||||
'conditions' => ['PrimaryProductPhotos.primary_photo' => true],
|
||||
'className' => 'CakeProducts.ProductPhotos',
|
||||
'dependent' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param Validator $validator Validator instance.
|
||||
* @return Validator
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->uuid('product_id')
|
||||
->notEmptyString('product_id');
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->uuid('product_id')
|
||||
->notEmptyString('product_id');
|
||||
|
||||
$validator
|
||||
->scalar('sku')
|
||||
->maxLength('sku', 255)
|
||||
->requirePresence('sku', 'create')
|
||||
->notEmptyString('sku');
|
||||
$validator
|
||||
->scalar('sku')
|
||||
->maxLength('sku', 255)
|
||||
->requirePresence('sku', 'create')
|
||||
->notEmptyString('sku');
|
||||
|
||||
$validator
|
||||
->scalar('barcode')
|
||||
->maxLength('barcode', 255)
|
||||
->allowEmptyString('barcode');
|
||||
$validator
|
||||
->scalar('barcode')
|
||||
->maxLength('barcode', 255)
|
||||
->allowEmptyString('barcode');
|
||||
|
||||
$validator
|
||||
->decimal('price')
|
||||
->allowEmptyString('price');
|
||||
$validator
|
||||
->decimal('price')
|
||||
->allowEmptyString('price');
|
||||
|
||||
$validator
|
||||
->decimal('cost')
|
||||
->allowEmptyString('cost');
|
||||
$validator
|
||||
->decimal('cost')
|
||||
->allowEmptyString('cost');
|
||||
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
|
||||
return $validator;
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param RulesChecker $rules The rules object to be modified.
|
||||
* @return RulesChecker
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
|
||||
$rules->add($rules->isUnique(['sku'], 'SKU must be unique'), ['errorField' => 'sku']);
|
||||
public function buildRules(RulesChecker $rules): RulesChecker {
|
||||
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
|
||||
$rules->add($rules->isUnique(['sku'], 'SKU must be unique'), ['errorField' => 'sku']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,18 +3,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Table;
|
||||
|
||||
use CakeProducts\Model\Entity\ProductVariant;
|
||||
use CakeProducts\Model\Table\ProductCategoryVariantsTable;
|
||||
use CakeProducts\Model\Table\ProductsTable;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Datasource\ResultSetInterface;
|
||||
use Cake\ORM\Association\BelongsTo;
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use Closure;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
/**
|
||||
* ProductVariants Model
|
||||
@@ -22,96 +13,94 @@ use Psr\SimpleCache\CacheInterface;
|
||||
* @property ProductCategoryVariantsTable&BelongsTo $ProductCategoryVariants
|
||||
* @property ProductsTable&BelongsTo $Products
|
||||
*
|
||||
* @method ProductVariant newEmptyEntity()
|
||||
* @method ProductVariant newEntity(array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductVariant newEmptyEntity()
|
||||
* @method \CakeProducts\Model\Entity\ProductVariant newEntity()
|
||||
* @method array<ProductVariant> newEntities(array $data, array $options = [])
|
||||
* @method ProductVariant get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
|
||||
* @method ProductVariant findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method ProductVariant patchEntity(EntityInterface $entity, array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductVariant get()
|
||||
* @method \CakeProducts\Model\Entity\ProductVariant findOrCreate()
|
||||
* @method \CakeProducts\Model\Entity\ProductVariant patchEntity()
|
||||
* @method array<ProductVariant> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method ProductVariant|false save(EntityInterface $entity, array $options = [])
|
||||
* @method ProductVariant saveOrFail(EntityInterface $entity, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductVariant saveOrFail()
|
||||
* @method iterable<ProductVariant>|ResultSetInterface<ProductVariant>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductVariant>|ResultSetInterface<ProductVariant> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductVariant>|ResultSetInterface<ProductVariant>|false deleteMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductVariant>|ResultSetInterface<ProductVariant> deleteManyOrFail(iterable $entities, array $options = [])
|
||||
*/
|
||||
class ProductVariantsTable extends Table
|
||||
{
|
||||
/**
|
||||
class ProductVariantsTable extends Table {
|
||||
|
||||
/**
|
||||
* Initialize method
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('product_variants');
|
||||
$this->setDisplayField('name');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setTable('product_variants');
|
||||
$this->setDisplayField('name');
|
||||
$this->setPrimaryKey('id');
|
||||
|
||||
$this->belongsTo('ProductCategoryVariants', [
|
||||
'className' => 'CakeProducts.ProductCategoryVariants',
|
||||
'foreignKey' => 'product_category_variant_id',
|
||||
]);
|
||||
$this->belongsTo('Products', [
|
||||
'className' => 'CakeProducts.Products',
|
||||
'foreignKey' => 'product_id',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
$this->belongsTo('ProductCategoryVariants', [
|
||||
'className' => 'CakeProducts.ProductCategoryVariants',
|
||||
'foreignKey' => 'product_category_variant_id',
|
||||
]);
|
||||
$this->belongsTo('Products', [
|
||||
'className' => 'CakeProducts.Products',
|
||||
'foreignKey' => 'product_id',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
|
||||
$this->hasMany('ProductSkuVariantValues', [
|
||||
'className' => 'CakeProducts.ProductSkuVariantValues',
|
||||
'foreignKey' => 'product_variant_id',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
}
|
||||
$this->hasMany('ProductSkuVariantValues', [
|
||||
'className' => 'CakeProducts.ProductSkuVariantValues',
|
||||
'foreignKey' => 'product_variant_id',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param Validator $validator Validator instance.
|
||||
* @return Validator
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->scalar('name')
|
||||
->maxLength('name', 255)
|
||||
->requirePresence('name', 'create')
|
||||
->notEmptyString('name');
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->scalar('name')
|
||||
->maxLength('name', 255)
|
||||
->requirePresence('name', 'create')
|
||||
->notEmptyString('name');
|
||||
|
||||
$validator
|
||||
->uuid('product_category_variant_id')
|
||||
->allowEmptyString('product_category_variant_id');
|
||||
$validator
|
||||
->uuid('product_category_variant_id')
|
||||
->allowEmptyString('product_category_variant_id');
|
||||
|
||||
$validator
|
||||
->uuid('product_id')
|
||||
->notEmptyString('product_id');
|
||||
$validator
|
||||
->uuid('product_id')
|
||||
->notEmptyString('product_id');
|
||||
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
->requirePresence('enabled', 'create')
|
||||
->notEmptyString('enabled');
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
->requirePresence('enabled', 'create')
|
||||
->notEmptyString('enabled');
|
||||
|
||||
return $validator;
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param RulesChecker $rules The rules object to be modified.
|
||||
* @return RulesChecker
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
$rules->add($rules->existsIn(['product_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']);
|
||||
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
|
||||
public function buildRules(RulesChecker $rules): RulesChecker {
|
||||
$rules->add($rules->existsIn(['product_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']);
|
||||
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,154 +5,145 @@ namespace CakeProducts\Model\Table;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Database\Type\EnumType;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Datasource\ResultSetInterface;
|
||||
use Cake\ORM\Association\BelongsTo;
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use CakeProducts\Model\Entity\Product;
|
||||
use CakeProducts\Model\Enum\ProductProductTypeId;
|
||||
use Closure;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
/**
|
||||
* Products Model
|
||||
*
|
||||
* @property ProductCategoriesTable&BelongsTo $ProductCategories
|
||||
*
|
||||
* @method Product newEmptyEntity()
|
||||
* @method Product newEntity(array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\Product newEmptyEntity()
|
||||
* @method \CakeProducts\Model\Entity\Product newEntity()
|
||||
* @method array<Product> newEntities(array $data, array $options = [])
|
||||
* @method Product get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
|
||||
* @method Product findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method Product patchEntity(EntityInterface $entity, array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\Product get()
|
||||
* @method \CakeProducts\Model\Entity\Product findOrCreate()
|
||||
* @method \CakeProducts\Model\Entity\Product patchEntity()
|
||||
* @method array<Product> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method Product|false save(EntityInterface $entity, array $options = [])
|
||||
* @method Product saveOrFail(EntityInterface $entity, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\Product saveOrFail()
|
||||
* @method iterable<Product>|ResultSetInterface<Product>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<Product>|ResultSetInterface<Product> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<Product>|ResultSetInterface<Product>|false deleteMany(iterable $entities, array $options = [])
|
||||
* @method iterable<Product>|ResultSetInterface<Product> deleteManyOrFail(iterable $entities, array $options = [])
|
||||
*/
|
||||
class ProductsTable extends Table
|
||||
{
|
||||
/**
|
||||
class ProductsTable extends Table {
|
||||
|
||||
/**
|
||||
* Initialize method
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('products');
|
||||
$this->setDisplayField('name');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setTable('products');
|
||||
$this->setDisplayField('name');
|
||||
$this->setPrimaryKey('id');
|
||||
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.Products.entity', 'CakeProducts\Model\Entity\Product')
|
||||
);
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.Products.entity', 'CakeProducts\Model\Entity\Product'),
|
||||
);
|
||||
|
||||
$this->belongsTo('ProductCategories', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'joinType' => 'INNER',
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
]);
|
||||
$this->belongsTo('ProductCategories', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'joinType' => 'INNER',
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
]);
|
||||
|
||||
$this->hasMany('ProductAttributes', [
|
||||
'className' => 'CakeProducts.ProductAttributes',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ProductAttributes', [
|
||||
'className' => 'CakeProducts.ProductAttributes',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
|
||||
$this->hasMany('ProductVariants', [
|
||||
'foreignKey' => 'product_id',
|
||||
'className' => 'CakeProducts.ProductVariants',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ProductVariants', [
|
||||
'foreignKey' => 'product_id',
|
||||
'className' => 'CakeProducts.ProductVariants',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
|
||||
$this->hasMany('ProductSkus', [
|
||||
'foreignKey' => 'product_id',
|
||||
'className' => 'CakeProducts.ProductSkus',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ProductSkus', [
|
||||
'foreignKey' => 'product_id',
|
||||
'className' => 'CakeProducts.ProductSkus',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
|
||||
$this->hasMany('ProductPhotos', [
|
||||
'foreignKey' => 'product_id',
|
||||
'className' => 'CakeProducts.ProductPhotos',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ProductPhotos', [
|
||||
'foreignKey' => 'product_id',
|
||||
'className' => 'CakeProducts.ProductPhotos',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
|
||||
$this->hasOne('PrimaryProductPhotos', [
|
||||
'foreignKey' => 'product_id',
|
||||
'conditions' => ['PrimaryProductPhotos.primary_photo' => true],
|
||||
'className' => 'CakeProducts.ProductPhotos',
|
||||
'dependent' => true,
|
||||
]);
|
||||
$this->hasOne('PrimaryProductPhotos', [
|
||||
'foreignKey' => 'product_id',
|
||||
'conditions' => ['PrimaryProductPhotos.primary_photo' => true],
|
||||
'className' => 'CakeProducts.ProductPhotos',
|
||||
'dependent' => true,
|
||||
]);
|
||||
|
||||
$this->hasOne('DefaultProductSkus', [
|
||||
'foreignKey' => 'product_id',
|
||||
'conditions' => ['DefaultProductSkus.default_sku' => true],
|
||||
'className' => 'CakeProducts.ProductSkus',
|
||||
'propertyName' => 'default_product_sku',
|
||||
'dependent' => true,
|
||||
]);
|
||||
$this->hasOne('DefaultProductSkus', [
|
||||
'foreignKey' => 'product_id',
|
||||
'conditions' => ['DefaultProductSkus.default_sku' => true],
|
||||
'className' => 'CakeProducts.ProductSkus',
|
||||
'propertyName' => 'default_product_sku',
|
||||
'dependent' => true,
|
||||
]);
|
||||
|
||||
$this->getSchema()->setColumnType('product_type_id', EnumType::from(ProductProductTypeId::class));
|
||||
$this->getSchema()->setColumnType('product_type_id', EnumType::from(ProductProductTypeId::class));
|
||||
|
||||
$this->addBehavior('Muffin/Trash.Trash');
|
||||
}
|
||||
$this->addBehavior('Muffin/Trash.Trash');
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param Validator $validator Validator instance.
|
||||
* @return Validator
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->scalar('name')
|
||||
->maxLength('name', 255)
|
||||
->requirePresence('name', 'create')
|
||||
->notEmptyString('name');
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->scalar('name')
|
||||
->maxLength('name', 255)
|
||||
->requirePresence('name', 'create')
|
||||
->notEmptyString('name');
|
||||
|
||||
$validator
|
||||
->uuid('product_category_id')
|
||||
->notEmptyString('product_category_id');
|
||||
$validator
|
||||
->uuid('product_category_id')
|
||||
->notEmptyString('product_category_id');
|
||||
|
||||
$validator
|
||||
->integer('product_type_id')
|
||||
->requirePresence('product_type_id', 'create')
|
||||
->notEmptyString('product_type_id');
|
||||
$validator
|
||||
->integer('product_type_id')
|
||||
->requirePresence('product_type_id', 'create')
|
||||
->notEmptyString('product_type_id');
|
||||
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
|
||||
return $validator;
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param RulesChecker $rules The rules object to be modified.
|
||||
* @return RulesChecker
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
$rules->add($rules->isUnique(['product_category_id', 'name']), ['errorField' => 'product_category_id']);
|
||||
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
|
||||
public function buildRules(RulesChecker $rules): RulesChecker {
|
||||
$rules->add($rules->isUnique(['product_category_id', 'name']), ['errorField' => 'product_category_id']);
|
||||
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
|
||||
// $rules->add($rules->validCount('product_attributes', 0, '<=', 'You must not have any tags'));
|
||||
|
||||
return $rules;
|
||||
}
|
||||
return $rules;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user