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",
"muffin/trash": "^4.2",
"cakephp/cakephp": "^5.0.1",
"bentools/cartesian-product": "dev-master"
"bentools/cartesian-product": "^2.0"
},
"require-dev": {
"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": {
"hi-powered-dev/cake-carts": "Allow users to add products/SKUs to a cart"
@@ -29,5 +32,22 @@
"Cake\\Test\\": "vendor/cakephp/cakephp/tests/",
"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;
class CreateProductCatalogs extends AbstractMigration
{
/**
class CreateProductCatalogs extends AbstractMigration {
/**
* Change Method.
*
* More information on this method is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
* @return void
*/
public function change(): void
{
$table = $this->table('product_catalogs', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('name', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('catalog_description', 'string', [
'default' => null,
'limit' => 255,
'null' => true,
]);
$table->addColumn('enabled', 'boolean', [
'default' => null,
'null' => false,
]);
$table->addIndex([
'name',
], [
'name' => 'BY_NAME',
'unique' => true,
]);
$table->create();
}
public function change(): void {
$table = $this->table('product_catalogs', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('name', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('catalog_description', 'string', [
'default' => null,
'limit' => 255,
'null' => true,
]);
$table->addColumn('enabled', 'boolean', [
'default' => null,
'null' => false,
]);
$table->addIndex([
'name',
], [
'name' => 'BY_NAME',
'unique' => true,
]);
$table->create();
}
}
@@ -3,36 +3,35 @@ declare(strict_types=1);
use Migrations\AbstractMigration;
class CreateProductCategories extends AbstractMigration
{
/**
class CreateProductCategories extends AbstractMigration {
/**
* Change Method.
*
* More information on this method is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
* @return void
*/
public function change(): void
{
$table = $this->table('product_categories');
public function change(): void {
$table = $this->table('product_categories');
$table->addColumn('product_catalog_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('internal_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('name', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('category_description', 'text', [
'default' => null,
'null' => true,
]);
$table->addColumn('product_catalog_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('internal_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('name', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('category_description', 'text', [
'default' => null,
'null' => true,
]);
// $table->addColumn('shopify_v1_id', 'integer', [
// 'default' => null,
// 'limit' => 11,
@@ -43,36 +42,37 @@ class CreateProductCategories extends AbstractMigration
// 'limit' => 255,
// 'null' => true,
// ]);
$table->addColumn('parent_id', 'integer', [
'default' => null,
'limit' => 11,
'null' => true,
]);
$table->addColumn('lft', 'integer', [
'default' => null,
'limit' => 11,
'null' => false,
]);
$table->addColumn('rght', 'integer', [
'default' => null,
'limit' => 11,
'null' => false,
]);
$table->addColumn('enabled', 'boolean', [
'default' => false,
'null' => false,
]);
$table->addColumn('parent_id', 'integer', [
'default' => null,
'limit' => 11,
'null' => true,
]);
$table->addColumn('lft', 'integer', [
'default' => null,
'limit' => 11,
'null' => false,
]);
$table->addColumn('rght', 'integer', [
'default' => null,
'limit' => 11,
'null' => false,
]);
$table->addColumn('enabled', 'boolean', [
'default' => 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;
class CreateProducts extends AbstractMigration
{
/**
class CreateProducts extends AbstractMigration {
/**
* Change Method.
*
* More information on this method is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
* @return void
*/
public function change(): void
{
$table = $this->table('products', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('name', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('product_category_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('product_type_id', 'integer', [
'default' => null,
'limit' => 11,
'null' => false,
]);
$table->addIndex('product_category_id');
$table->addIndex('product_type_id');
public function change(): void {
$table = $this->table('products', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('name', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('product_category_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('product_type_id', 'integer', [
'default' => null,
'limit' => 11,
'null' => false,
]);
$table->addIndex('product_category_id');
$table->addIndex('product_type_id');
// $table->addIndex([
// 'product_category_id',
// 'name',
@@ -42,6 +41,7 @@ class CreateProducts extends AbstractMigration
// 'name' => 'BY_NAME_AND_CATEGORY_ID',
// 'unique' => true,
// ]);
$table->create();
}
$table->create();
}
}
@@ -3,53 +3,53 @@ declare(strict_types=1);
use Migrations\AbstractMigration;
class CreateProductCategoryAttributes extends AbstractMigration
{
/**
class CreateProductCategoryAttributes extends AbstractMigration {
/**
* Change Method.
*
* More information on this method is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
* @return void
*/
public function change(): void
{
$table = $this->table('product_category_attributes', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('name', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('product_category_id', 'uuid', [
'default' => null,
'null' => true,
]);
$table->addColumn('attribute_type_id', 'integer', [
'default' => null,
'limit' => 11,
'null' => false,
]);
$table->addColumn('enabled', 'boolean', [
'default' => null,
'null' => false,
]);
$table->addIndex([
'product_category_id',
], [
'name' => 'BY_PRODUCT_CATEGORY_ID',
'unique' => false,
]);
$table->addIndex([
'name',
'product_category_id',
], [
'name' => 'BY_NAME_AND_PRODUCT_CATEGORY_ID_UNIQUE',
'unique' => true,
]);
$table->create();
}
public function change(): void {
$table = $this->table('product_category_attributes', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('name', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('product_category_id', 'uuid', [
'default' => null,
'null' => true,
]);
$table->addColumn('attribute_type_id', 'integer', [
'default' => null,
'limit' => 11,
'null' => false,
]);
$table->addColumn('enabled', 'boolean', [
'default' => null,
'null' => false,
]);
$table->addIndex([
'product_category_id',
], [
'name' => 'BY_PRODUCT_CATEGORY_ID',
'unique' => false,
]);
$table->addIndex([
'name',
'product_category_id',
], [
'name' => 'BY_NAME_AND_PRODUCT_CATEGORY_ID_UNIQUE',
'unique' => true,
]);
$table->create();
}
}
@@ -3,46 +3,46 @@ declare(strict_types=1);
use Migrations\AbstractMigration;
class CreateProductCategoryAttributeOptions extends AbstractMigration
{
/**
class CreateProductCategoryAttributeOptions extends AbstractMigration {
/**
* Change Method.
*
* More information on this method is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
* @return void
*/
public function change(): void
{
$table = $this->table('product_category_attribute_options', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('product_category_attribute_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('attribute_value', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('attribute_label', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('enabled', 'boolean', [
'default' => true,
'null' => false,
]);
$table->addIndex([
'product_category_attribute_id',
], [
'name' => 'BY_PRODUCT_CATEGORY_ATTRIBUTE_ID',
'unique' => false,
]);
$table->create();
}
public function change(): void {
$table = $this->table('product_category_attribute_options', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('product_category_attribute_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('attribute_value', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('attribute_label', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('enabled', 'boolean', [
'default' => true,
'null' => false,
]);
$table->addIndex([
'product_category_attribute_id',
], [
'name' => 'BY_PRODUCT_CATEGORY_ATTRIBUTE_ID',
'unique' => false,
]);
$table->create();
}
}
@@ -3,54 +3,54 @@ declare(strict_types=1);
use Migrations\AbstractMigration;
class CreateExternalProductCatalogs extends AbstractMigration
{
/**
class CreateExternalProductCatalogs extends AbstractMigration {
/**
* Change Method.
*
* More information on this method is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
* @return void
*/
public function change(): void
{
$table = $this->table('external_product_catalogs', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('product_catalog_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('base_url', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('api_url', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('created', 'datetime', [
'default' => null,
'null' => false,
]);
$table->addColumn('deleted', 'datetime', [
'default' => null,
'null' => true,
]);
$table->addColumn('enabled', 'boolean', [
'default' => null,
'null' => false,
]);
$table->addIndex([
'product_catalog_id',
], [
'name' => 'BY_PRODUCT_CATALOG_ID',
'unique' => false,
]);
$table->create();
}
public function change(): void {
$table = $this->table('external_product_catalogs', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('product_catalog_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('base_url', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('api_url', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('created', 'datetime', [
'default' => null,
'null' => false,
]);
$table->addColumn('deleted', 'datetime', [
'default' => null,
'null' => true,
]);
$table->addColumn('enabled', 'boolean', [
'default' => null,
'null' => false,
]);
$table->addIndex([
'product_catalog_id',
], [
'name' => 'BY_PRODUCT_CATALOG_ID',
'unique' => false,
]);
$table->create();
}
}
@@ -3,20 +3,20 @@ declare(strict_types=1);
use Migrations\BaseMigration;
class RemoveCatalogIdFromExternalProductCatalogs extends BaseMigration
{
/**
class RemoveCatalogIdFromExternalProductCatalogs 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 change(): void
{
$table = $this->table('external_product_catalogs');
$table->removeColumn('product_catalog_id');
$table->removeColumn('enabled');
$table->update();
}
public function change(): void {
$table = $this->table('external_product_catalogs');
$table->removeColumn('product_catalog_id');
$table->removeColumn('enabled');
$table->update();
}
}
@@ -3,34 +3,34 @@ declare(strict_types=1);
use Migrations\BaseMigration;
class CreateExternalProductCatalogsProductCatalogs extends BaseMigration
{
/**
class CreateExternalProductCatalogsProductCatalogs 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 change(): void
{
$table = $this->table('external_product_catalogs_product_catalogs');
$table->addColumn('external_product_catalog_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('product_catalog_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('created', 'datetime', [
'default' => null,
'null' => false,
]);
$table->addColumn('enabled', 'boolean', [
'default' => null,
'null' => false,
]);
$table->create();
}
public function change(): void {
$table = $this->table('external_product_catalogs_product_catalogs');
$table->addColumn('external_product_catalog_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('product_catalog_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('created', 'datetime', [
'default' => null,
'null' => false,
]);
$table->addColumn('enabled', 'boolean', [
'default' => null,
'null' => false,
]);
$table->create();
}
}
@@ -3,39 +3,39 @@ declare(strict_types=1);
use Migrations\BaseMigration;
class CreateProductAttributes extends BaseMigration
{
/**
class CreateProductAttributes 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 change(): void
{
$table = $this->table('product_attributes', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('product_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('product_category_attribute_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('attribute_value', 'string', [
'default' => null,
'limit' => 255,
'null' => true,
]);
$table->addColumn('product_category_attribute_option_id', 'uuid', [
'default' => null,
'null' => true,
]);
$table->create();
}
public function change(): void {
$table = $this->table('product_attributes', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('product_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('product_category_attribute_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('attribute_value', 'string', [
'default' => null,
'limit' => 255,
'null' => true,
]);
$table->addColumn('product_category_attribute_option_id', 'uuid', [
'default' => null,
'null' => true,
]);
$table->create();
}
}
@@ -3,64 +3,64 @@ declare(strict_types=1);
use Migrations\BaseMigration;
class AddSoftDeleteToAllTables extends BaseMigration
{
/**
class AddSoftDeleteToAllTables 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 change(): void
{
$table = $this->table('products');
$table->addColumn('deleted', 'datetime', [
'default' => null,
'null' => true,
]);
$table->update();
public function change(): void {
$table = $this->table('products');
$table->addColumn('deleted', 'datetime', [
'default' => null,
'null' => true,
]);
$table->update();
$table = $this->table('product_category_attributes');
$table->addColumn('deleted', 'datetime', [
'default' => null,
'null' => true,
]);
$table->update();
$table = $this->table('product_category_attributes');
$table->addColumn('deleted', 'datetime', [
'default' => null,
'null' => true,
]);
$table->update();
$table = $this->table('product_category_attribute_options');
$table->addColumn('deleted', 'datetime', [
'default' => null,
'null' => true,
]);
$table->update();
$table = $this->table('product_category_attribute_options');
$table->addColumn('deleted', 'datetime', [
'default' => null,
'null' => true,
]);
$table->update();
$table = $this->table('product_categories');
$table->addColumn('deleted', 'datetime', [
'default' => null,
'null' => true,
]);
$table->update();
$table = $this->table('product_categories');
$table->addColumn('deleted', 'datetime', [
'default' => null,
'null' => true,
]);
$table->update();
$table = $this->table('product_catalogs');
$table->addColumn('deleted', 'datetime', [
'default' => null,
'null' => true,
]);
$table->update();
$table = $this->table('product_catalogs');
$table->addColumn('deleted', 'datetime', [
'default' => null,
'null' => true,
]);
$table->update();
$table = $this->table('external_product_catalogs_product_catalogs');
$table->addColumn('deleted', 'datetime', [
'default' => null,
'null' => true,
]);
$table->update();
$table = $this->table('external_product_catalogs_product_catalogs');
$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();
}
$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;
class CreateProductSkus extends BaseMigration
{
/**
class CreateProductSkus 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 change(): void
{
$table = $this->table('product_skus', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('product_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('sku', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('barcode', 'string', [
'default' => null,
'limit' => 255,
'null' => true,
]);
$table->addColumn('price', 'decimal', [
'default' => null,
'precision' => 15,
'scale' => 6,
'null' => true,
]);
$table->addColumn('cost', 'decimal', [
'default' => null,
'precision' => 15,
'scale' => 6,
'null' => true,
]);
$table->addColumn('created', 'datetime', [
'default' => null,
'null' => false,
]);
$table->addColumn('modified', 'datetime', [
'default' => null,
'null' => true,
]);
$table->addColumn('deleted', 'datetime', [
'default' => null,
'null' => true,
]);
$table->create();
}
public function change(): void {
$table = $this->table('product_skus', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('product_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('sku', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('barcode', 'string', [
'default' => null,
'limit' => 255,
'null' => true,
]);
$table->addColumn('price', 'decimal', [
'default' => null,
'precision' => 15,
'scale' => 6,
'null' => true,
]);
$table->addColumn('cost', 'decimal', [
'default' => null,
'precision' => 15,
'scale' => 6,
'null' => true,
]);
$table->addColumn('created', 'datetime', [
'default' => null,
'null' => false,
]);
$table->addColumn('modified', 'datetime', [
'default' => null,
'null' => true,
]);
$table->addColumn('deleted', 'datetime', [
'default' => null,
'null' => true,
]);
$table->create();
}
}
@@ -3,51 +3,50 @@ declare(strict_types=1);
use Migrations\AbstractMigration;
class CreateProductCategoryVariants extends AbstractMigration
{
/**
class CreateProductCategoryVariants extends AbstractMigration {
/**
* Change Method.
*
* More information on this method is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
* @return void
*/
public function change(): void
{
$table = $this->table('product_category_variants', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('name', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('product_category_id', 'uuid', [
'default' => null,
'null' => true,
]);
$table->addColumn('product_id', 'uuid', [
'default' => null,
'null' => true,
]);
$table->addColumn('enabled', 'boolean', [
'default' => null,
'null' => false,
]);
$table->addIndex([
'product_category_id',
], [
'name' => 'VARIANTS_BY_PRODUCT_CATEGORY_ID',
'unique' => false,
]);
$table->addIndex([
'product_id',
], [
'name' => 'CATEGORY_VARIANTS_BY_PRODUCT_ID',
'unique' => false,
]);
public function change(): void {
$table = $this->table('product_category_variants', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('name', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('product_category_id', 'uuid', [
'default' => null,
'null' => true,
]);
$table->addColumn('product_id', 'uuid', [
'default' => null,
'null' => true,
]);
$table->addColumn('enabled', 'boolean', [
'default' => null,
'null' => false,
]);
$table->addIndex([
'product_category_id',
], [
'name' => 'VARIANTS_BY_PRODUCT_CATEGORY_ID',
'unique' => false,
]);
$table->addIndex([
'product_id',
], [
'name' => 'CATEGORY_VARIANTS_BY_PRODUCT_ID',
'unique' => false,
]);
// $table->addIndex([
// 'name',
// 'product_category_id',
@@ -56,6 +55,7 @@ class CreateProductCategoryVariants extends AbstractMigration
// 'name' => 'VARIANTS_BY_NAME_AND_PRODUCT_CATEGORY_ID_AND_PRODUCT_ID_UNIQUE',
// 'unique' => true,
// ]);
$table->create();
}
$table->create();
}
}
@@ -3,54 +3,54 @@ declare(strict_types=1);
use Migrations\BaseMigration;
class CreateProductCategoryVariantOptions extends BaseMigration
{
/**
class CreateProductCategoryVariantOptions 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 change(): void
{
$table = $this->table('product_category_variant_options', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('product_category_variant_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('variant_value', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('variant_label', 'string', [
'default' => null,
'limit' => 255,
'null' => true,
]);
$table->addColumn('created', 'datetime', [
'default' => null,
'null' => false,
]);
$table->addColumn('modified', 'datetime', [
'default' => null,
'null' => false,
]);
$table->addColumn('deleted', 'datetime', [
'default' => null,
'null' => true,
]);
$table->addColumn('enabled', 'boolean', [
'default' => true,
'null' => false,
]);
public function change(): void {
$table = $this->table('product_category_variant_options', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('product_category_variant_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('variant_value', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('variant_label', 'string', [
'default' => null,
'limit' => 255,
'null' => true,
]);
$table->addColumn('created', 'datetime', [
'default' => null,
'null' => false,
]);
$table->addColumn('modified', 'datetime', [
'default' => null,
'null' => false,
]);
$table->addColumn('deleted', 'datetime', [
'default' => null,
'null' => true,
]);
$table->addColumn('enabled', 'boolean', [
'default' => true,
'null' => false,
]);
// $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;
class AddDefaultProductTypeIdToProductCategories extends BaseMigration
{
/**
class AddDefaultProductTypeIdToProductCategories 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 change(): void
{
$table = $this->table('product_categories');
$table->addColumn('default_product_type_id', 'integer', [
'default' => null,
'limit' => 11,
'null' => true,
]);
$table->update();
}
public function change(): void {
$table = $this->table('product_categories');
$table->addColumn('default_product_type_id', 'integer', [
'default' => null,
'limit' => 11,
'null' => true,
]);
$table->update();
}
}
@@ -3,9 +3,9 @@ declare(strict_types=1);
use Migrations\BaseMigration;
class CreateProductPhotos extends BaseMigration
{
/**
class CreateProductPhotos extends BaseMigration {
/**
* Change Method.
*
* More information on this method is available here:
@@ -13,75 +13,75 @@ class CreateProductPhotos extends BaseMigration
*
* @return void
*/
public function change(): void
{
$table = $this->table('product_photos', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('product_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('product_sku_id', 'uuid', [
'default' => null,
'null' => true,
]);
public function change(): void {
$table = $this->table('product_photos', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('product_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('product_sku_id', 'uuid', [
'default' => null,
'null' => true,
]);
$table->addColumn('photo_dir', 'text', [
'default' => null,
'length' => 255,
'null' => false,
]);
$table->addColumn('photo_filename', 'string', [
'default' => null,
'length' => 255,
'null' => false,
]);
$table->addColumn('photo_dir', 'text', [
'default' => null,
'length' => 255,
'null' => false,
]);
$table->addColumn('photo_filename', 'string', [
'default' => null,
'length' => 255,
'null' => false,
]);
$table->addColumn('primary_photo', 'boolean', [
'default' => false,
'null' => false,
]);
$table->addColumn('primary_photo', 'boolean', [
'default' => false,
'null' => false,
]);
$table->addColumn('photo_position', 'integer', [
'default' => 100,
'limit' => 11,
'null' => false,
]);
$table->addColumn('photo_position', 'integer', [
'default' => 100,
'limit' => 11,
'null' => false,
]);
$table->addColumn('enabled', 'boolean', [
'default' => false,
'null' => false,
]);
$table->addColumn('enabled', 'boolean', [
'default' => false,
'null' => false,
]);
$table->addColumn('created', 'datetime', [
'default' => null,
'null' => false,
]);
$table->addColumn('modified', 'datetime', [
'default' => null,
'null' => true,
]);
$table->addColumn('deleted', 'datetime', [
'default' => null,
'null' => true,
]);
$table->addColumn('created', 'datetime', [
'default' => null,
'null' => false,
]);
$table->addColumn('modified', 'datetime', [
'default' => null,
'null' => true,
]);
$table->addColumn('deleted', 'datetime', [
'default' => null,
'null' => true,
]);
$table->addIndex([
'product_id',
], [
'name' => 'PRODUCT_PHOTOS_BY_PRODUCT_ID',
'unique' => false,
]);
$table->addIndex([
'product_sku_id',
], [
'name' => 'PRODUCT_PHOTOS_BY_PRODUCT_SKU_ID',
'unique' => false,
]);
$table->addIndex([
'product_id',
], [
'name' => 'PRODUCT_PHOTOS_BY_PRODUCT_ID',
'unique' => false,
]);
$table->addIndex([
'product_sku_id',
], [
'name' => 'PRODUCT_PHOTOS_BY_PRODUCT_SKU_ID',
'unique' => false,
]);
$table->create();
}
$table->create();
}
}
@@ -3,9 +3,9 @@ declare(strict_types=1);
use Migrations\BaseMigration;
class CreateProductSkuVariantValues extends BaseMigration
{
/**
class CreateProductSkuVariantValues extends BaseMigration {
/**
* Change Method.
*
* More information on this method is available here:
@@ -13,25 +13,25 @@ class CreateProductSkuVariantValues extends BaseMigration
*
* @return void
*/
public function change(): void
{
$table = $this->table('product_sku_variant_values', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('product_sku_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('product_variant_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('product_category_variant_option_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->create();
}
public function change(): void {
$table = $this->table('product_sku_variant_values', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('product_sku_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('product_variant_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('product_category_variant_option_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->create();
}
}
@@ -3,9 +3,9 @@ declare(strict_types=1);
use Migrations\BaseMigration;
class CreateProductVariants extends BaseMigration
{
/**
class CreateProductVariants extends BaseMigration {
/**
* Change Method.
*
* More information on this method is available here:
@@ -13,42 +13,41 @@ class CreateProductVariants extends BaseMigration
*
* @return void
*/
public function change(): void
{
$table = $this->table('product_variants', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('name', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('product_category_variant_id', 'uuid', [
'default' => null,
'null' => true,
]);
$table->addColumn('product_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('enabled', 'boolean', [
'default' => null,
'null' => false,
]);
$table->addIndex([
'product_category_variant_id',
], [
'name' => 'VARIANTS_BY_PARENT_PRODUCT_CATEGORY_VARIANT_ID',
'unique' => false,
]);
$table->addIndex([
'product_id',
], [
'name' => 'VARIANTS_BY_PRODUCT_ID',
'unique' => false,
]);
public function change(): void {
$table = $this->table('product_variants', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('name', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('product_category_variant_id', 'uuid', [
'default' => null,
'null' => true,
]);
$table->addColumn('product_id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('enabled', 'boolean', [
'default' => null,
'null' => false,
]);
$table->addIndex([
'product_category_variant_id',
], [
'name' => 'VARIANTS_BY_PARENT_PRODUCT_CATEGORY_VARIANT_ID',
'unique' => false,
]);
$table->addIndex([
'product_id',
], [
'name' => 'VARIANTS_BY_PRODUCT_ID',
'unique' => false,
]);
// $table->addIndex([
// 'name',
@@ -57,6 +56,7 @@ class CreateProductVariants extends BaseMigration
// 'name' => 'VARIANTS_BY_NAME_AND_PRODUCT_CATEGORY_ID_UNIQUE',
// 'unique' => true,
// ]);
$table->create();
}
$table->create();
}
}
@@ -3,23 +3,23 @@ declare(strict_types=1);
use Migrations\BaseMigration;
class AddDefaultSkuToProductSkus extends BaseMigration
{
/**
class AddDefaultSkuToProductSkus 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 change(): void
{
$table = $this->table('product_skus');
$table->addColumn('default_sku', 'boolean', [
'default' => false,
'limit' => 11,
'null' => false,
]);
$table->update();
}
public function change(): void {
$table = $this->table('product_skus');
$table->addColumn('default_sku', 'boolean', [
'default' => false,
'limit' => 11,
'null' => false,
]);
$table->update();
}
}
@@ -3,9 +3,9 @@ declare(strict_types=1);
use Migrations\BaseMigration;
class AddProductCategoryIdToProductPhotos extends BaseMigration
{
/**
class AddProductCategoryIdToProductPhotos extends BaseMigration {
/**
* Change Method.
*
* More information on this method is available here:
@@ -13,17 +13,17 @@ class AddProductCategoryIdToProductPhotos extends BaseMigration
*
* @return void
*/
public function change(): void
{
$table = $this->table('product_photos');
$table->addColumn('product_category_id', 'uuid', [
'default' => null,
'null' => true,
]);
$table->addColumn('primary_category_photo', 'boolean', [
'default' => false,
'null' => false,
]);
$table->update();
}
public function change(): void {
$table = $this->table('product_photos');
$table->addColumn('product_category_id', 'uuid', [
'default' => null,
'null' => true,
]);
$table->addColumn('primary_category_photo', 'boolean', [
'default' => false,
'null' => false,
]);
$table->update();
}
}
@@ -3,23 +3,23 @@ declare(strict_types=1);
use Migrations\BaseMigration;
class AddPrimarySkuPhotoToProductPhotos extends BaseMigration
{
/**
class AddPrimarySkuPhotoToProductPhotos 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 change(): void
{
$table = $this->table('product_photos');
$table->addColumn('primary_sku_photo', 'boolean', [
'default' => false,
'limit' => 11,
'null' => false,
]);
$table->update();
}
public function change(): void {
$table = $this->table('product_photos');
$table->addColumn('primary_sku_photo', 'boolean', [
'default' => false,
'limit' => 11,
'null' => false,
]);
$table->update();
}
}
@@ -3,51 +3,50 @@ declare(strict_types=1);
use Migrations\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();
}
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 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();
}
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.
*
* 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;
class AddIsSystemToProductCategoryVariants extends BaseMigration
{
/**
class AddIsSystemToProductCategoryVariants 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 change(): void
{
$table = $this->table('product_category_variants');
$table->addColumn('is_system_variant', 'boolean', [
'default' => false,
'limit' => 11,
'null' => false,
]);
$table->update();
}
public function change(): void {
$table = $this->table('product_category_variants');
$table->addColumn('is_system_variant', 'boolean', [
'default' => false,
'limit' => 11,
'null' => false,
]);
$table->update();
}
}
@@ -3,14 +3,15 @@ declare(strict_types=1);
namespace Seeds;
use Cake\Utility\Text;
use Migrations\BaseSeed;
/**
* CreateSystemCategoryVariants seed.
*/
class CreateSystemCategoryVariantsSeed extends BaseSeed
{
/**
class CreateSystemCategoryVariantsSeed extends BaseSeed {
/**
* Run Method.
*
* Write your database seeder using this method.
@@ -20,36 +21,36 @@ class CreateSystemCategoryVariantsSeed extends BaseSeed
*
* @return void
*/
public function run(): void
{
$data = [
[
'id' => \Cake\Utility\Text::uuid(),
'name' => 'Subscription Length',
'product_category_id' => null,
'enabled' => true,
'is_system_variant' => true,
],
[
'id' => \Cake\Utility\Text::uuid(),
'name' => 'Subscription Length Units',
'product_category_id' => null,
'enabled' => true,
'is_system_variant' => true,
],
];
$table = $this->table('product_category_variants');
$toInsert = [];
foreach ($data as $singleRecordToInsert) {
$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
if ($rows) {
continue;
}
$toInsert[] = $singleRecordToInsert;
}
if ($toInsert) {
$table->insert($data)->save();
}
}
public function run(): void {
$data = [
[
'id' => Text::uuid(),
'name' => 'Subscription Length',
'product_category_id' => null,
'enabled' => true,
'is_system_variant' => true,
],
[
'id' => Text::uuid(),
'name' => 'Subscription Length Units',
'product_category_id' => null,
'enabled' => true,
'is_system_variant' => true,
],
];
$table = $this->table('product_category_variants');
$toInsert = [];
foreach ($data as $singleRecordToInsert) {
$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
if ($rows) {
continue;
}
$toInsert[] = $singleRecordToInsert;
}
if ($toInsert) {
$table->insert($data)->save();
}
}
}
+12 -12
View File
@@ -4,10 +4,10 @@
return [
'CakeProducts' => [
'photos' => [
'directory' => WWW_ROOT . 'images' . DS . 'products' . DS,
],
/**
'photos' => [
'directory' => WWW_ROOT . 'images' . DS . 'products' . DS,
],
/**
* internal CakeProducts settings - used in the source of truth/internal only system.
* Can optionally manage external catalogs
*
@@ -15,17 +15,17 @@ return [
* 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
*/
'internal' => [
'enabled' => true,
/**
'internal' => [
'enabled' => true,
/**
* 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.
* Will have no effect if true but no external catalogs have been added or none are enabled
*/
'syncExternally' => false,
],
'external' => [ // product catalog settings for external use (as an API server to power an ecommerce site for example)
'enabled' => false,
],
'syncExternally' => false,
],
'external' => [ // product catalog settings for external use (as an API server to power an ecommerce site for example)
'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
*/
class CakeProductsPlugin extends BasePlugin
{
/**
class CakeProductsPlugin extends BasePlugin {
/**
* Load all the plugin configuration and bootstrap logic.
*
* The host application is provided as an argument. This allows you to load
@@ -24,11 +24,10 @@ class CakeProductsPlugin extends BasePlugin
* @param \Cake\Core\PluginApplicationInterface $app The host application
* @return void
*/
public function bootstrap(PluginApplicationInterface $app): void
{
}
public function bootstrap(PluginApplicationInterface $app): void {
}
/**
/**
* Add routes for the plugin.
*
* If your plugin has many routes and you would like to isolate them into a separate file,
@@ -37,57 +36,54 @@ class CakeProductsPlugin extends BasePlugin
* @param \Cake\Routing\RouteBuilder $routes The route builder to update.
* @return void
*/
public function routes(RouteBuilder $routes): void
{
$routes->plugin(
'CakeProducts',
['path' => '/cake-products'],
function (RouteBuilder $builder) {
// Add custom routes here
public function routes(RouteBuilder $routes): void {
$routes->plugin(
'CakeProducts',
['path' => '/cake-products'],
function (RouteBuilder $builder) {
// Add custom routes here
$builder->fallbacks();
}
);
parent::routes($routes);
}
$builder->fallbacks();
},
);
parent::routes($routes);
}
/**
/**
* Add middleware for the plugin.
*
* @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to update.
* @return \Cake\Http\MiddlewareQueue
*/
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
{
// Add your middlewares here
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue {
// Add your middlewares here
return $middlewareQueue;
}
return $middlewareQueue;
}
/**
/**
* Add commands for the plugin.
*
* @param \Cake\Console\CommandCollection $commands The command collection to update.
* @return \Cake\Console\CommandCollection
*/
public function console(CommandCollection $commands): CommandCollection
{
// Add your commands here
public function console(CommandCollection $commands): CommandCollection {
// Add your commands here
$commands = parent::console($commands);
$commands = parent::console($commands);
return $commands;
}
return $commands;
}
/**
/**
* Register application container services.
*
* @link https://book.cakephp.org/4/en/development/dependency-injection.html#dependency-injection
* @param \Cake\Core\ContainerInterface $container The Container to update.
* @return void
* @link https://book.cakephp.org/4/en/development/dependency-injection.html#dependency-injection
*/
public function services(ContainerInterface $container): void
{
// Add your services here
}
public function services(ContainerInterface $container): void {
// Add your services here
}
}
+1 -2
View File
@@ -5,6 +5,5 @@ namespace CakeProducts\Controller;
use App\Controller\AppController as BaseController;
class AppController extends BaseController
{
class AppController extends BaseController {
}
@@ -3,130 +3,122 @@ declare(strict_types=1);
namespace CakeProducts\Controller;
use Cake\Core\Configure;
use Cake\Log\Log;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
/**
* ExternalProductCatalogs Controller
*
* @property \CakeProducts\Model\Table\ExternalProductCatalogsTable $ExternalProductCatalogs
*/
class ExternalProductCatalogsController extends AppController
{
class ExternalProductCatalogsController extends AppController {
// use OverrideTableTrait;
/**
/**
* @return void
*/
public function initialize(): void
{
parent::initialize(); // TODO: Change the autogenerated stub
public function initialize(): void {
parent::initialize(); // TODO: Change the autogenerated stub
// $this->_defaultTable = 'CakeProducts.ExternalProductCatalogs';
// $this->_tableConfigKey = 'CakeProducts.ExternalProductCatalogs.table';
}
}
/**
/**
* Index method
*
* @return \Cake\Http\Response|null|void Renders view
*/
public function index()
{
$query = $this->ExternalProductCatalogs->find()
->contain(['ProductCatalogs']);
$externalProductCatalogs = $this->paginate($query);
public function index() {
$query = $this->ExternalProductCatalogs->find()
->contain(['ProductCatalogs']);
$externalProductCatalogs = $this->paginate($query);
$this->set(compact('externalProductCatalogs'));
}
$this->set(compact('externalProductCatalogs'));
}
/**
/**
* View method
*
* @param string|null $id External Product Catalog id.
* @return \Cake\Http\Response|null|void Renders view
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Renders view
*/
public function view($id = null)
{
$externalProductCatalog = $this->ExternalProductCatalogs->get($id, contain: ['ProductCatalogs']);
$this->set(compact('externalProductCatalog'));
}
public function view($id = null) {
$externalProductCatalog = $this->ExternalProductCatalogs->get($id, contain: ['ProductCatalogs']);
$this->set(compact('externalProductCatalog'));
}
/**
/**
* Add method
*
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
*/
public function add()
{
$externalProductCatalog = $this->ExternalProductCatalogs->newEmptyEntity();
if ($this->request->is('post')) {
$saveOptions = [
'associated' => [
'ExternalProductCatalogsProductCatalogs',
],
];
$postData = $this->request->getData();
Log::debug(print_r('$postData', true));
Log::debug(print_r($postData, true));
$externalProductCatalog = $this->ExternalProductCatalogs->patchEntity($externalProductCatalog, $postData, $saveOptions);
if ($this->ExternalProductCatalogs->save($externalProductCatalog, $saveOptions)) {
$this->Flash->success(__('The external product catalog has been saved.'));
public function add() {
$externalProductCatalog = $this->ExternalProductCatalogs->newEmptyEntity();
if ($this->request->is('post')) {
$saveOptions = [
'associated' => [
'ExternalProductCatalogsProductCatalogs',
],
];
$postData = $this->request->getData();
Log::debug(print_r('$postData', true));
Log::debug(print_r($postData, true));
$externalProductCatalog = $this->ExternalProductCatalogs->patchEntity($externalProductCatalog, $postData, $saveOptions);
if ($this->ExternalProductCatalogs->save($externalProductCatalog, $saveOptions)) {
$this->Flash->success(__('The external product catalog has been saved.'));
return $this->redirect(['action' => 'index']);
}
Log::debug(print_r('$externalProductCatalog->getErrors() next - failed /add', true));
Log::debug(print_r($externalProductCatalog->getErrors(), true));
$this->Flash->error(__('The external product catalog could not be saved. Please, try again.'));
}
$productCatalogs = $this->ExternalProductCatalogs->ProductCatalogs->find('list', limit: 200)->all();
$this->set(compact('externalProductCatalog', 'productCatalogs'));
}
return $this->redirect(['action' => 'index']);
}
Log::debug(print_r('$externalProductCatalog->getErrors() next - failed /add', true));
Log::debug(print_r($externalProductCatalog->getErrors(), true));
$this->Flash->error(__('The external product catalog could not be saved. Please, try again.'));
}
$productCatalogs = $this->ExternalProductCatalogs->ProductCatalogs->find('list', limit: 200)->all();
$this->set(compact('externalProductCatalog', 'productCatalogs'));
}
/**
/**
* Edit method
*
* @param string|null $id External Product Catalog id.
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
*/
public function edit($id = null)
{
$externalProductCatalog = $this->ExternalProductCatalogs->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) {
$externalProductCatalog = $this->ExternalProductCatalogs->patchEntity($externalProductCatalog, $this->request->getData());
if ($this->ExternalProductCatalogs->save($externalProductCatalog)) {
$this->Flash->success(__('The external product catalog has been saved.'));
public function edit($id = null) {
$externalProductCatalog = $this->ExternalProductCatalogs->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) {
$externalProductCatalog = $this->ExternalProductCatalogs->patchEntity($externalProductCatalog, $this->request->getData());
if ($this->ExternalProductCatalogs->save($externalProductCatalog)) {
$this->Flash->success(__('The external product catalog has been saved.'));
return $this->redirect(['action' => 'index']);
}
Log::debug(print_r('$externalProductCatalog->getErrors() next - failed /edit', true));
Log::debug(print_r($externalProductCatalog->getErrors(), true));
$this->Flash->error(__('The external product catalog could not be saved. Please, try again.'));
}
$productCatalogs = $this->ExternalProductCatalogs->ProductCatalogs->find('list', limit: 200)->all();
$this->set(compact('externalProductCatalog', 'productCatalogs'));
}
return $this->redirect(['action' => 'index']);
}
Log::debug(print_r('$externalProductCatalog->getErrors() next - failed /edit', true));
Log::debug(print_r($externalProductCatalog->getErrors(), true));
$this->Flash->error(__('The external product catalog could not be saved. Please, try again.'));
}
$productCatalogs = $this->ExternalProductCatalogs->ProductCatalogs->find('list', limit: 200)->all();
$this->set(compact('externalProductCatalog', 'productCatalogs'));
}
/**
/**
* Delete method
*
* @param string|null $id External Product Catalog id.
* @return \Cake\Http\Response|null Redirects to index.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null Redirects to index.
*/
public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$externalProductCatalog = $this->ExternalProductCatalogs->get($id);
if ($this->ExternalProductCatalogs->delete($externalProductCatalog)) {
$this->Flash->success(__('The external product catalog has been deleted.'));
} else {
$this->Flash->error(__('The external product catalog could not be deleted. Please, try again.'));
}
public function delete($id = null) {
$this->request->allowMethod(['post', 'delete']);
$externalProductCatalog = $this->ExternalProductCatalogs->get($id);
if ($this->ExternalProductCatalogs->delete($externalProductCatalog)) {
$this->Flash->success(__('The external product catalog has been deleted.'));
} else {
$this->Flash->error(__('The external product catalog could not be deleted. Please, try again.'));
}
return $this->redirect(['action' => 'index']);
}
return $this->redirect(['action' => 'index']);
}
}
@@ -3,49 +3,45 @@ declare(strict_types=1);
namespace CakeProducts\Controller;
use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Http\Response;
use Cake\Log\Log;
/**
* ExternalProductCatalogsProductCatalogs Controller
*
*/
class ExternalProductCatalogsProductCatalogsController extends AppController
{
/**
class ExternalProductCatalogsProductCatalogsController extends AppController {
/**
* Add method
*
* @return Response|null|void Redirects on successful add, renders view otherwise.
* @return \Cake\Http\Response|voidRedirects|null on successful add, renders view otherwise.
*/
public function add()
{
Log::debug('inside external product catalogs product catalogs controller add');
$productCatalogs = $this->ExternalProductCatalogsProductCatalogs->ProductCatalogs->find('list')->toArray();
$this->set(compact( 'productCatalogs'));
}
public function add() {
Log::debug('inside external product catalogs product catalogs controller add');
$productCatalogs = $this->ExternalProductCatalogsProductCatalogs->ProductCatalogs->find('list')->toArray();
$this->set(compact('productCatalogs'));
}
/**
/**
* Delete method
*
* @param string|null $id Customers Contact id.
* @return Response|null Redirects to index.
* @throws RecordNotFoundException When record not found.
* @return Response|null Redirects to index.
*/
public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$externalProductCatalogProductCatalog = $this->ExternalProductCatalogsProductCatalogs->get($id);
if ($this->ExternalProductCatalogsProductCatalogs->delete($externalProductCatalogProductCatalog)) {
$this->Flash->success(__('The customers contact has been deleted.'));
} else {
$this->Flash->error(__('The customers contact could not be deleted. Please, try again.'));
}
public function delete($id = null) {
$this->request->allowMethod(['post', 'delete']);
$externalProductCatalogProductCatalog = $this->ExternalProductCatalogsProductCatalogs->get($id);
if ($this->ExternalProductCatalogsProductCatalogs->delete($externalProductCatalogProductCatalog)) {
$this->Flash->success(__('The customers contact has been deleted.'));
} else {
$this->Flash->error(__('The customers contact could not be deleted. Please, try again.'));
}
return $this->redirect($this->referer([
'controller' => 'ExternalProductCatalogs',
'action' => 'view',
$externalProductCatalogProductCatalog->external_product_catalog_id,
]));
}
return $this->redirect($this->referer([
'controller' => 'ExternalProductCatalogs',
'action' => 'view',
$externalProductCatalogProductCatalog->external_product_catalog_id,
]));
}
}
+71 -81
View File
@@ -4,126 +4,116 @@ declare(strict_types=1);
namespace CakeProducts\Controller;
use Cake\Core\Configure;
use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Http\Response;
use Cake\Log\Log;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
use CakeProducts\Model\Table\ProductCatalogsTable;
/**
* ProductCatalogs Controller
*
* @property ProductCatalogsTable $ProductCatalogs
* @property \CakeProducts\Model\Table\ProductCatalogsTable $ProductCatalogs
*/
class ProductCatalogsController extends AppController
{
/**
class ProductCatalogsController extends AppController {
/**
* @return void
*/
public function initialize(): void
{
parent::initialize(); // TODO: Change the autogenerated stub
public function initialize(): void {
parent::initialize(); // TODO: Change the autogenerated stub
// $this->_defaultTable = 'CakeProducts.ProductCatalogs';
// $this->_tableConfigKey = 'CakeProducts.ProductCatalogs.table';
}
}
/**
/**
* Index method
*
* @return Response|null|void Renders view
* @return \Cake\Http\Response|voidRenders|null view
*/
public function index()
{
$query = $this->ProductCatalogs->find();
$productCatalogs = $this->paginate($query);
public function index() {
$query = $this->ProductCatalogs->find();
$productCatalogs = $this->paginate($query);
$this->set(compact('productCatalogs'));
}
$this->set(compact('productCatalogs'));
}
/**
/**
* View method
*
* @param string|null $id Product Catalog id.
* @return Response|null|void Renders view
* @throws RecordNotFoundException When record not found.
* @return Response|null|void Renders view
*/
public function view($id = null)
{
$contain = ['ProductCategories'];
if (Configure::read('CakeProducts.internal.syncExternally', false)) {
$contain[] = 'ExternalProductCatalogs';
}
$productCatalog = $this->ProductCatalogs->get($id, contain: $contain);
$this->set(compact('productCatalog'));
}
public function view($id = null) {
$contain = ['ProductCategories'];
if (Configure::read('CakeProducts.internal.syncExternally', false)) {
$contain[] = 'ExternalProductCatalogs';
}
$productCatalog = $this->ProductCatalogs->get($id, contain: $contain);
$this->set(compact('productCatalog'));
}
/**
/**
* Add method
*
* @return Response|null|void Redirects on successful add, renders view otherwise.
* @return \Cake\Http\Response|voidRedirects|null on successful add, renders view otherwise.
*/
public function add()
{
$productCatalogsTable = $this->ProductCatalogs;
$productCatalog = $productCatalogsTable->newEmptyEntity();
if ($this->request->is('post')) {
$productCatalog = $productCatalogsTable->patchEntity($productCatalog, $this->request->getData());
if ($productCatalogsTable->save($productCatalog)) {
$this->Flash->success(__('The product catalog has been saved.'));
public function add() {
$productCatalogsTable = $this->ProductCatalogs;
$productCatalog = $productCatalogsTable->newEmptyEntity();
if ($this->request->is('post')) {
$productCatalog = $productCatalogsTable->patchEntity($productCatalog, $this->request->getData());
if ($productCatalogsTable->save($productCatalog)) {
$this->Flash->success(__('The product catalog has been saved.'));
return $this->redirect(['action' => 'index']);
}
Log::debug('failed to save new product catalog errors next');
Log::debug(print_r('$productCatalog->getErrors()', true));
Log::debug(print_r($productCatalog->getErrors(), true));
return $this->redirect(['action' => 'index']);
}
Log::debug('failed to save new product catalog errors next');
Log::debug(print_r('$productCatalog->getErrors()', true));
Log::debug(print_r($productCatalog->getErrors(), true));
$this->Flash->error(__('The product catalog could not be saved. Please, try again.'));
}
$this->set(compact('productCatalog'));
}
$this->Flash->error(__('The product catalog could not be saved. Please, try again.'));
}
$this->set(compact('productCatalog'));
}
/**
/**
* Edit method
*
* @param string|null $id Product Catalog id.
* @return Response|null|void Redirects on successful edit, renders view otherwise.
* @throws RecordNotFoundException When record not found.
* @return Response|null|void Redirects on successful edit, renders view otherwise.
*/
public function edit($id = null)
{
$productCatalogsTable = $this->ProductCatalogs;
$productCatalog = $productCatalogsTable->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) {
$productCatalog = $productCatalogsTable->patchEntity($productCatalog, $this->request->getData());
if ($productCatalogsTable->save($productCatalog)) {
$this->Flash->success(__('The product catalog has been saved.'));
public function edit($id = null) {
$productCatalogsTable = $this->ProductCatalogs;
$productCatalog = $productCatalogsTable->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) {
$productCatalog = $productCatalogsTable->patchEntity($productCatalog, $this->request->getData());
if ($productCatalogsTable->save($productCatalog)) {
$this->Flash->success(__('The product catalog has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The product catalog could not be saved. Please, try again.'));
}
$this->set(compact('productCatalog'));
}
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The product catalog could not be saved. Please, try again.'));
}
$this->set(compact('productCatalog'));
}
/**
/**
* Delete method
*
* @param string|null $id Product Catalog id.
* @return Response|null Redirects to index.
* @throws RecordNotFoundException When record not found.
* @return Response|null Redirects to index.
*/
public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$productCatalogsTable = $this->ProductCatalogs;
$productCatalog = $productCatalogsTable->get($id);
if ($productCatalogsTable->delete($productCatalog)) {
$this->Flash->success(__('The product catalog has been deleted.'));
} else {
$this->Flash->error(__('The product catalog could not be deleted. Please, try again.'));
}
public function delete($id = null) {
$this->request->allowMethod(['post', 'delete']);
$productCatalogsTable = $this->ProductCatalogs;
$productCatalog = $productCatalogsTable->get($id);
if ($productCatalogsTable->delete($productCatalog)) {
$this->Flash->success(__('The product catalog has been deleted.'));
} else {
$this->Flash->error(__('The product catalog could not be deleted. Please, try again.'));
}
return $this->redirect(['action' => 'index']);
}
return $this->redirect(['action' => 'index']);
}
}
+105 -114
View File
@@ -3,10 +3,7 @@ declare(strict_types=1);
namespace CakeProducts\Controller;
use Cake\Core\Configure;
use Cake\Log\Log;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
use Cake\Utility\Text;
/**
@@ -14,163 +11,157 @@ use Cake\Utility\Text;
*
* @property \CakeProducts\Model\Table\ProductCategoriesTable $ProductCategories
*/
class ProductCategoriesController extends AppController
{
/**
class ProductCategoriesController extends AppController {
/**
* @return void
*/
public function initialize(): void
{
parent::initialize(); // TODO: Change the autogenerated stub
public function initialize(): void {
parent::initialize(); // TODO: Change the autogenerated stub
// $this->_defaultTable = 'CakeProducts.ProductCategories';
// $this->_tableConfigKey = 'CakeProducts.ProductCategories.table';
}
}
/**
/**
* Index method
*
* @return \Cake\Http\Response|null|void Renders view
*/
public function index()
{
$query = $this->ProductCategories->find()
->contain(['ProductCatalogs', 'ParentProductCategories']);
$productCategories = $this->paginate($query);
public function index() {
$query = $this->ProductCategories->find()
->contain(['ProductCatalogs', 'ParentProductCategories']);
$productCategories = $this->paginate($query);
$this->set(compact('productCategories'));
}
$this->set(compact('productCategories'));
}
/**
/**
* View method
*
* @param string|null $id Product Category id.
* @return \Cake\Http\Response|null|void Renders view
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Renders view
*/
public function view($id = null)
{
$productCategory = $this->ProductCategories->get($id, contain: [
'ProductCatalogs',
'ParentProductCategories',
'ChildProductCategories',
'ProductCategoryAttributes',
'ProductCategoryAttributes.ProductCategoryAttributeOptions',
'PrimaryProductPhotos',
]);
public function view($id = null) {
$productCategory = $this->ProductCategories->get($id, contain: [
'ProductCatalogs',
'ParentProductCategories',
'ChildProductCategories',
'ProductCategoryAttributes',
'ProductCategoryAttributes.ProductCategoryAttributeOptions',
'PrimaryProductPhotos',
]);
$productCategoryAttributes = $this->ProductCategories->ProductCategoryAttributes->getAllCategoryAttributesForCategoryId($productCategory->internal_id);
$this->set(compact('productCategory', 'productCategoryAttributes'));
}
$productCategoryAttributes = $this->ProductCategories->ProductCategoryAttributes->getAllCategoryAttributesForCategoryId($productCategory->internal_id);
$this->set(compact('productCategory', 'productCategoryAttributes'));
}
/**
/**
* Add method
*
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
*/
public function add()
{
$productCategoriesTable = $this->ProductCategories;
$productCategory = $productCategoriesTable->newEmptyEntity();
if ($this->request->is('post')) {
$postData = $this->request->getData();
$saveOptions = [
'associated' => [],
];
if ($this->request->getSession()->read('Auth.User.id')) {
$postData['created_by'] = $this->request->getSession()->read('Auth.User.id');
}
if (!array_key_exists('internal_id', $postData) || !$postData['internal_id']) {
$postData['internal_id'] = Text::uuid();
}
$productCategory = $productCategoriesTable->patchEntity($productCategory, $postData, $saveOptions);
if ($productCategory->getErrors()) {
Log::debug(print_r('$productCategory->getErrors() next - failed to save from create new product category', true));
Log::debug(print_r($productCategory->getErrors(), true));
}
if ($this->ProductCategories->save($productCategory, $saveOptions)) {
$this->Flash->success(__('The product category has been saved.'));
public function add() {
$productCategoriesTable = $this->ProductCategories;
$productCategory = $productCategoriesTable->newEmptyEntity();
if ($this->request->is('post')) {
$postData = $this->request->getData();
$saveOptions = [
'associated' => [],
];
if ($this->request->getSession()->read('Auth.User.id')) {
$postData['created_by'] = $this->request->getSession()->read('Auth.User.id');
}
if (!array_key_exists('internal_id', $postData) || !$postData['internal_id']) {
$postData['internal_id'] = Text::uuid();
}
$productCategory = $productCategoriesTable->patchEntity($productCategory, $postData, $saveOptions);
if ($productCategory->getErrors()) {
Log::debug(print_r('$productCategory->getErrors() next - failed to save from create new product category', true));
Log::debug(print_r($productCategory->getErrors(), true));
}
if ($this->ProductCategories->save($productCategory, $saveOptions)) {
$this->Flash->success(__('The product category has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The product category could not be saved. Please, try again.'));
}
$productCatalogs = $productCategoriesTable->ProductCatalogs->find('list', limit: 200)->all();
$parentProductCategories = $productCategoriesTable->ParentProductCategories->find('treeList', limit: 200)->toArray();
$this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories'));
}
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The product category could not be saved. Please, try again.'));
}
$productCatalogs = $productCategoriesTable->ProductCatalogs->find('list', limit: 200)->all();
$parentProductCategories = $productCategoriesTable->ParentProductCategories->find('treeList', limit: 200)->toArray();
$this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories'));
}
/**
/**
* Edit method
*
* @param string|null $id Product Category id.
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
*/
public function edit($id = null)
{
$productCategoriesTable = $this->ProductCategories;
$productCategory = $productCategoriesTable->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) {
$postData = $this->request->getData();
$productCategory = $productCategoriesTable->patchEntity($productCategory, $postData);
if ($productCategoriesTable->save($productCategory)) {
$this->Flash->success(__('The product category has been saved.'));
public function edit($id = null) {
$productCategoriesTable = $this->ProductCategories;
$productCategory = $productCategoriesTable->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) {
$postData = $this->request->getData();
$productCategory = $productCategoriesTable->patchEntity($productCategory, $postData);
if ($productCategoriesTable->save($productCategory)) {
$this->Flash->success(__('The product category has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The product category could not be saved. Please, try again.'));
}
$productCatalogs = $productCategoriesTable->ProductCatalogs->find('list', limit: 200)->all();
$parentProductCategories = $productCategoriesTable->ParentProductCategories->find('list', limit: 200)->all();
$this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories'));
}
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The product category could not be saved. Please, try again.'));
}
$productCatalogs = $productCategoriesTable->ProductCatalogs->find('list', limit: 200)->all();
$parentProductCategories = $productCategoriesTable->ParentProductCategories->find('list', limit: 200)->all();
$this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories'));
}
/**
/**
* Delete method
*
* @param string|null $id Product Category id.
* @return \Cake\Http\Response|null Redirects to index.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null Redirects to index.
*/
public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$productCategoriesTable = $this->ProductCategories;
public function delete($id = null) {
$this->request->allowMethod(['post', 'delete']);
$productCategoriesTable = $this->ProductCategories;
$productCategory = $productCategoriesTable->get($id);
$productCategory = $productCategoriesTable->get($id);
// $productCategoriesTable->behaviors()->get('Tree')->setConfig([
// 'scope' => [
// 'product_catalog_id' => $productCategory->product_catalog_id,
// ],
// ]);
if ($productCategoriesTable->delete($productCategory)) {
$this->Flash->success(__('The product category has been deleted.'));
} else {
$this->Flash->error(__('The product category could not be deleted. Please, try again.'));
}
if ($productCategoriesTable->delete($productCategory)) {
$this->Flash->success(__('The product category has been deleted.'));
} else {
$this->Flash->error(__('The product category could not be deleted. Please, try again.'));
}
return $this->redirect(['action' => 'index']);
}
return $this->redirect(['action' => 'index']);
}
/**
/**
* @return \Cake\Http\Response|null|void Renders view
*/
public function select()
{
$productCategoriesTable = $this->ProductCategories;
$productCategoriesTable->behaviors()->get('Tree')->setConfig([
'scope' => [
'product_catalog_id' => $this->request->getQuery('product_catalog_id', -1),
],
]);
$productCategoriesQ = $this->request->getQuery('form', 'product_category') === 'product' ?
$productCategoriesTable->find('treeList', keyPath: 'internal_id', valuePath: 'name') :
$productCategoriesTable->find('treeList');
public function select() {
$productCategoriesTable = $this->ProductCategories;
$productCategoriesTable->behaviors()->get('Tree')->setConfig([
'scope' => [
'product_catalog_id' => $this->request->getQuery('product_catalog_id', -1),
],
]);
$productCategoriesQ = $this->request->getQuery('form', 'product_category') === 'product' ?
$productCategoriesTable->find('treeList', keyPath: 'internal_id', valuePath: 'name') :
$productCategoriesTable->find('treeList');
$productCategories = $productCategoriesQ
->orderBy(['ProductCategories.name'])
->toArray();
$productCategories = $productCategoriesQ
->orderBy(['ProductCategories.name'])
->toArray();
$this->set(compact('productCategories'));
}
$this->set(compact('productCategories'));
}
}
@@ -3,60 +3,55 @@ declare(strict_types=1);
namespace CakeProducts\Controller;
use Cake\Core\Configure;
use Cake\Log\Log;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
/**
* ProductCategoryAttributeOptions Controller
*
* @property \CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable $ProductCategoryAttributeOptions
*/
class ProductCategoryAttributeOptionsController extends AppController
{
/**
class ProductCategoryAttributeOptionsController extends AppController {
/**
* @return void
*/
public function initialize(): void
{
parent::initialize(); // TODO: Change the autogenerated stub
public function initialize(): void {
parent::initialize(); // TODO: Change the autogenerated stub
// $this->_defaultTable = 'CakeProducts.ProductCategoryAttributeOptions';
// $this->_tableConfigKey = 'CakeProducts.ProductCategoryAttributeOptions.table';
}
}
/**
/**
* Add method
*
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
*/
public function add()
{
Log::debug('inside product category attribute options controller add');
public function add() {
Log::debug('inside product category attribute options controller add');
$productCategoryAttributeOption = $this->ProductCategoryAttributeOptions->newEmptyEntity();
$this->set(compact('productCategoryAttributeOption'));
}
$productCategoryAttributeOption = $this->ProductCategoryAttributeOptions->newEmptyEntity();
$this->set(compact('productCategoryAttributeOption'));
}
/**
/**
* Delete method
*
* @param string|null $id Product Category Attribute Option id.
* @return \Cake\Http\Response|null Redirects to index.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null Redirects to index.
*/
public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$productCategoryAttributeOptionsTable = $this->ProductCategoryAttributeOptions;
public function delete($id = null) {
$this->request->allowMethod(['post', 'delete']);
$productCategoryAttributeOptionsTable = $this->ProductCategoryAttributeOptions;
$productCategoryAttributeOption = $productCategoryAttributeOptionsTable->get($id);
if ($productCategoryAttributeOptionsTable->delete($productCategoryAttributeOption)) {
$this->Flash->success(__('The product category attribute option has been deleted.'));
} else {
$this->Flash->error(__('The product category attribute option could not be deleted. Please, try again.'));
}
$productCategoryAttributeOption = $productCategoryAttributeOptionsTable->get($id);
if ($productCategoryAttributeOptionsTable->delete($productCategoryAttributeOption)) {
$this->Flash->success(__('The product category attribute option has been deleted.'));
} else {
$this->Flash->error(__('The product category attribute option could not be deleted. Please, try again.'));
}
return $this->redirect(['controller' => 'ProductCategoryAttributes', 'action' => 'view', $productCategoryAttributeOption->product_category_attribute_id]);
}
return $this->redirect(['controller' => 'ProductCategoryAttributes', 'action' => 'view', $productCategoryAttributeOption->product_category_attribute_id]);
}
}
@@ -3,172 +3,159 @@ declare(strict_types=1);
namespace CakeProducts\Controller;
use Cake\Core\Configure;
use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Http\Response;
use Cake\Log\Log;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
use CakeProducts\Model\Enum\ProductCategoryAttributeTypeId;
use CakeProducts\Model\Table\ProductCategoryAttributesTable;
/**
* ProductCategoryAttributes Controller
*
* @property ProductCategoryAttributesTable $ProductCategoryAttributes
* @property \CakeProducts\Model\Table\ProductCategoryAttributesTable $ProductCategoryAttributes
*/
class ProductCategoryAttributesController extends AppController
{
/**
class ProductCategoryAttributesController extends AppController {
/**
* @return void
*/
public function initialize(): void
{
parent::initialize(); // TODO: Change the autogenerated stub
public function initialize(): void {
parent::initialize(); // TODO: Change the autogenerated stub
// $this->_defaultTable = 'CakeProducts.ProductCategoryAttributes';
// $this->_tableConfigKey = 'CakeProducts.ProductCategoryAttributes.table';
}
}
/**
/**
* Index method
*
* @return Response|null|void Renders view
* @return \Cake\Http\Response|voidRenders|null view
*/
public function index()
{
$query = $this->ProductCategoryAttributes->find()
->contain(['ProductCategories']);
$productCategoryAttributes = $this->paginate($query);
public function index() {
$query = $this->ProductCategoryAttributes->find()
->contain(['ProductCategories']);
$productCategoryAttributes = $this->paginate($query);
$this->set(compact('productCategoryAttributes'));
}
$this->set(compact('productCategoryAttributes'));
}
/**
/**
* View method
*
* @param string|null $id Product Category Attribute id.
* @return Response|null|void Renders view
* @throws RecordNotFoundException When record not found.
* @return Response|null|void Renders view
*/
public function view($id = null)
{
$productCategoryAttribute = $this->ProductCategoryAttributes->get($id, contain: [
'ProductCategories',
'ProductCategoryAttributeOptions',
]);
public function view($id = null) {
$productCategoryAttribute = $this->ProductCategoryAttributes->get($id, contain: [
'ProductCategories',
'ProductCategoryAttributeOptions',
]);
$this->set(compact('productCategoryAttribute'));
}
$this->set(compact('productCategoryAttribute'));
}
/**
/**
* Add method
*
* @return Response|null|void Redirects on successful add, renders view otherwise.
* @return \Cake\Http\Response|voidRedirects|null on successful add, renders view otherwise.
*/
public function add()
{
$productCategoryAttributesTable = $this->ProductCategoryAttributes;
$productCategoryAttribute = $productCategoryAttributesTable->newEmptyEntity();
if ($this->request->is('post')) {
$postData = $this->request->getData();
if ($this->request->getSession()->read('Auth.User.id')) {
$postData['created_by'] = $this->request->getSession()->read('Auth.User.id');
}
Log::debug(print_r('$postData', true));
Log::debug(print_r($postData, true));
$saveOptions = [
'associated' => [
'ProductCategoryAttributeOptions'
],
];
$productCategoryAttribute = $productCategoryAttributesTable->patchEntity($productCategoryAttribute, $postData, $saveOptions);
if ($productCategoryAttribute->getErrors()) {
Log::debug(print_r('$productCategoryAttribute->getErrors() next - failed to save from create new product category attribute', true));
Log::debug(print_r($productCategoryAttribute->getErrors(), true));
}
if ($productCategoryAttributesTable->save($productCategoryAttribute, $saveOptions)) {
$this->Flash->success(__('The product category attribute has been saved.'));
public function add() {
$productCategoryAttributesTable = $this->ProductCategoryAttributes;
$productCategoryAttribute = $productCategoryAttributesTable->newEmptyEntity();
if ($this->request->is('post')) {
$postData = $this->request->getData();
if ($this->request->getSession()->read('Auth.User.id')) {
$postData['created_by'] = $this->request->getSession()->read('Auth.User.id');
}
Log::debug(print_r('$postData', true));
Log::debug(print_r($postData, true));
$saveOptions = [
'associated' => [
'ProductCategoryAttributeOptions',
],
];
$productCategoryAttribute = $productCategoryAttributesTable->patchEntity($productCategoryAttribute, $postData, $saveOptions);
if ($productCategoryAttribute->getErrors()) {
Log::debug(print_r('$productCategoryAttribute->getErrors() next - failed to save from create new product category attribute', true));
Log::debug(print_r($productCategoryAttribute->getErrors(), true));
}
if ($productCategoryAttributesTable->save($productCategoryAttribute, $saveOptions)) {
$this->Flash->success(__('The product category attribute has been saved.'));
return $this->redirect(['action' => 'index']);
}
Log::debug('failed to save new product category attribute errors next');
Log::debug(print_r('$productCategoryAttribute->getErrors()', true));
Log::debug(print_r($productCategoryAttribute->getErrors(), true));
$this->Flash->error(__('The product category attribute could not be saved. Please, try again.'));
}
$productCategories = $productCategoryAttributesTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all();
$this->set(compact('productCategoryAttribute', 'productCategories'));
}
return $this->redirect(['action' => 'index']);
}
Log::debug('failed to save new product category attribute errors next');
Log::debug(print_r('$productCategoryAttribute->getErrors()', true));
Log::debug(print_r($productCategoryAttribute->getErrors(), true));
$this->Flash->error(__('The product category attribute could not be saved. Please, try again.'));
}
$productCategories = $productCategoryAttributesTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all();
$this->set(compact('productCategoryAttribute', 'productCategories'));
}
/**
/**
* Edit method
*
* @param string|null $id Product Category Attribute id.
* @return Response|null|void Redirects on successful edit, renders view otherwise.
* @throws RecordNotFoundException When record not found.
* @return Response|null|void Redirects on successful edit, renders view otherwise.
*/
public function edit($id = null)
{
$productCategoryAttributesTable = $this->ProductCategoryAttributes;
$productCategoryAttribute = $productCategoryAttributesTable->get($id, contain: ['ProductCategoryAttributeOptions']);
if ($this->request->is(['patch', 'post', 'put'])) {
$postData = $this->request->getData();
$saveOptions = [
'associated' => ['ProductCategoryAttributeOptions'],
];
Log::debug(print_r('$postData', true));
Log::debug(print_r($postData, true));
public function edit($id = null) {
$productCategoryAttributesTable = $this->ProductCategoryAttributes;
$productCategoryAttribute = $productCategoryAttributesTable->get($id, contain: ['ProductCategoryAttributeOptions']);
if ($this->request->is(['patch', 'post', 'put'])) {
$postData = $this->request->getData();
$saveOptions = [
'associated' => ['ProductCategoryAttributeOptions'],
];
Log::debug(print_r('$postData', true));
Log::debug(print_r($postData, true));
// if ($this->request->getData('attribute_type_id') != ProductCategoryAttributeTypeId::Constrained) {
// $saveOptions['associated'] = [];
// $postData['product_category_attribute_options'] = [];
// }
Log::debug(print_r('$postData', true));
Log::debug(print_r($postData, true));
$productCategoryAttribute = $productCategoryAttributesTable->patchEntity($productCategoryAttribute, $postData, $saveOptions);
Log::debug(print_r('$postData', true));
Log::debug(print_r($postData, true));
$productCategoryAttribute = $productCategoryAttributesTable->patchEntity($productCategoryAttribute, $postData, $saveOptions);
if ($productCategoryAttributesTable->save($productCategoryAttribute, $saveOptions)) {
$this->Flash->success(__('The product category attribute has been saved.'));
if ($productCategoryAttributesTable->save($productCategoryAttribute, $saveOptions)) {
$this->Flash->success(__('The product category attribute has been saved.'));
return $this->redirect(['action' => 'index']);
}
Log::debug('failed to save product category attribute on edit errors next');
Log::debug(print_r('$productCategoryAttribute->getErrors()', true));
Log::debug(print_r($productCategoryAttribute->getErrors(), true));
$this->Flash->error(__('The product category attribute could not be saved. Please, try again.'));
}
$productCategories = $productCategoryAttributesTable->ProductCategories->find('list', limit: 200, keyField: 'internal_id', valueField: 'name')->all();
$this->set(compact('productCategoryAttribute', 'productCategories'));
}
return $this->redirect(['action' => 'index']);
}
Log::debug('failed to save product category attribute on edit errors next');
Log::debug(print_r('$productCategoryAttribute->getErrors()', true));
Log::debug(print_r($productCategoryAttribute->getErrors(), true));
$this->Flash->error(__('The product category attribute could not be saved. Please, try again.'));
}
$productCategories = $productCategoryAttributesTable->ProductCategories->find('list', limit: 200, keyField: 'internal_id', valueField: 'name')->all();
$this->set(compact('productCategoryAttribute', 'productCategories'));
}
/**
/**
* Delete method
*
* @param string|null $id Product Category Attribute id.
* @return Response|null Redirects to index.
* @throws RecordNotFoundException When record not found.
* @return Response|null Redirects to index.
*/
public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
public function delete($id = null) {
$this->request->allowMethod(['post', 'delete']);
$productCategoryAttributesTable = $this->ProductCategoryAttributes;
$productCategoryAttribute = $productCategoryAttributesTable->get($id);
if ($productCategoryAttributesTable->delete($productCategoryAttribute)) {
$this->Flash->success(__('The product category attribute has been deleted.'));
} else {
$this->Flash->error(__('The product category attribute could not be deleted. Please, try again.'));
}
$productCategoryAttributesTable = $this->ProductCategoryAttributes;
$productCategoryAttribute = $productCategoryAttributesTable->get($id);
if ($productCategoryAttributesTable->delete($productCategoryAttribute)) {
$this->Flash->success(__('The product category attribute has been deleted.'));
} else {
$this->Flash->error(__('The product category attribute could not be deleted. Please, try again.'));
}
return $this->redirect(['action' => 'index']);
}
return $this->redirect(['action' => 'index']);
}
/**
/**
* @return void
*/
public function form()
{
$productCategories = $this->ProductCategoryAttributes->getAllCategoryAttributesForCategoryId($this->request->getQuery('product_category_id', '-1'));
public function form() {
$productCategories = $this->ProductCategoryAttributes->getAllCategoryAttributesForCategoryId($this->request->getQuery('product_category_id', '-1'));
$this->set(compact('productCategories'));
}
$this->set(compact('productCategories'));
}
}
@@ -3,158 +3,150 @@ declare(strict_types=1);
namespace CakeProducts\Controller;
use Cake\Core\Configure;
use Cake\Log\Log;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
/**
* ProductCategoryVariants Controller
*
* @property \App\Model\Table\ProductCategoryVariantsTable $ProductCategoryVariants
*/
class ProductCategoryVariantsController extends AppController
{
/**
class ProductCategoryVariantsController extends AppController {
/**
* @return void
*/
public function initialize(): void
{
parent::initialize(); // TODO: Change the autogenerated stub
public function initialize(): void {
parent::initialize(); // TODO: Change the autogenerated stub
// $this->_defaultTable = 'CakeProducts.ProductCategoryVariants';
// $this->_tableConfigKey = 'CakeProducts.ProductCategoryVariants.table';
}
}
/**
/**
* Index method
*
* @return \Cake\Http\Response|null|void Renders view
*/
public function index()
{
$query = $this->ProductCategoryVariants->find()
->contain(['ProductCategories', 'Products', 'ProductCategoryVariantOptions']);
$productCategoryVariants = $this->paginate($query);
public function index() {
$query = $this->ProductCategoryVariants->find()
->contain(['ProductCategories', 'Products', 'ProductCategoryVariantOptions']);
$productCategoryVariants = $this->paginate($query);
$this->set(compact('productCategoryVariants'));
}
$this->set(compact('productCategoryVariants'));
}
/**
/**
* View method
*
* @param string|null $id Product Category Variant id.
* @return \Cake\Http\Response|null|void Renders view
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Renders view
*/
public function view($id = null)
{
$productCategoryVariant = $this->ProductCategoryVariants->get($id, contain: [
'ProductCategories',
'Products',
'ProductCategoryVariantOptions',
]);
$this->set(compact('productCategoryVariant'));
}
public function view($id = null) {
$productCategoryVariant = $this->ProductCategoryVariants->get($id, contain: [
'ProductCategories',
'Products',
'ProductCategoryVariantOptions',
]);
$this->set(compact('productCategoryVariant'));
}
/**
/**
* Add method
*
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
*/
public function add()
{
$productCategoryVariantsTable = $this->ProductCategoryVariants;
public function add() {
$productCategoryVariantsTable = $this->ProductCategoryVariants;
$productCategoryVariant = $productCategoryVariantsTable->newEmptyEntity();
if ($this->request->is('post')) {
$postData = $this->request->getData();
if ($this->request->getSession()->read('Auth.User.id')) {
$postData['created_by'] = $this->request->getSession()->read('Auth.User.id');
}
$saveOptions = [
'associated' => [
'ProductCategoryVariantOptions'
],
];
$productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $postData, $saveOptions);
if ($productCategoryVariantsTable->save($productCategoryVariant, $saveOptions)) {
$this->Flash->success(__('The product category variant has been saved.'));
$productCategoryVariant = $productCategoryVariantsTable->newEmptyEntity();
if ($this->request->is('post')) {
$postData = $this->request->getData();
if ($this->request->getSession()->read('Auth.User.id')) {
$postData['created_by'] = $this->request->getSession()->read('Auth.User.id');
}
$saveOptions = [
'associated' => [
'ProductCategoryVariantOptions',
],
];
$productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $postData, $saveOptions);
if ($productCategoryVariantsTable->save($productCategoryVariant, $saveOptions)) {
$this->Flash->success(__('The product category variant has been saved.'));
return $this->redirect(['action' => 'index']);
}
Log::debug('print_r($productCategoryVariant->getErrors(), true) failed to save in product category variants add');
Log::debug(print_r($productCategoryVariant->getErrors(), true));
$this->Flash->error(__('The product category variant could not be saved. Please, try again.'));
}
$productCategories = $productCategoryVariantsTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all();
$products = $productCategoryVariantsTable->Products->find('list')->all();
$this->set(compact('productCategoryVariant', 'productCategories', 'products'));
}
return $this->redirect(['action' => 'index']);
}
Log::debug('print_r($productCategoryVariant->getErrors(), true) failed to save in product category variants add');
Log::debug(print_r($productCategoryVariant->getErrors(), true));
$this->Flash->error(__('The product category variant could not be saved. Please, try again.'));
}
$productCategories = $productCategoryVariantsTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all();
$products = $productCategoryVariantsTable->Products->find('list')->all();
$this->set(compact('productCategoryVariant', 'productCategories', 'products'));
}
/**
/**
* Edit method
*
* @param string|null $id Product Category Variant id.
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
*/
public function edit($id = null)
{
$productCategoryVariantsTable = $this->ProductCategoryVariants;
$productCategoryVariant = $productCategoryVariantsTable->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) {
$postData = $this->request->getData();
public function edit($id = null) {
$productCategoryVariantsTable = $this->ProductCategoryVariants;
$productCategoryVariant = $productCategoryVariantsTable->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) {
$postData = $this->request->getData();
// if ($this->request->getSession()->read('Auth.User.id')) {
// $postData['created_by'] = $this->request->getSession()->read('Auth.User.id');
// }
$postData = $productCategoryVariant->is_system_variant ? ['product_category_variant_options' => $this->request->getData('product_category_variant_options')] : $postData;
$saveOptions = [
'fields' => $productCategoryVariant->is_system_variant ? [
'product_category_variant_options',
] : [
'name',
'product_category_id',
'enabled',
'product_category_variant_options',
],
'associated' => [
'ProductCategoryVariantOptions'
],
];
$productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $postData, $saveOptions);
$postData = $productCategoryVariant->is_system_variant ? ['product_category_variant_options' => $this->request->getData('product_category_variant_options')] : $postData;
$saveOptions = [
'fields' => $productCategoryVariant->is_system_variant ? [
'product_category_variant_options',
] : [
'name',
'product_category_id',
'enabled',
'product_category_variant_options',
],
'associated' => [
'ProductCategoryVariantOptions',
],
];
$productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $postData, $saveOptions);
// dd($postData);
if ($productCategoryVariantsTable->save($productCategoryVariant, $saveOptions)) {
$this->Flash->success(__('The product category variant has been saved.'));
if ($productCategoryVariantsTable->save($productCategoryVariant, $saveOptions)) {
$this->Flash->success(__('The product category variant has been saved.'));
return $this->redirect(['action' => 'index']);
}
return $this->redirect(['action' => 'index']);
}
// dd($productCategoryVariant->getErrors());
$this->Flash->error(__('The product category variant could not be saved. Please, try again.'));
}
$productCategories = $productCategoryVariantsTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all();
$products = isset($productCategoryVariant->product_category_id) ? $productCategoryVariantsTable->Products->find('list', limit: 200)->where(['product_category_id' => $productCategoryVariant->product_category_id])->all() : [];
$this->set(compact('productCategoryVariant', 'productCategories', 'products'));
}
$this->Flash->error(__('The product category variant could not be saved. Please, try again.'));
}
$productCategories = $productCategoryVariantsTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all();
$products = isset($productCategoryVariant->product_category_id) ? $productCategoryVariantsTable->Products->find('list', limit: 200)->where(['product_category_id' => $productCategoryVariant->product_category_id])->all() : [];
$this->set(compact('productCategoryVariant', 'productCategories', 'products'));
}
/**
/**
* Delete method
*
* @param string|null $id Product Category Variant id.
* @return \Cake\Http\Response|null Redirects to index.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null Redirects to index.
*/
public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$productCategoryVariantsTable = $this->ProductCategoryVariants;
public function delete($id = null) {
$this->request->allowMethod(['post', 'delete']);
$productCategoryVariantsTable = $this->ProductCategoryVariants;
$productCategoryVariant = $productCategoryVariantsTable->get($id);
if ($productCategoryVariantsTable->delete($productCategoryVariant)) {
$this->Flash->success(__('The product category variant has been deleted.'));
} else {
$this->Flash->error(__('The product category variant could not be deleted. Please, try again.'));
}
$productCategoryVariant = $productCategoryVariantsTable->get($id);
if ($productCategoryVariantsTable->delete($productCategoryVariant)) {
$this->Flash->success(__('The product category variant has been deleted.'));
} else {
$this->Flash->error(__('The product category variant could not be deleted. Please, try again.'));
}
return $this->redirect(['action' => 'index']);
}
return $this->redirect(['action' => 'index']);
}
}
+144 -152
View File
@@ -6,209 +6,201 @@ namespace CakeProducts\Controller;
use Cake\Core\Configure;
use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Http\Exception\ForbiddenException;
use Cake\Http\Response;
use Cake\Utility\Text;
use CakeProducts\Model\Table\ProductPhotosTable;
use Psr\Http\Message\UploadedFileInterface;
/**
* ProductPhotos Controller
*
* @property ProductPhotosTable $ProductPhotos
* @property \CakeProducts\Model\Table\ProductPhotosTable $ProductPhotos
*/
class ProductPhotosController extends AppController
{
/**
class ProductPhotosController extends AppController {
/**
* Index method
*
* @return Response|null|void Renders view
* @return \Cake\Http\Response|null|void Renders view
*/
public function index()
{
$query = $this->ProductPhotos->find()
->contain(['Products', 'ProductSkus', 'ProductCategories']);
$productPhotos = $this->paginate($query);
public function index() {
$query = $this->ProductPhotos->find()
->contain(['Products', 'ProductSkus', 'ProductCategories']);
$productPhotos = $this->paginate($query);
$this->set(compact('productPhotos'));
}
$this->set(compact('productPhotos'));
}
/**
/**
* View method
*
* @param string|null $id Product Photo id.
* @return Response|null|void Renders view
* @throws RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Renders view
*/
public function view($id = null)
{
$productPhoto = $this->ProductPhotos->get($id, contain: ['Products', 'ProductSkus', 'ProductCategories']);
$this->set(compact('productPhoto'));
}
public function view($id = null) {
$productPhoto = $this->ProductPhotos->get($id, contain: ['Products', 'ProductSkus', 'ProductCategories']);
$this->set(compact('productPhoto'));
}
/**
/**
* Add method
*
* @return Response|null|void Redirects on successful add, renders view otherwise.
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
*/
public function add()
{
$productPhotosTable = $this->ProductPhotos;
$productPhoto = $productPhotosTable->newEmptyEntity();
if ($this->request->is('post')) {
if (!$this->request->getData('photo')) {
$this->Flash->error('Photo is required. Nothing was uploaded. Please try again.');
$productCategory = $productPhoto->product_category_id ? $productPhotosTable->ProductCategories->find()->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null;
$productCatalogs = $productPhotosTable->ProductCategories->ProductCatalogs->find('list')->toArray();
$this->set(compact('productPhoto', 'productCatalogs', 'productCategory'));
public function add() {
$productPhotosTable = $this->ProductPhotos;
$productPhoto = $productPhotosTable->newEmptyEntity();
if ($this->request->is('post')) {
if (!$this->request->getData('photo')) {
$this->Flash->error('Photo is required. Nothing was uploaded. Please try again.');
$productCategory = $productPhoto->product_category_id ? $productPhotosTable->ProductCategories->find()->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null;
$productCatalogs = $productPhotosTable->ProductCategories->ProductCatalogs->find('list')->toArray();
$this->set(compact('productPhoto', 'productCatalogs', 'productCategory'));
return;
}
$uuid = Text::uuid();
$postData = $this->request->getData();
$postData['id'] = $uuid;
$baseDir = Configure::readOrFail('CakeProducts.photos.directory');
$path = '';
if ($this->request->getData('product_sku_id')) {
$productSku = $productPhotosTable->ProductSkus
->find()
->contain(['Products', 'Products.ProductCategories'])
->where([
'ProductSkus.id' => $this->request->getData('product_sku_id'),
])
->first();
$path = $productSku ? $productSku->product_id . DS . 'skus' . DS . $productSku->id : $path;
return;
}
$uuid = Text::uuid();
$postData = $this->request->getData();
$postData['id'] = $uuid;
$baseDir = Configure::readOrFail('CakeProducts.photos.directory');
$path = '';
if ($this->request->getData('product_sku_id')) {
$productSku = $productPhotosTable->ProductSkus
->find()
->contain(['Products', 'Products.ProductCategories'])
->where([
'ProductSkus.id' => $this->request->getData('product_sku_id'),
])
->first();
$path = $productSku ? $productSku->product_id . DS . 'skus' . DS . $productSku->id : $path;
$postData['product_id'] = $productSku->product->id ?? null;
$postData['product_category_id'] = $productSku->product->product_category->internal_id ?? null;
} else if ($this->request->getData('product_id')) {
$product = $productPhotosTable->Products
->find()
->contain(['ProductCategories'])
->where([
'Products.id' => $this->request->getData('product_id'),
])
->first();
$path = $product ? $product->id : $path;
$postData['product_category_id'] = $product->product_category->internal_id ?? null;
$postData['product_id'] = $productSku->product->id ?? null;
$postData['product_category_id'] = $productSku->product->product_category->internal_id ?? null;
} else if ($this->request->getData('product_id')) {
$product = $productPhotosTable->Products
->find()
->contain(['ProductCategories'])
->where([
'Products.id' => $this->request->getData('product_id'),
])
->first();
$path = $product ? $product->id : $path;
$postData['product_category_id'] = $product->product_category->internal_id ?? null;
} else if ($this->request->getData('product_category_id')) {
$categoryId = $this->request->getData('product_category_id');
// @link https://developer.wordpress.org/reference/functions/wp_is_uuid/
$regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/';
$field = preg_match($regex, $categoryId) ? 'ProductCategories.internal_id' : 'ProductCategories.id';
$productCategoryPosted = $productPhotosTable->ProductCategories
->find()
->where([
$field => $categoryId,
])
->first();
$postData['product_category_id'] = $productCategoryPosted->internal_id ?? null;
$path = $productCategoryPosted ? 'categories' : $path;
}
/**
* @var UploadedFileInterface $photoObject
} else if ($this->request->getData('product_category_id')) {
$categoryId = $this->request->getData('product_category_id');
// @link https://developer.wordpress.org/reference/functions/wp_is_uuid/
$regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/';
$field = preg_match($regex, $categoryId) ? 'ProductCategories.internal_id' : 'ProductCategories.id';
$productCategoryPosted = $productPhotosTable->ProductCategories
->find()
->where([
$field => $categoryId,
])
->first();
$postData['product_category_id'] = $productCategoryPosted->internal_id ?? null;
$path = $productCategoryPosted ? 'categories' : $path;
}
/**
* @var \Psr\Http\Message\UploadedFileInterface $photoObject
*/
$photoObject = $this->request->getData('photo');
$ext = substr(strtolower($photoObject->getClientFilename()), -4);
$ext = str_starts_with($ext, '.') ? substr($ext, 1) : $ext;
$allowedFileTypes = ['png', 'jpeg', 'jpg'];
if (!in_array($ext, $allowedFileTypes)) {
throw new ForbiddenException('Invalid file type. Only PNG and JPG types are allowed.');
}
$photoObject = $this->request->getData('photo');
$ext = substr(strtolower($photoObject->getClientFilename()), -4);
$ext = str_starts_with($ext, '.') ? substr($ext, 1) : $ext;
$allowedFileTypes = ['png', 'jpeg', 'jpg'];
if (!in_array($ext, $allowedFileTypes)) {
throw new ForbiddenException('Invalid file type. Only PNG and JPG types are allowed.');
}
$fullPath = $baseDir . $path;
if (!file_exists($fullPath)) {
if (!mkdir($fullPath, 0777, true)) {
throw new ForbiddenException('Failed to create the required folders. Please check the folder permissions and try again.');
}
}
$destination = $fullPath . DS . $uuid . '.' . $ext;
$fullPath = $baseDir . $path;
if (!file_exists($fullPath)) {
if (!mkdir($fullPath, 0777, true)) {
throw new ForbiddenException('Failed to create the required folders. Please check the folder permissions and try again.');
}
}
$destination = $fullPath . DS . $uuid . '.' . $ext;
// Existing files with the same name will be replaced.
$photoObject->moveTo($destination);
if (!file_exists($destination)) {
throw new ForbiddenException('Failed to move the uploaded image to the appropriate folder. Please try again.');
}
// Existing files with the same name will be replaced.
$photoObject->moveTo($destination);
if (!file_exists($destination)) {
throw new ForbiddenException('Failed to move the uploaded image to the appropriate folder. Please try again.');
}
$postData['photo_dir'] = $path;
$postData['photo_filename'] = $uuid . '.' . $ext;
$postData['photo_dir'] = $path;
$postData['photo_filename'] = $uuid . '.' . $ext;
// dd($postData);
$productPhoto = $productPhotosTable->patchEntity($productPhoto, $postData);
if ($productPhotosTable->save($productPhoto)) {
$this->Flash->success(__('The product photo has been saved.'));
$productPhoto = $productPhotosTable->patchEntity($productPhoto, $postData);
if ($productPhotosTable->save($productPhoto)) {
$this->Flash->success(__('The product photo has been saved.'));
return $this->redirect(['action' => 'index']);
}
return $this->redirect(['action' => 'index']);
}
// dd($productPhoto->getErrors());
$this->Flash->error(__('The product photo could not be saved. Please, try again.'));
}
$productCategory = $productPhoto->product_category_id ? $productPhotosTable->ProductCategories->find()->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null;
$productCatalogs = $productPhotosTable->ProductCategories->ProductCatalogs->find('list')->toArray();
$this->set(compact('productPhoto', 'productCatalogs', 'productCategory'));
}
$this->Flash->error(__('The product photo could not be saved. Please, try again.'));
}
$productCategory = $productPhoto->product_category_id ? $productPhotosTable->ProductCategories->find()->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null;
$productCatalogs = $productPhotosTable->ProductCategories->ProductCatalogs->find('list')->toArray();
$this->set(compact('productPhoto', 'productCatalogs', 'productCategory'));
}
/**
/**
* Edit method
*
* @param string|null $id Product Photo id.
* @return Response|null|void Redirects on successful edit, renders view otherwise.
* @throws RecordNotFoundException When record not found.
* @return Response|null|void Redirects on successful edit, renders view otherwise.
*/
public function edit($id = null)
{
$productPhotosTable = $this->ProductPhotos;
$productPhoto = $productPhotosTable->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) {
$postData = $this->request->getData();
public function edit($id = null) {
$productPhotosTable = $this->ProductPhotos;
$productPhoto = $productPhotosTable->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) {
$postData = $this->request->getData();
$productPhoto = $productPhotosTable->patchEntity($productPhoto, $postData);
if ($productPhotosTable->save($productPhoto)) {
$this->Flash->success(__('The product photo has been saved.'));
$productPhoto = $productPhotosTable->patchEntity($productPhoto, $postData);
if ($productPhotosTable->save($productPhoto)) {
$this->Flash->success(__('The product photo has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The product photo could not be saved. Please, try again.'));
}
$products = $productPhotosTable->Products->find('list', limit: 200)->all();
$productSkus = $productPhotosTable->ProductSkus->find('list', limit: 200)->all();
$this->set(compact('productPhoto', 'products', 'productSkus'));
}
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The product photo could not be saved. Please, try again.'));
}
$products = $productPhotosTable->Products->find('list', limit: 200)->all();
$productSkus = $productPhotosTable->ProductSkus->find('list', limit: 200)->all();
$this->set(compact('productPhoto', 'products', 'productSkus'));
}
/**
/**
* Delete method
*
* @param string|null $id Product Photo id.
* @return Response|null Redirects to index.
* @throws RecordNotFoundException When record not found.
* @return Response|null Redirects to index.
*/
public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$productPhotosTable = $this->ProductPhotos;
public function delete($id = null) {
$this->request->allowMethod(['post', 'delete']);
$productPhotosTable = $this->ProductPhotos;
$productPhoto = $productPhotosTable->get($id);
if ($productPhotosTable->delete($productPhoto)) {
$this->Flash->success(__('The product photo has been deleted.'));
} else {
$this->Flash->error(__('The product photo could not be deleted. Please, try again.'));
}
$productPhoto = $productPhotosTable->get($id);
if ($productPhotosTable->delete($productPhoto)) {
$this->Flash->success(__('The product photo has been deleted.'));
} else {
$this->Flash->error(__('The product photo could not be deleted. Please, try again.'));
}
return $this->redirect(['action' => 'index']);
}
return $this->redirect(['action' => 'index']);
}
/**
/**
* @param $id
* @return Response
*/
public function image($id = null)
{
$productPhoto = $this->ProductPhotos->get($id);
public function image($id = null) {
$productPhoto = $this->ProductPhotos->get($id);
$fullPath = Configure::readOrFail('CakeProducts.photos.directory') . $productPhoto->photo_dir . DS . $productPhoto->photo_filename;
$fullPath = Configure::readOrFail('CakeProducts.photos.directory') . $productPhoto->photo_dir . DS . $productPhoto->photo_filename;
return $this->response->withFile($fullPath, [
'download' => $this->request->getQuery('download', false) === '1',
]);
}
return $this->response->withFile($fullPath, [
'download' => $this->request->getQuery('download', false) === '1'
]);
}
}
+171 -176
View File
@@ -12,240 +12,235 @@ use function BenTools\CartesianProduct\combinations;
*
* @property \CakeProducts\Model\Table\ProductSkusTable $ProductSkus
*/
class ProductSkusController extends AppController
{
/**
class ProductSkusController extends AppController {
/**
* @return void
*/
public function initialize(): void
{
parent::initialize(); // TODO: Change the autogenerated stub
public function initialize(): void {
parent::initialize(); // TODO: Change the autogenerated stub
// $this->_defaultTable = 'CakeProducts.ProductSkus';
// $this->_tableConfigKey = 'CakeProducts.ProductSkus.table';
}
}
/**
/**
* Index method
*
* @return \Cake\Http\Response|null|void Renders view
*/
public function index()
{
$query = $this->ProductSkus->find()
->contain(['Products']);
$productSkus = $this->paginate($query);
public function index() {
$query = $this->ProductSkus->find()
->contain(['Products']);
$productSkus = $this->paginate($query);
$this->set(compact('productSkus'));
}
$this->set(compact('productSkus'));
}
/**
/**
* View method
*
* @param string|null $id Product Skus id.
* @return \Cake\Http\Response|null|void Renders view
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Renders view
*/
public function view($id = null)
{
$productSku = $this->ProductSkus->get($id, contain: [
'Products',
'ProductSkuVariantValues',
'ProductSkuVariantValues.ProductVariants',
'ProductSkuVariantValues.ProductVariants.ProductCategoryVariants',
'ProductSkuVariantValues.ProductCategoryVariantOptions',
]);
$this->set(compact('productSku'));
}
public function view($id = null) {
$productSku = $this->ProductSkus->get($id, contain: [
'Products',
'ProductSkuVariantValues',
'ProductSkuVariantValues.ProductVariants',
'ProductSkuVariantValues.ProductVariants.ProductCategoryVariants',
'ProductSkuVariantValues.ProductCategoryVariantOptions',
]);
$this->set(compact('productSku'));
}
/**
/**
* Add method
*
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
*/
public function add($productId = null)
{
$toGetCartesianProductsFrom = [];
$productSkus = [];
$product = $this->ProductSkus->Products->get($productId, contain: [
'ProductSkus',
'ProductSkus.ProductSkuVariantValues',
'ProductVariants',
'ProductVariants.ProductCategoryVariants',
'ProductVariants.ProductCategoryVariants.ProductCategoryVariantOptions',
]);
$existingProductSkus = Hash::combine($product->product_skus ?? [], '{n}.id', '{n}');
$existingProductSkusForMapping = Hash::combine($product->product_skus ?? [], '{n}.id', '{n}.product_sku_variant_values');
$existingSkusForCartesianComparison = [];
foreach ($existingProductSkusForMapping as $existingProductSkuId => $existingProductSku) {
$existingSkusForCartesianComparison[$existingProductSkuId] = Hash::combine($existingProductSku, '{n}.product_variant_id', '{n}.product_category_variant_option_id');
}
$productVariants = isset($product->product_variants) ? $product->product_variants : [];
public function add($productId = null) {
$toGetCartesianProductsFrom = [];
$productSkus = [];
$product = $this->ProductSkus->Products->get($productId, contain: [
'ProductSkus',
'ProductSkus.ProductSkuVariantValues',
'ProductVariants',
'ProductVariants.ProductCategoryVariants',
'ProductVariants.ProductCategoryVariants.ProductCategoryVariantOptions',
]);
$existingProductSkus = Hash::combine($product->product_skus ?? [], '{n}.id', '{n}');
$existingProductSkusForMapping = Hash::combine($product->product_skus ?? [], '{n}.id', '{n}.product_sku_variant_values');
$existingSkusForCartesianComparison = [];
foreach ($existingProductSkusForMapping as $existingProductSkuId => $existingProductSku) {
$existingSkusForCartesianComparison[$existingProductSkuId] = Hash::combine($existingProductSku, '{n}.product_variant_id', '{n}.product_category_variant_option_id');
}
$productVariants = $product->product_variants ?? [];
// dd($productVariants);
$productVariantsMapping = Hash::combine($productVariants, '{n}.product_category_variant.id', '{n}.id');
$productCategoryVariants = Hash::extract($productVariants, '{n}.product_category_variant');
$productVariantsMapping = Hash::combine($productVariants, '{n}.product_category_variant.id', '{n}.id');
$productCategoryVariants = Hash::extract($productVariants, '{n}.product_category_variant');
// dd($productCategoryVariants);
$optionMapping = Hash::combine($productCategoryVariants, '{n}.product_category_variant_options.{n}.id', '{n}.product_category_variant_options.{n}.variant_value');
$optionMapping = Hash::combine($productCategoryVariants, '{n}.product_category_variant_options.{n}.id', '{n}.product_category_variant_options.{n}.variant_value');
// dd($optionMapping);
$variantNameMapping = Hash::combine($productCategoryVariants, '{n}.id', '{n}.name');
$variantNameMapping = Hash::combine($productCategoryVariants, '{n}.id', '{n}.name');
// dd($variantNameMapping);
foreach ($productCategoryVariants as $productCategoryVariant) {
$options = Hash::extract($productCategoryVariant['product_category_variant_options'] ?? [], '{n}.id');
$toGetCartesianProductsFrom[$productVariantsMapping[$productCategoryVariant['id']]] = $options;
}
foreach ($productCategoryVariants as $productCategoryVariant) {
$options = Hash::extract($productCategoryVariant['product_category_variant_options'] ?? [], '{n}.id');
$toGetCartesianProductsFrom[$productVariantsMapping[$productCategoryVariant['id']]] = $options;
}
// dd($toGetCartesianProductsFrom);
$numSkusToAdd = count(combinations($toGetCartesianProductsFrom));
for ($i = 0; $i < $numSkusToAdd; $i++) {
$productSkus[$i] = $this->ProductSkus->newEmptyEntity();
}
$this->set(compact(
'product',
'productSkus',
'productCategoryVariants',
'productVariantsMapping',
'toGetCartesianProductsFrom',
'optionMapping',
'variantNameMapping',
'numSkusToAdd',
'existingProductSkus',
'existingSkusForCartesianComparison'
));
$numSkusToAdd = count(combinations($toGetCartesianProductsFrom));
for ($i = 0; $i < $numSkusToAdd; $i++) {
$productSkus[$i] = $this->ProductSkus->newEmptyEntity();
}
$this->set(compact(
'product',
'productSkus',
'productCategoryVariants',
'productVariantsMapping',
'toGetCartesianProductsFrom',
'optionMapping',
'variantNameMapping',
'numSkusToAdd',
'existingProductSkus',
'existingSkusForCartesianComparison',
));
if ($this->request->is('post')) {
$postedSkus = $this->request->getData();
$saveOptions = [
'fields' => [
'product_id',
'sku',
'barcode',
'price',
'cost',
'product_sku_variant_values',
'created',
'modified',
'enabled',
'default_sku',
],
'associated' => [
'ProductSkuVariantValues' => [
'fields' => [
'product_variant_id',
'product_category_variant_option_id',
],
],
],
];
$finalPostData = [];
$postedSkus = Hash::insert($postedSkus, '{n}.product_id', $productId);
if ($this->request->is('post')) {
$postedSkus = $this->request->getData();
$saveOptions = [
'fields' => [
'product_id',
'sku',
'barcode',
'price',
'cost',
'product_sku_variant_values',
'created',
'modified',
'enabled',
'default_sku',
],
'associated' => [
'ProductSkuVariantValues' => [
'fields' => [
'product_variant_id',
'product_category_variant_option_id',
],
],
],
];
$finalPostData = [];
$postedSkus = Hash::insert($postedSkus, '{n}.product_id', $productId);
foreach ($postedSkus as $postedSkuCnt => $postedSku) {
if (!isset($postedSku['sku']) || !$postedSku['sku']) {
unset($productSkus[$postedSkuCnt]);
foreach ($postedSkus as $postedSkuCnt => $postedSku) {
if (!isset($postedSku['sku']) || !$postedSku['sku']) {
unset($productSkus[$postedSkuCnt]);
continue;
}
$finalPostData[$postedSkuCnt] = $postedSku;
}
if (!$productSkus || !$postedSkus) {
$this->Flash->error('Nothing to save! Add at least one SKU next time.');
continue;
}
$finalPostData[$postedSkuCnt] = $postedSku;
}
if (!$productSkus || !$postedSkus) {
$this->Flash->error('Nothing to save! Add at least one SKU next time.');
return;
}
return;
}
// dd($finalPostData);
$productSkus = $this->ProductSkus->patchEntities($productSkus, $finalPostData, $saveOptions);
$errors = [];
$successes = [];
foreach ($productSkus as $productSkuToSave) {
$productSkus = $this->ProductSkus->patchEntities($productSkus, $finalPostData, $saveOptions);
$errors = [];
$successes = [];
foreach ($productSkus as $productSkuToSave) {
// dd($productSkuToSave);
if (!$this->ProductSkus->save($productSkuToSave, $saveOptions)) {
Log::debug(print_r('$productSkuToSave->getErrors()', true));
Log::debug(print_r($productSkuToSave->getErrors(), true));
dd($productSkuToSave->getErrors());
continue;
}
$successes[] = $productSkuToSave;
}
if (!$this->ProductSkus->save($productSkuToSave, $saveOptions)) {
Log::debug(print_r('$productSkuToSave->getErrors()', true));
Log::debug(print_r($productSkuToSave->getErrors(), true));
dd($productSkuToSave->getErrors());
if ($successes) {
$this->Flash->success(__(count($successes) . ' New SKUs have been saved.'));
continue;
}
$successes[] = $productSkuToSave;
}
return $this->redirect(['action' => 'index']);
}
if ($successes) {
$this->Flash->success(__(count($successes) . ' New SKUs have been saved.'));
$this->Flash->error(__('The product SKU(s) could not be saved. Please, try again.'));
}
$this->set(compact(
'productSkus'
));
}
return $this->redirect(['action' => 'index']);
}
/**
$this->Flash->error(__('The product SKU(s) could not be saved. Please, try again.'));
}
$this->set(compact(
'productSkus',
));
}
/**
* Edit method
*
* @param string|null $id Product Skus id.
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
*/
public function edit($id = null)
{
$productSku = $this->ProductSkus->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) {
$postData = $this->request->getData();
$saveOptions = [
'associated' => [],
];
// Log::debug(print_r('$postData', true));
public function edit($id = null) {
$productSku = $this->ProductSkus->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) {
$postData = $this->request->getData();
$saveOptions = [
'associated' => [],
];
// Log::debug(print_r('$postData', true));
// Log::debug(print_r($postData, true));
// Log::debug(print_r('$saveOptions', true));
// Log::debug(print_r($saveOptions, true));
$productSku = $this->ProductSkus->patchEntity($productSku, $postData, $saveOptions);
if ($this->ProductSkus->save($productSku)) {
$this->Flash->success(__('The product skus has been saved.'));
$productSku = $this->ProductSkus->patchEntity($productSku, $postData, $saveOptions);
if ($this->ProductSkus->save($productSku)) {
$this->Flash->success(__('The product skus has been saved.'));
return $this->redirect(['action' => 'index']);
}
Log::debug(print_r('$productSku->getErrors() next - failed in productSkus/edit', true));
Log::debug(print_r($productSku->getErrors(), true));
$this->Flash->error(__('The product skus could not be saved. Please, try again.'));
}
$products = $this->ProductSkus->Products->find('list', limit: 200)->all();
$this->set(compact('productSku', 'products'));
}
return $this->redirect(['action' => 'index']);
}
Log::debug(print_r('$productSku->getErrors() next - failed in productSkus/edit', true));
Log::debug(print_r($productSku->getErrors(), true));
$this->Flash->error(__('The product skus could not be saved. Please, try again.'));
}
$products = $this->ProductSkus->Products->find('list', limit: 200)->all();
$this->set(compact('productSku', 'products'));
}
/**
/**
* Delete method
*
* @param string|null $id Product Skus id.
* @return \Cake\Http\Response|null Redirects to index.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null Redirects to index.
*/
public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$productSku = $this->ProductSkus->get($id);
if ($this->ProductSkus->delete($productSku)) {
$this->Flash->success(__('The product skus has been deleted.'));
} else {
$this->Flash->error(__('The product skus could not be deleted. Please, try again.'));
}
public function delete($id = null) {
$this->request->allowMethod(['post', 'delete']);
$productSku = $this->ProductSkus->get($id);
if ($this->ProductSkus->delete($productSku)) {
$this->Flash->success(__('The product skus has been deleted.'));
} else {
$this->Flash->error(__('The product skus could not be deleted. Please, try again.'));
}
return $this->redirect(['action' => 'index']);
}
return $this->redirect(['action' => 'index']);
}
/**
/**
* @return \Cake\Http\Response|null|void Renders view
*/
public function select()
{
$productSkus = $this->ProductSkus
->find('list')
->where(['product_id' => $this->request->getQuery('product_id', '-1')])
->orderBy(['sku'])
->toArray();
public function select() {
$productSkus = $this->ProductSkus
->find('list')
->where(['product_id' => $this->request->getQuery('product_id', '-1')])
->orderBy(['sku'])
->toArray();
$this->set(compact('productSkus'));
}
$this->set(compact('productSkus'));
}
}
+69 -73
View File
@@ -10,109 +10,105 @@ use Cake\Log\Log;
*
* @property \App\Model\Table\ProductVariantsTable $ProductVariants
*/
class ProductVariantsController extends AppController
{
/**
class ProductVariantsController extends AppController {
/**
* Index method
*
* @return \Cake\Http\Response|null|void Renders view
*/
public function index()
{
$query = $this->ProductVariants->find()
->contain(['ProductCategoryVariants', 'Products']);
$productVariants = $this->paginate($query);
public function index() {
$query = $this->ProductVariants->find()
->contain(['ProductCategoryVariants', 'Products']);
$productVariants = $this->paginate($query);
$this->set(compact('productVariants'));
}
$this->set(compact('productVariants'));
}
/**
/**
* View method
*
* @param string|null $id Product Variant id.
* @return \Cake\Http\Response|null|void Renders view
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Renders view
*/
public function view($id = null)
{
$productVariant = $this->ProductVariants->get($id, contain: ['ProductCategoryVariants', 'Products']);
$this->set(compact('productVariant'));
}
public function view($id = null) {
$productVariant = $this->ProductVariants->get($id, contain: ['ProductCategoryVariants', 'Products']);
$this->set(compact('productVariant'));
}
/**
/**
* Add method
*
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
*/
public function add($productId)
{
$product = $this->ProductVariants->Products->get($productId);
$productVariant = $this->ProductVariants->newEmptyEntity();
if ($this->request->is('post')) {
$saveOptions = [];
$postData = $this->request->getData();
$productCategoryVariant = $this->ProductVariants->ProductCategoryVariants->get($this->request->getData('product_category_variant_id', '-1'));
$postData['name'] = $productCategoryVariant->name;
$postData['product_id'] = $productId;
$productVariant = $this->ProductVariants->patchEntity($productVariant, $postData);
if ($this->ProductVariants->save($productVariant)) {
$this->Flash->success(__('The product variant has been saved.'));
public function add($productId) {
$product = $this->ProductVariants->Products->get($productId);
$productVariant = $this->ProductVariants->newEmptyEntity();
if ($this->request->is('post')) {
$saveOptions = [];
$postData = $this->request->getData();
$productCategoryVariant = $this->ProductVariants->ProductCategoryVariants->get($this->request->getData('product_category_variant_id', '-1'));
$postData['name'] = $productCategoryVariant->name;
$postData['product_id'] = $productId;
$productVariant = $this->ProductVariants->patchEntity($productVariant, $postData);
if ($this->ProductVariants->save($productVariant)) {
$this->Flash->success(__('The product variant has been saved.'));
return $this->redirect(['action' => 'index']);
}
return $this->redirect(['action' => 'index']);
}
Log::debug(print_r('$productVariant->getErrors()', true));
Log::debug(print_r($productVariant->getErrors(), true));
$this->Flash->error(__('The product variant could not be saved. Please, try again.'));
}
$productCategoryVariants = $this->ProductVariants->ProductCategoryVariants
->find('list', limit: 200)
->where(['product_category_id' => $product->product_category_id])
->toArray();
$this->set(compact('productVariant', 'productCategoryVariants', 'product'));
}
Log::debug(print_r('$productVariant->getErrors()', true));
Log::debug(print_r($productVariant->getErrors(), true));
$this->Flash->error(__('The product variant could not be saved. Please, try again.'));
}
$productCategoryVariants = $this->ProductVariants->ProductCategoryVariants
->find('list', limit: 200)
->where(['product_category_id' => $product->product_category_id])
->toArray();
$this->set(compact('productVariant', 'productCategoryVariants', 'product'));
}
/**
/**
* Edit method
*
* @param string|null $id Product Variant id.
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
*/
public function edit($id = null)
{
$productVariant = $this->ProductVariants->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) {
$productVariant = $this->ProductVariants->patchEntity($productVariant, $this->request->getData());
if ($this->ProductVariants->save($productVariant)) {
$this->Flash->success(__('The product variant has been saved.'));
public function edit($id = null) {
$productVariant = $this->ProductVariants->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) {
$productVariant = $this->ProductVariants->patchEntity($productVariant, $this->request->getData());
if ($this->ProductVariants->save($productVariant)) {
$this->Flash->success(__('The product variant has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The product variant could not be saved. Please, try again.'));
}
$productCategoryVariants = $this->ProductVariants->ProductCategoryVariants->find('list', limit: 200)->all();
$products = $this->ProductVariants->Products->find('list', limit: 200)->all();
$this->set(compact('productVariant', 'productCategoryVariants', 'products'));
}
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The product variant could not be saved. Please, try again.'));
}
$productCategoryVariants = $this->ProductVariants->ProductCategoryVariants->find('list', limit: 200)->all();
$products = $this->ProductVariants->Products->find('list', limit: 200)->all();
$this->set(compact('productVariant', 'productCategoryVariants', 'products'));
}
/**
/**
* Delete method
*
* @param string|null $id Product Variant id.
* @return \Cake\Http\Response|null Redirects to index.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null Redirects to index.
*/
public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$productVariant = $this->ProductVariants->get($id);
if ($this->ProductVariants->delete($productVariant)) {
$this->Flash->success(__('The product variant has been deleted.'));
} else {
$this->Flash->error(__('The product variant could not be deleted. Please, try again.'));
}
public function delete($id = null) {
$this->request->allowMethod(['post', 'delete']);
$productVariant = $this->ProductVariants->get($id);
if ($this->ProductVariants->delete($productVariant)) {
$this->Flash->success(__('The product variant has been deleted.'));
} else {
$this->Flash->error(__('The product variant could not be deleted. Please, try again.'));
}
return $this->redirect(['action' => 'index']);
}
return $this->redirect(['action' => 'index']);
}
}
+150 -159
View File
@@ -3,211 +3,202 @@ declare(strict_types=1);
namespace CakeProducts\Controller;
use Cake\Core\Configure;
use Cake\Log\Log;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
/**
* Products Controller
*
* @property \CakeProducts\Model\Table\ProductsTable $Products
*/
class ProductsController extends AppController
{
/**
class ProductsController extends AppController {
/**
* @return void
*/
public function initialize(): void
{
parent::initialize(); // TODO: Change the autogenerated stub
public function initialize(): void {
parent::initialize(); // TODO: Change the autogenerated stub
// $this->_defaultTable = 'CakeProducts.Products';
// $this->_tableConfigKey = 'CakeProducts.Products.table';
}
}
/**
/**
* Index method
*
* @return \Cake\Http\Response|null|void Renders view
*/
public function index()
{
$query = $this->Products->find()
->contain(['ProductCategories']);
$products = $this->paginate($query);
public function index() {
$query = $this->Products->find()
->contain(['ProductCategories']);
$products = $this->paginate($query);
$this->set(compact('products'));
}
$this->set(compact('products'));
}
/**
/**
* View method
*
* @param string|null $id Product id.
* @return \Cake\Http\Response|null|void Renders view
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Renders view
*/
public function view($id = null)
{
$product = $this->Products->get($id, contain: [
'ProductCategories',
'ProductAttributes',
'ProductAttributes.ProductCategoryAttributes',
'ProductAttributes.ProductCategoryAttributeOptions',
'ProductVariants',
'ProductVariants.ProductCategoryVariants',
'ProductVariants.ProductCategoryVariants.ProductCategoryVariantOptions',
'ProductSkus',
'ProductPhotos',
]);
$this->set(compact('product'));
}
public function view($id = null) {
$product = $this->Products->get($id, contain: [
'ProductCategories',
'ProductAttributes',
'ProductAttributes.ProductCategoryAttributes',
'ProductAttributes.ProductCategoryAttributeOptions',
'ProductVariants',
'ProductVariants.ProductCategoryVariants',
'ProductVariants.ProductCategoryVariants.ProductCategoryVariantOptions',
'ProductSkus',
'ProductPhotos',
]);
$this->set(compact('product'));
}
/**
/**
* Add method
*
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
*/
public function add()
{
$productsTable = $this->Products;
$product = $productsTable->newEmptyEntity();
if ($this->request->is('post')) {
$postData = $this->request->getData();
$saveOptions = [
'associated' => ['ProductAttributes'],
];
Log::debug(print_r('$postData', true));
Log::debug(print_r($postData, true));
Log::debug(print_r('$saveOptions', true));
Log::debug(print_r($saveOptions, true));
$productVariantsData = [];
if (isset($postData['product_variants']) && $postData['product_variants']) {
foreach ($postData['product_variants'] as $postedProductVariant) {
if (!isset($postedProductVariant['enabled']) || !$postedProductVariant['enabled'] || !isset($postedProductVariant['product_category_variant_id'])) {
continue;
}
$existingVariant = $this->Products->ProductCategories->ProductCategoryVariants->get($postedProductVariant['product_category_variant_id'], contain: ['ProductCategoryVariantOptions']);
$optionsData = [];
foreach ($existingVariant->product_category_variant_options as $existingOption) {
$optionsData[] = [
'variant_value' => $existingOption->variant_value,
'variant_label' => $existingOption->variant_label ?? null,
'enabled' => $existingOption->enabled,
];
}
$tmpVariantData = [
'name' => $existingVariant->name,
'product_category_variant_id' => $postedProductVariant['product_category_variant_id'],
'enabled' => true,
'product_category_variant_options' => $optionsData,
];
$productVariantsData[] = $tmpVariantData;
}
}
if ($productVariantsData) {
$saveOptions['fields'] = [
'name',
'product_category_id',
'product_type_id',
'product_attributes',
'product_category_variants'
];
$saveOptions['associated']['ProductCategoryVariants'] = [
'fields' => [
'name',
'enabled',
'product_category_variant_options',
]
];
$saveOptions['associated'][] = 'ProductCategoryVariants.ProductCategoryVariantOptions';
$postData['product_category_variants'] = $productVariantsData;
}
$product = $productsTable->patchEntity($product, $postData, $saveOptions);
if ($productsTable->save($product, $saveOptions)) {
$this->Flash->success(__('The product has been saved.'));
public function add() {
$productsTable = $this->Products;
$product = $productsTable->newEmptyEntity();
if ($this->request->is('post')) {
$postData = $this->request->getData();
$saveOptions = [
'associated' => ['ProductAttributes'],
];
Log::debug(print_r('$postData', true));
Log::debug(print_r($postData, true));
Log::debug(print_r('$saveOptions', true));
Log::debug(print_r($saveOptions, true));
$productVariantsData = [];
if (isset($postData['product_variants']) && $postData['product_variants']) {
foreach ($postData['product_variants'] as $postedProductVariant) {
if (!isset($postedProductVariant['enabled']) || !$postedProductVariant['enabled'] || !isset($postedProductVariant['product_category_variant_id'])) {
continue;
}
$existingVariant = $this->Products->ProductCategories->ProductCategoryVariants->get($postedProductVariant['product_category_variant_id'], contain: ['ProductCategoryVariantOptions']);
$optionsData = [];
foreach ($existingVariant->product_category_variant_options as $existingOption) {
$optionsData[] = [
'variant_value' => $existingOption->variant_value,
'variant_label' => $existingOption->variant_label ?? null,
'enabled' => $existingOption->enabled,
];
}
$tmpVariantData = [
'name' => $existingVariant->name,
'product_category_variant_id' => $postedProductVariant['product_category_variant_id'],
'enabled' => true,
'product_category_variant_options' => $optionsData,
];
$productVariantsData[] = $tmpVariantData;
}
}
if ($productVariantsData) {
$saveOptions['fields'] = [
'name',
'product_category_id',
'product_type_id',
'product_attributes',
'product_category_variants',
];
$saveOptions['associated']['ProductCategoryVariants'] = [
'fields' => [
'name',
'enabled',
'product_category_variant_options',
],
];
$saveOptions['associated'][] = 'ProductCategoryVariants.ProductCategoryVariantOptions';
$postData['product_category_variants'] = $productVariantsData;
}
$product = $productsTable->patchEntity($product, $postData, $saveOptions);
if ($productsTable->save($product, $saveOptions)) {
$this->Flash->success(__('The product has been saved.'));
return $this->redirect(['action' => 'index']);
}
Log::debug(print_r('$product->getErrors() next - failed in products/add', true));
Log::debug(print_r($product->getErrors(), true));
$this->Flash->error(__('The product could not be saved. Please, try again.'));
}
$productCategory = $product->product_category_id ? $productsTable->ProductCategories->find()->where(['internal_id' => $product->product_category_id])->first() : null;
$productCatalogs = $productsTable->ProductCategories->ProductCatalogs->find('list')->toArray();
$this->set(compact('product', 'productCatalogs', 'productCategory'));
}
return $this->redirect(['action' => 'index']);
}
Log::debug(print_r('$product->getErrors() next - failed in products/add', true));
Log::debug(print_r($product->getErrors(), true));
$this->Flash->error(__('The product could not be saved. Please, try again.'));
}
$productCategory = $product->product_category_id ? $productsTable->ProductCategories->find()->where(['internal_id' => $product->product_category_id])->first() : null;
$productCatalogs = $productsTable->ProductCategories->ProductCatalogs->find('list')->toArray();
$this->set(compact('product', 'productCatalogs', 'productCategory'));
}
/**
/**
* Edit method
*
* @param string|null $id Product id.
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
*/
public function edit($id = null)
{
$productsTable = $this->Products;
$product = $productsTable->get($id, contain: [
'ProductAttributes',
'ProductAttributes.ProductCategoryAttributes',
'ProductAttributes.ProductCategoryAttributes.ProductCategoryAttributeOptions',
]);
if ($this->request->is(['patch', 'post', 'put'])) {
$saveOptions = [
'associated' => ['ProductAttributes'],
];
$product = $productsTable->patchEntity($product, $this->request->getData(), $saveOptions);
if ($productsTable->save($product)) {
$this->Flash->success(__('The product has been saved.'));
public function edit($id = null) {
$productsTable = $this->Products;
$product = $productsTable->get($id, contain: [
'ProductAttributes',
'ProductAttributes.ProductCategoryAttributes',
'ProductAttributes.ProductCategoryAttributes.ProductCategoryAttributeOptions',
]);
if ($this->request->is(['patch', 'post', 'put'])) {
$saveOptions = [
'associated' => ['ProductAttributes'],
];
$product = $productsTable->patchEntity($product, $this->request->getData(), $saveOptions);
if ($productsTable->save($product)) {
$this->Flash->success(__('The product has been saved.'));
return $this->redirect(['action' => 'index']);
}
Log::debug(print_r('$product->getErrors() next - failed in products/edit', true));
Log::debug(print_r($product->getErrors(), true));
$this->Flash->error(__('The product could not be saved. Please, try again.'));
}
$productCategory = $product->product_category_id ? $productsTable->ProductCategories->find()->where(['internal_id' => $product->product_category_id])->first() : null;
$productCatalogs = $productsTable->ProductCategories->ProductCatalogs->find('list')->toArray();
$this->set(compact('product', 'productCatalogs', 'productCategory'));
}
return $this->redirect(['action' => 'index']);
}
Log::debug(print_r('$product->getErrors() next - failed in products/edit', true));
Log::debug(print_r($product->getErrors(), true));
$this->Flash->error(__('The product could not be saved. Please, try again.'));
}
$productCategory = $product->product_category_id ? $productsTable->ProductCategories->find()->where(['internal_id' => $product->product_category_id])->first() : null;
$productCatalogs = $productsTable->ProductCategories->ProductCatalogs->find('list')->toArray();
$this->set(compact('product', 'productCatalogs', 'productCategory'));
}
/**
/**
* Delete method
*
* @param string|null $id Product id.
* @return \Cake\Http\Response|null Redirects to index.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null Redirects to index.
*/
public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
public function delete($id = null) {
$this->request->allowMethod(['post', 'delete']);
$productsTable = $this->Products;
$product = $productsTable->get($id);
if ($productsTable->delete($product)) {
$this->Flash->success(__('The product has been deleted.'));
} else {
$this->Flash->error(__('The product could not be deleted. Please, try again.'));
}
$productsTable = $this->Products;
$product = $productsTable->get($id);
if ($productsTable->delete($product)) {
$this->Flash->success(__('The product has been deleted.'));
} else {
$this->Flash->error(__('The product could not be deleted. Please, try again.'));
}
return $this->redirect(['action' => 'index']);
}
return $this->redirect(['action' => 'index']);
}
/**
/**
* @return \Cake\Http\Response|null|void Renders view
*/
public function select()
{
$productsTable = $this->Products;
$productCategory = $productsTable->ProductCategories->find()
->where(['id' => $this->request->getQuery('product_category_id', '-1')])
->first();
$products = $productsTable
->find('list')
->where(['product_category_id' => $productCategory->internal_id ?? '-1'])
->orderBy(['Products.name'])
->toArray();
public function select() {
$productsTable = $this->Products;
$productCategory = $productsTable->ProductCategories->find()
->where(['id' => $this->request->getQuery('product_category_id', '-1')])
->first();
$products = $productsTable
->find('list')
->where(['product_category_id' => $productCategory->internal_id ?? '-1'])
->orderBy(['Products.name'])
->toArray();
$this->set(compact('products'));
}
$this->set(compact('products'));
}
}
+22 -25
View File
@@ -2,11 +2,7 @@
namespace CakeProducts\Model\Behavior;
use ArrayObject;
use Cake\Datasource\EntityInterface;
use Cake\Event\EventInterface;
use Cake\ORM\Behavior;
use LogicException;
use Tools\Model\Behavior\ToggleBehavior;
/**
@@ -21,37 +17,38 @@ use Tools\Model\Behavior\ToggleBehavior;
*/
class SecondToggleBehavior extends ToggleBehavior {
/**
/**
* Default config
*
* @var array<string, mixed>
*/
protected array $_defaultConfig = [
'field' => 'primary',
'on' => 'afterSave', // afterSave (without transactions) or beforeSave (with transactions)
'scopeFields' => [],
'scope' => [],
'findOrder' => null, // null = autodetect modified/created, false to disable
'implementedMethods' => [], // to prevent conflict with public toggleField method
];
protected array $_defaultConfig = [
'field' => 'primary',
'on' => 'afterSave', // afterSave (without transactions) or beforeSave (with transactions)
'scopeFields' => [],
'scope' => [],
'findOrder' => null, // null = autodetect modified/created, false to disable
'implementedMethods' => [], // to prevent conflict with public toggleField method
];
/**
/**
* @param \Cake\Datasource\EntityInterface $entity
*
* @return array
*/
protected function buildConditions(EntityInterface $entity) {
$conditions = $this->getConfig('scope');
$scopeFields = (array)$this->getConfig('scopeFields');
protected function buildConditions(EntityInterface $entity) {
$conditions = $this->getConfig('scope');
$scopeFields = (array)$this->getConfig('scopeFields');
foreach ($scopeFields as $scopeField) {
if ($entity->get($scopeField) === null) {
continue;
}
$conditions[$scopeField] = $entity->get($scopeField);
}
foreach ($scopeFields as $scopeField) {
if ($entity->get($scopeField) === null) {
continue;
}
$conditions[$scopeField] = $entity->get($scopeField);
}
// dd($conditions);
return $conditions;
}
return $conditions;
}
}
+22 -25
View File
@@ -2,11 +2,7 @@
namespace CakeProducts\Model\Behavior;
use ArrayObject;
use Cake\Datasource\EntityInterface;
use Cake\Event\EventInterface;
use Cake\ORM\Behavior;
use LogicException;
use Tools\Model\Behavior\ToggleBehavior;
/**
@@ -21,37 +17,38 @@ use Tools\Model\Behavior\ToggleBehavior;
*/
class ThirdToggleBehavior extends ToggleBehavior {
/**
/**
* Default config
*
* @var array<string, mixed>
*/
protected array $_defaultConfig = [
'field' => 'primary',
'on' => 'afterSave', // afterSave (without transactions) or beforeSave (with transactions)
'scopeFields' => [],
'scope' => [],
'findOrder' => null, // null = autodetect modified/created, false to disable
'implementedMethods' => [], // to prevent conflict with public toggleField method
];
protected array $_defaultConfig = [
'field' => 'primary',
'on' => 'afterSave', // afterSave (without transactions) or beforeSave (with transactions)
'scopeFields' => [],
'scope' => [],
'findOrder' => null, // null = autodetect modified/created, false to disable
'implementedMethods' => [], // to prevent conflict with public toggleField method
];
/**
/**
* @param \Cake\Datasource\EntityInterface $entity
*
* @return array
*/
protected function buildConditions(EntityInterface $entity) {
$conditions = $this->getConfig('scope');
$scopeFields = (array)$this->getConfig('scopeFields');
protected function buildConditions(EntityInterface $entity) {
$conditions = $this->getConfig('scope');
$scopeFields = (array)$this->getConfig('scopeFields');
foreach ($scopeFields as $scopeField) {
if ($entity->get($scopeField) === null) {
continue;
}
$conditions[$scopeField] = $entity->get($scopeField);
}
foreach ($scopeFields as $scopeField) {
if ($entity->get($scopeField) === null) {
continue;
}
$conditions[$scopeField] = $entity->get($scopeField);
}
// dd($conditions);
return $conditions;
}
return $conditions;
}
}
+15 -15
View File
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity;
/**
@@ -12,15 +11,15 @@ use Cake\ORM\Entity;
* @property int $id
* @property string $base_url
* @property string $api_url
* @property DateTime $created
* @property DateTime|null $deleted
* @property \Cake\I18n\DateTime $created
* @property \Cake\I18n\DateTime|null $deleted
*
* @property ProductCatalog[] $product_catalogs
* @property ExternalProductCatalogsProductCatalog[] $external_product_catalogs_product_catalogs
*/
class ExternalProductCatalog extends Entity
{
/**
class ExternalProductCatalog extends Entity {
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
@@ -29,14 +28,15 @@ class ExternalProductCatalog extends Entity
*
* @var array<string, bool>
*/
protected array $_accessible = [
'base_url' => true,
'api_url' => true,
'created' => true,
'deleted' => true,
'enabled' => true,
protected array $_accessible = [
'base_url' => true,
'api_url' => true,
'created' => true,
'deleted' => true,
'enabled' => true,
// entities
'external_product_catalogs_product_catalogs' => true,
];
// entities
'external_product_catalogs_product_catalogs' => true,
];
}
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity;
/**
@@ -12,16 +11,16 @@ use Cake\ORM\Entity;
* @property int $id
* @property string $external_product_catalog_id
* @property string $product_catalog_id
* @property DateTime $created
* @property \Cake\I18n\DateTime $created
* @property bool $enabled
* @property DateTime|null $deleted
* @property \Cake\I18n\DateTime|null $deleted
*
* @property ExternalProductCatalog $external_product_catalog
* @property ProductCatalog $product_catalog
*/
class ExternalProductCatalogsProductCatalog extends Entity
{
/**
class ExternalProductCatalogsProductCatalog extends Entity {
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
@@ -30,15 +29,16 @@ class ExternalProductCatalogsProductCatalog extends Entity
*
* @var array<string, bool>
*/
protected array $_accessible = [
'external_product_catalog_id' => true,
'product_catalog_id' => true,
'created' => true,
'enabled' => true,
'deleted' => true,
protected array $_accessible = [
'external_product_catalog_id' => true,
'product_catalog_id' => true,
'created' => true,
'enabled' => true,
'deleted' => true,
// entities
'external_product_catalog' => true,
'product_catalog' => true,
];
// entities
'external_product_catalog' => true,
'product_catalog' => true,
];
}
+17 -19
View File
@@ -3,9 +3,7 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity;
use CakeProducts\Model\Enum\ProductProductTypeId;
/**
* Product Entity
@@ -13,17 +11,16 @@ use CakeProducts\Model\Enum\ProductProductTypeId;
* @property string $id
* @property string $name
* @property string $product_category_id
* @property ProductProductTypeId $product_type_id
* @property DateTime|null $deleted
* @property \CakeProducts\Model\Enum\ProductProductTypeId $product_type_id
* @property \Cake\I18n\DateTime|null $deleted
*
* @property ProductCategory $product_category
* @property ProductAttribute[] $product_attributes
* @property ProductCategoryVariant[] $product_category_variants
*
*/
class Product extends Entity
{
/**
class Product extends Entity {
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
@@ -32,16 +29,17 @@ class Product extends Entity
*
* @var array<string, bool>
*/
protected array $_accessible = [
'name' => true,
'product_category_id' => true,
'product_type_id' => true,
'deleted' => true,
protected array $_accessible = [
'name' => true,
'product_category_id' => true,
'product_type_id' => true,
'deleted' => true,
// entities
'product_category' => false,
'product_attributes' => true,
'product_category_variants' => true,
'primary_product_photo' => true,
];
// entities
'product_category' => false,
'product_attributes' => true,
'product_category_variants' => true,
'primary_product_photo' => true,
];
}
+16 -16
View File
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity;
/**
@@ -14,15 +13,15 @@ use Cake\ORM\Entity;
* @property string $product_category_attribute_id
* @property string|null $attribute_value
* @property string|null $product_category_attribute_option_id
* @property DateTime|null $deleted
* @property \Cake\I18n\DateTime|null $deleted
*
* @property Product $product
* @property ProductCategoryAttribute $product_category_attribute
* @property ProductCategoryAttributeOption $product_category_attribute_option
*/
class ProductAttribute extends Entity
{
/**
class ProductAttribute extends Entity {
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
@@ -31,16 +30,17 @@ class ProductAttribute extends Entity
*
* @var array<string, bool>
*/
protected array $_accessible = [
'product_id' => true,
'product_category_attribute_id' => true,
'attribute_value' => true,
'product_category_attribute_option_id' => true,
'deleted' => true,
protected array $_accessible = [
'product_id' => true,
'product_category_attribute_id' => true,
'attribute_value' => true,
'product_category_attribute_option_id' => true,
'deleted' => true,
// entities
'product' => false,
'product_category_attribute' => false,
'product_category_attribute_option' => false,
];
// entities
'product' => false,
'product_category_attribute' => false,
'product_category_attribute_option' => false,
];
}
+14 -14
View File
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity;
/**
@@ -13,14 +12,14 @@ use Cake\ORM\Entity;
* @property string $name
* @property string|null $catalog_description
* @property bool $enabled
* @property DateTime|null $deleted
* @property \Cake\I18n\DateTime|null $deleted
*
* @property ProductCategory[] $product_categories
* @property ExternalProductCatalog[] $external_product_catalogs
*/
class ProductCatalog extends Entity
{
/**
class ProductCatalog extends Entity {
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
@@ -29,14 +28,15 @@ class ProductCatalog extends Entity
*
* @var array<string, bool>
*/
protected array $_accessible = [
'name' => true,
'catalog_description' => true,
'enabled' => true,
'deleted' => true,
protected array $_accessible = [
'name' => true,
'catalog_description' => true,
'enabled' => true,
'deleted' => true,
// entities
'product_categories' => true,
'external_product_catalogs' => true,
];
// entities
'product_categories' => true,
'external_product_catalogs' => true,
];
}
+23 -24
View File
@@ -3,9 +3,7 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity;
use CakeProducts\Model\Enum\ProductProductTypeId;
/**
* ProductCategory Entity
@@ -19,16 +17,16 @@ use CakeProducts\Model\Enum\ProductProductTypeId;
* @property int $lft
* @property int $rght
* @property bool $enabled
* @property DateTime|null $deleted
* @property ProductProductTypeId|null $default_product_type_id
* @property \Cake\I18n\DateTime|null $deleted
* @property \CakeProducts\Model\Enum\ProductProductTypeId|null $default_product_type_id
*
* @property \CakeProducts\Model\Entity\ProductCatalog $product_catalog
* @property \CakeProducts\Model\Entity\ParentProductCategory $parent_product_category
* @property \CakeProducts\Model\Entity\ChildProductCategory[] $child_product_categories
*/
class ProductCategory extends Entity
{
/**
class ProductCategory extends Entity {
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
@@ -37,22 +35,23 @@ class ProductCategory extends Entity
*
* @var array<string, bool>
*/
protected array $_accessible = [
'product_catalog_id' => true,
'internal_id' => true,
'name' => true,
'category_description' => true,
'default_product_type_id' => true,
'parent_id' => true,
'lft' => true,
'rght' => true,
'enabled' => true,
'deleted' => true,
protected array $_accessible = [
'product_catalog_id' => true,
'internal_id' => true,
'name' => true,
'category_description' => true,
'default_product_type_id' => true,
'parent_id' => true,
'lft' => true,
'rght' => true,
'enabled' => true,
'deleted' => true,
// entities
'product_catalog' => true,
'parent_product_category' => true,
'child_product_categories' => true,
'primary_product_photo' => true,
];
// entities
'product_catalog' => true,
'parent_product_category' => true,
'child_product_categories' => true,
'primary_product_photo' => true,
];
}
+15 -15
View File
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity;
/**
@@ -14,14 +13,14 @@ use Cake\ORM\Entity;
* @property string|null $product_category_id
* @property int $attribute_type_id
* @property bool $enabled
* @property DateTime|null $deleted
* @property \Cake\I18n\DateTime|null $deleted
*
* @property ProductCategory $product_category
* @property ProductCategoryAttributeOption[] $product_category_attribute_options
*/
class ProductCategoryAttribute extends Entity
{
/**
class ProductCategoryAttribute extends Entity {
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
@@ -30,15 +29,16 @@ class ProductCategoryAttribute extends Entity
*
* @var array<string, bool>
*/
protected array $_accessible = [
'name' => true,
'product_category_id' => true,
'attribute_type_id' => true,
'enabled' => true,
'deleted' => true,
protected array $_accessible = [
'name' => true,
'product_category_id' => true,
'attribute_type_id' => true,
'enabled' => true,
'deleted' => true,
// entities
'product_category' => true,
'product_category_attribute_options' => true,
];
// entities
'product_category' => true,
'product_category_attribute_options' => true,
];
}
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity;
/**
@@ -14,13 +13,13 @@ use Cake\ORM\Entity;
* @property string $attribute_value
* @property string $attribute_label
* @property bool $enabled
* @property DateTime|null $deleted
* @property \Cake\I18n\DateTime|null $deleted
*
* @property ProductCategoryAttribute $product_category_attribute
*/
class ProductCategoryAttributeOption extends Entity
{
/**
class ProductCategoryAttributeOption extends Entity {
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
@@ -29,14 +28,15 @@ class ProductCategoryAttributeOption extends Entity
*
* @var array<string, bool>
*/
protected array $_accessible = [
'product_category_attribute_id' => true,
'attribute_value' => true,
'attribute_label' => true,
'enabled' => true,
'deleted' => true,
protected array $_accessible = [
'product_category_attribute_id' => true,
'attribute_value' => true,
'attribute_label' => true,
'enabled' => true,
'deleted' => true,
// entities
'product_category_attribute' => true,
];
// entities
'product_category_attribute' => true,
];
}
+17 -17
View File
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity;
use Cake\Datasource\EntityInterface;
use Cake\ORM\Entity;
/**
@@ -16,12 +15,12 @@ use Cake\ORM\Entity;
* @property bool $enabled
* @property bool $is_system_variant
*
* @property ProductCategory|EntityInterface $product_category
* @property ProductCategoryVariantOption[]|EntityInterface[] $product_category_variant_options
* @property ProductCategory|\Cake\Datasource\EntityInterface $product_category
* @property ProductCategoryVariantOption[]|\Cake\Datasource\EntityInterface[] $product_category_variant_options
*/
class ProductCategoryVariant extends Entity
{
/**
class ProductCategoryVariant extends Entity {
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
@@ -30,16 +29,17 @@ class ProductCategoryVariant extends Entity
*
* @var array<string, bool>
*/
protected array $_accessible = [
'name' => true,
'product_category_id' => true,
'product_id' => true,
'enabled' => true,
'is_system_variant' => true,
protected array $_accessible = [
'name' => true,
'product_category_id' => true,
'product_id' => true,
'enabled' => true,
'is_system_variant' => true,
// entities
'product_category' => false,
'product' => false,
'product_category_variant_options' => true,
];
// entities
'product_category' => false,
'product' => false,
'product_category_variant_options' => true,
];
}
@@ -17,9 +17,9 @@ use Cake\ORM\Entity;
*
* @property \App\Model\Entity\ProductCategoryVariant $product_category_variant
*/
class ProductCategoryVariantOption extends Entity
{
/**
class ProductCategoryVariantOption extends Entity {
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
@@ -28,14 +28,15 @@ class ProductCategoryVariantOption extends Entity
*
* @var array<string, bool>
*/
protected array $_accessible = [
'product_category_variant_id' => true,
'variant_value' => true,
'created' => true,
'modified' => true,
'deleted' => true,
protected array $_accessible = [
'product_category_variant_id' => true,
'variant_value' => true,
'created' => true,
'modified' => true,
'deleted' => true,
// entities
'product_category_variant' => false,
];
// entities
'product_category_variant' => false,
];
}
+26 -26
View File
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity;
/**
@@ -20,17 +19,17 @@ use Cake\ORM\Entity;
* @property bool $primary_sku_photo
* @property int $photo_position
* @property bool $enabled
* @property DateTime $created
* @property DateTime|null $modified
* @property DateTime|null $deleted
* @property \Cake\I18n\DateTime $created
* @property \Cake\I18n\DateTime|null $modified
* @property \Cake\I18n\DateTime|null $deleted
*
* @property Product|null $product
* @property ProductSku|null $product_sku
* @property ProductCategory $product_category
*/
class ProductPhoto extends Entity
{
/**
class ProductPhoto extends Entity {
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
@@ -39,24 +38,25 @@ class ProductPhoto extends Entity
*
* @var array<string, bool>
*/
protected array $_accessible = [
'product_id' => true,
'product_sku_id' => true,
'product_category_id' => true,
'photo_dir' => true,
'photo_filename' => true,
'primary_photo' => true,
'primary_category_photo' => true,
'primary_sku_photo' => true,
'photo_position' => true,
'enabled' => true,
'created' => true,
'modified' => true,
'deleted' => true,
protected array $_accessible = [
'product_id' => true,
'product_sku_id' => true,
'product_category_id' => true,
'photo_dir' => true,
'photo_filename' => true,
'primary_photo' => true,
'primary_category_photo' => true,
'primary_sku_photo' => true,
'photo_position' => true,
'enabled' => true,
'created' => true,
'modified' => true,
'deleted' => true,
// entities
'product' => false,
'product_sku' => false,
'product_category' => false,
];
// entities
'product' => false,
'product_sku' => false,
'product_category' => false,
];
}
+21 -21
View File
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity;
/**
@@ -15,17 +14,17 @@ use Cake\ORM\Entity;
* @property string|null $barcode
* @property string|null $price
* @property string|null $cost
* @property DateTime $created
* @property DateTime|null $modified
* @property DateTime|null $deleted
* @property \Cake\I18n\DateTime $created
* @property \Cake\I18n\DateTime|null $modified
* @property \Cake\I18n\DateTime|null $deleted
* @property bool $default_sku
*
* @property Product $product
* @property ProductSkuVariantValue[] $product_sku_variant_values
*/
class ProductSku extends Entity
{
/**
class ProductSku extends Entity {
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
@@ -34,19 +33,20 @@ class ProductSku extends Entity
*
* @var array<string, bool>
*/
protected array $_accessible = [
'product_id' => true,
'sku' => true,
'barcode' => true,
'price' => true,
'cost' => true,
'created' => true,
'modified' => true,
'deleted' => true,
'default_sku' => true,
protected array $_accessible = [
'product_id' => true,
'sku' => true,
'barcode' => true,
'price' => true,
'cost' => true,
'created' => true,
'modified' => true,
'deleted' => true,
'default_sku' => true,
// entities
'product' => false,
'product_sku_variant_values' => true,
];
// entities
'product' => false,
'product_sku_variant_values' => true,
];
}
+13 -12
View File
@@ -17,9 +17,9 @@ use Cake\ORM\Entity;
* @property ProductCategoryVariant $product_category_variant
* @property ProductCategoryVariantOption $product_category_variant_option
*/
class ProductSkuVariantValue extends Entity
{
/**
class ProductSkuVariantValue extends Entity {
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
@@ -28,14 +28,15 @@ class ProductSkuVariantValue extends Entity
*
* @var array<string, bool>
*/
protected array $_accessible = [
'product_sku_id' => true,
'product_variant_id' => true,
'product_category_variant_option_id' => true,
protected array $_accessible = [
'product_sku_id' => true,
'product_variant_id' => true,
'product_category_variant_option_id' => true,
// entities
'product_sku' => true,
'product_variant' => true,
'product_category_variant_option' => true,
];
// entities
'product_sku' => true,
'product_variant' => true,
'product_category_variant_option' => true,
];
}
+12 -11
View File
@@ -17,9 +17,9 @@ use Cake\ORM\Entity;
* @property \App\Model\Entity\ProductCategoryVariant $product_category_variant
* @property \App\Model\Entity\Product $product
*/
class ProductVariant extends Entity
{
/**
class ProductVariant extends Entity {
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
@@ -28,12 +28,13 @@ class ProductVariant extends Entity
*
* @var array<string, bool>
*/
protected array $_accessible = [
'name' => true,
'product_category_variant_id' => true,
'product_id' => true,
'enabled' => true,
'product_category_variant' => true,
'product' => true,
];
protected array $_accessible = [
'name' => true,
'product_category_variant_id' => true,
'product_id' => true,
'enabled' => true,
'product_category_variant' => true,
'product' => true,
];
}
@@ -5,18 +5,10 @@ namespace CakeProducts\Model\Table;
use ArrayObject;
use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\Event\EventInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Behavior\TimestampBehavior;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog;
use Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ExternalProductCatalogsProductCatalogs Model
@@ -24,15 +16,15 @@ use Psr\SimpleCache\CacheInterface;
* @property ExternalProductCatalogsTable&BelongsTo $ExternalProductCatalogs
* @property ProductCatalogsTable&BelongsTo $ProductCatalogs
*
* @method ExternalProductCatalogsProductCatalog newEmptyEntity()
* @method ExternalProductCatalogsProductCatalog newEntity(array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog newEmptyEntity()
* @method \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog newEntity()
* @method array<ExternalProductCatalogsProductCatalog> newEntities(array $data, array $options = [])
* @method ExternalProductCatalogsProductCatalog get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
* @method ExternalProductCatalogsProductCatalog findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ExternalProductCatalogsProductCatalog patchEntity(EntityInterface $entity, array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog get()
* @method \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog findOrCreate()
* @method \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog patchEntity()
* @method array<ExternalProductCatalogsProductCatalog> patchEntities(iterable $entities, array $data, array $options = [])
* @method ExternalProductCatalogsProductCatalog|false save(EntityInterface $entity, array $options = [])
* @method ExternalProductCatalogsProductCatalog saveOrFail(EntityInterface $entity, array $options = [])
* @method \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog saveOrFail()
* @method iterable<ExternalProductCatalogsProductCatalog>|ResultSetInterface<ExternalProductCatalogsProductCatalog>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ExternalProductCatalogsProductCatalog>|ResultSetInterface<ExternalProductCatalogsProductCatalog> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ExternalProductCatalogsProductCatalog>|ResultSetInterface<ExternalProductCatalogsProductCatalog>|false deleteMany(iterable $entities, array $options = [])
@@ -40,86 +32,86 @@ use Psr\SimpleCache\CacheInterface;
*
* @mixin TimestampBehavior
*/
class ExternalProductCatalogsProductCatalogsTable extends Table
{
/**
class ExternalProductCatalogsProductCatalogsTable extends Table {
/**
* Initialize method
*
* @param array<string, mixed> $config The configuration for the Table.
* @return void
*/
public function initialize(array $config): void
{
parent::initialize($config);
public function initialize(array $config): void {
parent::initialize($config);
$this->setTable('external_product_catalogs_product_catalogs');
$this->setDisplayField('external_product_catalog_id');
$this->setPrimaryKey('id');
$this->setTable('external_product_catalogs_product_catalogs');
$this->setDisplayField('external_product_catalog_id');
$this->setPrimaryKey('id');
$this->addBehavior('Timestamp');
$this->addBehavior('Timestamp');
$this->setEntityClass(
Configure::read('CakeProducts.ExternalProductCatalogsProductCatalogs.entity', 'CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog')
);
$this->belongsTo('ExternalProductCatalogs', [
'className' => 'CakeProducts.ExternalProductCatalogs',
$this->setEntityClass(
Configure::read('CakeProducts.ExternalProductCatalogsProductCatalogs.entity', 'CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog'),
);
$this->belongsTo('ExternalProductCatalogs', [
'className' => 'CakeProducts.ExternalProductCatalogs',
// 'foreignKey' => 'external_product_catalog_id',
'joinType' => 'INNER',
]);
$this->belongsTo('ProductCatalogs', [
'className' => 'CakeProducts.ProductCatalogs',
'joinType' => 'INNER',
]);
$this->belongsTo('ProductCatalogs', [
'className' => 'CakeProducts.ProductCatalogs',
// 'foreignKey' => 'product_catalog_id',
'joinType' => 'INNER',
]);
'joinType' => 'INNER',
]);
$this->addBehavior('Muffin/Trash.Trash');
}
$this->addBehavior('Muffin/Trash.Trash');
}
/**
/**
* Default validation rules.
*
* @param Validator $validator Validator instance.
* @return Validator
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->uuid('external_product_catalog_id')
->notEmptyString('external_product_catalog_id');
public function validationDefault(Validator $validator): Validator {
$validator
->uuid('external_product_catalog_id')
->notEmptyString('external_product_catalog_id');
$validator
->uuid('product_catalog_id')
->notEmptyString('product_catalog_id');
$validator
->uuid('product_catalog_id')
->notEmptyString('product_catalog_id');
$validator
->boolean('enabled');
$validator
->boolean('enabled');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
return $validator;
}
return $validator;
}
public function beforeMarshal(EventInterface $event, ArrayObject $data, ArrayObject $options)
{
if (!isset($data['enabled'])) {
$data['enabled'] = false;
}
}
/**
* @return void
*/
public function beforeMarshal(EventInterface $event, ArrayObject $data, ArrayObject $options) {
if (!isset($data['enabled'])) {
$data['enabled'] = false;
}
}
/**
/**
* Returns a rules checker object that will be used for validating
* application integrity.
*
* @param RulesChecker $rules The rules object to be modified.
* @return RulesChecker
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return \Cake\ORM\RulesChecker
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
public function buildRules(RulesChecker $rules): RulesChecker {
// $rules->add($rules->existsIn(['external_product_catalog_id'], 'ExternalProductCatalogs'), ['errorField' => 'external_product_catalog_id']);
// $rules->add($rules->existsIn(['product_catalog_id'], 'ProductCatalogs'), ['errorField' => 'product_catalog_id']);
return $rules;
}
return $rules;
}
}
@@ -4,32 +4,24 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table;
use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Behavior\TimestampBehavior;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ExternalProductCatalog;
use Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ExternalProductCatalogs Model
*
* @property ProductCatalogsTable&BelongsTo $ProductCatalogs
*
* @method ExternalProductCatalog newEmptyEntity()
* @method ExternalProductCatalog newEntity(array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ExternalProductCatalog newEmptyEntity()
* @method \CakeProducts\Model\Entity\ExternalProductCatalog newEntity()
* @method array<ExternalProductCatalog> newEntities(array $data, array $options = [])
* @method ExternalProductCatalog get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
* @method ExternalProductCatalog findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ExternalProductCatalog patchEntity(EntityInterface $entity, array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ExternalProductCatalog get()
* @method \CakeProducts\Model\Entity\ExternalProductCatalog findOrCreate()
* @method \CakeProducts\Model\Entity\ExternalProductCatalog patchEntity()
* @method array<ExternalProductCatalog> patchEntities(iterable $entities, array $data, array $options = [])
* @method ExternalProductCatalog|false save(EntityInterface $entity, array $options = [])
* @method ExternalProductCatalog saveOrFail(EntityInterface $entity, array $options = [])
* @method \CakeProducts\Model\Entity\ExternalProductCatalog saveOrFail()
* @method iterable<ExternalProductCatalog>|ResultSetInterface<ExternalProductCatalog>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ExternalProductCatalog>|ResultSetInterface<ExternalProductCatalog> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ExternalProductCatalog>|ResultSetInterface<ExternalProductCatalog>|false deleteMany(iterable $entities, array $options = [])
@@ -37,81 +29,79 @@ use Psr\SimpleCache\CacheInterface;
*
* @mixin TimestampBehavior
*/
class ExternalProductCatalogsTable extends Table
{
/**
class ExternalProductCatalogsTable extends Table {
/**
* Initialize method
*
* @param array<string, mixed> $config The configuration for the Table.
* @return void
*/
public function initialize(array $config): void
{
parent::initialize($config);
public function initialize(array $config): void {
parent::initialize($config);
$this->setTable('external_product_catalogs');
$this->setDisplayField('base_url');
$this->setPrimaryKey('id');
$this->setTable('external_product_catalogs');
$this->setDisplayField('base_url');
$this->setPrimaryKey('id');
$this->addBehavior('Timestamp');
$this->addBehavior('Timestamp');
$this->setEntityClass(
Configure::read('CakeProducts.ExternalProductCatalogs.entity', 'CakeProducts\Model\Entity\ExternalProductCatalog')
);
$this->setEntityClass(
Configure::read('CakeProducts.ExternalProductCatalogs.entity', 'CakeProducts\Model\Entity\ExternalProductCatalog'),
);
$this->belongsToMany('ProductCatalogs', [
'through' => 'ExternalProductCatalogsProductCatalogs',
'className' => 'CakeProducts.ProductCatalogs',
]);
$this->belongsToMany('ProductCatalogs', [
'through' => 'ExternalProductCatalogsProductCatalogs',
'className' => 'CakeProducts.ProductCatalogs',
]);
$this->hasMany('ExternalProductCatalogsProductCatalogs', [
'foreignKey' => 'external_product_catalog_id',
'className' => 'CakeProducts.ExternalProductCatalogsProductCatalogs',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ExternalProductCatalogsProductCatalogs', [
'foreignKey' => 'external_product_catalog_id',
'className' => 'CakeProducts.ExternalProductCatalogsProductCatalogs',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->addBehavior('Muffin/Trash.Trash');
}
$this->addBehavior('Muffin/Trash.Trash');
}
/**
/**
* Default validation rules.
*
* @param Validator $validator Validator instance.
* @return Validator
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->scalar('base_url')
->maxLength('base_url', 255)
->requirePresence('base_url', 'create')
->notEmptyString('base_url');
public function validationDefault(Validator $validator): Validator {
$validator
->scalar('base_url')
->maxLength('base_url', 255)
->requirePresence('base_url', 'create')
->notEmptyString('base_url');
// ->url('base_url');
$validator
->scalar('api_url')
->maxLength('api_url', 255)
->requirePresence('api_url', 'create')
->notEmptyString('api_url');
$validator
->scalar('api_url')
->maxLength('api_url', 255)
->requirePresence('api_url', 'create')
->notEmptyString('api_url');
// ->url('api_url');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
return $validator;
}
return $validator;
}
/**
/**
* Returns a rules checker object that will be used for validating
* application integrity.
*
* @param RulesChecker $rules The rules object to be modified.
* @return RulesChecker
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return \Cake\ORM\RulesChecker
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
return $rules;
}
public function buildRules(RulesChecker $rules): RulesChecker {
return $rules;
}
}
+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> deleteManyOrFail(iterable $entities, array $options = [])
*/
class ProductAttributesTable extends Table
{
/**
class ProductAttributesTable extends Table {
/**
* Initialize method
*
* @param array<string, mixed> $config The configuration for the Table.
* @return void
*/
public function initialize(array $config): void
{
parent::initialize($config);
public function initialize(array $config): void {
parent::initialize($config);
$this->setTable('product_attributes');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->setTable('product_attributes');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->setEntityClass(
Configure::read('CakeProducts.ProductAttributes.entity', 'CakeProducts\Model\Entity\ProductAttribute')
);
$this->setEntityClass(
Configure::read('CakeProducts.ProductAttributes.entity', 'CakeProducts\Model\Entity\ProductAttribute'),
);
$this->belongsTo('Products', [
'foreignKey' => 'product_id',
'className' => 'CakeProducts.Products',
'joinType' => 'INNER',
]);
$this->belongsTo('ProductCategoryAttributes', [
'foreignKey' => 'product_category_attribute_id',
'className' => 'CakeProducts.ProductCategoryAttributes',
'joinType' => 'INNER',
]);
$this->belongsTo('ProductCategoryAttributeOptions', [
'foreignKey' => 'product_category_attribute_option_id',
'className' => 'CakeProducts.ProductCategoryAttributeOptions',
]);
$this->belongsTo('Products', [
'foreignKey' => 'product_id',
'className' => 'CakeProducts.Products',
'joinType' => 'INNER',
]);
$this->belongsTo('ProductCategoryAttributes', [
'foreignKey' => 'product_category_attribute_id',
'className' => 'CakeProducts.ProductCategoryAttributes',
'joinType' => 'INNER',
]);
$this->belongsTo('ProductCategoryAttributeOptions', [
'foreignKey' => 'product_category_attribute_option_id',
'className' => 'CakeProducts.ProductCategoryAttributeOptions',
]);
}
}
/**
/**
* Default validation rules.
*
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->uuid('product_id')
->notEmptyString('product_id');
public function validationDefault(Validator $validator): Validator {
$validator
->uuid('product_id')
->notEmptyString('product_id');
$validator
->uuid('product_category_attribute_id')
->notEmptyString('product_category_attribute_id');
$validator
->uuid('product_category_attribute_id')
->notEmptyString('product_category_attribute_id');
$validator
->scalar('attribute_value')
->maxLength('attribute_value', 255)
->allowEmptyString('attribute_value');
$validator
->scalar('attribute_value')
->maxLength('attribute_value', 255)
->allowEmptyString('attribute_value');
$validator
->uuid('product_category_attribute_option_id')
->allowEmptyString('product_category_attribute_option_id');
$validator
->uuid('product_category_attribute_option_id')
->allowEmptyString('product_category_attribute_option_id');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
return $validator;
}
return $validator;
}
/**
/**
* Returns a rules checker object that will be used for validating
* application integrity.
*
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return \Cake\ORM\RulesChecker
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
$rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']);
$rules->add($rules->existsIn(['product_category_attribute_option_id'], 'ProductCategoryAttributeOptions'), ['errorField' => 'product_category_attribute_option_id']);
public function buildRules(RulesChecker $rules): RulesChecker {
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
$rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']);
$rules->add($rules->existsIn(['product_category_attribute_option_id'], 'ProductCategoryAttributeOptions'), ['errorField' => 'product_category_attribute_option_id']);
return $rules;
}
return $rules;
}
}
+57 -65
View File
@@ -4,106 +4,98 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table;
use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductCatalog;
use Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ProductCatalogs Model
*
* @method ProductCatalog newEmptyEntity()
* @method ProductCatalog newEntity(array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCatalog newEmptyEntity()
* @method \CakeProducts\Model\Entity\ProductCatalog newEntity()
* @method array<ProductCatalog> newEntities(array $data, array $options = [])
* @method ProductCatalog get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductCatalog findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductCatalog patchEntity(EntityInterface $entity, array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCatalog get()
* @method \CakeProducts\Model\Entity\ProductCatalog findOrCreate()
* @method \CakeProducts\Model\Entity\ProductCatalog patchEntity()
* @method array<ProductCatalog> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductCatalog|false save(EntityInterface $entity, array $options = [])
* @method ProductCatalog saveOrFail(EntityInterface $entity, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCatalog saveOrFail()
* @method iterable<ProductCatalog>|ResultSetInterface<ProductCatalog>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductCatalog>|ResultSetInterface<ProductCatalog> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductCatalog>|ResultSetInterface<ProductCatalog>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductCatalog>|ResultSetInterface<ProductCatalog> deleteManyOrFail(iterable $entities, array $options = [])
*/
class ProductCatalogsTable extends Table
{
/**
class ProductCatalogsTable extends Table {
/**
* Initialize method
*
* @param array<string, mixed> $config The configuration for the Table.
* @return void
*/
public function initialize(array $config): void
{
parent::initialize($config);
public function initialize(array $config): void {
parent::initialize($config);
$this->setTable('product_catalogs');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->setTable('product_catalogs');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->setEntityClass(
Configure::read('CakeProducts.ProductCatalogs.entity', 'CakeProducts\Model\Entity\ProductCatalog')
);
$this->hasMany('ProductCategories', [
'className' => 'CakeProducts.ProductCategories',
]);
$this->belongsToMany('ExternalProductCatalogs', [
'through' => 'ExternalProductCatalogsProductCatalogs',
'className' => 'CakeProducts.ExternalProductCatalogs',
]);
$this->setEntityClass(
Configure::read('CakeProducts.ProductCatalogs.entity', 'CakeProducts\Model\Entity\ProductCatalog'),
);
$this->hasMany('ProductCategories', [
'className' => 'CakeProducts.ProductCategories',
]);
$this->belongsToMany('ExternalProductCatalogs', [
'through' => 'ExternalProductCatalogsProductCatalogs',
'className' => 'CakeProducts.ExternalProductCatalogs',
]);
$this->addBehavior('Muffin/Trash.Trash');
}
$this->addBehavior('Muffin/Trash.Trash');
}
/**
/**
* Default validation rules.
*
* @param Validator $validator Validator instance.
* @return Validator
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->scalar('name')
->maxLength('name', 255)
->requirePresence('name', 'create')
->notEmptyString('name')
->add('name', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']);
public function validationDefault(Validator $validator): Validator {
$validator
->scalar('name')
->maxLength('name', 255)
->requirePresence('name', 'create')
->notEmptyString('name')
->add('name', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']);
$validator
->scalar('catalog_description')
->maxLength('catalog_description', 255)
->allowEmptyString('catalog_description');
$validator
->scalar('catalog_description')
->maxLength('catalog_description', 255)
->allowEmptyString('catalog_description');
$validator
->boolean('enabled')
->requirePresence('enabled', 'create')
->notEmptyString('enabled');
$validator
->boolean('enabled')
->requirePresence('enabled', 'create')
->notEmptyString('enabled');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
return $validator;
}
return $validator;
}
/**
/**
* Returns a rules checker object that will be used for validating
* application integrity.
*
* @param RulesChecker $rules The rules object to be modified.
* @return RulesChecker
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return \Cake\ORM\RulesChecker
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->isUnique(['name']), ['errorField' => 'name']);
public function buildRules(RulesChecker $rules): RulesChecker {
$rules->add($rules->isUnique(['name']), ['errorField' => 'name']);
return $rules;
}
return $rules;
}
}
+133 -145
View File
@@ -6,18 +6,10 @@ namespace CakeProducts\Model\Table;
use Cake\Core\Configure;
use Cake\Database\Type\EnumType;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Association\HasMany;
use Cake\ORM\Behavior\TreeBehavior;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductCategory;
use CakeProducts\Model\Enum\ProductProductTypeId;
use Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ProductCategories Model
@@ -26,14 +18,14 @@ use Psr\SimpleCache\CacheInterface;
* @property ProductCategoriesTable&BelongsTo $ParentProductCategories
* @property ProductCategoriesTable&HasMany $ChildProductCategories
*
* @method ProductCategory newEmptyEntity()
* @method ProductCategory newEntity(array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategory newEmptyEntity()
* @method \CakeProducts\Model\Entity\ProductCategory newEntity()
* @method array<ProductCategory> newEntities(array $data, array $options = [])
* @method ProductCategory get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductCategory findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductCategory patchEntity(EntityInterface $entity, array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategory get()
* @method \CakeProducts\Model\Entity\ProductCategory findOrCreate()
* @method \CakeProducts\Model\Entity\ProductCategory patchEntity()
* @method array<ProductCategory> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductCategory saveOrFail(EntityInterface $entity, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategory saveOrFail()
* @method iterable<ProductCategory>|ResultSetInterface<ProductCategory>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductCategory>|ResultSetInterface<ProductCategory> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductCategory>|ResultSetInterface<ProductCategory>|false deleteMany(iterable $entities, array $options = [])
@@ -41,175 +33,171 @@ use Psr\SimpleCache\CacheInterface;
*
* @mixin TreeBehavior
*/
class ProductCategoriesTable extends Table
{
/**
class ProductCategoriesTable extends Table {
/**
* Current scope for Tree behavior - per catalog
*
* @var string
*/
protected $treeCatalogId;
protected $treeCatalogId;
/**
/**
* Initialize method
*
* @param array<string, mixed> $config The configuration for the Table.
* @return void
*/
public function initialize(array $config): void
{
parent::initialize($config);
$this->treeCatalogId = 1;
public function initialize(array $config): void {
parent::initialize($config);
$this->treeCatalogId = 1;
$this->setTable('product_categories');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->setEntityClass(
Configure::read('CakeProducts.ProductCategories.entity', 'CakeProducts\Model\Entity\ProductCategory')
);
$this->addBehavior('Tree', [
'cascadeCallbacks' => true,
]);
$this->setTable('product_categories');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->setEntityClass(
Configure::read('CakeProducts.ProductCategories.entity', 'CakeProducts\Model\Entity\ProductCategory'),
);
$this->addBehavior('Tree', [
'cascadeCallbacks' => true,
]);
$this->belongsTo('ProductCatalogs', [
'foreignKey' => 'product_catalog_id',
'joinType' => 'INNER',
'className' => 'CakeProducts.ProductCatalogs',
]);
$this->belongsTo('ParentProductCategories', [
'className' => 'CakeProducts.ProductCategories',
'foreignKey' => 'parent_id',
]);
$this->hasMany('ChildProductCategories', [
'className' => 'CakeProducts.ProductCategories',
'foreignKey' => 'parent_id',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ProductCategoryAttributes', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductCategoryAttributes',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ProductCategoryVariants', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductCategoryVariants',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('Products', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.Products',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ProductPhotos', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductPhotos',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasOne('PrimaryProductPhotos', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'conditions' => ['PrimaryProductPhotos.primary_category_photo' => true],
'className' => 'CakeProducts.ProductPhotos',
'dependent' => true,
]);
$this->belongsTo('ProductCatalogs', [
'foreignKey' => 'product_catalog_id',
'joinType' => 'INNER',
'className' => 'CakeProducts.ProductCatalogs',
]);
$this->belongsTo('ParentProductCategories', [
'className' => 'CakeProducts.ProductCategories',
'foreignKey' => 'parent_id',
]);
$this->hasMany('ChildProductCategories', [
'className' => 'CakeProducts.ProductCategories',
'foreignKey' => 'parent_id',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ProductCategoryAttributes', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductCategoryAttributes',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ProductCategoryVariants', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductCategoryVariants',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('Products', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.Products',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ProductPhotos', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductPhotos',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasOne('PrimaryProductPhotos', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'conditions' => ['PrimaryProductPhotos.primary_category_photo' => true],
'className' => 'CakeProducts.ProductPhotos',
'dependent' => true,
]);
$this->getSchema()->setColumnType('default_product_type_id', EnumType::from(ProductProductTypeId::class));
$this->getSchema()->setColumnType('default_product_type_id', EnumType::from(ProductProductTypeId::class));
$this->behaviors()->Tree->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]);
$this->addBehavior('Muffin/Trash.Trash');
}
$this->behaviors()->Tree->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]);
$this->addBehavior('Muffin/Trash.Trash');
}
/**
/**
* Default validation rules.
*
* @param Validator $validator Validator instance.
* @return Validator
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->uuid('product_catalog_id')
->notEmptyString('product_catalog_id');
public function validationDefault(Validator $validator): Validator {
$validator
->uuid('product_catalog_id')
->notEmptyString('product_catalog_id');
$validator
->scalar('name')
->maxLength('name', 255)
->requirePresence('name', 'create')
->notEmptyString('name');
$validator
->scalar('name')
->maxLength('name', 255)
->requirePresence('name', 'create')
->notEmptyString('name');
$validator
->scalar('category_description')
->allowEmptyString('category_description');
$validator
->scalar('category_description')
->allowEmptyString('category_description');
$validator
->integer('parent_id')
->allowEmptyString('parent_id');
$validator
->integer('parent_id')
->allowEmptyString('parent_id');
$validator
->boolean('enabled')
->notEmptyString('enabled');
$validator
->boolean('enabled')
->notEmptyString('enabled');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
$validator
->integer('default_product_type_id')
->allowEmptyString('default_product_type_id');
$validator
->integer('default_product_type_id')
->allowEmptyString('default_product_type_id');
return $validator;
}
return $validator;
}
/**
/**
* Returns a rules checker object that will be used for validating
* application integrity.
*
* @param RulesChecker $rules The rules object to be modified.
* @return RulesChecker
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return \Cake\ORM\RulesChecker
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->isUnique(['product_catalog_id', 'name']), ['errorField' => 'product_catalog_id']);
$rules->add($rules->existsIn(['product_catalog_id'], 'ProductCatalogs'), ['errorField' => 'product_catalog_id']);
$rules->add($rules->existsIn(['parent_id'], 'ParentProductCategories'), ['errorField' => 'parent_id']);
public function buildRules(RulesChecker $rules): RulesChecker {
$rules->add($rules->isUnique(['product_catalog_id', 'name']), ['errorField' => 'product_catalog_id']);
$rules->add($rules->existsIn(['product_catalog_id'], 'ProductCatalogs'), ['errorField' => 'product_catalog_id']);
$rules->add($rules->existsIn(['parent_id'], 'ParentProductCategories'), ['errorField' => 'parent_id']);
return $rules;
}
return $rules;
}
/**
* @param int $catalogId
/**
* @param string $catalogId
*
* @return void
*/
public function setConfigureCatalogId(string $catalogId)
{
$this->treeCatalogId = $catalogId;
$this->behaviors()->Tree->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]);
}
public function setConfigureCatalogId(string $catalogId) {
$this->treeCatalogId = $catalogId;
$this->behaviors()->Tree->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]);
}
/**
* @param EntityInterface $entity
/**
* @param \Cake\Datasource\EntityInterface $entity
* @param array $options
*
* @return EntityInterface|false
* @return \Cake\Datasource\EntityInterface|false
*/
public function save(EntityInterface $entity, array $options = []): EntityInterface|false
{
$this->behaviors()->get('Tree')->setConfig([
'scope' => [
'product_catalog_id' => $entity->product_catalog_id,
],
]);
public function save(EntityInterface $entity, array $options = []): EntityInterface|false {
$this->behaviors()->get('Tree')->setConfig([
'scope' => [
'product_catalog_id' => $entity->product_catalog_id,
],
]);
return parent::save($entity, $options);
}
return parent::save($entity, $options);
}
}
@@ -4,112 +4,103 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table;
use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductCategoryAttributeOption;
use Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ProductCategoryAttributeOptions Model
*
* @property ProductCategoryAttributesTable&BelongsTo $ProductCategoryAttributes
*
* @method ProductCategoryAttributeOption newEmptyEntity()
* @method ProductCategoryAttributeOption newEntity(array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption newEmptyEntity()
* @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption newEntity()
* @method array<ProductCategoryAttributeOption> newEntities(array $data, array $options = [])
* @method ProductCategoryAttributeOption get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductCategoryAttributeOption findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductCategoryAttributeOption patchEntity(EntityInterface $entity, array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption get()
* @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption findOrCreate()
* @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption patchEntity()
* @method array<ProductCategoryAttributeOption> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductCategoryAttributeOption|false save(EntityInterface $entity, array $options = [])
* @method ProductCategoryAttributeOption saveOrFail(EntityInterface $entity, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption saveOrFail()
* @method iterable<ProductCategoryAttributeOption>|ResultSetInterface<ProductCategoryAttributeOption>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryAttributeOption>|ResultSetInterface<ProductCategoryAttributeOption> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductCategoryAttributeOption>|ResultSetInterface<ProductCategoryAttributeOption>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryAttributeOption>|ResultSetInterface<ProductCategoryAttributeOption> deleteManyOrFail(iterable $entities, array $options = [])
*/
class ProductCategoryAttributeOptionsTable extends Table
{
/**
class ProductCategoryAttributeOptionsTable extends Table {
/**
* Initialize method
*
* @param array<string, mixed> $config The configuration for the Table.
* @return void
*/
public function initialize(array $config): void
{
parent::initialize($config);
public function initialize(array $config): void {
parent::initialize($config);
$this->setTable('product_category_attribute_options');
$this->setDisplayField('attribute_value');
$this->setPrimaryKey('id');
$this->setTable('product_category_attribute_options');
$this->setDisplayField('attribute_value');
$this->setPrimaryKey('id');
$this->setEntityClass(
Configure::read('CakeProducts.ProductCategoryAttributeOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryAttributeOption')
);
$this->setEntityClass(
Configure::read('CakeProducts.ProductCategoryAttributeOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryAttributeOption'),
);
$this->belongsTo('ProductCategoryAttributes', [
'foreignKey' => 'product_category_attribute_id',
'joinType' => 'INNER',
'className' => 'CakeProducts.ProductCategoryAttributes',
]);
$this->belongsTo('ProductCategoryAttributes', [
'foreignKey' => 'product_category_attribute_id',
'joinType' => 'INNER',
'className' => 'CakeProducts.ProductCategoryAttributes',
]);
$this->addBehavior('Muffin/Trash.Trash');
}
$this->addBehavior('Muffin/Trash.Trash');
}
/**
/**
* Default validation rules.
*
* @param Validator $validator Validator instance.
* @return Validator
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->uuid('product_category_attribute_id')
->notEmptyString('product_category_attribute_id');
public function validationDefault(Validator $validator): Validator {
$validator
->uuid('product_category_attribute_id')
->notEmptyString('product_category_attribute_id');
$validator
->scalar('attribute_value')
->maxLength('attribute_value', 255)
->requirePresence('attribute_value', 'create')
->notEmptyString('attribute_value');
$validator
->scalar('attribute_value')
->maxLength('attribute_value', 255)
->requirePresence('attribute_value', 'create')
->notEmptyString('attribute_value');
$validator
->scalar('attribute_label')
->maxLength('attribute_label', 255)
->requirePresence('attribute_label', 'create')
->notEmptyString('attribute_label');
$validator
->scalar('attribute_label')
->maxLength('attribute_label', 255)
->requirePresence('attribute_label', 'create')
->notEmptyString('attribute_label');
$validator
->boolean('enabled')
->notEmptyString('enabled');
$validator
->boolean('enabled')
->notEmptyString('enabled');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
return $validator;
}
return $validator;
}
/**
/**
* Returns a rules checker object that will be used for validating
* application integrity.
*
* @param RulesChecker $rules The rules object to be modified.
* @return RulesChecker
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return \Cake\ORM\RulesChecker
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']);
$rules->add($rules->isUnique(['attribute_value', 'product_category_attribute_id']));
public function buildRules(RulesChecker $rules): RulesChecker {
$rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']);
$rules->add($rules->isUnique(['attribute_value', 'product_category_attribute_id']));
return $rules;
}
return $rules;
}
}
@@ -5,146 +5,141 @@ namespace CakeProducts\Model\Table;
use Cake\Core\Configure;
use Cake\Database\Type\EnumType;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductCategoryAttribute;
use CakeProducts\Model\Enum\ProductCategoryAttributeTypeId;
use Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ProductCategoryAttributes Model
*
* @property ProductCategoriesTable&BelongsTo $ProductCategories
*
* @method ProductCategoryAttribute newEmptyEntity()
* @method ProductCategoryAttribute newEntity(array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategoryAttribute newEmptyEntity()
* @method \CakeProducts\Model\Entity\ProductCategoryAttribute newEntity()
* @method array<ProductCategoryAttribute> newEntities(array $data, array $options = [])
* @method ProductCategoryAttribute get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductCategoryAttribute findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductCategoryAttribute patchEntity(EntityInterface $entity, array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategoryAttribute get()
* @method \CakeProducts\Model\Entity\ProductCategoryAttribute findOrCreate()
* @method \CakeProducts\Model\Entity\ProductCategoryAttribute patchEntity()
* @method array<ProductCategoryAttribute> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductCategoryAttribute|false save(EntityInterface $entity, array $options = [])
* @method ProductCategoryAttribute saveOrFail(EntityInterface $entity, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategoryAttribute saveOrFail()
* @method iterable<ProductCategoryAttribute>|ResultSetInterface<ProductCategoryAttribute>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryAttribute>|ResultSetInterface<ProductCategoryAttribute> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductCategoryAttribute>|ResultSetInterface<ProductCategoryAttribute>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryAttribute>|ResultSetInterface<ProductCategoryAttribute> deleteManyOrFail(iterable $entities, array $options = [])
*/
class ProductCategoryAttributesTable extends Table
{
/**
class ProductCategoryAttributesTable extends Table {
/**
* Initialize method
*
* @param array<string, mixed> $config The configuration for the Table.
* @return void
*/
public function initialize(array $config): void
{
parent::initialize($config);
public function initialize(array $config): void {
parent::initialize($config);
$this->setTable('product_category_attributes');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->setTable('product_category_attributes');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->setEntityClass(
Configure::read('CakeProducts.ProductCategoryAttributes.entity', 'CakeProducts\Model\Entity\ProductCategoryAttribute')
);
$this->belongsTo('ProductCategories', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductCategories',
]);
$this->setEntityClass(
Configure::read('CakeProducts.ProductCategoryAttributes.entity', 'CakeProducts\Model\Entity\ProductCategoryAttribute'),
);
$this->belongsTo('ProductCategories', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductCategories',
]);
$this->hasMany('ProductCategoryAttributeOptions', [
'foreignKey' => 'product_category_attribute_id',
'className' => 'CakeProducts.ProductCategoryAttributeOptions',
'saveStrategy' => 'replace',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->getSchema()->setColumnType('attribute_type_id', EnumType::from(ProductCategoryAttributeTypeId::class));
$this->hasMany('ProductCategoryAttributeOptions', [
'foreignKey' => 'product_category_attribute_id',
'className' => 'CakeProducts.ProductCategoryAttributeOptions',
'saveStrategy' => 'replace',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->getSchema()->setColumnType('attribute_type_id', EnumType::from(ProductCategoryAttributeTypeId::class));
$this->addBehavior('Muffin/Trash.Trash');
}
$this->addBehavior('Muffin/Trash.Trash');
}
/**
/**
* Default validation rules.
*
* @param Validator $validator Validator instance.
* @return Validator
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->scalar('name')
->maxLength('name', 255)
->requirePresence('name', 'create')
->notEmptyString('name');
public function validationDefault(Validator $validator): Validator {
$validator
->scalar('name')
->maxLength('name', 255)
->requirePresence('name', 'create')
->notEmptyString('name');
$validator
->uuid('product_category_id')
->allowEmptyString('product_category_id');
$validator
->uuid('product_category_id')
->allowEmptyString('product_category_id');
$validator
->integer('attribute_type_id')
->requirePresence('attribute_type_id', 'create')
->notEmptyString('attribute_type_id');
$validator
->integer('attribute_type_id')
->requirePresence('attribute_type_id', 'create')
->notEmptyString('attribute_type_id');
$validator
->boolean('enabled')
->requirePresence('enabled', 'create')
->notEmptyString('enabled');
$validator
->boolean('enabled')
->requirePresence('enabled', 'create')
->notEmptyString('enabled');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
return $validator;
}
return $validator;
}
/**
/**
* Returns a rules checker object that will be used for validating
* application integrity.
*
* @param RulesChecker $rules The rules object to be modified.
* @return RulesChecker
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return \Cake\ORM\RulesChecker
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->isUnique(['name', 'product_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'name']);
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
public function buildRules(RulesChecker $rules): RulesChecker {
$rules->add($rules->isUnique(['name', 'product_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'name']);
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
return $rules;
}
return $rules;
}
/**
* @param SelectQuery $query
/**
* @param \Cake\ORM\Query\SelectQuery $query
* @param string $internalCategoryId
*
* @return array|\Cake\ORM\Query|SelectQuery
* @return \Cake\ORM\Query|\Cake\ORM\Query\SelectQuery|array
*/
public function findAllCategoryAttributesForCategoryId(SelectQuery $query, string $internalCategoryId)
{
$category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail();
public function findAllCategoryAttributesForCategoryId(SelectQuery $query, string $internalCategoryId) {
$category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail();
$this->ProductCategories->behaviors()->get('Tree')->setConfig([
'scope' => [
'product_catalog_id' => $category->product_catalog_id ?? 1,
],
]);
$this->ProductCategories->behaviors()->get('Tree')->setConfig([
'scope' => [
'product_catalog_id' => $category->product_catalog_id ?? 1,
],
]);
return $this->ProductCategories
->find('path', for: $category->id)
->contain(['ProductCategoryAttributes', 'ProductCategoryAttributes.ProductCategoryAttributeOptions']);
}
/**
* @param string $internalCategoryId
* @return array|array[]|\Cake\Datasource\EntityInterface[]
*/
public function getAllCategoryAttributesForCategoryId(string $internalCategoryId) {
return $this->find('allCategoryAttributesForCategoryId', $internalCategoryId)->toArray();
}
return $this->ProductCategories
->find('path', for: $category->id)
->contain(['ProductCategoryAttributes', 'ProductCategoryAttributes.ProductCategoryAttributeOptions']);
}
public function getAllCategoryAttributesForCategoryId(string $internalCategoryId)
{
return $this->find('allCategoryAttributesForCategoryId', $internalCategoryId)->toArray();
}
}
@@ -4,33 +4,24 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table;
use Cake\Core\Configure;
use CakeProducts\Model\Entity\ProductCategoryVariantOption;
use CakeProducts\Model\Table\ProductCategoryVariantsTable;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Behavior\TimestampBehavior;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ProductCategoryVariantOptions Model
*
* @property ProductCategoryVariantsTable&BelongsTo $ProductCategoryVariants
*
* @method ProductCategoryVariantOption newEmptyEntity()
* @method ProductCategoryVariantOption newEntity(array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategoryVariantOption newEmptyEntity()
* @method \CakeProducts\Model\Entity\ProductCategoryVariantOption newEntity()
* @method array<ProductCategoryVariantOption> newEntities(array $data, array $options = [])
* @method ProductCategoryVariantOption get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductCategoryVariantOption findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductCategoryVariantOption patchEntity(EntityInterface $entity, array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategoryVariantOption get()
* @method \CakeProducts\Model\Entity\ProductCategoryVariantOption findOrCreate()
* @method \CakeProducts\Model\Entity\ProductCategoryVariantOption patchEntity()
* @method array<ProductCategoryVariantOption> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductCategoryVariantOption|false save(EntityInterface $entity, array $options = [])
* @method ProductCategoryVariantOption saveOrFail(EntityInterface $entity, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategoryVariantOption saveOrFail()
* @method iterable<ProductCategoryVariantOption>|ResultSetInterface<ProductCategoryVariantOption>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryVariantOption>|ResultSetInterface<ProductCategoryVariantOption> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductCategoryVariantOption>|ResultSetInterface<ProductCategoryVariantOption>|false deleteMany(iterable $entities, array $options = [])
@@ -38,75 +29,73 @@ use Psr\SimpleCache\CacheInterface;
*
* @mixin TimestampBehavior
*/
class ProductCategoryVariantOptionsTable extends Table
{
/**
class ProductCategoryVariantOptionsTable extends Table {
/**
* Initialize method
*
* @param array<string, mixed> $config The configuration for the Table.
* @return void
*/
public function initialize(array $config): void
{
parent::initialize($config);
public function initialize(array $config): void {
parent::initialize($config);
$this->setTable('product_category_variant_options');
$this->setDisplayField('variant_value');
$this->setPrimaryKey('id');
$this->setTable('product_category_variant_options');
$this->setDisplayField('variant_value');
$this->setPrimaryKey('id');
$this->setEntityClass(
Configure::read('CakeProducts.ProductCategoryVariantOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryVariantOption')
);
$this->addBehavior('Timestamp');
$this->setEntityClass(
Configure::read('CakeProducts.ProductCategoryVariantOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryVariantOption'),
);
$this->addBehavior('Timestamp');
$this->belongsTo('ProductCategoryVariants', [
'foreignKey' => 'product_category_variant_id',
'joinType' => 'INNER',
]);
}
$this->belongsTo('ProductCategoryVariants', [
'foreignKey' => 'product_category_variant_id',
'joinType' => 'INNER',
]);
}
/**
/**
* Default validation rules.
*
* @param Validator $validator Validator instance.
* @return Validator
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->uuid('product_category_variant_id')
->notEmptyString('product_category_variant_id');
public function validationDefault(Validator $validator): Validator {
$validator
->uuid('product_category_variant_id')
->notEmptyString('product_category_variant_id');
$validator
->scalar('variant_value')
->maxLength('variant_value', 255)
->requirePresence('variant_value', 'create')
->notEmptyString('variant_value');
$validator
->scalar('variant_value')
->maxLength('variant_value', 255)
->requirePresence('variant_value', 'create')
->notEmptyString('variant_value');
$validator
->scalar('variant_label')
->maxLength('variant_label', 255)
->allowEmptyString('variant_label');
$validator
->scalar('variant_label')
->maxLength('variant_label', 255)
->allowEmptyString('variant_label');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
return $validator;
}
return $validator;
}
/**
/**
* Returns a rules checker object that will be used for validating
* application integrity.
*
* @param RulesChecker $rules The rules object to be modified.
* @return RulesChecker
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return \Cake\ORM\RulesChecker
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->existsIn(['product_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']);
$rules->add($rules->isUnique(['variant_value', 'product_category_variant_id']));
public function buildRules(RulesChecker $rules): RulesChecker {
$rules->add($rules->existsIn(['product_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']);
$rules->add($rules->isUnique(['variant_value', 'product_category_variant_id']));
return $rules;
}
return $rules;
}
}
+93 -104
View File
@@ -4,17 +4,10 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table;
use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Query;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductCategoryVariant;
use Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ProductCategoryVariants Model
@@ -22,143 +15,139 @@ use Psr\SimpleCache\CacheInterface;
* @property ProductCategoriesTable&BelongsTo $ProductCategories
* @property ProductsTable&BelongsTo $Products
*
* @method ProductCategoryVariant newEmptyEntity()
* @method ProductCategoryVariant newEntity(array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategoryVariant newEmptyEntity()
* @method \CakeProducts\Model\Entity\ProductCategoryVariant newEntity()
* @method array<ProductCategoryVariant> newEntities(array $data, array $options = [])
* @method ProductCategoryVariant get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductCategoryVariant findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductCategoryVariant patchEntity(EntityInterface $entity, array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategoryVariant get()
* @method \CakeProducts\Model\Entity\ProductCategoryVariant findOrCreate()
* @method \CakeProducts\Model\Entity\ProductCategoryVariant patchEntity()
* @method array<ProductCategoryVariant> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductCategoryVariant|false save(EntityInterface $entity, array $options = [])
* @method ProductCategoryVariant saveOrFail(EntityInterface $entity, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategoryVariant saveOrFail()
* @method iterable<ProductCategoryVariant>|ResultSetInterface<ProductCategoryVariant>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryVariant>|ResultSetInterface<ProductCategoryVariant> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductCategoryVariant>|ResultSetInterface<ProductCategoryVariant>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryVariant>|ResultSetInterface<ProductCategoryVariant> deleteManyOrFail(iterable $entities, array $options = [])
*/
class ProductCategoryVariantsTable extends Table
{
/**
class ProductCategoryVariantsTable extends Table {
/**
* Initialize method
*
* @param array<string, mixed> $config The configuration for the Table.
* @return void
*/
public function initialize(array $config): void
{
parent::initialize($config);
public function initialize(array $config): void {
parent::initialize($config);
$this->setTable('product_category_variants');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->setTable('product_category_variants');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->setEntityClass(
Configure::read('CakeProducts.ProductCategoryVariants.entity', 'CakeProducts\Model\Entity\ProductCategoryVariant')
);
$this->setEntityClass(
Configure::read('CakeProducts.ProductCategoryVariants.entity', 'CakeProducts\Model\Entity\ProductCategoryVariant'),
);
$this->belongsTo('ProductCategories', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductCategories',
]);
$this->belongsTo('Products', [
'foreignKey' => 'product_id',
'className' => 'CakeProducts.Products',
]);
$this->hasMany('ProductCategoryVariantOptions', [
'foreignKey' => 'product_category_variant_id',
'className' => 'CakeProducts.ProductCategoryVariantOptions',
'dependent' => true,
'cascadeCallbacks' => true,
'saveStrategy' => 'replace',
]);
$this->belongsTo('ProductCategories', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductCategories',
]);
$this->belongsTo('Products', [
'foreignKey' => 'product_id',
'className' => 'CakeProducts.Products',
]);
$this->hasMany('ProductCategoryVariantOptions', [
'foreignKey' => 'product_category_variant_id',
'className' => 'CakeProducts.ProductCategoryVariantOptions',
'dependent' => true,
'cascadeCallbacks' => true,
'saveStrategy' => 'replace',
]);
$this->hasMany('ProductVariants', [
'foreignKey' => 'product_category_variant_id',
'className' => 'CakeProducts.ProductVariants',
'dependent' => true,
'cascadeCallbacks' => true,
]);
}
$this->hasMany('ProductVariants', [
'foreignKey' => 'product_category_variant_id',
'className' => 'CakeProducts.ProductVariants',
'dependent' => true,
'cascadeCallbacks' => true,
]);
}
/**
/**
* Default validation rules.
*
* @param Validator $validator Validator instance.
* @return Validator
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->scalar('name')
->maxLength('name', 255)
->requirePresence('name', 'create')
->notEmptyString('name');
public function validationDefault(Validator $validator): Validator {
$validator
->scalar('name')
->maxLength('name', 255)
->requirePresence('name', 'create')
->notEmptyString('name');
$validator
->uuid('product_category_id')
->allowEmptyString('product_category_id');
$validator
->uuid('product_category_id')
->allowEmptyString('product_category_id');
$validator
->uuid('product_id')
->allowEmptyString('product_id');
$validator
->uuid('product_id')
->allowEmptyString('product_id');
$validator
->boolean('is_system_variant')
->allowEmptyString('is_system_variant');
$validator
->boolean('is_system_variant')
->allowEmptyString('is_system_variant');
$validator
->boolean('enabled')
->requirePresence('enabled', 'create')
->notEmptyString('enabled');
$validator
->boolean('enabled')
->requirePresence('enabled', 'create')
->notEmptyString('enabled');
return $validator;
}
return $validator;
}
/**
/**
* Returns a rules checker object that will be used for validating
* application integrity.
*
* @param RulesChecker $rules The rules object to be modified.
* @return RulesChecker
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return \Cake\ORM\RulesChecker
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->isUnique(['name', 'product_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_category_id']);
$rules->add($rules->isUnique(['name', 'product_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_id']);
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
public function buildRules(RulesChecker $rules): RulesChecker {
$rules->add($rules->isUnique(['name', 'product_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_category_id']);
$rules->add($rules->isUnique(['name', 'product_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_id']);
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
return $rules;
}
return $rules;
}
/**
* @param SelectQuery $query
/**
* @param \Cake\ORM\Query\SelectQuery $query
* @param string $internalCategoryId
*
* @return array|Query|SelectQuery
* @return Query|\Cake\ORM\Query\SelectQuery|array
*/
public function findAllCategoryVariantsForCategoryId(SelectQuery $query, string $internalCategoryId)
{
$category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail();
public function findAllCategoryVariantsForCategoryId(SelectQuery $query, string $internalCategoryId) {
$category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail();
$this->ProductCategories->behaviors()->get('Tree')->setConfig([
'scope' => [
'product_catalog_id' => $category->product_catalog_id ?? 1,
],
]);
$this->ProductCategories->behaviors()->get('Tree')->setConfig([
'scope' => [
'product_catalog_id' => $category->product_catalog_id ?? 1,
],
]);
return $this->ProductCategories
->find('path', for: $category->id)
->contain(['ProductCategoryVariants']);
}
return $this->ProductCategories
->find('path', for: $category->id)
->contain(['ProductCategoryVariants']);
}
/**
/**
* @param string $internalCategoryId
* @return array
*/
public function getAllCategoryVariantsForCategoryId(string $internalCategoryId)
{
return $this->find('allCategoryVariantsForCategoryId', $internalCategoryId)->toArray();
}
public function getAllCategoryVariantsForCategoryId(string $internalCategoryId) {
return $this->find('allCategoryVariantsForCategoryId', $internalCategoryId)->toArray();
}
}
+106 -115
View File
@@ -4,16 +4,9 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table;
use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Behavior\TimestampBehavior;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductPhoto;
use Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ProductPhotos Model
@@ -21,15 +14,15 @@ use Psr\SimpleCache\CacheInterface;
* @property ProductsTable&BelongsTo $Products
* @property ProductSkusTable&BelongsTo $ProductSkus
*
* @method ProductPhoto newEmptyEntity()
* @method ProductPhoto newEntity(array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductPhoto newEmptyEntity()
* @method \CakeProducts\Model\Entity\ProductPhoto newEntity()
* @method array<ProductPhoto> newEntities(array $data, array $options = [])
* @method ProductPhoto get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductPhoto findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductPhoto patchEntity(EntityInterface $entity, array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductPhoto get()
* @method \CakeProducts\Model\Entity\ProductPhoto findOrCreate()
* @method \CakeProducts\Model\Entity\ProductPhoto patchEntity()
* @method array<ProductPhoto> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductPhoto|false save(EntityInterface $entity, array $options = [])
* @method ProductPhoto saveOrFail(EntityInterface $entity, array $options = [])
* @method \CakeProducts\Model\Entity\ProductPhoto saveOrFail()
* @method iterable<ProductPhoto>|ResultSetInterface<ProductPhoto>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductPhoto>|ResultSetInterface<ProductPhoto> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductPhoto>|ResultSetInterface<ProductPhoto>|false deleteMany(iterable $entities, array $options = [])
@@ -37,136 +30,134 @@ use Psr\SimpleCache\CacheInterface;
*
* @mixin TimestampBehavior
*/
class ProductPhotosTable extends Table
{
/**
class ProductPhotosTable extends Table {
/**
* Initialize method
*
* @param array<string, mixed> $config The configuration for the Table.
* @return void
*/
public function initialize(array $config): void
{
parent::initialize($config);
public function initialize(array $config): void {
parent::initialize($config);
$this->setTable('product_photos');
$this->setDisplayField('photo_filename');
$this->setPrimaryKey('id');
$this->setTable('product_photos');
$this->setDisplayField('photo_filename');
$this->setPrimaryKey('id');
$this->setEntityClass(
Configure::read('CakeProducts.ProductPhotos.entity', 'CakeProducts\Model\Entity\ProductPhoto')
);
$this->setEntityClass(
Configure::read('CakeProducts.ProductPhotos.entity', 'CakeProducts\Model\Entity\ProductPhoto'),
);
$this->addBehavior('Timestamp');
$this->addBehavior('Timestamp');
$this->addBehavior('Tools.Toggle', [
'field' => 'primary_category_photo',
'scopeFields' => ['product_category_id'],
'scope' => [
'deleted IS' => null,
],
]);
$this->addBehavior('CakeProducts.SecondToggle', [
'field' => 'primary_photo',
'scopeFields' => ['product_id'],
'scope' => [
'deleted IS' => null,
'product_id IS NOT' => null,
],
]);
$this->addBehavior('CakeProducts.ThirdToggle', [
'field' => 'primary_sku_photo',
'scopeFields' => ['product_sku_id'],
'scope' => [
'deleted IS' => null,
'product_sku_id IS NOT' => null,
],
]);
$this->belongsTo('Products', [
'foreignKey' => 'product_id',
'joinType' => 'LEFT',
'className' => 'CakeProducts.Products',
]);
$this->addBehavior('Tools.Toggle', [
'field' => 'primary_category_photo',
'scopeFields' => ['product_category_id'],
'scope' => [
'deleted IS' => null,
],
]);
$this->addBehavior('CakeProducts.SecondToggle', [
'field' => 'primary_photo',
'scopeFields' => ['product_id'],
'scope' => [
'deleted IS' => null,
'product_id IS NOT' => null,
],
]);
$this->addBehavior('CakeProducts.ThirdToggle', [
'field' => 'primary_sku_photo',
'scopeFields' => ['product_sku_id'],
'scope' => [
'deleted IS' => null,
'product_sku_id IS NOT' => null,
],
]);
$this->belongsTo('Products', [
'foreignKey' => 'product_id',
'joinType' => 'LEFT',
'className' => 'CakeProducts.Products',
]);
$this->belongsTo('ProductCategories', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'joinType' => 'INNER',
'className' => 'CakeProducts.ProductCategories',
]);
$this->belongsTo('ProductCategories', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'joinType' => 'INNER',
'className' => 'CakeProducts.ProductCategories',
]);
$this->belongsTo('ProductSkus', [
'foreignKey' => 'product_sku_id',
'joinType' => 'LEFT',
'className' => 'CakeProducts.ProductSkus',
]);
}
$this->belongsTo('ProductSkus', [
'foreignKey' => 'product_sku_id',
'joinType' => 'LEFT',
'className' => 'CakeProducts.ProductSkus',
]);
}
/**
/**
* Default validation rules.
*
* @param Validator $validator Validator instance.
* @return Validator
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->uuid('product_id')
->allowEmptyString('product_id');
public function validationDefault(Validator $validator): Validator {
$validator
->uuid('product_id')
->allowEmptyString('product_id');
$validator
->uuid('product_sku_id')
->allowEmptyString('product_sku_id');
$validator
->uuid('product_sku_id')
->allowEmptyString('product_sku_id');
$validator
->uuid('product_category_id')
->requirePresence('product_category_id', 'create')
->notEmptyString('product_category_id');
$validator
->uuid('product_category_id')
->requirePresence('product_category_id', 'create')
->notEmptyString('product_category_id');
$validator
->scalar('photo_dir')
->maxLength('photo_dir', 255)
->requirePresence('photo_dir', 'create')
->notEmptyString('photo_dir');
$validator
->scalar('photo_dir')
->maxLength('photo_dir', 255)
->requirePresence('photo_dir', 'create')
->notEmptyString('photo_dir');
$validator
->scalar('photo_filename')
->maxLength('photo_filename', 255)
->requirePresence('photo_filename', 'create')
->notEmptyString('photo_filename');
$validator
->scalar('photo_filename')
->maxLength('photo_filename', 255)
->requirePresence('photo_filename', 'create')
->notEmptyString('photo_filename');
$validator
->boolean('primary_photo')
->notEmptyString('primary_photo');
$validator
->boolean('primary_photo')
->notEmptyString('primary_photo');
$validator
->integer('photo_position')
->notEmptyString('photo_position');
$validator
->integer('photo_position')
->notEmptyString('photo_position');
$validator
->boolean('enabled')
->notEmptyString('enabled');
$validator
->boolean('enabled')
->notEmptyString('enabled');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
return $validator;
}
return $validator;
}
/**
/**
* Returns a rules checker object that will be used for validating
* application integrity.
*
* @param RulesChecker $rules The rules object to be modified.
* @return RulesChecker
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return \Cake\ORM\RulesChecker
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
$rules->add($rules->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']);
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
public function buildRules(RulesChecker $rules): RulesChecker {
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
$rules->add($rules->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']);
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
return $rules;
}
return $rules;
}
}
@@ -3,16 +3,9 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductSkuVariantValue;
use Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ProductSkuVariantValues Model
@@ -21,92 +14,90 @@ use Psr\SimpleCache\CacheInterface;
* @property ProductCategoryVariantsTable&BelongsTo $ProductCategoryVariants
* @property ProductCategoryVariantOptionsTable&BelongsTo $ProductCategoryVariantOptions
*
* @method ProductSkuVariantValue newEmptyEntity()
* @method ProductSkuVariantValue newEntity(array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductSkuVariantValue newEmptyEntity()
* @method \CakeProducts\Model\Entity\ProductSkuVariantValue newEntity()
* @method array<ProductSkuVariantValue> newEntities(array $data, array $options = [])
* @method ProductSkuVariantValue get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductSkuVariantValue findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductSkuVariantValue patchEntity(EntityInterface $entity, array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductSkuVariantValue get()
* @method \CakeProducts\Model\Entity\ProductSkuVariantValue findOrCreate()
* @method \CakeProducts\Model\Entity\ProductSkuVariantValue patchEntity()
* @method array<ProductSkuVariantValue> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductSkuVariantValue|false save(EntityInterface $entity, array $options = [])
* @method ProductSkuVariantValue saveOrFail(EntityInterface $entity, array $options = [])
* @method \CakeProducts\Model\Entity\ProductSkuVariantValue saveOrFail()
* @method iterable<ProductSkuVariantValue>|ResultSetInterface<ProductSkuVariantValue>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductSkuVariantValue>|ResultSetInterface<ProductSkuVariantValue> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductSkuVariantValue>|ResultSetInterface<ProductSkuVariantValue>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductSkuVariantValue>|ResultSetInterface<ProductSkuVariantValue> deleteManyOrFail(iterable $entities, array $options = [])
*/
class ProductSkuVariantValuesTable extends Table
{
/**
class ProductSkuVariantValuesTable extends Table {
/**
* Initialize method
*
* @param array<string, mixed> $config The configuration for the Table.
* @return void
*/
public function initialize(array $config): void
{
parent::initialize($config);
public function initialize(array $config): void {
parent::initialize($config);
$this->setTable('product_sku_variant_values');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->setTable('product_sku_variant_values');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->belongsTo('ProductSkus', [
'className' => 'CakeProducts.ProductSkus',
'foreignKey' => 'product_sku_id',
'propertyName' => 'product_sku',
'joinType' => 'INNER',
]);
$this->belongsTo('ProductVariants', [
'className' => 'CakeProducts.ProductVariants',
'foreignKey' => 'product_variant_id',
'joinType' => 'INNER',
]);
$this->belongsTo('ProductCategoryVariantOptions', [
'className' => 'CakeProducts.ProductCategoryVariantOptions',
'foreignKey' => 'product_category_variant_option_id',
'joinType' => 'INNER',
]);
}
$this->belongsTo('ProductSkus', [
'className' => 'CakeProducts.ProductSkus',
'foreignKey' => 'product_sku_id',
'propertyName' => 'product_sku',
'joinType' => 'INNER',
]);
$this->belongsTo('ProductVariants', [
'className' => 'CakeProducts.ProductVariants',
'foreignKey' => 'product_variant_id',
'joinType' => 'INNER',
]);
$this->belongsTo('ProductCategoryVariantOptions', [
'className' => 'CakeProducts.ProductCategoryVariantOptions',
'foreignKey' => 'product_category_variant_option_id',
'joinType' => 'INNER',
]);
}
/**
/**
* Default validation rules.
*
* @param Validator $validator Validator instance.
* @return Validator
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->uuid('product_sku_id')
->notEmptyString('product_sku_id');
public function validationDefault(Validator $validator): Validator {
$validator
->uuid('product_sku_id')
->notEmptyString('product_sku_id');
$validator
->uuid('product_variant_id')
->notEmptyString('product_variant_id');
$validator
->uuid('product_variant_id')
->notEmptyString('product_variant_id');
$validator
->uuid('product_category_variant_option_id')
->notEmptyString('product_category_variant_option_id');
$validator
->uuid('product_category_variant_option_id')
->notEmptyString('product_category_variant_option_id');
return $validator;
}
return $validator;
}
/**
/**
* Returns a rules checker object that will be used for validating
* application integrity.
*
* @param RulesChecker $rules The rules object to be modified.
* @return RulesChecker
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return \Cake\ORM\RulesChecker
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']);
public function buildRules(RulesChecker $rules): RulesChecker {
$rules->add($rules->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']);
// @TODO why not working?? causing tests to fail / associated variant values not saving on product-skus/add
$rules->add($rules->existsIn(['product_variant_id'], 'ProductVariants'), ['errorField' => 'product_variant_id']);
$rules->add($rules->existsIn(['product_category_variant_option_id'], 'ProductCategoryVariantOptions'), ['errorField' => 'product_category_variant_option_id']);
// @TODO why not working?? causing tests to fail / associated variant values not saving on product-skus/add
$rules->add($rules->existsIn(['product_variant_id'], 'ProductVariants'), ['errorField' => 'product_variant_id']);
$rules->add($rules->existsIn(['product_category_variant_option_id'], 'ProductCategoryVariantOptions'), ['errorField' => 'product_category_variant_option_id']);
return $rules;
}
return $rules;
}
}
+86 -97
View File
@@ -4,33 +4,24 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table;
use Cake\Core\Configure;
use Cake\ORM\Query\SelectQuery;
use CakeProducts\Model\Table\ProductsTable;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Behavior\TimestampBehavior;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductSku;
use Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ProductSkus Model
*
* @property ProductsTable&BelongsTo $Products
*
* @method ProductSku newEmptyEntity()
* @method ProductSku newEntity(array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductSku newEmptyEntity()
* @method \CakeProducts\Model\Entity\ProductSku newEntity()
* @method array<ProductSku> newEntities(array $data, array $options = [])
* @method ProductSku get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductSku findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductSku patchEntity(EntityInterface $entity, array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductSku get()
* @method \CakeProducts\Model\Entity\ProductSku findOrCreate()
* @method \CakeProducts\Model\Entity\ProductSku patchEntity()
* @method array<ProductSku> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductSku|false save(EntityInterface $entity, array $options = [])
* @method ProductSku saveOrFail(EntityInterface $entity, array $options = [])
* @method \CakeProducts\Model\Entity\ProductSku saveOrFail()
* @method iterable<ProductSku>|ResultSetInterface<ProductSku>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductSku>|ResultSetInterface<ProductSku> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductSku>|ResultSetInterface<ProductSku>|false deleteMany(iterable $entities, array $options = [])
@@ -38,114 +29,112 @@ use Psr\SimpleCache\CacheInterface;
*
* @mixin TimestampBehavior
*/
class ProductSkusTable extends Table
{
/**
class ProductSkusTable extends Table {
/**
* Initialize method
*
* @param array<string, mixed> $config The configuration for the Table.
* @return void
*/
public function initialize(array $config): void
{
parent::initialize($config);
public function initialize(array $config): void {
parent::initialize($config);
$this->setTable('product_skus');
$this->setDisplayField('sku');
$this->setPrimaryKey('id');
$this->setTable('product_skus');
$this->setDisplayField('sku');
$this->setPrimaryKey('id');
$this->setEntityClass(
Configure::read('CakeProducts.ProductSkus.entity', 'CakeProducts\Model\Entity\ProductSku')
);
$this->setEntityClass(
Configure::read('CakeProducts.ProductSkus.entity', 'CakeProducts\Model\Entity\ProductSku'),
);
$this->addBehavior('Timestamp');
$this->addBehavior('Tools.Toggle', [
'field' => 'default_sku',
'scopeFields' => ['product_id'],
'scope' => [
'deleted IS' => null,
],
]);
$this->addBehavior('Timestamp');
$this->addBehavior('Tools.Toggle', [
'field' => 'default_sku',
'scopeFields' => ['product_id'],
'scope' => [
'deleted IS' => null,
],
]);
$this->belongsTo('Products', [
'className' => 'CakeProducts.Products',
'foreignKey' => 'product_id',
'joinType' => 'INNER',
]);
$this->belongsTo('Products', [
'className' => 'CakeProducts.Products',
'foreignKey' => 'product_id',
'joinType' => 'INNER',
]);
$this->hasMany('ProductSkuVariantValues', [
'foreignKey' => 'product_sku_id',
'className' => 'CakeProducts.ProductSkuVariantValues',
'saveStrategy' => 'replace',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ProductSkuVariantValues', [
'foreignKey' => 'product_sku_id',
'className' => 'CakeProducts.ProductSkuVariantValues',
'saveStrategy' => 'replace',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ProductPhotos', [
'foreignKey' => 'product_sku_id',
'className' => 'CakeProducts.ProductPhotos',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ProductPhotos', [
'foreignKey' => 'product_sku_id',
'className' => 'CakeProducts.ProductPhotos',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasOne('PrimaryProductPhotos', [
'foreignKey' => 'product_sku_id',
'conditions' => ['PrimaryProductPhotos.primary_photo' => true],
'className' => 'CakeProducts.ProductPhotos',
'dependent' => true,
]);
}
$this->hasOne('PrimaryProductPhotos', [
'foreignKey' => 'product_sku_id',
'conditions' => ['PrimaryProductPhotos.primary_photo' => true],
'className' => 'CakeProducts.ProductPhotos',
'dependent' => true,
]);
}
/**
/**
* Default validation rules.
*
* @param Validator $validator Validator instance.
* @return Validator
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->uuid('product_id')
->notEmptyString('product_id');
public function validationDefault(Validator $validator): Validator {
$validator
->uuid('product_id')
->notEmptyString('product_id');
$validator
->scalar('sku')
->maxLength('sku', 255)
->requirePresence('sku', 'create')
->notEmptyString('sku');
$validator
->scalar('sku')
->maxLength('sku', 255)
->requirePresence('sku', 'create')
->notEmptyString('sku');
$validator
->scalar('barcode')
->maxLength('barcode', 255)
->allowEmptyString('barcode');
$validator
->scalar('barcode')
->maxLength('barcode', 255)
->allowEmptyString('barcode');
$validator
->decimal('price')
->allowEmptyString('price');
$validator
->decimal('price')
->allowEmptyString('price');
$validator
->decimal('cost')
->allowEmptyString('cost');
$validator
->decimal('cost')
->allowEmptyString('cost');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
return $validator;
}
return $validator;
}
/**
/**
* Returns a rules checker object that will be used for validating
* application integrity.
*
* @param RulesChecker $rules The rules object to be modified.
* @return RulesChecker
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return \Cake\ORM\RulesChecker
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
$rules->add($rules->isUnique(['sku'], 'SKU must be unique'), ['errorField' => 'sku']);
public function buildRules(RulesChecker $rules): RulesChecker {
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
$rules->add($rules->isUnique(['sku'], 'SKU must be unique'), ['errorField' => 'sku']);
return $rules;
}
return $rules;
}
}
+60 -71
View File
@@ -3,18 +3,9 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table;
use CakeProducts\Model\Entity\ProductVariant;
use CakeProducts\Model\Table\ProductCategoryVariantsTable;
use CakeProducts\Model\Table\ProductsTable;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ProductVariants Model
@@ -22,96 +13,94 @@ use Psr\SimpleCache\CacheInterface;
* @property ProductCategoryVariantsTable&BelongsTo $ProductCategoryVariants
* @property ProductsTable&BelongsTo $Products
*
* @method ProductVariant newEmptyEntity()
* @method ProductVariant newEntity(array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductVariant newEmptyEntity()
* @method \CakeProducts\Model\Entity\ProductVariant newEntity()
* @method array<ProductVariant> newEntities(array $data, array $options = [])
* @method ProductVariant get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductVariant findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductVariant patchEntity(EntityInterface $entity, array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductVariant get()
* @method \CakeProducts\Model\Entity\ProductVariant findOrCreate()
* @method \CakeProducts\Model\Entity\ProductVariant patchEntity()
* @method array<ProductVariant> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductVariant|false save(EntityInterface $entity, array $options = [])
* @method ProductVariant saveOrFail(EntityInterface $entity, array $options = [])
* @method \CakeProducts\Model\Entity\ProductVariant saveOrFail()
* @method iterable<ProductVariant>|ResultSetInterface<ProductVariant>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductVariant>|ResultSetInterface<ProductVariant> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductVariant>|ResultSetInterface<ProductVariant>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductVariant>|ResultSetInterface<ProductVariant> deleteManyOrFail(iterable $entities, array $options = [])
*/
class ProductVariantsTable extends Table
{
/**
class ProductVariantsTable extends Table {
/**
* Initialize method
*
* @param array<string, mixed> $config The configuration for the Table.
* @return void
*/
public function initialize(array $config): void
{
parent::initialize($config);
public function initialize(array $config): void {
parent::initialize($config);
$this->setTable('product_variants');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->setTable('product_variants');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->belongsTo('ProductCategoryVariants', [
'className' => 'CakeProducts.ProductCategoryVariants',
'foreignKey' => 'product_category_variant_id',
]);
$this->belongsTo('Products', [
'className' => 'CakeProducts.Products',
'foreignKey' => 'product_id',
'joinType' => 'INNER',
]);
$this->belongsTo('ProductCategoryVariants', [
'className' => 'CakeProducts.ProductCategoryVariants',
'foreignKey' => 'product_category_variant_id',
]);
$this->belongsTo('Products', [
'className' => 'CakeProducts.Products',
'foreignKey' => 'product_id',
'joinType' => 'INNER',
]);
$this->hasMany('ProductSkuVariantValues', [
'className' => 'CakeProducts.ProductSkuVariantValues',
'foreignKey' => 'product_variant_id',
'dependent' => true,
'cascadeCallbacks' => true,
]);
}
$this->hasMany('ProductSkuVariantValues', [
'className' => 'CakeProducts.ProductSkuVariantValues',
'foreignKey' => 'product_variant_id',
'dependent' => true,
'cascadeCallbacks' => true,
]);
}
/**
/**
* Default validation rules.
*
* @param Validator $validator Validator instance.
* @return Validator
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->scalar('name')
->maxLength('name', 255)
->requirePresence('name', 'create')
->notEmptyString('name');
public function validationDefault(Validator $validator): Validator {
$validator
->scalar('name')
->maxLength('name', 255)
->requirePresence('name', 'create')
->notEmptyString('name');
$validator
->uuid('product_category_variant_id')
->allowEmptyString('product_category_variant_id');
$validator
->uuid('product_category_variant_id')
->allowEmptyString('product_category_variant_id');
$validator
->uuid('product_id')
->notEmptyString('product_id');
$validator
->uuid('product_id')
->notEmptyString('product_id');
$validator
->boolean('enabled')
->requirePresence('enabled', 'create')
->notEmptyString('enabled');
$validator
->boolean('enabled')
->requirePresence('enabled', 'create')
->notEmptyString('enabled');
return $validator;
}
return $validator;
}
/**
/**
* Returns a rules checker object that will be used for validating
* application integrity.
*
* @param RulesChecker $rules The rules object to be modified.
* @return RulesChecker
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return \Cake\ORM\RulesChecker
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->existsIn(['product_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']);
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
public function buildRules(RulesChecker $rules): RulesChecker {
$rules->add($rules->existsIn(['product_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']);
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
return $rules;
}
return $rules;
}
}
+92 -101
View File
@@ -5,154 +5,145 @@ namespace CakeProducts\Model\Table;
use Cake\Core\Configure;
use Cake\Database\Type\EnumType;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use CakeProducts\Model\Entity\Product;
use CakeProducts\Model\Enum\ProductProductTypeId;
use Closure;
use Psr\SimpleCache\CacheInterface;
/**
* Products Model
*
* @property ProductCategoriesTable&BelongsTo $ProductCategories
*
* @method Product newEmptyEntity()
* @method Product newEntity(array $data, array $options = [])
* @method \CakeProducts\Model\Entity\Product newEmptyEntity()
* @method \CakeProducts\Model\Entity\Product newEntity()
* @method array<Product> newEntities(array $data, array $options = [])
* @method Product get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
* @method Product findOrCreate($search, ?callable $callback = null, array $options = [])
* @method Product patchEntity(EntityInterface $entity, array $data, array $options = [])
* @method \CakeProducts\Model\Entity\Product get()
* @method \CakeProducts\Model\Entity\Product findOrCreate()
* @method \CakeProducts\Model\Entity\Product patchEntity()
* @method array<Product> patchEntities(iterable $entities, array $data, array $options = [])
* @method Product|false save(EntityInterface $entity, array $options = [])
* @method Product saveOrFail(EntityInterface $entity, array $options = [])
* @method \CakeProducts\Model\Entity\Product saveOrFail()
* @method iterable<Product>|ResultSetInterface<Product>|false saveMany(iterable $entities, array $options = [])
* @method iterable<Product>|ResultSetInterface<Product> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<Product>|ResultSetInterface<Product>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<Product>|ResultSetInterface<Product> deleteManyOrFail(iterable $entities, array $options = [])
*/
class ProductsTable extends Table
{
/**
class ProductsTable extends Table {
/**
* Initialize method
*
* @param array<string, mixed> $config The configuration for the Table.
* @return void
*/
public function initialize(array $config): void
{
parent::initialize($config);
public function initialize(array $config): void {
parent::initialize($config);
$this->setTable('products');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->setTable('products');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->setEntityClass(
Configure::read('CakeProducts.Products.entity', 'CakeProducts\Model\Entity\Product')
);
$this->setEntityClass(
Configure::read('CakeProducts.Products.entity', 'CakeProducts\Model\Entity\Product'),
);
$this->belongsTo('ProductCategories', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'joinType' => 'INNER',
'className' => 'CakeProducts.ProductCategories',
]);
$this->belongsTo('ProductCategories', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'joinType' => 'INNER',
'className' => 'CakeProducts.ProductCategories',
]);
$this->hasMany('ProductAttributes', [
'className' => 'CakeProducts.ProductAttributes',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ProductAttributes', [
'className' => 'CakeProducts.ProductAttributes',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ProductVariants', [
'foreignKey' => 'product_id',
'className' => 'CakeProducts.ProductVariants',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ProductVariants', [
'foreignKey' => 'product_id',
'className' => 'CakeProducts.ProductVariants',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ProductSkus', [
'foreignKey' => 'product_id',
'className' => 'CakeProducts.ProductSkus',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ProductSkus', [
'foreignKey' => 'product_id',
'className' => 'CakeProducts.ProductSkus',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ProductPhotos', [
'foreignKey' => 'product_id',
'className' => 'CakeProducts.ProductPhotos',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ProductPhotos', [
'foreignKey' => 'product_id',
'className' => 'CakeProducts.ProductPhotos',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasOne('PrimaryProductPhotos', [
'foreignKey' => 'product_id',
'conditions' => ['PrimaryProductPhotos.primary_photo' => true],
'className' => 'CakeProducts.ProductPhotos',
'dependent' => true,
]);
$this->hasOne('PrimaryProductPhotos', [
'foreignKey' => 'product_id',
'conditions' => ['PrimaryProductPhotos.primary_photo' => true],
'className' => 'CakeProducts.ProductPhotos',
'dependent' => true,
]);
$this->hasOne('DefaultProductSkus', [
'foreignKey' => 'product_id',
'conditions' => ['DefaultProductSkus.default_sku' => true],
'className' => 'CakeProducts.ProductSkus',
'propertyName' => 'default_product_sku',
'dependent' => true,
]);
$this->hasOne('DefaultProductSkus', [
'foreignKey' => 'product_id',
'conditions' => ['DefaultProductSkus.default_sku' => true],
'className' => 'CakeProducts.ProductSkus',
'propertyName' => 'default_product_sku',
'dependent' => true,
]);
$this->getSchema()->setColumnType('product_type_id', EnumType::from(ProductProductTypeId::class));
$this->getSchema()->setColumnType('product_type_id', EnumType::from(ProductProductTypeId::class));
$this->addBehavior('Muffin/Trash.Trash');
}
$this->addBehavior('Muffin/Trash.Trash');
}
/**
/**
* Default validation rules.
*
* @param Validator $validator Validator instance.
* @return Validator
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->scalar('name')
->maxLength('name', 255)
->requirePresence('name', 'create')
->notEmptyString('name');
public function validationDefault(Validator $validator): Validator {
$validator
->scalar('name')
->maxLength('name', 255)
->requirePresence('name', 'create')
->notEmptyString('name');
$validator
->uuid('product_category_id')
->notEmptyString('product_category_id');
$validator
->uuid('product_category_id')
->notEmptyString('product_category_id');
$validator
->integer('product_type_id')
->requirePresence('product_type_id', 'create')
->notEmptyString('product_type_id');
$validator
->integer('product_type_id')
->requirePresence('product_type_id', 'create')
->notEmptyString('product_type_id');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
return $validator;
}
return $validator;
}
/**
/**
* Returns a rules checker object that will be used for validating
* application integrity.
*
* @param RulesChecker $rules The rules object to be modified.
* @return RulesChecker
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return \Cake\ORM\RulesChecker
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->isUnique(['product_category_id', 'name']), ['errorField' => 'product_category_id']);
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
public function buildRules(RulesChecker $rules): RulesChecker {
$rules->add($rules->isUnique(['product_category_id', 'name']), ['errorField' => 'product_category_id']);
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
// $rules->add($rules->validCount('product_attributes', 0, '<=', 'You must not have any tags'));
return $rules;
}
return $rules;
}
}
@@ -8,24 +8,24 @@ use Cake\TestSuite\Fixture\TestFixture;
/**
* ExternalProductCatalogsFixture
*/
class ExternalProductCatalogsFixture extends TestFixture
{
/**
class ExternalProductCatalogsFixture extends TestFixture {
/**
* Init method
*
* @return void
*/
public function init(): void
{
$this->records = [
[
'id' => '115153f3-2f59-4234-8ff8-e1b205769999',
'base_url' => 'http://localhost:8766',
'api_url' => 'http://localhost:8766/api',
'created' => '2024-11-22 09:39:37',
'deleted' => null,
],
];
parent::init();
}
public function init(): void {
$this->records = [
[
'id' => '115153f3-2f59-4234-8ff8-e1b205769999',
'base_url' => 'http://localhost:8766',
'api_url' => 'http://localhost:8766/api',
'created' => '2024-11-22 09:39:37',
'deleted' => null,
],
];
parent::init();
}
}
@@ -8,25 +8,25 @@ use Cake\TestSuite\Fixture\TestFixture;
/**
* ExternalProductCatalogsProductCatalogsFixture
*/
class ExternalProductCatalogsProductCatalogsFixture extends TestFixture
{
/**
class ExternalProductCatalogsProductCatalogsFixture extends TestFixture {
/**
* Init method
*
* @return void
*/
public function init(): void
{
$this->records = [
[
'id' => 1,
'external_product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205769999',
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'created' => '2024-11-22 09:39:37',
'enabled' => false,
'deleted' => null,
],
];
parent::init();
}
public function init(): void {
$this->records = [
[
'id' => 1,
'external_product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205769999',
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'created' => '2024-11-22 09:39:37',
'enabled' => false,
'deleted' => null,
],
];
parent::init();
}
}
+7 -9
View File
@@ -8,18 +8,16 @@ use Cake\TestSuite\Fixture\TestFixture;
/**
* ProductAttributesFixture
*/
class ProductAttributesFixture extends TestFixture
{
/**
class ProductAttributesFixture extends TestFixture {
/**
* Init method
*
* @return void
*/
public function init(): void
{
$this->records = [
public function init(): void {
$this->records = [];
parent::init();
}
];
parent::init();
}
}
+23 -23
View File
@@ -8,31 +8,31 @@ use Cake\TestSuite\Fixture\TestFixture;
/**
* ProductCatalogsFixture
*/
class ProductCatalogsFixture extends TestFixture
{
/**
class ProductCatalogsFixture extends TestFixture {
/**
* Init method
*
* @return void
*/
public function init(): void
{
$this->records = [
[
'id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'name' => 'Automotive',
'catalog_description' => '',
'enabled' => true,
'deleted' => null,
],
[
'id' => 'f56f3412-ed23-490b-be6e-016208c415d2',
'name' => 'Software',
'catalog_description' => '',
'enabled' => true,
'deleted' => null,
],
];
parent::init();
}
public function init(): void {
$this->records = [
[
'id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'name' => 'Automotive',
'catalog_description' => '',
'enabled' => true,
'deleted' => null,
],
[
'id' => 'f56f3412-ed23-490b-be6e-016208c415d2',
'name' => 'Software',
'catalog_description' => '',
'enabled' => true,
'deleted' => null,
],
];
parent::init();
}
}
+93 -93
View File
@@ -8,101 +8,101 @@ use Cake\TestSuite\Fixture\TestFixture;
/**
* ProductCategoriesFixture
*/
class ProductCategoriesFixture extends TestFixture
{
/**
class ProductCategoriesFixture extends TestFixture {
/**
* Init method
*
* @return void
*/
public function init(): void
{
$this->records = [
[
'id' => 1,
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'internal_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'name' => 'Engine',
'category_description' => '',
'parent_id' => null,
'lft' => 1,
'rght' => 4,
'enabled' => true,
'deleted' => null,
],
[
'id' => 2,
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'internal_id' => '3c2377c5-b97c-4bc9-9660-8f77b4893d8b',
'name' => 'Engine Internals',
'category_description' => '',
'parent_id' => 1,
'lft' => 2,
'rght' => 3,
'enabled' => true,
'deleted' => null,
],
[
'id' => 3,
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'internal_id' => 'fbee6709-396f-4bb4-b60b-e125b0bc4e83',
'name' => 'Electrical',
'category_description' => '',
'parent_id' => null,
'lft' => 5,
'rght' => 8,
'enabled' => true,
'deleted' => null,
],
[
'id' => 4,
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'internal_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'name' => 'Wiring',
'category_description' => '',
'parent_id' => 3,
'lft' => 6,
'rght' => 7,
'enabled' => true,
'deleted' => null,
],
[
'id' => 5,
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'internal_id' => 'c447b6f4-0fb1-4d59-ba45-5613829a725a',
'name' => 'Suspension',
'category_description' => '',
'parent_id' => null,
'lft' => 9,
'rght' => 12,
'enabled' => true,
'deleted' => null,
],
[
'id' => 6,
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'internal_id' => '1e749d3b-aee0-48a5-8d6c-8cf2b83e9b6e',
'name' => 'Coilovers',
'category_description' => '',
'parent_id' => 5,
'lft' => 10,
'rght' => 11,
'enabled' => true,
'deleted' => null,
],
[
'id' => 7,
'product_catalog_id' => 'f56f3412-ed23-490b-be6e-016208c415d2',
'internal_id' => '8c89a3ca-d56f-46bf-a738-7e85b3342b2a',
'name' => 'Support',
'category_description' => '',
'parent_id' => null,
'lft' => 1,
'rght' => 2,
'enabled' => true,
'deleted' => null,
],
];
parent::init();
}
public function init(): void {
$this->records = [
[
'id' => 1,
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'internal_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'name' => 'Engine',
'category_description' => '',
'parent_id' => null,
'lft' => 1,
'rght' => 4,
'enabled' => true,
'deleted' => null,
],
[
'id' => 2,
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'internal_id' => '3c2377c5-b97c-4bc9-9660-8f77b4893d8b',
'name' => 'Engine Internals',
'category_description' => '',
'parent_id' => 1,
'lft' => 2,
'rght' => 3,
'enabled' => true,
'deleted' => null,
],
[
'id' => 3,
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'internal_id' => 'fbee6709-396f-4bb4-b60b-e125b0bc4e83',
'name' => 'Electrical',
'category_description' => '',
'parent_id' => null,
'lft' => 5,
'rght' => 8,
'enabled' => true,
'deleted' => null,
],
[
'id' => 4,
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'internal_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'name' => 'Wiring',
'category_description' => '',
'parent_id' => 3,
'lft' => 6,
'rght' => 7,
'enabled' => true,
'deleted' => null,
],
[
'id' => 5,
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'internal_id' => 'c447b6f4-0fb1-4d59-ba45-5613829a725a',
'name' => 'Suspension',
'category_description' => '',
'parent_id' => null,
'lft' => 9,
'rght' => 12,
'enabled' => true,
'deleted' => null,
],
[
'id' => 6,
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'internal_id' => '1e749d3b-aee0-48a5-8d6c-8cf2b83e9b6e',
'name' => 'Coilovers',
'category_description' => '',
'parent_id' => 5,
'lft' => 10,
'rght' => 11,
'enabled' => true,
'deleted' => null,
],
[
'id' => 7,
'product_catalog_id' => 'f56f3412-ed23-490b-be6e-016208c415d2',
'internal_id' => '8c89a3ca-d56f-46bf-a738-7e85b3342b2a',
'name' => 'Support',
'category_description' => '',
'parent_id' => null,
'lft' => 1,
'rght' => 2,
'enabled' => true,
'deleted' => null,
],
];
parent::init();
}
}
@@ -8,41 +8,41 @@ use Cake\TestSuite\Fixture\TestFixture;
/**
* ProductCategoryAttributeOptionsFixture
*/
class ProductCategoryAttributeOptionsFixture extends TestFixture
{
/**
class ProductCategoryAttributeOptionsFixture extends TestFixture {
/**
* Init method
*
* @return void
*/
public function init(): void
{
$this->records = [
[
'id' => 'e06f1723-2456-483a-b3c4-004603e032a8',
'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
'attribute_value' => 'Red',
'attribute_label' => 'Red',
'enabled' => 1,
'deleted' => null,
],
[
'id' => 'e06f1723-2456-483a-b3c4-004603e032a1',
'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
'attribute_value' => 'Blue',
'attribute_label' => 'Blue',
'enabled' => 1,
'deleted' => null,
],
[
'id' => 'e06f1723-2456-483a-b3c4-004603e032a2',
'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
'attribute_value' => 'Green',
'attribute_label' => 'Green',
'enabled' => 1,
'deleted' => null,
]
];
parent::init();
}
public function init(): void {
$this->records = [
[
'id' => 'e06f1723-2456-483a-b3c4-004603e032a8',
'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
'attribute_value' => 'Red',
'attribute_label' => 'Red',
'enabled' => 1,
'deleted' => null,
],
[
'id' => 'e06f1723-2456-483a-b3c4-004603e032a1',
'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
'attribute_value' => 'Blue',
'attribute_label' => 'Blue',
'enabled' => 1,
'deleted' => null,
],
[
'id' => 'e06f1723-2456-483a-b3c4-004603e032a2',
'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
'attribute_value' => 'Green',
'attribute_label' => 'Green',
'enabled' => 1,
'deleted' => null,
],
];
parent::init();
}
}
@@ -8,25 +8,25 @@ use Cake\TestSuite\Fixture\TestFixture;
/**
* ProductCategoryAttributesFixture
*/
class ProductCategoryAttributesFixture extends TestFixture
{
/**
class ProductCategoryAttributesFixture extends TestFixture {
/**
* Init method
*
* @return void
*/
public function init(): void
{
$this->records = [
[
'id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
'name' => 'Color',
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'attribute_type_id' => 1,
'enabled' => 1,
'deleted' => null,
],
];
parent::init();
}
public function init(): void {
$this->records = [
[
'id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
'name' => 'Color',
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'attribute_type_id' => 1,
'enabled' => 1,
'deleted' => null,
],
];
parent::init();
}
}
@@ -8,92 +8,91 @@ use Cake\TestSuite\Fixture\TestFixture;
/**
* ProductCategoryVariantsFixture
*/
class ProductCategoryVariantOptionsFixture extends TestFixture
{
/**
class ProductCategoryVariantOptionsFixture extends TestFixture {
/**
* Init method
*
* @return void
*/
public function init(): void
{
$this->records = [
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d23',
'variant_value' => 'Blue',
'variant_label' => null,
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
'created' => '2025-07-04 12:00:00',
'modified' => '2025-07-04 12:00:00',
'enabled' => 1,
],
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d24',
'variant_value' => 'Red',
'variant_label' => null,
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
'created' => '2025-07-04 12:00:00',
'modified' => '2025-07-04 12:00:00',
'enabled' => 1,
],
public function init(): void {
$this->records = [
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d23',
'variant_value' => 'Blue',
'variant_label' => null,
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
'created' => '2025-07-04 12:00:00',
'modified' => '2025-07-04 12:00:00',
'enabled' => 1,
],
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d24',
'variant_value' => 'Red',
'variant_label' => null,
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
'created' => '2025-07-04 12:00:00',
'modified' => '2025-07-04 12:00:00',
'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',
'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-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();
}
[
'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
*/
class ProductCategoryVariantsFixture extends TestFixture
{
/**
class ProductCategoryVariantsFixture extends TestFixture {
/**
* Init method
*
* @return void
*/
public function init(): void
{
$this->records = [
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78111',
'name' => 'Subscription Length Units',
'product_category_id' => null,
'enabled' => true,
'is_system_variant' => true,
],
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78222',
'name' => 'Subscription Length',
'product_category_id' => null,
'enabled' => true,
'is_system_variant' => true,
],
public function init(): void {
$this->records = [
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78111',
'name' => 'Subscription Length Units',
'product_category_id' => null,
'enabled' => true,
'is_system_variant' => true,
],
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78222',
'name' => 'Subscription Length',
'product_category_id' => null,
'enabled' => 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
*/
class ProductPhotosFixture extends TestFixture
{
/**
class ProductPhotosFixture extends TestFixture {
/**
* Init method
*
* @return void
*/
public function init(): void
{
$this->records = [
[
'id' => '2c386086-f4c5-4093-bea5-ee9c29479f58',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'product_sku_id' => null,
'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' => 1,
'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,
],
public function init(): void {
$this->records = [
[
'id' => '2c386086-f4c5-4093-bea5-ee9c29479f58',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'product_sku_id' => null,
'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' => 1,
'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,
],
[
'id' => '2c386086-f4c5-4093-bea5-ee9c29479f51',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'product_sku_id' => null,
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'photo_dir' => 'categories',
'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f51.png',
'primary_photo' => 0,
'primary_category_photo' => 1,
'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,
],
[
'id' => '2c386086-f4c5-4093-bea5-ee9c29479f51',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'product_sku_id' => null,
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'photo_dir' => 'categories',
'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f51.png',
'primary_photo' => 0,
'primary_category_photo' => 1,
'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,
],
[
'id' => '2c386086-f4c5-4093-bea5-ee9c29479f50',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'product_sku_id' => null,
'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' => 0,
'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-ee9c29479f53',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'product_sku_id' => null,
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'photo_dir' => 'categories',
'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,
],
[
'id' => '2c386086-f4c5-4093-bea5-ee9c29479f50',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'product_sku_id' => null,
'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' => 0,
'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-ee9c29479f53',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'product_sku_id' => null,
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'photo_dir' => 'categories',
'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,
],
[
'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
*/
class ProductSkuVariantValuesFixture extends TestFixture
{
/**
class ProductSkuVariantValuesFixture extends TestFixture {
/**
* Table name
*
* @var string
*/
public string $table = 'product_sku_variant_values';
public string $table = 'product_sku_variant_values';
/**
/**
* Init method
*
* @return void
*/
public function init(): void
{
$this->records = [
[
'id' => '98b609d8-1d4f-484c-a13a-6adb7102da56',
'product_sku_id' => '3a477e3e-7977-4813-81f6-f85949613979',
'product_variant_id' => '2e6e4031-c430-4d07-b8d6-a4e759b72569',
'product_category_variant_option_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d23',
],
];
parent::init();
}
public function init(): void {
$this->records = [
[
'id' => '98b609d8-1d4f-484c-a13a-6adb7102da56',
'product_sku_id' => '3a477e3e-7977-4813-81f6-f85949613979',
'product_variant_id' => '2e6e4031-c430-4d07-b8d6-a4e759b72569',
'product_category_variant_option_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d23',
],
];
parent::init();
}
}
+23 -22
View File
@@ -8,34 +8,35 @@ use Cake\TestSuite\Fixture\TestFixture;
/**
* ProductSkusFixture
*/
class ProductSkusFixture extends TestFixture
{
/**
class ProductSkusFixture extends TestFixture {
/**
* Table name
*
* @var string
*/
public string $table = 'product_skus';
/**
public string $table = 'product_skus';
/**
* Init method
*
* @return void
*/
public function init(): void
{
$this->records = [
[
'id' => '3a477e3e-7977-4813-81f6-f85949613979',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'sku' => '3a477e3e-7977-4813-81f6-f85949613979',
'barcode' => '3a477e3e-7977-4813-81f6-f85949613979',
'price' => 1.5,
'cost' => 1.5,
'created' => '2025-04-15 09:09:15',
'modified' => '2025-04-15 09:09:15',
'deleted' => null,
],
];
parent::init();
}
public function init(): void {
$this->records = [
[
'id' => '3a477e3e-7977-4813-81f6-f85949613979',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'sku' => '3a477e3e-7977-4813-81f6-f85949613979',
'barcode' => '3a477e3e-7977-4813-81f6-f85949613979',
'price' => 1.5,
'cost' => 1.5,
'created' => '2025-04-15 09:09:15',
'modified' => '2025-04-15 09:09:15',
'deleted' => null,
],
];
parent::init();
}
}
+37 -37
View File
@@ -8,45 +8,45 @@ use Cake\TestSuite\Fixture\TestFixture;
/**
* ProductVariantsFixture
*/
class ProductVariantsFixture extends TestFixture
{
/**
class ProductVariantsFixture extends TestFixture {
/**
* Init method
*
* @return void
*/
public function init(): void
{
$this->records = [
[
'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72568',
'name' => 'Color',
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'enabled' => 1,
],
[
'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72569',
'name' => 'Color',
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05318',
'enabled' => 1,
],
[
'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72561',
'name' => 'AWG',
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'enabled' => 1,
],
[
'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72562',
'name' => 'AWG',
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05318',
'enabled' => 1,
]
];
parent::init();
}
public function init(): void {
$this->records = [
[
'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72568',
'name' => 'Color',
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'enabled' => 1,
],
[
'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72569',
'name' => 'Color',
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05318',
'enabled' => 1,
],
[
'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72561',
'name' => 'AWG',
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'enabled' => 1,
],
[
'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72562',
'name' => 'AWG',
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05318',
'enabled' => 1,
],
];
parent::init();
}
}
+23 -23
View File
@@ -8,31 +8,31 @@ use Cake\TestSuite\Fixture\TestFixture;
/**
* ProductsFixture
*/
class ProductsFixture extends TestFixture
{
/**
class ProductsFixture extends TestFixture {
/**
* Init method
*
* @return void
*/
public function init(): void
{
$this->records = [
[
'id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'name' => '12AWG RED TXL Wire',
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'product_type_id' => 1,
'deleted' => null,
],
[
'id' => 'cfc98a9a-29b2-44c8-b587-8156adc05318',
'name' => 'Heat Shrink',
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'product_type_id' => 1,
'deleted' => null,
],
];
parent::init();
}
public function init(): void {
$this->records = [
[
'id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'name' => '12AWG RED TXL Wire',
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'product_type_id' => 1,
'deleted' => null,
],
[
'id' => 'cfc98a9a-29b2-44c8-b587-8156adc05318',
'name' => 'Heat Shrink',
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'product_type_id' => 1,
'deleted' => null,
],
];
parent::init();
}
}
@@ -14,55 +14,52 @@ use RecursiveIteratorIterator;
*
* Used to make logging in easier and to handle folder structure for product images
*/
class BaseControllerTest extends TestCase
{
use IntegrationTestTrait;
class BaseControllerTest extends TestCase {
public function loginUserByRole(string $role = 'admin'): void
{
$this->session(['Auth.User.id' => 1]);
$this->session(['Auth.id' => 1]);
}
use IntegrationTestTrait;
/**
public function loginUserByRole(string $role = 'admin'): void {
$this->session(['Auth.User.id' => 1]);
$this->session(['Auth.id' => 1]);
}
/**
* @return void
*/
public function testTest()
{
$this->assertEquals(1, 1);
}
public function testTest() {
$this->assertEquals(1, 1);
}
/**
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$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 .
'images' . DS . 'products' . DS . 'cfc98a9a-29b2-44c8-b587-8156adc05317';
$newName = $productsFolder . DS . '2c386086-f4c5-4093-bea5-ee9c29479f58.png';
if (file_exists($toCopy)) {
if (!file_exists($productsFolder)) {
mkdir($productsFolder, 0775, true);
}
copy($toCopy, $newName);
}
}
protected function setUp(): void {
parent::setUp();
$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
. 'images' . DS . 'products' . DS . 'cfc98a9a-29b2-44c8-b587-8156adc05317';
$newName = $productsFolder . DS . '2c386086-f4c5-4093-bea5-ee9c29479f58.png';
if (file_exists($toCopy)) {
if (!file_exists($productsFolder)) {
mkdir($productsFolder, 0775, true);
}
copy($toCopy, $newName);
}
}
protected function tearDown(): void
{
parent::tearDown(); // TODO: Change the autogenerated stub
protected function tearDown(): void {
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;
use Cake\Log\Log;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
use CakeProducts\Controller\ExternalProductCatalogsController;
use CakeProducts\Model\Table\ExternalProductCatalogsTable;
use PHPUnit\Exception;
use PHPUnit\Framework\Attributes\CoversClass;
/**
* CakeProducts\Controller\ExternalProductCatalogsController Test Case
*/
#[CoversClass(ExternalProductCatalogsController::class)]
class ExternalProductCatalogsControllerTest extends BaseControllerTest
{
/**
class ExternalProductCatalogsControllerTest extends BaseControllerTest {
/**
* Test subject table
*
* @var ExternalProductCatalogsTable|Table
* @var \CakeProducts\Model\Table\ExternalProductCatalogsTable|\Cake\ORM\Table
*/
protected $ExternalProductCatalogs;
protected $ExternalProductCatalogs;
/**
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeProducts.ExternalProductCatalogs',
'plugin.CakeProducts.ExternalProductCatalogsProductCatalogs',
'plugin.CakeProducts.ProductCatalogs',
];
protected array $fixtures = [
'plugin.CakeProducts.ExternalProductCatalogs',
'plugin.CakeProducts.ExternalProductCatalogsProductCatalogs',
'plugin.CakeProducts.ProductCatalogs',
];
/**
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
protected function setUp(): void {
parent::setUp();
// $this->enableCsrfToken();
// $this->enableSecurityToken();
$this->disableErrorHandlerMiddleware();
$this->ExternalProductCatalogs = $this->getTableLocator()->get('CakeProducts.ExternalProductCatalogs');
}
$this->disableErrorHandlerMiddleware();
$this->ExternalProductCatalogs = $this->getTableLocator()->get('CakeProducts.ExternalProductCatalogs');
}
/**
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->ExternalProductCatalogs);
protected function tearDown(): void {
unset($this->ExternalProductCatalogs);
parent::tearDown();
}
parent::tearDown();
}
/**
/**
* Test index method
*
* Tests the index action with a logged in user
*
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::index()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testIndexGet(): void
{
Log::debug('inside testIndexGet ExternalProductCatalogsControllerTest');
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ExternalProductCatalogs',
'action' => 'index',
];
$this->get($url);
$this->assertResponseCode(200);
}
public function testIndexGet(): void {
Log::debug('inside testIndexGet ExternalProductCatalogsControllerTest');
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ExternalProductCatalogs',
'action' => 'index',
];
$this->get($url);
$this->assertResponseCode(200);
}
/**
/**
* Test view method
*
* Tests the view action with a logged in user
*
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::view()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testViewGet(): void
{
$id = '115153f3-2f59-4234-8ff8-e1b205769999';
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ExternalProductCatalogs',
'action' => 'view',
$id,
];
$this->get($url);
$this->assertResponseCode(200);
}
public function testViewGet(): void {
$id = '115153f3-2f59-4234-8ff8-e1b205769999';
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ExternalProductCatalogs',
'action' => 'view',
$id,
];
$this->get($url);
$this->assertResponseCode(200);
}
/**
/**
* Test add method
*
* Tests the add action with a logged in user
*
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::add()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testAddGet(): void
{
$cntBefore = $this->ExternalProductCatalogs->find()->count();
public function testAddGet(): void {
$cntBefore = $this->ExternalProductCatalogs->find()->count();
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ExternalProductCatalogs',
'action' => 'add',
];
$this->get($url);
$this->assertResponseCode(200);
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ExternalProductCatalogs',
'action' => 'add',
];
$this->get($url);
$this->assertResponseCode(200);
$cntAfter = $this->ExternalProductCatalogs->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
$cntAfter = $this->ExternalProductCatalogs->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
/**
/**
* Test add method
*
* Tests a POST request to the add action with a logged in user
*
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::add()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testAddPostSuccess(): void
{
$linksTable = TableRegistry::getTableLocator()->get('CakeProducts.ExternalProductCatalogsProductCatalogs');
$cntBefore = $this->ExternalProductCatalogs->find()->count();
$linksBefore = $linksTable->find()->count();
public function testAddPostSuccess(): void {
$linksTable = TableRegistry::getTableLocator()->get('CakeProducts.ExternalProductCatalogsProductCatalogs');
$cntBefore = $this->ExternalProductCatalogs->find()->count();
$linksBefore = $linksTable->find()->count();
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ExternalProductCatalogs',
'action' => 'add',
];
$data = [
'base_url' => 'http://localhost:8766',
'api_url' => 'http://localhost:8766/api/v1/',
'enabled' => true,
'external_product_catalogs_product_catalogs' => [
['product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428'],
]
];
$this->post($url, $data);
$this->assertResponseCode(302);
$this->assertRedirectContains('external-product-catalogs');
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ExternalProductCatalogs',
'action' => 'add',
];
$data = [
'base_url' => 'http://localhost:8766',
'api_url' => 'http://localhost:8766/api/v1/',
'enabled' => true,
'external_product_catalogs_product_catalogs' => [
['product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428'],
],
];
$this->post($url, $data);
$this->assertResponseCode(302);
$this->assertRedirectContains('external-product-catalogs');
$cntAfter = $this->ExternalProductCatalogs->find()->count();
$linksAfter = $linksTable->find()->count();
$cntAfter = $this->ExternalProductCatalogs->find()->count();
$linksAfter = $linksTable->find()->count();
$this->assertEquals($cntBefore + 1, $cntAfter);
$this->assertEquals($linksBefore + 1, $linksAfter);
}
$this->assertEquals($cntBefore + 1, $cntAfter);
$this->assertEquals($linksBefore + 1, $linksAfter);
}
/**
/**
* Test add method
*
* Tests a POST request to the add action with a logged in user
*
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::add()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testAddPostFailure(): void
{
$cntBefore = $this->ExternalProductCatalogs->find()->count();
public function testAddPostFailure(): void {
$cntBefore = $this->ExternalProductCatalogs->find()->count();
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ExternalProductCatalogs',
'action' => 'add',
];
$data = [
'product_catalog_id' => 999999,
'base_url' => '',
'api_url' => 'http://localhost:8766/api/v1/',
'enabled' => true,
];
$this->post($url, $data);
$this->assertResponseCode(200);
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ExternalProductCatalogs',
'action' => 'add',
];
$data = [
'product_catalog_id' => 999999,
'base_url' => '',
'api_url' => 'http://localhost:8766/api/v1/',
'enabled' => true,
];
$this->post($url, $data);
$this->assertResponseCode(200);
$cntAfter = $this->ExternalProductCatalogs->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
$cntAfter = $this->ExternalProductCatalogs->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
/**
/**
* Test edit method
*
* Tests the edit action with a logged in user
*
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::edit()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testEditGet(): void
{
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ExternalProductCatalogs',
'action' => 'edit',
'115153f3-2f59-4234-8ff8-e1b205769999',
];
$this->get($url);
$this->assertResponseCode(200);
}
public function testEditGet(): void {
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ExternalProductCatalogs',
'action' => 'edit',
'115153f3-2f59-4234-8ff8-e1b205769999',
];
$this->get($url);
$this->assertResponseCode(200);
}
/**
/**
* Test edit method
*
* Tests a PUT request to the edit action with a logged in user
*
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::edit()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testEditPutSuccess(): void
{
$this->loginUserByRole('admin');
$id = '115153f3-2f59-4234-8ff8-e1b205769999';
$before = $this->ExternalProductCatalogs->get($id);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ExternalProductCatalogs',
'action' => 'edit',
$id,
];
$data = [
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'base_url' => 'http://localhost:8766',
'api_url' => 'http://localhost:8766/api/v1/',
'enabled' => true,
];
$this->put($url, $data);
public function testEditPutSuccess(): void {
$this->loginUserByRole('admin');
$id = '115153f3-2f59-4234-8ff8-e1b205769999';
$before = $this->ExternalProductCatalogs->get($id);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ExternalProductCatalogs',
'action' => 'edit',
$id,
];
$data = [
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'base_url' => 'http://localhost:8766',
'api_url' => 'http://localhost:8766/api/v1/',
'enabled' => true,
];
$this->put($url, $data);
$this->assertResponseCode(302);
$this->assertRedirectContains('external-product-catalogs');
$this->assertResponseCode(302);
$this->assertRedirectContains('external-product-catalogs');
$after = $this->ExternalProductCatalogs->get($id);
// assert saved properly below
}
$after = $this->ExternalProductCatalogs->get($id);
// assert saved properly below
}
/**
/**
* Test edit method
*
* Tests a PUT request to the edit action with a logged in user
*
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::edit()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testEditPutFailure(): void
{
$this->loginUserByRole('admin');
$id = '115153f3-2f59-4234-8ff8-e1b205769999';
$before = $this->ExternalProductCatalogs->get($id);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ExternalProductCatalogs',
'action' => 'edit',
$id,
];
$data = [
'product_catalog_id' => 9999999,
'base_url' => '',
'api_url' => 'http://localhost:8766/api/v1/',
'enabled' => true,
];
$this->put($url, $data);
$this->assertResponseCode(200);
$after = $this->ExternalProductCatalogs->get($id);
public function testEditPutFailure(): void {
$this->loginUserByRole('admin');
$id = '115153f3-2f59-4234-8ff8-e1b205769999';
$before = $this->ExternalProductCatalogs->get($id);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ExternalProductCatalogs',
'action' => 'edit',
$id,
];
$data = [
'product_catalog_id' => 9999999,
'base_url' => '',
'api_url' => 'http://localhost:8766/api/v1/',
'enabled' => true,
];
$this->put($url, $data);
$this->assertResponseCode(200);
$after = $this->ExternalProductCatalogs->get($id);
// assert save failed below
}
// assert save failed below
}
/**
/**
* Test delete method
*
* Tests the delete action with a logged in user
*
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::delete()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testDelete(): void
{
$cntBefore = $this->ExternalProductCatalogs->find()->count();
public function testDelete(): void {
$cntBefore = $this->ExternalProductCatalogs->find()->count();
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ExternalProductCatalogs',
'action' => 'delete',
'115153f3-2f59-4234-8ff8-e1b205769999',
];
$this->delete($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('external-product-catalogs');
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ExternalProductCatalogs',
'action' => 'delete',
'115153f3-2f59-4234-8ff8-e1b205769999',
];
$this->delete($url);
$this->assertResponseCode(302);
$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;
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;
/**
* CakeProducts\Controller\ExternalProductCatalogsProductCatalogsController Test Case
*/
#[CoversClass(ExternalProductCatalogsProductCatalogsController::class)]
class ExternalProductCatalogsProductCatalogsControllerTest extends BaseControllerTest
{
/**
class ExternalProductCatalogsProductCatalogsControllerTest extends BaseControllerTest {
/**
* Test subject table
*
* @var ExternalProductCatalogsProductCatalogsTable|Table
* @var \CakeProducts\Model\Table\ExternalProductCatalogsProductCatalogsTable|\Cake\ORM\Table
*/
protected $ExternalProductCatalogsProductCatalogs;
/**
protected $ExternalProductCatalogsProductCatalogs;
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeProducts.ExternalProductCatalogsProductCatalogs',
'plugin.CakeProducts.ExternalProductCatalogs',
'plugin.CakeProducts.ProductCatalogs',
];
protected array $fixtures = [
'plugin.CakeProducts.ExternalProductCatalogsProductCatalogs',
'plugin.CakeProducts.ExternalProductCatalogs',
'plugin.CakeProducts.ProductCatalogs',
];
/**
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
protected function setUp(): void {
parent::setUp();
// $this->enableCsrfToken();
// $this->enableSecurityToken();
$this->disableErrorHandlerMiddleware();
$this->ExternalProductCatalogsProductCatalogs = $this->getTableLocator()->get('CakeProducts.ExternalProductCatalogsProductCatalogs');
}
$this->disableErrorHandlerMiddleware();
$this->ExternalProductCatalogsProductCatalogs = $this->getTableLocator()->get('CakeProducts.ExternalProductCatalogsProductCatalogs');
}
/**
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->ExternalProductCatalogsProductCatalogs);
protected function tearDown(): void {
unset($this->ExternalProductCatalogsProductCatalogs);
parent::tearDown();
}
parent::tearDown();
}
/**
/**
* Test add method
*
* Tests the add action with a logged in user
*
* @uses \CakeProducts\Controller\ExternalProductCatalogsProductCatalogsController::add()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testAddGet(): void
{
$cntBefore = $this->ExternalProductCatalogsProductCatalogs->find()->count();
public function testAddGet(): void {
$cntBefore = $this->ExternalProductCatalogsProductCatalogs->find()->count();
// $this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ExternalProductCatalogsProductCatalogs',
'action' => 'add',
];
$this->get($url);
$this->assertResponseCode(200);
// $this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ExternalProductCatalogsProductCatalogs',
'action' => 'add',
];
$this->get($url);
$this->assertResponseCode(200);
$cntAfter = $this->ExternalProductCatalogsProductCatalogs->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
$cntAfter = $this->ExternalProductCatalogsProductCatalogs->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
/**
/**
* Test delete method
*
* Tests the delete action with a logged in user
*
* @uses \CakeProducts\Controller\ExternalProductCatalogsProductCatalogsController::delete()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testDelete(): void
{
$cntBeforeWithTrashed = $this->ExternalProductCatalogsProductCatalogs->find('withTrashed')->count();
$cntBefore = $this->ExternalProductCatalogsProductCatalogs->find()->count();
public function testDelete(): void {
$cntBeforeWithTrashed = $this->ExternalProductCatalogsProductCatalogs->find('withTrashed')->count();
$cntBefore = $this->ExternalProductCatalogsProductCatalogs->find()->count();
// $this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ExternalProductCatalogsProductCatalogs',
'action' => 'delete',
1,
];
$this->delete($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('external-product-catalogs');
// $this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ExternalProductCatalogsProductCatalogs',
'action' => 'delete',
1,
];
$this->delete($url);
$this->assertResponseCode(302);
$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;
use Cake\ORM\Table;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
use CakeProducts\Controller\ProductCatalogsController;
use CakeProducts\Model\Table\ProductCatalogsTable;
use PHPUnit\Exception;
use PHPUnit\Framework\Attributes\CoversClass;
/**
* CakeProducts\Controller\ProductCatalogsController Test Case
*/
#[CoversClass(ProductCatalogsController::class)]
class ProductCatalogsControllerTest extends BaseControllerTest
{
/**
class ProductCatalogsControllerTest extends BaseControllerTest {
/**
* Test subject table
*
* @var ProductCatalogsTable|Table
* @var \CakeProducts\Model\Table\ProductCatalogsTable|\Cake\ORM\Table
*/
protected $ProductCatalogs;
protected $ProductCatalogs;
/**
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeProducts.ProductCatalogs',
'plugin.CakeProducts.ProductCategories',
];
protected array $fixtures = [
'plugin.CakeProducts.ProductCatalogs',
'plugin.CakeProducts.ProductCategories',
];
/**
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
protected function setUp(): void {
parent::setUp();
// $this->enableCsrfToken();
// $this->enableSecurityToken();
$this->disableErrorHandlerMiddleware();
$config = $this->getTableLocator()->exists('ProductCatalogs') ? [] : ['className' => ProductCatalogsTable::class];
$this->ProductCatalogs = $this->getTableLocator()->get('ProductCatalogs', $config);
}
$this->disableErrorHandlerMiddleware();
$config = $this->getTableLocator()->exists('ProductCatalogs') ? [] : ['className' => ProductCatalogsTable::class];
$this->ProductCatalogs = $this->getTableLocator()->get('ProductCatalogs', $config);
}
/**
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->ProductCatalogs);
protected function tearDown(): void {
unset($this->ProductCatalogs);
parent::tearDown();
}
parent::tearDown();
}
/**
/**
* Test index method
*
* Tests the index action with a logged in user
*
* @uses \CakeProducts\Controller\ProductCatalogsController::index()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testIndexGet(): void
{
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCatalogs',
'action' => 'index',
];
$this->get($url);
$this->assertResponseCode(200);
}
public function testIndexGet(): void {
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCatalogs',
'action' => 'index',
];
$this->get($url);
$this->assertResponseCode(200);
}
/**
/**
* Test view method
*
* Tests the view action with a logged in user
*
* @uses \CakeProducts\Controller\ProductCatalogsController::view()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testViewGet(): void
{
$id = '115153f3-2f59-4234-8ff8-e1b205761428';
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCatalogs',
'action' => 'view',
$id,
];
$this->get($url);
$this->assertResponseCode(200);
}
public function testViewGet(): void {
$id = '115153f3-2f59-4234-8ff8-e1b205761428';
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCatalogs',
'action' => 'view',
$id,
];
$this->get($url);
$this->assertResponseCode(200);
}
/**
/**
* Test add method
*
* Tests the add action with a logged in user
*
* @uses \CakeProducts\Controller\ProductCatalogsController::add()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testAddGet(): void
{
$cntBefore = $this->ProductCatalogs->find()->count();
public function testAddGet(): void {
$cntBefore = $this->ProductCatalogs->find()->count();
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCatalogs',
'action' => 'add',
];
$this->get($url);
$this->assertResponseCode(200);
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCatalogs',
'action' => 'add',
];
$this->get($url);
$this->assertResponseCode(200);
$cntAfter = $this->ProductCatalogs->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
$cntAfter = $this->ProductCatalogs->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
/**
/**
* Test add method
*
* Tests a POST request to the add action with a logged in user
*
* @uses \CakeProducts\Controller\ProductCatalogsController::add()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testAddPostSuccess(): void
{
$cntBefore = $this->ProductCatalogs->find()->count();
public function testAddPostSuccess(): void {
$cntBefore = $this->ProductCatalogs->find()->count();
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCatalogs',
'action' => 'add',
];
$data = [
'name' => 'new catalog',
'catalog_description' => 'description',
'enabled' => true,
];
$this->post($url, $data);
$this->assertResponseCode(302);
$this->assertRedirectContains('product-catalogs');
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCatalogs',
'action' => 'add',
];
$data = [
'name' => 'new catalog',
'catalog_description' => 'description',
'enabled' => true,
];
$this->post($url, $data);
$this->assertResponseCode(302);
$this->assertRedirectContains('product-catalogs');
$cntAfter = $this->ProductCatalogs->find()->count();
$this->assertEquals($cntBefore + 1, $cntAfter);
}
$cntAfter = $this->ProductCatalogs->find()->count();
$this->assertEquals($cntBefore + 1, $cntAfter);
}
/**
/**
* Test add method
*
* Tests a POST request to the add action with a logged in user
*
* @uses \CakeProducts\Controller\ProductCatalogsController::add()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testAddPostFailure(): void
{
$cntBefore = $this->ProductCatalogs->find()->count();
public function testAddPostFailure(): void {
$cntBefore = $this->ProductCatalogs->find()->count();
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCatalogs',
'action' => 'add',
];
$data = [
'name' => '',
'catalog_description' => '',
'enabled' => '',
];
$this->post($url, $data);
$this->assertResponseCode(200);
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCatalogs',
'action' => 'add',
];
$data = [
'name' => '',
'catalog_description' => '',
'enabled' => '',
];
$this->post($url, $data);
$this->assertResponseCode(200);
$cntAfter = $this->ProductCatalogs->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
$cntAfter = $this->ProductCatalogs->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
/**
/**
* Test edit method
*
* Tests the edit action with a logged in user
*
* @uses \CakeProducts\Controller\ProductCatalogsController::edit()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testEditGet(): void
{
$this->loginUserByRole('admin');
$id = '115153f3-2f59-4234-8ff8-e1b205761428';
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCatalogs',
'action' => 'edit',
$id,
];
$this->get($url);
$this->assertResponseCode(200);
}
public function testEditGet(): void {
$this->loginUserByRole('admin');
$id = '115153f3-2f59-4234-8ff8-e1b205761428';
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCatalogs',
'action' => 'edit',
$id,
];
$this->get($url);
$this->assertResponseCode(200);
}
/**
/**
* Test edit method
*
* Tests a PUT request to the edit action with a logged in user
*
* @uses \CakeProducts\Controller\ProductCatalogsController::edit()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testEditPutSuccess(): void
{
$this->loginUserByRole('admin');
$id = '115153f3-2f59-4234-8ff8-e1b205761428';
public function testEditPutSuccess(): void {
$this->loginUserByRole('admin');
$id = '115153f3-2f59-4234-8ff8-e1b205761428';
// $before = $this->ProductCatalogs->get($id);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCatalogs',
'action' => 'edit',
$id,
];
$data = [
// test new data here
'name' => 'edited name',
'catalog_description' => 'new catalog description',
'enabled' => true,
];
$this->put($url, $data);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCatalogs',
'action' => 'edit',
$id,
];
$data = [
// test new data here
'name' => 'edited name',
'catalog_description' => 'new catalog description',
'enabled' => true,
];
$this->put($url, $data);
$this->assertResponseCode(302);
$this->assertRedirectContains('product-catalogs');
$this->assertResponseCode(302);
$this->assertRedirectContains('product-catalogs');
$after = $this->ProductCatalogs->get($id);
$this->assertEquals($data['name'], $after->name);
$this->assertEquals($data['catalog_description'], $after->catalog_description);
// assert saved properly below
}
$after = $this->ProductCatalogs->get($id);
$this->assertEquals($data['name'], $after->name);
$this->assertEquals($data['catalog_description'], $after->catalog_description);
// assert saved properly below
}
/**
/**
* Test edit method
*
* Tests a PUT request to the edit action with a logged in user
*
* @uses \CakeProducts\Controller\ProductCatalogsController::edit()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testEditPutFailure(): void
{
$this->loginUserByRole('admin');
$id = '115153f3-2f59-4234-8ff8-e1b205761428';
$before = $this->ProductCatalogs->get($id);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCatalogs',
'action' => 'edit',
$id,
];
$data = [
'name' => '',
'catalog_description' => 'edited description',
'enabled' => '',
];
$this->put($url, $data);
$this->assertResponseCode(200);
$after = $this->ProductCatalogs->get($id);
$this->assertEquals($before->name, $after->name);
$this->assertEquals($before->catalog_description, $after->catalog_description);
// assert save failed below
}
public function testEditPutFailure(): void {
$this->loginUserByRole('admin');
$id = '115153f3-2f59-4234-8ff8-e1b205761428';
$before = $this->ProductCatalogs->get($id);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCatalogs',
'action' => 'edit',
$id,
];
$data = [
'name' => '',
'catalog_description' => 'edited description',
'enabled' => '',
];
$this->put($url, $data);
$this->assertResponseCode(200);
$after = $this->ProductCatalogs->get($id);
$this->assertEquals($before->name, $after->name);
$this->assertEquals($before->catalog_description, $after->catalog_description);
// assert save failed below
}
/**
/**
* Test delete method
*
* Tests the delete action with a logged in user
*
* @uses \CakeProducts\Controller\ProductCatalogsController::delete()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testDelete(): void
{
$cntBefore = $this->ProductCatalogs->find()->count();
public function testDelete(): void {
$cntBefore = $this->ProductCatalogs->find()->count();
$this->loginUserByRole('admin');
$id = '115153f3-2f59-4234-8ff8-e1b205761428';
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCatalogs',
'action' => 'delete',
$id,
];
$this->delete($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('product-catalogs');
$this->loginUserByRole('admin');
$id = '115153f3-2f59-4234-8ff8-e1b205761428';
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCatalogs',
'action' => 'delete',
$id,
];
$this->delete($url);
$this->assertResponseCode(302);
$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;
use Cake\ORM\Table;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
use CakeProducts\Controller\ProductCategoriesController;
use CakeProducts\Model\Table\ProductCategoriesTable;
use PHPUnit\Exception;
use PHPUnit\Framework\Attributes\CoversClass;
/**
* CakeProducts\Controller\ProductCategoriesController Test Case
*/
#[CoversClass(ProductCategoriesController::class)]
class ProductCategoriesControllerTest extends BaseControllerTest
{
/**
class ProductCategoriesControllerTest extends BaseControllerTest {
/**
* Test subject table
*
* @var ProductCategoriesTable|Table
* @var \CakeProducts\Model\Table\ProductCategoriesTable|\Cake\ORM\Table
*/
protected $ProductCategories;
protected $ProductCategories;
/**
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeProducts.ProductCatalogs',
'plugin.CakeProducts.ProductCategories',
];
protected array $fixtures = [
'plugin.CakeProducts.ProductCatalogs',
'plugin.CakeProducts.ProductCategories',
];
/**
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
protected function setUp(): void {
parent::setUp();
// $this->enableCsrfToken();
// $this->enableSecurityToken();
$this->disableErrorHandlerMiddleware();
$this->ProductCategories = $this->getTableLocator()->get('CakeProducts.ProductCategories');
}
$this->disableErrorHandlerMiddleware();
$this->ProductCategories = $this->getTableLocator()->get('CakeProducts.ProductCategories');
}
/**
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->ProductCategories);
protected function tearDown(): void {
unset($this->ProductCategories);
parent::tearDown();
}
parent::tearDown();
}
/**
/**
* Test index method
*
* Tests the index action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoriesController::index
* @throws Exception
* @return void
*/
public function testIndexGet(): void
{
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategories',
'action' => 'index',
];
$this->get($url);
$this->assertResponseCode(200);
}
public function testIndexGet(): void {
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategories',
'action' => 'index',
];
$this->get($url);
$this->assertResponseCode(200);
}
/**
/**
* Test view method
*
* Tests the view action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoriesController::view
* @throws Exception
* @return void
*/
public function testViewGet(): void
{
$id = 1;
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategories',
'action' => 'view',
$id,
];
$this->get($url);
$this->assertResponseCode(200);
}
public function testViewGet(): void {
$id = 1;
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategories',
'action' => 'view',
$id,
];
$this->get($url);
$this->assertResponseCode(200);
}
/**
/**
* Test add method
*
* Tests the add action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoriesController::add
* @throws Exception
* @return void
*/
public function testAddGet(): void
{
$cntBefore = $this->ProductCategories->find()->count();
public function testAddGet(): void {
$cntBefore = $this->ProductCategories->find()->count();
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategories',
'action' => 'add',
];
$this->get($url);
$this->assertResponseCode(200);
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategories',
'action' => 'add',
];
$this->get($url);
$this->assertResponseCode(200);
$cntAfter = $this->ProductCategories->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
$cntAfter = $this->ProductCategories->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
/**
/**
* Test add method
*
* Tests a POST request to the add action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoriesController::add
* @throws Exception
* @return void
*/
public function testAddPostSuccess(): void
{
$cntBefore = $this->ProductCategories->find()->count();
public function testAddPostSuccess(): void {
$cntBefore = $this->ProductCategories->find()->count();
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategories',
'action' => 'add',
];
$data = [
'name' => 'Electrical Plugs',
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'category_description' => 'electrical',
'parent_id' => 3,
'enabled' => true,
];
$this->post($url, $data);
$this->assertResponseCode(302);
$this->assertRedirectContains('product-categories');
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategories',
'action' => 'add',
];
$data = [
'name' => 'Electrical Plugs',
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'category_description' => 'electrical',
'parent_id' => 3,
'enabled' => true,
];
$this->post($url, $data);
$this->assertResponseCode(302);
$this->assertRedirectContains('product-categories');
$cntAfter = $this->ProductCategories->find()->count();
$this->assertEquals($cntBefore + 1, $cntAfter);
}
$cntAfter = $this->ProductCategories->find()->count();
$this->assertEquals($cntBefore + 1, $cntAfter);
}
/**
/**
* Test add method
*
* Tests a POST request to the add action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoriesController::add
* @throws Exception
* @return void
*/
public function testAddPostFailure(): void
{
$cntBefore = $this->ProductCategories->find()->count();
public function testAddPostFailure(): void {
$cntBefore = $this->ProductCategories->find()->count();
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategories',
'action' => 'add',
];
$data = [
'name' => '',
'product_catalog_id' => '',
'category_description' => 'electrical',
'parent_id' => '',
'enabled' => true,
];
$this->post($url, $data);
$this->assertResponseCode(200);
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategories',
'action' => 'add',
];
$data = [
'name' => '',
'product_catalog_id' => '',
'category_description' => 'electrical',
'parent_id' => '',
'enabled' => true,
];
$this->post($url, $data);
$this->assertResponseCode(200);
$cntAfter = $this->ProductCategories->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
$cntAfter = $this->ProductCategories->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
/**
/**
* Test edit method
*
* Tests the edit action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoriesController::edit
* @throws Exception
* @return void
*/
public function testEditGet(): void
{
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategories',
'action' => 'edit',
1,
];
$this->get($url);
$this->assertResponseCode(200);
}
public function testEditGet(): void {
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategories',
'action' => 'edit',
1,
];
$this->get($url);
$this->assertResponseCode(200);
}
/**
/**
* Test edit method
*
* Tests a PUT request to the edit action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoriesController::edit
* @throws Exception
* @return void
*/
public function testEditPutSuccess(): void
{
$this->loginUserByRole('admin');
$id = 1;
$before = $this->ProductCategories->get($id);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategories',
'action' => 'edit',
$id,
];
$data = [
// test new data here
'name' => 'Electrical v2',
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'category_description' => 'electrical v2',
'parent_id' => '',
'enabled' => true,
];
$this->put($url, $data);
public function testEditPutSuccess(): void {
$this->loginUserByRole('admin');
$id = 1;
$before = $this->ProductCategories->get($id);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategories',
'action' => 'edit',
$id,
];
$data = [
// test new data here
'name' => 'Electrical v2',
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'category_description' => 'electrical v2',
'parent_id' => '',
'enabled' => true,
];
$this->put($url, $data);
$this->assertResponseCode(302);
$this->assertRedirectContains('product-categories');
$this->assertResponseCode(302);
$this->assertRedirectContains('product-categories');
$after = $this->ProductCategories->get($id);
$this->assertEquals($data['name'], $after->name);
$this->assertEquals($data['product_catalog_id'], $after->product_catalog_id);
$this->assertEquals($data['category_description'], $after->category_description);
$this->assertNull($after->parent_id);
// assert saved properly below
}
$after = $this->ProductCategories->get($id);
$this->assertEquals($data['name'], $after->name);
$this->assertEquals($data['product_catalog_id'], $after->product_catalog_id);
$this->assertEquals($data['category_description'], $after->category_description);
$this->assertNull($after->parent_id);
// assert saved properly below
}
/**
/**
* Test edit method
*
* Tests a PUT request to the edit action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoriesController::edit
* @throws Exception
* @return void
*/
public function testEditPutFailure(): void
{
$this->loginUserByRole('admin');
$id = 1;
$before = $this->ProductCategories->get($id);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategories',
'action' => 'edit',
$id,
];
$data = [
'name' => '',
'product_catalog_id' => '',
'category_description' => 'electrical',
'parent_id' => '',
'enabled' => true,
];
$this->put($url, $data);
$this->assertResponseCode(200);
$after = $this->ProductCategories->get($id);
public function testEditPutFailure(): void {
$this->loginUserByRole('admin');
$id = 1;
$before = $this->ProductCategories->get($id);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategories',
'action' => 'edit',
$id,
];
$data = [
'name' => '',
'product_catalog_id' => '',
'category_description' => 'electrical',
'parent_id' => '',
'enabled' => true,
];
$this->put($url, $data);
$this->assertResponseCode(200);
$after = $this->ProductCategories->get($id);
// assert save failed below
}
// assert save failed below
}
/**
/**
* Test delete method
*
* Tests the delete action with a logged in user
*
* @return void
*@throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoriesController::delete
*@throws Exception
* @return void
*/
public function testDelete(): void
{
$cntBefore = $this->ProductCategories->find()->count();
$cntBeforeWithTrashed = $this->ProductCategories->find('withTrashed')->count();
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategories',
'action' => 'delete',
1,
];
$this->delete($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('product-categories');
public function testDelete(): void {
$cntBefore = $this->ProductCategories->find()->count();
$cntBeforeWithTrashed = $this->ProductCategories->find('withTrashed')->count();
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategories',
'action' => 'delete',
1,
];
$this->delete($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('product-categories');
$cntAfter = $this->ProductCategories->find()->count();
$cntAfterWithTrashed = $this->ProductCategories->find('withTrashed')->count();
$cntAfter = $this->ProductCategories->find()->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;
use Cake\ORM\Table;
use CakeProducts\Controller\ProductCategoryAttributeOptionsController;
use CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable;
use PHPUnit\Exception;
use PHPUnit\Framework\Attributes\CoversClass;
/**
* CakeProducts\Controller\ProductCategoryAttributeOptionsController Test Case
*/
#[CoversClass(ProductCategoryAttributeOptionsController::class)]
class ProductCategoryAttributeOptionsControllerTest extends BaseControllerTest
{
/**
class ProductCategoryAttributeOptionsControllerTest extends BaseControllerTest {
/**
* Test subject
*
* @var ProductCategoryAttributeOptionsTable|Table
* @var \CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable|\Cake\ORM\Table
*/
protected $ProductCategoryAttributeOptions;
protected $ProductCategoryAttributeOptions;
/**
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeProducts.ProductCategoryAttributeOptions',
'plugin.CakeProducts.ProductCategoryAttributes',
];
protected array $fixtures = [
'plugin.CakeProducts.ProductCategoryAttributeOptions',
'plugin.CakeProducts.ProductCategoryAttributes',
];
/**
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
protected function setUp(): void {
parent::setUp();
// $this->enableCsrfToken();
// $this->enableSecurityToken();
$config = $this->getTableLocator()->exists('ProductCategoryAttributeOptions') ? [] : ['className' => ProductCategoryAttributeOptionsTable::class];
$this->ProductCategoryAttributeOptions = $this->getTableLocator()->get('ProductCategoryAttributeOptions', $config);
}
$config = $this->getTableLocator()->exists('ProductCategoryAttributeOptions') ? [] : ['className' => ProductCategoryAttributeOptionsTable::class];
$this->ProductCategoryAttributeOptions = $this->getTableLocator()->get('ProductCategoryAttributeOptions', $config);
}
/**
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->ProductCategoryAttributeOptions);
protected function tearDown(): void {
unset($this->ProductCategoryAttributeOptions);
parent::tearDown();
}
parent::tearDown();
}
/**
/**
* Test add method
*
* Tests the add action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoryAttributeOptionsController::add
* @throws Exception
* @return void
*/
public function testAddGet(): void
{
$cntBefore = $this->ProductCategoryAttributeOptions->find()->count();
public function testAddGet(): void {
$cntBefore = $this->ProductCategoryAttributeOptions->find()->count();
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributeOptions',
'action' => 'add',
];
$this->get($url);
$this->assertResponseCode(200);
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributeOptions',
'action' => 'add',
];
$this->get($url);
$this->assertResponseCode(200);
$cntAfter = $this->ProductCategoryAttributeOptions->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
$cntAfter = $this->ProductCategoryAttributeOptions->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
/**
/**
* Test add method
*
* Tests a POST request to the add action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoryAttributeOptionsController::add
* @throws Exception
* @return void
*/
public function testAddPostHasNoEffect(): void
{
$cntBefore = $this->ProductCategoryAttributeOptions->find()->count();
public function testAddPostHasNoEffect(): void {
$cntBefore = $this->ProductCategoryAttributeOptions->find()->count();
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributeOptions',
'action' => 'add',
];
$data = [];
$this->post($url, $data);
$this->assertResponseCode(200);
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributeOptions',
'action' => 'add',
];
$data = [];
$this->post($url, $data);
$this->assertResponseCode(200);
$cntAfter = $this->ProductCategoryAttributeOptions->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
$cntAfter = $this->ProductCategoryAttributeOptions->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
/**
/**
* Test delete method
*
* Tests the delete action with a logged in user
*
* @return void
*@throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoryAttributeOptionsController::delete
*@throws Exception
* @return void
*/
public function testDelete(): void
{
$cntBefore = $this->ProductCategoryAttributeOptions->find()->count();
public function testDelete(): void {
$cntBefore = $this->ProductCategoryAttributeOptions->find()->count();
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributeOptions',
'action' => 'delete',
'e06f1723-2456-483a-b3c4-004603e032a8',
];
$this->delete($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('product-category-attributes');
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributeOptions',
'action' => 'delete',
'e06f1723-2456-483a-b3c4-004603e032a8',
];
$this->delete($url);
$this->assertResponseCode(302);
$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;
use Cake\ORM\Table;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
use CakeProducts\Controller\ProductCategoryAttributesController;
use CakeProducts\Model\Table\ProductCategoryAttributesTable;
use PHPUnit\Exception;
use PHPUnit\Framework\Attributes\CoversClass;
/**
* CakeProducts\Controller\ProductCategoryAttributesController Test Case
*/
#[CoversClass(ProductCategoryAttributesController::class)]
class ProductCategoryAttributesControllerTest extends BaseControllerTest
{
/**
class ProductCategoryAttributesControllerTest extends BaseControllerTest {
/**
* Test subject
*
* @var ProductCategoryAttributesTable|Table
* @var \CakeProducts\Model\Table\ProductCategoryAttributesTable|\Cake\ORM\Table
*/
protected $ProductCategoryAttributes;
protected $ProductCategoryAttributes;
/**
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeProducts.ProductCategoryAttributes',
'plugin.CakeProducts.ProductCategories',
];
protected array $fixtures = [
'plugin.CakeProducts.ProductCategoryAttributes',
'plugin.CakeProducts.ProductCategories',
];
/**
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
protected function setUp(): void {
parent::setUp();
// $this->enableCsrfToken();
// $this->enableSecurityToken();
$config = $this->getTableLocator()->exists('ProductCategoryAttributes') ? [] : ['className' => ProductCategoryAttributesTable::class];
$this->ProductCategoryAttributes = $this->getTableLocator()->get('ProductCategoryAttributes', $config);
}
$config = $this->getTableLocator()->exists('ProductCategoryAttributes') ? [] : ['className' => ProductCategoryAttributesTable::class];
$this->ProductCategoryAttributes = $this->getTableLocator()->get('ProductCategoryAttributes', $config);
}
/**
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->ProductCategoryAttributes);
protected function tearDown(): void {
unset($this->ProductCategoryAttributes);
parent::tearDown();
}
parent::tearDown();
}
/**
/**
* Test index method
*
* Tests the index action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoryAttributesController::index
* @throws Exception
* @return void
*/
public function testIndexGet(): void
{
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributes',
'action' => 'index',
];
$this->get($url);
$this->assertResponseCode(200);
}
public function testIndexGet(): void {
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributes',
'action' => 'index',
];
$this->get($url);
$this->assertResponseCode(200);
}
/**
/**
* Test view method
*
* Tests the view action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoryAttributesController::view
* @throws Exception
* @return void
*/
public function testViewGet(): void
{
$id = '37078cf0-0130-4b93-bb7e-abe7d665ed2c';
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributes',
'action' => 'view',
$id,
];
$this->get($url);
$this->assertResponseCode(200);
}
public function testViewGet(): void {
$id = '37078cf0-0130-4b93-bb7e-abe7d665ed2c';
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributes',
'action' => 'view',
$id,
];
$this->get($url);
$this->assertResponseCode(200);
}
/**
/**
* Test add method
*
* Tests the add action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoryAttributesController::add
* @throws Exception
* @return void
*/
public function testAddGet(): void
{
$cntBefore = $this->ProductCategoryAttributes->find()->count();
public function testAddGet(): void {
$cntBefore = $this->ProductCategoryAttributes->find()->count();
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributes',
'action' => 'add',
];
$this->get($url);
$this->assertResponseCode(200);
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributes',
'action' => 'add',
];
$this->get($url);
$this->assertResponseCode(200);
$cntAfter = $this->ProductCategoryAttributes->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
$cntAfter = $this->ProductCategoryAttributes->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
/**
/**
* Test add method
*
* Tests a POST request to the add action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoryAttributesController::add
* @throws Exception
* @return void
*/
public function testAddPostSuccess(): void
{
$cntBefore = $this->ProductCategoryAttributes->find()->count();
public function testAddPostSuccess(): void {
$cntBefore = $this->ProductCategoryAttributes->find()->count();
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributes',
'action' => 'add',
];
$data = [
'name' => 'Size',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'attribute_type_id' => 2,
'enabled' => true,
];
$this->post($url, $data);
$this->assertResponseCode(302);
$this->assertRedirectContains('product-category-attributes');
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributes',
'action' => 'add',
];
$data = [
'name' => 'Size',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'attribute_type_id' => 2,
'enabled' => true,
];
$this->post($url, $data);
$this->assertResponseCode(302);
$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);
}
/**
/**
* Test add method
*
* Tests a POST request to the add action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoryAttributesController::add
* @throws Exception
* @return void
*/
public function testAddPostSuccessConstrainedWithOptions(): void
{
$cntBefore = $this->ProductCategoryAttributes->find()->count();
$cntOptionsBefore = $this->ProductCategoryAttributes->ProductCategoryAttributeOptions->find()->count();
public function testAddPostSuccessConstrainedWithOptions(): void {
$cntBefore = $this->ProductCategoryAttributes->find()->count();
$cntOptionsBefore = $this->ProductCategoryAttributes->ProductCategoryAttributeOptions->find()->count();
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributes',
'action' => 'add',
];
$data = [
'name' => 'Size',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'attribute_type_id' => 1,
'enabled' => true,
'product_category_attribute_options' => [
[
'attribute_value' => 'XL',
'attribute_label' => 'XL',
'enabled' => true,
],
[
'attribute_value' => 'L',
'attribute_label' => 'L',
'enabled' => true,
]
],
];
$this->post($url, $data);
$this->assertResponseCode(302);
$this->assertRedirectContains('product-category-attributes');
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributes',
'action' => 'add',
];
$data = [
'name' => 'Size',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'attribute_type_id' => 1,
'enabled' => true,
'product_category_attribute_options' => [
[
'attribute_value' => 'XL',
'attribute_label' => 'XL',
'enabled' => true,
],
[
'attribute_value' => 'L',
'attribute_label' => 'L',
'enabled' => true,
],
],
];
$this->post($url, $data);
$this->assertResponseCode(302);
$this->assertRedirectContains('product-category-attributes');
$cntAfter = $this->ProductCategoryAttributes->find()->count();
$cntOptionsAfter = $this->ProductCategoryAttributes->ProductCategoryAttributeOptions->find()->count();
$cntAfter = $this->ProductCategoryAttributes->find()->count();
$cntOptionsAfter = $this->ProductCategoryAttributes->ProductCategoryAttributeOptions->find()->count();
$this->assertEquals($cntBefore + 1, $cntAfter);
$this->assertEquals($cntOptionsBefore + 2, $cntOptionsAfter);
}
$this->assertEquals($cntBefore + 1, $cntAfter);
$this->assertEquals($cntOptionsBefore + 2, $cntOptionsAfter);
}
/**
/**
* Test add method
*
* Tests a POST request to the add action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoryAttributesController::add
* @throws Exception
* @return void
*/
public function testAddPostFailure(): void
{
$cntBefore = $this->ProductCategoryAttributes->find()->count();
public function testAddPostFailure(): void {
$cntBefore = $this->ProductCategoryAttributes->find()->count();
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributes',
'action' => 'add',
];
$data = [
'name' => '',
'product_category_id' => 1,
'attribute_type_id' => 1,
'enabled' => true,
];
$this->post($url, $data);
$this->assertResponseCode(200);
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributes',
'action' => 'add',
];
$data = [
'name' => '',
'product_category_id' => 1,
'attribute_type_id' => 1,
'enabled' => true,
];
$this->post($url, $data);
$this->assertResponseCode(200);
$cntAfter = $this->ProductCategoryAttributes->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
$cntAfter = $this->ProductCategoryAttributes->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
/**
/**
* Test edit method
*
* Tests the edit action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoryAttributesController::edit
* @throws Exception
* @return void
*/
public function testEditGet(): void
{
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributes',
'action' => 'edit',
'37078cf0-0130-4b93-bb7e-abe7d665ed2c',
];
$this->get($url);
$this->assertResponseCode(200);
}
public function testEditGet(): void {
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributes',
'action' => 'edit',
'37078cf0-0130-4b93-bb7e-abe7d665ed2c',
];
$this->get($url);
$this->assertResponseCode(200);
}
/**
/**
* Test edit method
*
* Tests a PUT request to the edit action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoryAttributesController::edit
* @throws Exception
* @return void
*/
public function testEditPutSuccess(): void
{
$this->loginUserByRole('admin');
$id = '37078cf0-0130-4b93-bb7e-abe7d665ed2c';
$before = $this->ProductCategoryAttributes->get($id);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributes',
'action' => 'edit',
$id,
];
$data = [
// test new data here
'name' => 'Color',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'attribute_type_id' => 1,
'enabled' => true,
];
$this->put($url, $data);
public function testEditPutSuccess(): void {
$this->loginUserByRole('admin');
$id = '37078cf0-0130-4b93-bb7e-abe7d665ed2c';
$before = $this->ProductCategoryAttributes->get($id);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributes',
'action' => 'edit',
$id,
];
$data = [
// test new data here
'name' => 'Color',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'attribute_type_id' => 1,
'enabled' => true,
];
$this->put($url, $data);
$this->assertResponseCode(302);
$this->assertRedirectContains('product-category-attributes');
$this->assertResponseCode(302);
$this->assertRedirectContains('product-category-attributes');
$after = $this->ProductCategoryAttributes->get($id);
// assert saved properly below
}
$after = $this->ProductCategoryAttributes->get($id);
// assert saved properly below
}
/**
/**
* Test edit method
*
* Tests a PUT request to the edit action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoryAttributesController::edit
* @throws Exception
* @return void
*/
public function testEditPutFailure(): void
{
$this->loginUserByRole('admin');
$id = '37078cf0-0130-4b93-bb7e-abe7d665ed2c';
$before = $this->ProductCategoryAttributes->get($id);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributes',
'action' => 'edit',
$id,
];
$data = [
'name' => '',
'product_category_id' => 1,
'attribute_type_id' => 1,
'enabled' => true,
];
$this->put($url, $data);
$this->assertResponseCode(200);
$after = $this->ProductCategoryAttributes->get($id);
public function testEditPutFailure(): void {
$this->loginUserByRole('admin');
$id = '37078cf0-0130-4b93-bb7e-abe7d665ed2c';
$before = $this->ProductCategoryAttributes->get($id);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributes',
'action' => 'edit',
$id,
];
$data = [
'name' => '',
'product_category_id' => 1,
'attribute_type_id' => 1,
'enabled' => true,
];
$this->put($url, $data);
$this->assertResponseCode(200);
$after = $this->ProductCategoryAttributes->get($id);
// assert save failed below
}
// assert save failed below
}
/**
/**
* Test delete method
*
* Tests the delete action with a logged in user
*
* @return void
*@throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoryAttributesController::delete
*@throws Exception
* @return void
*/
public function testDelete(): void
{
$cntBefore = $this->ProductCategoryAttributes->find()->count();
public function testDelete(): void {
$cntBefore = $this->ProductCategoryAttributes->find()->count();
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributes',
'action' => 'delete',
'37078cf0-0130-4b93-bb7e-abe7d665ed2c',
];
$this->delete($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('product-category-attributes');
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryAttributes',
'action' => 'delete',
'37078cf0-0130-4b93-bb7e-abe7d665ed2c',
];
$this->delete($url);
$this->assertResponseCode(302);
$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;
use Cake\ORM\Table;
use CakeProducts\Controller\ProductCategoryVariantsController;
use CakeProducts\Model\Table\ProductCategoryAttributesTable;
use CakeProducts\Model\Table\ProductCategoryVariantOptionsTable;
use CakeProducts\Model\Table\ProductCategoryVariantsTable;
use PHPUnit\Exception;
use PHPUnit\Framework\Attributes\CoversClass;
/**
* CakeProducts\Controller\ProductCategoryVariantsController Test Case
*/
#[CoversClass(ProductCategoryVariantsController::class)]
class ProductCategoryVariantsControllerTest extends BaseControllerTest
{
/**
* Test subject
*
* @var ProductCategoryVariantsTable|Table
*/
protected $ProductCategoryVariants;
class ProductCategoryVariantsControllerTest extends BaseControllerTest {
/**
/**
* 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
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeProducts.ProductCategoryVariants',
'plugin.CakeProducts.ProductCategoryVariantOptions',
'plugin.CakeProducts.ProductVariants',
'plugin.CakeProducts.ProductCategories',
'plugin.CakeProducts.Products',
'plugin.CakeProducts.ProductSkus',
'plugin.CakeProducts.ProductPhotos',
];
protected array $fixtures = [
'plugin.CakeProducts.ProductCategoryVariants',
'plugin.CakeProducts.ProductCategoryVariantOptions',
'plugin.CakeProducts.ProductVariants',
'plugin.CakeProducts.ProductCategories',
'plugin.CakeProducts.Products',
'plugin.CakeProducts.ProductSkus',
'plugin.CakeProducts.ProductPhotos',
];
/**
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$this->disableErrorHandlerMiddleware();
protected function setUp(): void {
parent::setUp();
$this->disableErrorHandlerMiddleware();
$config = $this->getTableLocator()->exists('ProductCategoryVariants') ? [] : ['className' => ProductCategoryVariantsTable::class];
$this->ProductCategoryVariants = $this->getTableLocator()->get('ProductCategoryVariants', $config);
$config = $this->getTableLocator()->exists('ProductCategoryVariants') ? [] : ['className' => ProductCategoryVariantsTable::class];
$this->ProductCategoryVariants = $this->getTableLocator()->get('ProductCategoryVariants', $config);
$config = $this->getTableLocator()->exists('ProductCategoryVariantOptions') ? [] : ['className' => ProductCategoryVariantOptionsTable::class];
$this->ProductCategoryVariantOptions = $this->getTableLocator()->get('ProductCategoryVariantOptions', $config);
}
$config = $this->getTableLocator()->exists('ProductCategoryVariantOptions') ? [] : ['className' => ProductCategoryVariantOptionsTable::class];
$this->ProductCategoryVariantOptions = $this->getTableLocator()->get('ProductCategoryVariantOptions', $config);
}
/**
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->ProductCategoryVariants);
unset($this->ProductCategoryVariantOptions);
protected function tearDown(): void {
unset($this->ProductCategoryVariants);
unset($this->ProductCategoryVariantOptions);
parent::tearDown();
}
parent::tearDown();
}
/**
/**
* Test index method
*
* Tests the index action with a logged in user
*
* @uses \CakeProducts\Controller\ProductCategoryVariantsController::index()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testIndexGet(): void
{
//$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryVariants',
'action' => 'index',
];
$this->get($url);
$this->assertResponseCode(200);
}
public function testIndexGet(): void {
//$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryVariants',
'action' => 'index',
];
$this->get($url);
$this->assertResponseCode(200);
}
/**
/**
* Test view method
*
* Tests the view action with a logged in user
*
* @uses \CakeProducts\Controller\ProductCategoryVariantsController::view()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testViewGet(): void
{
$id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93';
//$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryVariants',
'action' => 'view',
$id,
];
$this->get($url);
$this->assertResponseCode(200);
}
public function testViewGet(): void {
$id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93';
//$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryVariants',
'action' => 'view',
$id,
];
$this->get($url);
$this->assertResponseCode(200);
}
/**
/**
* Test add method
*
* Tests the add action with a logged in user
*
* @uses \CakeProducts\Controller\ProductCategoryVariantsController::add()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testAddGet(): void
{
$cntBefore = $this->ProductCategoryVariants->find()->count();
public function testAddGet(): void {
$cntBefore = $this->ProductCategoryVariants->find()->count();
//$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryVariants',
'action' => 'add',
];
$this->get($url);
$this->assertResponseCode(200);
//$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryVariants',
'action' => 'add',
];
$this->get($url);
$this->assertResponseCode(200);
$cntAfter = $this->ProductCategoryVariants->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
$cntAfter = $this->ProductCategoryVariants->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
/**
/**
* Test add method
*
* Tests a POST request to the add action with a logged in user
*
* @uses \CakeProducts\Controller\ProductCategoryVariantsController::add()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testAddPostLoggedInSuccess(): void
{
$cntBefore = $this->ProductCategoryVariants->find()->count();
$cntBeforeOptions = $this->ProductCategoryVariantOptions->find()->count();
public function testAddPostLoggedInSuccess(): void {
$cntBefore = $this->ProductCategoryVariants->find()->count();
$cntBeforeOptions = $this->ProductCategoryVariantOptions->find()->count();
//$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryVariants',
'action' => 'add',
];
$data = [
'name' => 'Size',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'product_id' => '',
'enabled' => true,
'product_category_variant_options' => [
[
'variant_value' => 'XL',
'variant_label' => 'XL',
'enabled' => true,
],
[
'variant_value' => 'XXL',
'variant_label' => 'XXL',
'enabled' => true,
],
]
];
$this->post($url, $data);
$this->assertResponseCode(302);
$this->assertRedirectContains('product-category-variants');
//$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryVariants',
'action' => 'add',
];
$data = [
'name' => 'Size',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'product_id' => '',
'enabled' => true,
'product_category_variant_options' => [
[
'variant_value' => 'XL',
'variant_label' => 'XL',
'enabled' => true,
],
[
'variant_value' => 'XXL',
'variant_label' => 'XXL',
'enabled' => true,
],
],
];
$this->post($url, $data);
$this->assertResponseCode(302);
$this->assertRedirectContains('product-category-variants');
$cntAfter = $this->ProductCategoryVariants->find()->count();
$cntAfterOptions = $this->ProductCategoryVariantOptions->find()->count();
$this->assertEquals($cntBefore + 1, $cntAfter);
$this->assertEquals($cntBeforeOptions + 2, $cntAfterOptions);
}
$cntAfter = $this->ProductCategoryVariants->find()->count();
$cntAfterOptions = $this->ProductCategoryVariantOptions->find()->count();
$this->assertEquals($cntBefore + 1, $cntAfter);
$this->assertEquals($cntBeforeOptions + 2, $cntAfterOptions);
}
/**
/**
* Test add method
*
* Tests a POST request to the add action with a logged in user
*
* @uses \CakeProducts\Controller\ProductCategoryVariantsController::add()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testAddPostLoggedInFailure(): void
{
$cntBefore = $this->ProductCategoryVariants->find()->count();
public function testAddPostLoggedInFailure(): void {
$cntBefore = $this->ProductCategoryVariants->find()->count();
//$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryVariants',
'action' => 'add',
];
$data = [
'name' => '',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'enabled' => true,
];
$this->post($url, $data);
$this->assertResponseCode(200);
//$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryVariants',
'action' => 'add',
];
$data = [
'name' => '',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'enabled' => true,
];
$this->post($url, $data);
$this->assertResponseCode(200);
$cntAfter = $this->ProductCategoryVariants->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
$cntAfter = $this->ProductCategoryVariants->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
/**
/**
* Test edit method
*
* Tests the edit action with a logged in user
*
* @uses \CakeProducts\Controller\ProductCategoryVariantsController::edit()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testEditGet(): void
{
//$this->loginUserByRole('admin');
$id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93';
public function testEditGet(): void {
//$this->loginUserByRole('admin');
$id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93';
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryVariants',
'action' => 'edit',
$id,
];
$this->get($url);
$this->assertResponseCode(200);
}
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryVariants',
'action' => 'edit',
$id,
];
$this->get($url);
$this->assertResponseCode(200);
}
/**
/**
* Test edit method
*
* Tests a PUT request to the edit action with a logged in user
*
* @uses \CakeProducts\Controller\ProductCategoryVariantsController::edit()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testEditPutLoggedInSuccess(): void
{
//$this->loginUserByRole('admin');
$id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93';
$before = $this->ProductCategoryVariants->get($id);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryVariants',
'action' => 'edit',
$id,
];
$data = [
// test new data here
'name' => 'updated name',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'enabled' => true,
];
$this->put($url, $data);
public function testEditPutLoggedInSuccess(): void {
//$this->loginUserByRole('admin');
$id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93';
$before = $this->ProductCategoryVariants->get($id);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryVariants',
'action' => 'edit',
$id,
];
$data = [
// test new data here
'name' => 'updated name',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'enabled' => true,
];
$this->put($url, $data);
$this->assertResponseCode(302);
$this->assertRedirectContains('product-category-variants');
$this->assertResponseCode(302);
$this->assertRedirectContains('product-category-variants');
$after = $this->ProductCategoryVariants->get($id);
// assert saved properly below
}
$after = $this->ProductCategoryVariants->get($id);
// assert saved properly below
}
/**
/**
* Test edit method
*
* Tests a PUT request to the edit action with a logged in user
*
* @uses \CakeProducts\Controller\ProductCategoryVariantsController::edit()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testEditPutLoggedInSuccessSystemVariant(): void
{
//$this->loginUserByRole('admin');
$id = '5a386e9f-6e7a-4ae7-9360-c8e529f78222'; // subscription length
$before = $this->ProductCategoryVariants->get($id);
$cntBeforeOptions = $this->ProductCategoryVariantOptions
->find()
->where(['product_category_variant_id' => $id])
->toArray();
public function testEditPutLoggedInSuccessSystemVariant(): void {
//$this->loginUserByRole('admin');
$id = '5a386e9f-6e7a-4ae7-9360-c8e529f78222'; // subscription length
$before = $this->ProductCategoryVariants->get($id);
$cntBeforeOptions = $this->ProductCategoryVariantOptions
->find()
->where(['product_category_variant_id' => $id])
->toArray();
// $this->assertEquals(2, count($cntBeforeOptions));
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryVariants',
'action' => 'edit',
$id,
];
$data = [
// test new data here
'name' => 'updated name',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'enabled' => false,
'product_category_variant_options' => [
[
'variant_value' => '14',
'variant_label' => '14',
'enabled' => true,
],
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f22221',
'variant_value' => '6',
'variant_label' => '6',
'enabled' => true,
],
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f22222',
'variant_value' => 12,
'variant_label' => 12,
'enabled' => true,
],
],
];
$this->put($url, $data);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryVariants',
'action' => 'edit',
$id,
];
$data = [
// test new data here
'name' => 'updated name',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'enabled' => false,
'product_category_variant_options' => [
[
'variant_value' => '14',
'variant_label' => '14',
'enabled' => true,
],
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f22221',
'variant_value' => '6',
'variant_label' => '6',
'enabled' => true,
],
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f22222',
'variant_value' => 12,
'variant_label' => 12,
'enabled' => true,
],
],
];
$this->put($url, $data);
$this->assertResponseCode(302);
$this->assertRedirectContains('product-category-variants');
$this->assertResponseCode(302);
$this->assertRedirectContains('product-category-variants');
$after = $this->ProductCategoryVariants->get($id);
$cntAfterOptions = $this->ProductCategoryVariantOptions
->find()
->where(['product_category_variant_id' => $id])
->toArray();
$after = $this->ProductCategoryVariants->get($id);
$cntAfterOptions = $this->ProductCategoryVariantOptions
->find()
->where(['product_category_variant_id' => $id])
->toArray();
$this->assertEquals(count($cntBeforeOptions) + 1, count($cntAfterOptions));
$this->assertEquals(count($cntBeforeOptions) + 1, count($cntAfterOptions));
$this->assertEquals($before->name, $after->name);
$this->assertNull($after->product_category_id);
$this->assertTrue($after->enabled);
// assert saved properly below
}
$this->assertEquals($before->name, $after->name);
$this->assertNull($after->product_category_id);
$this->assertTrue($after->enabled);
// assert saved properly below
}
/**
/**
* Test edit method
*
* Tests a PUT request to the edit action with a logged in user
*
* @uses \CakeProducts\Controller\ProductCategoryVariantsController::edit()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testEditPutLoggedInFailure(): void
{
//$this->loginUserByRole('admin');
$id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93';
$before = $this->ProductCategoryVariants->get($id);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryVariants',
'action' => 'edit',
$id,
];
$data = [
'name' => '',
'product_category_id' => 'NOT A VALID ID',
'enabled' => true,
];
$this->put($url, $data);
$this->assertResponseCode(200);
$after = $this->ProductCategoryVariants->get($id);
public function testEditPutLoggedInFailure(): void {
//$this->loginUserByRole('admin');
$id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93';
$before = $this->ProductCategoryVariants->get($id);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryVariants',
'action' => 'edit',
$id,
];
$data = [
'name' => '',
'product_category_id' => 'NOT A VALID ID',
'enabled' => true,
];
$this->put($url, $data);
$this->assertResponseCode(200);
$after = $this->ProductCategoryVariants->get($id);
// assert save failed below
}
// assert save failed below
}
/**
/**
* Test delete method
*
* Tests the delete action with a logged in user
*
* @uses \CakeProducts\Controller\ProductCategoryVariantsController::delete()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testDelete(): void
{
$cntBefore = $this->ProductCategoryVariants->find()->count();
public function testDelete(): void {
$cntBefore = $this->ProductCategoryVariants->find()->count();
//$this->loginUserByRole('admin');
$id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93';
//$this->loginUserByRole('admin');
$id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93';
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryVariants',
'action' => 'delete',
$id,
];
$this->delete($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('product-category-variants');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductCategoryVariants',
'action' => 'delete',
$id,
];
$this->delete($url);
$this->assertResponseCode(302);
$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;
use Cake\ORM\Table;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
use CakeProducts\Controller\ProductSkusController;
use CakeProducts\Model\Table\ProductSkusTable;
use CakeProducts\Model\Table\ProductSkuVariantValuesTable;
use CakeProducts\Model\Table\ProductsTable;
use PHPUnit\Exception;
use PHPUnit\Framework\Attributes\CoversClass;
/**
* CakeProducts\Controller\ProductSkusController Test Case
*/
#[CoversClass(ProductSkusController::class)]
class ProductSkusControllerTest extends BaseControllerTest
{
/**
class ProductSkusControllerTest extends BaseControllerTest {
/**
* Test subject table
*
* @var ProductSkusTable|Table
* @var \CakeProducts\Model\Table\ProductSkusTable|\Cake\ORM\Table
*/
protected $ProductSkus;
protected $ProductSkus;
/**
/**
* Test subject table
*
* @var ProductSkuVariantValuesTable|Table
* @var \CakeProducts\Model\Table\ProductSkuVariantValuesTable|\Cake\ORM\Table
*/
protected $ProductSkuVariantValues;
protected $ProductSkuVariantValues;
/**
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeProducts.ProductSkus',
'plugin.CakeProducts.Products',
'plugin.CakeProducts.ProductAttributes',
'plugin.CakeProducts.ProductVariants',
'plugin.CakeProducts.ProductCategoryVariants',
'plugin.CakeProducts.ProductCategoryVariantOptions',
'plugin.CakeProducts.ProductSkuVariantValues',
];
protected array $fixtures = [
'plugin.CakeProducts.ProductSkus',
'plugin.CakeProducts.Products',
'plugin.CakeProducts.ProductAttributes',
'plugin.CakeProducts.ProductVariants',
'plugin.CakeProducts.ProductCategoryVariants',
'plugin.CakeProducts.ProductCategoryVariantOptions',
'plugin.CakeProducts.ProductSkuVariantValues',
];
/**
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
protected function setUp(): void {
parent::setUp();
// $this->enableCsrfToken();
// $this->enableSecurityToken();
$this->disableErrorHandlerMiddleware();
$this->disableErrorHandlerMiddleware();
$config = $this->getTableLocator()->exists('ProductSkus') ? [] : ['className' => ProductSkusTable::class];
$this->ProductSkus = $this->getTableLocator()->get('ProductSkus', $config);
$config = $this->getTableLocator()->exists('ProductSkus') ? [] : ['className' => ProductSkusTable::class];
$this->ProductSkus = $this->getTableLocator()->get('ProductSkus', $config);
$config = $this->getTableLocator()->exists('ProductSkuVariantValues') ? [] : ['className' => ProductSkuVariantValuesTable::class];
$this->ProductSkuVariantValues = $this->getTableLocator()->get('ProductSkuVariantValues', $config);
}
$config = $this->getTableLocator()->exists('ProductSkuVariantValues') ? [] : ['className' => ProductSkuVariantValuesTable::class];
$this->ProductSkuVariantValues = $this->getTableLocator()->get('ProductSkuVariantValues', $config);
}
/**
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->ProductSkus);
protected function tearDown(): void {
unset($this->ProductSkus);
parent::tearDown();
}
parent::tearDown();
}
/**
/**
* Test index method
*
* Tests the index action with a logged in user
*
* @uses \CakeProducts\Controller\ProductSkusController::index()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testIndexGet(): void
{
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductSkus',
'action' => 'index',
];
$this->get($url);
$this->assertResponseCode(200);
}
public function testIndexGet(): void {
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductSkus',
'action' => 'index',
];
$this->get($url);
$this->assertResponseCode(200);
}
/**
/**
* Test view method
*
* Tests the view action with a logged in user
*
* @uses \CakeProducts\Controller\ProductSkusController::view()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testViewGet(): void
{
$id = '3a477e3e-7977-4813-81f6-f85949613979';
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductSkus',
'action' => 'view',
$id,
];
$this->get($url);
$this->assertResponseCode(200);
}
public function testViewGet(): void {
$id = '3a477e3e-7977-4813-81f6-f85949613979';
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductSkus',
'action' => 'view',
$id,
];
$this->get($url);
$this->assertResponseCode(200);
}
/**
/**
* Test add method
*
* Tests the add action with a logged in user
*
* @uses \CakeProducts\Controller\ProductSkusController::add()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testAddGet(): void
{
$cntBefore = $this->ProductSkus->find()->count();
public function testAddGet(): void {
$cntBefore = $this->ProductSkus->find()->count();
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductSkus',
'action' => 'add',
'cfc98a9a-29b2-44c8-b587-8156adc05317'
];
$this->get($url);
$this->assertResponseCode(200);
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductSkus',
'action' => 'add',
'cfc98a9a-29b2-44c8-b587-8156adc05317',
];
$this->get($url);
$this->assertResponseCode(200);
$cntAfter = $this->ProductSkus->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
$cntAfter = $this->ProductSkus->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
/**
/**
* Test add method
*
* Tests a POST request to the add action with a logged in user
*
* @uses \CakeProducts\Controller\ProductSkusController::add()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testAddPostSuccess(): void
{
$cntBefore = $this->ProductSkus->find()->count();
$cntVariantValuesBefore = $this->ProductSkuVariantValues->find()->count();
public function testAddPostSuccess(): void {
$cntBefore = $this->ProductSkus->find()->count();
$cntVariantValuesBefore = $this->ProductSkuVariantValues->find()->count();
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductSkus',
'action' => 'add',
'cfc98a9a-29b2-44c8-b587-8156adc05317',
];
$data = [
0 => [
'sku' => 'cfc98a9a-29b2-44c8-b587-8156a',
'barcode' => 'cfc98a9a-29b2-44c8-b587-8156a',
'price' => 1.5,
'cost' => 1.5,
'product_sku_variant_values' => [
0 => [
'product_variant_id' => '2e6e4031-c430-4d07-b8d6-a4e759b72568',
'product_category_variant_option_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d23',
],
],
],
];
$this->post($url, $data);
$this->assertResponseCode(302);
$this->assertRedirectContains('product-skus');
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductSkus',
'action' => 'add',
'cfc98a9a-29b2-44c8-b587-8156adc05317',
];
$data = [
0 => [
'sku' => 'cfc98a9a-29b2-44c8-b587-8156a',
'barcode' => 'cfc98a9a-29b2-44c8-b587-8156a',
'price' => 1.5,
'cost' => 1.5,
'product_sku_variant_values' => [
0 => [
'product_variant_id' => '2e6e4031-c430-4d07-b8d6-a4e759b72568',
'product_category_variant_option_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d23',
],
],
],
];
$this->post($url, $data);
$this->assertResponseCode(302);
$this->assertRedirectContains('product-skus');
$cntAfter = $this->ProductSkus->find()->count();
$cntVariantValuesAfter = $this->ProductSkuVariantValues->find()->count();
$this->assertEquals($cntBefore + 1, $cntAfter);
$this->assertEquals($cntVariantValuesBefore + 1, $cntVariantValuesAfter);
}
$cntAfter = $this->ProductSkus->find()->count();
$cntVariantValuesAfter = $this->ProductSkuVariantValues->find()->count();
$this->assertEquals($cntBefore + 1, $cntAfter);
$this->assertEquals($cntVariantValuesBefore + 1, $cntVariantValuesAfter);
}
/**
/**
* Test add method
*
* Tests a POST request to the add action with a logged in user
*
* @uses \CakeProducts\Controller\ProductSkusController::add()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testAddPostFailure(): void
{
$cntBefore = $this->ProductSkus->find()->count();
public function testAddPostFailure(): void {
$cntBefore = $this->ProductSkus->find()->count();
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductSkus',
'action' => 'add',
'cfc98a9a-29b2-44c8-b587-8156adc05317',
];
$data = [
0 => [
'sku' => '',
'barcode' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'price' => 1.5,
'cost' => 1.5,
],
];
$this->post($url, $data);
$this->assertResponseCode(200);
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductSkus',
'action' => 'add',
'cfc98a9a-29b2-44c8-b587-8156adc05317',
];
$data = [
0 => [
'sku' => '',
'barcode' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'price' => 1.5,
'cost' => 1.5,
],
];
$this->post($url, $data);
$this->assertResponseCode(200);
$cntAfter = $this->ProductSkus->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
$cntAfter = $this->ProductSkus->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
/**
/**
* Test edit method
*
* Tests the edit action with a logged in user
*
* @uses \CakeProducts\Controller\ProductSkusController::edit()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testEditGet(): void
{
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductSkus',
'action' => 'edit',
'3a477e3e-7977-4813-81f6-f85949613979',
];
$this->get($url);
$this->assertResponseCode(200);
}
public function testEditGet(): void {
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductSkus',
'action' => 'edit',
'3a477e3e-7977-4813-81f6-f85949613979',
];
$this->get($url);
$this->assertResponseCode(200);
}
/**
/**
* Test edit method
*
* Tests a PUT request to the edit action with a logged in user
*
* @uses \CakeProducts\Controller\ProductSkusController::edit()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testEditPutSuccess(): void
{
$this->loginUserByRole('admin');
$id = '3a477e3e-7977-4813-81f6-f85949613979';
$before = $this->ProductSkus->get($id);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductSkus',
'action' => 'edit',
$id,
];
$data = [
// test new data here
];
$this->put($url, $data);
public function testEditPutSuccess(): void {
$this->loginUserByRole('admin');
$id = '3a477e3e-7977-4813-81f6-f85949613979';
$before = $this->ProductSkus->get($id);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductSkus',
'action' => 'edit',
$id,
];
$data = [
// test new data here
];
$this->put($url, $data);
$this->assertResponseCode(302);
$this->assertRedirectContains('product-skus');
$this->assertResponseCode(302);
$this->assertRedirectContains('product-skus');
$after = $this->ProductSkus->get($id);
// assert saved properly below
}
$after = $this->ProductSkus->get($id);
// assert saved properly below
}
/**
/**
* Test edit method
*
* Tests a PUT request to the edit action with a logged in user
*
* @uses \CakeProducts\Controller\ProductSkusController::edit()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testEditPutFailure(): void
{
$this->loginUserByRole('admin');
$id = '3a477e3e-7977-4813-81f6-f85949613979';
$before = $this->ProductSkus->get($id);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductSkus',
'action' => 'edit',
$id,
];
$data = [
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'sku' => '',
'barcode' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'price' => 1.5,
'cost' => 1.5,
];
$this->put($url, $data);
$this->assertResponseCode(200);
$after = $this->ProductSkus->get($id);
public function testEditPutFailure(): void {
$this->loginUserByRole('admin');
$id = '3a477e3e-7977-4813-81f6-f85949613979';
$before = $this->ProductSkus->get($id);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductSkus',
'action' => 'edit',
$id,
];
$data = [
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'sku' => '',
'barcode' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'price' => 1.5,
'cost' => 1.5,
];
$this->put($url, $data);
$this->assertResponseCode(200);
$after = $this->ProductSkus->get($id);
// assert save failed below
}
// assert save failed below
}
/**
/**
* Test delete method
*
* Tests the delete action with a logged in user
*
* @uses \CakeProducts\Controller\ProductSkusController::delete()
* @throws Exception
* @throws \PHPUnit\Exception
*
* @return void
*/
public function testDelete(): void
{
$cntBefore = $this->ProductSkus->find()->count();
public function testDelete(): void {
$cntBefore = $this->ProductSkus->find()->count();
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductSkus',
'action' => 'delete',
'3a477e3e-7977-4813-81f6-f85949613979',
];
$this->delete($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('product-skus');
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductSkus',
'action' => 'delete',
'3a477e3e-7977-4813-81f6-f85949613979',
];
$this->delete($url);
$this->assertResponseCode(302);
$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;
use Cake\ORM\Table;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
use CakeProducts\Controller\ProductsController;
use CakeProducts\Model\Table\ProductCatalogsTable;
use CakeProducts\Model\Table\ProductsTable;
use PHPUnit\Exception;
use PHPUnit\Framework\Attributes\CoversClass;
/**
* CakeProducts\Controller\ProductsController Test Case
*/
#[CoversClass(ProductsController::class)]
class ProductsControllerTest extends BaseControllerTest
{
/**
class ProductsControllerTest extends BaseControllerTest {
/**
* Test subject table
*
* @var ProductsTable|Table
* @var \CakeProducts\Model\Table\ProductsTable|\Cake\ORM\Table
*/
protected $Products;
protected $Products;
/**
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeProducts.Products',
'plugin.CakeProducts.ProductAttributes',
'plugin.CakeProducts.ProductCategories',
'plugin.CakeProducts.ProductCategoryAttributes',
'plugin.CakeProducts.ProductCategoryAttributeOptions',
protected array $fixtures = [
'plugin.CakeProducts.Products',
'plugin.CakeProducts.ProductAttributes',
'plugin.CakeProducts.ProductCategories',
'plugin.CakeProducts.ProductCategoryAttributes',
'plugin.CakeProducts.ProductCategoryAttributeOptions',
// 'plugin.CakeProducts.ProductCatalogs',
];
];
/**
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
protected function setUp(): void {
parent::setUp();
// $this->enableCsrfToken();
// $this->enableSecurityToken();
$config = $this->getTableLocator()->exists('Products') ? [] : ['className' => ProductsTable::class];
$this->Products = $this->getTableLocator()->get('Products', $config);
}
$config = $this->getTableLocator()->exists('Products') ? [] : ['className' => ProductsTable::class];
$this->Products = $this->getTableLocator()->get('Products', $config);
}
/**
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->Products);
protected function tearDown(): void {
unset($this->Products);
parent::tearDown();
}
parent::tearDown();
}
/**
/**
* Test index method
*
* Tests the index action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductsController::index
* @throws Exception
* @return void
*/
public function testIndexGet(): void
{
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'Products',
'action' => 'index',
];
$this->get($url);
$this->assertResponseCode(200);
}
public function testIndexGet(): void {
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'Products',
'action' => 'index',
];
$this->get($url);
$this->assertResponseCode(200);
}
/**
/**
* Test view method
*
* Tests the view action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductsController::view
* @throws Exception
* @return void
*/
public function testViewGet(): void
{
$id = 'cfc98a9a-29b2-44c8-b587-8156adc05317';
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'Products',
'action' => 'view',
$id,
];
$this->get($url);
$this->assertResponseCode(200);
}
public function testViewGet(): void {
$id = 'cfc98a9a-29b2-44c8-b587-8156adc05317';
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'Products',
'action' => 'view',
$id,
];
$this->get($url);
$this->assertResponseCode(200);
}
/**
/**
* Test add method
*
* Tests the add action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductsController::add
* @throws Exception
* @return void
*/
public function testAddGet(): void
{
$cntBefore = $this->Products->find()->count();
public function testAddGet(): void {
$cntBefore = $this->Products->find()->count();
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'Products',
'action' => 'add',
];
$this->get($url);
$this->assertResponseCode(200);
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'Products',
'action' => 'add',
];
$this->get($url);
$this->assertResponseCode(200);
$cntAfter = $this->Products->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
$cntAfter = $this->Products->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
/**
/**
* Test add method
*
* Tests the add action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductsController::add
* @throws Exception
* @return void
*/
public function testAddPostSuccess(): void
{
$cntBefore = $this->Products->find()->count();
$productAttributesCntBefore = $this->Products->ProductAttributes->find()->count();
public function testAddPostSuccess(): void {
$cntBefore = $this->Products->find()->count();
$productAttributesCntBefore = $this->Products->ProductAttributes->find()->count();
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'Products',
'action' => 'add',
];
$data = [
// test new data here
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'name' => '14AWG Red Wire',
'product_type_id' => 1,
'product_attributes' => [
[
'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
'product_category_attribute_option_id' => 'e06f1723-2456-483a-b3c4-004603e032a2', // green
'attribute_value' => '',
],
],
];
$this->post($url, $data);
$this->assertResponseCode(302);
$this->assertRedirectContains('products');
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'Products',
'action' => 'add',
];
$data = [
// test new data here
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'name' => '14AWG Red Wire',
'product_type_id' => 1,
'product_attributes' => [
[
'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
'product_category_attribute_option_id' => 'e06f1723-2456-483a-b3c4-004603e032a2', // green
'attribute_value' => '',
],
],
];
$this->post($url, $data);
$this->assertResponseCode(302);
$this->assertRedirectContains('products');
$cntAfter = $this->Products->find()->count();
$productAttributesCntAfter = $this->Products->ProductAttributes->find()->count();
$this->assertEquals($cntBefore + 1, $cntAfter);
$this->assertEquals($productAttributesCntBefore + 1, $productAttributesCntAfter);
}
$cntAfter = $this->Products->find()->count();
$productAttributesCntAfter = $this->Products->ProductAttributes->find()->count();
$this->assertEquals($cntBefore + 1, $cntAfter);
$this->assertEquals($productAttributesCntBefore + 1, $productAttributesCntAfter);
}
/**
/**
* Test add method
*
* Tests a POST request to the add action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductsController::add
* @throws Exception
* @return void
*/
public function testAddPostFailure(): void
{
$cntBefore = $this->Products->find()->count();
public function testAddPostFailure(): void {
$cntBefore = $this->Products->find()->count();
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'Products',
'action' => 'add',
];
$data = [
'product_catalog_id' => '',
'product_category_id' => '',
'name' => '',
'product_type_id' => 1,
'product_attributes' => [],
];
$this->post($url, $data);
$this->assertResponseCode(200);
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'Products',
'action' => 'add',
];
$data = [
'product_catalog_id' => '',
'product_category_id' => '',
'name' => '',
'product_type_id' => 1,
'product_attributes' => [],
];
$this->post($url, $data);
$this->assertResponseCode(200);
$cntAfter = $this->Products->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
$cntAfter = $this->Products->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
/**
/**
* Test edit method
*
* Tests the edit action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductsController::edit
* @throws Exception
* @return void
*/
public function testEditGet(): void
{
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'Products',
'action' => 'edit',
'cfc98a9a-29b2-44c8-b587-8156adc05317',
];
$this->get($url);
$this->assertResponseCode(200);
}
public function testEditGet(): void {
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'Products',
'action' => 'edit',
'cfc98a9a-29b2-44c8-b587-8156adc05317',
];
$this->get($url);
$this->assertResponseCode(200);
}
/**
/**
* Test edit method
*
* Tests a PUT request to the edit action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductsController::edit
* @throws Exception
* @return void
*/
public function testEditPutSuccess(): void
{
$this->loginUserByRole('admin');
$id = 'cfc98a9a-29b2-44c8-b587-8156adc05317';
$before = $this->Products->get($id);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'Products',
'action' => 'edit',
$id,
];
$data = [
// test new data here
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'name' => 'edited product name',
'product_type_id' => 1,
];
$this->put($url, $data);
public function testEditPutSuccess(): void {
$this->loginUserByRole('admin');
$id = 'cfc98a9a-29b2-44c8-b587-8156adc05317';
$before = $this->Products->get($id);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'Products',
'action' => 'edit',
$id,
];
$data = [
// test new data here
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'name' => 'edited product name',
'product_type_id' => 1,
];
$this->put($url, $data);
$this->assertResponseCode(302);
$this->assertRedirectContains('products');
$this->assertResponseCode(302);
$this->assertRedirectContains('products');
$after = $this->Products->get($id);
$this->assertEquals($data['name'], $after->name);
// assert saved properly below
}
$after = $this->Products->get($id);
$this->assertEquals($data['name'], $after->name);
// assert saved properly below
}
/**
/**
* Test edit method
*
* Tests a PUT request to the edit action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductsController::edit
* @throws Exception
* @return void
*/
public function testEditPutFailure(): void
{
$this->loginUserByRole('admin');
$id = 'cfc98a9a-29b2-44c8-b587-8156adc05317';
$before = $this->Products->get($id);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'Products',
'action' => 'edit',
$id,
];
$data = [
'product_catalog_id' => '',
'product_category_id' => '',
'name' => 'edited name not gonna take',
'product_type_id' => 1,
];
$this->put($url, $data);
$this->assertResponseCode(200);
$after = $this->Products->get($id);
$this->assertEquals($before->name, $after->name);
$this->assertEquals($before->product_category_id, $after->product_category_id);
// assert save failed below
}
public function testEditPutFailure(): void {
$this->loginUserByRole('admin');
$id = 'cfc98a9a-29b2-44c8-b587-8156adc05317';
$before = $this->Products->get($id);
$url = [
'plugin' => 'CakeProducts',
'controller' => 'Products',
'action' => 'edit',
$id,
];
$data = [
'product_catalog_id' => '',
'product_category_id' => '',
'name' => 'edited name not gonna take',
'product_type_id' => 1,
];
$this->put($url, $data);
$this->assertResponseCode(200);
$after = $this->Products->get($id);
$this->assertEquals($before->name, $after->name);
$this->assertEquals($before->product_category_id, $after->product_category_id);
// assert save failed below
}
/**
/**
* Test delete method
*
* Tests the delete action with a logged in user
*
* @return void
*@throws Exception
*
* @uses \CakeProducts\Controller\ProductsController::delete
*@throws Exception
* @return void
*/
public function testDelete(): void
{
$cntBefore = $this->Products->find()->count();
public function testDelete(): void {
$cntBefore = $this->Products->find()->count();
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'Products',
'action' => 'delete',
'cfc98a9a-29b2-44c8-b587-8156adc05317',
];
$this->delete($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('products');
$this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'Products',
'action' => 'delete',
'cfc98a9a-29b2-44c8-b587-8156adc05317',
];
$this->delete($url);
$this->assertResponseCode(302);
$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;
use Cake\ORM\Table;
use Cake\TestSuite\TestCase;
use CakeProducts\Model\Table\ExternalProductCatalogsTable;
use PHPUnit\Framework\Attributes\CoversClass;
@@ -12,102 +11,98 @@ use PHPUnit\Framework\Attributes\CoversClass;
* CakeProducts\Model\Table\ExternalProductCatalogsTable Test Case
*/
#[CoversClass(ExternalProductCatalogsTable::class)]
class ExternalProductCatalogsTableTest extends TestCase
{
/**
class ExternalProductCatalogsTableTest extends TestCase {
/**
* Test subject
*
* @var ExternalProductCatalogsTable
* @var \CakeProducts\Model\Table\ExternalProductCatalogsTable
*/
protected $ExternalProductCatalogs;
protected $ExternalProductCatalogs;
/**
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeProducts.ExternalProductCatalogs',
'plugin.CakeProducts.ExternalProductCatalogsProductCatalogs',
'plugin.CakeProducts.ProductCatalogs',
];
protected array $fixtures = [
'plugin.CakeProducts.ExternalProductCatalogs',
'plugin.CakeProducts.ExternalProductCatalogsProductCatalogs',
'plugin.CakeProducts.ProductCatalogs',
];
/**
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$config = $this->getTableLocator()->exists('ExternalProductCatalogs') ? [] : ['className' => ExternalProductCatalogsTable::class];
$this->ExternalProductCatalogs = $this->getTableLocator()->get('ExternalProductCatalogs', $config);
}
protected function setUp(): void {
parent::setUp();
$config = $this->getTableLocator()->exists('ExternalProductCatalogs') ? [] : ['className' => ExternalProductCatalogsTable::class];
$this->ExternalProductCatalogs = $this->getTableLocator()->get('ExternalProductCatalogs', $config);
}
/**
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->ExternalProductCatalogs);
protected function tearDown(): void {
unset($this->ExternalProductCatalogs);
parent::tearDown();
}
parent::tearDown();
}
/**
/**
* TestInitialize method
*
* @return void
* @uses \CakeProducts\Model\Table\ExternalProductCatalogsTable::initialize
* @return void
*/
public function testInitialize(): void
{
// verify all associations loaded
$expectedAssociations = [
'ProductCatalogs',
'ExternalProductCatalogsProductCatalogs',
];
$associations = $this->ExternalProductCatalogs->associations();
public function testInitialize(): void {
// verify all associations loaded
$expectedAssociations = [
'ProductCatalogs',
'ExternalProductCatalogsProductCatalogs',
];
$associations = $this->ExternalProductCatalogs->associations();
$this->assertCount(count($expectedAssociations), $associations);
foreach ($expectedAssociations as $expectedAssociation) {
$this->assertTrue($this->ExternalProductCatalogs->hasAssociation($expectedAssociation));
}
$this->assertCount(count($expectedAssociations), $associations);
foreach ($expectedAssociations as $expectedAssociation) {
$this->assertTrue($this->ExternalProductCatalogs->hasAssociation($expectedAssociation));
}
// verify all behaviors loaded
$expectedBehaviors = [
'Timestamp',
'Trash',
];
$behaviors = $this->ExternalProductCatalogs->behaviors();
// verify all behaviors loaded
$expectedBehaviors = [
'Timestamp',
'Trash',
];
$behaviors = $this->ExternalProductCatalogs->behaviors();
$this->assertCount(count($expectedBehaviors), $behaviors);
foreach ($expectedBehaviors as $expectedBehavior) {
$this->assertTrue($this->ExternalProductCatalogs->hasBehavior($expectedBehavior));
}
}
$this->assertCount(count($expectedBehaviors), $behaviors);
foreach ($expectedBehaviors as $expectedBehavior) {
$this->assertTrue($this->ExternalProductCatalogs->hasBehavior($expectedBehavior));
}
}
/**
/**
* Test validationDefault method
*
* @return void
* @uses \CakeProducts\Model\Table\ExternalProductCatalogsTable::validationDefault
* @return void
*/
public function testValidationDefault(): void
{
$this->markTestIncomplete('Not implemented yet.');
}
public function testValidationDefault(): void {
$this->markTestIncomplete('Not implemented yet.');
}
/**
/**
* Test buildRules method
*
* @return void
* @uses \CakeProducts\Model\Table\ExternalProductCatalogsTable::buildRules
* @return void
*/
public function testBuildRules(): void
{
$this->markTestIncomplete('Not implemented yet.');
}
public function testBuildRules(): void {
$this->markTestIncomplete('Not implemented yet.');
}
}
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace CakeProducts\Test\TestCase\Model\Table;
use Cake\ORM\Table;
use Cake\TestSuite\TestCase;
use CakeProducts\Model\Table\ProductCatalogsTable;
use PHPUnit\Framework\Attributes\CoversClass;
@@ -12,90 +11,87 @@ use PHPUnit\Framework\Attributes\CoversClass;
* CakeProducts\Model\Table\ProductCatalogsTable Test Case
*/
#[CoversClass(ProductCatalogsTable::class)]
class ProductCatalogsTableTest extends TestCase
{
/**
class ProductCatalogsTableTest extends TestCase {
/**
* Test subject
*
* @var ProductCatalogsTable|Table
* @var \CakeProducts\Model\Table\ProductCatalogsTable|\Cake\ORM\Table
*/
protected $ProductCatalogs;
protected $ProductCatalogs;
/**
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeProducts.ProductCatalogs',
'plugin.CakeProducts.ExternalProductCatalogsProductCatalogs',
'plugin.CakeProducts.ProductCategories',
];
protected array $fixtures = [
'plugin.CakeProducts.ProductCatalogs',
'plugin.CakeProducts.ExternalProductCatalogsProductCatalogs',
'plugin.CakeProducts.ProductCategories',
];
/**
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$config = $this->getTableLocator()->exists('ProductCatalogs') ? [] : ['className' => ProductCatalogsTable::class];
$this->ProductCatalogs = $this->getTableLocator()->get('ProductCatalogs', $config);
}
protected function setUp(): void {
parent::setUp();
$config = $this->getTableLocator()->exists('ProductCatalogs') ? [] : ['className' => ProductCatalogsTable::class];
$this->ProductCatalogs = $this->getTableLocator()->get('ProductCatalogs', $config);
}
/**
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->ProductCatalogs);
protected function tearDown(): void {
unset($this->ProductCatalogs);
parent::tearDown();
}
parent::tearDown();
}
/**
/**
* TestInitialize method
*
* @return void
* @uses \CakeProducts\Model\Table\ProductCatalogsTable::initialize
* @return void
*/
public function testInitialize(): void
{
// verify all associations loaded
$expectedAssociations = [
'ProductCategories',
'ExternalProductCatalogs',
];
$associations = $this->ProductCatalogs->associations();
public function testInitialize(): void {
// verify all associations loaded
$expectedAssociations = [
'ProductCategories',
'ExternalProductCatalogs',
];
$associations = $this->ProductCatalogs->associations();
$this->assertCount(count($expectedAssociations), $associations);
foreach ($expectedAssociations as $expectedAssociation) {
$this->assertTrue($this->ProductCatalogs->hasAssociation($expectedAssociation));
}
$this->assertCount(count($expectedAssociations), $associations);
foreach ($expectedAssociations as $expectedAssociation) {
$this->assertTrue($this->ProductCatalogs->hasAssociation($expectedAssociation));
}
// verify all behaviors loaded
$expectedBehaviors = [
'Trash',
];
$behaviors = $this->ProductCatalogs->behaviors();
// verify all behaviors loaded
$expectedBehaviors = [
'Trash',
];
$behaviors = $this->ProductCatalogs->behaviors();
$this->assertCount(count($expectedBehaviors), $behaviors);
foreach ($expectedBehaviors as $expectedBehavior) {
$this->assertTrue($this->ProductCatalogs->hasBehavior($expectedBehavior));
}
}
$this->assertCount(count($expectedBehaviors), $behaviors);
foreach ($expectedBehaviors as $expectedBehavior) {
$this->assertTrue($this->ProductCatalogs->hasBehavior($expectedBehavior));
}
}
/**
/**
* Test validationDefault method
*
* @return void
* @uses \CakeProducts\Model\Table\ProductCatalogsTable::validationDefault
* @return void
*/
public function testValidationDefault(): void
{
$this->markTestIncomplete('Not implemented yet.');
}
public function testValidationDefault(): void {
$this->markTestIncomplete('Not implemented yet.');
}
}
@@ -11,107 +11,103 @@ use PHPUnit\Framework\Attributes\CoversClass;
* CakeProducts\Model\Table\ProductCategoriesTable Test Case
*/
#[CoversClass(ProductCategoriesTable::class)]
class ProductCategoriesTableTest extends TestCase
{
/**
class ProductCategoriesTableTest extends TestCase {
/**
* Test subject
*
* @var \CakeProducts\Model\Table\ProductCategoriesTable
*/
protected $ProductCategories;
protected $ProductCategories;
/**
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeProducts.ProductCategories',
'plugin.CakeProducts.ProductCatalogs',
];
protected array $fixtures = [
'plugin.CakeProducts.ProductCategories',
'plugin.CakeProducts.ProductCatalogs',
];
/**
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$config = $this->getTableLocator()->exists('ProductCategories') ? [] : ['className' => ProductCategoriesTable::class];
$this->ProductCategories = $this->getTableLocator()->get('ProductCategories', $config);
}
protected function setUp(): void {
parent::setUp();
$config = $this->getTableLocator()->exists('ProductCategories') ? [] : ['className' => ProductCategoriesTable::class];
$this->ProductCategories = $this->getTableLocator()->get('ProductCategories', $config);
}
/**
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->ProductCategories);
protected function tearDown(): void {
unset($this->ProductCategories);
parent::tearDown();
}
parent::tearDown();
}
/**
/**
* TestInitialize method
*
* @return void
* @uses \CakeProducts\Model\Table\ProductCategoriesTable::initialize()
* @return void
*/
public function testInitialize(): void
{
// verify all associations loaded
$expectedAssociations = [
'ProductCatalogs',
'ParentProductCategories',
'ChildProductCategories',
'Products',
'ProductCategoryAttributes',
'ProductCategoryVariants',
'ProductPhotos',
'PrimaryProductPhotos',
];
$associations = $this->ProductCategories->associations();
public function testInitialize(): void {
// verify all associations loaded
$expectedAssociations = [
'ProductCatalogs',
'ParentProductCategories',
'ChildProductCategories',
'Products',
'ProductCategoryAttributes',
'ProductCategoryVariants',
'ProductPhotos',
'PrimaryProductPhotos',
];
$associations = $this->ProductCategories->associations();
$this->assertCount(count($expectedAssociations), $associations);
foreach ($expectedAssociations as $expectedAssociation) {
$this->assertTrue($this->ProductCategories->hasAssociation($expectedAssociation));
}
$this->assertCount(count($expectedAssociations), $associations);
foreach ($expectedAssociations as $expectedAssociation) {
$this->assertTrue($this->ProductCategories->hasAssociation($expectedAssociation));
}
// verify all behaviors loaded
$expectedBehaviors = [
'Tree',
'Trash',
];
$behaviors = $this->ProductCategories->behaviors();
// verify all behaviors loaded
$expectedBehaviors = [
'Tree',
'Trash',
];
$behaviors = $this->ProductCategories->behaviors();
$this->assertCount(count($expectedBehaviors), $behaviors);
foreach ($expectedBehaviors as $expectedBehavior) {
$this->assertTrue($this->ProductCategories->hasBehavior($expectedBehavior));
}
}
$this->assertCount(count($expectedBehaviors), $behaviors);
foreach ($expectedBehaviors as $expectedBehavior) {
$this->assertTrue($this->ProductCategories->hasBehavior($expectedBehavior));
}
}
/**
/**
* Test validationDefault method
*
* @return void
* @uses \CakeProducts\Model\Table\ProductCategoriesTable::validationDefault()
* @return void
*/
public function testValidationDefault(): void
{
$this->markTestIncomplete('Not implemented yet.');
}
public function testValidationDefault(): void {
$this->markTestIncomplete('Not implemented yet.');
}
/**
/**
* Test buildRules method
*
* @return void
* @uses \CakeProducts\Model\Table\ProductCategoriesTable::buildRules()
* @return void
*/
public function testBuildRules(): void
{
$this->markTestIncomplete('Not implemented yet.');
}
public function testBuildRules(): void {
$this->markTestIncomplete('Not implemented yet.');
}
}
@@ -11,98 +11,94 @@ use PHPUnit\Framework\Attributes\CoversClass;
* CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable Test Case
*/
#[CoversClass(ProductCategoryAttributeOptionsTable::class)]
class ProductCategoryAttributeOptionsTableTest extends TestCase
{
/**
class ProductCategoryAttributeOptionsTableTest extends TestCase {
/**
* Test subject
*
* @var ProductCategoryAttributeOptionsTable
* @var \CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable
*/
protected $ProductCategoryAttributeOptions;
protected $ProductCategoryAttributeOptions;
/**
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeProducts.ProductCategoryAttributeOptions',
];
protected array $fixtures = [
'plugin.CakeProducts.ProductCategoryAttributeOptions',
];
/**
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$config = $this->getTableLocator()->exists('ProductCategoryAttributeOptions') ? [] : ['className' => ProductCategoryAttributeOptionsTable::class];
$this->ProductCategoryAttributeOptions = $this->getTableLocator()->get('ProductCategoryAttributeOptions', $config);
}
protected function setUp(): void {
parent::setUp();
$config = $this->getTableLocator()->exists('ProductCategoryAttributeOptions') ? [] : ['className' => ProductCategoryAttributeOptionsTable::class];
$this->ProductCategoryAttributeOptions = $this->getTableLocator()->get('ProductCategoryAttributeOptions', $config);
}
/**
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->ProductCategoryAttributeOptions);
protected function tearDown(): void {
unset($this->ProductCategoryAttributeOptions);
parent::tearDown();
}
parent::tearDown();
}
/**
/**
* TestInitialize method
*
* @return void
* @uses \CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable::initialize
* @return void
*/
public function testInitialize(): void
{
// verify all associations loaded
$expectedAssociations = [
'ProductCategoryAttributes',
];
$associations = $this->ProductCategoryAttributeOptions->associations();
public function testInitialize(): void {
// verify all associations loaded
$expectedAssociations = [
'ProductCategoryAttributes',
];
$associations = $this->ProductCategoryAttributeOptions->associations();
$this->assertCount(count($expectedAssociations), $associations);
foreach ($expectedAssociations as $expectedAssociation) {
$this->assertTrue($this->ProductCategoryAttributeOptions->hasAssociation($expectedAssociation));
}
$this->assertCount(count($expectedAssociations), $associations);
foreach ($expectedAssociations as $expectedAssociation) {
$this->assertTrue($this->ProductCategoryAttributeOptions->hasAssociation($expectedAssociation));
}
// verify all behaviors loaded
$expectedBehaviors = [
'Trash',
];
$behaviors = $this->ProductCategoryAttributeOptions->behaviors();
// verify all behaviors loaded
$expectedBehaviors = [
'Trash',
];
$behaviors = $this->ProductCategoryAttributeOptions->behaviors();
$this->assertCount(count($expectedBehaviors), $behaviors);
foreach ($expectedBehaviors as $expectedBehavior) {
$this->assertTrue($this->ProductCategoryAttributeOptions->hasBehavior($expectedBehavior));
}
}
$this->assertCount(count($expectedBehaviors), $behaviors);
foreach ($expectedBehaviors as $expectedBehavior) {
$this->assertTrue($this->ProductCategoryAttributeOptions->hasBehavior($expectedBehavior));
}
}
/**
/**
* Test validationDefault method
*
* @return void
* @uses \CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable::validationDefault
* @return void
*/
public function testValidationDefault(): void
{
$this->markTestIncomplete('Not implemented yet.');
}
public function testValidationDefault(): void {
$this->markTestIncomplete('Not implemented yet.');
}
/**
/**
* Test buildRules method
*
* @return void
* @uses \CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable::buildRules
* @return void
*/
public function testBuildRules(): void
{
$this->markTestIncomplete('Not implemented yet.');
}
public function testBuildRules(): void {
$this->markTestIncomplete('Not implemented yet.');
}
}
@@ -11,101 +11,97 @@ use PHPUnit\Framework\Attributes\CoversClass;
* CakeProducts\Model\Table\ProductCategoryAttributesTable Test Case
*/
#[CoversClass(ProductCategoryAttributesTable::class)]
class ProductCategoryAttributesTableTest extends TestCase
{
/**
class ProductCategoryAttributesTableTest extends TestCase {
/**
* Test subject
*
* @var ProductCategoryAttributesTable
* @var \CakeProducts\Model\Table\ProductCategoryAttributesTable
*/
protected $ProductCategoryAttributes;
protected $ProductCategoryAttributes;
/**
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeProducts.ProductCategoryAttributes',
'plugin.CakeProducts.ProductCategoryAttributeOptions',
'plugin.CakeProducts.ProductCategories',
];
protected array $fixtures = [
'plugin.CakeProducts.ProductCategoryAttributes',
'plugin.CakeProducts.ProductCategoryAttributeOptions',
'plugin.CakeProducts.ProductCategories',
];
/**
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$config = $this->getTableLocator()->exists('ProductCategoryAttributes') ? [] : ['className' => ProductCategoryAttributesTable::class];
$this->ProductCategoryAttributes = $this->getTableLocator()->get('ProductCategoryAttributes', $config);
}
protected function setUp(): void {
parent::setUp();
$config = $this->getTableLocator()->exists('ProductCategoryAttributes') ? [] : ['className' => ProductCategoryAttributesTable::class];
$this->ProductCategoryAttributes = $this->getTableLocator()->get('ProductCategoryAttributes', $config);
}
/**
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->ProductCategoryAttributes);
protected function tearDown(): void {
unset($this->ProductCategoryAttributes);
parent::tearDown();
}
parent::tearDown();
}
/**
/**
* TestInitialize method
*
* @return void
* @uses \CakeProducts\Model\Table\ProductCategoryAttributesTable::initialize
* @return void
*/
public function testInitialize(): void
{
// verify all associations loaded
$expectedAssociations = [
'ProductCategories',
'ProductCategoryAttributeOptions',
];
$associations = $this->ProductCategoryAttributes->associations();
public function testInitialize(): void {
// verify all associations loaded
$expectedAssociations = [
'ProductCategories',
'ProductCategoryAttributeOptions',
];
$associations = $this->ProductCategoryAttributes->associations();
$this->assertCount(count($expectedAssociations), $associations);
foreach ($expectedAssociations as $expectedAssociation) {
$this->assertTrue($this->ProductCategoryAttributes->hasAssociation($expectedAssociation));
}
$this->assertCount(count($expectedAssociations), $associations);
foreach ($expectedAssociations as $expectedAssociation) {
$this->assertTrue($this->ProductCategoryAttributes->hasAssociation($expectedAssociation));
}
// verify all behaviors loaded
$expectedBehaviors = [
'Trash',
];
$behaviors = $this->ProductCategoryAttributes->behaviors();
// verify all behaviors loaded
$expectedBehaviors = [
'Trash',
];
$behaviors = $this->ProductCategoryAttributes->behaviors();
$this->assertCount(count($expectedBehaviors), $behaviors);
foreach ($expectedBehaviors as $expectedBehavior) {
$this->assertTrue($this->ProductCategoryAttributes->hasBehavior($expectedBehavior));
}
}
$this->assertCount(count($expectedBehaviors), $behaviors);
foreach ($expectedBehaviors as $expectedBehavior) {
$this->assertTrue($this->ProductCategoryAttributes->hasBehavior($expectedBehavior));
}
}
/**
/**
* Test validationDefault method
*
* @return void
* @uses \CakeProducts\Model\Table\ProductCategoryAttributesTable::validationDefault
* @return void
*/
public function testValidationDefault(): void
{
$this->markTestIncomplete('Not implemented yet.');
}
public function testValidationDefault(): void {
$this->markTestIncomplete('Not implemented yet.');
}
/**
/**
* Test buildRules method
*
* @return void
* @uses \CakeProducts\Model\Table\ProductCategoryAttributesTable::buildRules
* @return void
*/
public function testBuildRules(): void
{
$this->markTestIncomplete('Not implemented yet.');
}
public function testBuildRules(): void {
$this->markTestIncomplete('Not implemented yet.');
}
}
@@ -3,107 +3,103 @@ declare(strict_types=1);
namespace CakeProducts\Test\TestCase\Model\Table;
use CakeProducts\Model\Table\ProductCategoryVariantOptionsTable;
use Cake\TestSuite\TestCase;
use CakeProducts\Model\Table\ProductCategoryVariantOptionsTable;
use PHPUnit\Framework\Attributes\CoversClass;
/**
* App\Model\Table\ProductCategoryVariantOptionsTable Test Case
*/
#[CoversClass(ProductCategoryVariantOptionsTable::class)]
class ProductCategoryVariantOptionsTableTest extends TestCase
{
/**
class ProductCategoryVariantOptionsTableTest extends TestCase {
/**
* Test subject
*
* @var \App\Model\Table\ProductCategoryVariantOptionsTable
*/
protected $ProductCategoryVariantOptions;
protected $ProductCategoryVariantOptions;
/**
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeProducts.ProductCategoryVariants',
'plugin.CakeProducts.ProductCategoryVariantOptions',
];
protected array $fixtures = [
'plugin.CakeProducts.ProductCategoryVariants',
'plugin.CakeProducts.ProductCategoryVariantOptions',
];
/**
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$config = $this->getTableLocator()->exists('ProductCategoryVariantOptions') ? [] : ['className' => ProductCategoryVariantOptionsTable::class];
$this->ProductCategoryVariantOptions = $this->getTableLocator()->get('ProductCategoryVariantOptions', $config);
}
protected function setUp(): void {
parent::setUp();
$config = $this->getTableLocator()->exists('ProductCategoryVariantOptions') ? [] : ['className' => ProductCategoryVariantOptionsTable::class];
$this->ProductCategoryVariantOptions = $this->getTableLocator()->get('ProductCategoryVariantOptions', $config);
}
/**
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->ProductCategoryVariantOptions);
protected function tearDown(): void {
unset($this->ProductCategoryVariantOptions);
parent::tearDown();
}
parent::tearDown();
}
/**
/**
* TestInitialize method
*
* @return void
* @uses \CakeProducts\Model\Table\ProductCategoryVariantOptionsTable::initialize()
* @return void
*/
public function testInitialize(): void
{
// verify all associations loaded
$expectedAssociations = [
'ProductCategoryVariants',
];
$associations = $this->ProductCategoryVariantOptions->associations();
public function testInitialize(): void {
// verify all associations loaded
$expectedAssociations = [
'ProductCategoryVariants',
];
$associations = $this->ProductCategoryVariantOptions->associations();
$this->assertCount(count($expectedAssociations), $associations);
foreach ($expectedAssociations as $expectedAssociation) {
$this->assertTrue($this->ProductCategoryVariantOptions->hasAssociation($expectedAssociation));
}
$this->assertCount(count($expectedAssociations), $associations);
foreach ($expectedAssociations as $expectedAssociation) {
$this->assertTrue($this->ProductCategoryVariantOptions->hasAssociation($expectedAssociation));
}
// verify all behaviors loaded
$expectedBehaviors = [
'Timestamp',
];
$behaviors = $this->ProductCategoryVariantOptions->behaviors();
// verify all behaviors loaded
$expectedBehaviors = [
'Timestamp',
];
$behaviors = $this->ProductCategoryVariantOptions->behaviors();
$this->assertCount(count($expectedBehaviors), $behaviors);
foreach ($expectedBehaviors as $expectedBehavior) {
$this->assertTrue($this->ProductCategoryVariantOptions->hasBehavior($expectedBehavior));
}
}
$this->assertCount(count($expectedBehaviors), $behaviors);
foreach ($expectedBehaviors as $expectedBehavior) {
$this->assertTrue($this->ProductCategoryVariantOptions->hasBehavior($expectedBehavior));
}
}
/**
/**
* Test validationDefault method
*
* @return void
* @uses \CakeProducts\Model\Table\ProductCategoryVariantOptionsTable::validationDefault()
* @return void
*/
public function testValidationDefault(): void
{
$this->markTestIncomplete('Not implemented yet.');
}
public function testValidationDefault(): void {
$this->markTestIncomplete('Not implemented yet.');
}
/**
/**
* Test buildRules method
*
* @return void
* @uses \CakeProducts\Model\Table\ProductCategoryVariantOptionsTable::buildRules()
* @return void
*/
public function testBuildRules(): void
{
$this->markTestIncomplete('Not implemented yet.');
}
public function testBuildRules(): void {
$this->markTestIncomplete('Not implemented yet.');
}
}

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