composer update + load more dev dependencies for code quality, checkstyle fix

This commit is contained in:
bs
2026-08-21 23:57:55 -07:00
parent c196dc2fe0
commit 8e142f56ab
104 changed files with 6341 additions and 6743 deletions
+22 -2
View File
@@ -9,11 +9,14 @@
"dereuromark/cakephp-tools": "^3.9", "dereuromark/cakephp-tools": "^3.9",
"muffin/trash": "^4.2", "muffin/trash": "^4.2",
"cakephp/cakephp": "^5.0.1", "cakephp/cakephp": "^5.0.1",
"bentools/cartesian-product": "dev-master" "bentools/cartesian-product": "^2.0"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^10.1", "phpunit/phpunit": "^10.1",
"cakephp/migrations": "^4.0.0" "cakephp/migrations": "^4.0.0",
"cakedc/cakephp-phpstan": "^4.1",
"dereuromark/composer-prefer-lowest": "^0.1.10",
"fig-r/psr2r-sniffer": "^2.7"
}, },
"suggest": { "suggest": {
"hi-powered-dev/cake-carts": "Allow users to add products/SKUs to a cart" "hi-powered-dev/cake-carts": "Allow users to add products/SKUs to a cart"
@@ -29,5 +32,22 @@
"Cake\\Test\\": "vendor/cakephp/cakephp/tests/", "Cake\\Test\\": "vendor/cakephp/cakephp/tests/",
"TestApp\\": "tests/test_app/src/" "TestApp\\": "tests/test_app/src/"
} }
},
"scripts": {
"check": [
"@test",
"@cs-check"
],
"test": "phpunit --colors=always",
"cs-check": "vendor/bin/phpcs --colors",
"cs-fix": "vendor/bin/phpcbf --colors",
"lowest": "validate-prefer-lowest",
"lowest-setup": "composer update --prefer-lowest --prefer-stable --prefer-dist --no-interaction && cp composer.json composer.backup && composer require --dev dereuromark/composer-prefer-lowest && mv composer.backup composer.json",
"stan": "phpstan analyze"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
} }
} }
@@ -3,42 +3,42 @@ declare(strict_types=1);
use Migrations\AbstractMigration; use Migrations\AbstractMigration;
class CreateProductCatalogs extends AbstractMigration class CreateProductCatalogs extends AbstractMigration {
{
/** /**
* Change Method. * Change Method.
* *
* More information on this method is available here: * More information on this method is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{ $table = $this->table('product_catalogs', ['id' => false, 'primary_key' => ['id']]);
$table = $this->table('product_catalogs', ['id' => false, 'primary_key' => ['id']]); $table->addColumn('id', 'uuid', [
$table->addColumn('id', 'uuid', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('name', 'string', [
$table->addColumn('name', 'string', [ 'default' => null,
'default' => null, 'limit' => 255,
'limit' => 255, 'null' => false,
'null' => false, ]);
]); $table->addColumn('catalog_description', 'string', [
$table->addColumn('catalog_description', 'string', [ 'default' => null,
'default' => null, 'limit' => 255,
'limit' => 255, 'null' => true,
'null' => true, ]);
]); $table->addColumn('enabled', 'boolean', [
$table->addColumn('enabled', 'boolean', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addIndex([
$table->addIndex([ 'name',
'name', ], [
], [ 'name' => 'BY_NAME',
'name' => 'BY_NAME', 'unique' => true,
'unique' => true, ]);
]); $table->create();
$table->create(); }
}
} }
@@ -3,36 +3,35 @@ declare(strict_types=1);
use Migrations\AbstractMigration; use Migrations\AbstractMigration;
class CreateProductCategories extends AbstractMigration class CreateProductCategories extends AbstractMigration {
{
/** /**
* Change Method. * Change Method.
* *
* More information on this method is available here: * More information on this method is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{ $table = $this->table('product_categories');
$table = $this->table('product_categories');
$table->addColumn('product_catalog_id', 'uuid', [ $table->addColumn('product_catalog_id', 'uuid', [
'default' => null, 'default' => null,
'null' => false, 'null' => false,
]); ]);
$table->addColumn('internal_id', 'uuid', [ $table->addColumn('internal_id', 'uuid', [
'default' => null, 'default' => null,
'null' => false, 'null' => false,
]); ]);
$table->addColumn('name', 'string', [ $table->addColumn('name', 'string', [
'default' => null, 'default' => null,
'limit' => 255, 'limit' => 255,
'null' => false, 'null' => false,
]); ]);
$table->addColumn('category_description', 'text', [ $table->addColumn('category_description', 'text', [
'default' => null, 'default' => null,
'null' => true, 'null' => true,
]); ]);
// $table->addColumn('shopify_v1_id', 'integer', [ // $table->addColumn('shopify_v1_id', 'integer', [
// 'default' => null, // 'default' => null,
// 'limit' => 11, // 'limit' => 11,
@@ -43,36 +42,37 @@ class CreateProductCategories extends AbstractMigration
// 'limit' => 255, // 'limit' => 255,
// 'null' => true, // 'null' => true,
// ]); // ]);
$table->addColumn('parent_id', 'integer', [ $table->addColumn('parent_id', 'integer', [
'default' => null, 'default' => null,
'limit' => 11, 'limit' => 11,
'null' => true, 'null' => true,
]); ]);
$table->addColumn('lft', 'integer', [ $table->addColumn('lft', 'integer', [
'default' => null, 'default' => null,
'limit' => 11, 'limit' => 11,
'null' => false, 'null' => false,
]); ]);
$table->addColumn('rght', 'integer', [ $table->addColumn('rght', 'integer', [
'default' => null, 'default' => null,
'limit' => 11, 'limit' => 11,
'null' => false, 'null' => false,
]); ]);
$table->addColumn('enabled', 'boolean', [ $table->addColumn('enabled', 'boolean', [
'default' => false, 'default' => false,
'null' => false, 'null' => false,
]); ]);
$table->addIndex('parent_id');
$table->addIndex('lft');
$table->addIndex('product_catalog_id');
$table->addIndex([
'product_catalog_id',
'name',
], [
'name' => 'BY_NAME_AND_CATALOG_ID',
'unique' => true,
]);
$table->create();
}
$table->addIndex('parent_id');
$table->addIndex('lft');
$table->addIndex('product_catalog_id');
$table->addIndex([
'product_catalog_id',
'name',
], [
'name' => 'BY_NAME_AND_CATALOG_ID',
'unique' => true,
]);
$table->create();
}
} }
@@ -3,38 +3,37 @@ declare(strict_types=1);
use Migrations\AbstractMigration; use Migrations\AbstractMigration;
class CreateProducts extends AbstractMigration class CreateProducts extends AbstractMigration {
{
/** /**
* Change Method. * Change Method.
* *
* More information on this method is available here: * More information on this method is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{ $table = $this->table('products', ['id' => false, 'primary_key' => ['id']]);
$table = $this->table('products', ['id' => false, 'primary_key' => ['id']]); $table->addColumn('id', 'uuid', [
$table->addColumn('id', 'uuid', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('name', 'string', [
$table->addColumn('name', 'string', [ 'default' => null,
'default' => null, 'limit' => 255,
'limit' => 255, 'null' => false,
'null' => false, ]);
]); $table->addColumn('product_category_id', 'uuid', [
$table->addColumn('product_category_id', 'uuid', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('product_type_id', 'integer', [
$table->addColumn('product_type_id', 'integer', [ 'default' => null,
'default' => null, 'limit' => 11,
'limit' => 11, 'null' => false,
'null' => false, ]);
]); $table->addIndex('product_category_id');
$table->addIndex('product_category_id'); $table->addIndex('product_type_id');
$table->addIndex('product_type_id');
// $table->addIndex([ // $table->addIndex([
// 'product_category_id', // 'product_category_id',
// 'name', // 'name',
@@ -42,6 +41,7 @@ class CreateProducts extends AbstractMigration
// 'name' => 'BY_NAME_AND_CATEGORY_ID', // 'name' => 'BY_NAME_AND_CATEGORY_ID',
// 'unique' => true, // 'unique' => true,
// ]); // ]);
$table->create(); $table->create();
} }
} }
@@ -3,53 +3,53 @@ declare(strict_types=1);
use Migrations\AbstractMigration; use Migrations\AbstractMigration;
class CreateProductCategoryAttributes extends AbstractMigration class CreateProductCategoryAttributes extends AbstractMigration {
{
/** /**
* Change Method. * Change Method.
* *
* More information on this method is available here: * More information on this method is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{ $table = $this->table('product_category_attributes', ['id' => false, 'primary_key' => ['id']]);
$table = $this->table('product_category_attributes', ['id' => false, 'primary_key' => ['id']]); $table->addColumn('id', 'uuid', [
$table->addColumn('id', 'uuid', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('name', 'string', [
$table->addColumn('name', 'string', [ 'default' => null,
'default' => null, 'limit' => 255,
'limit' => 255, 'null' => false,
'null' => false, ]);
]); $table->addColumn('product_category_id', 'uuid', [
$table->addColumn('product_category_id', 'uuid', [ 'default' => null,
'default' => null, 'null' => true,
'null' => true, ]);
]); $table->addColumn('attribute_type_id', 'integer', [
$table->addColumn('attribute_type_id', 'integer', [ 'default' => null,
'default' => null, 'limit' => 11,
'limit' => 11, 'null' => false,
'null' => false, ]);
]); $table->addColumn('enabled', 'boolean', [
$table->addColumn('enabled', 'boolean', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addIndex([
$table->addIndex([ 'product_category_id',
'product_category_id', ], [
], [ 'name' => 'BY_PRODUCT_CATEGORY_ID',
'name' => 'BY_PRODUCT_CATEGORY_ID', 'unique' => false,
'unique' => false, ]);
]); $table->addIndex([
$table->addIndex([ 'name',
'name', 'product_category_id',
'product_category_id', ], [
], [ 'name' => 'BY_NAME_AND_PRODUCT_CATEGORY_ID_UNIQUE',
'name' => 'BY_NAME_AND_PRODUCT_CATEGORY_ID_UNIQUE', 'unique' => true,
'unique' => true, ]);
]); $table->create();
$table->create(); }
}
} }
@@ -3,46 +3,46 @@ declare(strict_types=1);
use Migrations\AbstractMigration; use Migrations\AbstractMigration;
class CreateProductCategoryAttributeOptions extends AbstractMigration class CreateProductCategoryAttributeOptions extends AbstractMigration {
{
/** /**
* Change Method. * Change Method.
* *
* More information on this method is available here: * More information on this method is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{ $table = $this->table('product_category_attribute_options', ['id' => false, 'primary_key' => ['id']]);
$table = $this->table('product_category_attribute_options', ['id' => false, 'primary_key' => ['id']]); $table->addColumn('id', 'uuid', [
$table->addColumn('id', 'uuid', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('product_category_attribute_id', 'uuid', [
$table->addColumn('product_category_attribute_id', 'uuid', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('attribute_value', 'string', [
$table->addColumn('attribute_value', 'string', [ 'default' => null,
'default' => null, 'limit' => 255,
'limit' => 255, 'null' => false,
'null' => false, ]);
]); $table->addColumn('attribute_label', 'string', [
$table->addColumn('attribute_label', 'string', [ 'default' => null,
'default' => null, 'limit' => 255,
'limit' => 255, 'null' => false,
'null' => false, ]);
]); $table->addColumn('enabled', 'boolean', [
$table->addColumn('enabled', 'boolean', [ 'default' => true,
'default' => true, 'null' => false,
'null' => false, ]);
]); $table->addIndex([
$table->addIndex([ 'product_category_attribute_id',
'product_category_attribute_id', ], [
], [ 'name' => 'BY_PRODUCT_CATEGORY_ATTRIBUTE_ID',
'name' => 'BY_PRODUCT_CATEGORY_ATTRIBUTE_ID', 'unique' => false,
'unique' => false, ]);
]); $table->create();
$table->create(); }
}
} }
@@ -3,54 +3,54 @@ declare(strict_types=1);
use Migrations\AbstractMigration; use Migrations\AbstractMigration;
class CreateExternalProductCatalogs extends AbstractMigration class CreateExternalProductCatalogs extends AbstractMigration {
{
/** /**
* Change Method. * Change Method.
* *
* More information on this method is available here: * More information on this method is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{ $table = $this->table('external_product_catalogs', ['id' => false, 'primary_key' => ['id']]);
$table = $this->table('external_product_catalogs', ['id' => false, 'primary_key' => ['id']]); $table->addColumn('id', 'uuid', [
$table->addColumn('id', 'uuid', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('product_catalog_id', 'uuid', [
$table->addColumn('product_catalog_id', 'uuid', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('base_url', 'string', [
$table->addColumn('base_url', 'string', [ 'default' => null,
'default' => null, 'limit' => 255,
'limit' => 255, 'null' => false,
'null' => false, ]);
]); $table->addColumn('api_url', 'string', [
$table->addColumn('api_url', 'string', [ 'default' => null,
'default' => null, 'limit' => 255,
'limit' => 255, 'null' => false,
'null' => false, ]);
]); $table->addColumn('created', 'datetime', [
$table->addColumn('created', 'datetime', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('deleted', 'datetime', [
$table->addColumn('deleted', 'datetime', [ 'default' => null,
'default' => null, 'null' => true,
'null' => true, ]);
]); $table->addColumn('enabled', 'boolean', [
$table->addColumn('enabled', 'boolean', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addIndex([
$table->addIndex([ 'product_catalog_id',
'product_catalog_id', ], [
], [ 'name' => 'BY_PRODUCT_CATALOG_ID',
'name' => 'BY_PRODUCT_CATALOG_ID', 'unique' => false,
'unique' => false, ]);
]); $table->create();
$table->create(); }
}
} }
@@ -3,20 +3,20 @@ declare(strict_types=1);
use Migrations\BaseMigration; use Migrations\BaseMigration;
class RemoveCatalogIdFromExternalProductCatalogs extends BaseMigration class RemoveCatalogIdFromExternalProductCatalogs extends BaseMigration {
{
/** /**
* Change Method. * Change Method.
* *
* More information on this method is available here: * More information on this method is available here:
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{ $table = $this->table('external_product_catalogs');
$table = $this->table('external_product_catalogs'); $table->removeColumn('product_catalog_id');
$table->removeColumn('product_catalog_id'); $table->removeColumn('enabled');
$table->removeColumn('enabled'); $table->update();
$table->update(); }
}
} }
@@ -3,34 +3,34 @@ declare(strict_types=1);
use Migrations\BaseMigration; use Migrations\BaseMigration;
class CreateExternalProductCatalogsProductCatalogs extends BaseMigration class CreateExternalProductCatalogsProductCatalogs extends BaseMigration {
{
/** /**
* Change Method. * Change Method.
* *
* More information on this method is available here: * More information on this method is available here:
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{ $table = $this->table('external_product_catalogs_product_catalogs');
$table = $this->table('external_product_catalogs_product_catalogs'); $table->addColumn('external_product_catalog_id', 'uuid', [
$table->addColumn('external_product_catalog_id', 'uuid', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('product_catalog_id', 'uuid', [
$table->addColumn('product_catalog_id', 'uuid', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('created', 'datetime', [
$table->addColumn('created', 'datetime', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('enabled', 'boolean', [
$table->addColumn('enabled', 'boolean', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->create();
$table->create(); }
}
} }
@@ -3,39 +3,39 @@ declare(strict_types=1);
use Migrations\BaseMigration; use Migrations\BaseMigration;
class CreateProductAttributes extends BaseMigration class CreateProductAttributes extends BaseMigration {
{
/** /**
* Change Method. * Change Method.
* *
* More information on this method is available here: * More information on this method is available here:
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{ $table = $this->table('product_attributes', ['id' => false, 'primary_key' => ['id']]);
$table = $this->table('product_attributes', ['id' => false, 'primary_key' => ['id']]); $table->addColumn('id', 'uuid', [
$table->addColumn('id', 'uuid', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('product_id', 'uuid', [
$table->addColumn('product_id', 'uuid', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('product_category_attribute_id', 'uuid', [
$table->addColumn('product_category_attribute_id', 'uuid', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('attribute_value', 'string', [
$table->addColumn('attribute_value', 'string', [ 'default' => null,
'default' => null, 'limit' => 255,
'limit' => 255, 'null' => true,
'null' => true, ]);
]); $table->addColumn('product_category_attribute_option_id', 'uuid', [
$table->addColumn('product_category_attribute_option_id', 'uuid', [ 'default' => null,
'default' => null, 'null' => true,
'null' => true, ]);
]); $table->create();
$table->create(); }
}
} }
@@ -3,64 +3,64 @@ declare(strict_types=1);
use Migrations\BaseMigration; use Migrations\BaseMigration;
class AddSoftDeleteToAllTables extends BaseMigration class AddSoftDeleteToAllTables extends BaseMigration {
{
/** /**
* Change Method. * Change Method.
* *
* More information on this method is available here: * More information on this method is available here:
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{ $table = $this->table('products');
$table = $this->table('products'); $table->addColumn('deleted', 'datetime', [
$table->addColumn('deleted', 'datetime', [ 'default' => null,
'default' => null, 'null' => true,
'null' => true, ]);
]); $table->update();
$table->update();
$table = $this->table('product_category_attributes'); $table = $this->table('product_category_attributes');
$table->addColumn('deleted', 'datetime', [ $table->addColumn('deleted', 'datetime', [
'default' => null, 'default' => null,
'null' => true, 'null' => true,
]); ]);
$table->update(); $table->update();
$table = $this->table('product_category_attribute_options'); $table = $this->table('product_category_attribute_options');
$table->addColumn('deleted', 'datetime', [ $table->addColumn('deleted', 'datetime', [
'default' => null, 'default' => null,
'null' => true, 'null' => true,
]); ]);
$table->update(); $table->update();
$table = $this->table('product_categories'); $table = $this->table('product_categories');
$table->addColumn('deleted', 'datetime', [ $table->addColumn('deleted', 'datetime', [
'default' => null, 'default' => null,
'null' => true, 'null' => true,
]); ]);
$table->update(); $table->update();
$table = $this->table('product_catalogs'); $table = $this->table('product_catalogs');
$table->addColumn('deleted', 'datetime', [ $table->addColumn('deleted', 'datetime', [
'default' => null, 'default' => null,
'null' => true, 'null' => true,
]); ]);
$table->update(); $table->update();
$table = $this->table('external_product_catalogs_product_catalogs'); $table = $this->table('external_product_catalogs_product_catalogs');
$table->addColumn('deleted', 'datetime', [ $table->addColumn('deleted', 'datetime', [
'default' => null, 'default' => null,
'null' => true, 'null' => true,
]); ]);
$table->update(); $table->update();
$table = $this->table('product_attributes');
$table->addColumn('deleted', 'datetime', [
'default' => null,
'null' => true,
]);
$table->update();
}
$table = $this->table('product_attributes');
$table->addColumn('deleted', 'datetime', [
'default' => null,
'null' => true,
]);
$table->update();
}
} }
@@ -3,60 +3,60 @@ declare(strict_types=1);
use Migrations\BaseMigration; use Migrations\BaseMigration;
class CreateProductSkus extends BaseMigration class CreateProductSkus extends BaseMigration {
{
/** /**
* Change Method. * Change Method.
* *
* More information on this method is available here: * More information on this method is available here:
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{ $table = $this->table('product_skus', ['id' => false, 'primary_key' => ['id']]);
$table = $this->table('product_skus', ['id' => false, 'primary_key' => ['id']]); $table->addColumn('id', 'uuid', [
$table->addColumn('id', 'uuid', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('product_id', 'uuid', [
$table->addColumn('product_id', 'uuid', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('sku', 'string', [
$table->addColumn('sku', 'string', [ 'default' => null,
'default' => null, 'limit' => 255,
'limit' => 255, 'null' => false,
'null' => false, ]);
]); $table->addColumn('barcode', 'string', [
$table->addColumn('barcode', 'string', [ 'default' => null,
'default' => null, 'limit' => 255,
'limit' => 255, 'null' => true,
'null' => true, ]);
]); $table->addColumn('price', 'decimal', [
$table->addColumn('price', 'decimal', [ 'default' => null,
'default' => null, 'precision' => 15,
'precision' => 15, 'scale' => 6,
'scale' => 6, 'null' => true,
'null' => true, ]);
]); $table->addColumn('cost', 'decimal', [
$table->addColumn('cost', 'decimal', [ 'default' => null,
'default' => null, 'precision' => 15,
'precision' => 15, 'scale' => 6,
'scale' => 6, 'null' => true,
'null' => true, ]);
]); $table->addColumn('created', 'datetime', [
$table->addColumn('created', 'datetime', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('modified', 'datetime', [
$table->addColumn('modified', 'datetime', [ 'default' => null,
'default' => null, 'null' => true,
'null' => true, ]);
]); $table->addColumn('deleted', 'datetime', [
$table->addColumn('deleted', 'datetime', [ 'default' => null,
'default' => null, 'null' => true,
'null' => true, ]);
]); $table->create();
$table->create(); }
}
} }
@@ -3,51 +3,50 @@ declare(strict_types=1);
use Migrations\AbstractMigration; use Migrations\AbstractMigration;
class CreateProductCategoryVariants extends AbstractMigration class CreateProductCategoryVariants extends AbstractMigration {
{
/** /**
* Change Method. * Change Method.
* *
* More information on this method is available here: * More information on this method is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{ $table = $this->table('product_category_variants', ['id' => false, 'primary_key' => ['id']]);
$table = $this->table('product_category_variants', ['id' => false, 'primary_key' => ['id']]); $table->addColumn('id', 'uuid', [
$table->addColumn('id', 'uuid', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('name', 'string', [
$table->addColumn('name', 'string', [ 'default' => null,
'default' => null, 'limit' => 255,
'limit' => 255, 'null' => false,
'null' => false, ]);
]); $table->addColumn('product_category_id', 'uuid', [
$table->addColumn('product_category_id', 'uuid', [ 'default' => null,
'default' => null, 'null' => true,
'null' => true, ]);
]); $table->addColumn('product_id', 'uuid', [
$table->addColumn('product_id', 'uuid', [ 'default' => null,
'default' => null, 'null' => true,
'null' => true, ]);
]); $table->addColumn('enabled', 'boolean', [
$table->addColumn('enabled', 'boolean', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addIndex([
$table->addIndex([ 'product_category_id',
'product_category_id', ], [
], [ 'name' => 'VARIANTS_BY_PRODUCT_CATEGORY_ID',
'name' => 'VARIANTS_BY_PRODUCT_CATEGORY_ID', 'unique' => false,
'unique' => false, ]);
]); $table->addIndex([
$table->addIndex([ 'product_id',
'product_id', ], [
], [ 'name' => 'CATEGORY_VARIANTS_BY_PRODUCT_ID',
'name' => 'CATEGORY_VARIANTS_BY_PRODUCT_ID', 'unique' => false,
'unique' => false, ]);
]);
// $table->addIndex([ // $table->addIndex([
// 'name', // 'name',
// 'product_category_id', // 'product_category_id',
@@ -56,6 +55,7 @@ class CreateProductCategoryVariants extends AbstractMigration
// 'name' => 'VARIANTS_BY_NAME_AND_PRODUCT_CATEGORY_ID_AND_PRODUCT_ID_UNIQUE', // 'name' => 'VARIANTS_BY_NAME_AND_PRODUCT_CATEGORY_ID_AND_PRODUCT_ID_UNIQUE',
// 'unique' => true, // 'unique' => true,
// ]); // ]);
$table->create(); $table->create();
} }
} }
@@ -3,54 +3,54 @@ declare(strict_types=1);
use Migrations\BaseMigration; use Migrations\BaseMigration;
class CreateProductCategoryVariantOptions extends BaseMigration class CreateProductCategoryVariantOptions extends BaseMigration {
{
/** /**
* Change Method. * Change Method.
* *
* More information on this method is available here: * More information on this method is available here:
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{ $table = $this->table('product_category_variant_options', ['id' => false, 'primary_key' => ['id']]);
$table = $this->table('product_category_variant_options', ['id' => false, 'primary_key' => ['id']]); $table->addColumn('id', 'uuid', [
$table->addColumn('id', 'uuid', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('product_category_variant_id', 'uuid', [
$table->addColumn('product_category_variant_id', 'uuid', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('variant_value', 'string', [
$table->addColumn('variant_value', 'string', [ 'default' => null,
'default' => null, 'limit' => 255,
'limit' => 255, 'null' => false,
'null' => false, ]);
]); $table->addColumn('variant_label', 'string', [
$table->addColumn('variant_label', 'string', [ 'default' => null,
'default' => null, 'limit' => 255,
'limit' => 255, 'null' => true,
'null' => true, ]);
]); $table->addColumn('created', 'datetime', [
$table->addColumn('created', 'datetime', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('modified', 'datetime', [
$table->addColumn('modified', 'datetime', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('deleted', 'datetime', [
$table->addColumn('deleted', 'datetime', [ 'default' => null,
'default' => null, 'null' => true,
'null' => true, ]);
]); $table->addColumn('enabled', 'boolean', [
$table->addColumn('enabled', 'boolean', [ 'default' => true,
'default' => true, 'null' => false,
'null' => false, ]);
]);
// $table->addForeignKey('product_category_variant_id', 'product_category_variants'); // @TODO why cant this be included??? breaks tests on tearDown // $table->addForeignKey('product_category_variant_id', 'product_category_variants'); // @TODO why cant this be included??? breaks tests on tearDown
$table->create(); $table->create();
} }
} }
@@ -3,23 +3,23 @@ declare(strict_types=1);
use Migrations\BaseMigration; use Migrations\BaseMigration;
class AddDefaultProductTypeIdToProductCategories extends BaseMigration class AddDefaultProductTypeIdToProductCategories extends BaseMigration {
{
/** /**
* Change Method. * Change Method.
* *
* More information on this method is available here: * More information on this method is available here:
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{ $table = $this->table('product_categories');
$table = $this->table('product_categories'); $table->addColumn('default_product_type_id', 'integer', [
$table->addColumn('default_product_type_id', 'integer', [ 'default' => null,
'default' => null, 'limit' => 11,
'limit' => 11, 'null' => true,
'null' => true, ]);
]); $table->update();
$table->update(); }
}
} }
@@ -3,9 +3,9 @@ declare(strict_types=1);
use Migrations\BaseMigration; use Migrations\BaseMigration;
class CreateProductPhotos extends BaseMigration class CreateProductPhotos extends BaseMigration {
{
/** /**
* Change Method. * Change Method.
* *
* More information on this method is available here: * More information on this method is available here:
@@ -13,75 +13,75 @@ class CreateProductPhotos extends BaseMigration
* *
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{ $table = $this->table('product_photos', ['id' => false, 'primary_key' => ['id']]);
$table = $this->table('product_photos', ['id' => false, 'primary_key' => ['id']]); $table->addColumn('id', 'uuid', [
$table->addColumn('id', 'uuid', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('product_id', 'uuid', [
$table->addColumn('product_id', 'uuid', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('product_sku_id', 'uuid', [
$table->addColumn('product_sku_id', 'uuid', [ 'default' => null,
'default' => null, 'null' => true,
'null' => true, ]);
]);
$table->addColumn('photo_dir', 'text', [ $table->addColumn('photo_dir', 'text', [
'default' => null, 'default' => null,
'length' => 255, 'length' => 255,
'null' => false, 'null' => false,
]); ]);
$table->addColumn('photo_filename', 'string', [ $table->addColumn('photo_filename', 'string', [
'default' => null, 'default' => null,
'length' => 255, 'length' => 255,
'null' => false, 'null' => false,
]); ]);
$table->addColumn('primary_photo', 'boolean', [ $table->addColumn('primary_photo', 'boolean', [
'default' => false, 'default' => false,
'null' => false, 'null' => false,
]); ]);
$table->addColumn('photo_position', 'integer', [ $table->addColumn('photo_position', 'integer', [
'default' => 100, 'default' => 100,
'limit' => 11, 'limit' => 11,
'null' => false, 'null' => false,
]); ]);
$table->addColumn('enabled', 'boolean', [ $table->addColumn('enabled', 'boolean', [
'default' => false, 'default' => false,
'null' => false, 'null' => false,
]); ]);
$table->addColumn('created', 'datetime', [ $table->addColumn('created', 'datetime', [
'default' => null, 'default' => null,
'null' => false, 'null' => false,
]); ]);
$table->addColumn('modified', 'datetime', [ $table->addColumn('modified', 'datetime', [
'default' => null, 'default' => null,
'null' => true, 'null' => true,
]); ]);
$table->addColumn('deleted', 'datetime', [ $table->addColumn('deleted', 'datetime', [
'default' => null, 'default' => null,
'null' => true, 'null' => true,
]); ]);
$table->addIndex([ $table->addIndex([
'product_id', 'product_id',
], [ ], [
'name' => 'PRODUCT_PHOTOS_BY_PRODUCT_ID', 'name' => 'PRODUCT_PHOTOS_BY_PRODUCT_ID',
'unique' => false, 'unique' => false,
]); ]);
$table->addIndex([ $table->addIndex([
'product_sku_id', 'product_sku_id',
], [ ], [
'name' => 'PRODUCT_PHOTOS_BY_PRODUCT_SKU_ID', 'name' => 'PRODUCT_PHOTOS_BY_PRODUCT_SKU_ID',
'unique' => false, 'unique' => false,
]); ]);
$table->create();
}
$table->create();
}
} }
@@ -3,9 +3,9 @@ declare(strict_types=1);
use Migrations\BaseMigration; use Migrations\BaseMigration;
class CreateProductSkuVariantValues extends BaseMigration class CreateProductSkuVariantValues extends BaseMigration {
{
/** /**
* Change Method. * Change Method.
* *
* More information on this method is available here: * More information on this method is available here:
@@ -13,25 +13,25 @@ class CreateProductSkuVariantValues extends BaseMigration
* *
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{ $table = $this->table('product_sku_variant_values', ['id' => false, 'primary_key' => ['id']]);
$table = $this->table('product_sku_variant_values', ['id' => false, 'primary_key' => ['id']]); $table->addColumn('id', 'uuid', [
$table->addColumn('id', 'uuid', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('product_sku_id', 'uuid', [
$table->addColumn('product_sku_id', 'uuid', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('product_variant_id', 'uuid', [
$table->addColumn('product_variant_id', 'uuid', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('product_category_variant_option_id', 'uuid', [
$table->addColumn('product_category_variant_option_id', 'uuid', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->create();
$table->create(); }
}
} }
@@ -3,9 +3,9 @@ declare(strict_types=1);
use Migrations\BaseMigration; use Migrations\BaseMigration;
class CreateProductVariants extends BaseMigration class CreateProductVariants extends BaseMigration {
{
/** /**
* Change Method. * Change Method.
* *
* More information on this method is available here: * More information on this method is available here:
@@ -13,42 +13,41 @@ class CreateProductVariants extends BaseMigration
* *
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{ $table = $this->table('product_variants', ['id' => false, 'primary_key' => ['id']]);
$table = $this->table('product_variants', ['id' => false, 'primary_key' => ['id']]); $table->addColumn('id', 'uuid', [
$table->addColumn('id', 'uuid', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('name', 'string', [
$table->addColumn('name', 'string', [ 'default' => null,
'default' => null, 'limit' => 255,
'limit' => 255, 'null' => false,
'null' => false, ]);
]); $table->addColumn('product_category_variant_id', 'uuid', [
$table->addColumn('product_category_variant_id', 'uuid', [ 'default' => null,
'default' => null, 'null' => true,
'null' => true, ]);
]); $table->addColumn('product_id', 'uuid', [
$table->addColumn('product_id', 'uuid', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addColumn('enabled', 'boolean', [
$table->addColumn('enabled', 'boolean', [ 'default' => null,
'default' => null, 'null' => false,
'null' => false, ]);
]); $table->addIndex([
$table->addIndex([ 'product_category_variant_id',
'product_category_variant_id', ], [
], [ 'name' => 'VARIANTS_BY_PARENT_PRODUCT_CATEGORY_VARIANT_ID',
'name' => 'VARIANTS_BY_PARENT_PRODUCT_CATEGORY_VARIANT_ID', 'unique' => false,
'unique' => false, ]);
]); $table->addIndex([
$table->addIndex([ 'product_id',
'product_id', ], [
], [ 'name' => 'VARIANTS_BY_PRODUCT_ID',
'name' => 'VARIANTS_BY_PRODUCT_ID', 'unique' => false,
'unique' => false, ]);
]);
// $table->addIndex([ // $table->addIndex([
// 'name', // 'name',
@@ -57,6 +56,7 @@ class CreateProductVariants extends BaseMigration
// 'name' => 'VARIANTS_BY_NAME_AND_PRODUCT_CATEGORY_ID_UNIQUE', // 'name' => 'VARIANTS_BY_NAME_AND_PRODUCT_CATEGORY_ID_UNIQUE',
// 'unique' => true, // 'unique' => true,
// ]); // ]);
$table->create(); $table->create();
} }
} }
@@ -3,23 +3,23 @@ declare(strict_types=1);
use Migrations\BaseMigration; use Migrations\BaseMigration;
class AddDefaultSkuToProductSkus extends BaseMigration class AddDefaultSkuToProductSkus extends BaseMigration {
{
/** /**
* Change Method. * Change Method.
* *
* More information on this method is available here: * More information on this method is available here:
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{ $table = $this->table('product_skus');
$table = $this->table('product_skus'); $table->addColumn('default_sku', 'boolean', [
$table->addColumn('default_sku', 'boolean', [ 'default' => false,
'default' => false, 'limit' => 11,
'limit' => 11, 'null' => false,
'null' => false, ]);
]); $table->update();
$table->update(); }
}
} }
@@ -3,9 +3,9 @@ declare(strict_types=1);
use Migrations\BaseMigration; use Migrations\BaseMigration;
class AddProductCategoryIdToProductPhotos extends BaseMigration class AddProductCategoryIdToProductPhotos extends BaseMigration {
{
/** /**
* Change Method. * Change Method.
* *
* More information on this method is available here: * More information on this method is available here:
@@ -13,17 +13,17 @@ class AddProductCategoryIdToProductPhotos extends BaseMigration
* *
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{ $table = $this->table('product_photos');
$table = $this->table('product_photos'); $table->addColumn('product_category_id', 'uuid', [
$table->addColumn('product_category_id', 'uuid', [ 'default' => null,
'default' => null, 'null' => true,
'null' => true, ]);
]); $table->addColumn('primary_category_photo', 'boolean', [
$table->addColumn('primary_category_photo', 'boolean', [ 'default' => false,
'default' => false, 'null' => false,
'null' => false, ]);
]); $table->update();
$table->update(); }
}
} }
@@ -3,23 +3,23 @@ declare(strict_types=1);
use Migrations\BaseMigration; use Migrations\BaseMigration;
class AddPrimarySkuPhotoToProductPhotos extends BaseMigration class AddPrimarySkuPhotoToProductPhotos extends BaseMigration {
{
/** /**
* Change Method. * Change Method.
* *
* More information on this method is available here: * More information on this method is available here:
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{ $table = $this->table('product_photos');
$table = $this->table('product_photos'); $table->addColumn('primary_sku_photo', 'boolean', [
$table->addColumn('primary_sku_photo', 'boolean', [ 'default' => false,
'default' => false, 'limit' => 11,
'limit' => 11, 'null' => false,
'null' => false, ]);
]); $table->update();
$table->update(); }
}
} }
@@ -3,51 +3,50 @@ declare(strict_types=1);
use Migrations\BaseMigration; use Migrations\BaseMigration;
class AllowProductIdToBeNullInProductPhotos extends BaseMigration class AllowProductIdToBeNullInProductPhotos extends BaseMigration {
{
/**
* Change Method.
*
* More information on this method is available here:
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
* @return void
*/
public function up(): void
{
$table = $this->table('product_photos');
$table->changeColumn('product_id', 'uuid', [
'default' => null,
'limit' => 11,
'null' => true,
]);
$table->changeColumn('product_category_id', 'uuid', [
'default' => null,
'limit' => 11,
'null' => false,
]);
$table->update();
}
/** /**
* Change Method. * Change Method.
* *
* More information on this method is available here: * More information on this method is available here:
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function down(): void public function up(): void {
{ $table = $this->table('product_photos');
$table = $this->table('product_photos'); $table->changeColumn('product_id', 'uuid', [
$table->changeColumn('product_id', 'uuid', [ 'default' => null,
'default' => null, 'limit' => 11,
'limit' => 11, 'null' => true,
'null' => false, ]);
]); $table->changeColumn('product_category_id', 'uuid', [
$table->changeColumn('product_category_id', 'uuid', [ 'default' => null,
'default' => null, 'limit' => 11,
'limit' => 11, 'null' => false,
'null' => true, ]);
]); $table->update();
$table->update(); }
}
/**
* Change Method.
*
* More information on this method is available here:
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
* @return void
*/
public function down(): void {
$table = $this->table('product_photos');
$table->changeColumn('product_id', 'uuid', [
'default' => null,
'limit' => 11,
'null' => false,
]);
$table->changeColumn('product_category_id', 'uuid', [
'default' => null,
'limit' => 11,
'null' => true,
]);
$table->update();
}
} }
@@ -3,23 +3,23 @@ declare(strict_types=1);
use Migrations\BaseMigration; use Migrations\BaseMigration;
class AddIsSystemToProductCategoryVariants extends BaseMigration class AddIsSystemToProductCategoryVariants extends BaseMigration {
{
/** /**
* Change Method. * Change Method.
* *
* More information on this method is available here: * More information on this method is available here:
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{ $table = $this->table('product_category_variants');
$table = $this->table('product_category_variants'); $table->addColumn('is_system_variant', 'boolean', [
$table->addColumn('is_system_variant', 'boolean', [ 'default' => false,
'default' => false, 'limit' => 11,
'limit' => 11, 'null' => false,
'null' => false, ]);
]); $table->update();
$table->update(); }
}
} }
@@ -3,14 +3,15 @@ declare(strict_types=1);
namespace Seeds; namespace Seeds;
use Cake\Utility\Text;
use Migrations\BaseSeed; use Migrations\BaseSeed;
/** /**
* CreateSystemCategoryVariants seed. * CreateSystemCategoryVariants seed.
*/ */
class CreateSystemCategoryVariantsSeed extends BaseSeed class CreateSystemCategoryVariantsSeed extends BaseSeed {
{
/** /**
* Run Method. * Run Method.
* *
* Write your database seeder using this method. * Write your database seeder using this method.
@@ -20,36 +21,36 @@ class CreateSystemCategoryVariantsSeed extends BaseSeed
* *
* @return void * @return void
*/ */
public function run(): void public function run(): void {
{ $data = [
$data = [ [
[ 'id' => Text::uuid(),
'id' => \Cake\Utility\Text::uuid(), 'name' => 'Subscription Length',
'name' => 'Subscription Length', 'product_category_id' => null,
'product_category_id' => null, 'enabled' => true,
'enabled' => true, 'is_system_variant' => true,
'is_system_variant' => true, ],
], [
[ 'id' => Text::uuid(),
'id' => \Cake\Utility\Text::uuid(), 'name' => 'Subscription Length Units',
'name' => 'Subscription Length Units', 'product_category_id' => null,
'product_category_id' => null, 'enabled' => true,
'enabled' => true, 'is_system_variant' => true,
'is_system_variant' => true, ],
], ];
]; $table = $this->table('product_category_variants');
$table = $this->table('product_category_variants'); $toInsert = [];
$toInsert = []; foreach ($data as $singleRecordToInsert) {
foreach ($data as $singleRecordToInsert) { $stmt = $this->query('SELECT * FROM product_category_variants WHERE name="' . $singleRecordToInsert['name'] . '" AND product_category_id IS NULL;'); // returns PDOStatement
$stmt = $this->query('SELECT * FROM product_category_variants WHERE name="' . $singleRecordToInsert['name'] . '" AND product_category_id IS NULL;'); // returns PDOStatement $rows = $stmt->fetchAll(); // returns the result as an array
$rows = $stmt->fetchAll(); // returns the result as an array if ($rows) {
if ($rows) { continue;
continue; }
} $toInsert[] = $singleRecordToInsert;
$toInsert[] = $singleRecordToInsert; }
} if ($toInsert) {
if ($toInsert) { $table->insert($data)->save();
$table->insert($data)->save(); }
} }
}
} }
+12 -12
View File
@@ -4,10 +4,10 @@
return [ return [
'CakeProducts' => [ 'CakeProducts' => [
'photos' => [ 'photos' => [
'directory' => WWW_ROOT . 'images' . DS . 'products' . DS, 'directory' => WWW_ROOT . 'images' . DS . 'products' . DS,
], ],
/** /**
* internal CakeProducts settings - used in the source of truth/internal only system. * internal CakeProducts settings - used in the source of truth/internal only system.
* Can optionally manage external catalogs * Can optionally manage external catalogs
* *
@@ -15,17 +15,17 @@ return [
* which will receive changes to the catalogs and optionally allow for external API access. * which will receive changes to the catalogs and optionally allow for external API access.
* Will have no effect if true but no external catalogs have been added or none are enabled * Will have no effect if true but no external catalogs have been added or none are enabled
*/ */
'internal' => [ 'internal' => [
'enabled' => true, 'enabled' => true,
/** /**
* syncExternally defaults to false - product catalogs can have 1 or more external catalogs linked to them * syncExternally defaults to false - product catalogs can have 1 or more external catalogs linked to them
* which will receive changes to the catalogs and optionally allow for external API access. * which will receive changes to the catalogs and optionally allow for external API access.
* Will have no effect if true but no external catalogs have been added or none are enabled * Will have no effect if true but no external catalogs have been added or none are enabled
*/ */
'syncExternally' => false, 'syncExternally' => false,
], ],
'external' => [ // product catalog settings for external use (as an API server to power an ecommerce site for example) 'external' => [ // product catalog settings for external use (as an API server to power an ecommerce site for example)
'enabled' => false, 'enabled' => false,
], ],
], ],
]; ];
+21
View File
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<ruleset name="plugin">
<arg value="nps"/>
<file>src/</file>
<file>config/</file>
<file>tests/</file>
<exclude-pattern>/tests/test_files/</exclude-pattern>
<exclude-pattern>/tests/test_app/</exclude-pattern>
<rule ref="vendor/fig-r/psr2r-sniffer/PSR2R/ruleset.xml"/>
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
<exclude-pattern>*/config/Migrations/*</exclude-pattern>
</rule>
<rule ref="PhpCollective.Classes.ClassFileName.NoMatch">
<exclude-pattern>*/config/Migrations/*</exclude-pattern>
</rule>
</ruleset>
+34 -38
View File
@@ -13,9 +13,9 @@ use Cake\Routing\RouteBuilder;
/** /**
* Plugin for CakeProducts * Plugin for CakeProducts
*/ */
class CakeProductsPlugin extends BasePlugin class CakeProductsPlugin extends BasePlugin {
{
/** /**
* Load all the plugin configuration and bootstrap logic. * Load all the plugin configuration and bootstrap logic.
* *
* The host application is provided as an argument. This allows you to load * 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 * @param \Cake\Core\PluginApplicationInterface $app The host application
* @return void * @return void
*/ */
public function bootstrap(PluginApplicationInterface $app): void public function bootstrap(PluginApplicationInterface $app): void {
{ }
}
/** /**
* Add routes for the plugin. * Add routes for the plugin.
* *
* If your plugin has many routes and you would like to isolate them into a separate file, * 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. * @param \Cake\Routing\RouteBuilder $routes The route builder to update.
* @return void * @return void
*/ */
public function routes(RouteBuilder $routes): void public function routes(RouteBuilder $routes): void {
{ $routes->plugin(
$routes->plugin( 'CakeProducts',
'CakeProducts', ['path' => '/cake-products'],
['path' => '/cake-products'], function (RouteBuilder $builder) {
function (RouteBuilder $builder) { // Add custom routes here
// Add custom routes here
$builder->fallbacks(); $builder->fallbacks();
} },
); );
parent::routes($routes); parent::routes($routes);
} }
/** /**
* Add middleware for the plugin. * Add middleware for the plugin.
* *
* @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to update. * @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to update.
* @return \Cake\Http\MiddlewareQueue * @return \Cake\Http\MiddlewareQueue
*/ */
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue {
{ // Add your middlewares here
// Add your middlewares here
return $middlewareQueue; return $middlewareQueue;
} }
/** /**
* Add commands for the plugin. * Add commands for the plugin.
* *
* @param \Cake\Console\CommandCollection $commands The command collection to update. * @param \Cake\Console\CommandCollection $commands The command collection to update.
* @return \Cake\Console\CommandCollection * @return \Cake\Console\CommandCollection
*/ */
public function console(CommandCollection $commands): CommandCollection public function console(CommandCollection $commands): CommandCollection {
{ // Add your commands here
// Add your commands here
$commands = parent::console($commands); $commands = parent::console($commands);
return $commands; return $commands;
} }
/** /**
* Register application container services. * 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. * @param \Cake\Core\ContainerInterface $container The Container to update.
* @return void * @return void
* @link https://book.cakephp.org/4/en/development/dependency-injection.html#dependency-injection
*/ */
public function services(ContainerInterface $container): void public function services(ContainerInterface $container): void {
{ // Add your services here
// Add your services here }
}
} }
+1 -2
View File
@@ -5,6 +5,5 @@ namespace CakeProducts\Controller;
use App\Controller\AppController as BaseController; 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; namespace CakeProducts\Controller;
use Cake\Core\Configure;
use Cake\Log\Log; use Cake\Log\Log;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
/** /**
* ExternalProductCatalogs Controller * ExternalProductCatalogs Controller
* *
* @property \CakeProducts\Model\Table\ExternalProductCatalogsTable $ExternalProductCatalogs * @property \CakeProducts\Model\Table\ExternalProductCatalogsTable $ExternalProductCatalogs
*/ */
class ExternalProductCatalogsController extends AppController class ExternalProductCatalogsController extends AppController {
{
// use OverrideTableTrait; // use OverrideTableTrait;
/** /**
* @return void * @return void
*/ */
public function initialize(): void public function initialize(): void {
{ parent::initialize(); // TODO: Change the autogenerated stub
parent::initialize(); // TODO: Change the autogenerated stub
// $this->_defaultTable = 'CakeProducts.ExternalProductCatalogs'; // $this->_defaultTable = 'CakeProducts.ExternalProductCatalogs';
// $this->_tableConfigKey = 'CakeProducts.ExternalProductCatalogs.table'; // $this->_tableConfigKey = 'CakeProducts.ExternalProductCatalogs.table';
} }
/** /**
* Index method * Index method
* *
* @return \Cake\Http\Response|null|void Renders view * @return \Cake\Http\Response|null|void Renders view
*/ */
public function index() public function index() {
{ $query = $this->ExternalProductCatalogs->find()
$query = $this->ExternalProductCatalogs->find() ->contain(['ProductCatalogs']);
->contain(['ProductCatalogs']); $externalProductCatalogs = $this->paginate($query);
$externalProductCatalogs = $this->paginate($query);
$this->set(compact('externalProductCatalogs')); $this->set(compact('externalProductCatalogs'));
} }
/** /**
* View method * View method
* *
* @param string|null $id External Product Catalog id. * @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. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Renders view
*/ */
public function view($id = null) public function view($id = null) {
{ $externalProductCatalog = $this->ExternalProductCatalogs->get($id, contain: ['ProductCatalogs']);
$externalProductCatalog = $this->ExternalProductCatalogs->get($id, contain: ['ProductCatalogs']); $this->set(compact('externalProductCatalog'));
$this->set(compact('externalProductCatalog')); }
}
/** /**
* Add method * Add method
* *
* @return \Cake\Http\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() public function add() {
{ $externalProductCatalog = $this->ExternalProductCatalogs->newEmptyEntity();
$externalProductCatalog = $this->ExternalProductCatalogs->newEmptyEntity(); if ($this->request->is('post')) {
if ($this->request->is('post')) { $saveOptions = [
$saveOptions = [ 'associated' => [
'associated' => [ 'ExternalProductCatalogsProductCatalogs',
'ExternalProductCatalogsProductCatalogs', ],
], ];
]; $postData = $this->request->getData();
$postData = $this->request->getData(); Log::debug(print_r('$postData', true));
Log::debug(print_r('$postData', true)); Log::debug(print_r($postData, true));
Log::debug(print_r($postData, true)); $externalProductCatalog = $this->ExternalProductCatalogs->patchEntity($externalProductCatalog, $postData, $saveOptions);
$externalProductCatalog = $this->ExternalProductCatalogs->patchEntity($externalProductCatalog, $postData, $saveOptions); if ($this->ExternalProductCatalogs->save($externalProductCatalog, $saveOptions)) {
if ($this->ExternalProductCatalogs->save($externalProductCatalog, $saveOptions)) { $this->Flash->success(__('The external product catalog has been saved.'));
$this->Flash->success(__('The external product catalog has been saved.'));
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
} }
Log::debug(print_r('$externalProductCatalog->getErrors() next - failed /add', true)); Log::debug(print_r('$externalProductCatalog->getErrors() next - failed /add', true));
Log::debug(print_r($externalProductCatalog->getErrors(), true)); Log::debug(print_r($externalProductCatalog->getErrors(), true));
$this->Flash->error(__('The external product catalog could not be saved. Please, try again.')); $this->Flash->error(__('The external product catalog could not be saved. Please, try again.'));
} }
$productCatalogs = $this->ExternalProductCatalogs->ProductCatalogs->find('list', limit: 200)->all(); $productCatalogs = $this->ExternalProductCatalogs->ProductCatalogs->find('list', limit: 200)->all();
$this->set(compact('externalProductCatalog', 'productCatalogs')); $this->set(compact('externalProductCatalog', 'productCatalogs'));
} }
/** /**
* Edit method * Edit method
* *
* @param string|null $id External Product Catalog id. * @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. * @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) public function edit($id = null) {
{ $externalProductCatalog = $this->ExternalProductCatalogs->get($id, contain: []);
$externalProductCatalog = $this->ExternalProductCatalogs->get($id, contain: []); if ($this->request->is(['patch', 'post', 'put'])) {
if ($this->request->is(['patch', 'post', 'put'])) { $externalProductCatalog = $this->ExternalProductCatalogs->patchEntity($externalProductCatalog, $this->request->getData());
$externalProductCatalog = $this->ExternalProductCatalogs->patchEntity($externalProductCatalog, $this->request->getData()); if ($this->ExternalProductCatalogs->save($externalProductCatalog)) {
if ($this->ExternalProductCatalogs->save($externalProductCatalog)) { $this->Flash->success(__('The external product catalog has been saved.'));
$this->Flash->success(__('The external product catalog has been saved.'));
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
} }
Log::debug(print_r('$externalProductCatalog->getErrors() next - failed /edit', true)); Log::debug(print_r('$externalProductCatalog->getErrors() next - failed /edit', true));
Log::debug(print_r($externalProductCatalog->getErrors(), true)); Log::debug(print_r($externalProductCatalog->getErrors(), true));
$this->Flash->error(__('The external product catalog could not be saved. Please, try again.')); $this->Flash->error(__('The external product catalog could not be saved. Please, try again.'));
} }
$productCatalogs = $this->ExternalProductCatalogs->ProductCatalogs->find('list', limit: 200)->all(); $productCatalogs = $this->ExternalProductCatalogs->ProductCatalogs->find('list', limit: 200)->all();
$this->set(compact('externalProductCatalog', 'productCatalogs')); $this->set(compact('externalProductCatalog', 'productCatalogs'));
} }
/** /**
* Delete method * Delete method
* *
* @param string|null $id External Product Catalog id. * @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. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null Redirects to index.
*/ */
public function delete($id = null) public function delete($id = null) {
{ $this->request->allowMethod(['post', 'delete']);
$this->request->allowMethod(['post', 'delete']); $externalProductCatalog = $this->ExternalProductCatalogs->get($id);
$externalProductCatalog = $this->ExternalProductCatalogs->get($id); if ($this->ExternalProductCatalogs->delete($externalProductCatalog)) {
if ($this->ExternalProductCatalogs->delete($externalProductCatalog)) { $this->Flash->success(__('The external product catalog has been deleted.'));
$this->Flash->success(__('The external product catalog has been deleted.')); } else {
} else { $this->Flash->error(__('The external product catalog could not be deleted. Please, try again.'));
$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; namespace CakeProducts\Controller;
use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Http\Response;
use Cake\Log\Log; use Cake\Log\Log;
/** /**
* ExternalProductCatalogsProductCatalogs Controller * ExternalProductCatalogsProductCatalogs Controller
*
*/ */
class ExternalProductCatalogsProductCatalogsController extends AppController class ExternalProductCatalogsProductCatalogsController extends AppController {
{
/** /**
* Add method * 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() public function add() {
{ Log::debug('inside external product catalogs product catalogs controller add');
Log::debug('inside external product catalogs product catalogs controller add'); $productCatalogs = $this->ExternalProductCatalogsProductCatalogs->ProductCatalogs->find('list')->toArray();
$productCatalogs = $this->ExternalProductCatalogsProductCatalogs->ProductCatalogs->find('list')->toArray(); $this->set(compact('productCatalogs'));
$this->set(compact( 'productCatalogs')); }
}
/** /**
* Delete method * Delete method
* *
* @param string|null $id Customers Contact id. * @param string|null $id Customers Contact id.
* @return Response|null Redirects to index.
* @throws RecordNotFoundException When record not found. * @throws RecordNotFoundException When record not found.
* @return Response|null Redirects to index.
*/ */
public function delete($id = null) public function delete($id = null) {
{ $this->request->allowMethod(['post', 'delete']);
$this->request->allowMethod(['post', 'delete']); $externalProductCatalogProductCatalog = $this->ExternalProductCatalogsProductCatalogs->get($id);
$externalProductCatalogProductCatalog = $this->ExternalProductCatalogsProductCatalogs->get($id); if ($this->ExternalProductCatalogsProductCatalogs->delete($externalProductCatalogProductCatalog)) {
if ($this->ExternalProductCatalogsProductCatalogs->delete($externalProductCatalogProductCatalog)) { $this->Flash->success(__('The customers contact has been deleted.'));
$this->Flash->success(__('The customers contact has been deleted.')); } else {
} else { $this->Flash->error(__('The customers contact could not be deleted. Please, try again.'));
$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,
]));
}
} }
+71 -81
View File
@@ -4,126 +4,116 @@ declare(strict_types=1);
namespace CakeProducts\Controller; namespace CakeProducts\Controller;
use Cake\Core\Configure; use Cake\Core\Configure;
use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Http\Response;
use Cake\Log\Log; use Cake\Log\Log;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
use CakeProducts\Model\Table\ProductCatalogsTable;
/** /**
* ProductCatalogs Controller * ProductCatalogs Controller
* *
* @property ProductCatalogsTable $ProductCatalogs * @property \CakeProducts\Model\Table\ProductCatalogsTable $ProductCatalogs
*/ */
class ProductCatalogsController extends AppController class ProductCatalogsController extends AppController {
{
/** /**
* @return void * @return void
*/ */
public function initialize(): void public function initialize(): void {
{ parent::initialize(); // TODO: Change the autogenerated stub
parent::initialize(); // TODO: Change the autogenerated stub
// $this->_defaultTable = 'CakeProducts.ProductCatalogs'; // $this->_defaultTable = 'CakeProducts.ProductCatalogs';
// $this->_tableConfigKey = 'CakeProducts.ProductCatalogs.table'; // $this->_tableConfigKey = 'CakeProducts.ProductCatalogs.table';
} }
/** /**
* Index method * Index method
* *
* @return Response|null|void Renders view * @return \Cake\Http\Response|voidRenders|null view
*/ */
public function index() public function index() {
{ $query = $this->ProductCatalogs->find();
$query = $this->ProductCatalogs->find(); $productCatalogs = $this->paginate($query);
$productCatalogs = $this->paginate($query);
$this->set(compact('productCatalogs')); $this->set(compact('productCatalogs'));
} }
/** /**
* View method * View method
* *
* @param string|null $id Product Catalog id. * @param string|null $id Product Catalog id.
* @return Response|null|void Renders view
* @throws RecordNotFoundException When record not found. * @throws RecordNotFoundException When record not found.
* @return Response|null|void Renders view
*/ */
public function view($id = null) public function view($id = null) {
{ $contain = ['ProductCategories'];
$contain = ['ProductCategories']; if (Configure::read('CakeProducts.internal.syncExternally', false)) {
if (Configure::read('CakeProducts.internal.syncExternally', false)) { $contain[] = 'ExternalProductCatalogs';
$contain[] = 'ExternalProductCatalogs'; }
} $productCatalog = $this->ProductCatalogs->get($id, contain: $contain);
$productCatalog = $this->ProductCatalogs->get($id, contain: $contain); $this->set(compact('productCatalog'));
$this->set(compact('productCatalog')); }
}
/** /**
* Add method * 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() public function add() {
{ $productCatalogsTable = $this->ProductCatalogs;
$productCatalogsTable = $this->ProductCatalogs; $productCatalog = $productCatalogsTable->newEmptyEntity();
$productCatalog = $productCatalogsTable->newEmptyEntity(); if ($this->request->is('post')) {
if ($this->request->is('post')) { $productCatalog = $productCatalogsTable->patchEntity($productCatalog, $this->request->getData());
$productCatalog = $productCatalogsTable->patchEntity($productCatalog, $this->request->getData()); if ($productCatalogsTable->save($productCatalog)) {
if ($productCatalogsTable->save($productCatalog)) { $this->Flash->success(__('The product catalog has been saved.'));
$this->Flash->success(__('The product catalog has been saved.'));
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
} }
Log::debug('failed to save new product catalog errors next'); Log::debug('failed to save new product catalog errors next');
Log::debug(print_r('$productCatalog->getErrors()', true)); Log::debug(print_r('$productCatalog->getErrors()', true));
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->Flash->error(__('The product catalog could not be saved. Please, try again.'));
} }
$this->set(compact('productCatalog')); $this->set(compact('productCatalog'));
} }
/** /**
* Edit method * Edit method
* *
* @param string|null $id Product Catalog id. * @param string|null $id Product Catalog id.
* @return Response|null|void Redirects on successful edit, renders view otherwise.
* @throws RecordNotFoundException When record not found. * @throws RecordNotFoundException When record not found.
* @return Response|null|void Redirects on successful edit, renders view otherwise.
*/ */
public function edit($id = null) public function edit($id = null) {
{ $productCatalogsTable = $this->ProductCatalogs;
$productCatalogsTable = $this->ProductCatalogs; $productCatalog = $productCatalogsTable->get($id, contain: []);
$productCatalog = $productCatalogsTable->get($id, contain: []); if ($this->request->is(['patch', 'post', 'put'])) {
if ($this->request->is(['patch', 'post', 'put'])) { $productCatalog = $productCatalogsTable->patchEntity($productCatalog, $this->request->getData());
$productCatalog = $productCatalogsTable->patchEntity($productCatalog, $this->request->getData()); if ($productCatalogsTable->save($productCatalog)) {
if ($productCatalogsTable->save($productCatalog)) { $this->Flash->success(__('The product catalog has been saved.'));
$this->Flash->success(__('The product catalog has been saved.'));
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
} }
$this->Flash->error(__('The product catalog could not be saved. Please, try again.')); $this->Flash->error(__('The product catalog could not be saved. Please, try again.'));
} }
$this->set(compact('productCatalog')); $this->set(compact('productCatalog'));
} }
/** /**
* Delete method * Delete method
* *
* @param string|null $id Product Catalog id. * @param string|null $id Product Catalog id.
* @return Response|null Redirects to index.
* @throws RecordNotFoundException When record not found. * @throws RecordNotFoundException When record not found.
* @return Response|null Redirects to index.
*/ */
public function delete($id = null) public function delete($id = null) {
{ $this->request->allowMethod(['post', 'delete']);
$this->request->allowMethod(['post', 'delete']); $productCatalogsTable = $this->ProductCatalogs;
$productCatalogsTable = $this->ProductCatalogs; $productCatalog = $productCatalogsTable->get($id);
$productCatalog = $productCatalogsTable->get($id); if ($productCatalogsTable->delete($productCatalog)) {
if ($productCatalogsTable->delete($productCatalog)) { $this->Flash->success(__('The product catalog has been deleted.'));
$this->Flash->success(__('The product catalog has been deleted.')); } else {
} else { $this->Flash->error(__('The product catalog could not be deleted. Please, try again.'));
$this->Flash->error(__('The product catalog could not be deleted. Please, try again.')); }
}
return $this->redirect(['action' => 'index']);
}
return $this->redirect(['action' => 'index']);
}
} }
+105 -114
View File
@@ -3,10 +3,7 @@ declare(strict_types=1);
namespace CakeProducts\Controller; namespace CakeProducts\Controller;
use Cake\Core\Configure;
use Cake\Log\Log; use Cake\Log\Log;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
use Cake\Utility\Text; use Cake\Utility\Text;
/** /**
@@ -14,163 +11,157 @@ use Cake\Utility\Text;
* *
* @property \CakeProducts\Model\Table\ProductCategoriesTable $ProductCategories * @property \CakeProducts\Model\Table\ProductCategoriesTable $ProductCategories
*/ */
class ProductCategoriesController extends AppController class ProductCategoriesController extends AppController {
{
/** /**
* @return void * @return void
*/ */
public function initialize(): void public function initialize(): void {
{ parent::initialize(); // TODO: Change the autogenerated stub
parent::initialize(); // TODO: Change the autogenerated stub
// $this->_defaultTable = 'CakeProducts.ProductCategories'; // $this->_defaultTable = 'CakeProducts.ProductCategories';
// $this->_tableConfigKey = 'CakeProducts.ProductCategories.table'; // $this->_tableConfigKey = 'CakeProducts.ProductCategories.table';
} }
/** /**
* Index method * Index method
* *
* @return \Cake\Http\Response|null|void Renders view * @return \Cake\Http\Response|null|void Renders view
*/ */
public function index() public function index() {
{ $query = $this->ProductCategories->find()
$query = $this->ProductCategories->find() ->contain(['ProductCatalogs', 'ParentProductCategories']);
->contain(['ProductCatalogs', 'ParentProductCategories']); $productCategories = $this->paginate($query);
$productCategories = $this->paginate($query);
$this->set(compact('productCategories')); $this->set(compact('productCategories'));
} }
/** /**
* View method * View method
* *
* @param string|null $id Product Category id. * @param string|null $id Product Category id.
* @return \Cake\Http\Response|null|void Renders view
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Renders view
*/ */
public function view($id = null) public function view($id = null) {
{ $productCategory = $this->ProductCategories->get($id, contain: [
$productCategory = $this->ProductCategories->get($id, contain: [ 'ProductCatalogs',
'ProductCatalogs', 'ParentProductCategories',
'ParentProductCategories', 'ChildProductCategories',
'ChildProductCategories', 'ProductCategoryAttributes',
'ProductCategoryAttributes', 'ProductCategoryAttributes.ProductCategoryAttributeOptions',
'ProductCategoryAttributes.ProductCategoryAttributeOptions', 'PrimaryProductPhotos',
'PrimaryProductPhotos', ]);
]);
$productCategoryAttributes = $this->ProductCategories->ProductCategoryAttributes->getAllCategoryAttributesForCategoryId($productCategory->internal_id); $productCategoryAttributes = $this->ProductCategories->ProductCategoryAttributes->getAllCategoryAttributesForCategoryId($productCategory->internal_id);
$this->set(compact('productCategory', 'productCategoryAttributes')); $this->set(compact('productCategory', 'productCategoryAttributes'));
} }
/** /**
* Add method * Add method
* *
* @return \Cake\Http\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() public function add() {
{ $productCategoriesTable = $this->ProductCategories;
$productCategoriesTable = $this->ProductCategories; $productCategory = $productCategoriesTable->newEmptyEntity();
$productCategory = $productCategoriesTable->newEmptyEntity(); if ($this->request->is('post')) {
if ($this->request->is('post')) { $postData = $this->request->getData();
$postData = $this->request->getData(); $saveOptions = [
$saveOptions = [ 'associated' => [],
'associated' => [], ];
]; if ($this->request->getSession()->read('Auth.User.id')) {
if ($this->request->getSession()->read('Auth.User.id')) { $postData['created_by'] = $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']) {
if (!array_key_exists('internal_id', $postData) || !$postData['internal_id']) { $postData['internal_id'] = Text::uuid();
$postData['internal_id'] = Text::uuid(); }
} $productCategory = $productCategoriesTable->patchEntity($productCategory, $postData, $saveOptions);
$productCategory = $productCategoriesTable->patchEntity($productCategory, $postData, $saveOptions); if ($productCategory->getErrors()) {
if ($productCategory->getErrors()) { Log::debug(print_r('$productCategory->getErrors() next - failed to save from create new product category', true));
Log::debug(print_r('$productCategory->getErrors() next - failed to save from create new product category', true)); Log::debug(print_r($productCategory->getErrors(), true));
Log::debug(print_r($productCategory->getErrors(), true)); }
} if ($this->ProductCategories->save($productCategory, $saveOptions)) {
if ($this->ProductCategories->save($productCategory, $saveOptions)) { $this->Flash->success(__('The product category has been saved.'));
$this->Flash->success(__('The product category has been saved.'));
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
} }
$this->Flash->error(__('The product category could not be saved. Please, try again.')); $this->Flash->error(__('The product category could not be saved. Please, try again.'));
} }
$productCatalogs = $productCategoriesTable->ProductCatalogs->find('list', limit: 200)->all(); $productCatalogs = $productCategoriesTable->ProductCatalogs->find('list', limit: 200)->all();
$parentProductCategories = $productCategoriesTable->ParentProductCategories->find('treeList', limit: 200)->toArray(); $parentProductCategories = $productCategoriesTable->ParentProductCategories->find('treeList', limit: 200)->toArray();
$this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories')); $this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories'));
} }
/** /**
* Edit method * Edit method
* *
* @param string|null $id Product Category id. * @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. * @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) public function edit($id = null) {
{ $productCategoriesTable = $this->ProductCategories;
$productCategoriesTable = $this->ProductCategories; $productCategory = $productCategoriesTable->get($id, contain: []);
$productCategory = $productCategoriesTable->get($id, contain: []); if ($this->request->is(['patch', 'post', 'put'])) {
if ($this->request->is(['patch', 'post', 'put'])) { $postData = $this->request->getData();
$postData = $this->request->getData(); $productCategory = $productCategoriesTable->patchEntity($productCategory, $postData);
$productCategory = $productCategoriesTable->patchEntity($productCategory, $postData); if ($productCategoriesTable->save($productCategory)) {
if ($productCategoriesTable->save($productCategory)) { $this->Flash->success(__('The product category has been saved.'));
$this->Flash->success(__('The product category has been saved.'));
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
} }
$this->Flash->error(__('The product category could not be saved. Please, try again.')); $this->Flash->error(__('The product category could not be saved. Please, try again.'));
} }
$productCatalogs = $productCategoriesTable->ProductCatalogs->find('list', limit: 200)->all(); $productCatalogs = $productCategoriesTable->ProductCatalogs->find('list', limit: 200)->all();
$parentProductCategories = $productCategoriesTable->ParentProductCategories->find('list', limit: 200)->all(); $parentProductCategories = $productCategoriesTable->ParentProductCategories->find('list', limit: 200)->all();
$this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories')); $this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories'));
} }
/** /**
* Delete method * Delete method
* *
* @param string|null $id Product Category id. * @param string|null $id Product Category id.
* @return \Cake\Http\Response|null Redirects to index.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null Redirects to index.
*/ */
public function delete($id = null) public function delete($id = null) {
{ $this->request->allowMethod(['post', 'delete']);
$this->request->allowMethod(['post', 'delete']); $productCategoriesTable = $this->ProductCategories;
$productCategoriesTable = $this->ProductCategories;
$productCategory = $productCategoriesTable->get($id); $productCategory = $productCategoriesTable->get($id);
// $productCategoriesTable->behaviors()->get('Tree')->setConfig([ // $productCategoriesTable->behaviors()->get('Tree')->setConfig([
// 'scope' => [ // 'scope' => [
// 'product_catalog_id' => $productCategory->product_catalog_id, // 'product_catalog_id' => $productCategory->product_catalog_id,
// ], // ],
// ]); // ]);
if ($productCategoriesTable->delete($productCategory)) { if ($productCategoriesTable->delete($productCategory)) {
$this->Flash->success(__('The product category has been deleted.')); $this->Flash->success(__('The product category has been deleted.'));
} else { } else {
$this->Flash->error(__('The product category could not be deleted. Please, try again.')); $this->Flash->error(__('The product category could not be deleted. Please, try again.'));
} }
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
} }
/** /**
* @return \Cake\Http\Response|null|void Renders view * @return \Cake\Http\Response|null|void Renders view
*/ */
public function select() public function select() {
{ $productCategoriesTable = $this->ProductCategories;
$productCategoriesTable = $this->ProductCategories; $productCategoriesTable->behaviors()->get('Tree')->setConfig([
$productCategoriesTable->behaviors()->get('Tree')->setConfig([ 'scope' => [
'scope' => [ 'product_catalog_id' => $this->request->getQuery('product_catalog_id', -1),
'product_catalog_id' => $this->request->getQuery('product_catalog_id', -1), ],
], ]);
]); $productCategoriesQ = $this->request->getQuery('form', 'product_category') === 'product' ?
$productCategoriesQ = $this->request->getQuery('form', 'product_category') === 'product' ? $productCategoriesTable->find('treeList', keyPath: 'internal_id', valuePath: 'name') :
$productCategoriesTable->find('treeList', keyPath: 'internal_id', valuePath: 'name') : $productCategoriesTable->find('treeList');
$productCategoriesTable->find('treeList');
$productCategories = $productCategoriesQ $productCategories = $productCategoriesQ
->orderBy(['ProductCategories.name']) ->orderBy(['ProductCategories.name'])
->toArray(); ->toArray();
$this->set(compact('productCategories'));
}
$this->set(compact('productCategories'));
}
} }
@@ -3,60 +3,55 @@ declare(strict_types=1);
namespace CakeProducts\Controller; namespace CakeProducts\Controller;
use Cake\Core\Configure;
use Cake\Log\Log; use Cake\Log\Log;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
/** /**
* ProductCategoryAttributeOptions Controller * ProductCategoryAttributeOptions Controller
* *
* @property \CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable $ProductCategoryAttributeOptions * @property \CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable $ProductCategoryAttributeOptions
*/ */
class ProductCategoryAttributeOptionsController extends AppController class ProductCategoryAttributeOptionsController extends AppController {
{
/** /**
* @return void * @return void
*/ */
public function initialize(): void public function initialize(): void {
{ parent::initialize(); // TODO: Change the autogenerated stub
parent::initialize(); // TODO: Change the autogenerated stub
// $this->_defaultTable = 'CakeProducts.ProductCategoryAttributeOptions'; // $this->_defaultTable = 'CakeProducts.ProductCategoryAttributeOptions';
// $this->_tableConfigKey = 'CakeProducts.ProductCategoryAttributeOptions.table'; // $this->_tableConfigKey = 'CakeProducts.ProductCategoryAttributeOptions.table';
} }
/** /**
* Add method * Add method
* *
* @return \Cake\Http\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() public function add() {
{ Log::debug('inside product category attribute options controller add');
Log::debug('inside product category attribute options controller add');
$productCategoryAttributeOption = $this->ProductCategoryAttributeOptions->newEmptyEntity(); $productCategoryAttributeOption = $this->ProductCategoryAttributeOptions->newEmptyEntity();
$this->set(compact('productCategoryAttributeOption')); $this->set(compact('productCategoryAttributeOption'));
} }
/** /**
* Delete method * Delete method
* *
* @param string|null $id Product Category Attribute Option id. * @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. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null Redirects to index.
*/ */
public function delete($id = null) public function delete($id = null) {
{ $this->request->allowMethod(['post', 'delete']);
$this->request->allowMethod(['post', 'delete']); $productCategoryAttributeOptionsTable = $this->ProductCategoryAttributeOptions;
$productCategoryAttributeOptionsTable = $this->ProductCategoryAttributeOptions;
$productCategoryAttributeOption = $productCategoryAttributeOptionsTable->get($id); $productCategoryAttributeOption = $productCategoryAttributeOptionsTable->get($id);
if ($productCategoryAttributeOptionsTable->delete($productCategoryAttributeOption)) { if ($productCategoryAttributeOptionsTable->delete($productCategoryAttributeOption)) {
$this->Flash->success(__('The product category attribute option has been deleted.')); $this->Flash->success(__('The product category attribute option has been deleted.'));
} else { } else {
$this->Flash->error(__('The product category attribute option could not be deleted. Please, try again.')); $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; namespace CakeProducts\Controller;
use Cake\Core\Configure;
use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Http\Response;
use Cake\Log\Log; use Cake\Log\Log;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
use CakeProducts\Model\Enum\ProductCategoryAttributeTypeId;
use CakeProducts\Model\Table\ProductCategoryAttributesTable;
/** /**
* ProductCategoryAttributes Controller * ProductCategoryAttributes Controller
* *
* @property ProductCategoryAttributesTable $ProductCategoryAttributes * @property \CakeProducts\Model\Table\ProductCategoryAttributesTable $ProductCategoryAttributes
*/ */
class ProductCategoryAttributesController extends AppController class ProductCategoryAttributesController extends AppController {
{
/** /**
* @return void * @return void
*/ */
public function initialize(): void public function initialize(): void {
{ parent::initialize(); // TODO: Change the autogenerated stub
parent::initialize(); // TODO: Change the autogenerated stub
// $this->_defaultTable = 'CakeProducts.ProductCategoryAttributes'; // $this->_defaultTable = 'CakeProducts.ProductCategoryAttributes';
// $this->_tableConfigKey = 'CakeProducts.ProductCategoryAttributes.table'; // $this->_tableConfigKey = 'CakeProducts.ProductCategoryAttributes.table';
} }
/** /**
* Index method * Index method
* *
* @return Response|null|void Renders view * @return \Cake\Http\Response|voidRenders|null view
*/ */
public function index() public function index() {
{ $query = $this->ProductCategoryAttributes->find()
$query = $this->ProductCategoryAttributes->find() ->contain(['ProductCategories']);
->contain(['ProductCategories']); $productCategoryAttributes = $this->paginate($query);
$productCategoryAttributes = $this->paginate($query);
$this->set(compact('productCategoryAttributes')); $this->set(compact('productCategoryAttributes'));
} }
/** /**
* View method * View method
* *
* @param string|null $id Product Category Attribute id. * @param string|null $id Product Category Attribute id.
* @return Response|null|void Renders view
* @throws RecordNotFoundException When record not found. * @throws RecordNotFoundException When record not found.
* @return Response|null|void Renders view
*/ */
public function view($id = null) public function view($id = null) {
{ $productCategoryAttribute = $this->ProductCategoryAttributes->get($id, contain: [
$productCategoryAttribute = $this->ProductCategoryAttributes->get($id, contain: [ 'ProductCategories',
'ProductCategories', 'ProductCategoryAttributeOptions',
'ProductCategoryAttributeOptions', ]);
]);
$this->set(compact('productCategoryAttribute')); $this->set(compact('productCategoryAttribute'));
} }
/** /**
* Add method * 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() public function add() {
{ $productCategoryAttributesTable = $this->ProductCategoryAttributes;
$productCategoryAttributesTable = $this->ProductCategoryAttributes; $productCategoryAttribute = $productCategoryAttributesTable->newEmptyEntity();
$productCategoryAttribute = $productCategoryAttributesTable->newEmptyEntity(); if ($this->request->is('post')) {
if ($this->request->is('post')) { $postData = $this->request->getData();
$postData = $this->request->getData(); if ($this->request->getSession()->read('Auth.User.id')) {
if ($this->request->getSession()->read('Auth.User.id')) { $postData['created_by'] = $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)); Log::debug(print_r($postData, true));
Log::debug(print_r($postData, true)); $saveOptions = [
$saveOptions = [ 'associated' => [
'associated' => [ 'ProductCategoryAttributeOptions',
'ProductCategoryAttributeOptions' ],
], ];
]; $productCategoryAttribute = $productCategoryAttributesTable->patchEntity($productCategoryAttribute, $postData, $saveOptions);
$productCategoryAttribute = $productCategoryAttributesTable->patchEntity($productCategoryAttribute, $postData, $saveOptions); if ($productCategoryAttribute->getErrors()) {
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() next - failed to save from create new product category attribute', true)); Log::debug(print_r($productCategoryAttribute->getErrors(), true));
Log::debug(print_r($productCategoryAttribute->getErrors(), true)); }
} if ($productCategoryAttributesTable->save($productCategoryAttribute, $saveOptions)) {
if ($productCategoryAttributesTable->save($productCategoryAttribute, $saveOptions)) { $this->Flash->success(__('The product category attribute has been saved.'));
$this->Flash->success(__('The product category attribute has been saved.'));
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
} }
Log::debug('failed to save new product category attribute errors next'); 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));
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.')); $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(); $productCategories = $productCategoryAttributesTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all();
$this->set(compact('productCategoryAttribute', 'productCategories')); $this->set(compact('productCategoryAttribute', 'productCategories'));
} }
/** /**
* Edit method * Edit method
* *
* @param string|null $id Product Category Attribute id. * @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. * @throws RecordNotFoundException When record not found.
* @return Response|null|void Redirects on successful edit, renders view otherwise.
*/ */
public function edit($id = null) public function edit($id = null) {
{ $productCategoryAttributesTable = $this->ProductCategoryAttributes;
$productCategoryAttributesTable = $this->ProductCategoryAttributes; $productCategoryAttribute = $productCategoryAttributesTable->get($id, contain: ['ProductCategoryAttributeOptions']);
$productCategoryAttribute = $productCategoryAttributesTable->get($id, contain: ['ProductCategoryAttributeOptions']); if ($this->request->is(['patch', 'post', 'put'])) {
if ($this->request->is(['patch', 'post', 'put'])) { $postData = $this->request->getData();
$postData = $this->request->getData(); $saveOptions = [
$saveOptions = [ 'associated' => ['ProductCategoryAttributeOptions'],
'associated' => ['ProductCategoryAttributeOptions'], ];
]; Log::debug(print_r('$postData', true));
Log::debug(print_r('$postData', true)); Log::debug(print_r($postData, true));
Log::debug(print_r($postData, true));
// if ($this->request->getData('attribute_type_id') != ProductCategoryAttributeTypeId::Constrained) { // if ($this->request->getData('attribute_type_id') != ProductCategoryAttributeTypeId::Constrained) {
// $saveOptions['associated'] = []; // $saveOptions['associated'] = [];
// $postData['product_category_attribute_options'] = []; // $postData['product_category_attribute_options'] = [];
// } // }
Log::debug(print_r('$postData', true)); Log::debug(print_r('$postData', true));
Log::debug(print_r($postData, true)); Log::debug(print_r($postData, true));
$productCategoryAttribute = $productCategoryAttributesTable->patchEntity($productCategoryAttribute, $postData, $saveOptions); $productCategoryAttribute = $productCategoryAttributesTable->patchEntity($productCategoryAttribute, $postData, $saveOptions);
if ($productCategoryAttributesTable->save($productCategoryAttribute, $saveOptions)) { if ($productCategoryAttributesTable->save($productCategoryAttribute, $saveOptions)) {
$this->Flash->success(__('The product category attribute has been saved.')); $this->Flash->success(__('The product category attribute has been saved.'));
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
} }
Log::debug('failed to save product category attribute on edit errors next'); 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));
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.')); $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(); $productCategories = $productCategoryAttributesTable->ProductCategories->find('list', limit: 200, keyField: 'internal_id', valueField: 'name')->all();
$this->set(compact('productCategoryAttribute', 'productCategories')); $this->set(compact('productCategoryAttribute', 'productCategories'));
} }
/** /**
* Delete method * Delete method
* *
* @param string|null $id Product Category Attribute id. * @param string|null $id Product Category Attribute id.
* @return Response|null Redirects to index.
* @throws RecordNotFoundException When record not found. * @throws RecordNotFoundException When record not found.
* @return Response|null Redirects to index.
*/ */
public function delete($id = null) public function delete($id = null) {
{ $this->request->allowMethod(['post', 'delete']);
$this->request->allowMethod(['post', 'delete']);
$productCategoryAttributesTable = $this->ProductCategoryAttributes; $productCategoryAttributesTable = $this->ProductCategoryAttributes;
$productCategoryAttribute = $productCategoryAttributesTable->get($id); $productCategoryAttribute = $productCategoryAttributesTable->get($id);
if ($productCategoryAttributesTable->delete($productCategoryAttribute)) { if ($productCategoryAttributesTable->delete($productCategoryAttribute)) {
$this->Flash->success(__('The product category attribute has been deleted.')); $this->Flash->success(__('The product category attribute has been deleted.'));
} else { } else {
$this->Flash->error(__('The product category attribute could not be deleted. Please, try again.')); $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 * @return void
*/ */
public function form() public function form() {
{ $productCategories = $this->ProductCategoryAttributes->getAllCategoryAttributesForCategoryId($this->request->getQuery('product_category_id', '-1'));
$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; namespace CakeProducts\Controller;
use Cake\Core\Configure;
use Cake\Log\Log; use Cake\Log\Log;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
/** /**
* ProductCategoryVariants Controller * ProductCategoryVariants Controller
* *
* @property \App\Model\Table\ProductCategoryVariantsTable $ProductCategoryVariants * @property \App\Model\Table\ProductCategoryVariantsTable $ProductCategoryVariants
*/ */
class ProductCategoryVariantsController extends AppController class ProductCategoryVariantsController extends AppController {
{
/** /**
* @return void * @return void
*/ */
public function initialize(): void public function initialize(): void {
{ parent::initialize(); // TODO: Change the autogenerated stub
parent::initialize(); // TODO: Change the autogenerated stub
// $this->_defaultTable = 'CakeProducts.ProductCategoryVariants'; // $this->_defaultTable = 'CakeProducts.ProductCategoryVariants';
// $this->_tableConfigKey = 'CakeProducts.ProductCategoryVariants.table'; // $this->_tableConfigKey = 'CakeProducts.ProductCategoryVariants.table';
} }
/** /**
* Index method * Index method
* *
* @return \Cake\Http\Response|null|void Renders view * @return \Cake\Http\Response|null|void Renders view
*/ */
public function index() public function index() {
{ $query = $this->ProductCategoryVariants->find()
$query = $this->ProductCategoryVariants->find() ->contain(['ProductCategories', 'Products', 'ProductCategoryVariantOptions']);
->contain(['ProductCategories', 'Products', 'ProductCategoryVariantOptions']); $productCategoryVariants = $this->paginate($query);
$productCategoryVariants = $this->paginate($query);
$this->set(compact('productCategoryVariants')); $this->set(compact('productCategoryVariants'));
} }
/** /**
* View method * View method
* *
* @param string|null $id Product Category Variant id. * @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. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Renders view
*/ */
public function view($id = null) public function view($id = null) {
{ $productCategoryVariant = $this->ProductCategoryVariants->get($id, contain: [
$productCategoryVariant = $this->ProductCategoryVariants->get($id, contain: [ 'ProductCategories',
'ProductCategories', 'Products',
'Products', 'ProductCategoryVariantOptions',
'ProductCategoryVariantOptions', ]);
]); $this->set(compact('productCategoryVariant'));
$this->set(compact('productCategoryVariant')); }
}
/** /**
* Add method * Add method
* *
* @return \Cake\Http\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() public function add() {
{ $productCategoryVariantsTable = $this->ProductCategoryVariants;
$productCategoryVariantsTable = $this->ProductCategoryVariants;
$productCategoryVariant = $productCategoryVariantsTable->newEmptyEntity(); $productCategoryVariant = $productCategoryVariantsTable->newEmptyEntity();
if ($this->request->is('post')) { if ($this->request->is('post')) {
$postData = $this->request->getData(); $postData = $this->request->getData();
if ($this->request->getSession()->read('Auth.User.id')) { if ($this->request->getSession()->read('Auth.User.id')) {
$postData['created_by'] = $this->request->getSession()->read('Auth.User.id'); $postData['created_by'] = $this->request->getSession()->read('Auth.User.id');
} }
$saveOptions = [ $saveOptions = [
'associated' => [ 'associated' => [
'ProductCategoryVariantOptions' 'ProductCategoryVariantOptions',
], ],
]; ];
$productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $postData, $saveOptions); $productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $postData, $saveOptions);
if ($productCategoryVariantsTable->save($productCategoryVariant, $saveOptions)) { if ($productCategoryVariantsTable->save($productCategoryVariant, $saveOptions)) {
$this->Flash->success(__('The product category variant has been saved.')); $this->Flash->success(__('The product category variant has been saved.'));
return $this->redirect(['action' => 'index']); 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) failed to save in product category variants add');
Log::debug(print_r($productCategoryVariant->getErrors(), true)); Log::debug(print_r($productCategoryVariant->getErrors(), true));
$this->Flash->error(__('The product category variant could not be saved. Please, try again.')); $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(); $productCategories = $productCategoryVariantsTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all();
$products = $productCategoryVariantsTable->Products->find('list')->all(); $products = $productCategoryVariantsTable->Products->find('list')->all();
$this->set(compact('productCategoryVariant', 'productCategories', 'products')); $this->set(compact('productCategoryVariant', 'productCategories', 'products'));
} }
/** /**
* Edit method * Edit method
* *
* @param string|null $id Product Category Variant id. * @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. * @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) public function edit($id = null) {
{ $productCategoryVariantsTable = $this->ProductCategoryVariants;
$productCategoryVariantsTable = $this->ProductCategoryVariants; $productCategoryVariant = $productCategoryVariantsTable->get($id, contain: []);
$productCategoryVariant = $productCategoryVariantsTable->get($id, contain: []); if ($this->request->is(['patch', 'post', 'put'])) {
if ($this->request->is(['patch', 'post', 'put'])) { $postData = $this->request->getData();
$postData = $this->request->getData();
// if ($this->request->getSession()->read('Auth.User.id')) { // if ($this->request->getSession()->read('Auth.User.id')) {
// $postData['created_by'] = $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; $postData = $productCategoryVariant->is_system_variant ? ['product_category_variant_options' => $this->request->getData('product_category_variant_options')] : $postData;
$saveOptions = [ $saveOptions = [
'fields' => $productCategoryVariant->is_system_variant ? [ 'fields' => $productCategoryVariant->is_system_variant ? [
'product_category_variant_options', 'product_category_variant_options',
] : [ ] : [
'name', 'name',
'product_category_id', 'product_category_id',
'enabled', 'enabled',
'product_category_variant_options', 'product_category_variant_options',
], ],
'associated' => [ 'associated' => [
'ProductCategoryVariantOptions' 'ProductCategoryVariantOptions',
], ],
]; ];
$productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $postData, $saveOptions); $productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $postData, $saveOptions);
// dd($postData); // dd($postData);
if ($productCategoryVariantsTable->save($productCategoryVariant, $saveOptions)) { if ($productCategoryVariantsTable->save($productCategoryVariant, $saveOptions)) {
$this->Flash->success(__('The product category variant has been saved.')); $this->Flash->success(__('The product category variant has been saved.'));
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
} }
// dd($productCategoryVariant->getErrors()); // dd($productCategoryVariant->getErrors());
$this->Flash->error(__('The product category variant could not be saved. Please, try again.')); $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(); $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() : []; $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->set(compact('productCategoryVariant', 'productCategories', 'products'));
} }
/** /**
* Delete method * Delete method
* *
* @param string|null $id Product Category Variant id. * @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. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null Redirects to index.
*/ */
public function delete($id = null) public function delete($id = null) {
{ $this->request->allowMethod(['post', 'delete']);
$this->request->allowMethod(['post', 'delete']); $productCategoryVariantsTable = $this->ProductCategoryVariants;
$productCategoryVariantsTable = $this->ProductCategoryVariants;
$productCategoryVariant = $productCategoryVariantsTable->get($id); $productCategoryVariant = $productCategoryVariantsTable->get($id);
if ($productCategoryVariantsTable->delete($productCategoryVariant)) { if ($productCategoryVariantsTable->delete($productCategoryVariant)) {
$this->Flash->success(__('The product category variant has been deleted.')); $this->Flash->success(__('The product category variant has been deleted.'));
} else { } else {
$this->Flash->error(__('The product category variant could not be deleted. Please, try again.')); $this->Flash->error(__('The product category variant could not be deleted. Please, try again.'));
} }
return $this->redirect(['action' => 'index']);
}
return $this->redirect(['action' => 'index']);
}
} }
+144 -152
View File
@@ -6,209 +6,201 @@ namespace CakeProducts\Controller;
use Cake\Core\Configure; use Cake\Core\Configure;
use Cake\Datasource\Exception\RecordNotFoundException; use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Http\Exception\ForbiddenException; use Cake\Http\Exception\ForbiddenException;
use Cake\Http\Response;
use Cake\Utility\Text; use Cake\Utility\Text;
use CakeProducts\Model\Table\ProductPhotosTable;
use Psr\Http\Message\UploadedFileInterface;
/** /**
* ProductPhotos Controller * ProductPhotos Controller
* *
* @property ProductPhotosTable $ProductPhotos * @property \CakeProducts\Model\Table\ProductPhotosTable $ProductPhotos
*/ */
class ProductPhotosController extends AppController class ProductPhotosController extends AppController {
{
/** /**
* Index method * Index method
* *
* @return Response|null|void Renders view * @return \Cake\Http\Response|null|void Renders view
*/ */
public function index() public function index() {
{ $query = $this->ProductPhotos->find()
$query = $this->ProductPhotos->find() ->contain(['Products', 'ProductSkus', 'ProductCategories']);
->contain(['Products', 'ProductSkus', 'ProductCategories']); $productPhotos = $this->paginate($query);
$productPhotos = $this->paginate($query);
$this->set(compact('productPhotos')); $this->set(compact('productPhotos'));
} }
/** /**
* View method * View method
* *
* @param string|null $id Product Photo id. * @param string|null $id Product Photo id.
* @return Response|null|void Renders view
* @throws RecordNotFoundException When record not found. * @throws RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Renders view
*/ */
public function view($id = null) public function view($id = null) {
{ $productPhoto = $this->ProductPhotos->get($id, contain: ['Products', 'ProductSkus', 'ProductCategories']);
$productPhoto = $this->ProductPhotos->get($id, contain: ['Products', 'ProductSkus', 'ProductCategories']); $this->set(compact('productPhoto'));
$this->set(compact('productPhoto')); }
}
/** /**
* Add method * 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() public function add() {
{ $productPhotosTable = $this->ProductPhotos;
$productPhotosTable = $this->ProductPhotos; $productPhoto = $productPhotosTable->newEmptyEntity();
$productPhoto = $productPhotosTable->newEmptyEntity(); if ($this->request->is('post')) {
if ($this->request->is('post')) { if (!$this->request->getData('photo')) {
if (!$this->request->getData('photo')) { $this->Flash->error('Photo is required. Nothing was uploaded. Please try again.');
$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;
$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();
$productCatalogs = $productPhotosTable->ProductCategories->ProductCatalogs->find('list')->toArray(); $this->set(compact('productPhoto', 'productCatalogs', 'productCategory'));
$this->set(compact('productPhoto', 'productCatalogs', 'productCategory'));
return; return;
} }
$uuid = Text::uuid(); $uuid = Text::uuid();
$postData = $this->request->getData(); $postData = $this->request->getData();
$postData['id'] = $uuid; $postData['id'] = $uuid;
$baseDir = Configure::readOrFail('CakeProducts.photos.directory'); $baseDir = Configure::readOrFail('CakeProducts.photos.directory');
$path = ''; $path = '';
if ($this->request->getData('product_sku_id')) { if ($this->request->getData('product_sku_id')) {
$productSku = $productPhotosTable->ProductSkus $productSku = $productPhotosTable->ProductSkus
->find() ->find()
->contain(['Products', 'Products.ProductCategories']) ->contain(['Products', 'Products.ProductCategories'])
->where([ ->where([
'ProductSkus.id' => $this->request->getData('product_sku_id'), 'ProductSkus.id' => $this->request->getData('product_sku_id'),
]) ])
->first(); ->first();
$path = $productSku ? $productSku->product_id . DS . 'skus' . DS . $productSku->id : $path; $path = $productSku ? $productSku->product_id . DS . 'skus' . DS . $productSku->id : $path;
$postData['product_id'] = $productSku->product->id ?? null; $postData['product_id'] = $productSku->product->id ?? null;
$postData['product_category_id'] = $productSku->product->product_category->internal_id ?? null; $postData['product_category_id'] = $productSku->product->product_category->internal_id ?? null;
} else if ($this->request->getData('product_id')) { } else if ($this->request->getData('product_id')) {
$product = $productPhotosTable->Products $product = $productPhotosTable->Products
->find() ->find()
->contain(['ProductCategories']) ->contain(['ProductCategories'])
->where([ ->where([
'Products.id' => $this->request->getData('product_id'), 'Products.id' => $this->request->getData('product_id'),
]) ])
->first(); ->first();
$path = $product ? $product->id : $path; $path = $product ? $product->id : $path;
$postData['product_category_id'] = $product->product_category->internal_id ?? null; $postData['product_category_id'] = $product->product_category->internal_id ?? null;
} else if ($this->request->getData('product_category_id')) { } else if ($this->request->getData('product_category_id')) {
$categoryId = $this->request->getData('product_category_id'); $categoryId = $this->request->getData('product_category_id');
// @link https://developer.wordpress.org/reference/functions/wp_is_uuid/ // @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}$/'; $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'; $field = preg_match($regex, $categoryId) ? 'ProductCategories.internal_id' : 'ProductCategories.id';
$productCategoryPosted = $productPhotosTable->ProductCategories $productCategoryPosted = $productPhotosTable->ProductCategories
->find() ->find()
->where([ ->where([
$field => $categoryId, $field => $categoryId,
]) ])
->first(); ->first();
$postData['product_category_id'] = $productCategoryPosted->internal_id ?? null; $postData['product_category_id'] = $productCategoryPosted->internal_id ?? null;
$path = $productCategoryPosted ? 'categories' : $path; $path = $productCategoryPosted ? 'categories' : $path;
} }
/** /**
* @var UploadedFileInterface $photoObject * @var \Psr\Http\Message\UploadedFileInterface $photoObject
*/ */
$photoObject = $this->request->getData('photo'); $photoObject = $this->request->getData('photo');
$ext = substr(strtolower($photoObject->getClientFilename()), -4); $ext = substr(strtolower($photoObject->getClientFilename()), -4);
$ext = str_starts_with($ext, '.') ? substr($ext, 1) : $ext; $ext = str_starts_with($ext, '.') ? substr($ext, 1) : $ext;
$allowedFileTypes = ['png', 'jpeg', 'jpg']; $allowedFileTypes = ['png', 'jpeg', 'jpg'];
if (!in_array($ext, $allowedFileTypes)) { if (!in_array($ext, $allowedFileTypes)) {
throw new ForbiddenException('Invalid file type. Only PNG and JPG types are allowed.'); throw new ForbiddenException('Invalid file type. Only PNG and JPG types are allowed.');
} }
$fullPath = $baseDir . $path; $fullPath = $baseDir . $path;
if (!file_exists($fullPath)) { if (!file_exists($fullPath)) {
if (!mkdir($fullPath, 0777, true)) { if (!mkdir($fullPath, 0777, true)) {
throw new ForbiddenException('Failed to create the required folders. Please check the folder permissions and try again.'); throw new ForbiddenException('Failed to create the required folders. Please check the folder permissions and try again.');
} }
} }
$destination = $fullPath . DS . $uuid . '.' . $ext; $destination = $fullPath . DS . $uuid . '.' . $ext;
// Existing files with the same name will be replaced. // Existing files with the same name will be replaced.
$photoObject->moveTo($destination); $photoObject->moveTo($destination);
if (!file_exists($destination)) { if (!file_exists($destination)) {
throw new ForbiddenException('Failed to move the uploaded image to the appropriate folder. Please try again.'); throw new ForbiddenException('Failed to move the uploaded image to the appropriate folder. Please try again.');
} }
$postData['photo_dir'] = $path; $postData['photo_dir'] = $path;
$postData['photo_filename'] = $uuid . '.' . $ext; $postData['photo_filename'] = $uuid . '.' . $ext;
// dd($postData); // dd($postData);
$productPhoto = $productPhotosTable->patchEntity($productPhoto, $postData); $productPhoto = $productPhotosTable->patchEntity($productPhoto, $postData);
if ($productPhotosTable->save($productPhoto)) { if ($productPhotosTable->save($productPhoto)) {
$this->Flash->success(__('The product photo has been saved.')); $this->Flash->success(__('The product photo has been saved.'));
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
} }
// dd($productPhoto->getErrors()); // dd($productPhoto->getErrors());
$this->Flash->error(__('The product photo could not be saved. Please, try again.')); $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; $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(); $productCatalogs = $productPhotosTable->ProductCategories->ProductCatalogs->find('list')->toArray();
$this->set(compact('productPhoto', 'productCatalogs', 'productCategory')); $this->set(compact('productPhoto', 'productCatalogs', 'productCategory'));
} }
/** /**
* Edit method * Edit method
* *
* @param string|null $id Product Photo id. * @param string|null $id Product Photo id.
* @return Response|null|void Redirects on successful edit, renders view otherwise.
* @throws RecordNotFoundException When record not found. * @throws RecordNotFoundException When record not found.
* @return Response|null|void Redirects on successful edit, renders view otherwise.
*/ */
public function edit($id = null) public function edit($id = null) {
{ $productPhotosTable = $this->ProductPhotos;
$productPhotosTable = $this->ProductPhotos; $productPhoto = $productPhotosTable->get($id, contain: []);
$productPhoto = $productPhotosTable->get($id, contain: []); if ($this->request->is(['patch', 'post', 'put'])) {
if ($this->request->is(['patch', 'post', 'put'])) { $postData = $this->request->getData();
$postData = $this->request->getData();
$productPhoto = $productPhotosTable->patchEntity($productPhoto, $postData); $productPhoto = $productPhotosTable->patchEntity($productPhoto, $postData);
if ($productPhotosTable->save($productPhoto)) { if ($productPhotosTable->save($productPhoto)) {
$this->Flash->success(__('The product photo has been saved.')); $this->Flash->success(__('The product photo has been saved.'));
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
} }
$this->Flash->error(__('The product photo could not be saved. Please, try again.')); $this->Flash->error(__('The product photo could not be saved. Please, try again.'));
} }
$products = $productPhotosTable->Products->find('list', limit: 200)->all(); $products = $productPhotosTable->Products->find('list', limit: 200)->all();
$productSkus = $productPhotosTable->ProductSkus->find('list', limit: 200)->all(); $productSkus = $productPhotosTable->ProductSkus->find('list', limit: 200)->all();
$this->set(compact('productPhoto', 'products', 'productSkus')); $this->set(compact('productPhoto', 'products', 'productSkus'));
} }
/** /**
* Delete method * Delete method
* *
* @param string|null $id Product Photo id. * @param string|null $id Product Photo id.
* @return Response|null Redirects to index.
* @throws RecordNotFoundException When record not found. * @throws RecordNotFoundException When record not found.
* @return Response|null Redirects to index.
*/ */
public function delete($id = null) public function delete($id = null) {
{ $this->request->allowMethod(['post', 'delete']);
$this->request->allowMethod(['post', 'delete']); $productPhotosTable = $this->ProductPhotos;
$productPhotosTable = $this->ProductPhotos;
$productPhoto = $productPhotosTable->get($id); $productPhoto = $productPhotosTable->get($id);
if ($productPhotosTable->delete($productPhoto)) { if ($productPhotosTable->delete($productPhoto)) {
$this->Flash->success(__('The product photo has been deleted.')); $this->Flash->success(__('The product photo has been deleted.'));
} else { } else {
$this->Flash->error(__('The product photo could not be deleted. Please, try again.')); $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 * @param $id
* @return Response * @return Response
*/ */
public function image($id = null) public function image($id = null) {
{ $productPhoto = $this->ProductPhotos->get($id);
$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'
]);
}
} }
+171 -176
View File
@@ -12,240 +12,235 @@ use function BenTools\CartesianProduct\combinations;
* *
* @property \CakeProducts\Model\Table\ProductSkusTable $ProductSkus * @property \CakeProducts\Model\Table\ProductSkusTable $ProductSkus
*/ */
class ProductSkusController extends AppController class ProductSkusController extends AppController {
{
/** /**
* @return void * @return void
*/ */
public function initialize(): void public function initialize(): void {
{ parent::initialize(); // TODO: Change the autogenerated stub
parent::initialize(); // TODO: Change the autogenerated stub
// $this->_defaultTable = 'CakeProducts.ProductSkus'; // $this->_defaultTable = 'CakeProducts.ProductSkus';
// $this->_tableConfigKey = 'CakeProducts.ProductSkus.table'; // $this->_tableConfigKey = 'CakeProducts.ProductSkus.table';
} }
/** /**
* Index method * Index method
* *
* @return \Cake\Http\Response|null|void Renders view * @return \Cake\Http\Response|null|void Renders view
*/ */
public function index() public function index() {
{ $query = $this->ProductSkus->find()
$query = $this->ProductSkus->find() ->contain(['Products']);
->contain(['Products']); $productSkus = $this->paginate($query);
$productSkus = $this->paginate($query);
$this->set(compact('productSkus')); $this->set(compact('productSkus'));
} }
/** /**
* View method * View method
* *
* @param string|null $id Product Skus id. * @param string|null $id Product Skus id.
* @return \Cake\Http\Response|null|void Renders view
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Renders view
*/ */
public function view($id = null) public function view($id = null) {
{ $productSku = $this->ProductSkus->get($id, contain: [
$productSku = $this->ProductSkus->get($id, contain: [ 'Products',
'Products', 'ProductSkuVariantValues',
'ProductSkuVariantValues', 'ProductSkuVariantValues.ProductVariants',
'ProductSkuVariantValues.ProductVariants', 'ProductSkuVariantValues.ProductVariants.ProductCategoryVariants',
'ProductSkuVariantValues.ProductVariants.ProductCategoryVariants', 'ProductSkuVariantValues.ProductCategoryVariantOptions',
'ProductSkuVariantValues.ProductCategoryVariantOptions', ]);
]); $this->set(compact('productSku'));
$this->set(compact('productSku')); }
}
/** /**
* Add method * Add method
* *
* @return \Cake\Http\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($productId = null) public function add($productId = null) {
{ $toGetCartesianProductsFrom = [];
$toGetCartesianProductsFrom = []; $productSkus = [];
$productSkus = []; $product = $this->ProductSkus->Products->get($productId, contain: [
$product = $this->ProductSkus->Products->get($productId, contain: [ 'ProductSkus',
'ProductSkus', 'ProductSkus.ProductSkuVariantValues',
'ProductSkus.ProductSkuVariantValues', 'ProductVariants',
'ProductVariants', 'ProductVariants.ProductCategoryVariants',
'ProductVariants.ProductCategoryVariants', 'ProductVariants.ProductCategoryVariants.ProductCategoryVariantOptions',
'ProductVariants.ProductCategoryVariants.ProductCategoryVariantOptions', ]);
]); $existingProductSkus = Hash::combine($product->product_skus ?? [], '{n}.id', '{n}');
$existingProductSkus = Hash::combine($product->product_skus ?? [], '{n}.id', '{n}'); $existingProductSkusForMapping = Hash::combine($product->product_skus ?? [], '{n}.id', '{n}.product_sku_variant_values');
$existingProductSkusForMapping = Hash::combine($product->product_skus ?? [], '{n}.id', '{n}.product_sku_variant_values'); $existingSkusForCartesianComparison = [];
$existingSkusForCartesianComparison = []; foreach ($existingProductSkusForMapping as $existingProductSkuId => $existingProductSku) {
foreach ($existingProductSkusForMapping as $existingProductSkuId => $existingProductSku) { $existingSkusForCartesianComparison[$existingProductSkuId] = Hash::combine($existingProductSku, '{n}.product_variant_id', '{n}.product_category_variant_option_id');
$existingSkusForCartesianComparison[$existingProductSkuId] = Hash::combine($existingProductSku, '{n}.product_variant_id', '{n}.product_category_variant_option_id'); }
} $productVariants = $product->product_variants ?? [];
$productVariants = isset($product->product_variants) ? $product->product_variants : [];
// dd($productVariants); // dd($productVariants);
$productVariantsMapping = Hash::combine($productVariants, '{n}.product_category_variant.id', '{n}.id'); $productVariantsMapping = Hash::combine($productVariants, '{n}.product_category_variant.id', '{n}.id');
$productCategoryVariants = Hash::extract($productVariants, '{n}.product_category_variant'); $productCategoryVariants = Hash::extract($productVariants, '{n}.product_category_variant');
// dd($productCategoryVariants); // 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); // dd($optionMapping);
$variantNameMapping = Hash::combine($productCategoryVariants, '{n}.id', '{n}.name'); $variantNameMapping = Hash::combine($productCategoryVariants, '{n}.id', '{n}.name');
// dd($variantNameMapping); // dd($variantNameMapping);
foreach ($productCategoryVariants as $productCategoryVariant) { foreach ($productCategoryVariants as $productCategoryVariant) {
$options = Hash::extract($productCategoryVariant['product_category_variant_options'] ?? [], '{n}.id'); $options = Hash::extract($productCategoryVariant['product_category_variant_options'] ?? [], '{n}.id');
$toGetCartesianProductsFrom[$productVariantsMapping[$productCategoryVariant['id']]] = $options; $toGetCartesianProductsFrom[$productVariantsMapping[$productCategoryVariant['id']]] = $options;
} }
// dd($toGetCartesianProductsFrom); // dd($toGetCartesianProductsFrom);
$numSkusToAdd = count(combinations($toGetCartesianProductsFrom)); $numSkusToAdd = count(combinations($toGetCartesianProductsFrom));
for ($i = 0; $i < $numSkusToAdd; $i++) { for ($i = 0; $i < $numSkusToAdd; $i++) {
$productSkus[$i] = $this->ProductSkus->newEmptyEntity(); $productSkus[$i] = $this->ProductSkus->newEmptyEntity();
} }
$this->set(compact( $this->set(compact(
'product', 'product',
'productSkus', 'productSkus',
'productCategoryVariants', 'productCategoryVariants',
'productVariantsMapping', 'productVariantsMapping',
'toGetCartesianProductsFrom', 'toGetCartesianProductsFrom',
'optionMapping', 'optionMapping',
'variantNameMapping', 'variantNameMapping',
'numSkusToAdd', 'numSkusToAdd',
'existingProductSkus', 'existingProductSkus',
'existingSkusForCartesianComparison' 'existingSkusForCartesianComparison',
)); ));
if ($this->request->is('post')) { if ($this->request->is('post')) {
$postedSkus = $this->request->getData(); $postedSkus = $this->request->getData();
$saveOptions = [ $saveOptions = [
'fields' => [ 'fields' => [
'product_id', 'product_id',
'sku', 'sku',
'barcode', 'barcode',
'price', 'price',
'cost', 'cost',
'product_sku_variant_values', 'product_sku_variant_values',
'created', 'created',
'modified', 'modified',
'enabled', 'enabled',
'default_sku', 'default_sku',
], ],
'associated' => [ 'associated' => [
'ProductSkuVariantValues' => [ 'ProductSkuVariantValues' => [
'fields' => [ 'fields' => [
'product_variant_id', 'product_variant_id',
'product_category_variant_option_id', 'product_category_variant_option_id',
], ],
], ],
], ],
]; ];
$finalPostData = []; $finalPostData = [];
$postedSkus = Hash::insert($postedSkus, '{n}.product_id', $productId); $postedSkus = Hash::insert($postedSkus, '{n}.product_id', $productId);
foreach ($postedSkus as $postedSkuCnt => $postedSku) { foreach ($postedSkus as $postedSkuCnt => $postedSku) {
if (!isset($postedSku['sku']) || !$postedSku['sku']) { if (!isset($postedSku['sku']) || !$postedSku['sku']) {
unset($productSkus[$postedSkuCnt]); unset($productSkus[$postedSkuCnt]);
continue; continue;
} }
$finalPostData[$postedSkuCnt] = $postedSku; $finalPostData[$postedSkuCnt] = $postedSku;
} }
if (!$productSkus || !$postedSkus) { if (!$productSkus || !$postedSkus) {
$this->Flash->error('Nothing to save! Add at least one SKU next time.'); $this->Flash->error('Nothing to save! Add at least one SKU next time.');
return; return;
} }
// dd($finalPostData); // dd($finalPostData);
$productSkus = $this->ProductSkus->patchEntities($productSkus, $finalPostData, $saveOptions); $productSkus = $this->ProductSkus->patchEntities($productSkus, $finalPostData, $saveOptions);
$errors = []; $errors = [];
$successes = []; $successes = [];
foreach ($productSkus as $productSkuToSave) { foreach ($productSkus as $productSkuToSave) {
// dd($productSkuToSave); // dd($productSkuToSave);
if (!$this->ProductSkus->save($productSkuToSave, $saveOptions)) { if (!$this->ProductSkus->save($productSkuToSave, $saveOptions)) {
Log::debug(print_r('$productSkuToSave->getErrors()', true)); Log::debug(print_r('$productSkuToSave->getErrors()', true));
Log::debug(print_r($productSkuToSave->getErrors(), true)); Log::debug(print_r($productSkuToSave->getErrors(), true));
dd($productSkuToSave->getErrors()); dd($productSkuToSave->getErrors());
continue;
}
$successes[] = $productSkuToSave;
}
if ($successes) { continue;
$this->Flash->success(__(count($successes) . ' New SKUs have been saved.')); }
$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.')); return $this->redirect(['action' => 'index']);
} }
$this->set(compact(
'productSkus'
));
}
/** $this->Flash->error(__('The product SKU(s) could not be saved. Please, try again.'));
}
$this->set(compact(
'productSkus',
));
}
/**
* Edit method * Edit method
* *
* @param string|null $id Product Skus id. * @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. * @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) public function edit($id = null) {
{ $productSku = $this->ProductSkus->get($id, contain: []);
$productSku = $this->ProductSkus->get($id, contain: []); if ($this->request->is(['patch', 'post', 'put'])) {
if ($this->request->is(['patch', 'post', 'put'])) { $postData = $this->request->getData();
$postData = $this->request->getData(); $saveOptions = [
$saveOptions = [ 'associated' => [],
'associated' => [], ];
]; // Log::debug(print_r('$postData', true));
// Log::debug(print_r('$postData', true));
// Log::debug(print_r($postData, true)); // Log::debug(print_r($postData, true));
// Log::debug(print_r('$saveOptions', true)); // Log::debug(print_r('$saveOptions', true));
// Log::debug(print_r($saveOptions, true)); // Log::debug(print_r($saveOptions, true));
$productSku = $this->ProductSkus->patchEntity($productSku, $postData, $saveOptions); $productSku = $this->ProductSkus->patchEntity($productSku, $postData, $saveOptions);
if ($this->ProductSkus->save($productSku)) { if ($this->ProductSkus->save($productSku)) {
$this->Flash->success(__('The product skus has been saved.')); $this->Flash->success(__('The product skus has been saved.'));
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
} }
Log::debug(print_r('$productSku->getErrors() next - failed in productSkus/edit', true)); Log::debug(print_r('$productSku->getErrors() next - failed in productSkus/edit', true));
Log::debug(print_r($productSku->getErrors(), true)); Log::debug(print_r($productSku->getErrors(), true));
$this->Flash->error(__('The product skus could not be saved. Please, try again.')); $this->Flash->error(__('The product skus could not be saved. Please, try again.'));
} }
$products = $this->ProductSkus->Products->find('list', limit: 200)->all(); $products = $this->ProductSkus->Products->find('list', limit: 200)->all();
$this->set(compact('productSku', 'products')); $this->set(compact('productSku', 'products'));
} }
/** /**
* Delete method * Delete method
* *
* @param string|null $id Product Skus id. * @param string|null $id Product Skus id.
* @return \Cake\Http\Response|null Redirects to index.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null Redirects to index.
*/ */
public function delete($id = null) public function delete($id = null) {
{ $this->request->allowMethod(['post', 'delete']);
$this->request->allowMethod(['post', 'delete']); $productSku = $this->ProductSkus->get($id);
$productSku = $this->ProductSkus->get($id); if ($this->ProductSkus->delete($productSku)) {
if ($this->ProductSkus->delete($productSku)) { $this->Flash->success(__('The product skus has been deleted.'));
$this->Flash->success(__('The product skus has been deleted.')); } else {
} else { $this->Flash->error(__('The product skus could not be deleted. Please, try again.'));
$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 * @return \Cake\Http\Response|null|void Renders view
*/ */
public function select() public function select() {
{ $productSkus = $this->ProductSkus
$productSkus = $this->ProductSkus ->find('list')
->find('list') ->where(['product_id' => $this->request->getQuery('product_id', '-1')])
->where(['product_id' => $this->request->getQuery('product_id', '-1')]) ->orderBy(['sku'])
->orderBy(['sku']) ->toArray();
->toArray();
$this->set(compact('productSkus'));
}
$this->set(compact('productSkus'));
}
} }
+69 -73
View File
@@ -10,109 +10,105 @@ use Cake\Log\Log;
* *
* @property \App\Model\Table\ProductVariantsTable $ProductVariants * @property \App\Model\Table\ProductVariantsTable $ProductVariants
*/ */
class ProductVariantsController extends AppController class ProductVariantsController extends AppController {
{
/** /**
* Index method * Index method
* *
* @return \Cake\Http\Response|null|void Renders view * @return \Cake\Http\Response|null|void Renders view
*/ */
public function index() public function index() {
{ $query = $this->ProductVariants->find()
$query = $this->ProductVariants->find() ->contain(['ProductCategoryVariants', 'Products']);
->contain(['ProductCategoryVariants', 'Products']); $productVariants = $this->paginate($query);
$productVariants = $this->paginate($query);
$this->set(compact('productVariants')); $this->set(compact('productVariants'));
} }
/** /**
* View method * View method
* *
* @param string|null $id Product Variant id. * @param string|null $id Product Variant id.
* @return \Cake\Http\Response|null|void Renders view
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Renders view
*/ */
public function view($id = null) public function view($id = null) {
{ $productVariant = $this->ProductVariants->get($id, contain: ['ProductCategoryVariants', 'Products']);
$productVariant = $this->ProductVariants->get($id, contain: ['ProductCategoryVariants', 'Products']); $this->set(compact('productVariant'));
$this->set(compact('productVariant')); }
}
/** /**
* Add method * Add method
* *
* @return \Cake\Http\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($productId) public function add($productId) {
{ $product = $this->ProductVariants->Products->get($productId);
$product = $this->ProductVariants->Products->get($productId); $productVariant = $this->ProductVariants->newEmptyEntity();
$productVariant = $this->ProductVariants->newEmptyEntity(); if ($this->request->is('post')) {
if ($this->request->is('post')) { $saveOptions = [];
$saveOptions = []; $postData = $this->request->getData();
$postData = $this->request->getData(); $productCategoryVariant = $this->ProductVariants->ProductCategoryVariants->get($this->request->getData('product_category_variant_id', '-1'));
$productCategoryVariant = $this->ProductVariants->ProductCategoryVariants->get($this->request->getData('product_category_variant_id', '-1')); $postData['name'] = $productCategoryVariant->name;
$postData['name'] = $productCategoryVariant->name; $postData['product_id'] = $productId;
$postData['product_id'] = $productId; $productVariant = $this->ProductVariants->patchEntity($productVariant, $postData);
$productVariant = $this->ProductVariants->patchEntity($productVariant, $postData); if ($this->ProductVariants->save($productVariant)) {
if ($this->ProductVariants->save($productVariant)) { $this->Flash->success(__('The product variant has been saved.'));
$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));
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.')); $this->Flash->error(__('The product variant could not be saved. Please, try again.'));
} }
$productCategoryVariants = $this->ProductVariants->ProductCategoryVariants $productCategoryVariants = $this->ProductVariants->ProductCategoryVariants
->find('list', limit: 200) ->find('list', limit: 200)
->where(['product_category_id' => $product->product_category_id]) ->where(['product_category_id' => $product->product_category_id])
->toArray(); ->toArray();
$this->set(compact('productVariant', 'productCategoryVariants', 'product')); $this->set(compact('productVariant', 'productCategoryVariants', 'product'));
} }
/** /**
* Edit method * Edit method
* *
* @param string|null $id Product Variant id. * @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. * @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) public function edit($id = null) {
{ $productVariant = $this->ProductVariants->get($id, contain: []);
$productVariant = $this->ProductVariants->get($id, contain: []); if ($this->request->is(['patch', 'post', 'put'])) {
if ($this->request->is(['patch', 'post', 'put'])) { $productVariant = $this->ProductVariants->patchEntity($productVariant, $this->request->getData());
$productVariant = $this->ProductVariants->patchEntity($productVariant, $this->request->getData()); if ($this->ProductVariants->save($productVariant)) {
if ($this->ProductVariants->save($productVariant)) { $this->Flash->success(__('The product variant has been saved.'));
$this->Flash->success(__('The product variant has been saved.'));
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
} }
$this->Flash->error(__('The product variant could not be saved. Please, try again.')); $this->Flash->error(__('The product variant could not be saved. Please, try again.'));
} }
$productCategoryVariants = $this->ProductVariants->ProductCategoryVariants->find('list', limit: 200)->all(); $productCategoryVariants = $this->ProductVariants->ProductCategoryVariants->find('list', limit: 200)->all();
$products = $this->ProductVariants->Products->find('list', limit: 200)->all(); $products = $this->ProductVariants->Products->find('list', limit: 200)->all();
$this->set(compact('productVariant', 'productCategoryVariants', 'products')); $this->set(compact('productVariant', 'productCategoryVariants', 'products'));
} }
/** /**
* Delete method * Delete method
* *
* @param string|null $id Product Variant id. * @param string|null $id Product Variant id.
* @return \Cake\Http\Response|null Redirects to index.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null Redirects to index.
*/ */
public function delete($id = null) public function delete($id = null) {
{ $this->request->allowMethod(['post', 'delete']);
$this->request->allowMethod(['post', 'delete']); $productVariant = $this->ProductVariants->get($id);
$productVariant = $this->ProductVariants->get($id); if ($this->ProductVariants->delete($productVariant)) {
if ($this->ProductVariants->delete($productVariant)) { $this->Flash->success(__('The product variant has been deleted.'));
$this->Flash->success(__('The product variant has been deleted.')); } else {
} else { $this->Flash->error(__('The product variant could not be deleted. Please, try again.'));
$this->Flash->error(__('The product variant could not be deleted. Please, try again.')); }
}
return $this->redirect(['action' => 'index']);
}
return $this->redirect(['action' => 'index']);
}
} }
+150 -159
View File
@@ -3,211 +3,202 @@ declare(strict_types=1);
namespace CakeProducts\Controller; namespace CakeProducts\Controller;
use Cake\Core\Configure;
use Cake\Log\Log; use Cake\Log\Log;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
/** /**
* Products Controller * Products Controller
* *
* @property \CakeProducts\Model\Table\ProductsTable $Products * @property \CakeProducts\Model\Table\ProductsTable $Products
*/ */
class ProductsController extends AppController class ProductsController extends AppController {
{
/** /**
* @return void * @return void
*/ */
public function initialize(): void public function initialize(): void {
{ parent::initialize(); // TODO: Change the autogenerated stub
parent::initialize(); // TODO: Change the autogenerated stub
// $this->_defaultTable = 'CakeProducts.Products'; // $this->_defaultTable = 'CakeProducts.Products';
// $this->_tableConfigKey = 'CakeProducts.Products.table'; // $this->_tableConfigKey = 'CakeProducts.Products.table';
} }
/** /**
* Index method * Index method
* *
* @return \Cake\Http\Response|null|void Renders view * @return \Cake\Http\Response|null|void Renders view
*/ */
public function index() public function index() {
{ $query = $this->Products->find()
$query = $this->Products->find() ->contain(['ProductCategories']);
->contain(['ProductCategories']); $products = $this->paginate($query);
$products = $this->paginate($query);
$this->set(compact('products')); $this->set(compact('products'));
} }
/** /**
* View method * View method
* *
* @param string|null $id Product id. * @param string|null $id Product id.
* @return \Cake\Http\Response|null|void Renders view
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Renders view
*/ */
public function view($id = null) public function view($id = null) {
{ $product = $this->Products->get($id, contain: [
$product = $this->Products->get($id, contain: [ 'ProductCategories',
'ProductCategories', 'ProductAttributes',
'ProductAttributes', 'ProductAttributes.ProductCategoryAttributes',
'ProductAttributes.ProductCategoryAttributes', 'ProductAttributes.ProductCategoryAttributeOptions',
'ProductAttributes.ProductCategoryAttributeOptions', 'ProductVariants',
'ProductVariants', 'ProductVariants.ProductCategoryVariants',
'ProductVariants.ProductCategoryVariants', 'ProductVariants.ProductCategoryVariants.ProductCategoryVariantOptions',
'ProductVariants.ProductCategoryVariants.ProductCategoryVariantOptions', 'ProductSkus',
'ProductSkus', 'ProductPhotos',
'ProductPhotos', ]);
]); $this->set(compact('product'));
$this->set(compact('product')); }
}
/** /**
* Add method * Add method
* *
* @return \Cake\Http\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() public function add() {
{ $productsTable = $this->Products;
$productsTable = $this->Products; $product = $productsTable->newEmptyEntity();
$product = $productsTable->newEmptyEntity(); if ($this->request->is('post')) {
if ($this->request->is('post')) { $postData = $this->request->getData();
$postData = $this->request->getData(); $saveOptions = [
$saveOptions = [ 'associated' => ['ProductAttributes'],
'associated' => ['ProductAttributes'], ];
]; Log::debug(print_r('$postData', true));
Log::debug(print_r('$postData', true)); Log::debug(print_r($postData, true));
Log::debug(print_r($postData, true)); Log::debug(print_r('$saveOptions', true));
Log::debug(print_r('$saveOptions', true)); Log::debug(print_r($saveOptions, true));
Log::debug(print_r($saveOptions, true)); $productVariantsData = [];
$productVariantsData = []; if (isset($postData['product_variants']) && $postData['product_variants']) {
if (isset($postData['product_variants']) && $postData['product_variants']) { foreach ($postData['product_variants'] as $postedProductVariant) {
foreach ($postData['product_variants'] as $postedProductVariant) { if (!isset($postedProductVariant['enabled']) || !$postedProductVariant['enabled'] || !isset($postedProductVariant['product_category_variant_id'])) {
if (!isset($postedProductVariant['enabled']) || !$postedProductVariant['enabled'] || !isset($postedProductVariant['product_category_variant_id'])) { continue;
continue; }
} $existingVariant = $this->Products->ProductCategories->ProductCategoryVariants->get($postedProductVariant['product_category_variant_id'], contain: ['ProductCategoryVariantOptions']);
$existingVariant = $this->Products->ProductCategories->ProductCategoryVariants->get($postedProductVariant['product_category_variant_id'], contain: ['ProductCategoryVariantOptions']); $optionsData = [];
$optionsData = []; foreach ($existingVariant->product_category_variant_options as $existingOption) {
foreach ($existingVariant->product_category_variant_options as $existingOption) { $optionsData[] = [
$optionsData[] = [ 'variant_value' => $existingOption->variant_value,
'variant_value' => $existingOption->variant_value, 'variant_label' => $existingOption->variant_label ?? null,
'variant_label' => $existingOption->variant_label ?? null, 'enabled' => $existingOption->enabled,
'enabled' => $existingOption->enabled, ];
]; }
} $tmpVariantData = [
$tmpVariantData = [ 'name' => $existingVariant->name,
'name' => $existingVariant->name, 'product_category_variant_id' => $postedProductVariant['product_category_variant_id'],
'product_category_variant_id' => $postedProductVariant['product_category_variant_id'], 'enabled' => true,
'enabled' => true, 'product_category_variant_options' => $optionsData,
'product_category_variant_options' => $optionsData, ];
]; $productVariantsData[] = $tmpVariantData;
$productVariantsData[] = $tmpVariantData; }
} }
} if ($productVariantsData) {
if ($productVariantsData) { $saveOptions['fields'] = [
$saveOptions['fields'] = [ 'name',
'name', 'product_category_id',
'product_category_id', 'product_type_id',
'product_type_id', 'product_attributes',
'product_attributes', 'product_category_variants',
'product_category_variants' ];
]; $saveOptions['associated']['ProductCategoryVariants'] = [
$saveOptions['associated']['ProductCategoryVariants'] = [ 'fields' => [
'fields' => [ 'name',
'name', 'enabled',
'enabled', 'product_category_variant_options',
'product_category_variant_options', ],
] ];
]; $saveOptions['associated'][] = 'ProductCategoryVariants.ProductCategoryVariantOptions';
$saveOptions['associated'][] = 'ProductCategoryVariants.ProductCategoryVariantOptions'; $postData['product_category_variants'] = $productVariantsData;
$postData['product_category_variants'] = $productVariantsData; }
} $product = $productsTable->patchEntity($product, $postData, $saveOptions);
$product = $productsTable->patchEntity($product, $postData, $saveOptions); if ($productsTable->save($product, $saveOptions)) {
if ($productsTable->save($product, $saveOptions)) { $this->Flash->success(__('The product has been saved.'));
$this->Flash->success(__('The product has been saved.'));
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
} }
Log::debug(print_r('$product->getErrors() next - failed in products/add', true)); Log::debug(print_r('$product->getErrors() next - failed in products/add', true));
Log::debug(print_r($product->getErrors(), true)); Log::debug(print_r($product->getErrors(), true));
$this->Flash->error(__('The product could not be saved. Please, try again.')); $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; $productCategory = $product->product_category_id ? $productsTable->ProductCategories->find()->where(['internal_id' => $product->product_category_id])->first() : null;
$productCatalogs = $productsTable->ProductCategories->ProductCatalogs->find('list')->toArray(); $productCatalogs = $productsTable->ProductCategories->ProductCatalogs->find('list')->toArray();
$this->set(compact('product', 'productCatalogs', 'productCategory')); $this->set(compact('product', 'productCatalogs', 'productCategory'));
} }
/** /**
* Edit method * Edit method
* *
* @param string|null $id Product id. * @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. * @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) public function edit($id = null) {
{ $productsTable = $this->Products;
$productsTable = $this->Products; $product = $productsTable->get($id, contain: [
$product = $productsTable->get($id, contain: [ 'ProductAttributes',
'ProductAttributes', 'ProductAttributes.ProductCategoryAttributes',
'ProductAttributes.ProductCategoryAttributes', 'ProductAttributes.ProductCategoryAttributes.ProductCategoryAttributeOptions',
'ProductAttributes.ProductCategoryAttributes.ProductCategoryAttributeOptions', ]);
]); if ($this->request->is(['patch', 'post', 'put'])) {
if ($this->request->is(['patch', 'post', 'put'])) { $saveOptions = [
$saveOptions = [ 'associated' => ['ProductAttributes'],
'associated' => ['ProductAttributes'], ];
]; $product = $productsTable->patchEntity($product, $this->request->getData(), $saveOptions);
$product = $productsTable->patchEntity($product, $this->request->getData(), $saveOptions); if ($productsTable->save($product)) {
if ($productsTable->save($product)) { $this->Flash->success(__('The product has been saved.'));
$this->Flash->success(__('The product has been saved.'));
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
} }
Log::debug(print_r('$product->getErrors() next - failed in products/edit', true)); Log::debug(print_r('$product->getErrors() next - failed in products/edit', true));
Log::debug(print_r($product->getErrors(), true)); Log::debug(print_r($product->getErrors(), true));
$this->Flash->error(__('The product could not be saved. Please, try again.')); $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; $productCategory = $product->product_category_id ? $productsTable->ProductCategories->find()->where(['internal_id' => $product->product_category_id])->first() : null;
$productCatalogs = $productsTable->ProductCategories->ProductCatalogs->find('list')->toArray(); $productCatalogs = $productsTable->ProductCategories->ProductCatalogs->find('list')->toArray();
$this->set(compact('product', 'productCatalogs', 'productCategory')); $this->set(compact('product', 'productCatalogs', 'productCategory'));
} }
/** /**
* Delete method * Delete method
* *
* @param string|null $id Product id. * @param string|null $id Product id.
* @return \Cake\Http\Response|null Redirects to index.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null Redirects to index.
*/ */
public function delete($id = null) public function delete($id = null) {
{ $this->request->allowMethod(['post', 'delete']);
$this->request->allowMethod(['post', 'delete']);
$productsTable = $this->Products; $productsTable = $this->Products;
$product = $productsTable->get($id); $product = $productsTable->get($id);
if ($productsTable->delete($product)) { if ($productsTable->delete($product)) {
$this->Flash->success(__('The product has been deleted.')); $this->Flash->success(__('The product has been deleted.'));
} else { } else {
$this->Flash->error(__('The product could not be deleted. Please, try again.')); $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 * @return \Cake\Http\Response|null|void Renders view
*/ */
public function select() public function select() {
{ $productsTable = $this->Products;
$productsTable = $this->Products; $productCategory = $productsTable->ProductCategories->find()
$productCategory = $productsTable->ProductCategories->find() ->where(['id' => $this->request->getQuery('product_category_id', '-1')])
->where(['id' => $this->request->getQuery('product_category_id', '-1')]) ->first();
->first(); $products = $productsTable
$products = $productsTable ->find('list')
->find('list') ->where(['product_category_id' => $productCategory->internal_id ?? '-1'])
->where(['product_category_id' => $productCategory->internal_id ?? '-1']) ->orderBy(['Products.name'])
->orderBy(['Products.name']) ->toArray();
->toArray();
$this->set(compact('products'));
}
$this->set(compact('products'));
}
} }
+22 -25
View File
@@ -2,11 +2,7 @@
namespace CakeProducts\Model\Behavior; namespace CakeProducts\Model\Behavior;
use ArrayObject;
use Cake\Datasource\EntityInterface; use Cake\Datasource\EntityInterface;
use Cake\Event\EventInterface;
use Cake\ORM\Behavior;
use LogicException;
use Tools\Model\Behavior\ToggleBehavior; use Tools\Model\Behavior\ToggleBehavior;
/** /**
@@ -21,37 +17,38 @@ use Tools\Model\Behavior\ToggleBehavior;
*/ */
class SecondToggleBehavior extends ToggleBehavior { class SecondToggleBehavior extends ToggleBehavior {
/** /**
* Default config * Default config
* *
* @var array<string, mixed> * @var array<string, mixed>
*/ */
protected array $_defaultConfig = [ protected array $_defaultConfig = [
'field' => 'primary', 'field' => 'primary',
'on' => 'afterSave', // afterSave (without transactions) or beforeSave (with transactions) 'on' => 'afterSave', // afterSave (without transactions) or beforeSave (with transactions)
'scopeFields' => [], 'scopeFields' => [],
'scope' => [], 'scope' => [],
'findOrder' => null, // null = autodetect modified/created, false to disable 'findOrder' => null, // null = autodetect modified/created, false to disable
'implementedMethods' => [], // to prevent conflict with public toggleField method 'implementedMethods' => [], // to prevent conflict with public toggleField method
]; ];
/** /**
* @param \Cake\Datasource\EntityInterface $entity * @param \Cake\Datasource\EntityInterface $entity
* *
* @return array * @return array
*/ */
protected function buildConditions(EntityInterface $entity) { protected function buildConditions(EntityInterface $entity) {
$conditions = $this->getConfig('scope'); $conditions = $this->getConfig('scope');
$scopeFields = (array)$this->getConfig('scopeFields'); $scopeFields = (array)$this->getConfig('scopeFields');
foreach ($scopeFields as $scopeField) { foreach ($scopeFields as $scopeField) {
if ($entity->get($scopeField) === null) { if ($entity->get($scopeField) === null) {
continue; continue;
} }
$conditions[$scopeField] = $entity->get($scopeField); $conditions[$scopeField] = $entity->get($scopeField);
} }
// dd($conditions); // dd($conditions);
return $conditions; return $conditions;
} }
} }
+22 -25
View File
@@ -2,11 +2,7 @@
namespace CakeProducts\Model\Behavior; namespace CakeProducts\Model\Behavior;
use ArrayObject;
use Cake\Datasource\EntityInterface; use Cake\Datasource\EntityInterface;
use Cake\Event\EventInterface;
use Cake\ORM\Behavior;
use LogicException;
use Tools\Model\Behavior\ToggleBehavior; use Tools\Model\Behavior\ToggleBehavior;
/** /**
@@ -21,37 +17,38 @@ use Tools\Model\Behavior\ToggleBehavior;
*/ */
class ThirdToggleBehavior extends ToggleBehavior { class ThirdToggleBehavior extends ToggleBehavior {
/** /**
* Default config * Default config
* *
* @var array<string, mixed> * @var array<string, mixed>
*/ */
protected array $_defaultConfig = [ protected array $_defaultConfig = [
'field' => 'primary', 'field' => 'primary',
'on' => 'afterSave', // afterSave (without transactions) or beforeSave (with transactions) 'on' => 'afterSave', // afterSave (without transactions) or beforeSave (with transactions)
'scopeFields' => [], 'scopeFields' => [],
'scope' => [], 'scope' => [],
'findOrder' => null, // null = autodetect modified/created, false to disable 'findOrder' => null, // null = autodetect modified/created, false to disable
'implementedMethods' => [], // to prevent conflict with public toggleField method 'implementedMethods' => [], // to prevent conflict with public toggleField method
]; ];
/** /**
* @param \Cake\Datasource\EntityInterface $entity * @param \Cake\Datasource\EntityInterface $entity
* *
* @return array * @return array
*/ */
protected function buildConditions(EntityInterface $entity) { protected function buildConditions(EntityInterface $entity) {
$conditions = $this->getConfig('scope'); $conditions = $this->getConfig('scope');
$scopeFields = (array)$this->getConfig('scopeFields'); $scopeFields = (array)$this->getConfig('scopeFields');
foreach ($scopeFields as $scopeField) { foreach ($scopeFields as $scopeField) {
if ($entity->get($scopeField) === null) { if ($entity->get($scopeField) === null) {
continue; continue;
} }
$conditions[$scopeField] = $entity->get($scopeField); $conditions[$scopeField] = $entity->get($scopeField);
} }
// dd($conditions); // dd($conditions);
return $conditions; return $conditions;
} }
} }
+15 -15
View File
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity; namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity; use Cake\ORM\Entity;
/** /**
@@ -12,15 +11,15 @@ use Cake\ORM\Entity;
* @property int $id * @property int $id
* @property string $base_url * @property string $base_url
* @property string $api_url * @property string $api_url
* @property DateTime $created * @property \Cake\I18n\DateTime $created
* @property DateTime|null $deleted * @property \Cake\I18n\DateTime|null $deleted
* *
* @property ProductCatalog[] $product_catalogs * @property ProductCatalog[] $product_catalogs
* @property ExternalProductCatalogsProductCatalog[] $external_product_catalogs_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(). * Fields that can be mass assigned using newEntity() or patchEntity().
* *
* Note that when '*' is set to true, this allows all unspecified fields to * 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> * @var array<string, bool>
*/ */
protected array $_accessible = [ protected array $_accessible = [
'base_url' => true, 'base_url' => true,
'api_url' => true, 'api_url' => true,
'created' => true, 'created' => true,
'deleted' => true, 'deleted' => true,
'enabled' => 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; namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity; use Cake\ORM\Entity;
/** /**
@@ -12,16 +11,16 @@ use Cake\ORM\Entity;
* @property int $id * @property int $id
* @property string $external_product_catalog_id * @property string $external_product_catalog_id
* @property string $product_catalog_id * @property string $product_catalog_id
* @property DateTime $created * @property \Cake\I18n\DateTime $created
* @property bool $enabled * @property bool $enabled
* @property DateTime|null $deleted * @property \Cake\I18n\DateTime|null $deleted
* *
* @property ExternalProductCatalog $external_product_catalog * @property ExternalProductCatalog $external_product_catalog
* @property ProductCatalog $product_catalog * @property ProductCatalog $product_catalog
*/ */
class ExternalProductCatalogsProductCatalog extends Entity class ExternalProductCatalogsProductCatalog extends Entity {
{
/** /**
* Fields that can be mass assigned using newEntity() or patchEntity(). * Fields that can be mass assigned using newEntity() or patchEntity().
* *
* Note that when '*' is set to true, this allows all unspecified fields to * 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> * @var array<string, bool>
*/ */
protected array $_accessible = [ protected array $_accessible = [
'external_product_catalog_id' => true, 'external_product_catalog_id' => true,
'product_catalog_id' => true, 'product_catalog_id' => true,
'created' => true, 'created' => true,
'enabled' => true, 'enabled' => true,
'deleted' => true, 'deleted' => true,
// entities
'external_product_catalog' => true,
'product_catalog' => true,
];
// entities
'external_product_catalog' => true,
'product_catalog' => true,
];
} }
+17 -19
View File
@@ -3,9 +3,7 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity; namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity; use Cake\ORM\Entity;
use CakeProducts\Model\Enum\ProductProductTypeId;
/** /**
* Product Entity * Product Entity
@@ -13,17 +11,16 @@ use CakeProducts\Model\Enum\ProductProductTypeId;
* @property string $id * @property string $id
* @property string $name * @property string $name
* @property string $product_category_id * @property string $product_category_id
* @property ProductProductTypeId $product_type_id * @property \CakeProducts\Model\Enum\ProductProductTypeId $product_type_id
* @property DateTime|null $deleted * @property \Cake\I18n\DateTime|null $deleted
* *
* @property ProductCategory $product_category * @property ProductCategory $product_category
* @property ProductAttribute[] $product_attributes * @property ProductAttribute[] $product_attributes
* @property ProductCategoryVariant[] $product_category_variants * @property ProductCategoryVariant[] $product_category_variants
*
*/ */
class Product extends Entity class Product extends Entity {
{
/** /**
* Fields that can be mass assigned using newEntity() or patchEntity(). * Fields that can be mass assigned using newEntity() or patchEntity().
* *
* Note that when '*' is set to true, this allows all unspecified fields to * 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> * @var array<string, bool>
*/ */
protected array $_accessible = [ protected array $_accessible = [
'name' => true, 'name' => true,
'product_category_id' => true, 'product_category_id' => true,
'product_type_id' => true, 'product_type_id' => true,
'deleted' => 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,
];
} }
+16 -16
View File
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity; namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity; use Cake\ORM\Entity;
/** /**
@@ -14,15 +13,15 @@ use Cake\ORM\Entity;
* @property string $product_category_attribute_id * @property string $product_category_attribute_id
* @property string|null $attribute_value * @property string|null $attribute_value
* @property string|null $product_category_attribute_option_id * @property string|null $product_category_attribute_option_id
* @property DateTime|null $deleted * @property \Cake\I18n\DateTime|null $deleted
* *
* @property Product $product * @property Product $product
* @property ProductCategoryAttribute $product_category_attribute * @property ProductCategoryAttribute $product_category_attribute
* @property ProductCategoryAttributeOption $product_category_attribute_option * @property ProductCategoryAttributeOption $product_category_attribute_option
*/ */
class ProductAttribute extends Entity class ProductAttribute extends Entity {
{
/** /**
* Fields that can be mass assigned using newEntity() or patchEntity(). * Fields that can be mass assigned using newEntity() or patchEntity().
* *
* Note that when '*' is set to true, this allows all unspecified fields to * 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> * @var array<string, bool>
*/ */
protected array $_accessible = [ protected array $_accessible = [
'product_id' => true, 'product_id' => true,
'product_category_attribute_id' => true, 'product_category_attribute_id' => true,
'attribute_value' => true, 'attribute_value' => true,
'product_category_attribute_option_id' => true, 'product_category_attribute_option_id' => true,
'deleted' => 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,
];
} }
+14 -14
View File
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity; namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity; use Cake\ORM\Entity;
/** /**
@@ -13,14 +12,14 @@ use Cake\ORM\Entity;
* @property string $name * @property string $name
* @property string|null $catalog_description * @property string|null $catalog_description
* @property bool $enabled * @property bool $enabled
* @property DateTime|null $deleted * @property \Cake\I18n\DateTime|null $deleted
* *
* @property ProductCategory[] $product_categories * @property ProductCategory[] $product_categories
* @property ExternalProductCatalog[] $external_product_catalogs * @property ExternalProductCatalog[] $external_product_catalogs
*/ */
class ProductCatalog extends Entity class ProductCatalog extends Entity {
{
/** /**
* Fields that can be mass assigned using newEntity() or patchEntity(). * Fields that can be mass assigned using newEntity() or patchEntity().
* *
* Note that when '*' is set to true, this allows all unspecified fields to * 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> * @var array<string, bool>
*/ */
protected array $_accessible = [ protected array $_accessible = [
'name' => true, 'name' => true,
'catalog_description' => true, 'catalog_description' => true,
'enabled' => true, 'enabled' => true,
'deleted' => true, 'deleted' => true,
// entities
'product_categories' => true,
'external_product_catalogs' => true,
];
// entities
'product_categories' => true,
'external_product_catalogs' => true,
];
} }
+23 -24
View File
@@ -3,9 +3,7 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity; namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity; use Cake\ORM\Entity;
use CakeProducts\Model\Enum\ProductProductTypeId;
/** /**
* ProductCategory Entity * ProductCategory Entity
@@ -19,16 +17,16 @@ use CakeProducts\Model\Enum\ProductProductTypeId;
* @property int $lft * @property int $lft
* @property int $rght * @property int $rght
* @property bool $enabled * @property bool $enabled
* @property DateTime|null $deleted * @property \Cake\I18n\DateTime|null $deleted
* @property ProductProductTypeId|null $default_product_type_id * @property \CakeProducts\Model\Enum\ProductProductTypeId|null $default_product_type_id
* *
* @property \CakeProducts\Model\Entity\ProductCatalog $product_catalog * @property \CakeProducts\Model\Entity\ProductCatalog $product_catalog
* @property \CakeProducts\Model\Entity\ParentProductCategory $parent_product_category * @property \CakeProducts\Model\Entity\ParentProductCategory $parent_product_category
* @property \CakeProducts\Model\Entity\ChildProductCategory[] $child_product_categories * @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(). * Fields that can be mass assigned using newEntity() or patchEntity().
* *
* Note that when '*' is set to true, this allows all unspecified fields to * 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> * @var array<string, bool>
*/ */
protected array $_accessible = [ protected array $_accessible = [
'product_catalog_id' => true, 'product_catalog_id' => true,
'internal_id' => true, 'internal_id' => true,
'name' => true, 'name' => true,
'category_description' => true, 'category_description' => true,
'default_product_type_id' => true, 'default_product_type_id' => true,
'parent_id' => true, 'parent_id' => true,
'lft' => true, 'lft' => true,
'rght' => true, 'rght' => true,
'enabled' => true, 'enabled' => true,
'deleted' => 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,
];
} }
+15 -15
View File
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity; namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity; use Cake\ORM\Entity;
/** /**
@@ -14,14 +13,14 @@ use Cake\ORM\Entity;
* @property string|null $product_category_id * @property string|null $product_category_id
* @property int $attribute_type_id * @property int $attribute_type_id
* @property bool $enabled * @property bool $enabled
* @property DateTime|null $deleted * @property \Cake\I18n\DateTime|null $deleted
* *
* @property ProductCategory $product_category * @property ProductCategory $product_category
* @property ProductCategoryAttributeOption[] $product_category_attribute_options * @property ProductCategoryAttributeOption[] $product_category_attribute_options
*/ */
class ProductCategoryAttribute extends Entity class ProductCategoryAttribute extends Entity {
{
/** /**
* Fields that can be mass assigned using newEntity() or patchEntity(). * Fields that can be mass assigned using newEntity() or patchEntity().
* *
* Note that when '*' is set to true, this allows all unspecified fields to * 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> * @var array<string, bool>
*/ */
protected array $_accessible = [ protected array $_accessible = [
'name' => true, 'name' => true,
'product_category_id' => true, 'product_category_id' => true,
'attribute_type_id' => true, 'attribute_type_id' => true,
'enabled' => true, 'enabled' => true,
'deleted' => 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; namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity; use Cake\ORM\Entity;
/** /**
@@ -14,13 +13,13 @@ use Cake\ORM\Entity;
* @property string $attribute_value * @property string $attribute_value
* @property string $attribute_label * @property string $attribute_label
* @property bool $enabled * @property bool $enabled
* @property DateTime|null $deleted * @property \Cake\I18n\DateTime|null $deleted
* *
* @property ProductCategoryAttribute $product_category_attribute * @property ProductCategoryAttribute $product_category_attribute
*/ */
class ProductCategoryAttributeOption extends Entity class ProductCategoryAttributeOption extends Entity {
{
/** /**
* Fields that can be mass assigned using newEntity() or patchEntity(). * Fields that can be mass assigned using newEntity() or patchEntity().
* *
* Note that when '*' is set to true, this allows all unspecified fields to * 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> * @var array<string, bool>
*/ */
protected array $_accessible = [ protected array $_accessible = [
'product_category_attribute_id' => true, 'product_category_attribute_id' => true,
'attribute_value' => true, 'attribute_value' => true,
'attribute_label' => true, 'attribute_label' => true,
'enabled' => true, 'enabled' => true,
'deleted' => true, 'deleted' => true,
// entities
'product_category_attribute' => true,
];
// entities
'product_category_attribute' => true,
];
} }
+17 -17
View File
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity; namespace CakeProducts\Model\Entity;
use Cake\Datasource\EntityInterface;
use Cake\ORM\Entity; use Cake\ORM\Entity;
/** /**
@@ -16,12 +15,12 @@ use Cake\ORM\Entity;
* @property bool $enabled * @property bool $enabled
* @property bool $is_system_variant * @property bool $is_system_variant
* *
* @property ProductCategory|EntityInterface $product_category * @property ProductCategory|\Cake\Datasource\EntityInterface $product_category
* @property ProductCategoryVariantOption[]|EntityInterface[] $product_category_variant_options * @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(). * Fields that can be mass assigned using newEntity() or patchEntity().
* *
* Note that when '*' is set to true, this allows all unspecified fields to * 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> * @var array<string, bool>
*/ */
protected array $_accessible = [ protected array $_accessible = [
'name' => true, 'name' => true,
'product_category_id' => true, 'product_category_id' => true,
'product_id' => true, 'product_id' => true,
'enabled' => true, 'enabled' => true,
'is_system_variant' => 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 * @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(). * Fields that can be mass assigned using newEntity() or patchEntity().
* *
* Note that when '*' is set to true, this allows all unspecified fields to * 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> * @var array<string, bool>
*/ */
protected array $_accessible = [ protected array $_accessible = [
'product_category_variant_id' => true, 'product_category_variant_id' => true,
'variant_value' => true, 'variant_value' => true,
'created' => true, 'created' => true,
'modified' => true, 'modified' => true,
'deleted' => true, 'deleted' => true,
// entities
'product_category_variant' => false,
];
// entities
'product_category_variant' => false,
];
} }
+26 -26
View File
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity; namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity; use Cake\ORM\Entity;
/** /**
@@ -20,17 +19,17 @@ use Cake\ORM\Entity;
* @property bool $primary_sku_photo * @property bool $primary_sku_photo
* @property int $photo_position * @property int $photo_position
* @property bool $enabled * @property bool $enabled
* @property DateTime $created * @property \Cake\I18n\DateTime $created
* @property DateTime|null $modified * @property \Cake\I18n\DateTime|null $modified
* @property DateTime|null $deleted * @property \Cake\I18n\DateTime|null $deleted
* *
* @property Product|null $product * @property Product|null $product
* @property ProductSku|null $product_sku * @property ProductSku|null $product_sku
* @property ProductCategory $product_category * @property ProductCategory $product_category
*/ */
class ProductPhoto extends Entity class ProductPhoto extends Entity {
{
/** /**
* Fields that can be mass assigned using newEntity() or patchEntity(). * Fields that can be mass assigned using newEntity() or patchEntity().
* *
* Note that when '*' is set to true, this allows all unspecified fields to * 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> * @var array<string, bool>
*/ */
protected array $_accessible = [ protected array $_accessible = [
'product_id' => true, 'product_id' => true,
'product_sku_id' => true, 'product_sku_id' => true,
'product_category_id' => true, 'product_category_id' => true,
'photo_dir' => true, 'photo_dir' => true,
'photo_filename' => true, 'photo_filename' => true,
'primary_photo' => true, 'primary_photo' => true,
'primary_category_photo' => true, 'primary_category_photo' => true,
'primary_sku_photo' => true, 'primary_sku_photo' => true,
'photo_position' => true, 'photo_position' => true,
'enabled' => true, 'enabled' => true,
'created' => true, 'created' => true,
'modified' => true, 'modified' => true,
'deleted' => true, 'deleted' => true,
// entities
'product' => false,
'product_sku' => false,
'product_category' => false,
];
// entities
'product' => false,
'product_sku' => false,
'product_category' => false,
];
} }
+21 -21
View File
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity; namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity; use Cake\ORM\Entity;
/** /**
@@ -15,17 +14,17 @@ use Cake\ORM\Entity;
* @property string|null $barcode * @property string|null $barcode
* @property string|null $price * @property string|null $price
* @property string|null $cost * @property string|null $cost
* @property DateTime $created * @property \Cake\I18n\DateTime $created
* @property DateTime|null $modified * @property \Cake\I18n\DateTime|null $modified
* @property DateTime|null $deleted * @property \Cake\I18n\DateTime|null $deleted
* @property bool $default_sku * @property bool $default_sku
* *
* @property Product $product * @property Product $product
* @property ProductSkuVariantValue[] $product_sku_variant_values * @property ProductSkuVariantValue[] $product_sku_variant_values
*/ */
class ProductSku extends Entity class ProductSku extends Entity {
{
/** /**
* Fields that can be mass assigned using newEntity() or patchEntity(). * Fields that can be mass assigned using newEntity() or patchEntity().
* *
* Note that when '*' is set to true, this allows all unspecified fields to * 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> * @var array<string, bool>
*/ */
protected array $_accessible = [ protected array $_accessible = [
'product_id' => true, 'product_id' => true,
'sku' => true, 'sku' => true,
'barcode' => true, 'barcode' => true,
'price' => true, 'price' => true,
'cost' => true, 'cost' => true,
'created' => true, 'created' => true,
'modified' => true, 'modified' => true,
'deleted' => true, 'deleted' => true,
'default_sku' => true, 'default_sku' => true,
// entities
'product' => false,
'product_sku_variant_values' => true,
];
// entities
'product' => false,
'product_sku_variant_values' => true,
];
} }
+13 -12
View File
@@ -17,9 +17,9 @@ use Cake\ORM\Entity;
* @property ProductCategoryVariant $product_category_variant * @property ProductCategoryVariant $product_category_variant
* @property ProductCategoryVariantOption $product_category_variant_option * @property ProductCategoryVariantOption $product_category_variant_option
*/ */
class ProductSkuVariantValue extends Entity class ProductSkuVariantValue extends Entity {
{
/** /**
* Fields that can be mass assigned using newEntity() or patchEntity(). * Fields that can be mass assigned using newEntity() or patchEntity().
* *
* Note that when '*' is set to true, this allows all unspecified fields to * 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> * @var array<string, bool>
*/ */
protected array $_accessible = [ protected array $_accessible = [
'product_sku_id' => true, 'product_sku_id' => true,
'product_variant_id' => true, 'product_variant_id' => true,
'product_category_variant_option_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,
];
} }
+12 -11
View File
@@ -17,9 +17,9 @@ use Cake\ORM\Entity;
* @property \App\Model\Entity\ProductCategoryVariant $product_category_variant * @property \App\Model\Entity\ProductCategoryVariant $product_category_variant
* @property \App\Model\Entity\Product $product * @property \App\Model\Entity\Product $product
*/ */
class ProductVariant extends Entity class ProductVariant extends Entity {
{
/** /**
* Fields that can be mass assigned using newEntity() or patchEntity(). * Fields that can be mass assigned using newEntity() or patchEntity().
* *
* Note that when '*' is set to true, this allows all unspecified fields to * 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> * @var array<string, bool>
*/ */
protected array $_accessible = [ protected array $_accessible = [
'name' => true, 'name' => true,
'product_category_variant_id' => true, 'product_category_variant_id' => true,
'product_id' => true, 'product_id' => true,
'enabled' => true, 'enabled' => true,
'product_category_variant' => true, 'product_category_variant' => true,
'product' => true, 'product' => true,
]; ];
} }
@@ -5,18 +5,10 @@ namespace CakeProducts\Model\Table;
use ArrayObject; use ArrayObject;
use Cake\Core\Configure; use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\Event\EventInterface; 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\RulesChecker;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\Validation\Validator; use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog;
use Closure;
use Psr\SimpleCache\CacheInterface;
/** /**
* ExternalProductCatalogsProductCatalogs Model * ExternalProductCatalogsProductCatalogs Model
@@ -24,15 +16,15 @@ use Psr\SimpleCache\CacheInterface;
* @property ExternalProductCatalogsTable&BelongsTo $ExternalProductCatalogs * @property ExternalProductCatalogsTable&BelongsTo $ExternalProductCatalogs
* @property ProductCatalogsTable&BelongsTo $ProductCatalogs * @property ProductCatalogsTable&BelongsTo $ProductCatalogs
* *
* @method ExternalProductCatalogsProductCatalog newEmptyEntity() * @method \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog newEmptyEntity()
* @method ExternalProductCatalogsProductCatalog newEntity(array $data, array $options = []) * @method \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog newEntity()
* @method array<ExternalProductCatalogsProductCatalog> newEntities(array $data, array $options = []) * @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 \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog get()
* @method ExternalProductCatalogsProductCatalog findOrCreate($search, ?callable $callback = null, array $options = []) * @method \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog findOrCreate()
* @method ExternalProductCatalogsProductCatalog patchEntity(EntityInterface $entity, array $data, array $options = []) * @method \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog patchEntity()
* @method array<ExternalProductCatalogsProductCatalog> patchEntities(iterable $entities, array $data, array $options = []) * @method array<ExternalProductCatalogsProductCatalog> patchEntities(iterable $entities, array $data, array $options = [])
* @method ExternalProductCatalogsProductCatalog|false save(EntityInterface $entity, 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>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ExternalProductCatalogsProductCatalog>|ResultSetInterface<ExternalProductCatalogsProductCatalog> saveManyOrFail(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 = []) * @method iterable<ExternalProductCatalogsProductCatalog>|ResultSetInterface<ExternalProductCatalogsProductCatalog>|false deleteMany(iterable $entities, array $options = [])
@@ -40,86 +32,86 @@ use Psr\SimpleCache\CacheInterface;
* *
* @mixin TimestampBehavior * @mixin TimestampBehavior
*/ */
class ExternalProductCatalogsProductCatalogsTable extends Table class ExternalProductCatalogsProductCatalogsTable extends Table {
{
/** /**
* Initialize method * Initialize method
* *
* @param array<string, mixed> $config The configuration for the Table. * @param array<string, mixed> $config The configuration for the Table.
* @return void * @return void
*/ */
public function initialize(array $config): void public function initialize(array $config): void {
{ parent::initialize($config);
parent::initialize($config);
$this->setTable('external_product_catalogs_product_catalogs'); $this->setTable('external_product_catalogs_product_catalogs');
$this->setDisplayField('external_product_catalog_id'); $this->setDisplayField('external_product_catalog_id');
$this->setPrimaryKey('id'); $this->setPrimaryKey('id');
$this->addBehavior('Timestamp'); $this->addBehavior('Timestamp');
$this->setEntityClass( $this->setEntityClass(
Configure::read('CakeProducts.ExternalProductCatalogsProductCatalogs.entity', 'CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog') Configure::read('CakeProducts.ExternalProductCatalogsProductCatalogs.entity', 'CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog'),
); );
$this->belongsTo('ExternalProductCatalogs', [ $this->belongsTo('ExternalProductCatalogs', [
'className' => 'CakeProducts.ExternalProductCatalogs', 'className' => 'CakeProducts.ExternalProductCatalogs',
// 'foreignKey' => 'external_product_catalog_id', // 'foreignKey' => 'external_product_catalog_id',
'joinType' => 'INNER', 'joinType' => 'INNER',
]); ]);
$this->belongsTo('ProductCatalogs', [ $this->belongsTo('ProductCatalogs', [
'className' => 'CakeProducts.ProductCatalogs', 'className' => 'CakeProducts.ProductCatalogs',
// 'foreignKey' => 'product_catalog_id', // 'foreignKey' => 'product_catalog_id',
'joinType' => 'INNER', 'joinType' => 'INNER',
]); ]);
$this->addBehavior('Muffin/Trash.Trash'); $this->addBehavior('Muffin/Trash.Trash');
} }
/** /**
* Default validation rules. * Default validation rules.
* *
* @param Validator $validator Validator instance. * @param \Cake\Validation\Validator $validator Validator instance.
* @return Validator * @return \Cake\Validation\Validator
*/ */
public function validationDefault(Validator $validator): Validator public function validationDefault(Validator $validator): Validator {
{ $validator
$validator ->uuid('external_product_catalog_id')
->uuid('external_product_catalog_id') ->notEmptyString('external_product_catalog_id');
->notEmptyString('external_product_catalog_id');
$validator $validator
->uuid('product_catalog_id') ->uuid('product_catalog_id')
->notEmptyString('product_catalog_id'); ->notEmptyString('product_catalog_id');
$validator $validator
->boolean('enabled'); ->boolean('enabled');
$validator $validator
->dateTime('deleted') ->dateTime('deleted')
->allowEmptyDateTime('deleted'); ->allowEmptyDateTime('deleted');
return $validator; return $validator;
} }
public function beforeMarshal(EventInterface $event, ArrayObject $data, ArrayObject $options) /**
{ * @return void
if (!isset($data['enabled'])) { */
$data['enabled'] = false; 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 * Returns a rules checker object that will be used for validating
* application integrity. * application integrity.
* *
* @param RulesChecker $rules The rules object to be modified. * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return RulesChecker * @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(['external_product_catalog_id'], 'ExternalProductCatalogs'), ['errorField' => 'external_product_catalog_id']);
// $rules->add($rules->existsIn(['product_catalog_id'], 'ProductCatalogs'), ['errorField' => '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; namespace CakeProducts\Model\Table;
use Cake\Core\Configure; 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\RulesChecker;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\Validation\Validator; use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ExternalProductCatalog;
use Closure;
use Psr\SimpleCache\CacheInterface;
/** /**
* ExternalProductCatalogs Model * ExternalProductCatalogs Model
* *
* @property ProductCatalogsTable&BelongsTo $ProductCatalogs * @property ProductCatalogsTable&BelongsTo $ProductCatalogs
* *
* @method ExternalProductCatalog newEmptyEntity() * @method \CakeProducts\Model\Entity\ExternalProductCatalog newEmptyEntity()
* @method ExternalProductCatalog newEntity(array $data, array $options = []) * @method \CakeProducts\Model\Entity\ExternalProductCatalog newEntity()
* @method array<ExternalProductCatalog> newEntities(array $data, array $options = []) * @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 \CakeProducts\Model\Entity\ExternalProductCatalog get()
* @method ExternalProductCatalog findOrCreate($search, ?callable $callback = null, array $options = []) * @method \CakeProducts\Model\Entity\ExternalProductCatalog findOrCreate()
* @method ExternalProductCatalog patchEntity(EntityInterface $entity, array $data, array $options = []) * @method \CakeProducts\Model\Entity\ExternalProductCatalog patchEntity()
* @method array<ExternalProductCatalog> patchEntities(iterable $entities, array $data, array $options = []) * @method array<ExternalProductCatalog> patchEntities(iterable $entities, array $data, array $options = [])
* @method ExternalProductCatalog|false save(EntityInterface $entity, 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>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ExternalProductCatalog>|ResultSetInterface<ExternalProductCatalog> saveManyOrFail(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 = []) * @method iterable<ExternalProductCatalog>|ResultSetInterface<ExternalProductCatalog>|false deleteMany(iterable $entities, array $options = [])
@@ -37,81 +29,79 @@ use Psr\SimpleCache\CacheInterface;
* *
* @mixin TimestampBehavior * @mixin TimestampBehavior
*/ */
class ExternalProductCatalogsTable extends Table class ExternalProductCatalogsTable extends Table {
{
/** /**
* Initialize method * Initialize method
* *
* @param array<string, mixed> $config The configuration for the Table. * @param array<string, mixed> $config The configuration for the Table.
* @return void * @return void
*/ */
public function initialize(array $config): void public function initialize(array $config): void {
{ parent::initialize($config);
parent::initialize($config);
$this->setTable('external_product_catalogs'); $this->setTable('external_product_catalogs');
$this->setDisplayField('base_url'); $this->setDisplayField('base_url');
$this->setPrimaryKey('id'); $this->setPrimaryKey('id');
$this->addBehavior('Timestamp'); $this->addBehavior('Timestamp');
$this->setEntityClass( $this->setEntityClass(
Configure::read('CakeProducts.ExternalProductCatalogs.entity', 'CakeProducts\Model\Entity\ExternalProductCatalog') Configure::read('CakeProducts.ExternalProductCatalogs.entity', 'CakeProducts\Model\Entity\ExternalProductCatalog'),
); );
$this->belongsToMany('ProductCatalogs', [ $this->belongsToMany('ProductCatalogs', [
'through' => 'ExternalProductCatalogsProductCatalogs', 'through' => 'ExternalProductCatalogsProductCatalogs',
'className' => 'CakeProducts.ProductCatalogs', 'className' => 'CakeProducts.ProductCatalogs',
]); ]);
$this->hasMany('ExternalProductCatalogsProductCatalogs', [ $this->hasMany('ExternalProductCatalogsProductCatalogs', [
'foreignKey' => 'external_product_catalog_id', 'foreignKey' => 'external_product_catalog_id',
'className' => 'CakeProducts.ExternalProductCatalogsProductCatalogs', 'className' => 'CakeProducts.ExternalProductCatalogsProductCatalogs',
'dependent' => true, 'dependent' => true,
'cascadeCallbacks' => true, 'cascadeCallbacks' => true,
]); ]);
$this->addBehavior('Muffin/Trash.Trash'); $this->addBehavior('Muffin/Trash.Trash');
} }
/** /**
* Default validation rules. * Default validation rules.
* *
* @param Validator $validator Validator instance. * @param \Cake\Validation\Validator $validator Validator instance.
* @return Validator * @return \Cake\Validation\Validator
*/ */
public function validationDefault(Validator $validator): Validator public function validationDefault(Validator $validator): Validator {
{ $validator
$validator ->scalar('base_url')
->scalar('base_url') ->maxLength('base_url', 255)
->maxLength('base_url', 255) ->requirePresence('base_url', 'create')
->requirePresence('base_url', 'create') ->notEmptyString('base_url');
->notEmptyString('base_url');
// ->url('base_url'); // ->url('base_url');
$validator $validator
->scalar('api_url') ->scalar('api_url')
->maxLength('api_url', 255) ->maxLength('api_url', 255)
->requirePresence('api_url', 'create') ->requirePresence('api_url', 'create')
->notEmptyString('api_url'); ->notEmptyString('api_url');
// ->url('api_url'); // ->url('api_url');
$validator $validator
->dateTime('deleted') ->dateTime('deleted')
->allowEmptyDateTime('deleted'); ->allowEmptyDateTime('deleted');
return $validator; return $validator;
} }
/** /**
* Returns a rules checker object that will be used for validating * Returns a rules checker object that will be used for validating
* application integrity. * application integrity.
* *
* @param RulesChecker $rules The rules object to be modified. * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return RulesChecker * @return \Cake\ORM\RulesChecker
*/ */
public function buildRules(RulesChecker $rules): RulesChecker public function buildRules(RulesChecker $rules): RulesChecker {
{ return $rules;
return $rules; }
}
} }
+54 -56
View File
@@ -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>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<\App\Model\Entity\ProductAttribute>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\ProductAttribute> deleteManyOrFail(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 * Initialize method
* *
* @param array<string, mixed> $config The configuration for the Table. * @param array<string, mixed> $config The configuration for the Table.
* @return void * @return void
*/ */
public function initialize(array $config): void public function initialize(array $config): void {
{ parent::initialize($config);
parent::initialize($config);
$this->setTable('product_attributes'); $this->setTable('product_attributes');
$this->setDisplayField('id'); $this->setDisplayField('id');
$this->setPrimaryKey('id'); $this->setPrimaryKey('id');
$this->setEntityClass( $this->setEntityClass(
Configure::read('CakeProducts.ProductAttributes.entity', 'CakeProducts\Model\Entity\ProductAttribute') Configure::read('CakeProducts.ProductAttributes.entity', 'CakeProducts\Model\Entity\ProductAttribute'),
); );
$this->belongsTo('Products', [ $this->belongsTo('Products', [
'foreignKey' => 'product_id', 'foreignKey' => 'product_id',
'className' => 'CakeProducts.Products', 'className' => 'CakeProducts.Products',
'joinType' => 'INNER', 'joinType' => 'INNER',
]); ]);
$this->belongsTo('ProductCategoryAttributes', [ $this->belongsTo('ProductCategoryAttributes', [
'foreignKey' => 'product_category_attribute_id', 'foreignKey' => 'product_category_attribute_id',
'className' => 'CakeProducts.ProductCategoryAttributes', 'className' => 'CakeProducts.ProductCategoryAttributes',
'joinType' => 'INNER', 'joinType' => 'INNER',
]); ]);
$this->belongsTo('ProductCategoryAttributeOptions', [ $this->belongsTo('ProductCategoryAttributeOptions', [
'foreignKey' => 'product_category_attribute_option_id', 'foreignKey' => 'product_category_attribute_option_id',
'className' => 'CakeProducts.ProductCategoryAttributeOptions', 'className' => 'CakeProducts.ProductCategoryAttributeOptions',
]); ]);
} }
/** /**
* Default validation rules. * Default validation rules.
* *
* @param \Cake\Validation\Validator $validator Validator instance. * @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator * @return \Cake\Validation\Validator
*/ */
public function validationDefault(Validator $validator): Validator public function validationDefault(Validator $validator): Validator {
{ $validator
$validator ->uuid('product_id')
->uuid('product_id') ->notEmptyString('product_id');
->notEmptyString('product_id');
$validator $validator
->uuid('product_category_attribute_id') ->uuid('product_category_attribute_id')
->notEmptyString('product_category_attribute_id'); ->notEmptyString('product_category_attribute_id');
$validator $validator
->scalar('attribute_value') ->scalar('attribute_value')
->maxLength('attribute_value', 255) ->maxLength('attribute_value', 255)
->allowEmptyString('attribute_value'); ->allowEmptyString('attribute_value');
$validator $validator
->uuid('product_category_attribute_option_id') ->uuid('product_category_attribute_option_id')
->allowEmptyString('product_category_attribute_option_id'); ->allowEmptyString('product_category_attribute_option_id');
$validator $validator
->dateTime('deleted') ->dateTime('deleted')
->allowEmptyDateTime('deleted'); ->allowEmptyDateTime('deleted');
return $validator; return $validator;
} }
/** /**
* Returns a rules checker object that will be used for validating * Returns a rules checker object that will be used for validating
* application integrity. * application integrity.
* *
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified. * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return \Cake\ORM\RulesChecker * @return \Cake\ORM\RulesChecker
*/ */
public function buildRules(RulesChecker $rules): RulesChecker public function buildRules(RulesChecker $rules): RulesChecker {
{ $rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
$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_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']); $rules->add($rules->existsIn(['product_category_attribute_option_id'], 'ProductCategoryAttributeOptions'), ['errorField' => 'product_category_attribute_option_id']);
$rules->add($rules->existsIn(['product_category_attribute_option_id'], 'ProductCategoryAttributeOptions'), ['errorField' => 'product_category_attribute_option_id']);
return $rules;
}
return $rules;
}
} }
+57 -65
View File
@@ -4,106 +4,98 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table; namespace CakeProducts\Model\Table;
use Cake\Core\Configure; use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker; use Cake\ORM\RulesChecker;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\Validation\Validator; use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductCatalog;
use Closure;
use Psr\SimpleCache\CacheInterface;
/** /**
* ProductCatalogs Model * ProductCatalogs Model
* *
* @method ProductCatalog newEmptyEntity() * @method \CakeProducts\Model\Entity\ProductCatalog newEmptyEntity()
* @method ProductCatalog newEntity(array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductCatalog newEntity()
* @method array<ProductCatalog> newEntities(array $data, array $options = []) * @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 \CakeProducts\Model\Entity\ProductCatalog get()
* @method ProductCatalog findOrCreate($search, ?callable $callback = null, array $options = []) * @method \CakeProducts\Model\Entity\ProductCatalog findOrCreate()
* @method ProductCatalog patchEntity(EntityInterface $entity, array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductCatalog patchEntity()
* @method array<ProductCatalog> patchEntities(iterable $entities, array $data, array $options = []) * @method array<ProductCatalog> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductCatalog|false save(EntityInterface $entity, 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>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductCatalog>|ResultSetInterface<ProductCatalog> saveManyOrFail(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>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductCatalog>|ResultSetInterface<ProductCatalog> deleteManyOrFail(iterable $entities, array $options = []) * @method iterable<ProductCatalog>|ResultSetInterface<ProductCatalog> deleteManyOrFail(iterable $entities, array $options = [])
*/ */
class ProductCatalogsTable extends Table class ProductCatalogsTable extends Table {
{
/** /**
* Initialize method * Initialize method
* *
* @param array<string, mixed> $config The configuration for the Table. * @param array<string, mixed> $config The configuration for the Table.
* @return void * @return void
*/ */
public function initialize(array $config): void public function initialize(array $config): void {
{ parent::initialize($config);
parent::initialize($config);
$this->setTable('product_catalogs'); $this->setTable('product_catalogs');
$this->setDisplayField('name'); $this->setDisplayField('name');
$this->setPrimaryKey('id'); $this->setPrimaryKey('id');
$this->setEntityClass( $this->setEntityClass(
Configure::read('CakeProducts.ProductCatalogs.entity', 'CakeProducts\Model\Entity\ProductCatalog') Configure::read('CakeProducts.ProductCatalogs.entity', 'CakeProducts\Model\Entity\ProductCatalog'),
); );
$this->hasMany('ProductCategories', [ $this->hasMany('ProductCategories', [
'className' => 'CakeProducts.ProductCategories', 'className' => 'CakeProducts.ProductCategories',
]); ]);
$this->belongsToMany('ExternalProductCatalogs', [ $this->belongsToMany('ExternalProductCatalogs', [
'through' => 'ExternalProductCatalogsProductCatalogs', 'through' => 'ExternalProductCatalogsProductCatalogs',
'className' => 'CakeProducts.ExternalProductCatalogs', 'className' => 'CakeProducts.ExternalProductCatalogs',
]); ]);
$this->addBehavior('Muffin/Trash.Trash'); $this->addBehavior('Muffin/Trash.Trash');
} }
/** /**
* Default validation rules. * Default validation rules.
* *
* @param Validator $validator Validator instance. * @param \Cake\Validation\Validator $validator Validator instance.
* @return Validator * @return \Cake\Validation\Validator
*/ */
public function validationDefault(Validator $validator): Validator public function validationDefault(Validator $validator): Validator {
{ $validator
$validator ->scalar('name')
->scalar('name') ->maxLength('name', 255)
->maxLength('name', 255) ->requirePresence('name', 'create')
->requirePresence('name', 'create') ->notEmptyString('name')
->notEmptyString('name') ->add('name', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']);
->add('name', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']);
$validator $validator
->scalar('catalog_description') ->scalar('catalog_description')
->maxLength('catalog_description', 255) ->maxLength('catalog_description', 255)
->allowEmptyString('catalog_description'); ->allowEmptyString('catalog_description');
$validator $validator
->boolean('enabled') ->boolean('enabled')
->requirePresence('enabled', 'create') ->requirePresence('enabled', 'create')
->notEmptyString('enabled'); ->notEmptyString('enabled');
$validator $validator
->dateTime('deleted') ->dateTime('deleted')
->allowEmptyDateTime('deleted'); ->allowEmptyDateTime('deleted');
return $validator; return $validator;
} }
/** /**
* Returns a rules checker object that will be used for validating * Returns a rules checker object that will be used for validating
* application integrity. * application integrity.
* *
* @param RulesChecker $rules The rules object to be modified. * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return RulesChecker * @return \Cake\ORM\RulesChecker
*/ */
public function buildRules(RulesChecker $rules): RulesChecker public function buildRules(RulesChecker $rules): RulesChecker {
{ $rules->add($rules->isUnique(['name']), ['errorField' => 'name']);
$rules->add($rules->isUnique(['name']), ['errorField' => 'name']);
return $rules;
}
return $rules;
}
} }
+133 -145
View File
@@ -6,18 +6,10 @@ namespace CakeProducts\Model\Table;
use Cake\Core\Configure; use Cake\Core\Configure;
use Cake\Database\Type\EnumType; use Cake\Database\Type\EnumType;
use Cake\Datasource\EntityInterface; 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\RulesChecker;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\Validation\Validator; use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductCategory;
use CakeProducts\Model\Enum\ProductProductTypeId; use CakeProducts\Model\Enum\ProductProductTypeId;
use Closure;
use Psr\SimpleCache\CacheInterface;
/** /**
* ProductCategories Model * ProductCategories Model
@@ -26,14 +18,14 @@ use Psr\SimpleCache\CacheInterface;
* @property ProductCategoriesTable&BelongsTo $ParentProductCategories * @property ProductCategoriesTable&BelongsTo $ParentProductCategories
* @property ProductCategoriesTable&HasMany $ChildProductCategories * @property ProductCategoriesTable&HasMany $ChildProductCategories
* *
* @method ProductCategory newEmptyEntity() * @method \CakeProducts\Model\Entity\ProductCategory newEmptyEntity()
* @method ProductCategory newEntity(array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategory newEntity()
* @method array<ProductCategory> newEntities(array $data, array $options = []) * @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 \CakeProducts\Model\Entity\ProductCategory get()
* @method ProductCategory findOrCreate($search, ?callable $callback = null, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategory findOrCreate()
* @method ProductCategory patchEntity(EntityInterface $entity, array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategory patchEntity()
* @method array<ProductCategory> patchEntities(iterable $entities, array $data, array $options = []) * @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>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductCategory>|ResultSetInterface<ProductCategory> saveManyOrFail(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 = []) * @method iterable<ProductCategory>|ResultSetInterface<ProductCategory>|false deleteMany(iterable $entities, array $options = [])
@@ -41,175 +33,171 @@ use Psr\SimpleCache\CacheInterface;
* *
* @mixin TreeBehavior * @mixin TreeBehavior
*/ */
class ProductCategoriesTable extends Table class ProductCategoriesTable extends Table {
{
/** /**
* Current scope for Tree behavior - per catalog * Current scope for Tree behavior - per catalog
* *
* @var string * @var string
*/ */
protected $treeCatalogId; protected $treeCatalogId;
/** /**
* Initialize method * Initialize method
* *
* @param array<string, mixed> $config The configuration for the Table. * @param array<string, mixed> $config The configuration for the Table.
* @return void * @return void
*/ */
public function initialize(array $config): void public function initialize(array $config): void {
{ parent::initialize($config);
parent::initialize($config); $this->treeCatalogId = 1;
$this->treeCatalogId = 1;
$this->setTable('product_categories'); $this->setTable('product_categories');
$this->setDisplayField('name'); $this->setDisplayField('name');
$this->setPrimaryKey('id'); $this->setPrimaryKey('id');
$this->setEntityClass( $this->setEntityClass(
Configure::read('CakeProducts.ProductCategories.entity', 'CakeProducts\Model\Entity\ProductCategory') Configure::read('CakeProducts.ProductCategories.entity', 'CakeProducts\Model\Entity\ProductCategory'),
); );
$this->addBehavior('Tree', [ $this->addBehavior('Tree', [
'cascadeCallbacks' => true, 'cascadeCallbacks' => true,
]); ]);
$this->belongsTo('ProductCatalogs', [ $this->belongsTo('ProductCatalogs', [
'foreignKey' => 'product_catalog_id', 'foreignKey' => 'product_catalog_id',
'joinType' => 'INNER', 'joinType' => 'INNER',
'className' => 'CakeProducts.ProductCatalogs', 'className' => 'CakeProducts.ProductCatalogs',
]); ]);
$this->belongsTo('ParentProductCategories', [ $this->belongsTo('ParentProductCategories', [
'className' => 'CakeProducts.ProductCategories', 'className' => 'CakeProducts.ProductCategories',
'foreignKey' => 'parent_id', 'foreignKey' => 'parent_id',
]); ]);
$this->hasMany('ChildProductCategories', [ $this->hasMany('ChildProductCategories', [
'className' => 'CakeProducts.ProductCategories', 'className' => 'CakeProducts.ProductCategories',
'foreignKey' => 'parent_id', 'foreignKey' => 'parent_id',
'dependent' => true, 'dependent' => true,
'cascadeCallbacks' => true, 'cascadeCallbacks' => true,
]); ]);
$this->hasMany('ProductCategoryAttributes', [ $this->hasMany('ProductCategoryAttributes', [
'foreignKey' => 'product_category_id', 'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id', 'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductCategoryAttributes', 'className' => 'CakeProducts.ProductCategoryAttributes',
'dependent' => true, 'dependent' => true,
'cascadeCallbacks' => true, 'cascadeCallbacks' => true,
]); ]);
$this->hasMany('ProductCategoryVariants', [ $this->hasMany('ProductCategoryVariants', [
'foreignKey' => 'product_category_id', 'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id', 'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductCategoryVariants', 'className' => 'CakeProducts.ProductCategoryVariants',
'dependent' => true, 'dependent' => true,
'cascadeCallbacks' => true, 'cascadeCallbacks' => true,
]); ]);
$this->hasMany('Products', [ $this->hasMany('Products', [
'foreignKey' => 'product_category_id', 'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id', 'bindingKey' => 'internal_id',
'className' => 'CakeProducts.Products', 'className' => 'CakeProducts.Products',
'dependent' => true, 'dependent' => true,
'cascadeCallbacks' => true, 'cascadeCallbacks' => true,
]); ]);
$this->hasMany('ProductPhotos', [ $this->hasMany('ProductPhotos', [
'foreignKey' => 'product_category_id', 'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id', 'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductPhotos', 'className' => 'CakeProducts.ProductPhotos',
'dependent' => true, 'dependent' => true,
'cascadeCallbacks' => true, 'cascadeCallbacks' => true,
]); ]);
$this->hasOne('PrimaryProductPhotos', [ $this->hasOne('PrimaryProductPhotos', [
'foreignKey' => 'product_category_id', 'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id', 'bindingKey' => 'internal_id',
'conditions' => ['PrimaryProductPhotos.primary_category_photo' => true], 'conditions' => ['PrimaryProductPhotos.primary_category_photo' => true],
'className' => 'CakeProducts.ProductPhotos', 'className' => 'CakeProducts.ProductPhotos',
'dependent' => true, '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->behaviors()->Tree->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]);
$this->addBehavior('Muffin/Trash.Trash'); $this->addBehavior('Muffin/Trash.Trash');
} }
/** /**
* Default validation rules. * Default validation rules.
* *
* @param Validator $validator Validator instance. * @param \Cake\Validation\Validator $validator Validator instance.
* @return Validator * @return \Cake\Validation\Validator
*/ */
public function validationDefault(Validator $validator): Validator public function validationDefault(Validator $validator): Validator {
{ $validator
$validator ->uuid('product_catalog_id')
->uuid('product_catalog_id') ->notEmptyString('product_catalog_id');
->notEmptyString('product_catalog_id');
$validator $validator
->scalar('name') ->scalar('name')
->maxLength('name', 255) ->maxLength('name', 255)
->requirePresence('name', 'create') ->requirePresence('name', 'create')
->notEmptyString('name'); ->notEmptyString('name');
$validator $validator
->scalar('category_description') ->scalar('category_description')
->allowEmptyString('category_description'); ->allowEmptyString('category_description');
$validator $validator
->integer('parent_id') ->integer('parent_id')
->allowEmptyString('parent_id'); ->allowEmptyString('parent_id');
$validator $validator
->boolean('enabled') ->boolean('enabled')
->notEmptyString('enabled'); ->notEmptyString('enabled');
$validator $validator
->dateTime('deleted') ->dateTime('deleted')
->allowEmptyDateTime('deleted'); ->allowEmptyDateTime('deleted');
$validator $validator
->integer('default_product_type_id') ->integer('default_product_type_id')
->allowEmptyString('default_product_type_id'); ->allowEmptyString('default_product_type_id');
return $validator; return $validator;
} }
/** /**
* Returns a rules checker object that will be used for validating * Returns a rules checker object that will be used for validating
* application integrity. * application integrity.
* *
* @param RulesChecker $rules The rules object to be modified. * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return RulesChecker * @return \Cake\ORM\RulesChecker
*/ */
public function buildRules(RulesChecker $rules): RulesChecker public function buildRules(RulesChecker $rules): RulesChecker {
{ $rules->add($rules->isUnique(['product_catalog_id', 'name']), ['errorField' => 'product_catalog_id']);
$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(['product_catalog_id'], 'ProductCatalogs'), ['errorField' => 'product_catalog_id']); $rules->add($rules->existsIn(['parent_id'], 'ParentProductCategories'), ['errorField' => 'parent_id']);
$rules->add($rules->existsIn(['parent_id'], 'ParentProductCategories'), ['errorField' => 'parent_id']);
return $rules; return $rules;
} }
/** /**
* @param int $catalogId * @param string $catalogId
* *
* @return void * @return void
*/ */
public function setConfigureCatalogId(string $catalogId) public function setConfigureCatalogId(string $catalogId) {
{ $this->treeCatalogId = $catalogId;
$this->treeCatalogId = $catalogId; $this->behaviors()->Tree->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]);
$this->behaviors()->Tree->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]); }
}
/** /**
* @param EntityInterface $entity * @param \Cake\Datasource\EntityInterface $entity
* @param array $options * @param array $options
* *
* @return EntityInterface|false * @return \Cake\Datasource\EntityInterface|false
*/ */
public function save(EntityInterface $entity, array $options = []): EntityInterface|false public function save(EntityInterface $entity, array $options = []): EntityInterface|false {
{ $this->behaviors()->get('Tree')->setConfig([
$this->behaviors()->get('Tree')->setConfig([ 'scope' => [
'scope' => [ 'product_catalog_id' => $entity->product_catalog_id,
'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; namespace CakeProducts\Model\Table;
use Cake\Core\Configure; 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\RulesChecker;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\Validation\Validator; use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductCategoryAttributeOption;
use Closure;
use Psr\SimpleCache\CacheInterface;
/** /**
* ProductCategoryAttributeOptions Model * ProductCategoryAttributeOptions Model
* *
* @property ProductCategoryAttributesTable&BelongsTo $ProductCategoryAttributes * @property ProductCategoryAttributesTable&BelongsTo $ProductCategoryAttributes
* *
* @method ProductCategoryAttributeOption newEmptyEntity() * @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption newEmptyEntity()
* @method ProductCategoryAttributeOption newEntity(array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption newEntity()
* @method array<ProductCategoryAttributeOption> newEntities(array $data, array $options = []) * @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 \CakeProducts\Model\Entity\ProductCategoryAttributeOption get()
* @method ProductCategoryAttributeOption findOrCreate($search, ?callable $callback = null, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption findOrCreate()
* @method ProductCategoryAttributeOption patchEntity(EntityInterface $entity, array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption patchEntity()
* @method array<ProductCategoryAttributeOption> patchEntities(iterable $entities, array $data, array $options = []) * @method array<ProductCategoryAttributeOption> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductCategoryAttributeOption|false save(EntityInterface $entity, 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>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryAttributeOption>|ResultSetInterface<ProductCategoryAttributeOption> saveManyOrFail(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>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryAttributeOption>|ResultSetInterface<ProductCategoryAttributeOption> deleteManyOrFail(iterable $entities, array $options = []) * @method iterable<ProductCategoryAttributeOption>|ResultSetInterface<ProductCategoryAttributeOption> deleteManyOrFail(iterable $entities, array $options = [])
*/ */
class ProductCategoryAttributeOptionsTable extends Table class ProductCategoryAttributeOptionsTable extends Table {
{
/** /**
* Initialize method * Initialize method
* *
* @param array<string, mixed> $config The configuration for the Table. * @param array<string, mixed> $config The configuration for the Table.
* @return void * @return void
*/ */
public function initialize(array $config): void public function initialize(array $config): void {
{ parent::initialize($config);
parent::initialize($config);
$this->setTable('product_category_attribute_options'); $this->setTable('product_category_attribute_options');
$this->setDisplayField('attribute_value'); $this->setDisplayField('attribute_value');
$this->setPrimaryKey('id'); $this->setPrimaryKey('id');
$this->setEntityClass( $this->setEntityClass(
Configure::read('CakeProducts.ProductCategoryAttributeOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryAttributeOption') Configure::read('CakeProducts.ProductCategoryAttributeOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryAttributeOption'),
); );
$this->belongsTo('ProductCategoryAttributes', [ $this->belongsTo('ProductCategoryAttributes', [
'foreignKey' => 'product_category_attribute_id', 'foreignKey' => 'product_category_attribute_id',
'joinType' => 'INNER', 'joinType' => 'INNER',
'className' => 'CakeProducts.ProductCategoryAttributes', 'className' => 'CakeProducts.ProductCategoryAttributes',
]); ]);
$this->addBehavior('Muffin/Trash.Trash'); $this->addBehavior('Muffin/Trash.Trash');
} }
/** /**
* Default validation rules. * Default validation rules.
* *
* @param Validator $validator Validator instance. * @param \Cake\Validation\Validator $validator Validator instance.
* @return Validator * @return \Cake\Validation\Validator
*/ */
public function validationDefault(Validator $validator): Validator public function validationDefault(Validator $validator): Validator {
{ $validator
$validator ->uuid('product_category_attribute_id')
->uuid('product_category_attribute_id') ->notEmptyString('product_category_attribute_id');
->notEmptyString('product_category_attribute_id');
$validator $validator
->scalar('attribute_value') ->scalar('attribute_value')
->maxLength('attribute_value', 255) ->maxLength('attribute_value', 255)
->requirePresence('attribute_value', 'create') ->requirePresence('attribute_value', 'create')
->notEmptyString('attribute_value'); ->notEmptyString('attribute_value');
$validator $validator
->scalar('attribute_label') ->scalar('attribute_label')
->maxLength('attribute_label', 255) ->maxLength('attribute_label', 255)
->requirePresence('attribute_label', 'create') ->requirePresence('attribute_label', 'create')
->notEmptyString('attribute_label'); ->notEmptyString('attribute_label');
$validator $validator
->boolean('enabled') ->boolean('enabled')
->notEmptyString('enabled'); ->notEmptyString('enabled');
$validator $validator
->dateTime('deleted') ->dateTime('deleted')
->allowEmptyDateTime('deleted'); ->allowEmptyDateTime('deleted');
return $validator; return $validator;
} }
/** /**
* Returns a rules checker object that will be used for validating * Returns a rules checker object that will be used for validating
* application integrity. * application integrity.
* *
* @param RulesChecker $rules The rules object to be modified. * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return RulesChecker * @return \Cake\ORM\RulesChecker
*/ */
public function buildRules(RulesChecker $rules): RulesChecker public function buildRules(RulesChecker $rules): RulesChecker {
{ $rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']);
$rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']); $rules->add($rules->isUnique(['attribute_value', '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\Core\Configure;
use Cake\Database\Type\EnumType; 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\Query\SelectQuery;
use Cake\ORM\RulesChecker; use Cake\ORM\RulesChecker;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\Validation\Validator; use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductCategoryAttribute;
use CakeProducts\Model\Enum\ProductCategoryAttributeTypeId; use CakeProducts\Model\Enum\ProductCategoryAttributeTypeId;
use Closure;
use Psr\SimpleCache\CacheInterface;
/** /**
* ProductCategoryAttributes Model * ProductCategoryAttributes Model
* *
* @property ProductCategoriesTable&BelongsTo $ProductCategories * @property ProductCategoriesTable&BelongsTo $ProductCategories
* *
* @method ProductCategoryAttribute newEmptyEntity() * @method \CakeProducts\Model\Entity\ProductCategoryAttribute newEmptyEntity()
* @method ProductCategoryAttribute newEntity(array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryAttribute newEntity()
* @method array<ProductCategoryAttribute> newEntities(array $data, array $options = []) * @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 \CakeProducts\Model\Entity\ProductCategoryAttribute get()
* @method ProductCategoryAttribute findOrCreate($search, ?callable $callback = null, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryAttribute findOrCreate()
* @method ProductCategoryAttribute patchEntity(EntityInterface $entity, array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryAttribute patchEntity()
* @method array<ProductCategoryAttribute> patchEntities(iterable $entities, array $data, array $options = []) * @method array<ProductCategoryAttribute> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductCategoryAttribute|false save(EntityInterface $entity, 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>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryAttribute>|ResultSetInterface<ProductCategoryAttribute> saveManyOrFail(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>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryAttribute>|ResultSetInterface<ProductCategoryAttribute> deleteManyOrFail(iterable $entities, array $options = []) * @method iterable<ProductCategoryAttribute>|ResultSetInterface<ProductCategoryAttribute> deleteManyOrFail(iterable $entities, array $options = [])
*/ */
class ProductCategoryAttributesTable extends Table class ProductCategoryAttributesTable extends Table {
{
/** /**
* Initialize method * Initialize method
* *
* @param array<string, mixed> $config The configuration for the Table. * @param array<string, mixed> $config The configuration for the Table.
* @return void * @return void
*/ */
public function initialize(array $config): void public function initialize(array $config): void {
{ parent::initialize($config);
parent::initialize($config);
$this->setTable('product_category_attributes'); $this->setTable('product_category_attributes');
$this->setDisplayField('name'); $this->setDisplayField('name');
$this->setPrimaryKey('id'); $this->setPrimaryKey('id');
$this->setEntityClass( $this->setEntityClass(
Configure::read('CakeProducts.ProductCategoryAttributes.entity', 'CakeProducts\Model\Entity\ProductCategoryAttribute') Configure::read('CakeProducts.ProductCategoryAttributes.entity', 'CakeProducts\Model\Entity\ProductCategoryAttribute'),
); );
$this->belongsTo('ProductCategories', [ $this->belongsTo('ProductCategories', [
'foreignKey' => 'product_category_id', 'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id', 'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductCategories', 'className' => 'CakeProducts.ProductCategories',
]); ]);
$this->hasMany('ProductCategoryAttributeOptions', [ $this->hasMany('ProductCategoryAttributeOptions', [
'foreignKey' => 'product_category_attribute_id', 'foreignKey' => 'product_category_attribute_id',
'className' => 'CakeProducts.ProductCategoryAttributeOptions', 'className' => 'CakeProducts.ProductCategoryAttributeOptions',
'saveStrategy' => 'replace', 'saveStrategy' => 'replace',
'dependent' => true, 'dependent' => true,
'cascadeCallbacks' => true, 'cascadeCallbacks' => true,
]); ]);
$this->getSchema()->setColumnType('attribute_type_id', EnumType::from(ProductCategoryAttributeTypeId::class)); $this->getSchema()->setColumnType('attribute_type_id', EnumType::from(ProductCategoryAttributeTypeId::class));
$this->addBehavior('Muffin/Trash.Trash'); $this->addBehavior('Muffin/Trash.Trash');
} }
/** /**
* Default validation rules. * Default validation rules.
* *
* @param Validator $validator Validator instance. * @param \Cake\Validation\Validator $validator Validator instance.
* @return Validator * @return \Cake\Validation\Validator
*/ */
public function validationDefault(Validator $validator): Validator public function validationDefault(Validator $validator): Validator {
{ $validator
$validator ->scalar('name')
->scalar('name') ->maxLength('name', 255)
->maxLength('name', 255) ->requirePresence('name', 'create')
->requirePresence('name', 'create') ->notEmptyString('name');
->notEmptyString('name');
$validator $validator
->uuid('product_category_id') ->uuid('product_category_id')
->allowEmptyString('product_category_id'); ->allowEmptyString('product_category_id');
$validator $validator
->integer('attribute_type_id') ->integer('attribute_type_id')
->requirePresence('attribute_type_id', 'create') ->requirePresence('attribute_type_id', 'create')
->notEmptyString('attribute_type_id'); ->notEmptyString('attribute_type_id');
$validator $validator
->boolean('enabled') ->boolean('enabled')
->requirePresence('enabled', 'create') ->requirePresence('enabled', 'create')
->notEmptyString('enabled'); ->notEmptyString('enabled');
$validator $validator
->dateTime('deleted') ->dateTime('deleted')
->allowEmptyDateTime('deleted'); ->allowEmptyDateTime('deleted');
return $validator; return $validator;
} }
/** /**
* Returns a rules checker object that will be used for validating * Returns a rules checker object that will be used for validating
* application integrity. * application integrity.
* *
* @param RulesChecker $rules The rules object to be modified. * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return RulesChecker * @return \Cake\ORM\RulesChecker
*/ */
public function buildRules(RulesChecker $rules): RulesChecker public function buildRules(RulesChecker $rules): RulesChecker {
{ $rules->add($rules->isUnique(['name', 'product_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'name']);
$rules->add($rules->isUnique(['name', 'product_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'name']); $rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
$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 * @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) public function findAllCategoryAttributesForCategoryId(SelectQuery $query, string $internalCategoryId) {
{ $category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail();
$category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail();
$this->ProductCategories->behaviors()->get('Tree')->setConfig([ $this->ProductCategories->behaviors()->get('Tree')->setConfig([
'scope' => [ 'scope' => [
'product_catalog_id' => $category->product_catalog_id ?? 1, '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; namespace CakeProducts\Model\Table;
use Cake\Core\Configure; 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\RulesChecker;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\Validation\Validator; use Cake\Validation\Validator;
use Closure;
use Psr\SimpleCache\CacheInterface;
/** /**
* ProductCategoryVariantOptions Model * ProductCategoryVariantOptions Model
* *
* @property ProductCategoryVariantsTable&BelongsTo $ProductCategoryVariants * @property ProductCategoryVariantsTable&BelongsTo $ProductCategoryVariants
* *
* @method ProductCategoryVariantOption newEmptyEntity() * @method \CakeProducts\Model\Entity\ProductCategoryVariantOption newEmptyEntity()
* @method ProductCategoryVariantOption newEntity(array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryVariantOption newEntity()
* @method array<ProductCategoryVariantOption> newEntities(array $data, array $options = []) * @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 \CakeProducts\Model\Entity\ProductCategoryVariantOption get()
* @method ProductCategoryVariantOption findOrCreate($search, ?callable $callback = null, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryVariantOption findOrCreate()
* @method ProductCategoryVariantOption patchEntity(EntityInterface $entity, array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryVariantOption patchEntity()
* @method array<ProductCategoryVariantOption> patchEntities(iterable $entities, array $data, array $options = []) * @method array<ProductCategoryVariantOption> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductCategoryVariantOption|false save(EntityInterface $entity, 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>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryVariantOption>|ResultSetInterface<ProductCategoryVariantOption> saveManyOrFail(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 = []) * @method iterable<ProductCategoryVariantOption>|ResultSetInterface<ProductCategoryVariantOption>|false deleteMany(iterable $entities, array $options = [])
@@ -38,75 +29,73 @@ use Psr\SimpleCache\CacheInterface;
* *
* @mixin TimestampBehavior * @mixin TimestampBehavior
*/ */
class ProductCategoryVariantOptionsTable extends Table class ProductCategoryVariantOptionsTable extends Table {
{
/** /**
* Initialize method * Initialize method
* *
* @param array<string, mixed> $config The configuration for the Table. * @param array<string, mixed> $config The configuration for the Table.
* @return void * @return void
*/ */
public function initialize(array $config): void public function initialize(array $config): void {
{ parent::initialize($config);
parent::initialize($config);
$this->setTable('product_category_variant_options'); $this->setTable('product_category_variant_options');
$this->setDisplayField('variant_value'); $this->setDisplayField('variant_value');
$this->setPrimaryKey('id'); $this->setPrimaryKey('id');
$this->setEntityClass( $this->setEntityClass(
Configure::read('CakeProducts.ProductCategoryVariantOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryVariantOption') Configure::read('CakeProducts.ProductCategoryVariantOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryVariantOption'),
); );
$this->addBehavior('Timestamp'); $this->addBehavior('Timestamp');
$this->belongsTo('ProductCategoryVariants', [ $this->belongsTo('ProductCategoryVariants', [
'foreignKey' => 'product_category_variant_id', 'foreignKey' => 'product_category_variant_id',
'joinType' => 'INNER', 'joinType' => 'INNER',
]); ]);
} }
/** /**
* Default validation rules. * Default validation rules.
* *
* @param Validator $validator Validator instance. * @param \Cake\Validation\Validator $validator Validator instance.
* @return Validator * @return \Cake\Validation\Validator
*/ */
public function validationDefault(Validator $validator): Validator public function validationDefault(Validator $validator): Validator {
{ $validator
$validator ->uuid('product_category_variant_id')
->uuid('product_category_variant_id') ->notEmptyString('product_category_variant_id');
->notEmptyString('product_category_variant_id');
$validator $validator
->scalar('variant_value') ->scalar('variant_value')
->maxLength('variant_value', 255) ->maxLength('variant_value', 255)
->requirePresence('variant_value', 'create') ->requirePresence('variant_value', 'create')
->notEmptyString('variant_value'); ->notEmptyString('variant_value');
$validator $validator
->scalar('variant_label') ->scalar('variant_label')
->maxLength('variant_label', 255) ->maxLength('variant_label', 255)
->allowEmptyString('variant_label'); ->allowEmptyString('variant_label');
$validator $validator
->dateTime('deleted') ->dateTime('deleted')
->allowEmptyDateTime('deleted'); ->allowEmptyDateTime('deleted');
return $validator; return $validator;
} }
/** /**
* Returns a rules checker object that will be used for validating * Returns a rules checker object that will be used for validating
* application integrity. * application integrity.
* *
* @param RulesChecker $rules The rules object to be modified. * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return RulesChecker * @return \Cake\ORM\RulesChecker
*/ */
public function buildRules(RulesChecker $rules): 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_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']); $rules->add($rules->isUnique(['variant_value', 'product_category_variant_id']));
$rules->add($rules->isUnique(['variant_value', 'product_category_variant_id']));
return $rules;
}
return $rules;
}
} }
+93 -104
View File
@@ -4,17 +4,10 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table; namespace CakeProducts\Model\Table;
use Cake\Core\Configure; 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\Query\SelectQuery;
use Cake\ORM\RulesChecker; use Cake\ORM\RulesChecker;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\Validation\Validator; use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductCategoryVariant;
use Closure;
use Psr\SimpleCache\CacheInterface;
/** /**
* ProductCategoryVariants Model * ProductCategoryVariants Model
@@ -22,143 +15,139 @@ use Psr\SimpleCache\CacheInterface;
* @property ProductCategoriesTable&BelongsTo $ProductCategories * @property ProductCategoriesTable&BelongsTo $ProductCategories
* @property ProductsTable&BelongsTo $Products * @property ProductsTable&BelongsTo $Products
* *
* @method ProductCategoryVariant newEmptyEntity() * @method \CakeProducts\Model\Entity\ProductCategoryVariant newEmptyEntity()
* @method ProductCategoryVariant newEntity(array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryVariant newEntity()
* @method array<ProductCategoryVariant> newEntities(array $data, array $options = []) * @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 \CakeProducts\Model\Entity\ProductCategoryVariant get()
* @method ProductCategoryVariant findOrCreate($search, ?callable $callback = null, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryVariant findOrCreate()
* @method ProductCategoryVariant patchEntity(EntityInterface $entity, array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryVariant patchEntity()
* @method array<ProductCategoryVariant> patchEntities(iterable $entities, array $data, array $options = []) * @method array<ProductCategoryVariant> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductCategoryVariant|false save(EntityInterface $entity, 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>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryVariant>|ResultSetInterface<ProductCategoryVariant> saveManyOrFail(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>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryVariant>|ResultSetInterface<ProductCategoryVariant> deleteManyOrFail(iterable $entities, array $options = []) * @method iterable<ProductCategoryVariant>|ResultSetInterface<ProductCategoryVariant> deleteManyOrFail(iterable $entities, array $options = [])
*/ */
class ProductCategoryVariantsTable extends Table class ProductCategoryVariantsTable extends Table {
{
/** /**
* Initialize method * Initialize method
* *
* @param array<string, mixed> $config The configuration for the Table. * @param array<string, mixed> $config The configuration for the Table.
* @return void * @return void
*/ */
public function initialize(array $config): void public function initialize(array $config): void {
{ parent::initialize($config);
parent::initialize($config);
$this->setTable('product_category_variants'); $this->setTable('product_category_variants');
$this->setDisplayField('name'); $this->setDisplayField('name');
$this->setPrimaryKey('id'); $this->setPrimaryKey('id');
$this->setEntityClass( $this->setEntityClass(
Configure::read('CakeProducts.ProductCategoryVariants.entity', 'CakeProducts\Model\Entity\ProductCategoryVariant') Configure::read('CakeProducts.ProductCategoryVariants.entity', 'CakeProducts\Model\Entity\ProductCategoryVariant'),
); );
$this->belongsTo('ProductCategories', [ $this->belongsTo('ProductCategories', [
'foreignKey' => 'product_category_id', 'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id', 'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductCategories', 'className' => 'CakeProducts.ProductCategories',
]); ]);
$this->belongsTo('Products', [ $this->belongsTo('Products', [
'foreignKey' => 'product_id', 'foreignKey' => 'product_id',
'className' => 'CakeProducts.Products', 'className' => 'CakeProducts.Products',
]); ]);
$this->hasMany('ProductCategoryVariantOptions', [ $this->hasMany('ProductCategoryVariantOptions', [
'foreignKey' => 'product_category_variant_id', 'foreignKey' => 'product_category_variant_id',
'className' => 'CakeProducts.ProductCategoryVariantOptions', 'className' => 'CakeProducts.ProductCategoryVariantOptions',
'dependent' => true, 'dependent' => true,
'cascadeCallbacks' => true, 'cascadeCallbacks' => true,
'saveStrategy' => 'replace', 'saveStrategy' => 'replace',
]); ]);
$this->hasMany('ProductVariants', [ $this->hasMany('ProductVariants', [
'foreignKey' => 'product_category_variant_id', 'foreignKey' => 'product_category_variant_id',
'className' => 'CakeProducts.ProductVariants', 'className' => 'CakeProducts.ProductVariants',
'dependent' => true, 'dependent' => true,
'cascadeCallbacks' => true, 'cascadeCallbacks' => true,
]); ]);
} }
/** /**
* Default validation rules. * Default validation rules.
* *
* @param Validator $validator Validator instance. * @param \Cake\Validation\Validator $validator Validator instance.
* @return Validator * @return \Cake\Validation\Validator
*/ */
public function validationDefault(Validator $validator): Validator public function validationDefault(Validator $validator): Validator {
{ $validator
$validator ->scalar('name')
->scalar('name') ->maxLength('name', 255)
->maxLength('name', 255) ->requirePresence('name', 'create')
->requirePresence('name', 'create') ->notEmptyString('name');
->notEmptyString('name');
$validator $validator
->uuid('product_category_id') ->uuid('product_category_id')
->allowEmptyString('product_category_id'); ->allowEmptyString('product_category_id');
$validator $validator
->uuid('product_id') ->uuid('product_id')
->allowEmptyString('product_id'); ->allowEmptyString('product_id');
$validator $validator
->boolean('is_system_variant') ->boolean('is_system_variant')
->allowEmptyString('is_system_variant'); ->allowEmptyString('is_system_variant');
$validator $validator
->boolean('enabled') ->boolean('enabled')
->requirePresence('enabled', 'create') ->requirePresence('enabled', 'create')
->notEmptyString('enabled'); ->notEmptyString('enabled');
return $validator; return $validator;
} }
/** /**
* Returns a rules checker object that will be used for validating * Returns a rules checker object that will be used for validating
* application integrity. * application integrity.
* *
* @param RulesChecker $rules The rules object to be modified. * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return RulesChecker * @return \Cake\ORM\RulesChecker
*/ */
public function buildRules(RulesChecker $rules): 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_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_category_id']); $rules->add($rules->isUnique(['name', 'product_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_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_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']); $rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_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 * @param string $internalCategoryId
* *
* @return array|Query|SelectQuery * @return Query|\Cake\ORM\Query\SelectQuery|array
*/ */
public function findAllCategoryVariantsForCategoryId(SelectQuery $query, string $internalCategoryId) public function findAllCategoryVariantsForCategoryId(SelectQuery $query, string $internalCategoryId) {
{ $category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail();
$category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail();
$this->ProductCategories->behaviors()->get('Tree')->setConfig([ $this->ProductCategories->behaviors()->get('Tree')->setConfig([
'scope' => [ 'scope' => [
'product_catalog_id' => $category->product_catalog_id ?? 1, 'product_catalog_id' => $category->product_catalog_id ?? 1,
], ],
]); ]);
return $this->ProductCategories return $this->ProductCategories
->find('path', for: $category->id) ->find('path', for: $category->id)
->contain(['ProductCategoryVariants']); ->contain(['ProductCategoryVariants']);
} }
/** /**
* @param string $internalCategoryId * @param string $internalCategoryId
* @return array * @return array
*/ */
public function getAllCategoryVariantsForCategoryId(string $internalCategoryId) public function getAllCategoryVariantsForCategoryId(string $internalCategoryId) {
{ return $this->find('allCategoryVariantsForCategoryId', $internalCategoryId)->toArray();
return $this->find('allCategoryVariantsForCategoryId', $internalCategoryId)->toArray(); }
}
} }
+106 -115
View File
@@ -4,16 +4,9 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table; namespace CakeProducts\Model\Table;
use Cake\Core\Configure; 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\RulesChecker;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\Validation\Validator; use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductPhoto;
use Closure;
use Psr\SimpleCache\CacheInterface;
/** /**
* ProductPhotos Model * ProductPhotos Model
@@ -21,15 +14,15 @@ use Psr\SimpleCache\CacheInterface;
* @property ProductsTable&BelongsTo $Products * @property ProductsTable&BelongsTo $Products
* @property ProductSkusTable&BelongsTo $ProductSkus * @property ProductSkusTable&BelongsTo $ProductSkus
* *
* @method ProductPhoto newEmptyEntity() * @method \CakeProducts\Model\Entity\ProductPhoto newEmptyEntity()
* @method ProductPhoto newEntity(array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductPhoto newEntity()
* @method array<ProductPhoto> newEntities(array $data, array $options = []) * @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 \CakeProducts\Model\Entity\ProductPhoto get()
* @method ProductPhoto findOrCreate($search, ?callable $callback = null, array $options = []) * @method \CakeProducts\Model\Entity\ProductPhoto findOrCreate()
* @method ProductPhoto patchEntity(EntityInterface $entity, array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductPhoto patchEntity()
* @method array<ProductPhoto> patchEntities(iterable $entities, array $data, array $options = []) * @method array<ProductPhoto> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductPhoto|false save(EntityInterface $entity, 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>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductPhoto>|ResultSetInterface<ProductPhoto> saveManyOrFail(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 = []) * @method iterable<ProductPhoto>|ResultSetInterface<ProductPhoto>|false deleteMany(iterable $entities, array $options = [])
@@ -37,136 +30,134 @@ use Psr\SimpleCache\CacheInterface;
* *
* @mixin TimestampBehavior * @mixin TimestampBehavior
*/ */
class ProductPhotosTable extends Table class ProductPhotosTable extends Table {
{
/** /**
* Initialize method * Initialize method
* *
* @param array<string, mixed> $config The configuration for the Table. * @param array<string, mixed> $config The configuration for the Table.
* @return void * @return void
*/ */
public function initialize(array $config): void public function initialize(array $config): void {
{ parent::initialize($config);
parent::initialize($config);
$this->setTable('product_photos'); $this->setTable('product_photos');
$this->setDisplayField('photo_filename'); $this->setDisplayField('photo_filename');
$this->setPrimaryKey('id'); $this->setPrimaryKey('id');
$this->setEntityClass( $this->setEntityClass(
Configure::read('CakeProducts.ProductPhotos.entity', 'CakeProducts\Model\Entity\ProductPhoto') Configure::read('CakeProducts.ProductPhotos.entity', 'CakeProducts\Model\Entity\ProductPhoto'),
); );
$this->addBehavior('Timestamp'); $this->addBehavior('Timestamp');
$this->addBehavior('Tools.Toggle', [ $this->addBehavior('Tools.Toggle', [
'field' => 'primary_category_photo', 'field' => 'primary_category_photo',
'scopeFields' => ['product_category_id'], 'scopeFields' => ['product_category_id'],
'scope' => [ 'scope' => [
'deleted IS' => null, 'deleted IS' => null,
], ],
]); ]);
$this->addBehavior('CakeProducts.SecondToggle', [ $this->addBehavior('CakeProducts.SecondToggle', [
'field' => 'primary_photo', 'field' => 'primary_photo',
'scopeFields' => ['product_id'], 'scopeFields' => ['product_id'],
'scope' => [ 'scope' => [
'deleted IS' => null, 'deleted IS' => null,
'product_id IS NOT' => null, 'product_id IS NOT' => null,
], ],
]); ]);
$this->addBehavior('CakeProducts.ThirdToggle', [ $this->addBehavior('CakeProducts.ThirdToggle', [
'field' => 'primary_sku_photo', 'field' => 'primary_sku_photo',
'scopeFields' => ['product_sku_id'], 'scopeFields' => ['product_sku_id'],
'scope' => [ 'scope' => [
'deleted IS' => null, 'deleted IS' => null,
'product_sku_id IS NOT' => null, 'product_sku_id IS NOT' => null,
], ],
]); ]);
$this->belongsTo('Products', [ $this->belongsTo('Products', [
'foreignKey' => 'product_id', 'foreignKey' => 'product_id',
'joinType' => 'LEFT', 'joinType' => 'LEFT',
'className' => 'CakeProducts.Products', 'className' => 'CakeProducts.Products',
]); ]);
$this->belongsTo('ProductCategories', [ $this->belongsTo('ProductCategories', [
'foreignKey' => 'product_category_id', 'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id', 'bindingKey' => 'internal_id',
'joinType' => 'INNER', 'joinType' => 'INNER',
'className' => 'CakeProducts.ProductCategories', 'className' => 'CakeProducts.ProductCategories',
]); ]);
$this->belongsTo('ProductSkus', [ $this->belongsTo('ProductSkus', [
'foreignKey' => 'product_sku_id', 'foreignKey' => 'product_sku_id',
'joinType' => 'LEFT', 'joinType' => 'LEFT',
'className' => 'CakeProducts.ProductSkus', 'className' => 'CakeProducts.ProductSkus',
]); ]);
} }
/** /**
* Default validation rules. * Default validation rules.
* *
* @param Validator $validator Validator instance. * @param \Cake\Validation\Validator $validator Validator instance.
* @return Validator * @return \Cake\Validation\Validator
*/ */
public function validationDefault(Validator $validator): Validator public function validationDefault(Validator $validator): Validator {
{ $validator
$validator ->uuid('product_id')
->uuid('product_id') ->allowEmptyString('product_id');
->allowEmptyString('product_id');
$validator $validator
->uuid('product_sku_id') ->uuid('product_sku_id')
->allowEmptyString('product_sku_id'); ->allowEmptyString('product_sku_id');
$validator $validator
->uuid('product_category_id') ->uuid('product_category_id')
->requirePresence('product_category_id', 'create') ->requirePresence('product_category_id', 'create')
->notEmptyString('product_category_id'); ->notEmptyString('product_category_id');
$validator $validator
->scalar('photo_dir') ->scalar('photo_dir')
->maxLength('photo_dir', 255) ->maxLength('photo_dir', 255)
->requirePresence('photo_dir', 'create') ->requirePresence('photo_dir', 'create')
->notEmptyString('photo_dir'); ->notEmptyString('photo_dir');
$validator $validator
->scalar('photo_filename') ->scalar('photo_filename')
->maxLength('photo_filename', 255) ->maxLength('photo_filename', 255)
->requirePresence('photo_filename', 'create') ->requirePresence('photo_filename', 'create')
->notEmptyString('photo_filename'); ->notEmptyString('photo_filename');
$validator $validator
->boolean('primary_photo') ->boolean('primary_photo')
->notEmptyString('primary_photo'); ->notEmptyString('primary_photo');
$validator $validator
->integer('photo_position') ->integer('photo_position')
->notEmptyString('photo_position'); ->notEmptyString('photo_position');
$validator $validator
->boolean('enabled') ->boolean('enabled')
->notEmptyString('enabled'); ->notEmptyString('enabled');
$validator $validator
->dateTime('deleted') ->dateTime('deleted')
->allowEmptyDateTime('deleted'); ->allowEmptyDateTime('deleted');
return $validator; return $validator;
} }
/** /**
* Returns a rules checker object that will be used for validating * Returns a rules checker object that will be used for validating
* application integrity. * application integrity.
* *
* @param RulesChecker $rules The rules object to be modified. * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return RulesChecker * @return \Cake\ORM\RulesChecker
*/ */
public function buildRules(RulesChecker $rules): RulesChecker public function buildRules(RulesChecker $rules): RulesChecker {
{ $rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
$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_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']); $rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_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; 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\RulesChecker;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\Validation\Validator; use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductSkuVariantValue;
use Closure;
use Psr\SimpleCache\CacheInterface;
/** /**
* ProductSkuVariantValues Model * ProductSkuVariantValues Model
@@ -21,92 +14,90 @@ use Psr\SimpleCache\CacheInterface;
* @property ProductCategoryVariantsTable&BelongsTo $ProductCategoryVariants * @property ProductCategoryVariantsTable&BelongsTo $ProductCategoryVariants
* @property ProductCategoryVariantOptionsTable&BelongsTo $ProductCategoryVariantOptions * @property ProductCategoryVariantOptionsTable&BelongsTo $ProductCategoryVariantOptions
* *
* @method ProductSkuVariantValue newEmptyEntity() * @method \CakeProducts\Model\Entity\ProductSkuVariantValue newEmptyEntity()
* @method ProductSkuVariantValue newEntity(array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductSkuVariantValue newEntity()
* @method array<ProductSkuVariantValue> newEntities(array $data, array $options = []) * @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 \CakeProducts\Model\Entity\ProductSkuVariantValue get()
* @method ProductSkuVariantValue findOrCreate($search, ?callable $callback = null, array $options = []) * @method \CakeProducts\Model\Entity\ProductSkuVariantValue findOrCreate()
* @method ProductSkuVariantValue patchEntity(EntityInterface $entity, array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductSkuVariantValue patchEntity()
* @method array<ProductSkuVariantValue> patchEntities(iterable $entities, array $data, array $options = []) * @method array<ProductSkuVariantValue> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductSkuVariantValue|false save(EntityInterface $entity, 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>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductSkuVariantValue>|ResultSetInterface<ProductSkuVariantValue> saveManyOrFail(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>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductSkuVariantValue>|ResultSetInterface<ProductSkuVariantValue> deleteManyOrFail(iterable $entities, array $options = []) * @method iterable<ProductSkuVariantValue>|ResultSetInterface<ProductSkuVariantValue> deleteManyOrFail(iterable $entities, array $options = [])
*/ */
class ProductSkuVariantValuesTable extends Table class ProductSkuVariantValuesTable extends Table {
{
/** /**
* Initialize method * Initialize method
* *
* @param array<string, mixed> $config The configuration for the Table. * @param array<string, mixed> $config The configuration for the Table.
* @return void * @return void
*/ */
public function initialize(array $config): void public function initialize(array $config): void {
{ parent::initialize($config);
parent::initialize($config);
$this->setTable('product_sku_variant_values'); $this->setTable('product_sku_variant_values');
$this->setDisplayField('id'); $this->setDisplayField('id');
$this->setPrimaryKey('id'); $this->setPrimaryKey('id');
$this->belongsTo('ProductSkus', [ $this->belongsTo('ProductSkus', [
'className' => 'CakeProducts.ProductSkus', 'className' => 'CakeProducts.ProductSkus',
'foreignKey' => 'product_sku_id', 'foreignKey' => 'product_sku_id',
'propertyName' => 'product_sku', 'propertyName' => 'product_sku',
'joinType' => 'INNER', 'joinType' => 'INNER',
]); ]);
$this->belongsTo('ProductVariants', [ $this->belongsTo('ProductVariants', [
'className' => 'CakeProducts.ProductVariants', 'className' => 'CakeProducts.ProductVariants',
'foreignKey' => 'product_variant_id', 'foreignKey' => 'product_variant_id',
'joinType' => 'INNER', 'joinType' => 'INNER',
]); ]);
$this->belongsTo('ProductCategoryVariantOptions', [ $this->belongsTo('ProductCategoryVariantOptions', [
'className' => 'CakeProducts.ProductCategoryVariantOptions', 'className' => 'CakeProducts.ProductCategoryVariantOptions',
'foreignKey' => 'product_category_variant_option_id', 'foreignKey' => 'product_category_variant_option_id',
'joinType' => 'INNER', 'joinType' => 'INNER',
]); ]);
} }
/** /**
* Default validation rules. * Default validation rules.
* *
* @param Validator $validator Validator instance. * @param \Cake\Validation\Validator $validator Validator instance.
* @return Validator * @return \Cake\Validation\Validator
*/ */
public function validationDefault(Validator $validator): Validator public function validationDefault(Validator $validator): Validator {
{ $validator
$validator ->uuid('product_sku_id')
->uuid('product_sku_id') ->notEmptyString('product_sku_id');
->notEmptyString('product_sku_id');
$validator $validator
->uuid('product_variant_id') ->uuid('product_variant_id')
->notEmptyString('product_variant_id'); ->notEmptyString('product_variant_id');
$validator $validator
->uuid('product_category_variant_option_id') ->uuid('product_category_variant_option_id')
->notEmptyString('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 * Returns a rules checker object that will be used for validating
* application integrity. * application integrity.
* *
* @param RulesChecker $rules The rules object to be modified. * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return RulesChecker * @return \Cake\ORM\RulesChecker
*/ */
public function buildRules(RulesChecker $rules): RulesChecker public function buildRules(RulesChecker $rules): RulesChecker {
{ $rules->add($rules->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']);
$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 // @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_variant_id'], 'ProductVariants'), ['errorField' => 'product_variant_id']);
$rules->add($rules->existsIn(['product_category_variant_option_id'], 'ProductCategoryVariantOptions'), ['errorField' => 'product_category_variant_option_id']); $rules->add($rules->existsIn(['product_category_variant_option_id'], 'ProductCategoryVariantOptions'), ['errorField' => 'product_category_variant_option_id']);
return $rules;
}
return $rules;
}
} }
+86 -97
View File
@@ -4,33 +4,24 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table; namespace CakeProducts\Model\Table;
use Cake\Core\Configure; 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\RulesChecker;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\Validation\Validator; use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductSku;
use Closure;
use Psr\SimpleCache\CacheInterface;
/** /**
* ProductSkus Model * ProductSkus Model
* *
* @property ProductsTable&BelongsTo $Products * @property ProductsTable&BelongsTo $Products
* *
* @method ProductSku newEmptyEntity() * @method \CakeProducts\Model\Entity\ProductSku newEmptyEntity()
* @method ProductSku newEntity(array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductSku newEntity()
* @method array<ProductSku> newEntities(array $data, array $options = []) * @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 \CakeProducts\Model\Entity\ProductSku get()
* @method ProductSku findOrCreate($search, ?callable $callback = null, array $options = []) * @method \CakeProducts\Model\Entity\ProductSku findOrCreate()
* @method ProductSku patchEntity(EntityInterface $entity, array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductSku patchEntity()
* @method array<ProductSku> patchEntities(iterable $entities, array $data, array $options = []) * @method array<ProductSku> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductSku|false save(EntityInterface $entity, 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>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductSku>|ResultSetInterface<ProductSku> saveManyOrFail(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 = []) * @method iterable<ProductSku>|ResultSetInterface<ProductSku>|false deleteMany(iterable $entities, array $options = [])
@@ -38,114 +29,112 @@ use Psr\SimpleCache\CacheInterface;
* *
* @mixin TimestampBehavior * @mixin TimestampBehavior
*/ */
class ProductSkusTable extends Table class ProductSkusTable extends Table {
{
/** /**
* Initialize method * Initialize method
* *
* @param array<string, mixed> $config The configuration for the Table. * @param array<string, mixed> $config The configuration for the Table.
* @return void * @return void
*/ */
public function initialize(array $config): void public function initialize(array $config): void {
{ parent::initialize($config);
parent::initialize($config);
$this->setTable('product_skus'); $this->setTable('product_skus');
$this->setDisplayField('sku'); $this->setDisplayField('sku');
$this->setPrimaryKey('id'); $this->setPrimaryKey('id');
$this->setEntityClass( $this->setEntityClass(
Configure::read('CakeProducts.ProductSkus.entity', 'CakeProducts\Model\Entity\ProductSku') Configure::read('CakeProducts.ProductSkus.entity', 'CakeProducts\Model\Entity\ProductSku'),
); );
$this->addBehavior('Timestamp'); $this->addBehavior('Timestamp');
$this->addBehavior('Tools.Toggle', [ $this->addBehavior('Tools.Toggle', [
'field' => 'default_sku', 'field' => 'default_sku',
'scopeFields' => ['product_id'], 'scopeFields' => ['product_id'],
'scope' => [ 'scope' => [
'deleted IS' => null, 'deleted IS' => null,
], ],
]); ]);
$this->belongsTo('Products', [ $this->belongsTo('Products', [
'className' => 'CakeProducts.Products', 'className' => 'CakeProducts.Products',
'foreignKey' => 'product_id', 'foreignKey' => 'product_id',
'joinType' => 'INNER', 'joinType' => 'INNER',
]); ]);
$this->hasMany('ProductSkuVariantValues', [ $this->hasMany('ProductSkuVariantValues', [
'foreignKey' => 'product_sku_id', 'foreignKey' => 'product_sku_id',
'className' => 'CakeProducts.ProductSkuVariantValues', 'className' => 'CakeProducts.ProductSkuVariantValues',
'saveStrategy' => 'replace', 'saveStrategy' => 'replace',
'dependent' => true, 'dependent' => true,
'cascadeCallbacks' => true, 'cascadeCallbacks' => true,
]); ]);
$this->hasMany('ProductPhotos', [ $this->hasMany('ProductPhotos', [
'foreignKey' => 'product_sku_id', 'foreignKey' => 'product_sku_id',
'className' => 'CakeProducts.ProductPhotos', 'className' => 'CakeProducts.ProductPhotos',
'dependent' => true, 'dependent' => true,
'cascadeCallbacks' => true, 'cascadeCallbacks' => true,
]); ]);
$this->hasOne('PrimaryProductPhotos', [ $this->hasOne('PrimaryProductPhotos', [
'foreignKey' => 'product_sku_id', 'foreignKey' => 'product_sku_id',
'conditions' => ['PrimaryProductPhotos.primary_photo' => true], 'conditions' => ['PrimaryProductPhotos.primary_photo' => true],
'className' => 'CakeProducts.ProductPhotos', 'className' => 'CakeProducts.ProductPhotos',
'dependent' => true, 'dependent' => true,
]); ]);
} }
/** /**
* Default validation rules. * Default validation rules.
* *
* @param Validator $validator Validator instance. * @param \Cake\Validation\Validator $validator Validator instance.
* @return Validator * @return \Cake\Validation\Validator
*/ */
public function validationDefault(Validator $validator): Validator public function validationDefault(Validator $validator): Validator {
{ $validator
$validator ->uuid('product_id')
->uuid('product_id') ->notEmptyString('product_id');
->notEmptyString('product_id');
$validator $validator
->scalar('sku') ->scalar('sku')
->maxLength('sku', 255) ->maxLength('sku', 255)
->requirePresence('sku', 'create') ->requirePresence('sku', 'create')
->notEmptyString('sku'); ->notEmptyString('sku');
$validator $validator
->scalar('barcode') ->scalar('barcode')
->maxLength('barcode', 255) ->maxLength('barcode', 255)
->allowEmptyString('barcode'); ->allowEmptyString('barcode');
$validator $validator
->decimal('price') ->decimal('price')
->allowEmptyString('price'); ->allowEmptyString('price');
$validator $validator
->decimal('cost') ->decimal('cost')
->allowEmptyString('cost'); ->allowEmptyString('cost');
$validator $validator
->dateTime('deleted') ->dateTime('deleted')
->allowEmptyDateTime('deleted'); ->allowEmptyDateTime('deleted');
return $validator; return $validator;
} }
/** /**
* Returns a rules checker object that will be used for validating * Returns a rules checker object that will be used for validating
* application integrity. * application integrity.
* *
* @param RulesChecker $rules The rules object to be modified. * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return RulesChecker * @return \Cake\ORM\RulesChecker
*/ */
public function buildRules(RulesChecker $rules): RulesChecker public function buildRules(RulesChecker $rules): RulesChecker {
{ $rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']); $rules->add($rules->isUnique(['sku'], 'SKU must be unique'), ['errorField' => 'sku']);
$rules->add($rules->isUnique(['sku'], 'SKU must be unique'), ['errorField' => 'sku']);
return $rules;
}
return $rules;
}
} }
+60 -71
View File
@@ -3,18 +3,9 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table; 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\RulesChecker;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\Validation\Validator; use Cake\Validation\Validator;
use Closure;
use Psr\SimpleCache\CacheInterface;
/** /**
* ProductVariants Model * ProductVariants Model
@@ -22,96 +13,94 @@ use Psr\SimpleCache\CacheInterface;
* @property ProductCategoryVariantsTable&BelongsTo $ProductCategoryVariants * @property ProductCategoryVariantsTable&BelongsTo $ProductCategoryVariants
* @property ProductsTable&BelongsTo $Products * @property ProductsTable&BelongsTo $Products
* *
* @method ProductVariant newEmptyEntity() * @method \CakeProducts\Model\Entity\ProductVariant newEmptyEntity()
* @method ProductVariant newEntity(array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductVariant newEntity()
* @method array<ProductVariant> newEntities(array $data, array $options = []) * @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 \CakeProducts\Model\Entity\ProductVariant get()
* @method ProductVariant findOrCreate($search, ?callable $callback = null, array $options = []) * @method \CakeProducts\Model\Entity\ProductVariant findOrCreate()
* @method ProductVariant patchEntity(EntityInterface $entity, array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductVariant patchEntity()
* @method array<ProductVariant> patchEntities(iterable $entities, array $data, array $options = []) * @method array<ProductVariant> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductVariant|false save(EntityInterface $entity, 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>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductVariant>|ResultSetInterface<ProductVariant> saveManyOrFail(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>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductVariant>|ResultSetInterface<ProductVariant> deleteManyOrFail(iterable $entities, array $options = []) * @method iterable<ProductVariant>|ResultSetInterface<ProductVariant> deleteManyOrFail(iterable $entities, array $options = [])
*/ */
class ProductVariantsTable extends Table class ProductVariantsTable extends Table {
{
/** /**
* Initialize method * Initialize method
* *
* @param array<string, mixed> $config The configuration for the Table. * @param array<string, mixed> $config The configuration for the Table.
* @return void * @return void
*/ */
public function initialize(array $config): void public function initialize(array $config): void {
{ parent::initialize($config);
parent::initialize($config);
$this->setTable('product_variants'); $this->setTable('product_variants');
$this->setDisplayField('name'); $this->setDisplayField('name');
$this->setPrimaryKey('id'); $this->setPrimaryKey('id');
$this->belongsTo('ProductCategoryVariants', [ $this->belongsTo('ProductCategoryVariants', [
'className' => 'CakeProducts.ProductCategoryVariants', 'className' => 'CakeProducts.ProductCategoryVariants',
'foreignKey' => 'product_category_variant_id', 'foreignKey' => 'product_category_variant_id',
]); ]);
$this->belongsTo('Products', [ $this->belongsTo('Products', [
'className' => 'CakeProducts.Products', 'className' => 'CakeProducts.Products',
'foreignKey' => 'product_id', 'foreignKey' => 'product_id',
'joinType' => 'INNER', 'joinType' => 'INNER',
]); ]);
$this->hasMany('ProductSkuVariantValues', [ $this->hasMany('ProductSkuVariantValues', [
'className' => 'CakeProducts.ProductSkuVariantValues', 'className' => 'CakeProducts.ProductSkuVariantValues',
'foreignKey' => 'product_variant_id', 'foreignKey' => 'product_variant_id',
'dependent' => true, 'dependent' => true,
'cascadeCallbacks' => true, 'cascadeCallbacks' => true,
]); ]);
} }
/** /**
* Default validation rules. * Default validation rules.
* *
* @param Validator $validator Validator instance. * @param \Cake\Validation\Validator $validator Validator instance.
* @return Validator * @return \Cake\Validation\Validator
*/ */
public function validationDefault(Validator $validator): Validator public function validationDefault(Validator $validator): Validator {
{ $validator
$validator ->scalar('name')
->scalar('name') ->maxLength('name', 255)
->maxLength('name', 255) ->requirePresence('name', 'create')
->requirePresence('name', 'create') ->notEmptyString('name');
->notEmptyString('name');
$validator $validator
->uuid('product_category_variant_id') ->uuid('product_category_variant_id')
->allowEmptyString('product_category_variant_id'); ->allowEmptyString('product_category_variant_id');
$validator $validator
->uuid('product_id') ->uuid('product_id')
->notEmptyString('product_id'); ->notEmptyString('product_id');
$validator $validator
->boolean('enabled') ->boolean('enabled')
->requirePresence('enabled', 'create') ->requirePresence('enabled', 'create')
->notEmptyString('enabled'); ->notEmptyString('enabled');
return $validator; return $validator;
} }
/** /**
* Returns a rules checker object that will be used for validating * Returns a rules checker object that will be used for validating
* application integrity. * application integrity.
* *
* @param RulesChecker $rules The rules object to be modified. * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return RulesChecker * @return \Cake\ORM\RulesChecker
*/ */
public function buildRules(RulesChecker $rules): 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_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']); $rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
return $rules;
}
return $rules;
}
} }
+92 -101
View File
@@ -5,154 +5,145 @@ namespace CakeProducts\Model\Table;
use Cake\Core\Configure; use Cake\Core\Configure;
use Cake\Database\Type\EnumType; 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\RulesChecker;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\Validation\Validator; use Cake\Validation\Validator;
use CakeProducts\Model\Entity\Product;
use CakeProducts\Model\Enum\ProductProductTypeId; use CakeProducts\Model\Enum\ProductProductTypeId;
use Closure;
use Psr\SimpleCache\CacheInterface;
/** /**
* Products Model * Products Model
* *
* @property ProductCategoriesTable&BelongsTo $ProductCategories * @property ProductCategoriesTable&BelongsTo $ProductCategories
* *
* @method Product newEmptyEntity() * @method \CakeProducts\Model\Entity\Product newEmptyEntity()
* @method Product newEntity(array $data, array $options = []) * @method \CakeProducts\Model\Entity\Product newEntity()
* @method array<Product> newEntities(array $data, array $options = []) * @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 \CakeProducts\Model\Entity\Product get()
* @method Product findOrCreate($search, ?callable $callback = null, array $options = []) * @method \CakeProducts\Model\Entity\Product findOrCreate()
* @method Product patchEntity(EntityInterface $entity, array $data, array $options = []) * @method \CakeProducts\Model\Entity\Product patchEntity()
* @method array<Product> patchEntities(iterable $entities, array $data, array $options = []) * @method array<Product> patchEntities(iterable $entities, array $data, array $options = [])
* @method Product|false save(EntityInterface $entity, 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>|false saveMany(iterable $entities, array $options = [])
* @method iterable<Product>|ResultSetInterface<Product> saveManyOrFail(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>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<Product>|ResultSetInterface<Product> deleteManyOrFail(iterable $entities, array $options = []) * @method iterable<Product>|ResultSetInterface<Product> deleteManyOrFail(iterable $entities, array $options = [])
*/ */
class ProductsTable extends Table class ProductsTable extends Table {
{
/** /**
* Initialize method * Initialize method
* *
* @param array<string, mixed> $config The configuration for the Table. * @param array<string, mixed> $config The configuration for the Table.
* @return void * @return void
*/ */
public function initialize(array $config): void public function initialize(array $config): void {
{ parent::initialize($config);
parent::initialize($config);
$this->setTable('products'); $this->setTable('products');
$this->setDisplayField('name'); $this->setDisplayField('name');
$this->setPrimaryKey('id'); $this->setPrimaryKey('id');
$this->setEntityClass( $this->setEntityClass(
Configure::read('CakeProducts.Products.entity', 'CakeProducts\Model\Entity\Product') Configure::read('CakeProducts.Products.entity', 'CakeProducts\Model\Entity\Product'),
); );
$this->belongsTo('ProductCategories', [ $this->belongsTo('ProductCategories', [
'foreignKey' => 'product_category_id', 'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id', 'bindingKey' => 'internal_id',
'joinType' => 'INNER', 'joinType' => 'INNER',
'className' => 'CakeProducts.ProductCategories', 'className' => 'CakeProducts.ProductCategories',
]); ]);
$this->hasMany('ProductAttributes', [ $this->hasMany('ProductAttributes', [
'className' => 'CakeProducts.ProductAttributes', 'className' => 'CakeProducts.ProductAttributes',
'dependent' => true, 'dependent' => true,
'cascadeCallbacks' => true, 'cascadeCallbacks' => true,
]); ]);
$this->hasMany('ProductVariants', [ $this->hasMany('ProductVariants', [
'foreignKey' => 'product_id', 'foreignKey' => 'product_id',
'className' => 'CakeProducts.ProductVariants', 'className' => 'CakeProducts.ProductVariants',
'dependent' => true, 'dependent' => true,
'cascadeCallbacks' => true, 'cascadeCallbacks' => true,
]); ]);
$this->hasMany('ProductSkus', [ $this->hasMany('ProductSkus', [
'foreignKey' => 'product_id', 'foreignKey' => 'product_id',
'className' => 'CakeProducts.ProductSkus', 'className' => 'CakeProducts.ProductSkus',
'dependent' => true, 'dependent' => true,
'cascadeCallbacks' => true, 'cascadeCallbacks' => true,
]); ]);
$this->hasMany('ProductPhotos', [ $this->hasMany('ProductPhotos', [
'foreignKey' => 'product_id', 'foreignKey' => 'product_id',
'className' => 'CakeProducts.ProductPhotos', 'className' => 'CakeProducts.ProductPhotos',
'dependent' => true, 'dependent' => true,
'cascadeCallbacks' => true, 'cascadeCallbacks' => true,
]); ]);
$this->hasOne('PrimaryProductPhotos', [ $this->hasOne('PrimaryProductPhotos', [
'foreignKey' => 'product_id', 'foreignKey' => 'product_id',
'conditions' => ['PrimaryProductPhotos.primary_photo' => true], 'conditions' => ['PrimaryProductPhotos.primary_photo' => true],
'className' => 'CakeProducts.ProductPhotos', 'className' => 'CakeProducts.ProductPhotos',
'dependent' => true, 'dependent' => true,
]); ]);
$this->hasOne('DefaultProductSkus', [ $this->hasOne('DefaultProductSkus', [
'foreignKey' => 'product_id', 'foreignKey' => 'product_id',
'conditions' => ['DefaultProductSkus.default_sku' => true], 'conditions' => ['DefaultProductSkus.default_sku' => true],
'className' => 'CakeProducts.ProductSkus', 'className' => 'CakeProducts.ProductSkus',
'propertyName' => 'default_product_sku', 'propertyName' => 'default_product_sku',
'dependent' => true, '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. * Default validation rules.
* *
* @param Validator $validator Validator instance. * @param \Cake\Validation\Validator $validator Validator instance.
* @return Validator * @return \Cake\Validation\Validator
*/ */
public function validationDefault(Validator $validator): Validator public function validationDefault(Validator $validator): Validator {
{ $validator
$validator ->scalar('name')
->scalar('name') ->maxLength('name', 255)
->maxLength('name', 255) ->requirePresence('name', 'create')
->requirePresence('name', 'create') ->notEmptyString('name');
->notEmptyString('name');
$validator $validator
->uuid('product_category_id') ->uuid('product_category_id')
->notEmptyString('product_category_id'); ->notEmptyString('product_category_id');
$validator $validator
->integer('product_type_id') ->integer('product_type_id')
->requirePresence('product_type_id', 'create') ->requirePresence('product_type_id', 'create')
->notEmptyString('product_type_id'); ->notEmptyString('product_type_id');
$validator $validator
->dateTime('deleted') ->dateTime('deleted')
->allowEmptyDateTime('deleted'); ->allowEmptyDateTime('deleted');
return $validator; return $validator;
} }
/** /**
* Returns a rules checker object that will be used for validating * Returns a rules checker object that will be used for validating
* application integrity. * application integrity.
* *
* @param RulesChecker $rules The rules object to be modified. * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return RulesChecker * @return \Cake\ORM\RulesChecker
*/ */
public function buildRules(RulesChecker $rules): RulesChecker public function buildRules(RulesChecker $rules): RulesChecker {
{ $rules->add($rules->isUnique(['product_category_id', 'name']), ['errorField' => 'product_category_id']);
$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->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
// $rules->add($rules->validCount('product_attributes', 0, '<=', 'You must not have any tags')); // $rules->add($rules->validCount('product_attributes', 0, '<=', 'You must not have any tags'));
return $rules; return $rules;
} }
} }
@@ -8,24 +8,24 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* ExternalProductCatalogsFixture * ExternalProductCatalogsFixture
*/ */
class ExternalProductCatalogsFixture extends TestFixture class ExternalProductCatalogsFixture extends TestFixture {
{
/** /**
* Init method * Init method
* *
* @return void * @return void
*/ */
public function init(): void public function init(): void {
{ $this->records = [
$this->records = [ [
[ 'id' => '115153f3-2f59-4234-8ff8-e1b205769999',
'id' => '115153f3-2f59-4234-8ff8-e1b205769999', 'base_url' => 'http://localhost:8766',
'base_url' => 'http://localhost:8766', 'api_url' => 'http://localhost:8766/api',
'api_url' => 'http://localhost:8766/api', 'created' => '2024-11-22 09:39:37',
'created' => '2024-11-22 09:39:37', 'deleted' => null,
'deleted' => null, ],
], ];
]; parent::init();
parent::init(); }
}
} }
@@ -8,25 +8,25 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* ExternalProductCatalogsProductCatalogsFixture * ExternalProductCatalogsProductCatalogsFixture
*/ */
class ExternalProductCatalogsProductCatalogsFixture extends TestFixture class ExternalProductCatalogsProductCatalogsFixture extends TestFixture {
{
/** /**
* Init method * Init method
* *
* @return void * @return void
*/ */
public function init(): void public function init(): void {
{ $this->records = [
$this->records = [ [
[ 'id' => 1,
'id' => 1, 'external_product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205769999',
'external_product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205769999', 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', 'created' => '2024-11-22 09:39:37',
'created' => '2024-11-22 09:39:37', 'enabled' => false,
'enabled' => false, 'deleted' => null,
'deleted' => null, ],
], ];
]; parent::init();
parent::init(); }
}
} }
+7 -9
View File
@@ -8,18 +8,16 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* ProductAttributesFixture * ProductAttributesFixture
*/ */
class ProductAttributesFixture extends TestFixture class ProductAttributesFixture extends TestFixture {
{
/** /**
* Init method * Init method
* *
* @return void * @return void
*/ */
public function init(): void public function init(): void {
{ $this->records = [];
$this->records = [ parent::init();
}
];
parent::init();
}
} }
+23 -23
View File
@@ -8,31 +8,31 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* ProductCatalogsFixture * ProductCatalogsFixture
*/ */
class ProductCatalogsFixture extends TestFixture class ProductCatalogsFixture extends TestFixture {
{
/** /**
* Init method * Init method
* *
* @return void * @return void
*/ */
public function init(): void public function init(): void {
{ $this->records = [
$this->records = [ [
[ 'id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'id' => '115153f3-2f59-4234-8ff8-e1b205761428', 'name' => 'Automotive',
'name' => 'Automotive', 'catalog_description' => '',
'catalog_description' => '', 'enabled' => true,
'enabled' => true, 'deleted' => null,
'deleted' => null, ],
], [
[ 'id' => 'f56f3412-ed23-490b-be6e-016208c415d2',
'id' => 'f56f3412-ed23-490b-be6e-016208c415d2', 'name' => 'Software',
'name' => 'Software', 'catalog_description' => '',
'catalog_description' => '', 'enabled' => true,
'enabled' => true, 'deleted' => null,
'deleted' => null, ],
], ];
]; parent::init();
parent::init(); }
}
} }
+93 -93
View File
@@ -8,101 +8,101 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* ProductCategoriesFixture * ProductCategoriesFixture
*/ */
class ProductCategoriesFixture extends TestFixture class ProductCategoriesFixture extends TestFixture {
{
/** /**
* Init method * Init method
* *
* @return void * @return void
*/ */
public function init(): void public function init(): void {
{ $this->records = [
$this->records = [ [
[ 'id' => 1,
'id' => 1, 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', 'internal_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'internal_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', 'name' => 'Engine',
'name' => 'Engine', 'category_description' => '',
'category_description' => '', 'parent_id' => null,
'parent_id' => null, 'lft' => 1,
'lft' => 1, 'rght' => 4,
'rght' => 4, 'enabled' => true,
'enabled' => true, 'deleted' => null,
'deleted' => null, ],
], [
[ 'id' => 2,
'id' => 2, 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', 'internal_id' => '3c2377c5-b97c-4bc9-9660-8f77b4893d8b',
'internal_id' => '3c2377c5-b97c-4bc9-9660-8f77b4893d8b', 'name' => 'Engine Internals',
'name' => 'Engine Internals', 'category_description' => '',
'category_description' => '', 'parent_id' => 1,
'parent_id' => 1, 'lft' => 2,
'lft' => 2, 'rght' => 3,
'rght' => 3, 'enabled' => true,
'enabled' => true, 'deleted' => null,
'deleted' => null, ],
], [
[ 'id' => 3,
'id' => 3, 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', 'internal_id' => 'fbee6709-396f-4bb4-b60b-e125b0bc4e83',
'internal_id' => 'fbee6709-396f-4bb4-b60b-e125b0bc4e83', 'name' => 'Electrical',
'name' => 'Electrical', 'category_description' => '',
'category_description' => '', 'parent_id' => null,
'parent_id' => null, 'lft' => 5,
'lft' => 5, 'rght' => 8,
'rght' => 8, 'enabled' => true,
'enabled' => true, 'deleted' => null,
'deleted' => null, ],
], [
[ 'id' => 4,
'id' => 4, 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', 'internal_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'internal_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', 'name' => 'Wiring',
'name' => 'Wiring', 'category_description' => '',
'category_description' => '', 'parent_id' => 3,
'parent_id' => 3, 'lft' => 6,
'lft' => 6, 'rght' => 7,
'rght' => 7, 'enabled' => true,
'enabled' => true, 'deleted' => null,
'deleted' => null, ],
], [
[ 'id' => 5,
'id' => 5, 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', 'internal_id' => 'c447b6f4-0fb1-4d59-ba45-5613829a725a',
'internal_id' => 'c447b6f4-0fb1-4d59-ba45-5613829a725a', 'name' => 'Suspension',
'name' => 'Suspension', 'category_description' => '',
'category_description' => '', 'parent_id' => null,
'parent_id' => null, 'lft' => 9,
'lft' => 9, 'rght' => 12,
'rght' => 12, 'enabled' => true,
'enabled' => true, 'deleted' => null,
'deleted' => null, ],
], [
[ 'id' => 6,
'id' => 6, 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', 'internal_id' => '1e749d3b-aee0-48a5-8d6c-8cf2b83e9b6e',
'internal_id' => '1e749d3b-aee0-48a5-8d6c-8cf2b83e9b6e', 'name' => 'Coilovers',
'name' => 'Coilovers', 'category_description' => '',
'category_description' => '', 'parent_id' => 5,
'parent_id' => 5, 'lft' => 10,
'lft' => 10, 'rght' => 11,
'rght' => 11, 'enabled' => true,
'enabled' => true, 'deleted' => null,
'deleted' => null, ],
], [
[ 'id' => 7,
'id' => 7, 'product_catalog_id' => 'f56f3412-ed23-490b-be6e-016208c415d2',
'product_catalog_id' => 'f56f3412-ed23-490b-be6e-016208c415d2', 'internal_id' => '8c89a3ca-d56f-46bf-a738-7e85b3342b2a',
'internal_id' => '8c89a3ca-d56f-46bf-a738-7e85b3342b2a', 'name' => 'Support',
'name' => 'Support', 'category_description' => '',
'category_description' => '', 'parent_id' => null,
'parent_id' => null, 'lft' => 1,
'lft' => 1, 'rght' => 2,
'rght' => 2, 'enabled' => true,
'enabled' => true, 'deleted' => null,
'deleted' => null, ],
], ];
]; parent::init();
parent::init(); }
}
} }
@@ -8,41 +8,41 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* ProductCategoryAttributeOptionsFixture * ProductCategoryAttributeOptionsFixture
*/ */
class ProductCategoryAttributeOptionsFixture extends TestFixture class ProductCategoryAttributeOptionsFixture extends TestFixture {
{
/** /**
* Init method * Init method
* *
* @return void * @return void
*/ */
public function init(): void public function init(): void {
{ $this->records = [
$this->records = [ [
[ 'id' => 'e06f1723-2456-483a-b3c4-004603e032a8',
'id' => 'e06f1723-2456-483a-b3c4-004603e032a8', 'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c', 'attribute_value' => 'Red',
'attribute_value' => 'Red', 'attribute_label' => 'Red',
'attribute_label' => 'Red', 'enabled' => 1,
'enabled' => 1, 'deleted' => null,
'deleted' => null, ],
], [
[ 'id' => 'e06f1723-2456-483a-b3c4-004603e032a1',
'id' => 'e06f1723-2456-483a-b3c4-004603e032a1', 'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c', 'attribute_value' => 'Blue',
'attribute_value' => 'Blue', 'attribute_label' => 'Blue',
'attribute_label' => 'Blue', 'enabled' => 1,
'enabled' => 1, 'deleted' => null,
'deleted' => null, ],
], [
[ 'id' => 'e06f1723-2456-483a-b3c4-004603e032a2',
'id' => 'e06f1723-2456-483a-b3c4-004603e032a2', 'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c', 'attribute_value' => 'Green',
'attribute_value' => 'Green', 'attribute_label' => 'Green',
'attribute_label' => 'Green', 'enabled' => 1,
'enabled' => 1, 'deleted' => null,
'deleted' => null, ],
] ];
]; parent::init();
parent::init(); }
}
} }
@@ -8,25 +8,25 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* ProductCategoryAttributesFixture * ProductCategoryAttributesFixture
*/ */
class ProductCategoryAttributesFixture extends TestFixture class ProductCategoryAttributesFixture extends TestFixture {
{
/** /**
* Init method * Init method
* *
* @return void * @return void
*/ */
public function init(): void public function init(): void {
{ $this->records = [
$this->records = [ [
[ 'id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
'id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c', 'name' => 'Color',
'name' => 'Color', 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', 'attribute_type_id' => 1,
'attribute_type_id' => 1, 'enabled' => 1,
'enabled' => 1, 'deleted' => null,
'deleted' => null, ],
], ];
]; parent::init();
parent::init(); }
}
} }
@@ -8,92 +8,91 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* ProductCategoryVariantsFixture * ProductCategoryVariantsFixture
*/ */
class ProductCategoryVariantOptionsFixture extends TestFixture class ProductCategoryVariantOptionsFixture extends TestFixture {
{
/** /**
* Init method * Init method
* *
* @return void * @return void
*/ */
public function init(): void public function init(): void {
{ $this->records = [
$this->records = [ [
[ 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d23',
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d23', 'variant_value' => 'Blue',
'variant_value' => 'Blue', 'variant_label' => null,
'variant_label' => null, 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93', 'created' => '2025-07-04 12:00:00',
'created' => '2025-07-04 12:00:00', 'modified' => '2025-07-04 12:00:00',
'modified' => '2025-07-04 12:00:00', 'enabled' => 1,
'enabled' => 1, ],
], [
[ 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d24',
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d24', 'variant_value' => 'Red',
'variant_value' => 'Red', 'variant_label' => null,
'variant_label' => null, 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93', 'created' => '2025-07-04 12:00:00',
'created' => '2025-07-04 12:00:00', 'modified' => '2025-07-04 12:00:00',
'modified' => '2025-07-04 12:00:00', 'enabled' => 1,
'enabled' => 1, ],
],
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d21',
'variant_value' => '12AWG',
'variant_label' => null,
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
'created' => '2025-07-04 12:00:00',
'modified' => '2025-07-04 12:00:00',
'enabled' => 1,
],
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d22',
'variant_value' => '14AWG',
'variant_label' => null,
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
'created' => '2025-07-04 12:00:00',
'modified' => '2025-07-04 12:00:00',
'enabled' => 1,
],
[ [
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d21', 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78111',
'variant_value' => '12AWG', 'variant_value' => 'Months',
'variant_label' => null, 'variant_label' => 'Months',
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94', 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78111',
'created' => '2025-07-04 12:00:00', 'created' => '2025-07-04 12:00:00',
'modified' => '2025-07-04 12:00:00', 'modified' => '2025-07-04 12:00:00',
'enabled' => 1, 'enabled' => 1,
], ],
[ [
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d22', 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78112',
'variant_value' => '14AWG', 'variant_value' => 'Years',
'variant_label' => null, 'variant_label' => 'Years',
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94', 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78111',
'created' => '2025-07-04 12:00:00', 'created' => '2025-07-04 12:00:00',
'modified' => '2025-07-04 12:00:00', 'modified' => '2025-07-04 12:00:00',
'enabled' => 1, 'enabled' => 1,
], ],
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f22221',
'variant_value' => '6',
'variant_label' => '6',
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78222',
'created' => '2025-07-04 12:00:00',
'modified' => '2025-07-04 12:00:00',
'enabled' => 1,
],
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f22222',
'variant_value' => 12,
'variant_label' => 12,
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78222',
'created' => '2025-07-04 12:00:00',
'modified' => '2025-07-04 12:00:00',
'enabled' => 1,
],
];
parent::init();
}
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78111',
'variant_value' => 'Months',
'variant_label' => 'Months',
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78111',
'created' => '2025-07-04 12:00:00',
'modified' => '2025-07-04 12:00:00',
'enabled' => 1,
],
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78112',
'variant_value' => 'Years',
'variant_label' => 'Years',
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78111',
'created' => '2025-07-04 12:00:00',
'modified' => '2025-07-04 12:00:00',
'enabled' => 1,
],
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f22221',
'variant_value' => '6',
'variant_label' => '6',
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78222',
'created' => '2025-07-04 12:00:00',
'modified' => '2025-07-04 12:00:00',
'enabled' => 1,
],
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f22222',
'variant_value' => 12,
'variant_label' => 12,
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78222',
'created' => '2025-07-04 12:00:00',
'modified' => '2025-07-04 12:00:00',
'enabled' => 1,
],
];
parent::init();
}
} }
@@ -8,46 +8,46 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* ProductCategoryVariantsFixture * ProductCategoryVariantsFixture
*/ */
class ProductCategoryVariantsFixture extends TestFixture class ProductCategoryVariantsFixture extends TestFixture {
{
/** /**
* Init method * Init method
* *
* @return void * @return void
*/ */
public function init(): void public function init(): void {
{ $this->records = [
$this->records = [ [
[ 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78111',
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78111', 'name' => 'Subscription Length Units',
'name' => 'Subscription Length Units', 'product_category_id' => null,
'product_category_id' => null, 'enabled' => true,
'enabled' => true, 'is_system_variant' => true,
'is_system_variant' => true, ],
], [
[ 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78222',
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78222', 'name' => 'Subscription Length',
'name' => 'Subscription Length', 'product_category_id' => null,
'product_category_id' => null, 'enabled' => true,
'enabled' => true, 'is_system_variant' => true,
'is_system_variant' => true, ],
],
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
'name' => 'Color',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'enabled' => true,
'is_system_variant' => false,
],
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
'name' => 'AWG',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'enabled' => true,
'is_system_variant' => false,
],
];
parent::init();
}
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
'name' => 'Color',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'enabled' => true,
'is_system_variant' => false,
],
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
'name' => 'AWG',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'enabled' => true,
'is_system_variant' => false,
],
];
parent::init();
}
} }
+105 -105
View File
@@ -8,116 +8,116 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* ProductPhotosFixture * ProductPhotosFixture
*/ */
class ProductPhotosFixture extends TestFixture class ProductPhotosFixture extends TestFixture {
{
/** /**
* Init method * Init method
* *
* @return void * @return void
*/ */
public function init(): void public function init(): void {
{ $this->records = [
$this->records = [ [
[ 'id' => '2c386086-f4c5-4093-bea5-ee9c29479f58',
'id' => '2c386086-f4c5-4093-bea5-ee9c29479f58', 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', 'product_sku_id' => null,
'product_sku_id' => null, 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', 'photo_dir' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'photo_dir' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', 'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f58.png',
'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f58.png', 'primary_photo' => 1,
'primary_photo' => 1, 'primary_category_photo' => 0,
'primary_category_photo' => 0, 'primary_sku_photo' => 0,
'primary_sku_photo' => 0, 'photo_position' => 100,
'photo_position' => 100, 'enabled' => 1,
'enabled' => 1, 'created' => '2025-08-10 04:32:10',
'created' => '2025-08-10 04:32:10', 'modified' => '2025-08-10 04:32:10',
'modified' => '2025-08-10 04:32:10', 'deleted' => null,
'deleted' => null, ],
],
[ [
'id' => '2c386086-f4c5-4093-bea5-ee9c29479f51', 'id' => '2c386086-f4c5-4093-bea5-ee9c29479f51',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'product_sku_id' => null, 'product_sku_id' => null,
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'photo_dir' => 'categories', 'photo_dir' => 'categories',
'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f51.png', 'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f51.png',
'primary_photo' => 0, 'primary_photo' => 0,
'primary_category_photo' => 1, 'primary_category_photo' => 1,
'primary_sku_photo' => 0, 'primary_sku_photo' => 0,
'photo_position' => 100, 'photo_position' => 100,
'enabled' => 1, 'enabled' => 1,
'created' => '2025-08-10 04:32:10', 'created' => '2025-08-10 04:32:10',
'modified' => '2025-08-10 04:32:10', 'modified' => '2025-08-10 04:32:10',
'deleted' => null, 'deleted' => null,
], ],
[ [
'id' => '2c386086-f4c5-4093-bea5-ee9c29479f50', 'id' => '2c386086-f4c5-4093-bea5-ee9c29479f50',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'product_sku_id' => null, 'product_sku_id' => null,
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'photo_dir' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', 'photo_dir' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f58.png', 'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f58.png',
'primary_photo' => 0, 'primary_photo' => 0,
'primary_category_photo' => 0, 'primary_category_photo' => 0,
'primary_sku_photo' => 0, 'primary_sku_photo' => 0,
'photo_position' => 100, 'photo_position' => 100,
'enabled' => 1, 'enabled' => 1,
'created' => '2025-08-10 04:32:10', 'created' => '2025-08-10 04:32:10',
'modified' => '2025-08-10 04:32:10', 'modified' => '2025-08-10 04:32:10',
'deleted' => null, 'deleted' => null,
], ],
[ [
'id' => '2c386086-f4c5-4093-bea5-ee9c29479f53', 'id' => '2c386086-f4c5-4093-bea5-ee9c29479f53',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'product_sku_id' => null, 'product_sku_id' => null,
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'photo_dir' => 'categories', 'photo_dir' => 'categories',
'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f51.png', 'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f51.png',
'primary_photo' => 0, 'primary_photo' => 0,
'primary_category_photo' => 0, 'primary_category_photo' => 0,
'primary_sku_photo' => 0, 'primary_sku_photo' => 0,
'photo_position' => 100, 'photo_position' => 100,
'enabled' => 1, 'enabled' => 1,
'created' => '2025-08-10 04:32:10', 'created' => '2025-08-10 04:32:10',
'modified' => '2025-08-10 04:32:10', 'modified' => '2025-08-10 04:32:10',
'deleted' => null, 'deleted' => null,
], ],
[
'id' => '2c386086-f4c5-4093-bea5-ee9c29479f11',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'product_sku_id' => '3a477e3e-7977-4813-81f6-f85949613979',
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'photo_dir' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f58.png',
'primary_photo' => 0,
'primary_category_photo' => 0,
'primary_sku_photo' => 1,
'photo_position' => 100,
'enabled' => 1,
'created' => '2025-08-10 04:32:10',
'modified' => '2025-08-10 04:32:10',
'deleted' => null,
],
[
'id' => '2c386086-f4c5-4093-bea5-ee9c29479f12',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'product_sku_id' => '3a477e3e-7977-4813-81f6-f85949613979',
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'photo_dir' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f51.png',
'primary_photo' => 0,
'primary_category_photo' => 0,
'primary_sku_photo' => 0,
'photo_position' => 100,
'enabled' => 1,
'created' => '2025-08-10 04:32:10',
'modified' => '2025-08-10 04:32:10',
'deleted' => null,
],
];
parent::init();
}
[
'id' => '2c386086-f4c5-4093-bea5-ee9c29479f11',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'product_sku_id' => '3a477e3e-7977-4813-81f6-f85949613979',
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'photo_dir' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f58.png',
'primary_photo' => 0,
'primary_category_photo' => 0,
'primary_sku_photo' => 1,
'photo_position' => 100,
'enabled' => 1,
'created' => '2025-08-10 04:32:10',
'modified' => '2025-08-10 04:32:10',
'deleted' => null,
],
[
'id' => '2c386086-f4c5-4093-bea5-ee9c29479f12',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'product_sku_id' => '3a477e3e-7977-4813-81f6-f85949613979',
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'photo_dir' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f51.png',
'primary_photo' => 0,
'primary_category_photo' => 0,
'primary_sku_photo' => 0,
'photo_position' => 100,
'enabled' => 1,
'created' => '2025-08-10 04:32:10',
'modified' => '2025-08-10 04:32:10',
'deleted' => null,
],
];
parent::init();
}
} }
@@ -8,30 +8,30 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* ProductSkuVariantValuesFixture * ProductSkuVariantValuesFixture
*/ */
class ProductSkuVariantValuesFixture extends TestFixture class ProductSkuVariantValuesFixture extends TestFixture {
{
/** /**
* Table name * Table name
* *
* @var string * @var string
*/ */
public string $table = 'product_sku_variant_values'; public string $table = 'product_sku_variant_values';
/** /**
* Init method * Init method
* *
* @return void * @return void
*/ */
public function init(): void public function init(): void {
{ $this->records = [
$this->records = [ [
[ 'id' => '98b609d8-1d4f-484c-a13a-6adb7102da56',
'id' => '98b609d8-1d4f-484c-a13a-6adb7102da56', 'product_sku_id' => '3a477e3e-7977-4813-81f6-f85949613979',
'product_sku_id' => '3a477e3e-7977-4813-81f6-f85949613979', 'product_variant_id' => '2e6e4031-c430-4d07-b8d6-a4e759b72569',
'product_variant_id' => '2e6e4031-c430-4d07-b8d6-a4e759b72569', 'product_category_variant_option_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d23',
'product_category_variant_option_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d23', ],
], ];
]; parent::init();
parent::init(); }
}
} }
+23 -22
View File
@@ -8,34 +8,35 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* ProductSkusFixture * ProductSkusFixture
*/ */
class ProductSkusFixture extends TestFixture class ProductSkusFixture extends TestFixture {
{
/** /**
* Table name * Table name
* *
* @var string * @var string
*/ */
public string $table = 'product_skus'; public string $table = 'product_skus';
/**
/**
* Init method * Init method
* *
* @return void * @return void
*/ */
public function init(): void public function init(): void {
{ $this->records = [
$this->records = [ [
[ 'id' => '3a477e3e-7977-4813-81f6-f85949613979',
'id' => '3a477e3e-7977-4813-81f6-f85949613979', 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', 'sku' => '3a477e3e-7977-4813-81f6-f85949613979',
'sku' => '3a477e3e-7977-4813-81f6-f85949613979', 'barcode' => '3a477e3e-7977-4813-81f6-f85949613979',
'barcode' => '3a477e3e-7977-4813-81f6-f85949613979', 'price' => 1.5,
'price' => 1.5, 'cost' => 1.5,
'cost' => 1.5, 'created' => '2025-04-15 09:09:15',
'created' => '2025-04-15 09:09:15', 'modified' => '2025-04-15 09:09:15',
'modified' => '2025-04-15 09:09:15', 'deleted' => null,
'deleted' => null, ],
], ];
]; parent::init();
parent::init(); }
}
} }
+37 -37
View File
@@ -8,45 +8,45 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* ProductVariantsFixture * ProductVariantsFixture
*/ */
class ProductVariantsFixture extends TestFixture class ProductVariantsFixture extends TestFixture {
{
/** /**
* Init method * Init method
* *
* @return void * @return void
*/ */
public function init(): void public function init(): void {
{ $this->records = [
$this->records = [ [
[ 'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72568',
'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72568', 'name' => 'Color',
'name' => 'Color', 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93', 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', 'enabled' => 1,
'enabled' => 1, ],
], [
[ 'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72569',
'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72569', 'name' => 'Color',
'name' => 'Color', 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93', 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05318',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05318', 'enabled' => 1,
'enabled' => 1, ],
], [
[ 'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72561',
'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72561', 'name' => 'AWG',
'name' => 'AWG', 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94', 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', 'enabled' => 1,
'enabled' => 1, ],
], [
[ 'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72562',
'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72562', 'name' => 'AWG',
'name' => 'AWG', 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94', 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05318',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05318', 'enabled' => 1,
'enabled' => 1, ],
] ];
]; parent::init();
parent::init(); }
}
} }
+23 -23
View File
@@ -8,31 +8,31 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* ProductsFixture * ProductsFixture
*/ */
class ProductsFixture extends TestFixture class ProductsFixture extends TestFixture {
{
/** /**
* Init method * Init method
* *
* @return void * @return void
*/ */
public function init(): void public function init(): void {
{ $this->records = [
$this->records = [ [
[ 'id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', 'name' => '12AWG RED TXL Wire',
'name' => '12AWG RED TXL Wire', 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', 'product_type_id' => 1,
'product_type_id' => 1, 'deleted' => null,
'deleted' => null, ],
], [
[ 'id' => 'cfc98a9a-29b2-44c8-b587-8156adc05318',
'id' => 'cfc98a9a-29b2-44c8-b587-8156adc05318', 'name' => 'Heat Shrink',
'name' => 'Heat Shrink', 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', 'product_type_id' => 1,
'product_type_id' => 1, 'deleted' => null,
'deleted' => null, ],
], ];
]; parent::init();
parent::init(); }
}
} }
@@ -14,55 +14,52 @@ use RecursiveIteratorIterator;
* *
* Used to make logging in easier and to handle folder structure for product images * Used to make logging in easier and to handle folder structure for product images
*/ */
class BaseControllerTest extends TestCase class BaseControllerTest extends TestCase {
{
use IntegrationTestTrait;
public function loginUserByRole(string $role = 'admin'): void use IntegrationTestTrait;
{
$this->session(['Auth.User.id' => 1]);
$this->session(['Auth.id' => 1]);
}
/** public function loginUserByRole(string $role = 'admin'): void {
$this->session(['Auth.User.id' => 1]);
$this->session(['Auth.id' => 1]);
}
/**
* @return void * @return void
*/ */
public function testTest() public function testTest() {
{ $this->assertEquals(1, 1);
$this->assertEquals(1, 1); }
}
/** /**
* setUp method * setUp method
* *
* @return void * @return void
*/ */
protected function setUp(): void protected function setUp(): void {
{ parent::setUp();
parent::setUp(); $toCopy = PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'webroot' . DS . 'images' . DS . '2c386086-f4c5-4093-bea5-ee9c29479f58.png';
$toCopy = PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'webroot' . DS . 'images' . DS . '2c386086-f4c5-4093-bea5-ee9c29479f58.png'; $productsFolder = PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'webroot' . DS . 'uploads' . DS
$productsFolder = PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'webroot' . DS . 'uploads' . DS . . 'images' . DS . 'products' . DS . 'cfc98a9a-29b2-44c8-b587-8156adc05317';
'images' . DS . 'products' . DS . 'cfc98a9a-29b2-44c8-b587-8156adc05317'; $newName = $productsFolder . DS . '2c386086-f4c5-4093-bea5-ee9c29479f58.png';
$newName = $productsFolder . DS . '2c386086-f4c5-4093-bea5-ee9c29479f58.png'; if (file_exists($toCopy)) {
if (file_exists($toCopy)) { if (!file_exists($productsFolder)) {
if (!file_exists($productsFolder)) { mkdir($productsFolder, 0775, true);
mkdir($productsFolder, 0775, true); }
} copy($toCopy, $newName);
copy($toCopy, $newName); }
} }
}
protected function tearDown(): void protected function tearDown(): void {
{ parent::tearDown(); // TODO: Change the autogenerated stub
parent::tearDown(); // TODO: Change the autogenerated stub
$path = Configure::readOrFail('CakeProducts.photos.directory');
if (file_exists($path)) {
$di = new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS);
$ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
foreach ($ri as $file) {
$file->isDir() ? rmdir($file->getRealPath()) : unlink($file->getRealPath());
}
}
}
$path = Configure::readOrFail('CakeProducts.photos.directory');
if (file_exists($path)) {
$di = new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS);
$ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
foreach ( $ri as $file ) {
$file->isDir() ? rmdir($file->getRealPath()) : unlink($file->getRealPath());
}
}
}
} }
@@ -4,332 +4,317 @@ declare(strict_types=1);
namespace CakeProducts\Test\TestCase\Controller; namespace CakeProducts\Test\TestCase\Controller;
use Cake\Log\Log; use Cake\Log\Log;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry; use Cake\ORM\TableRegistry;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
use CakeProducts\Controller\ExternalProductCatalogsController; use CakeProducts\Controller\ExternalProductCatalogsController;
use CakeProducts\Model\Table\ExternalProductCatalogsTable;
use PHPUnit\Exception;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
/** /**
* CakeProducts\Controller\ExternalProductCatalogsController Test Case * CakeProducts\Controller\ExternalProductCatalogsController Test Case
*/ */
#[CoversClass(ExternalProductCatalogsController::class)] #[CoversClass(ExternalProductCatalogsController::class)]
class ExternalProductCatalogsControllerTest extends BaseControllerTest class ExternalProductCatalogsControllerTest extends BaseControllerTest {
{
/** /**
* Test subject table * Test subject table
* *
* @var ExternalProductCatalogsTable|Table * @var \CakeProducts\Model\Table\ExternalProductCatalogsTable|\Cake\ORM\Table
*/ */
protected $ExternalProductCatalogs; protected $ExternalProductCatalogs;
/** /**
* Fixtures * Fixtures
* *
* @var array<string> * @var array<string>
*/ */
protected array $fixtures = [ protected array $fixtures = [
'plugin.CakeProducts.ExternalProductCatalogs', 'plugin.CakeProducts.ExternalProductCatalogs',
'plugin.CakeProducts.ExternalProductCatalogsProductCatalogs', 'plugin.CakeProducts.ExternalProductCatalogsProductCatalogs',
'plugin.CakeProducts.ProductCatalogs', 'plugin.CakeProducts.ProductCatalogs',
]; ];
/** /**
* setUp method * setUp method
* *
* @return void * @return void
*/ */
protected function setUp(): void protected function setUp(): void {
{ parent::setUp();
parent::setUp();
// $this->enableCsrfToken(); // $this->enableCsrfToken();
// $this->enableSecurityToken(); // $this->enableSecurityToken();
$this->disableErrorHandlerMiddleware(); $this->disableErrorHandlerMiddleware();
$this->ExternalProductCatalogs = $this->getTableLocator()->get('CakeProducts.ExternalProductCatalogs'); $this->ExternalProductCatalogs = $this->getTableLocator()->get('CakeProducts.ExternalProductCatalogs');
} }
/** /**
* tearDown method * tearDown method
* *
* @return void * @return void
*/ */
protected function tearDown(): void protected function tearDown(): void {
{ unset($this->ExternalProductCatalogs);
unset($this->ExternalProductCatalogs);
parent::tearDown(); parent::tearDown();
} }
/** /**
* Test index method * Test index method
* *
* Tests the index action with a logged in user * Tests the index action with a logged in user
* *
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::index() * @uses \CakeProducts\Controller\ExternalProductCatalogsController::index()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testIndexGet(): void public function testIndexGet(): void {
{ Log::debug('inside testIndexGet ExternalProductCatalogsControllerTest');
Log::debug('inside testIndexGet ExternalProductCatalogsControllerTest'); $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ExternalProductCatalogs',
'controller' => 'ExternalProductCatalogs', 'action' => 'index',
'action' => 'index', ];
]; $this->get($url);
$this->get($url); $this->assertResponseCode(200);
$this->assertResponseCode(200); }
}
/** /**
* Test view method * Test view method
* *
* Tests the view action with a logged in user * Tests the view action with a logged in user
* *
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::view() * @uses \CakeProducts\Controller\ExternalProductCatalogsController::view()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testViewGet(): void public function testViewGet(): void {
{ $id = '115153f3-2f59-4234-8ff8-e1b205769999';
$id = '115153f3-2f59-4234-8ff8-e1b205769999'; $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ExternalProductCatalogs',
'controller' => 'ExternalProductCatalogs', 'action' => 'view',
'action' => 'view', $id,
$id, ];
]; $this->get($url);
$this->get($url); $this->assertResponseCode(200);
$this->assertResponseCode(200); }
}
/** /**
* Test add method * Test add method
* *
* Tests the add action with a logged in user * Tests the add action with a logged in user
* *
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::add() * @uses \CakeProducts\Controller\ExternalProductCatalogsController::add()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testAddGet(): void public function testAddGet(): void {
{ $cntBefore = $this->ExternalProductCatalogs->find()->count();
$cntBefore = $this->ExternalProductCatalogs->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ExternalProductCatalogs', 'controller' => 'ExternalProductCatalogs',
'action' => 'add', 'action' => 'add',
]; ];
$this->get($url); $this->get($url);
$this->assertResponseCode(200); $this->assertResponseCode(200);
$cntAfter = $this->ExternalProductCatalogs->find()->count(); $cntAfter = $this->ExternalProductCatalogs->find()->count();
$this->assertEquals($cntBefore, $cntAfter); $this->assertEquals($cntBefore, $cntAfter);
} }
/** /**
* Test add method * Test add method
* *
* Tests a POST request to the add action with a logged in user * Tests a POST request to the add action with a logged in user
* *
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::add() * @uses \CakeProducts\Controller\ExternalProductCatalogsController::add()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testAddPostSuccess(): void public function testAddPostSuccess(): void {
{ $linksTable = TableRegistry::getTableLocator()->get('CakeProducts.ExternalProductCatalogsProductCatalogs');
$linksTable = TableRegistry::getTableLocator()->get('CakeProducts.ExternalProductCatalogsProductCatalogs'); $cntBefore = $this->ExternalProductCatalogs->find()->count();
$cntBefore = $this->ExternalProductCatalogs->find()->count(); $linksBefore = $linksTable->find()->count();
$linksBefore = $linksTable->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ExternalProductCatalogs', 'controller' => 'ExternalProductCatalogs',
'action' => 'add', 'action' => 'add',
]; ];
$data = [ $data = [
'base_url' => 'http://localhost:8766', 'base_url' => 'http://localhost:8766',
'api_url' => 'http://localhost:8766/api/v1/', 'api_url' => 'http://localhost:8766/api/v1/',
'enabled' => true, 'enabled' => true,
'external_product_catalogs_product_catalogs' => [ 'external_product_catalogs_product_catalogs' => [
['product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428'], ['product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428'],
] ],
]; ];
$this->post($url, $data); $this->post($url, $data);
$this->assertResponseCode(302); $this->assertResponseCode(302);
$this->assertRedirectContains('external-product-catalogs'); $this->assertRedirectContains('external-product-catalogs');
$cntAfter = $this->ExternalProductCatalogs->find()->count(); $cntAfter = $this->ExternalProductCatalogs->find()->count();
$linksAfter = $linksTable->find()->count(); $linksAfter = $linksTable->find()->count();
$this->assertEquals($cntBefore + 1, $cntAfter); $this->assertEquals($cntBefore + 1, $cntAfter);
$this->assertEquals($linksBefore + 1, $linksAfter); $this->assertEquals($linksBefore + 1, $linksAfter);
} }
/** /**
* Test add method * Test add method
* *
* Tests a POST request to the add action with a logged in user * Tests a POST request to the add action with a logged in user
* *
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::add() * @uses \CakeProducts\Controller\ExternalProductCatalogsController::add()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testAddPostFailure(): void public function testAddPostFailure(): void {
{ $cntBefore = $this->ExternalProductCatalogs->find()->count();
$cntBefore = $this->ExternalProductCatalogs->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ExternalProductCatalogs', 'controller' => 'ExternalProductCatalogs',
'action' => 'add', 'action' => 'add',
]; ];
$data = [ $data = [
'product_catalog_id' => 999999, 'product_catalog_id' => 999999,
'base_url' => '', 'base_url' => '',
'api_url' => 'http://localhost:8766/api/v1/', 'api_url' => 'http://localhost:8766/api/v1/',
'enabled' => true, 'enabled' => true,
]; ];
$this->post($url, $data); $this->post($url, $data);
$this->assertResponseCode(200); $this->assertResponseCode(200);
$cntAfter = $this->ExternalProductCatalogs->find()->count(); $cntAfter = $this->ExternalProductCatalogs->find()->count();
$this->assertEquals($cntBefore, $cntAfter); $this->assertEquals($cntBefore, $cntAfter);
} }
/** /**
* Test edit method * Test edit method
* *
* Tests the edit action with a logged in user * Tests the edit action with a logged in user
* *
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::edit() * @uses \CakeProducts\Controller\ExternalProductCatalogsController::edit()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testEditGet(): void public function testEditGet(): void {
{ $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ExternalProductCatalogs',
'controller' => 'ExternalProductCatalogs', 'action' => 'edit',
'action' => 'edit', '115153f3-2f59-4234-8ff8-e1b205769999',
'115153f3-2f59-4234-8ff8-e1b205769999', ];
]; $this->get($url);
$this->get($url); $this->assertResponseCode(200);
$this->assertResponseCode(200); }
}
/** /**
* Test edit method * Test edit method
* *
* Tests a PUT request to the edit action with a logged in user * Tests a PUT request to the edit action with a logged in user
* *
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::edit() * @uses \CakeProducts\Controller\ExternalProductCatalogsController::edit()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testEditPutSuccess(): void public function testEditPutSuccess(): void {
{ $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $id = '115153f3-2f59-4234-8ff8-e1b205769999';
$id = '115153f3-2f59-4234-8ff8-e1b205769999'; $before = $this->ExternalProductCatalogs->get($id);
$before = $this->ExternalProductCatalogs->get($id); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ExternalProductCatalogs',
'controller' => 'ExternalProductCatalogs', 'action' => 'edit',
'action' => 'edit', $id,
$id, ];
]; $data = [
$data = [ 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', 'base_url' => 'http://localhost:8766',
'base_url' => 'http://localhost:8766', 'api_url' => 'http://localhost:8766/api/v1/',
'api_url' => 'http://localhost:8766/api/v1/', 'enabled' => true,
'enabled' => true, ];
]; $this->put($url, $data);
$this->put($url, $data);
$this->assertResponseCode(302); $this->assertResponseCode(302);
$this->assertRedirectContains('external-product-catalogs'); $this->assertRedirectContains('external-product-catalogs');
$after = $this->ExternalProductCatalogs->get($id); $after = $this->ExternalProductCatalogs->get($id);
// assert saved properly below // assert saved properly below
} }
/** /**
* Test edit method * Test edit method
* *
* Tests a PUT request to the edit action with a logged in user * Tests a PUT request to the edit action with a logged in user
* *
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::edit() * @uses \CakeProducts\Controller\ExternalProductCatalogsController::edit()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testEditPutFailure(): void public function testEditPutFailure(): void {
{ $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $id = '115153f3-2f59-4234-8ff8-e1b205769999';
$id = '115153f3-2f59-4234-8ff8-e1b205769999'; $before = $this->ExternalProductCatalogs->get($id);
$before = $this->ExternalProductCatalogs->get($id); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ExternalProductCatalogs',
'controller' => 'ExternalProductCatalogs', 'action' => 'edit',
'action' => 'edit', $id,
$id, ];
]; $data = [
$data = [ 'product_catalog_id' => 9999999,
'product_catalog_id' => 9999999, 'base_url' => '',
'base_url' => '', 'api_url' => 'http://localhost:8766/api/v1/',
'api_url' => 'http://localhost:8766/api/v1/', 'enabled' => true,
'enabled' => true, ];
]; $this->put($url, $data);
$this->put($url, $data); $this->assertResponseCode(200);
$this->assertResponseCode(200); $after = $this->ExternalProductCatalogs->get($id);
$after = $this->ExternalProductCatalogs->get($id);
// assert save failed below // assert save failed below
} }
/** /**
* Test delete method * Test delete method
* *
* Tests the delete action with a logged in user * Tests the delete action with a logged in user
* *
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::delete() * @uses \CakeProducts\Controller\ExternalProductCatalogsController::delete()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testDelete(): void public function testDelete(): void {
{ $cntBefore = $this->ExternalProductCatalogs->find()->count();
$cntBefore = $this->ExternalProductCatalogs->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ExternalProductCatalogs', 'controller' => 'ExternalProductCatalogs',
'action' => 'delete', 'action' => 'delete',
'115153f3-2f59-4234-8ff8-e1b205769999', '115153f3-2f59-4234-8ff8-e1b205769999',
]; ];
$this->delete($url); $this->delete($url);
$this->assertResponseCode(302); $this->assertResponseCode(302);
$this->assertRedirectContains('external-product-catalogs'); $this->assertRedirectContains('external-product-catalogs');
$cntAfter = $this->ExternalProductCatalogs->find()->count();
$this->assertEquals($cntBefore - 1, $cntAfter);
}
$cntAfter = $this->ExternalProductCatalogs->find()->count();
$this->assertEquals($cntBefore - 1, $cntAfter);
}
} }
@@ -4,118 +4,111 @@ declare(strict_types=1);
namespace CakeProducts\Test\TestCase\Controller; namespace CakeProducts\Test\TestCase\Controller;
use CakeProducts\Controller\ExternalProductCatalogsProductCatalogsController; use CakeProducts\Controller\ExternalProductCatalogsProductCatalogsController;
use Cake\ORM\Table;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
use CakeProducts\Model\Table\ExternalProductCatalogsProductCatalogsTable;
use PHPUnit\Exception;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
/** /**
* CakeProducts\Controller\ExternalProductCatalogsProductCatalogsController Test Case * CakeProducts\Controller\ExternalProductCatalogsProductCatalogsController Test Case
*/ */
#[CoversClass(ExternalProductCatalogsProductCatalogsController::class)] #[CoversClass(ExternalProductCatalogsProductCatalogsController::class)]
class ExternalProductCatalogsProductCatalogsControllerTest extends BaseControllerTest class ExternalProductCatalogsProductCatalogsControllerTest extends BaseControllerTest {
{
/** /**
* Test subject table * Test subject table
* *
* @var ExternalProductCatalogsProductCatalogsTable|Table * @var \CakeProducts\Model\Table\ExternalProductCatalogsProductCatalogsTable|\Cake\ORM\Table
*/ */
protected $ExternalProductCatalogsProductCatalogs; protected $ExternalProductCatalogsProductCatalogs;
/**
/**
* Fixtures * Fixtures
* *
* @var array<string> * @var array<string>
*/ */
protected array $fixtures = [ protected array $fixtures = [
'plugin.CakeProducts.ExternalProductCatalogsProductCatalogs', 'plugin.CakeProducts.ExternalProductCatalogsProductCatalogs',
'plugin.CakeProducts.ExternalProductCatalogs', 'plugin.CakeProducts.ExternalProductCatalogs',
'plugin.CakeProducts.ProductCatalogs', 'plugin.CakeProducts.ProductCatalogs',
]; ];
/** /**
* setUp method * setUp method
* *
* @return void * @return void
*/ */
protected function setUp(): void protected function setUp(): void {
{ parent::setUp();
parent::setUp();
// $this->enableCsrfToken(); // $this->enableCsrfToken();
// $this->enableSecurityToken(); // $this->enableSecurityToken();
$this->disableErrorHandlerMiddleware(); $this->disableErrorHandlerMiddleware();
$this->ExternalProductCatalogsProductCatalogs = $this->getTableLocator()->get('CakeProducts.ExternalProductCatalogsProductCatalogs'); $this->ExternalProductCatalogsProductCatalogs = $this->getTableLocator()->get('CakeProducts.ExternalProductCatalogsProductCatalogs');
} }
/** /**
* tearDown method * tearDown method
* *
* @return void * @return void
*/ */
protected function tearDown(): void protected function tearDown(): void {
{ unset($this->ExternalProductCatalogsProductCatalogs);
unset($this->ExternalProductCatalogsProductCatalogs);
parent::tearDown(); parent::tearDown();
} }
/** /**
* Test add method * Test add method
* *
* Tests the add action with a logged in user * Tests the add action with a logged in user
* *
* @uses \CakeProducts\Controller\ExternalProductCatalogsProductCatalogsController::add() * @uses \CakeProducts\Controller\ExternalProductCatalogsProductCatalogsController::add()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testAddGet(): void public function testAddGet(): void {
{ $cntBefore = $this->ExternalProductCatalogsProductCatalogs->find()->count();
$cntBefore = $this->ExternalProductCatalogsProductCatalogs->find()->count();
// $this->loginUserByRole('admin'); // $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ExternalProductCatalogsProductCatalogs', 'controller' => 'ExternalProductCatalogsProductCatalogs',
'action' => 'add', 'action' => 'add',
]; ];
$this->get($url); $this->get($url);
$this->assertResponseCode(200); $this->assertResponseCode(200);
$cntAfter = $this->ExternalProductCatalogsProductCatalogs->find()->count(); $cntAfter = $this->ExternalProductCatalogsProductCatalogs->find()->count();
$this->assertEquals($cntBefore, $cntAfter); $this->assertEquals($cntBefore, $cntAfter);
} }
/** /**
* Test delete method * Test delete method
* *
* Tests the delete action with a logged in user * Tests the delete action with a logged in user
* *
* @uses \CakeProducts\Controller\ExternalProductCatalogsProductCatalogsController::delete() * @uses \CakeProducts\Controller\ExternalProductCatalogsProductCatalogsController::delete()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testDelete(): void public function testDelete(): void {
{ $cntBeforeWithTrashed = $this->ExternalProductCatalogsProductCatalogs->find('withTrashed')->count();
$cntBeforeWithTrashed = $this->ExternalProductCatalogsProductCatalogs->find('withTrashed')->count(); $cntBefore = $this->ExternalProductCatalogsProductCatalogs->find()->count();
$cntBefore = $this->ExternalProductCatalogsProductCatalogs->find()->count();
// $this->loginUserByRole('admin'); // $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ExternalProductCatalogsProductCatalogs', 'controller' => 'ExternalProductCatalogsProductCatalogs',
'action' => 'delete', 'action' => 'delete',
1, 1,
]; ];
$this->delete($url); $this->delete($url);
$this->assertResponseCode(302); $this->assertResponseCode(302);
$this->assertRedirectContains('external-product-catalogs'); $this->assertRedirectContains('external-product-catalogs');
$cntAfterWithTrashed = $this->ExternalProductCatalogsProductCatalogs->find('withTrashed')->count();
$cntAfter = $this->ExternalProductCatalogsProductCatalogs->find()->count();
$this->assertEquals($cntBefore - 1, $cntAfter);
$this->assertEquals($cntBeforeWithTrashed, $cntAfterWithTrashed);
}
$cntAfterWithTrashed = $this->ExternalProductCatalogsProductCatalogs->find('withTrashed')->count();
$cntAfter = $this->ExternalProductCatalogsProductCatalogs->find()->count();
$this->assertEquals($cntBefore - 1, $cntAfter);
$this->assertEquals($cntBeforeWithTrashed, $cntAfterWithTrashed);
}
} }
@@ -3,325 +3,311 @@ declare(strict_types=1);
namespace CakeProducts\Test\TestCase\Controller; namespace CakeProducts\Test\TestCase\Controller;
use Cake\ORM\Table;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
use CakeProducts\Controller\ProductCatalogsController; use CakeProducts\Controller\ProductCatalogsController;
use CakeProducts\Model\Table\ProductCatalogsTable; use CakeProducts\Model\Table\ProductCatalogsTable;
use PHPUnit\Exception;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
/** /**
* CakeProducts\Controller\ProductCatalogsController Test Case * CakeProducts\Controller\ProductCatalogsController Test Case
*/ */
#[CoversClass(ProductCatalogsController::class)] #[CoversClass(ProductCatalogsController::class)]
class ProductCatalogsControllerTest extends BaseControllerTest class ProductCatalogsControllerTest extends BaseControllerTest {
{
/** /**
* Test subject table * Test subject table
* *
* @var ProductCatalogsTable|Table * @var \CakeProducts\Model\Table\ProductCatalogsTable|\Cake\ORM\Table
*/ */
protected $ProductCatalogs; protected $ProductCatalogs;
/** /**
* Fixtures * Fixtures
* *
* @var array<string> * @var array<string>
*/ */
protected array $fixtures = [ protected array $fixtures = [
'plugin.CakeProducts.ProductCatalogs', 'plugin.CakeProducts.ProductCatalogs',
'plugin.CakeProducts.ProductCategories', 'plugin.CakeProducts.ProductCategories',
]; ];
/** /**
* setUp method * setUp method
* *
* @return void * @return void
*/ */
protected function setUp(): void protected function setUp(): void {
{ parent::setUp();
parent::setUp();
// $this->enableCsrfToken(); // $this->enableCsrfToken();
// $this->enableSecurityToken(); // $this->enableSecurityToken();
$this->disableErrorHandlerMiddleware(); $this->disableErrorHandlerMiddleware();
$config = $this->getTableLocator()->exists('ProductCatalogs') ? [] : ['className' => ProductCatalogsTable::class]; $config = $this->getTableLocator()->exists('ProductCatalogs') ? [] : ['className' => ProductCatalogsTable::class];
$this->ProductCatalogs = $this->getTableLocator()->get('ProductCatalogs', $config); $this->ProductCatalogs = $this->getTableLocator()->get('ProductCatalogs', $config);
} }
/** /**
* tearDown method * tearDown method
* *
* @return void * @return void
*/ */
protected function tearDown(): void protected function tearDown(): void {
{ unset($this->ProductCatalogs);
unset($this->ProductCatalogs);
parent::tearDown(); parent::tearDown();
} }
/** /**
* Test index method * Test index method
* *
* Tests the index action with a logged in user * Tests the index action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductCatalogsController::index() * @uses \CakeProducts\Controller\ProductCatalogsController::index()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testIndexGet(): void public function testIndexGet(): void {
{ $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ProductCatalogs',
'controller' => 'ProductCatalogs', 'action' => 'index',
'action' => 'index', ];
]; $this->get($url);
$this->get($url); $this->assertResponseCode(200);
$this->assertResponseCode(200); }
}
/** /**
* Test view method * Test view method
* *
* Tests the view action with a logged in user * Tests the view action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductCatalogsController::view() * @uses \CakeProducts\Controller\ProductCatalogsController::view()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testViewGet(): void public function testViewGet(): void {
{ $id = '115153f3-2f59-4234-8ff8-e1b205761428';
$id = '115153f3-2f59-4234-8ff8-e1b205761428'; $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ProductCatalogs',
'controller' => 'ProductCatalogs', 'action' => 'view',
'action' => 'view', $id,
$id, ];
]; $this->get($url);
$this->get($url); $this->assertResponseCode(200);
$this->assertResponseCode(200); }
}
/** /**
* Test add method * Test add method
* *
* Tests the add action with a logged in user * Tests the add action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductCatalogsController::add() * @uses \CakeProducts\Controller\ProductCatalogsController::add()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testAddGet(): void public function testAddGet(): void {
{ $cntBefore = $this->ProductCatalogs->find()->count();
$cntBefore = $this->ProductCatalogs->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ProductCatalogs', 'controller' => 'ProductCatalogs',
'action' => 'add', 'action' => 'add',
]; ];
$this->get($url); $this->get($url);
$this->assertResponseCode(200); $this->assertResponseCode(200);
$cntAfter = $this->ProductCatalogs->find()->count(); $cntAfter = $this->ProductCatalogs->find()->count();
$this->assertEquals($cntBefore, $cntAfter); $this->assertEquals($cntBefore, $cntAfter);
} }
/** /**
* Test add method * Test add method
* *
* Tests a POST request to the add action with a logged in user * Tests a POST request to the add action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductCatalogsController::add() * @uses \CakeProducts\Controller\ProductCatalogsController::add()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testAddPostSuccess(): void public function testAddPostSuccess(): void {
{ $cntBefore = $this->ProductCatalogs->find()->count();
$cntBefore = $this->ProductCatalogs->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ProductCatalogs', 'controller' => 'ProductCatalogs',
'action' => 'add', 'action' => 'add',
]; ];
$data = [ $data = [
'name' => 'new catalog', 'name' => 'new catalog',
'catalog_description' => 'description', 'catalog_description' => 'description',
'enabled' => true, 'enabled' => true,
]; ];
$this->post($url, $data); $this->post($url, $data);
$this->assertResponseCode(302); $this->assertResponseCode(302);
$this->assertRedirectContains('product-catalogs'); $this->assertRedirectContains('product-catalogs');
$cntAfter = $this->ProductCatalogs->find()->count(); $cntAfter = $this->ProductCatalogs->find()->count();
$this->assertEquals($cntBefore + 1, $cntAfter); $this->assertEquals($cntBefore + 1, $cntAfter);
} }
/** /**
* Test add method * Test add method
* *
* Tests a POST request to the add action with a logged in user * Tests a POST request to the add action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductCatalogsController::add() * @uses \CakeProducts\Controller\ProductCatalogsController::add()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testAddPostFailure(): void public function testAddPostFailure(): void {
{ $cntBefore = $this->ProductCatalogs->find()->count();
$cntBefore = $this->ProductCatalogs->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ProductCatalogs', 'controller' => 'ProductCatalogs',
'action' => 'add', 'action' => 'add',
]; ];
$data = [ $data = [
'name' => '', 'name' => '',
'catalog_description' => '', 'catalog_description' => '',
'enabled' => '', 'enabled' => '',
]; ];
$this->post($url, $data); $this->post($url, $data);
$this->assertResponseCode(200); $this->assertResponseCode(200);
$cntAfter = $this->ProductCatalogs->find()->count(); $cntAfter = $this->ProductCatalogs->find()->count();
$this->assertEquals($cntBefore, $cntAfter); $this->assertEquals($cntBefore, $cntAfter);
} }
/** /**
* Test edit method * Test edit method
* *
* Tests the edit action with a logged in user * Tests the edit action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductCatalogsController::edit() * @uses \CakeProducts\Controller\ProductCatalogsController::edit()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testEditGet(): void public function testEditGet(): void {
{ $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $id = '115153f3-2f59-4234-8ff8-e1b205761428';
$id = '115153f3-2f59-4234-8ff8-e1b205761428'; $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ProductCatalogs',
'controller' => 'ProductCatalogs', 'action' => 'edit',
'action' => 'edit', $id,
$id, ];
]; $this->get($url);
$this->get($url); $this->assertResponseCode(200);
$this->assertResponseCode(200); }
}
/** /**
* Test edit method * Test edit method
* *
* Tests a PUT request to the edit action with a logged in user * Tests a PUT request to the edit action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductCatalogsController::edit() * @uses \CakeProducts\Controller\ProductCatalogsController::edit()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testEditPutSuccess(): void public function testEditPutSuccess(): void {
{ $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $id = '115153f3-2f59-4234-8ff8-e1b205761428';
$id = '115153f3-2f59-4234-8ff8-e1b205761428';
// $before = $this->ProductCatalogs->get($id); // $before = $this->ProductCatalogs->get($id);
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ProductCatalogs', 'controller' => 'ProductCatalogs',
'action' => 'edit', 'action' => 'edit',
$id, $id,
]; ];
$data = [ $data = [
// test new data here // test new data here
'name' => 'edited name', 'name' => 'edited name',
'catalog_description' => 'new catalog description', 'catalog_description' => 'new catalog description',
'enabled' => true, 'enabled' => true,
]; ];
$this->put($url, $data); $this->put($url, $data);
$this->assertResponseCode(302); $this->assertResponseCode(302);
$this->assertRedirectContains('product-catalogs'); $this->assertRedirectContains('product-catalogs');
$after = $this->ProductCatalogs->get($id); $after = $this->ProductCatalogs->get($id);
$this->assertEquals($data['name'], $after->name); $this->assertEquals($data['name'], $after->name);
$this->assertEquals($data['catalog_description'], $after->catalog_description); $this->assertEquals($data['catalog_description'], $after->catalog_description);
// assert saved properly below // assert saved properly below
} }
/** /**
* Test edit method * Test edit method
* *
* Tests a PUT request to the edit action with a logged in user * Tests a PUT request to the edit action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductCatalogsController::edit() * @uses \CakeProducts\Controller\ProductCatalogsController::edit()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testEditPutFailure(): void public function testEditPutFailure(): void {
{ $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $id = '115153f3-2f59-4234-8ff8-e1b205761428';
$id = '115153f3-2f59-4234-8ff8-e1b205761428'; $before = $this->ProductCatalogs->get($id);
$before = $this->ProductCatalogs->get($id); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ProductCatalogs',
'controller' => 'ProductCatalogs', 'action' => 'edit',
'action' => 'edit', $id,
$id, ];
]; $data = [
$data = [ 'name' => '',
'name' => '', 'catalog_description' => 'edited description',
'catalog_description' => 'edited description', 'enabled' => '',
'enabled' => '', ];
]; $this->put($url, $data);
$this->put($url, $data); $this->assertResponseCode(200);
$this->assertResponseCode(200); $after = $this->ProductCatalogs->get($id);
$after = $this->ProductCatalogs->get($id); $this->assertEquals($before->name, $after->name);
$this->assertEquals($before->name, $after->name); $this->assertEquals($before->catalog_description, $after->catalog_description);
$this->assertEquals($before->catalog_description, $after->catalog_description); // assert save failed below
// assert save failed below }
}
/** /**
* Test delete method * Test delete method
* *
* Tests the delete action with a logged in user * Tests the delete action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductCatalogsController::delete() * @uses \CakeProducts\Controller\ProductCatalogsController::delete()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testDelete(): void public function testDelete(): void {
{ $cntBefore = $this->ProductCatalogs->find()->count();
$cntBefore = $this->ProductCatalogs->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$id = '115153f3-2f59-4234-8ff8-e1b205761428'; $id = '115153f3-2f59-4234-8ff8-e1b205761428';
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ProductCatalogs', 'controller' => 'ProductCatalogs',
'action' => 'delete', 'action' => 'delete',
$id, $id,
]; ];
$this->delete($url); $this->delete($url);
$this->assertResponseCode(302); $this->assertResponseCode(302);
$this->assertRedirectContains('product-catalogs'); $this->assertRedirectContains('product-catalogs');
$cntAfter = $this->ProductCatalogs->find()->count();
$this->assertEquals($cntBefore - 1, $cntAfter);
}
$cntAfter = $this->ProductCatalogs->find()->count();
$this->assertEquals($cntBefore - 1, $cntAfter);
}
} }
@@ -3,334 +3,310 @@ declare(strict_types=1);
namespace CakeProducts\Test\TestCase\Controller; namespace CakeProducts\Test\TestCase\Controller;
use Cake\ORM\Table;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
use CakeProducts\Controller\ProductCategoriesController; use CakeProducts\Controller\ProductCategoriesController;
use CakeProducts\Model\Table\ProductCategoriesTable;
use PHPUnit\Exception;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
/** /**
* CakeProducts\Controller\ProductCategoriesController Test Case * CakeProducts\Controller\ProductCategoriesController Test Case
*/ */
#[CoversClass(ProductCategoriesController::class)] #[CoversClass(ProductCategoriesController::class)]
class ProductCategoriesControllerTest extends BaseControllerTest class ProductCategoriesControllerTest extends BaseControllerTest {
{
/** /**
* Test subject table * Test subject table
* *
* @var ProductCategoriesTable|Table * @var \CakeProducts\Model\Table\ProductCategoriesTable|\Cake\ORM\Table
*/ */
protected $ProductCategories; protected $ProductCategories;
/** /**
* Fixtures * Fixtures
* *
* @var array<string> * @var array<string>
*/ */
protected array $fixtures = [ protected array $fixtures = [
'plugin.CakeProducts.ProductCatalogs', 'plugin.CakeProducts.ProductCatalogs',
'plugin.CakeProducts.ProductCategories', 'plugin.CakeProducts.ProductCategories',
]; ];
/** /**
* setUp method * setUp method
* *
* @return void * @return void
*/ */
protected function setUp(): void protected function setUp(): void {
{ parent::setUp();
parent::setUp();
// $this->enableCsrfToken(); // $this->enableCsrfToken();
// $this->enableSecurityToken(); // $this->enableSecurityToken();
$this->disableErrorHandlerMiddleware(); $this->disableErrorHandlerMiddleware();
$this->ProductCategories = $this->getTableLocator()->get('CakeProducts.ProductCategories'); $this->ProductCategories = $this->getTableLocator()->get('CakeProducts.ProductCategories');
} }
/** /**
* tearDown method * tearDown method
* *
* @return void * @return void
*/ */
protected function tearDown(): void protected function tearDown(): void {
{ unset($this->ProductCategories);
unset($this->ProductCategories);
parent::tearDown(); parent::tearDown();
} }
/** /**
* Test index method * Test index method
* *
* Tests the index action with a logged in user * Tests the index action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoriesController::index * @uses \CakeProducts\Controller\ProductCategoriesController::index
* @throws Exception
* @return void
*/ */
public function testIndexGet(): void public function testIndexGet(): void {
{ $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ProductCategories',
'controller' => 'ProductCategories', 'action' => 'index',
'action' => 'index', ];
]; $this->get($url);
$this->get($url); $this->assertResponseCode(200);
$this->assertResponseCode(200); }
}
/** /**
* Test view method * Test view method
* *
* Tests the view action with a logged in user * Tests the view action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoriesController::view * @uses \CakeProducts\Controller\ProductCategoriesController::view
* @throws Exception
* @return void
*/ */
public function testViewGet(): void public function testViewGet(): void {
{ $id = 1;
$id = 1; $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ProductCategories',
'controller' => 'ProductCategories', 'action' => 'view',
'action' => 'view', $id,
$id, ];
]; $this->get($url);
$this->get($url); $this->assertResponseCode(200);
$this->assertResponseCode(200); }
}
/** /**
* Test add method * Test add method
* *
* Tests the add action with a logged in user * Tests the add action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoriesController::add * @uses \CakeProducts\Controller\ProductCategoriesController::add
* @throws Exception
* @return void
*/ */
public function testAddGet(): void public function testAddGet(): void {
{ $cntBefore = $this->ProductCategories->find()->count();
$cntBefore = $this->ProductCategories->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ProductCategories', 'controller' => 'ProductCategories',
'action' => 'add', 'action' => 'add',
]; ];
$this->get($url); $this->get($url);
$this->assertResponseCode(200); $this->assertResponseCode(200);
$cntAfter = $this->ProductCategories->find()->count(); $cntAfter = $this->ProductCategories->find()->count();
$this->assertEquals($cntBefore, $cntAfter); $this->assertEquals($cntBefore, $cntAfter);
} }
/** /**
* Test add method * Test add method
* *
* Tests a POST request to the add action with a logged in user * Tests a POST request to the add action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoriesController::add * @uses \CakeProducts\Controller\ProductCategoriesController::add
* @throws Exception
* @return void
*/ */
public function testAddPostSuccess(): void public function testAddPostSuccess(): void {
{ $cntBefore = $this->ProductCategories->find()->count();
$cntBefore = $this->ProductCategories->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ProductCategories', 'controller' => 'ProductCategories',
'action' => 'add', 'action' => 'add',
]; ];
$data = [ $data = [
'name' => 'Electrical Plugs', 'name' => 'Electrical Plugs',
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'category_description' => 'electrical', 'category_description' => 'electrical',
'parent_id' => 3, 'parent_id' => 3,
'enabled' => true, 'enabled' => true,
]; ];
$this->post($url, $data); $this->post($url, $data);
$this->assertResponseCode(302); $this->assertResponseCode(302);
$this->assertRedirectContains('product-categories'); $this->assertRedirectContains('product-categories');
$cntAfter = $this->ProductCategories->find()->count(); $cntAfter = $this->ProductCategories->find()->count();
$this->assertEquals($cntBefore + 1, $cntAfter); $this->assertEquals($cntBefore + 1, $cntAfter);
} }
/** /**
* Test add method * Test add method
* *
* Tests a POST request to the add action with a logged in user * Tests a POST request to the add action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoriesController::add * @uses \CakeProducts\Controller\ProductCategoriesController::add
* @throws Exception
* @return void
*/ */
public function testAddPostFailure(): void public function testAddPostFailure(): void {
{ $cntBefore = $this->ProductCategories->find()->count();
$cntBefore = $this->ProductCategories->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ProductCategories', 'controller' => 'ProductCategories',
'action' => 'add', 'action' => 'add',
]; ];
$data = [ $data = [
'name' => '', 'name' => '',
'product_catalog_id' => '', 'product_catalog_id' => '',
'category_description' => 'electrical', 'category_description' => 'electrical',
'parent_id' => '', 'parent_id' => '',
'enabled' => true, 'enabled' => true,
]; ];
$this->post($url, $data); $this->post($url, $data);
$this->assertResponseCode(200); $this->assertResponseCode(200);
$cntAfter = $this->ProductCategories->find()->count(); $cntAfter = $this->ProductCategories->find()->count();
$this->assertEquals($cntBefore, $cntAfter); $this->assertEquals($cntBefore, $cntAfter);
} }
/** /**
* Test edit method * Test edit method
* *
* Tests the edit action with a logged in user * Tests the edit action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoriesController::edit * @uses \CakeProducts\Controller\ProductCategoriesController::edit
* @throws Exception
* @return void
*/ */
public function testEditGet(): void public function testEditGet(): void {
{ $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ProductCategories',
'controller' => 'ProductCategories', 'action' => 'edit',
'action' => 'edit', 1,
1, ];
]; $this->get($url);
$this->get($url); $this->assertResponseCode(200);
$this->assertResponseCode(200); }
}
/** /**
* Test edit method * Test edit method
* *
* Tests a PUT request to the edit action with a logged in user * Tests a PUT request to the edit action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoriesController::edit * @uses \CakeProducts\Controller\ProductCategoriesController::edit
* @throws Exception
* @return void
*/ */
public function testEditPutSuccess(): void public function testEditPutSuccess(): void {
{ $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $id = 1;
$id = 1; $before = $this->ProductCategories->get($id);
$before = $this->ProductCategories->get($id); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ProductCategories',
'controller' => 'ProductCategories', 'action' => 'edit',
'action' => 'edit', $id,
$id, ];
]; $data = [
$data = [ // test new data here
// test new data here 'name' => 'Electrical v2',
'name' => 'Electrical v2', 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', 'category_description' => 'electrical v2',
'category_description' => 'electrical v2', 'parent_id' => '',
'parent_id' => '', 'enabled' => true,
'enabled' => true, ];
]; $this->put($url, $data);
$this->put($url, $data);
$this->assertResponseCode(302); $this->assertResponseCode(302);
$this->assertRedirectContains('product-categories'); $this->assertRedirectContains('product-categories');
$after = $this->ProductCategories->get($id); $after = $this->ProductCategories->get($id);
$this->assertEquals($data['name'], $after->name); $this->assertEquals($data['name'], $after->name);
$this->assertEquals($data['product_catalog_id'], $after->product_catalog_id); $this->assertEquals($data['product_catalog_id'], $after->product_catalog_id);
$this->assertEquals($data['category_description'], $after->category_description); $this->assertEquals($data['category_description'], $after->category_description);
$this->assertNull($after->parent_id); $this->assertNull($after->parent_id);
// assert saved properly below // assert saved properly below
} }
/** /**
* Test edit method * Test edit method
* *
* Tests a PUT request to the edit action with a logged in user * Tests a PUT request to the edit action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoriesController::edit * @uses \CakeProducts\Controller\ProductCategoriesController::edit
* @throws Exception
* @return void
*/ */
public function testEditPutFailure(): void public function testEditPutFailure(): void {
{ $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $id = 1;
$id = 1; $before = $this->ProductCategories->get($id);
$before = $this->ProductCategories->get($id); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ProductCategories',
'controller' => 'ProductCategories', 'action' => 'edit',
'action' => 'edit', $id,
$id, ];
]; $data = [
$data = [ 'name' => '',
'name' => '', 'product_catalog_id' => '',
'product_catalog_id' => '', 'category_description' => 'electrical',
'category_description' => 'electrical', 'parent_id' => '',
'parent_id' => '', 'enabled' => true,
'enabled' => true, ];
]; $this->put($url, $data);
$this->put($url, $data); $this->assertResponseCode(200);
$this->assertResponseCode(200); $after = $this->ProductCategories->get($id);
$after = $this->ProductCategories->get($id);
// assert save failed below // assert save failed below
} }
/** /**
* Test delete method * Test delete method
* *
* Tests the delete action with a logged in user * Tests the delete action with a logged in user
* *
* @return void
*@throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoriesController::delete * @uses \CakeProducts\Controller\ProductCategoriesController::delete
*@throws Exception
* @return void
*/ */
public function testDelete(): void public function testDelete(): void {
{ $cntBefore = $this->ProductCategories->find()->count();
$cntBefore = $this->ProductCategories->find()->count(); $cntBeforeWithTrashed = $this->ProductCategories->find('withTrashed')->count();
$cntBeforeWithTrashed = $this->ProductCategories->find('withTrashed')->count(); $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ProductCategories',
'controller' => 'ProductCategories', 'action' => 'delete',
'action' => 'delete', 1,
1, ];
]; $this->delete($url);
$this->delete($url); $this->assertResponseCode(302);
$this->assertResponseCode(302); $this->assertRedirectContains('product-categories');
$this->assertRedirectContains('product-categories');
$cntAfter = $this->ProductCategories->find()->count(); $cntAfter = $this->ProductCategories->find()->count();
$cntAfterWithTrashed = $this->ProductCategories->find('withTrashed')->count(); $cntAfterWithTrashed = $this->ProductCategories->find('withTrashed')->count();
$this->assertEquals($cntBefore - 2, $cntAfter); // has 1 child category
$this->assertEquals($cntBeforeWithTrashed, $cntAfterWithTrashed);
}
$this->assertEquals($cntBefore - 2, $cntAfter); // has 1 child category
$this->assertEquals($cntBeforeWithTrashed, $cntAfterWithTrashed);
}
} }
@@ -3,142 +3,133 @@ declare(strict_types=1);
namespace CakeProducts\Test\TestCase\Controller; namespace CakeProducts\Test\TestCase\Controller;
use Cake\ORM\Table;
use CakeProducts\Controller\ProductCategoryAttributeOptionsController; use CakeProducts\Controller\ProductCategoryAttributeOptionsController;
use CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable; use CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable;
use PHPUnit\Exception;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
/** /**
* CakeProducts\Controller\ProductCategoryAttributeOptionsController Test Case * CakeProducts\Controller\ProductCategoryAttributeOptionsController Test Case
*/ */
#[CoversClass(ProductCategoryAttributeOptionsController::class)] #[CoversClass(ProductCategoryAttributeOptionsController::class)]
class ProductCategoryAttributeOptionsControllerTest extends BaseControllerTest class ProductCategoryAttributeOptionsControllerTest extends BaseControllerTest {
{
/** /**
* Test subject * Test subject
* *
* @var ProductCategoryAttributeOptionsTable|Table * @var \CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable|\Cake\ORM\Table
*/ */
protected $ProductCategoryAttributeOptions; protected $ProductCategoryAttributeOptions;
/** /**
* Fixtures * Fixtures
* *
* @var array<string> * @var array<string>
*/ */
protected array $fixtures = [ protected array $fixtures = [
'plugin.CakeProducts.ProductCategoryAttributeOptions', 'plugin.CakeProducts.ProductCategoryAttributeOptions',
'plugin.CakeProducts.ProductCategoryAttributes', 'plugin.CakeProducts.ProductCategoryAttributes',
]; ];
/** /**
* setUp method * setUp method
* *
* @return void * @return void
*/ */
protected function setUp(): void protected function setUp(): void {
{ parent::setUp();
parent::setUp();
// $this->enableCsrfToken(); // $this->enableCsrfToken();
// $this->enableSecurityToken(); // $this->enableSecurityToken();
$config = $this->getTableLocator()->exists('ProductCategoryAttributeOptions') ? [] : ['className' => ProductCategoryAttributeOptionsTable::class]; $config = $this->getTableLocator()->exists('ProductCategoryAttributeOptions') ? [] : ['className' => ProductCategoryAttributeOptionsTable::class];
$this->ProductCategoryAttributeOptions = $this->getTableLocator()->get('ProductCategoryAttributeOptions', $config); $this->ProductCategoryAttributeOptions = $this->getTableLocator()->get('ProductCategoryAttributeOptions', $config);
} }
/** /**
* tearDown method * tearDown method
* *
* @return void * @return void
*/ */
protected function tearDown(): void protected function tearDown(): void {
{ unset($this->ProductCategoryAttributeOptions);
unset($this->ProductCategoryAttributeOptions);
parent::tearDown(); parent::tearDown();
} }
/** /**
* Test add method * Test add method
* *
* Tests the add action with a logged in user * Tests the add action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoryAttributeOptionsController::add * @uses \CakeProducts\Controller\ProductCategoryAttributeOptionsController::add
* @throws Exception
* @return void
*/ */
public function testAddGet(): void public function testAddGet(): void {
{ $cntBefore = $this->ProductCategoryAttributeOptions->find()->count();
$cntBefore = $this->ProductCategoryAttributeOptions->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributeOptions', 'controller' => 'ProductCategoryAttributeOptions',
'action' => 'add', 'action' => 'add',
]; ];
$this->get($url); $this->get($url);
$this->assertResponseCode(200); $this->assertResponseCode(200);
$cntAfter = $this->ProductCategoryAttributeOptions->find()->count(); $cntAfter = $this->ProductCategoryAttributeOptions->find()->count();
$this->assertEquals($cntBefore, $cntAfter); $this->assertEquals($cntBefore, $cntAfter);
} }
/** /**
* Test add method * Test add method
* *
* Tests a POST request to the add action with a logged in user * Tests a POST request to the add action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoryAttributeOptionsController::add * @uses \CakeProducts\Controller\ProductCategoryAttributeOptionsController::add
* @throws Exception
* @return void
*/ */
public function testAddPostHasNoEffect(): void public function testAddPostHasNoEffect(): void {
{ $cntBefore = $this->ProductCategoryAttributeOptions->find()->count();
$cntBefore = $this->ProductCategoryAttributeOptions->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributeOptions', 'controller' => 'ProductCategoryAttributeOptions',
'action' => 'add', 'action' => 'add',
]; ];
$data = []; $data = [];
$this->post($url, $data); $this->post($url, $data);
$this->assertResponseCode(200); $this->assertResponseCode(200);
$cntAfter = $this->ProductCategoryAttributeOptions->find()->count(); $cntAfter = $this->ProductCategoryAttributeOptions->find()->count();
$this->assertEquals($cntBefore, $cntAfter); $this->assertEquals($cntBefore, $cntAfter);
} }
/** /**
* Test delete method * Test delete method
* *
* Tests the delete action with a logged in user * Tests the delete action with a logged in user
* *
* @return void
*@throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoryAttributeOptionsController::delete * @uses \CakeProducts\Controller\ProductCategoryAttributeOptionsController::delete
*@throws Exception
* @return void
*/ */
public function testDelete(): void public function testDelete(): void {
{ $cntBefore = $this->ProductCategoryAttributeOptions->find()->count();
$cntBefore = $this->ProductCategoryAttributeOptions->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributeOptions', 'controller' => 'ProductCategoryAttributeOptions',
'action' => 'delete', 'action' => 'delete',
'e06f1723-2456-483a-b3c4-004603e032a8', 'e06f1723-2456-483a-b3c4-004603e032a8',
]; ];
$this->delete($url); $this->delete($url);
$this->assertResponseCode(302); $this->assertResponseCode(302);
$this->assertRedirectContains('product-category-attributes'); $this->assertRedirectContains('product-category-attributes');
$cntAfter = $this->ProductCategoryAttributeOptions->find()->count();
$this->assertEquals($cntBefore - 1, $cntAfter);
}
$cntAfter = $this->ProductCategoryAttributeOptions->find()->count();
$this->assertEquals($cntBefore - 1, $cntAfter);
}
} }
@@ -3,373 +3,348 @@ declare(strict_types=1);
namespace CakeProducts\Test\TestCase\Controller; namespace CakeProducts\Test\TestCase\Controller;
use Cake\ORM\Table;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
use CakeProducts\Controller\ProductCategoryAttributesController; use CakeProducts\Controller\ProductCategoryAttributesController;
use CakeProducts\Model\Table\ProductCategoryAttributesTable; use CakeProducts\Model\Table\ProductCategoryAttributesTable;
use PHPUnit\Exception;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
/** /**
* CakeProducts\Controller\ProductCategoryAttributesController Test Case * CakeProducts\Controller\ProductCategoryAttributesController Test Case
*/ */
#[CoversClass(ProductCategoryAttributesController::class)] #[CoversClass(ProductCategoryAttributesController::class)]
class ProductCategoryAttributesControllerTest extends BaseControllerTest class ProductCategoryAttributesControllerTest extends BaseControllerTest {
{
/** /**
* Test subject * Test subject
* *
* @var ProductCategoryAttributesTable|Table * @var \CakeProducts\Model\Table\ProductCategoryAttributesTable|\Cake\ORM\Table
*/ */
protected $ProductCategoryAttributes; protected $ProductCategoryAttributes;
/** /**
* Fixtures * Fixtures
* *
* @var array<string> * @var array<string>
*/ */
protected array $fixtures = [ protected array $fixtures = [
'plugin.CakeProducts.ProductCategoryAttributes', 'plugin.CakeProducts.ProductCategoryAttributes',
'plugin.CakeProducts.ProductCategories', 'plugin.CakeProducts.ProductCategories',
]; ];
/** /**
* setUp method * setUp method
* *
* @return void * @return void
*/ */
protected function setUp(): void protected function setUp(): void {
{ parent::setUp();
parent::setUp();
// $this->enableCsrfToken(); // $this->enableCsrfToken();
// $this->enableSecurityToken(); // $this->enableSecurityToken();
$config = $this->getTableLocator()->exists('ProductCategoryAttributes') ? [] : ['className' => ProductCategoryAttributesTable::class]; $config = $this->getTableLocator()->exists('ProductCategoryAttributes') ? [] : ['className' => ProductCategoryAttributesTable::class];
$this->ProductCategoryAttributes = $this->getTableLocator()->get('ProductCategoryAttributes', $config); $this->ProductCategoryAttributes = $this->getTableLocator()->get('ProductCategoryAttributes', $config);
} }
/** /**
* tearDown method * tearDown method
* *
* @return void * @return void
*/ */
protected function tearDown(): void protected function tearDown(): void {
{ unset($this->ProductCategoryAttributes);
unset($this->ProductCategoryAttributes);
parent::tearDown(); parent::tearDown();
} }
/** /**
* Test index method * Test index method
* *
* Tests the index action with a logged in user * Tests the index action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoryAttributesController::index * @uses \CakeProducts\Controller\ProductCategoryAttributesController::index
* @throws Exception
* @return void
*/ */
public function testIndexGet(): void public function testIndexGet(): void {
{ $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ProductCategoryAttributes',
'controller' => 'ProductCategoryAttributes', 'action' => 'index',
'action' => 'index', ];
]; $this->get($url);
$this->get($url); $this->assertResponseCode(200);
$this->assertResponseCode(200); }
}
/** /**
* Test view method * Test view method
* *
* Tests the view action with a logged in user * Tests the view action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoryAttributesController::view * @uses \CakeProducts\Controller\ProductCategoryAttributesController::view
* @throws Exception
* @return void
*/ */
public function testViewGet(): void public function testViewGet(): void {
{ $id = '37078cf0-0130-4b93-bb7e-abe7d665ed2c';
$id = '37078cf0-0130-4b93-bb7e-abe7d665ed2c'; $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ProductCategoryAttributes',
'controller' => 'ProductCategoryAttributes', 'action' => 'view',
'action' => 'view', $id,
$id, ];
]; $this->get($url);
$this->get($url); $this->assertResponseCode(200);
$this->assertResponseCode(200); }
}
/** /**
* Test add method * Test add method
* *
* Tests the add action with a logged in user * Tests the add action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoryAttributesController::add * @uses \CakeProducts\Controller\ProductCategoryAttributesController::add
* @throws Exception
* @return void
*/ */
public function testAddGet(): void public function testAddGet(): void {
{ $cntBefore = $this->ProductCategoryAttributes->find()->count();
$cntBefore = $this->ProductCategoryAttributes->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributes', 'controller' => 'ProductCategoryAttributes',
'action' => 'add', 'action' => 'add',
]; ];
$this->get($url); $this->get($url);
$this->assertResponseCode(200); $this->assertResponseCode(200);
$cntAfter = $this->ProductCategoryAttributes->find()->count(); $cntAfter = $this->ProductCategoryAttributes->find()->count();
$this->assertEquals($cntBefore, $cntAfter); $this->assertEquals($cntBefore, $cntAfter);
} }
/** /**
* Test add method * Test add method
* *
* Tests a POST request to the add action with a logged in user * Tests a POST request to the add action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoryAttributesController::add * @uses \CakeProducts\Controller\ProductCategoryAttributesController::add
* @throws Exception
* @return void
*/ */
public function testAddPostSuccess(): void public function testAddPostSuccess(): void {
{ $cntBefore = $this->ProductCategoryAttributes->find()->count();
$cntBefore = $this->ProductCategoryAttributes->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributes', 'controller' => 'ProductCategoryAttributes',
'action' => 'add', 'action' => 'add',
]; ];
$data = [ $data = [
'name' => 'Size', 'name' => 'Size',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'attribute_type_id' => 2, 'attribute_type_id' => 2,
'enabled' => true, 'enabled' => true,
]; ];
$this->post($url, $data); $this->post($url, $data);
$this->assertResponseCode(302); $this->assertResponseCode(302);
$this->assertRedirectContains('product-category-attributes'); $this->assertRedirectContains('product-category-attributes');
$cntAfter = $this->ProductCategoryAttributes->find()->count(); $cntAfter = $this->ProductCategoryAttributes->find()->count();
$this->assertEquals($cntBefore + 1, $cntAfter); $this->assertEquals($cntBefore + 1, $cntAfter);
} }
/** /**
* Test add method * Test add method
* *
* Tests a POST request to the add action with a logged in user * Tests a POST request to the add action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoryAttributesController::add * @uses \CakeProducts\Controller\ProductCategoryAttributesController::add
* @throws Exception
* @return void
*/ */
public function testAddPostSuccessConstrainedWithOptions(): void public function testAddPostSuccessConstrainedWithOptions(): void {
{ $cntBefore = $this->ProductCategoryAttributes->find()->count();
$cntBefore = $this->ProductCategoryAttributes->find()->count(); $cntOptionsBefore = $this->ProductCategoryAttributes->ProductCategoryAttributeOptions->find()->count();
$cntOptionsBefore = $this->ProductCategoryAttributes->ProductCategoryAttributeOptions->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributes', 'controller' => 'ProductCategoryAttributes',
'action' => 'add', 'action' => 'add',
]; ];
$data = [ $data = [
'name' => 'Size', 'name' => 'Size',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'attribute_type_id' => 1, 'attribute_type_id' => 1,
'enabled' => true, 'enabled' => true,
'product_category_attribute_options' => [ 'product_category_attribute_options' => [
[ [
'attribute_value' => 'XL', 'attribute_value' => 'XL',
'attribute_label' => 'XL', 'attribute_label' => 'XL',
'enabled' => true, 'enabled' => true,
], ],
[ [
'attribute_value' => 'L', 'attribute_value' => 'L',
'attribute_label' => 'L', 'attribute_label' => 'L',
'enabled' => true, 'enabled' => true,
] ],
], ],
]; ];
$this->post($url, $data); $this->post($url, $data);
$this->assertResponseCode(302); $this->assertResponseCode(302);
$this->assertRedirectContains('product-category-attributes'); $this->assertRedirectContains('product-category-attributes');
$cntAfter = $this->ProductCategoryAttributes->find()->count(); $cntAfter = $this->ProductCategoryAttributes->find()->count();
$cntOptionsAfter = $this->ProductCategoryAttributes->ProductCategoryAttributeOptions->find()->count(); $cntOptionsAfter = $this->ProductCategoryAttributes->ProductCategoryAttributeOptions->find()->count();
$this->assertEquals($cntBefore + 1, $cntAfter); $this->assertEquals($cntBefore + 1, $cntAfter);
$this->assertEquals($cntOptionsBefore + 2, $cntOptionsAfter); $this->assertEquals($cntOptionsBefore + 2, $cntOptionsAfter);
} }
/** /**
* Test add method * Test add method
* *
* Tests a POST request to the add action with a logged in user * Tests a POST request to the add action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoryAttributesController::add * @uses \CakeProducts\Controller\ProductCategoryAttributesController::add
* @throws Exception
* @return void
*/ */
public function testAddPostFailure(): void public function testAddPostFailure(): void {
{ $cntBefore = $this->ProductCategoryAttributes->find()->count();
$cntBefore = $this->ProductCategoryAttributes->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributes', 'controller' => 'ProductCategoryAttributes',
'action' => 'add', 'action' => 'add',
]; ];
$data = [ $data = [
'name' => '', 'name' => '',
'product_category_id' => 1, 'product_category_id' => 1,
'attribute_type_id' => 1, 'attribute_type_id' => 1,
'enabled' => true, 'enabled' => true,
]; ];
$this->post($url, $data); $this->post($url, $data);
$this->assertResponseCode(200); $this->assertResponseCode(200);
$cntAfter = $this->ProductCategoryAttributes->find()->count(); $cntAfter = $this->ProductCategoryAttributes->find()->count();
$this->assertEquals($cntBefore, $cntAfter); $this->assertEquals($cntBefore, $cntAfter);
} }
/** /**
* Test edit method * Test edit method
* *
* Tests the edit action with a logged in user * Tests the edit action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoryAttributesController::edit * @uses \CakeProducts\Controller\ProductCategoryAttributesController::edit
* @throws Exception
* @return void
*/ */
public function testEditGet(): void public function testEditGet(): void {
{ $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ProductCategoryAttributes',
'controller' => 'ProductCategoryAttributes', 'action' => 'edit',
'action' => 'edit', '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
'37078cf0-0130-4b93-bb7e-abe7d665ed2c', ];
]; $this->get($url);
$this->get($url); $this->assertResponseCode(200);
$this->assertResponseCode(200); }
}
/** /**
* Test edit method * Test edit method
* *
* Tests a PUT request to the edit action with a logged in user * Tests a PUT request to the edit action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoryAttributesController::edit * @uses \CakeProducts\Controller\ProductCategoryAttributesController::edit
* @throws Exception
* @return void
*/ */
public function testEditPutSuccess(): void public function testEditPutSuccess(): void {
{ $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $id = '37078cf0-0130-4b93-bb7e-abe7d665ed2c';
$id = '37078cf0-0130-4b93-bb7e-abe7d665ed2c'; $before = $this->ProductCategoryAttributes->get($id);
$before = $this->ProductCategoryAttributes->get($id); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ProductCategoryAttributes',
'controller' => 'ProductCategoryAttributes', 'action' => 'edit',
'action' => 'edit', $id,
$id, ];
]; $data = [
$data = [ // test new data here
// test new data here 'name' => 'Color',
'name' => 'Color', 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', 'attribute_type_id' => 1,
'attribute_type_id' => 1, 'enabled' => true,
'enabled' => true, ];
]; $this->put($url, $data);
$this->put($url, $data);
$this->assertResponseCode(302); $this->assertResponseCode(302);
$this->assertRedirectContains('product-category-attributes'); $this->assertRedirectContains('product-category-attributes');
$after = $this->ProductCategoryAttributes->get($id); $after = $this->ProductCategoryAttributes->get($id);
// assert saved properly below // assert saved properly below
} }
/** /**
* Test edit method * Test edit method
* *
* Tests a PUT request to the edit action with a logged in user * Tests a PUT request to the edit action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoryAttributesController::edit * @uses \CakeProducts\Controller\ProductCategoryAttributesController::edit
* @throws Exception
* @return void
*/ */
public function testEditPutFailure(): void public function testEditPutFailure(): void {
{ $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $id = '37078cf0-0130-4b93-bb7e-abe7d665ed2c';
$id = '37078cf0-0130-4b93-bb7e-abe7d665ed2c'; $before = $this->ProductCategoryAttributes->get($id);
$before = $this->ProductCategoryAttributes->get($id); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ProductCategoryAttributes',
'controller' => 'ProductCategoryAttributes', 'action' => 'edit',
'action' => 'edit', $id,
$id, ];
]; $data = [
$data = [ 'name' => '',
'name' => '', 'product_category_id' => 1,
'product_category_id' => 1, 'attribute_type_id' => 1,
'attribute_type_id' => 1, 'enabled' => true,
'enabled' => true, ];
]; $this->put($url, $data);
$this->put($url, $data); $this->assertResponseCode(200);
$this->assertResponseCode(200); $after = $this->ProductCategoryAttributes->get($id);
$after = $this->ProductCategoryAttributes->get($id);
// assert save failed below // assert save failed below
} }
/** /**
* Test delete method * Test delete method
* *
* Tests the delete action with a logged in user * Tests the delete action with a logged in user
* *
* @return void
*@throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoryAttributesController::delete * @uses \CakeProducts\Controller\ProductCategoryAttributesController::delete
*@throws Exception
* @return void
*/ */
public function testDelete(): void public function testDelete(): void {
{ $cntBefore = $this->ProductCategoryAttributes->find()->count();
$cntBefore = $this->ProductCategoryAttributes->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributes', 'controller' => 'ProductCategoryAttributes',
'action' => 'delete', 'action' => 'delete',
'37078cf0-0130-4b93-bb7e-abe7d665ed2c', '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
]; ];
$this->delete($url); $this->delete($url);
$this->assertResponseCode(302); $this->assertResponseCode(302);
$this->assertRedirectContains('product-category-attributes'); $this->assertRedirectContains('product-category-attributes');
$cntAfter = $this->ProductCategoryAttributes->find()->count();
$this->assertEquals($cntBefore - 1, $cntAfter);
}
$cntAfter = $this->ProductCategoryAttributes->find()->count();
$this->assertEquals($cntBefore - 1, $cntAfter);
}
} }
@@ -3,425 +3,412 @@ declare(strict_types=1);
namespace CakeProducts\Test\TestCase\Controller; namespace CakeProducts\Test\TestCase\Controller;
use Cake\ORM\Table;
use CakeProducts\Controller\ProductCategoryVariantsController; use CakeProducts\Controller\ProductCategoryVariantsController;
use CakeProducts\Model\Table\ProductCategoryAttributesTable;
use CakeProducts\Model\Table\ProductCategoryVariantOptionsTable; use CakeProducts\Model\Table\ProductCategoryVariantOptionsTable;
use CakeProducts\Model\Table\ProductCategoryVariantsTable; use CakeProducts\Model\Table\ProductCategoryVariantsTable;
use PHPUnit\Exception;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
/** /**
* CakeProducts\Controller\ProductCategoryVariantsController Test Case * CakeProducts\Controller\ProductCategoryVariantsController Test Case
*/ */
#[CoversClass(ProductCategoryVariantsController::class)] #[CoversClass(ProductCategoryVariantsController::class)]
class ProductCategoryVariantsControllerTest extends BaseControllerTest class ProductCategoryVariantsControllerTest extends BaseControllerTest {
{
/**
* Test subject
*
* @var ProductCategoryVariantsTable|Table
*/
protected $ProductCategoryVariants;
/** /**
* Test subject * Test subject
* *
* @var ProductCategoryVariantOptionsTable|Table * @var \CakeProducts\Model\Table\ProductCategoryVariantsTable|\Cake\ORM\Table
*/ */
protected $ProductCategoryVariantOptions; protected $ProductCategoryVariants;
/**
/**
* Test subject
*
* @var \CakeProducts\Model\Table\ProductCategoryVariantOptionsTable|\Cake\ORM\Table
*/
protected $ProductCategoryVariantOptions;
/**
* Fixtures * Fixtures
* *
* @var array<string> * @var array<string>
*/ */
protected array $fixtures = [ protected array $fixtures = [
'plugin.CakeProducts.ProductCategoryVariants', 'plugin.CakeProducts.ProductCategoryVariants',
'plugin.CakeProducts.ProductCategoryVariantOptions', 'plugin.CakeProducts.ProductCategoryVariantOptions',
'plugin.CakeProducts.ProductVariants', 'plugin.CakeProducts.ProductVariants',
'plugin.CakeProducts.ProductCategories', 'plugin.CakeProducts.ProductCategories',
'plugin.CakeProducts.Products', 'plugin.CakeProducts.Products',
'plugin.CakeProducts.ProductSkus', 'plugin.CakeProducts.ProductSkus',
'plugin.CakeProducts.ProductPhotos', 'plugin.CakeProducts.ProductPhotos',
]; ];
/** /**
* setUp method * setUp method
* *
* @return void * @return void
*/ */
protected function setUp(): void protected function setUp(): void {
{ parent::setUp();
parent::setUp(); $this->disableErrorHandlerMiddleware();
$this->disableErrorHandlerMiddleware();
$config = $this->getTableLocator()->exists('ProductCategoryVariants') ? [] : ['className' => ProductCategoryVariantsTable::class]; $config = $this->getTableLocator()->exists('ProductCategoryVariants') ? [] : ['className' => ProductCategoryVariantsTable::class];
$this->ProductCategoryVariants = $this->getTableLocator()->get('ProductCategoryVariants', $config); $this->ProductCategoryVariants = $this->getTableLocator()->get('ProductCategoryVariants', $config);
$config = $this->getTableLocator()->exists('ProductCategoryVariantOptions') ? [] : ['className' => ProductCategoryVariantOptionsTable::class]; $config = $this->getTableLocator()->exists('ProductCategoryVariantOptions') ? [] : ['className' => ProductCategoryVariantOptionsTable::class];
$this->ProductCategoryVariantOptions = $this->getTableLocator()->get('ProductCategoryVariantOptions', $config); $this->ProductCategoryVariantOptions = $this->getTableLocator()->get('ProductCategoryVariantOptions', $config);
} }
/** /**
* tearDown method * tearDown method
* *
* @return void * @return void
*/ */
protected function tearDown(): void protected function tearDown(): void {
{ unset($this->ProductCategoryVariants);
unset($this->ProductCategoryVariants); unset($this->ProductCategoryVariantOptions);
unset($this->ProductCategoryVariantOptions);
parent::tearDown(); parent::tearDown();
} }
/** /**
* Test index method * Test index method
* *
* Tests the index action with a logged in user * Tests the index action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductCategoryVariantsController::index() * @uses \CakeProducts\Controller\ProductCategoryVariantsController::index()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testIndexGet(): void public function testIndexGet(): void {
{ //$this->loginUserByRole('admin');
//$this->loginUserByRole('admin'); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ProductCategoryVariants',
'controller' => 'ProductCategoryVariants', 'action' => 'index',
'action' => 'index', ];
]; $this->get($url);
$this->get($url); $this->assertResponseCode(200);
$this->assertResponseCode(200); }
}
/** /**
* Test view method * Test view method
* *
* Tests the view action with a logged in user * Tests the view action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductCategoryVariantsController::view() * @uses \CakeProducts\Controller\ProductCategoryVariantsController::view()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testViewGet(): void public function testViewGet(): void {
{ $id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93';
$id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93'; //$this->loginUserByRole('admin');
//$this->loginUserByRole('admin'); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ProductCategoryVariants',
'controller' => 'ProductCategoryVariants', 'action' => 'view',
'action' => 'view', $id,
$id, ];
]; $this->get($url);
$this->get($url); $this->assertResponseCode(200);
$this->assertResponseCode(200); }
}
/** /**
* Test add method * Test add method
* *
* Tests the add action with a logged in user * Tests the add action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductCategoryVariantsController::add() * @uses \CakeProducts\Controller\ProductCategoryVariantsController::add()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testAddGet(): void public function testAddGet(): void {
{ $cntBefore = $this->ProductCategoryVariants->find()->count();
$cntBefore = $this->ProductCategoryVariants->find()->count();
//$this->loginUserByRole('admin'); //$this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryVariants', 'controller' => 'ProductCategoryVariants',
'action' => 'add', 'action' => 'add',
]; ];
$this->get($url); $this->get($url);
$this->assertResponseCode(200); $this->assertResponseCode(200);
$cntAfter = $this->ProductCategoryVariants->find()->count(); $cntAfter = $this->ProductCategoryVariants->find()->count();
$this->assertEquals($cntBefore, $cntAfter); $this->assertEquals($cntBefore, $cntAfter);
} }
/** /**
* Test add method * Test add method
* *
* Tests a POST request to the add action with a logged in user * Tests a POST request to the add action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductCategoryVariantsController::add() * @uses \CakeProducts\Controller\ProductCategoryVariantsController::add()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testAddPostLoggedInSuccess(): void public function testAddPostLoggedInSuccess(): void {
{ $cntBefore = $this->ProductCategoryVariants->find()->count();
$cntBefore = $this->ProductCategoryVariants->find()->count(); $cntBeforeOptions = $this->ProductCategoryVariantOptions->find()->count();
$cntBeforeOptions = $this->ProductCategoryVariantOptions->find()->count();
//$this->loginUserByRole('admin'); //$this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryVariants', 'controller' => 'ProductCategoryVariants',
'action' => 'add', 'action' => 'add',
]; ];
$data = [ $data = [
'name' => 'Size', 'name' => 'Size',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'product_id' => '', 'product_id' => '',
'enabled' => true, 'enabled' => true,
'product_category_variant_options' => [ 'product_category_variant_options' => [
[ [
'variant_value' => 'XL', 'variant_value' => 'XL',
'variant_label' => 'XL', 'variant_label' => 'XL',
'enabled' => true, 'enabled' => true,
], ],
[ [
'variant_value' => 'XXL', 'variant_value' => 'XXL',
'variant_label' => 'XXL', 'variant_label' => 'XXL',
'enabled' => true, 'enabled' => true,
], ],
] ],
]; ];
$this->post($url, $data); $this->post($url, $data);
$this->assertResponseCode(302); $this->assertResponseCode(302);
$this->assertRedirectContains('product-category-variants'); $this->assertRedirectContains('product-category-variants');
$cntAfter = $this->ProductCategoryVariants->find()->count(); $cntAfter = $this->ProductCategoryVariants->find()->count();
$cntAfterOptions = $this->ProductCategoryVariantOptions->find()->count(); $cntAfterOptions = $this->ProductCategoryVariantOptions->find()->count();
$this->assertEquals($cntBefore + 1, $cntAfter); $this->assertEquals($cntBefore + 1, $cntAfter);
$this->assertEquals($cntBeforeOptions + 2, $cntAfterOptions); $this->assertEquals($cntBeforeOptions + 2, $cntAfterOptions);
} }
/** /**
* Test add method * Test add method
* *
* Tests a POST request to the add action with a logged in user * Tests a POST request to the add action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductCategoryVariantsController::add() * @uses \CakeProducts\Controller\ProductCategoryVariantsController::add()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testAddPostLoggedInFailure(): void public function testAddPostLoggedInFailure(): void {
{ $cntBefore = $this->ProductCategoryVariants->find()->count();
$cntBefore = $this->ProductCategoryVariants->find()->count();
//$this->loginUserByRole('admin'); //$this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryVariants', 'controller' => 'ProductCategoryVariants',
'action' => 'add', 'action' => 'add',
]; ];
$data = [ $data = [
'name' => '', 'name' => '',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'enabled' => true, 'enabled' => true,
]; ];
$this->post($url, $data); $this->post($url, $data);
$this->assertResponseCode(200); $this->assertResponseCode(200);
$cntAfter = $this->ProductCategoryVariants->find()->count(); $cntAfter = $this->ProductCategoryVariants->find()->count();
$this->assertEquals($cntBefore, $cntAfter); $this->assertEquals($cntBefore, $cntAfter);
} }
/** /**
* Test edit method * Test edit method
* *
* Tests the edit action with a logged in user * Tests the edit action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductCategoryVariantsController::edit() * @uses \CakeProducts\Controller\ProductCategoryVariantsController::edit()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testEditGet(): void public function testEditGet(): void {
{ //$this->loginUserByRole('admin');
//$this->loginUserByRole('admin'); $id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93';
$id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93';
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryVariants', 'controller' => 'ProductCategoryVariants',
'action' => 'edit', 'action' => 'edit',
$id, $id,
]; ];
$this->get($url); $this->get($url);
$this->assertResponseCode(200); $this->assertResponseCode(200);
} }
/** /**
* Test edit method * Test edit method
* *
* Tests a PUT request to the edit action with a logged in user * Tests a PUT request to the edit action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductCategoryVariantsController::edit() * @uses \CakeProducts\Controller\ProductCategoryVariantsController::edit()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testEditPutLoggedInSuccess(): void public function testEditPutLoggedInSuccess(): void {
{ //$this->loginUserByRole('admin');
//$this->loginUserByRole('admin'); $id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93';
$id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93'; $before = $this->ProductCategoryVariants->get($id);
$before = $this->ProductCategoryVariants->get($id); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ProductCategoryVariants',
'controller' => 'ProductCategoryVariants', 'action' => 'edit',
'action' => 'edit', $id,
$id, ];
]; $data = [
$data = [ // test new data here
// test new data here 'name' => 'updated name',
'name' => 'updated name', 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', 'enabled' => true,
'enabled' => true, ];
]; $this->put($url, $data);
$this->put($url, $data);
$this->assertResponseCode(302); $this->assertResponseCode(302);
$this->assertRedirectContains('product-category-variants'); $this->assertRedirectContains('product-category-variants');
$after = $this->ProductCategoryVariants->get($id); $after = $this->ProductCategoryVariants->get($id);
// assert saved properly below // assert saved properly below
} }
/** /**
* Test edit method * Test edit method
* *
* Tests a PUT request to the edit action with a logged in user * Tests a PUT request to the edit action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductCategoryVariantsController::edit() * @uses \CakeProducts\Controller\ProductCategoryVariantsController::edit()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testEditPutLoggedInSuccessSystemVariant(): void public function testEditPutLoggedInSuccessSystemVariant(): void {
{ //$this->loginUserByRole('admin');
//$this->loginUserByRole('admin'); $id = '5a386e9f-6e7a-4ae7-9360-c8e529f78222'; // subscription length
$id = '5a386e9f-6e7a-4ae7-9360-c8e529f78222'; // subscription length $before = $this->ProductCategoryVariants->get($id);
$before = $this->ProductCategoryVariants->get($id); $cntBeforeOptions = $this->ProductCategoryVariantOptions
$cntBeforeOptions = $this->ProductCategoryVariantOptions ->find()
->find() ->where(['product_category_variant_id' => $id])
->where(['product_category_variant_id' => $id]) ->toArray();
->toArray();
// $this->assertEquals(2, count($cntBeforeOptions)); // $this->assertEquals(2, count($cntBeforeOptions));
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryVariants', 'controller' => 'ProductCategoryVariants',
'action' => 'edit', 'action' => 'edit',
$id, $id,
]; ];
$data = [ $data = [
// test new data here // test new data here
'name' => 'updated name', 'name' => 'updated name',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'enabled' => false, 'enabled' => false,
'product_category_variant_options' => [ 'product_category_variant_options' => [
[ [
'variant_value' => '14', 'variant_value' => '14',
'variant_label' => '14', 'variant_label' => '14',
'enabled' => true, 'enabled' => true,
], ],
[ [
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f22221', 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f22221',
'variant_value' => '6', 'variant_value' => '6',
'variant_label' => '6', 'variant_label' => '6',
'enabled' => true, 'enabled' => true,
], ],
[ [
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f22222', 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f22222',
'variant_value' => 12, 'variant_value' => 12,
'variant_label' => 12, 'variant_label' => 12,
'enabled' => true, 'enabled' => true,
], ],
], ],
]; ];
$this->put($url, $data); $this->put($url, $data);
$this->assertResponseCode(302); $this->assertResponseCode(302);
$this->assertRedirectContains('product-category-variants'); $this->assertRedirectContains('product-category-variants');
$after = $this->ProductCategoryVariants->get($id); $after = $this->ProductCategoryVariants->get($id);
$cntAfterOptions = $this->ProductCategoryVariantOptions $cntAfterOptions = $this->ProductCategoryVariantOptions
->find() ->find()
->where(['product_category_variant_id' => $id]) ->where(['product_category_variant_id' => $id])
->toArray(); ->toArray();
$this->assertEquals(count($cntBeforeOptions) + 1, count($cntAfterOptions)); $this->assertEquals(count($cntBeforeOptions) + 1, count($cntAfterOptions));
$this->assertEquals($before->name, $after->name); $this->assertEquals($before->name, $after->name);
$this->assertNull($after->product_category_id); $this->assertNull($after->product_category_id);
$this->assertTrue($after->enabled); $this->assertTrue($after->enabled);
// assert saved properly below // assert saved properly below
} }
/** /**
* Test edit method * Test edit method
* *
* Tests a PUT request to the edit action with a logged in user * Tests a PUT request to the edit action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductCategoryVariantsController::edit() * @uses \CakeProducts\Controller\ProductCategoryVariantsController::edit()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testEditPutLoggedInFailure(): void public function testEditPutLoggedInFailure(): void {
{ //$this->loginUserByRole('admin');
//$this->loginUserByRole('admin'); $id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93';
$id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93'; $before = $this->ProductCategoryVariants->get($id);
$before = $this->ProductCategoryVariants->get($id); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ProductCategoryVariants',
'controller' => 'ProductCategoryVariants', 'action' => 'edit',
'action' => 'edit', $id,
$id, ];
]; $data = [
$data = [ 'name' => '',
'name' => '', 'product_category_id' => 'NOT A VALID ID',
'product_category_id' => 'NOT A VALID ID', 'enabled' => true,
'enabled' => true, ];
]; $this->put($url, $data);
$this->put($url, $data); $this->assertResponseCode(200);
$this->assertResponseCode(200); $after = $this->ProductCategoryVariants->get($id);
$after = $this->ProductCategoryVariants->get($id);
// assert save failed below // assert save failed below
} }
/** /**
* Test delete method * Test delete method
* *
* Tests the delete action with a logged in user * Tests the delete action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductCategoryVariantsController::delete() * @uses \CakeProducts\Controller\ProductCategoryVariantsController::delete()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testDelete(): void public function testDelete(): void {
{ $cntBefore = $this->ProductCategoryVariants->find()->count();
$cntBefore = $this->ProductCategoryVariants->find()->count();
//$this->loginUserByRole('admin'); //$this->loginUserByRole('admin');
$id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93'; $id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93';
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryVariants', 'controller' => 'ProductCategoryVariants',
'action' => 'delete', 'action' => 'delete',
$id, $id,
]; ];
$this->delete($url); $this->delete($url);
$this->assertResponseCode(302); $this->assertResponseCode(302);
$this->assertRedirectContains('product-category-variants'); $this->assertRedirectContains('product-category-variants');
$cntAfter = $this->ProductCategoryVariants->find()->count();
$this->assertEquals($cntBefore - 1, $cntAfter);
}
$cntAfter = $this->ProductCategoryVariants->find()->count();
$this->assertEquals($cntBefore - 1, $cntAfter);
}
} }
File diff suppressed because it is too large Load Diff
@@ -3,355 +3,340 @@ declare(strict_types=1);
namespace CakeProducts\Test\TestCase\Controller; namespace CakeProducts\Test\TestCase\Controller;
use Cake\ORM\Table;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
use CakeProducts\Controller\ProductSkusController; use CakeProducts\Controller\ProductSkusController;
use CakeProducts\Model\Table\ProductSkusTable; use CakeProducts\Model\Table\ProductSkusTable;
use CakeProducts\Model\Table\ProductSkuVariantValuesTable; use CakeProducts\Model\Table\ProductSkuVariantValuesTable;
use CakeProducts\Model\Table\ProductsTable;
use PHPUnit\Exception;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
/** /**
* CakeProducts\Controller\ProductSkusController Test Case * CakeProducts\Controller\ProductSkusController Test Case
*/ */
#[CoversClass(ProductSkusController::class)] #[CoversClass(ProductSkusController::class)]
class ProductSkusControllerTest extends BaseControllerTest class ProductSkusControllerTest extends BaseControllerTest {
{
/** /**
* Test subject table * Test subject table
* *
* @var ProductSkusTable|Table * @var \CakeProducts\Model\Table\ProductSkusTable|\Cake\ORM\Table
*/ */
protected $ProductSkus; protected $ProductSkus;
/** /**
* Test subject table * Test subject table
* *
* @var ProductSkuVariantValuesTable|Table * @var \CakeProducts\Model\Table\ProductSkuVariantValuesTable|\Cake\ORM\Table
*/ */
protected $ProductSkuVariantValues; protected $ProductSkuVariantValues;
/** /**
* Fixtures * Fixtures
* *
* @var array<string> * @var array<string>
*/ */
protected array $fixtures = [ protected array $fixtures = [
'plugin.CakeProducts.ProductSkus', 'plugin.CakeProducts.ProductSkus',
'plugin.CakeProducts.Products', 'plugin.CakeProducts.Products',
'plugin.CakeProducts.ProductAttributes', 'plugin.CakeProducts.ProductAttributes',
'plugin.CakeProducts.ProductVariants', 'plugin.CakeProducts.ProductVariants',
'plugin.CakeProducts.ProductCategoryVariants', 'plugin.CakeProducts.ProductCategoryVariants',
'plugin.CakeProducts.ProductCategoryVariantOptions', 'plugin.CakeProducts.ProductCategoryVariantOptions',
'plugin.CakeProducts.ProductSkuVariantValues', 'plugin.CakeProducts.ProductSkuVariantValues',
]; ];
/** /**
* setUp method * setUp method
* *
* @return void * @return void
*/ */
protected function setUp(): void protected function setUp(): void {
{ parent::setUp();
parent::setUp();
// $this->enableCsrfToken(); // $this->enableCsrfToken();
// $this->enableSecurityToken(); // $this->enableSecurityToken();
$this->disableErrorHandlerMiddleware(); $this->disableErrorHandlerMiddleware();
$config = $this->getTableLocator()->exists('ProductSkus') ? [] : ['className' => ProductSkusTable::class]; $config = $this->getTableLocator()->exists('ProductSkus') ? [] : ['className' => ProductSkusTable::class];
$this->ProductSkus = $this->getTableLocator()->get('ProductSkus', $config); $this->ProductSkus = $this->getTableLocator()->get('ProductSkus', $config);
$config = $this->getTableLocator()->exists('ProductSkuVariantValues') ? [] : ['className' => ProductSkuVariantValuesTable::class]; $config = $this->getTableLocator()->exists('ProductSkuVariantValues') ? [] : ['className' => ProductSkuVariantValuesTable::class];
$this->ProductSkuVariantValues = $this->getTableLocator()->get('ProductSkuVariantValues', $config); $this->ProductSkuVariantValues = $this->getTableLocator()->get('ProductSkuVariantValues', $config);
} }
/** /**
* tearDown method * tearDown method
* *
* @return void * @return void
*/ */
protected function tearDown(): void protected function tearDown(): void {
{ unset($this->ProductSkus);
unset($this->ProductSkus);
parent::tearDown(); parent::tearDown();
} }
/** /**
* Test index method * Test index method
* *
* Tests the index action with a logged in user * Tests the index action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductSkusController::index() * @uses \CakeProducts\Controller\ProductSkusController::index()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testIndexGet(): void public function testIndexGet(): void {
{ $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ProductSkus',
'controller' => 'ProductSkus', 'action' => 'index',
'action' => 'index', ];
]; $this->get($url);
$this->get($url); $this->assertResponseCode(200);
$this->assertResponseCode(200); }
}
/** /**
* Test view method * Test view method
* *
* Tests the view action with a logged in user * Tests the view action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductSkusController::view() * @uses \CakeProducts\Controller\ProductSkusController::view()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testViewGet(): void public function testViewGet(): void {
{ $id = '3a477e3e-7977-4813-81f6-f85949613979';
$id = '3a477e3e-7977-4813-81f6-f85949613979'; $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ProductSkus',
'controller' => 'ProductSkus', 'action' => 'view',
'action' => 'view', $id,
$id, ];
]; $this->get($url);
$this->get($url); $this->assertResponseCode(200);
$this->assertResponseCode(200); }
}
/** /**
* Test add method * Test add method
* *
* Tests the add action with a logged in user * Tests the add action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductSkusController::add() * @uses \CakeProducts\Controller\ProductSkusController::add()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testAddGet(): void public function testAddGet(): void {
{ $cntBefore = $this->ProductSkus->find()->count();
$cntBefore = $this->ProductSkus->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ProductSkus', 'controller' => 'ProductSkus',
'action' => 'add', 'action' => 'add',
'cfc98a9a-29b2-44c8-b587-8156adc05317' 'cfc98a9a-29b2-44c8-b587-8156adc05317',
]; ];
$this->get($url); $this->get($url);
$this->assertResponseCode(200); $this->assertResponseCode(200);
$cntAfter = $this->ProductSkus->find()->count(); $cntAfter = $this->ProductSkus->find()->count();
$this->assertEquals($cntBefore, $cntAfter); $this->assertEquals($cntBefore, $cntAfter);
} }
/** /**
* Test add method * Test add method
* *
* Tests a POST request to the add action with a logged in user * Tests a POST request to the add action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductSkusController::add() * @uses \CakeProducts\Controller\ProductSkusController::add()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testAddPostSuccess(): void public function testAddPostSuccess(): void {
{ $cntBefore = $this->ProductSkus->find()->count();
$cntBefore = $this->ProductSkus->find()->count(); $cntVariantValuesBefore = $this->ProductSkuVariantValues->find()->count();
$cntVariantValuesBefore = $this->ProductSkuVariantValues->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ProductSkus', 'controller' => 'ProductSkus',
'action' => 'add', 'action' => 'add',
'cfc98a9a-29b2-44c8-b587-8156adc05317', 'cfc98a9a-29b2-44c8-b587-8156adc05317',
]; ];
$data = [ $data = [
0 => [ 0 => [
'sku' => 'cfc98a9a-29b2-44c8-b587-8156a', 'sku' => 'cfc98a9a-29b2-44c8-b587-8156a',
'barcode' => 'cfc98a9a-29b2-44c8-b587-8156a', 'barcode' => 'cfc98a9a-29b2-44c8-b587-8156a',
'price' => 1.5, 'price' => 1.5,
'cost' => 1.5, 'cost' => 1.5,
'product_sku_variant_values' => [ 'product_sku_variant_values' => [
0 => [ 0 => [
'product_variant_id' => '2e6e4031-c430-4d07-b8d6-a4e759b72568', 'product_variant_id' => '2e6e4031-c430-4d07-b8d6-a4e759b72568',
'product_category_variant_option_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d23', 'product_category_variant_option_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d23',
], ],
], ],
], ],
]; ];
$this->post($url, $data); $this->post($url, $data);
$this->assertResponseCode(302); $this->assertResponseCode(302);
$this->assertRedirectContains('product-skus'); $this->assertRedirectContains('product-skus');
$cntAfter = $this->ProductSkus->find()->count(); $cntAfter = $this->ProductSkus->find()->count();
$cntVariantValuesAfter = $this->ProductSkuVariantValues->find()->count(); $cntVariantValuesAfter = $this->ProductSkuVariantValues->find()->count();
$this->assertEquals($cntBefore + 1, $cntAfter); $this->assertEquals($cntBefore + 1, $cntAfter);
$this->assertEquals($cntVariantValuesBefore + 1, $cntVariantValuesAfter); $this->assertEquals($cntVariantValuesBefore + 1, $cntVariantValuesAfter);
} }
/** /**
* Test add method * Test add method
* *
* Tests a POST request to the add action with a logged in user * Tests a POST request to the add action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductSkusController::add() * @uses \CakeProducts\Controller\ProductSkusController::add()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testAddPostFailure(): void public function testAddPostFailure(): void {
{ $cntBefore = $this->ProductSkus->find()->count();
$cntBefore = $this->ProductSkus->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ProductSkus', 'controller' => 'ProductSkus',
'action' => 'add', 'action' => 'add',
'cfc98a9a-29b2-44c8-b587-8156adc05317', 'cfc98a9a-29b2-44c8-b587-8156adc05317',
]; ];
$data = [ $data = [
0 => [ 0 => [
'sku' => '', 'sku' => '',
'barcode' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', 'barcode' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'price' => 1.5, 'price' => 1.5,
'cost' => 1.5, 'cost' => 1.5,
], ],
]; ];
$this->post($url, $data); $this->post($url, $data);
$this->assertResponseCode(200); $this->assertResponseCode(200);
$cntAfter = $this->ProductSkus->find()->count(); $cntAfter = $this->ProductSkus->find()->count();
$this->assertEquals($cntBefore, $cntAfter); $this->assertEquals($cntBefore, $cntAfter);
} }
/** /**
* Test edit method * Test edit method
* *
* Tests the edit action with a logged in user * Tests the edit action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductSkusController::edit() * @uses \CakeProducts\Controller\ProductSkusController::edit()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testEditGet(): void public function testEditGet(): void {
{ $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ProductSkus',
'controller' => 'ProductSkus', 'action' => 'edit',
'action' => 'edit', '3a477e3e-7977-4813-81f6-f85949613979',
'3a477e3e-7977-4813-81f6-f85949613979', ];
]; $this->get($url);
$this->get($url); $this->assertResponseCode(200);
$this->assertResponseCode(200); }
}
/** /**
* Test edit method * Test edit method
* *
* Tests a PUT request to the edit action with a logged in user * Tests a PUT request to the edit action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductSkusController::edit() * @uses \CakeProducts\Controller\ProductSkusController::edit()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testEditPutSuccess(): void public function testEditPutSuccess(): void {
{ $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $id = '3a477e3e-7977-4813-81f6-f85949613979';
$id = '3a477e3e-7977-4813-81f6-f85949613979'; $before = $this->ProductSkus->get($id);
$before = $this->ProductSkus->get($id); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ProductSkus',
'controller' => 'ProductSkus', 'action' => 'edit',
'action' => 'edit', $id,
$id, ];
]; $data = [
$data = [ // test new data here
// test new data here ];
]; $this->put($url, $data);
$this->put($url, $data);
$this->assertResponseCode(302); $this->assertResponseCode(302);
$this->assertRedirectContains('product-skus'); $this->assertRedirectContains('product-skus');
$after = $this->ProductSkus->get($id); $after = $this->ProductSkus->get($id);
// assert saved properly below // assert saved properly below
} }
/** /**
* Test edit method * Test edit method
* *
* Tests a PUT request to the edit action with a logged in user * Tests a PUT request to the edit action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductSkusController::edit() * @uses \CakeProducts\Controller\ProductSkusController::edit()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testEditPutFailure(): void public function testEditPutFailure(): void {
{ $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $id = '3a477e3e-7977-4813-81f6-f85949613979';
$id = '3a477e3e-7977-4813-81f6-f85949613979'; $before = $this->ProductSkus->get($id);
$before = $this->ProductSkus->get($id); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'ProductSkus',
'controller' => 'ProductSkus', 'action' => 'edit',
'action' => 'edit', $id,
$id, ];
]; $data = [
$data = [ 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', 'sku' => '',
'sku' => '', 'barcode' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'barcode' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', 'price' => 1.5,
'price' => 1.5, 'cost' => 1.5,
'cost' => 1.5, ];
]; $this->put($url, $data);
$this->put($url, $data); $this->assertResponseCode(200);
$this->assertResponseCode(200); $after = $this->ProductSkus->get($id);
$after = $this->ProductSkus->get($id);
// assert save failed below // assert save failed below
} }
/** /**
* Test delete method * Test delete method
* *
* Tests the delete action with a logged in user * Tests the delete action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductSkusController::delete() * @uses \CakeProducts\Controller\ProductSkusController::delete()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testDelete(): void public function testDelete(): void {
{ $cntBefore = $this->ProductSkus->find()->count();
$cntBefore = $this->ProductSkus->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'ProductSkus', 'controller' => 'ProductSkus',
'action' => 'delete', 'action' => 'delete',
'3a477e3e-7977-4813-81f6-f85949613979', '3a477e3e-7977-4813-81f6-f85949613979',
]; ];
$this->delete($url); $this->delete($url);
$this->assertResponseCode(302); $this->assertResponseCode(302);
$this->assertRedirectContains('product-skus'); $this->assertRedirectContains('product-skus');
$cntAfter = $this->ProductSkus->find()->count();
$this->assertEquals($cntBefore - 1, $cntAfter);
}
$cntAfter = $this->ProductSkus->find()->count();
$this->assertEquals($cntBefore - 1, $cntAfter);
}
} }
@@ -3,343 +3,318 @@ declare(strict_types=1);
namespace CakeProducts\Test\TestCase\Controller; namespace CakeProducts\Test\TestCase\Controller;
use Cake\ORM\Table;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
use CakeProducts\Controller\ProductsController; use CakeProducts\Controller\ProductsController;
use CakeProducts\Model\Table\ProductCatalogsTable;
use CakeProducts\Model\Table\ProductsTable; use CakeProducts\Model\Table\ProductsTable;
use PHPUnit\Exception;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
/** /**
* CakeProducts\Controller\ProductsController Test Case * CakeProducts\Controller\ProductsController Test Case
*/ */
#[CoversClass(ProductsController::class)] #[CoversClass(ProductsController::class)]
class ProductsControllerTest extends BaseControllerTest class ProductsControllerTest extends BaseControllerTest {
{
/** /**
* Test subject table * Test subject table
* *
* @var ProductsTable|Table * @var \CakeProducts\Model\Table\ProductsTable|\Cake\ORM\Table
*/ */
protected $Products; protected $Products;
/** /**
* Fixtures * Fixtures
* *
* @var array<string> * @var array<string>
*/ */
protected array $fixtures = [ protected array $fixtures = [
'plugin.CakeProducts.Products', 'plugin.CakeProducts.Products',
'plugin.CakeProducts.ProductAttributes', 'plugin.CakeProducts.ProductAttributes',
'plugin.CakeProducts.ProductCategories', 'plugin.CakeProducts.ProductCategories',
'plugin.CakeProducts.ProductCategoryAttributes', 'plugin.CakeProducts.ProductCategoryAttributes',
'plugin.CakeProducts.ProductCategoryAttributeOptions', 'plugin.CakeProducts.ProductCategoryAttributeOptions',
// 'plugin.CakeProducts.ProductCatalogs', // 'plugin.CakeProducts.ProductCatalogs',
]; ];
/** /**
* setUp method * setUp method
* *
* @return void * @return void
*/ */
protected function setUp(): void protected function setUp(): void {
{ parent::setUp();
parent::setUp();
// $this->enableCsrfToken(); // $this->enableCsrfToken();
// $this->enableSecurityToken(); // $this->enableSecurityToken();
$config = $this->getTableLocator()->exists('Products') ? [] : ['className' => ProductsTable::class]; $config = $this->getTableLocator()->exists('Products') ? [] : ['className' => ProductsTable::class];
$this->Products = $this->getTableLocator()->get('Products', $config); $this->Products = $this->getTableLocator()->get('Products', $config);
} }
/** /**
* tearDown method * tearDown method
* *
* @return void * @return void
*/ */
protected function tearDown(): void protected function tearDown(): void {
{ unset($this->Products);
unset($this->Products);
parent::tearDown(); parent::tearDown();
} }
/** /**
* Test index method * Test index method
* *
* Tests the index action with a logged in user * Tests the index action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductsController::index * @uses \CakeProducts\Controller\ProductsController::index
* @throws Exception
* @return void
*/ */
public function testIndexGet(): void public function testIndexGet(): void {
{ $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'Products',
'controller' => 'Products', 'action' => 'index',
'action' => 'index', ];
]; $this->get($url);
$this->get($url); $this->assertResponseCode(200);
$this->assertResponseCode(200); }
}
/** /**
* Test view method * Test view method
* *
* Tests the view action with a logged in user * Tests the view action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductsController::view * @uses \CakeProducts\Controller\ProductsController::view
* @throws Exception
* @return void
*/ */
public function testViewGet(): void public function testViewGet(): void {
{ $id = 'cfc98a9a-29b2-44c8-b587-8156adc05317';
$id = 'cfc98a9a-29b2-44c8-b587-8156adc05317'; $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'Products',
'controller' => 'Products', 'action' => 'view',
'action' => 'view', $id,
$id, ];
]; $this->get($url);
$this->get($url); $this->assertResponseCode(200);
$this->assertResponseCode(200); }
}
/** /**
* Test add method * Test add method
* *
* Tests the add action with a logged in user * Tests the add action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductsController::add * @uses \CakeProducts\Controller\ProductsController::add
* @throws Exception
* @return void
*/ */
public function testAddGet(): void public function testAddGet(): void {
{ $cntBefore = $this->Products->find()->count();
$cntBefore = $this->Products->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'Products', 'controller' => 'Products',
'action' => 'add', 'action' => 'add',
]; ];
$this->get($url); $this->get($url);
$this->assertResponseCode(200); $this->assertResponseCode(200);
$cntAfter = $this->Products->find()->count(); $cntAfter = $this->Products->find()->count();
$this->assertEquals($cntBefore, $cntAfter); $this->assertEquals($cntBefore, $cntAfter);
} }
/** /**
* Test add method * Test add method
* *
* Tests the add action with a logged in user * Tests the add action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductsController::add * @uses \CakeProducts\Controller\ProductsController::add
* @throws Exception
* @return void
*/ */
public function testAddPostSuccess(): void public function testAddPostSuccess(): void {
{ $cntBefore = $this->Products->find()->count();
$cntBefore = $this->Products->find()->count(); $productAttributesCntBefore = $this->Products->ProductAttributes->find()->count();
$productAttributesCntBefore = $this->Products->ProductAttributes->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'Products', 'controller' => 'Products',
'action' => 'add', 'action' => 'add',
]; ];
$data = [ $data = [
// test new data here // test new data here
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'name' => '14AWG Red Wire', 'name' => '14AWG Red Wire',
'product_type_id' => 1, 'product_type_id' => 1,
'product_attributes' => [ 'product_attributes' => [
[ [
'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c', 'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
'product_category_attribute_option_id' => 'e06f1723-2456-483a-b3c4-004603e032a2', // green 'product_category_attribute_option_id' => 'e06f1723-2456-483a-b3c4-004603e032a2', // green
'attribute_value' => '', 'attribute_value' => '',
], ],
], ],
]; ];
$this->post($url, $data); $this->post($url, $data);
$this->assertResponseCode(302); $this->assertResponseCode(302);
$this->assertRedirectContains('products'); $this->assertRedirectContains('products');
$cntAfter = $this->Products->find()->count(); $cntAfter = $this->Products->find()->count();
$productAttributesCntAfter = $this->Products->ProductAttributes->find()->count(); $productAttributesCntAfter = $this->Products->ProductAttributes->find()->count();
$this->assertEquals($cntBefore + 1, $cntAfter); $this->assertEquals($cntBefore + 1, $cntAfter);
$this->assertEquals($productAttributesCntBefore + 1, $productAttributesCntAfter); $this->assertEquals($productAttributesCntBefore + 1, $productAttributesCntAfter);
} }
/**
/**
* Test add method * Test add method
* *
* Tests a POST request to the add action with a logged in user * Tests a POST request to the add action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductsController::add * @uses \CakeProducts\Controller\ProductsController::add
* @throws Exception
* @return void
*/ */
public function testAddPostFailure(): void public function testAddPostFailure(): void {
{ $cntBefore = $this->Products->find()->count();
$cntBefore = $this->Products->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'Products', 'controller' => 'Products',
'action' => 'add', 'action' => 'add',
]; ];
$data = [ $data = [
'product_catalog_id' => '', 'product_catalog_id' => '',
'product_category_id' => '', 'product_category_id' => '',
'name' => '', 'name' => '',
'product_type_id' => 1, 'product_type_id' => 1,
'product_attributes' => [], 'product_attributes' => [],
]; ];
$this->post($url, $data); $this->post($url, $data);
$this->assertResponseCode(200); $this->assertResponseCode(200);
$cntAfter = $this->Products->find()->count(); $cntAfter = $this->Products->find()->count();
$this->assertEquals($cntBefore, $cntAfter); $this->assertEquals($cntBefore, $cntAfter);
} }
/** /**
* Test edit method * Test edit method
* *
* Tests the edit action with a logged in user * Tests the edit action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductsController::edit * @uses \CakeProducts\Controller\ProductsController::edit
* @throws Exception
* @return void
*/ */
public function testEditGet(): void public function testEditGet(): void {
{ $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'Products',
'controller' => 'Products', 'action' => 'edit',
'action' => 'edit', 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'cfc98a9a-29b2-44c8-b587-8156adc05317', ];
]; $this->get($url);
$this->get($url); $this->assertResponseCode(200);
$this->assertResponseCode(200); }
}
/** /**
* Test edit method * Test edit method
* *
* Tests a PUT request to the edit action with a logged in user * Tests a PUT request to the edit action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductsController::edit * @uses \CakeProducts\Controller\ProductsController::edit
* @throws Exception
* @return void
*/ */
public function testEditPutSuccess(): void public function testEditPutSuccess(): void {
{ $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $id = 'cfc98a9a-29b2-44c8-b587-8156adc05317';
$id = 'cfc98a9a-29b2-44c8-b587-8156adc05317'; $before = $this->Products->get($id);
$before = $this->Products->get($id); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'Products',
'controller' => 'Products', 'action' => 'edit',
'action' => 'edit', $id,
$id, ];
]; $data = [
$data = [ // test new data here
// test new data here 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', 'name' => 'edited product name',
'name' => 'edited product name', 'product_type_id' => 1,
'product_type_id' => 1, ];
]; $this->put($url, $data);
$this->put($url, $data);
$this->assertResponseCode(302); $this->assertResponseCode(302);
$this->assertRedirectContains('products'); $this->assertRedirectContains('products');
$after = $this->Products->get($id); $after = $this->Products->get($id);
$this->assertEquals($data['name'], $after->name); $this->assertEquals($data['name'], $after->name);
// assert saved properly below // assert saved properly below
} }
/** /**
* Test edit method * Test edit method
* *
* Tests a PUT request to the edit action with a logged in user * Tests a PUT request to the edit action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductsController::edit * @uses \CakeProducts\Controller\ProductsController::edit
* @throws Exception
* @return void
*/ */
public function testEditPutFailure(): void public function testEditPutFailure(): void {
{ $this->loginUserByRole('admin');
$this->loginUserByRole('admin'); $id = 'cfc98a9a-29b2-44c8-b587-8156adc05317';
$id = 'cfc98a9a-29b2-44c8-b587-8156adc05317'; $before = $this->Products->get($id);
$before = $this->Products->get($id); $url = [
$url = [ 'plugin' => 'CakeProducts',
'plugin' => 'CakeProducts', 'controller' => 'Products',
'controller' => 'Products', 'action' => 'edit',
'action' => 'edit', $id,
$id, ];
]; $data = [
$data = [ 'product_catalog_id' => '',
'product_catalog_id' => '', 'product_category_id' => '',
'product_category_id' => '', 'name' => 'edited name not gonna take',
'name' => 'edited name not gonna take', 'product_type_id' => 1,
'product_type_id' => 1, ];
]; $this->put($url, $data);
$this->put($url, $data); $this->assertResponseCode(200);
$this->assertResponseCode(200); $after = $this->Products->get($id);
$after = $this->Products->get($id); $this->assertEquals($before->name, $after->name);
$this->assertEquals($before->name, $after->name); $this->assertEquals($before->product_category_id, $after->product_category_id);
$this->assertEquals($before->product_category_id, $after->product_category_id); // assert save failed below
// assert save failed below }
}
/** /**
* Test delete method * Test delete method
* *
* Tests the delete action with a logged in user * Tests the delete action with a logged in user
* *
* @return void
*@throws Exception
*
* @uses \CakeProducts\Controller\ProductsController::delete * @uses \CakeProducts\Controller\ProductsController::delete
*@throws Exception
* @return void
*/ */
public function testDelete(): void public function testDelete(): void {
{ $cntBefore = $this->Products->find()->count();
$cntBefore = $this->Products->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
'controller' => 'Products', 'controller' => 'Products',
'action' => 'delete', 'action' => 'delete',
'cfc98a9a-29b2-44c8-b587-8156adc05317', 'cfc98a9a-29b2-44c8-b587-8156adc05317',
]; ];
$this->delete($url); $this->delete($url);
$this->assertResponseCode(302); $this->assertResponseCode(302);
$this->assertRedirectContains('products'); $this->assertRedirectContains('products');
$cntAfter = $this->Products->find()->count();
$this->assertEquals($cntBefore - 1, $cntAfter);
}
$cntAfter = $this->Products->find()->count();
$this->assertEquals($cntBefore - 1, $cntAfter);
}
} }
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace CakeProducts\Test\TestCase\Model\Table; namespace CakeProducts\Test\TestCase\Model\Table;
use Cake\ORM\Table;
use Cake\TestSuite\TestCase; use Cake\TestSuite\TestCase;
use CakeProducts\Model\Table\ExternalProductCatalogsTable; use CakeProducts\Model\Table\ExternalProductCatalogsTable;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
@@ -12,102 +11,98 @@ use PHPUnit\Framework\Attributes\CoversClass;
* CakeProducts\Model\Table\ExternalProductCatalogsTable Test Case * CakeProducts\Model\Table\ExternalProductCatalogsTable Test Case
*/ */
#[CoversClass(ExternalProductCatalogsTable::class)] #[CoversClass(ExternalProductCatalogsTable::class)]
class ExternalProductCatalogsTableTest extends TestCase class ExternalProductCatalogsTableTest extends TestCase {
{
/** /**
* Test subject * Test subject
* *
* @var ExternalProductCatalogsTable * @var \CakeProducts\Model\Table\ExternalProductCatalogsTable
*/ */
protected $ExternalProductCatalogs; protected $ExternalProductCatalogs;
/** /**
* Fixtures * Fixtures
* *
* @var array<string> * @var array<string>
*/ */
protected array $fixtures = [ protected array $fixtures = [
'plugin.CakeProducts.ExternalProductCatalogs', 'plugin.CakeProducts.ExternalProductCatalogs',
'plugin.CakeProducts.ExternalProductCatalogsProductCatalogs', 'plugin.CakeProducts.ExternalProductCatalogsProductCatalogs',
'plugin.CakeProducts.ProductCatalogs', 'plugin.CakeProducts.ProductCatalogs',
]; ];
/** /**
* setUp method * setUp method
* *
* @return void * @return void
*/ */
protected function setUp(): void protected function setUp(): void {
{ parent::setUp();
parent::setUp(); $config = $this->getTableLocator()->exists('ExternalProductCatalogs') ? [] : ['className' => ExternalProductCatalogsTable::class];
$config = $this->getTableLocator()->exists('ExternalProductCatalogs') ? [] : ['className' => ExternalProductCatalogsTable::class]; $this->ExternalProductCatalogs = $this->getTableLocator()->get('ExternalProductCatalogs', $config);
$this->ExternalProductCatalogs = $this->getTableLocator()->get('ExternalProductCatalogs', $config); }
}
/** /**
* tearDown method * tearDown method
* *
* @return void * @return void
*/ */
protected function tearDown(): void protected function tearDown(): void {
{ unset($this->ExternalProductCatalogs);
unset($this->ExternalProductCatalogs);
parent::tearDown(); parent::tearDown();
} }
/** /**
* TestInitialize method * TestInitialize method
* *
* @return void
* @uses \CakeProducts\Model\Table\ExternalProductCatalogsTable::initialize * @uses \CakeProducts\Model\Table\ExternalProductCatalogsTable::initialize
* @return void
*/ */
public function testInitialize(): void public function testInitialize(): void {
{ // verify all associations loaded
// verify all associations loaded $expectedAssociations = [
$expectedAssociations = [ 'ProductCatalogs',
'ProductCatalogs', 'ExternalProductCatalogsProductCatalogs',
'ExternalProductCatalogsProductCatalogs', ];
]; $associations = $this->ExternalProductCatalogs->associations();
$associations = $this->ExternalProductCatalogs->associations();
$this->assertCount(count($expectedAssociations), $associations); $this->assertCount(count($expectedAssociations), $associations);
foreach ($expectedAssociations as $expectedAssociation) { foreach ($expectedAssociations as $expectedAssociation) {
$this->assertTrue($this->ExternalProductCatalogs->hasAssociation($expectedAssociation)); $this->assertTrue($this->ExternalProductCatalogs->hasAssociation($expectedAssociation));
} }
// verify all behaviors loaded // verify all behaviors loaded
$expectedBehaviors = [ $expectedBehaviors = [
'Timestamp', 'Timestamp',
'Trash', 'Trash',
]; ];
$behaviors = $this->ExternalProductCatalogs->behaviors(); $behaviors = $this->ExternalProductCatalogs->behaviors();
$this->assertCount(count($expectedBehaviors), $behaviors); $this->assertCount(count($expectedBehaviors), $behaviors);
foreach ($expectedBehaviors as $expectedBehavior) { foreach ($expectedBehaviors as $expectedBehavior) {
$this->assertTrue($this->ExternalProductCatalogs->hasBehavior($expectedBehavior)); $this->assertTrue($this->ExternalProductCatalogs->hasBehavior($expectedBehavior));
} }
} }
/** /**
* Test validationDefault method * Test validationDefault method
* *
* @return void
* @uses \CakeProducts\Model\Table\ExternalProductCatalogsTable::validationDefault * @uses \CakeProducts\Model\Table\ExternalProductCatalogsTable::validationDefault
* @return void
*/ */
public function testValidationDefault(): void public function testValidationDefault(): void {
{ $this->markTestIncomplete('Not implemented yet.');
$this->markTestIncomplete('Not implemented yet.'); }
}
/** /**
* Test buildRules method * Test buildRules method
* *
* @return void
* @uses \CakeProducts\Model\Table\ExternalProductCatalogsTable::buildRules * @uses \CakeProducts\Model\Table\ExternalProductCatalogsTable::buildRules
* @return void
*/ */
public function testBuildRules(): void public function testBuildRules(): void {
{ $this->markTestIncomplete('Not implemented yet.');
$this->markTestIncomplete('Not implemented yet.'); }
}
} }
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace CakeProducts\Test\TestCase\Model\Table; namespace CakeProducts\Test\TestCase\Model\Table;
use Cake\ORM\Table;
use Cake\TestSuite\TestCase; use Cake\TestSuite\TestCase;
use CakeProducts\Model\Table\ProductCatalogsTable; use CakeProducts\Model\Table\ProductCatalogsTable;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
@@ -12,90 +11,87 @@ use PHPUnit\Framework\Attributes\CoversClass;
* CakeProducts\Model\Table\ProductCatalogsTable Test Case * CakeProducts\Model\Table\ProductCatalogsTable Test Case
*/ */
#[CoversClass(ProductCatalogsTable::class)] #[CoversClass(ProductCatalogsTable::class)]
class ProductCatalogsTableTest extends TestCase class ProductCatalogsTableTest extends TestCase {
{
/** /**
* Test subject * Test subject
* *
* @var ProductCatalogsTable|Table * @var \CakeProducts\Model\Table\ProductCatalogsTable|\Cake\ORM\Table
*/ */
protected $ProductCatalogs; protected $ProductCatalogs;
/** /**
* Fixtures * Fixtures
* *
* @var array<string> * @var array<string>
*/ */
protected array $fixtures = [ protected array $fixtures = [
'plugin.CakeProducts.ProductCatalogs', 'plugin.CakeProducts.ProductCatalogs',
'plugin.CakeProducts.ExternalProductCatalogsProductCatalogs', 'plugin.CakeProducts.ExternalProductCatalogsProductCatalogs',
'plugin.CakeProducts.ProductCategories', 'plugin.CakeProducts.ProductCategories',
]; ];
/** /**
* setUp method * setUp method
* *
* @return void * @return void
*/ */
protected function setUp(): void protected function setUp(): void {
{ parent::setUp();
parent::setUp(); $config = $this->getTableLocator()->exists('ProductCatalogs') ? [] : ['className' => ProductCatalogsTable::class];
$config = $this->getTableLocator()->exists('ProductCatalogs') ? [] : ['className' => ProductCatalogsTable::class]; $this->ProductCatalogs = $this->getTableLocator()->get('ProductCatalogs', $config);
$this->ProductCatalogs = $this->getTableLocator()->get('ProductCatalogs', $config); }
}
/** /**
* tearDown method * tearDown method
* *
* @return void * @return void
*/ */
protected function tearDown(): void protected function tearDown(): void {
{ unset($this->ProductCatalogs);
unset($this->ProductCatalogs);
parent::tearDown(); parent::tearDown();
} }
/** /**
* TestInitialize method * TestInitialize method
* *
* @return void
* @uses \CakeProducts\Model\Table\ProductCatalogsTable::initialize * @uses \CakeProducts\Model\Table\ProductCatalogsTable::initialize
* @return void
*/ */
public function testInitialize(): void public function testInitialize(): void {
{ // verify all associations loaded
// verify all associations loaded $expectedAssociations = [
$expectedAssociations = [ 'ProductCategories',
'ProductCategories', 'ExternalProductCatalogs',
'ExternalProductCatalogs', ];
]; $associations = $this->ProductCatalogs->associations();
$associations = $this->ProductCatalogs->associations();
$this->assertCount(count($expectedAssociations), $associations); $this->assertCount(count($expectedAssociations), $associations);
foreach ($expectedAssociations as $expectedAssociation) { foreach ($expectedAssociations as $expectedAssociation) {
$this->assertTrue($this->ProductCatalogs->hasAssociation($expectedAssociation)); $this->assertTrue($this->ProductCatalogs->hasAssociation($expectedAssociation));
} }
// verify all behaviors loaded // verify all behaviors loaded
$expectedBehaviors = [ $expectedBehaviors = [
'Trash', 'Trash',
]; ];
$behaviors = $this->ProductCatalogs->behaviors(); $behaviors = $this->ProductCatalogs->behaviors();
$this->assertCount(count($expectedBehaviors), $behaviors); $this->assertCount(count($expectedBehaviors), $behaviors);
foreach ($expectedBehaviors as $expectedBehavior) { foreach ($expectedBehaviors as $expectedBehavior) {
$this->assertTrue($this->ProductCatalogs->hasBehavior($expectedBehavior)); $this->assertTrue($this->ProductCatalogs->hasBehavior($expectedBehavior));
} }
} }
/** /**
* Test validationDefault method * Test validationDefault method
* *
* @return void
* @uses \CakeProducts\Model\Table\ProductCatalogsTable::validationDefault * @uses \CakeProducts\Model\Table\ProductCatalogsTable::validationDefault
* @return void
*/ */
public function testValidationDefault(): void public function testValidationDefault(): void {
{ $this->markTestIncomplete('Not implemented yet.');
$this->markTestIncomplete('Not implemented yet.'); }
}
} }
@@ -11,107 +11,103 @@ use PHPUnit\Framework\Attributes\CoversClass;
* CakeProducts\Model\Table\ProductCategoriesTable Test Case * CakeProducts\Model\Table\ProductCategoriesTable Test Case
*/ */
#[CoversClass(ProductCategoriesTable::class)] #[CoversClass(ProductCategoriesTable::class)]
class ProductCategoriesTableTest extends TestCase class ProductCategoriesTableTest extends TestCase {
{
/** /**
* Test subject * Test subject
* *
* @var \CakeProducts\Model\Table\ProductCategoriesTable * @var \CakeProducts\Model\Table\ProductCategoriesTable
*/ */
protected $ProductCategories; protected $ProductCategories;
/** /**
* Fixtures * Fixtures
* *
* @var array<string> * @var array<string>
*/ */
protected array $fixtures = [ protected array $fixtures = [
'plugin.CakeProducts.ProductCategories', 'plugin.CakeProducts.ProductCategories',
'plugin.CakeProducts.ProductCatalogs', 'plugin.CakeProducts.ProductCatalogs',
]; ];
/** /**
* setUp method * setUp method
* *
* @return void * @return void
*/ */
protected function setUp(): void protected function setUp(): void {
{ parent::setUp();
parent::setUp(); $config = $this->getTableLocator()->exists('ProductCategories') ? [] : ['className' => ProductCategoriesTable::class];
$config = $this->getTableLocator()->exists('ProductCategories') ? [] : ['className' => ProductCategoriesTable::class]; $this->ProductCategories = $this->getTableLocator()->get('ProductCategories', $config);
$this->ProductCategories = $this->getTableLocator()->get('ProductCategories', $config); }
}
/** /**
* tearDown method * tearDown method
* *
* @return void * @return void
*/ */
protected function tearDown(): void protected function tearDown(): void {
{ unset($this->ProductCategories);
unset($this->ProductCategories);
parent::tearDown(); parent::tearDown();
} }
/** /**
* TestInitialize method * TestInitialize method
* *
* @return void
* @uses \CakeProducts\Model\Table\ProductCategoriesTable::initialize() * @uses \CakeProducts\Model\Table\ProductCategoriesTable::initialize()
* @return void
*/ */
public function testInitialize(): void public function testInitialize(): void {
{ // verify all associations loaded
// verify all associations loaded $expectedAssociations = [
$expectedAssociations = [ 'ProductCatalogs',
'ProductCatalogs', 'ParentProductCategories',
'ParentProductCategories', 'ChildProductCategories',
'ChildProductCategories', 'Products',
'Products', 'ProductCategoryAttributes',
'ProductCategoryAttributes', 'ProductCategoryVariants',
'ProductCategoryVariants', 'ProductPhotos',
'ProductPhotos', 'PrimaryProductPhotos',
'PrimaryProductPhotos', ];
]; $associations = $this->ProductCategories->associations();
$associations = $this->ProductCategories->associations();
$this->assertCount(count($expectedAssociations), $associations); $this->assertCount(count($expectedAssociations), $associations);
foreach ($expectedAssociations as $expectedAssociation) { foreach ($expectedAssociations as $expectedAssociation) {
$this->assertTrue($this->ProductCategories->hasAssociation($expectedAssociation)); $this->assertTrue($this->ProductCategories->hasAssociation($expectedAssociation));
} }
// verify all behaviors loaded // verify all behaviors loaded
$expectedBehaviors = [ $expectedBehaviors = [
'Tree', 'Tree',
'Trash', 'Trash',
]; ];
$behaviors = $this->ProductCategories->behaviors(); $behaviors = $this->ProductCategories->behaviors();
$this->assertCount(count($expectedBehaviors), $behaviors); $this->assertCount(count($expectedBehaviors), $behaviors);
foreach ($expectedBehaviors as $expectedBehavior) { foreach ($expectedBehaviors as $expectedBehavior) {
$this->assertTrue($this->ProductCategories->hasBehavior($expectedBehavior)); $this->assertTrue($this->ProductCategories->hasBehavior($expectedBehavior));
} }
} }
/** /**
* Test validationDefault method * Test validationDefault method
* *
* @return void
* @uses \CakeProducts\Model\Table\ProductCategoriesTable::validationDefault() * @uses \CakeProducts\Model\Table\ProductCategoriesTable::validationDefault()
* @return void
*/ */
public function testValidationDefault(): void public function testValidationDefault(): void {
{ $this->markTestIncomplete('Not implemented yet.');
$this->markTestIncomplete('Not implemented yet.'); }
}
/** /**
* Test buildRules method * Test buildRules method
* *
* @return void
* @uses \CakeProducts\Model\Table\ProductCategoriesTable::buildRules() * @uses \CakeProducts\Model\Table\ProductCategoriesTable::buildRules()
* @return void
*/ */
public function testBuildRules(): void public function testBuildRules(): void {
{ $this->markTestIncomplete('Not implemented yet.');
$this->markTestIncomplete('Not implemented yet.'); }
}
} }
@@ -11,98 +11,94 @@ use PHPUnit\Framework\Attributes\CoversClass;
* CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable Test Case * CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable Test Case
*/ */
#[CoversClass(ProductCategoryAttributeOptionsTable::class)] #[CoversClass(ProductCategoryAttributeOptionsTable::class)]
class ProductCategoryAttributeOptionsTableTest extends TestCase class ProductCategoryAttributeOptionsTableTest extends TestCase {
{
/** /**
* Test subject * Test subject
* *
* @var ProductCategoryAttributeOptionsTable * @var \CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable
*/ */
protected $ProductCategoryAttributeOptions; protected $ProductCategoryAttributeOptions;
/** /**
* Fixtures * Fixtures
* *
* @var array<string> * @var array<string>
*/ */
protected array $fixtures = [ protected array $fixtures = [
'plugin.CakeProducts.ProductCategoryAttributeOptions', 'plugin.CakeProducts.ProductCategoryAttributeOptions',
]; ];
/** /**
* setUp method * setUp method
* *
* @return void * @return void
*/ */
protected function setUp(): void protected function setUp(): void {
{ parent::setUp();
parent::setUp(); $config = $this->getTableLocator()->exists('ProductCategoryAttributeOptions') ? [] : ['className' => ProductCategoryAttributeOptionsTable::class];
$config = $this->getTableLocator()->exists('ProductCategoryAttributeOptions') ? [] : ['className' => ProductCategoryAttributeOptionsTable::class]; $this->ProductCategoryAttributeOptions = $this->getTableLocator()->get('ProductCategoryAttributeOptions', $config);
$this->ProductCategoryAttributeOptions = $this->getTableLocator()->get('ProductCategoryAttributeOptions', $config); }
}
/** /**
* tearDown method * tearDown method
* *
* @return void * @return void
*/ */
protected function tearDown(): void protected function tearDown(): void {
{ unset($this->ProductCategoryAttributeOptions);
unset($this->ProductCategoryAttributeOptions);
parent::tearDown(); parent::tearDown();
} }
/** /**
* TestInitialize method * TestInitialize method
* *
* @return void
* @uses \CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable::initialize * @uses \CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable::initialize
* @return void
*/ */
public function testInitialize(): void public function testInitialize(): void {
{ // verify all associations loaded
// verify all associations loaded $expectedAssociations = [
$expectedAssociations = [ 'ProductCategoryAttributes',
'ProductCategoryAttributes', ];
]; $associations = $this->ProductCategoryAttributeOptions->associations();
$associations = $this->ProductCategoryAttributeOptions->associations();
$this->assertCount(count($expectedAssociations), $associations); $this->assertCount(count($expectedAssociations), $associations);
foreach ($expectedAssociations as $expectedAssociation) { foreach ($expectedAssociations as $expectedAssociation) {
$this->assertTrue($this->ProductCategoryAttributeOptions->hasAssociation($expectedAssociation)); $this->assertTrue($this->ProductCategoryAttributeOptions->hasAssociation($expectedAssociation));
} }
// verify all behaviors loaded // verify all behaviors loaded
$expectedBehaviors = [ $expectedBehaviors = [
'Trash', 'Trash',
]; ];
$behaviors = $this->ProductCategoryAttributeOptions->behaviors(); $behaviors = $this->ProductCategoryAttributeOptions->behaviors();
$this->assertCount(count($expectedBehaviors), $behaviors); $this->assertCount(count($expectedBehaviors), $behaviors);
foreach ($expectedBehaviors as $expectedBehavior) { foreach ($expectedBehaviors as $expectedBehavior) {
$this->assertTrue($this->ProductCategoryAttributeOptions->hasBehavior($expectedBehavior)); $this->assertTrue($this->ProductCategoryAttributeOptions->hasBehavior($expectedBehavior));
} }
} }
/** /**
* Test validationDefault method * Test validationDefault method
* *
* @return void
* @uses \CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable::validationDefault * @uses \CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable::validationDefault
* @return void
*/ */
public function testValidationDefault(): void public function testValidationDefault(): void {
{ $this->markTestIncomplete('Not implemented yet.');
$this->markTestIncomplete('Not implemented yet.'); }
}
/** /**
* Test buildRules method * Test buildRules method
* *
* @return void
* @uses \CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable::buildRules * @uses \CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable::buildRules
* @return void
*/ */
public function testBuildRules(): void public function testBuildRules(): void {
{ $this->markTestIncomplete('Not implemented yet.');
$this->markTestIncomplete('Not implemented yet.'); }
}
} }
@@ -11,101 +11,97 @@ use PHPUnit\Framework\Attributes\CoversClass;
* CakeProducts\Model\Table\ProductCategoryAttributesTable Test Case * CakeProducts\Model\Table\ProductCategoryAttributesTable Test Case
*/ */
#[CoversClass(ProductCategoryAttributesTable::class)] #[CoversClass(ProductCategoryAttributesTable::class)]
class ProductCategoryAttributesTableTest extends TestCase class ProductCategoryAttributesTableTest extends TestCase {
{
/** /**
* Test subject * Test subject
* *
* @var ProductCategoryAttributesTable * @var \CakeProducts\Model\Table\ProductCategoryAttributesTable
*/ */
protected $ProductCategoryAttributes; protected $ProductCategoryAttributes;
/** /**
* Fixtures * Fixtures
* *
* @var array<string> * @var array<string>
*/ */
protected array $fixtures = [ protected array $fixtures = [
'plugin.CakeProducts.ProductCategoryAttributes', 'plugin.CakeProducts.ProductCategoryAttributes',
'plugin.CakeProducts.ProductCategoryAttributeOptions', 'plugin.CakeProducts.ProductCategoryAttributeOptions',
'plugin.CakeProducts.ProductCategories', 'plugin.CakeProducts.ProductCategories',
]; ];
/** /**
* setUp method * setUp method
* *
* @return void * @return void
*/ */
protected function setUp(): void protected function setUp(): void {
{ parent::setUp();
parent::setUp(); $config = $this->getTableLocator()->exists('ProductCategoryAttributes') ? [] : ['className' => ProductCategoryAttributesTable::class];
$config = $this->getTableLocator()->exists('ProductCategoryAttributes') ? [] : ['className' => ProductCategoryAttributesTable::class]; $this->ProductCategoryAttributes = $this->getTableLocator()->get('ProductCategoryAttributes', $config);
$this->ProductCategoryAttributes = $this->getTableLocator()->get('ProductCategoryAttributes', $config); }
}
/** /**
* tearDown method * tearDown method
* *
* @return void * @return void
*/ */
protected function tearDown(): void protected function tearDown(): void {
{ unset($this->ProductCategoryAttributes);
unset($this->ProductCategoryAttributes);
parent::tearDown(); parent::tearDown();
} }
/** /**
* TestInitialize method * TestInitialize method
* *
* @return void
* @uses \CakeProducts\Model\Table\ProductCategoryAttributesTable::initialize * @uses \CakeProducts\Model\Table\ProductCategoryAttributesTable::initialize
* @return void
*/ */
public function testInitialize(): void public function testInitialize(): void {
{ // verify all associations loaded
// verify all associations loaded $expectedAssociations = [
$expectedAssociations = [ 'ProductCategories',
'ProductCategories', 'ProductCategoryAttributeOptions',
'ProductCategoryAttributeOptions', ];
]; $associations = $this->ProductCategoryAttributes->associations();
$associations = $this->ProductCategoryAttributes->associations();
$this->assertCount(count($expectedAssociations), $associations); $this->assertCount(count($expectedAssociations), $associations);
foreach ($expectedAssociations as $expectedAssociation) { foreach ($expectedAssociations as $expectedAssociation) {
$this->assertTrue($this->ProductCategoryAttributes->hasAssociation($expectedAssociation)); $this->assertTrue($this->ProductCategoryAttributes->hasAssociation($expectedAssociation));
} }
// verify all behaviors loaded // verify all behaviors loaded
$expectedBehaviors = [ $expectedBehaviors = [
'Trash', 'Trash',
]; ];
$behaviors = $this->ProductCategoryAttributes->behaviors(); $behaviors = $this->ProductCategoryAttributes->behaviors();
$this->assertCount(count($expectedBehaviors), $behaviors); $this->assertCount(count($expectedBehaviors), $behaviors);
foreach ($expectedBehaviors as $expectedBehavior) { foreach ($expectedBehaviors as $expectedBehavior) {
$this->assertTrue($this->ProductCategoryAttributes->hasBehavior($expectedBehavior)); $this->assertTrue($this->ProductCategoryAttributes->hasBehavior($expectedBehavior));
} }
} }
/** /**
* Test validationDefault method * Test validationDefault method
* *
* @return void
* @uses \CakeProducts\Model\Table\ProductCategoryAttributesTable::validationDefault * @uses \CakeProducts\Model\Table\ProductCategoryAttributesTable::validationDefault
* @return void
*/ */
public function testValidationDefault(): void public function testValidationDefault(): void {
{ $this->markTestIncomplete('Not implemented yet.');
$this->markTestIncomplete('Not implemented yet.'); }
}
/** /**
* Test buildRules method * Test buildRules method
* *
* @return void
* @uses \CakeProducts\Model\Table\ProductCategoryAttributesTable::buildRules * @uses \CakeProducts\Model\Table\ProductCategoryAttributesTable::buildRules
* @return void
*/ */
public function testBuildRules(): void public function testBuildRules(): void {
{ $this->markTestIncomplete('Not implemented yet.');
$this->markTestIncomplete('Not implemented yet.'); }
}
} }
@@ -3,107 +3,103 @@ declare(strict_types=1);
namespace CakeProducts\Test\TestCase\Model\Table; namespace CakeProducts\Test\TestCase\Model\Table;
use CakeProducts\Model\Table\ProductCategoryVariantOptionsTable;
use Cake\TestSuite\TestCase; use Cake\TestSuite\TestCase;
use CakeProducts\Model\Table\ProductCategoryVariantOptionsTable;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
/** /**
* App\Model\Table\ProductCategoryVariantOptionsTable Test Case * App\Model\Table\ProductCategoryVariantOptionsTable Test Case
*/ */
#[CoversClass(ProductCategoryVariantOptionsTable::class)] #[CoversClass(ProductCategoryVariantOptionsTable::class)]
class ProductCategoryVariantOptionsTableTest extends TestCase class ProductCategoryVariantOptionsTableTest extends TestCase {
{
/** /**
* Test subject * Test subject
* *
* @var \App\Model\Table\ProductCategoryVariantOptionsTable * @var \App\Model\Table\ProductCategoryVariantOptionsTable
*/ */
protected $ProductCategoryVariantOptions; protected $ProductCategoryVariantOptions;
/** /**
* Fixtures * Fixtures
* *
* @var array<string> * @var array<string>
*/ */
protected array $fixtures = [ protected array $fixtures = [
'plugin.CakeProducts.ProductCategoryVariants', 'plugin.CakeProducts.ProductCategoryVariants',
'plugin.CakeProducts.ProductCategoryVariantOptions', 'plugin.CakeProducts.ProductCategoryVariantOptions',
]; ];
/** /**
* setUp method * setUp method
* *
* @return void * @return void
*/ */
protected function setUp(): void protected function setUp(): void {
{ parent::setUp();
parent::setUp(); $config = $this->getTableLocator()->exists('ProductCategoryVariantOptions') ? [] : ['className' => ProductCategoryVariantOptionsTable::class];
$config = $this->getTableLocator()->exists('ProductCategoryVariantOptions') ? [] : ['className' => ProductCategoryVariantOptionsTable::class]; $this->ProductCategoryVariantOptions = $this->getTableLocator()->get('ProductCategoryVariantOptions', $config);
$this->ProductCategoryVariantOptions = $this->getTableLocator()->get('ProductCategoryVariantOptions', $config); }
}
/** /**
* tearDown method * tearDown method
* *
* @return void * @return void
*/ */
protected function tearDown(): void protected function tearDown(): void {
{ unset($this->ProductCategoryVariantOptions);
unset($this->ProductCategoryVariantOptions);
parent::tearDown(); parent::tearDown();
} }
/** /**
* TestInitialize method * TestInitialize method
* *
* @return void
* @uses \CakeProducts\Model\Table\ProductCategoryVariantOptionsTable::initialize() * @uses \CakeProducts\Model\Table\ProductCategoryVariantOptionsTable::initialize()
* @return void
*/ */
public function testInitialize(): void public function testInitialize(): void {
{ // verify all associations loaded
// verify all associations loaded $expectedAssociations = [
$expectedAssociations = [ 'ProductCategoryVariants',
'ProductCategoryVariants', ];
]; $associations = $this->ProductCategoryVariantOptions->associations();
$associations = $this->ProductCategoryVariantOptions->associations();
$this->assertCount(count($expectedAssociations), $associations); $this->assertCount(count($expectedAssociations), $associations);
foreach ($expectedAssociations as $expectedAssociation) { foreach ($expectedAssociations as $expectedAssociation) {
$this->assertTrue($this->ProductCategoryVariantOptions->hasAssociation($expectedAssociation)); $this->assertTrue($this->ProductCategoryVariantOptions->hasAssociation($expectedAssociation));
} }
// verify all behaviors loaded // verify all behaviors loaded
$expectedBehaviors = [ $expectedBehaviors = [
'Timestamp', 'Timestamp',
]; ];
$behaviors = $this->ProductCategoryVariantOptions->behaviors(); $behaviors = $this->ProductCategoryVariantOptions->behaviors();
$this->assertCount(count($expectedBehaviors), $behaviors); $this->assertCount(count($expectedBehaviors), $behaviors);
foreach ($expectedBehaviors as $expectedBehavior) { foreach ($expectedBehaviors as $expectedBehavior) {
$this->assertTrue($this->ProductCategoryVariantOptions->hasBehavior($expectedBehavior)); $this->assertTrue($this->ProductCategoryVariantOptions->hasBehavior($expectedBehavior));
} }
} }
/** /**
* Test validationDefault method * Test validationDefault method
* *
* @return void
* @uses \CakeProducts\Model\Table\ProductCategoryVariantOptionsTable::validationDefault() * @uses \CakeProducts\Model\Table\ProductCategoryVariantOptionsTable::validationDefault()
* @return void
*/ */
public function testValidationDefault(): void public function testValidationDefault(): void {
{ $this->markTestIncomplete('Not implemented yet.');
$this->markTestIncomplete('Not implemented yet.'); }
}
/** /**
* Test buildRules method * Test buildRules method
* *
* @return void
* @uses \CakeProducts\Model\Table\ProductCategoryVariantOptionsTable::buildRules() * @uses \CakeProducts\Model\Table\ProductCategoryVariantOptionsTable::buildRules()
* @return void
*/ */
public function testBuildRules(): void public function testBuildRules(): void {
{ $this->markTestIncomplete('Not implemented yet.');
$this->markTestIncomplete('Not implemented yet.'); }
}
} }

Some files were not shown because too many files have changed in this diff Show More