Merge branch 'develop' into prod
CI / testsuite (mysql, 8.2, ) (push) Successful in 3m39s
CI / testsuite (pgsql, 8.2, ) (push) Successful in 5m28s
CI / testsuite (pgsql, 8.5, ) (push) Successful in 3m8s
CI / testsuite (mysql, 8.5, ) (push) Successful in 9m33s
CI / testsuite (sqlite, 8.2, ) (push) Successful in 4m47s
CI / testsuite (sqlite, 8.2, prefer-lowest) (push) Successful in 3m40s
Release / build (push) Successful in 12s
CI / testsuite (sqlite, 8.5, ) (push) Successful in 3m59s
CI / Coding Standard & Static Analysis (push) Successful in 4m50s

This commit is contained in:
bs
2026-08-26 02:07:10 -07:00
117 changed files with 5933 additions and 7724 deletions
+7 -17
View File
@@ -11,9 +11,9 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
php-version: ['8.2', '8.4'] php-version: ['8.2', '8.5']
db-type: ['mysql'] # db-type: ['mysql']
# db-type: ['sqlite', 'mysql', 'pgsql'] db-type: ['sqlite', 'mysql', 'pgsql']
prefer-lowest: [''] prefer-lowest: ['']
include: include:
- php-version: '8.2' - php-version: '8.2'
@@ -33,13 +33,6 @@ jobs:
# - 5432:5432 # - 5432:5432
# env: # env:
# POSTGRES_PASSWORD: postgres # POSTGRES_PASSWORD: postgres
# mysql8:
# image: mysql:8.0
# env:
# MYSQL_ALLOW_EMPTY_PASSWORD: yes
# MYSQL_DATABASE: test_db
# ports:
# - 3306:3306
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
@@ -47,7 +40,7 @@ jobs:
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v2
with: with:
php-version: ${{ matrix.php-version }} php-version: ${{ matrix.php-version }}
extensions: mbstring, intl, sqlite, pdo_${{ matrix.db-type }} extensions: mbstring, intl, bcmath, sqlite, pdo_${{ matrix.db-type }}
coverage: pcov coverage: pcov
- name: Get composer cache directory - name: Get composer cache directory
@@ -108,8 +101,8 @@ jobs:
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v2
with: with:
php-version: '8.1' php-version: '8.2'
extensions: mbstring, intl, sqlite extensions: mbstring, intl, sqlite, bcmath
coverage: none coverage: none
- name: Get composer cache directory - name: Get composer cache directory
@@ -133,11 +126,8 @@ jobs:
composer install --no-progress --prefer-dist --optimize-autoloader composer install --no-progress --prefer-dist --optimize-autoloader
fi fi
- name: Composer phpstan setup
run: composer stan-setup
- name: Run phpstan - name: Run phpstan
run: vendor/bin/phpstan analyse --error-format=github run: vendor/bin/phpstan analyse src --error-format=github
- name: Run phpcs - name: Run phpcs
run: composer cs-check run: composer cs-check
+17
View File
@@ -0,0 +1,17 @@
name: Release
on:
push:
tags:
- "v*.*.*"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Release
uses: softprops/action-gh-release@v2
+31
View File
@@ -0,0 +1,31 @@
---
name: CI Build Status
on:
workflow_run:
workflows:
- CI
types:
- completed
jobs:
on-success:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Webhook
uses: zzzze/webhook-trigger@master
with:
data: "{\"text\":\"${{ gitea.repository }} build succeeded 🎉\"}"
webhook_url: ${{ secrets.BUILD_STATUS_NOTIFY_WEBHOOK_URL }}
options: "-H \"Content-Type: application/json\""
on-failure:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
- name: Webhook
uses: zzzze/webhook-trigger@master
with:
data: "{\"text\":\"${{ gitea.repository }} build failed 🔎\"}"
webhook_url: ${{ secrets.BUILD_STATUS_NOTIFY_WEBHOOK_URL }}
options: "-H \"Content-Type: application/json\""
+1
View File
@@ -8,3 +8,4 @@
/.idea/ /.idea/
tmp tmp
tests/test_app/webroot/images/products/ tests/test_app/webroot/images/products/
tests/test_app/webroot/uploads/
+23 -3
View File
@@ -9,11 +9,14 @@
"dereuromark/cakephp-tools": "^3.9", "dereuromark/cakephp-tools": "^3.9",
"muffin/trash": "^4.2", "muffin/trash": "^4.2",
"cakephp/cakephp": "^5.0.1", "cakephp/cakephp": "^5.0.1",
"bentools/cartesian-product": "dev-master" "bentools/cartesian-product": "^2.0"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^10.1", "phpunit/phpunit": "^10.3",
"cakephp/migrations": "^4.0.0" "cakephp/migrations": "^4.5.0",
"cakedc/cakephp-phpstan": "^4.1",
"dereuromark/composer-prefer-lowest": "^0.1.10",
"fig-r/psr2r-sniffer": "^2.7"
}, },
"suggest": { "suggest": {
"hi-powered-dev/cake-carts": "Allow users to add products/SKUs to a cart" "hi-powered-dev/cake-carts": "Allow users to add products/SKUs to a cart"
@@ -29,5 +32,22 @@
"Cake\\Test\\": "vendor/cakephp/cakephp/tests/", "Cake\\Test\\": "vendor/cakephp/cakephp/tests/",
"TestApp\\": "tests/test_app/src/" "TestApp\\": "tests/test_app/src/"
} }
},
"scripts": {
"check": [
"@test",
"@cs-check"
],
"test": "phpunit --colors=always",
"cs-check": "vendor/bin/phpcs --colors",
"cs-fix": "vendor/bin/phpcbf --colors",
"lowest": "validate-prefer-lowest",
"lowest-setup": "composer update --prefer-lowest --prefer-stable --prefer-dist --no-interaction && cp composer.json composer.backup && composer require --dev dereuromark/composer-prefer-lowest && mv composer.backup composer.json",
"stan": "phpstan analyze"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": false
}
} }
} }
@@ -1,10 +1,10 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
use Migrations\AbstractMigration; use Migrations\BaseMigration;
class CreateProductCatalogs extends BaseMigration {
class CreateProductCatalogs extends AbstractMigration
{
/** /**
* Change Method. * Change Method.
* *
@@ -12,8 +12,7 @@ class CreateProductCatalogs extends AbstractMigration
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{
$table = $this->table('product_catalogs', ['id' => false, 'primary_key' => ['id']]); $table = $this->table('product_catalogs', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [ $table->addColumn('id', 'uuid', [
'default' => null, 'default' => null,
@@ -41,4 +40,5 @@ class CreateProductCatalogs extends AbstractMigration
]); ]);
$table->create(); $table->create();
} }
} }
@@ -1,10 +1,10 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
use Migrations\AbstractMigration; use Migrations\BaseMigration;
class CreateProductCategories extends BaseMigration {
class CreateProductCategories extends AbstractMigration
{
/** /**
* Change Method. * Change Method.
* *
@@ -12,8 +12,7 @@ class CreateProductCategories extends AbstractMigration
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{
$table = $this->table('product_categories'); $table = $this->table('product_categories');
$table->addColumn('product_catalog_id', 'uuid', [ $table->addColumn('product_catalog_id', 'uuid', [
@@ -75,4 +74,5 @@ class CreateProductCategories extends AbstractMigration
]); ]);
$table->create(); $table->create();
} }
} }
@@ -1,10 +1,10 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
use Migrations\AbstractMigration; use Migrations\BaseMigration;
class CreateProducts extends BaseMigration {
class CreateProducts extends AbstractMigration
{
/** /**
* Change Method. * Change Method.
* *
@@ -12,8 +12,7 @@ class CreateProducts extends AbstractMigration
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{
$table = $this->table('products', ['id' => false, 'primary_key' => ['id']]); $table = $this->table('products', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [ $table->addColumn('id', 'uuid', [
'default' => null, 'default' => null,
@@ -44,4 +43,5 @@ class CreateProducts extends AbstractMigration
// ]); // ]);
$table->create(); $table->create();
} }
} }
@@ -1,10 +1,10 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
use Migrations\AbstractMigration; use Migrations\BaseMigration;
class CreateProductCategoryAttributes extends BaseMigration {
class CreateProductCategoryAttributes extends AbstractMigration
{
/** /**
* Change Method. * Change Method.
* *
@@ -12,8 +12,7 @@ class CreateProductCategoryAttributes extends AbstractMigration
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{
$table = $this->table('product_category_attributes', ['id' => false, 'primary_key' => ['id']]); $table = $this->table('product_category_attributes', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [ $table->addColumn('id', 'uuid', [
'default' => null, 'default' => null,
@@ -52,4 +51,5 @@ class CreateProductCategoryAttributes extends AbstractMigration
]); ]);
$table->create(); $table->create();
} }
} }
@@ -1,10 +1,10 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
use Migrations\AbstractMigration; use Migrations\BaseMigration;
class CreateProductCategoryAttributeOptions extends BaseMigration {
class CreateProductCategoryAttributeOptions extends AbstractMigration
{
/** /**
* Change Method. * Change Method.
* *
@@ -12,8 +12,7 @@ class CreateProductCategoryAttributeOptions extends AbstractMigration
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{
$table = $this->table('product_category_attribute_options', ['id' => false, 'primary_key' => ['id']]); $table = $this->table('product_category_attribute_options', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [ $table->addColumn('id', 'uuid', [
'default' => null, 'default' => null,
@@ -45,4 +44,5 @@ class CreateProductCategoryAttributeOptions extends AbstractMigration
]); ]);
$table->create(); $table->create();
} }
} }
@@ -1,56 +0,0 @@
<?php
declare(strict_types=1);
use Migrations\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();
}
}
@@ -1,22 +0,0 @@
<?php
declare(strict_types=1);
use Migrations\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();
}
}
@@ -1,36 +0,0 @@
<?php
declare(strict_types=1);
use Migrations\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();
}
}
@@ -3,8 +3,8 @@ declare(strict_types=1);
use Migrations\BaseMigration; use Migrations\BaseMigration;
class CreateProductAttributes extends BaseMigration class CreateProductAttributes extends BaseMigration {
{
/** /**
* Change Method. * Change Method.
* *
@@ -12,8 +12,7 @@ class CreateProductAttributes extends BaseMigration
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{
$table = $this->table('product_attributes', ['id' => false, 'primary_key' => ['id']]); $table = $this->table('product_attributes', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [ $table->addColumn('id', 'uuid', [
'default' => null, 'default' => null,
@@ -38,4 +37,5 @@ class CreateProductAttributes extends BaseMigration
]); ]);
$table->create(); $table->create();
} }
} }
@@ -3,8 +3,8 @@ declare(strict_types=1);
use Migrations\BaseMigration; use Migrations\BaseMigration;
class AddSoftDeleteToAllTables extends BaseMigration class AddSoftDeleteToAllTables extends BaseMigration {
{
/** /**
* Change Method. * Change Method.
* *
@@ -12,8 +12,7 @@ class AddSoftDeleteToAllTables extends BaseMigration
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{
$table = $this->table('products'); $table = $this->table('products');
$table->addColumn('deleted', 'datetime', [ $table->addColumn('deleted', 'datetime', [
'default' => null, 'default' => null,
@@ -49,13 +48,6 @@ class AddSoftDeleteToAllTables extends BaseMigration
]); ]);
$table->update(); $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 = $this->table('product_attributes');
$table->addColumn('deleted', 'datetime', [ $table->addColumn('deleted', 'datetime', [
'default' => null, 'default' => null,
@@ -63,4 +55,5 @@ class AddSoftDeleteToAllTables extends BaseMigration
]); ]);
$table->update(); $table->update();
} }
} }
@@ -3,8 +3,8 @@ declare(strict_types=1);
use Migrations\BaseMigration; use Migrations\BaseMigration;
class CreateProductSkus extends BaseMigration class CreateProductSkus extends BaseMigration {
{
/** /**
* Change Method. * Change Method.
* *
@@ -12,8 +12,7 @@ class CreateProductSkus extends BaseMigration
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{
$table = $this->table('product_skus', ['id' => false, 'primary_key' => ['id']]); $table = $this->table('product_skus', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [ $table->addColumn('id', 'uuid', [
'default' => null, 'default' => null,
@@ -59,4 +58,5 @@ class CreateProductSkus extends BaseMigration
]); ]);
$table->create(); $table->create();
} }
} }
@@ -1,10 +1,10 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
use Migrations\AbstractMigration; use Migrations\BaseMigration;
class CreateProductCategoryVariants extends BaseMigration {
class CreateProductCategoryVariants extends AbstractMigration
{
/** /**
* Change Method. * Change Method.
* *
@@ -12,8 +12,7 @@ class CreateProductCategoryVariants extends AbstractMigration
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{
$table = $this->table('product_category_variants', ['id' => false, 'primary_key' => ['id']]); $table = $this->table('product_category_variants', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [ $table->addColumn('id', 'uuid', [
'default' => null, 'default' => null,
@@ -58,4 +57,5 @@ class CreateProductCategoryVariants extends AbstractMigration
// ]); // ]);
$table->create(); $table->create();
} }
} }
@@ -3,8 +3,8 @@ declare(strict_types=1);
use Migrations\BaseMigration; use Migrations\BaseMigration;
class CreateProductCategoryVariantOptions extends BaseMigration class CreateProductCategoryVariantOptions extends BaseMigration {
{
/** /**
* Change Method. * Change Method.
* *
@@ -12,8 +12,7 @@ class CreateProductCategoryVariantOptions extends BaseMigration
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{
$table = $this->table('product_category_variant_options', ['id' => false, 'primary_key' => ['id']]); $table = $this->table('product_category_variant_options', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [ $table->addColumn('id', 'uuid', [
'default' => null, 'default' => null,
@@ -53,4 +52,5 @@ class CreateProductCategoryVariantOptions extends BaseMigration
$table->create(); $table->create();
} }
} }
@@ -3,8 +3,8 @@ declare(strict_types=1);
use Migrations\BaseMigration; use Migrations\BaseMigration;
class AddDefaultProductTypeIdToProductCategories extends BaseMigration class AddDefaultProductTypeIdToProductCategories extends BaseMigration {
{
/** /**
* Change Method. * Change Method.
* *
@@ -12,8 +12,7 @@ class AddDefaultProductTypeIdToProductCategories extends BaseMigration
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{
$table = $this->table('product_categories'); $table = $this->table('product_categories');
$table->addColumn('default_product_type_id', 'integer', [ $table->addColumn('default_product_type_id', 'integer', [
'default' => null, 'default' => null,
@@ -22,4 +21,5 @@ class AddDefaultProductTypeIdToProductCategories extends BaseMigration
]); ]);
$table->update(); $table->update();
} }
} }
@@ -3,8 +3,8 @@ declare(strict_types=1);
use Migrations\BaseMigration; use Migrations\BaseMigration;
class CreateProductPhotos extends BaseMigration class CreateProductPhotos extends BaseMigration {
{
/** /**
* Change Method. * Change Method.
* *
@@ -13,8 +13,7 @@ class CreateProductPhotos extends BaseMigration
* *
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{
$table = $this->table('product_photos', ['id' => false, 'primary_key' => ['id']]); $table = $this->table('product_photos', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [ $table->addColumn('id', 'uuid', [
'default' => null, 'default' => null,
@@ -84,4 +83,5 @@ class CreateProductPhotos extends BaseMigration
$table->create(); $table->create();
} }
} }
@@ -3,8 +3,8 @@ declare(strict_types=1);
use Migrations\BaseMigration; use Migrations\BaseMigration;
class CreateProductSkuVariantValues extends BaseMigration class CreateProductSkuVariantValues extends BaseMigration {
{
/** /**
* Change Method. * Change Method.
* *
@@ -13,8 +13,7 @@ class CreateProductSkuVariantValues extends BaseMigration
* *
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{
$table = $this->table('product_sku_variant_values', ['id' => false, 'primary_key' => ['id']]); $table = $this->table('product_sku_variant_values', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [ $table->addColumn('id', 'uuid', [
'default' => null, 'default' => null,
@@ -34,4 +33,5 @@ class CreateProductSkuVariantValues extends BaseMigration
]); ]);
$table->create(); $table->create();
} }
} }
@@ -3,8 +3,8 @@ declare(strict_types=1);
use Migrations\BaseMigration; use Migrations\BaseMigration;
class CreateProductVariants extends BaseMigration class CreateProductVariants extends BaseMigration {
{
/** /**
* Change Method. * Change Method.
* *
@@ -13,8 +13,7 @@ class CreateProductVariants extends BaseMigration
* *
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{
$table = $this->table('product_variants', ['id' => false, 'primary_key' => ['id']]); $table = $this->table('product_variants', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [ $table->addColumn('id', 'uuid', [
'default' => null, 'default' => null,
@@ -59,4 +58,5 @@ class CreateProductVariants extends BaseMigration
// ]); // ]);
$table->create(); $table->create();
} }
} }
@@ -3,8 +3,8 @@ declare(strict_types=1);
use Migrations\BaseMigration; use Migrations\BaseMigration;
class AddDefaultSkuToProductSkus extends BaseMigration class AddDefaultSkuToProductSkus extends BaseMigration {
{
/** /**
* Change Method. * Change Method.
* *
@@ -12,8 +12,7 @@ class AddDefaultSkuToProductSkus extends BaseMigration
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{
$table = $this->table('product_skus'); $table = $this->table('product_skus');
$table->addColumn('default_sku', 'boolean', [ $table->addColumn('default_sku', 'boolean', [
'default' => false, 'default' => false,
@@ -22,4 +21,5 @@ class AddDefaultSkuToProductSkus extends BaseMigration
]); ]);
$table->update(); $table->update();
} }
} }
@@ -3,8 +3,8 @@ declare(strict_types=1);
use Migrations\BaseMigration; use Migrations\BaseMigration;
class AddProductCategoryIdToProductPhotos extends BaseMigration class AddProductCategoryIdToProductPhotos extends BaseMigration {
{
/** /**
* Change Method. * Change Method.
* *
@@ -13,8 +13,7 @@ class AddProductCategoryIdToProductPhotos extends BaseMigration
* *
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{
$table = $this->table('product_photos'); $table = $this->table('product_photos');
$table->addColumn('product_category_id', 'uuid', [ $table->addColumn('product_category_id', 'uuid', [
'default' => null, 'default' => null,
@@ -26,4 +25,5 @@ class AddProductCategoryIdToProductPhotos extends BaseMigration
]); ]);
$table->update(); $table->update();
} }
} }
@@ -3,8 +3,8 @@ declare(strict_types=1);
use Migrations\BaseMigration; use Migrations\BaseMigration;
class AddPrimarySkuPhotoToProductPhotos extends BaseMigration class AddPrimarySkuPhotoToProductPhotos extends BaseMigration {
{
/** /**
* Change Method. * Change Method.
* *
@@ -12,8 +12,7 @@ class AddPrimarySkuPhotoToProductPhotos extends BaseMigration
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{
$table = $this->table('product_photos'); $table = $this->table('product_photos');
$table->addColumn('primary_sku_photo', 'boolean', [ $table->addColumn('primary_sku_photo', 'boolean', [
'default' => false, 'default' => false,
@@ -22,4 +21,5 @@ class AddPrimarySkuPhotoToProductPhotos extends BaseMigration
]); ]);
$table->update(); $table->update();
} }
} }
@@ -3,8 +3,8 @@ declare(strict_types=1);
use Migrations\BaseMigration; use Migrations\BaseMigration;
class AllowProductIdToBeNullInProductPhotos extends BaseMigration class AllowProductIdToBeNullInProductPhotos extends BaseMigration {
{
/** /**
* Change Method. * Change Method.
* *
@@ -12,8 +12,7 @@ class AllowProductIdToBeNullInProductPhotos extends BaseMigration
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function up(): void public function up(): void {
{
$table = $this->table('product_photos'); $table = $this->table('product_photos');
$table->changeColumn('product_id', 'uuid', [ $table->changeColumn('product_id', 'uuid', [
'default' => null, 'default' => null,
@@ -35,8 +34,7 @@ class AllowProductIdToBeNullInProductPhotos extends BaseMigration
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function down(): void public function down(): void {
{
$table = $this->table('product_photos'); $table = $this->table('product_photos');
$table->changeColumn('product_id', 'uuid', [ $table->changeColumn('product_id', 'uuid', [
'default' => null, 'default' => null,
@@ -50,4 +48,5 @@ class AllowProductIdToBeNullInProductPhotos extends BaseMigration
]); ]);
$table->update(); $table->update();
} }
} }
@@ -3,8 +3,8 @@ declare(strict_types=1);
use Migrations\BaseMigration; use Migrations\BaseMigration;
class AddIsSystemToProductCategoryVariants extends BaseMigration class AddIsSystemToProductCategoryVariants extends BaseMigration {
{
/** /**
* Change Method. * Change Method.
* *
@@ -12,8 +12,7 @@ class AddIsSystemToProductCategoryVariants extends BaseMigration
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
* @return void * @return void
*/ */
public function change(): void public function change(): void {
{
$table = $this->table('product_category_variants'); $table = $this->table('product_category_variants');
$table->addColumn('is_system_variant', 'boolean', [ $table->addColumn('is_system_variant', 'boolean', [
'default' => false, 'default' => false,
@@ -22,4 +21,5 @@ class AddIsSystemToProductCategoryVariants extends BaseMigration
]); ]);
$table->update(); $table->update();
} }
} }
@@ -3,13 +3,14 @@ declare(strict_types=1);
namespace Seeds; namespace Seeds;
use Cake\Utility\Text;
use Migrations\BaseSeed; use Migrations\BaseSeed;
/** /**
* CreateSystemCategoryVariants seed. * CreateSystemCategoryVariants seed.
*/ */
class CreateSystemCategoryVariantsSeed extends BaseSeed class CreateSystemCategoryVariantsSeed extends BaseSeed {
{
/** /**
* Run Method. * Run Method.
* *
@@ -20,18 +21,17 @@ class CreateSystemCategoryVariantsSeed extends BaseSeed
* *
* @return void * @return void
*/ */
public function run(): void public function run(): void {
{
$data = [ $data = [
[ [
'id' => \Cake\Utility\Text::uuid(), 'id' => Text::uuid(),
'name' => 'Subscription Length', 'name' => 'Subscription Length',
'product_category_id' => null, 'product_category_id' => null,
'enabled' => true, 'enabled' => true,
'is_system_variant' => true, 'is_system_variant' => true,
], ],
[ [
'id' => \Cake\Utility\Text::uuid(), 'id' => Text::uuid(),
'name' => 'Subscription Length Units', 'name' => 'Subscription Length Units',
'product_category_id' => null, 'product_category_id' => null,
'enabled' => true, 'enabled' => true,
@@ -52,4 +52,5 @@ class CreateSystemCategoryVariantsSeed extends BaseSeed
$table->insert($data)->save(); $table->insert($data)->save();
} }
} }
} }
+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>
+10
View File
@@ -0,0 +1,10 @@
includes:
- vendor/cakedc/cakephp-phpstan/extension.neon
parameters:
level: 4
paths:
- src
bootstrapFiles:
- tests/bootstrap.php
treatPhpDocTypesAsCertain: false
+10 -14
View File
@@ -13,8 +13,8 @@ use Cake\Routing\RouteBuilder;
/** /**
* Plugin for CakeProducts * Plugin for CakeProducts
*/ */
class CakeProductsPlugin extends BasePlugin class CakeProductsPlugin extends BasePlugin {
{
/** /**
* Load all the plugin configuration and bootstrap logic. * Load all the plugin configuration and bootstrap logic.
* *
@@ -24,8 +24,7 @@ class CakeProductsPlugin extends BasePlugin
* @param \Cake\Core\PluginApplicationInterface $app The host application * @param \Cake\Core\PluginApplicationInterface $app The host application
* @return void * @return void
*/ */
public function bootstrap(PluginApplicationInterface $app): void public function bootstrap(PluginApplicationInterface $app): void {
{
} }
/** /**
@@ -37,8 +36,7 @@ class CakeProductsPlugin extends BasePlugin
* @param \Cake\Routing\RouteBuilder $routes The route builder to update. * @param \Cake\Routing\RouteBuilder $routes The route builder to update.
* @return void * @return void
*/ */
public function routes(RouteBuilder $routes): void public function routes(RouteBuilder $routes): void {
{
$routes->plugin( $routes->plugin(
'CakeProducts', 'CakeProducts',
['path' => '/cake-products'], ['path' => '/cake-products'],
@@ -46,7 +44,7 @@ class CakeProductsPlugin extends BasePlugin
// Add custom routes here // Add custom routes here
$builder->fallbacks(); $builder->fallbacks();
} },
); );
parent::routes($routes); parent::routes($routes);
} }
@@ -57,8 +55,7 @@ class CakeProductsPlugin extends BasePlugin
* @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to update. * @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to update.
* @return \Cake\Http\MiddlewareQueue * @return \Cake\Http\MiddlewareQueue
*/ */
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue {
{
// Add your middlewares here // Add your middlewares here
return $middlewareQueue; return $middlewareQueue;
@@ -70,8 +67,7 @@ class CakeProductsPlugin extends BasePlugin
* @param \Cake\Console\CommandCollection $commands The command collection to update. * @param \Cake\Console\CommandCollection $commands The command collection to update.
* @return \Cake\Console\CommandCollection * @return \Cake\Console\CommandCollection
*/ */
public function console(CommandCollection $commands): CommandCollection public function console(CommandCollection $commands): CommandCollection {
{
// Add your commands here // Add your commands here
$commands = parent::console($commands); $commands = parent::console($commands);
@@ -82,12 +78,12 @@ class CakeProductsPlugin extends BasePlugin
/** /**
* Register application container services. * Register application container services.
* *
* @link https://book.cakephp.org/4/en/development/dependency-injection.html#dependency-injection
* @param \Cake\Core\ContainerInterface $container The Container to update. * @param \Cake\Core\ContainerInterface $container The Container to update.
* @return void * @return void
* @link https://book.cakephp.org/4/en/development/dependency-injection.html#dependency-injection
*/ */
public function services(ContainerInterface $container): void public function services(ContainerInterface $container): void {
{
// Add your services here // Add your services here
} }
} }
+1 -2
View File
@@ -5,6 +5,5 @@ namespace CakeProducts\Controller;
use App\Controller\AppController as BaseController; use App\Controller\AppController as BaseController;
class AppController extends BaseController class AppController extends BaseController {
{
} }
@@ -1,132 +0,0 @@
<?php
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
{
// use OverrideTableTrait;
/**
* @return void
*/
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);
$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.
*/
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.'));
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.
*/
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'));
}
/**
* 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.
*/
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']);
}
}
@@ -1,51 +0,0 @@
<?php
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
{
/**
* Add method
*
* @return Response|null|void Redirects 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'));
}
/**
* Delete method
*
* @param string|null $id Customers Contact id.
* @return Response|null Redirects to index.
* @throws RecordNotFoundException When record not found.
*/
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,
]));
}
}
+19 -30
View File
@@ -4,37 +4,28 @@ declare(strict_types=1);
namespace CakeProducts\Controller; namespace CakeProducts\Controller;
use Cake\Core\Configure; use Cake\Core\Configure;
use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Http\Response;
use Cake\Log\Log; use Cake\Log\Log;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
use CakeProducts\Model\Table\ProductCatalogsTable;
/** /**
* ProductCatalogs Controller * ProductCatalogs Controller
* *
* @property ProductCatalogsTable $ProductCatalogs * @property \CakeProducts\Model\Table\ProductCatalogsTable $ProductCatalogs
*/ */
class ProductCatalogsController extends AppController class ProductCatalogsController extends AppController {
{
/** /**
* @return void * @return void
*/ */
public function initialize(): void public function initialize(): void {
{
parent::initialize(); // TODO: Change the autogenerated stub parent::initialize(); // TODO: Change the autogenerated stub
// $this->_defaultTable = 'CakeProducts.ProductCatalogs';
// $this->_tableConfigKey = 'CakeProducts.ProductCatalogs.table';
} }
/** /**
* Index method * Index method
* *
* @return Response|null|void Renders view * @return \Cake\Http\Response|null|void Renders view
*/ */
public function index() public function index() {
{
$query = $this->ProductCatalogs->find(); $query = $this->ProductCatalogs->find();
$productCatalogs = $this->paginate($query); $productCatalogs = $this->paginate($query);
@@ -45,11 +36,11 @@ class ProductCatalogsController extends AppController
* View method * View method
* *
* @param string|null $id Product Catalog id. * @param string|null $id Product Catalog id.
* @return Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @throws RecordNotFoundException When record not found. *
* @return \Cake\Http\Response|null|void Renders view
*/ */
public function view($id = null) public function view($id = null) {
{
$contain = ['ProductCategories']; $contain = ['ProductCategories'];
if (Configure::read('CakeProducts.internal.syncExternally', false)) { if (Configure::read('CakeProducts.internal.syncExternally', false)) {
$contain[] = 'ExternalProductCatalogs'; $contain[] = 'ExternalProductCatalogs';
@@ -61,10 +52,9 @@ class ProductCatalogsController extends AppController
/** /**
* Add method * Add method
* *
* @return Response|null|void Redirects on successful add, renders view otherwise. * @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
*/ */
public function add() public function add() {
{
$productCatalogsTable = $this->ProductCatalogs; $productCatalogsTable = $this->ProductCatalogs;
$productCatalog = $productCatalogsTable->newEmptyEntity(); $productCatalog = $productCatalogsTable->newEmptyEntity();
if ($this->request->is('post')) { if ($this->request->is('post')) {
@@ -87,11 +77,10 @@ class ProductCatalogsController extends AppController
* Edit method * Edit method
* *
* @param string|null $id Product Catalog id. * @param string|null $id Product Catalog id.
* @return Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @throws RecordNotFoundException When record not found. * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
*/ */
public function edit($id = null) public function edit($id = null) {
{
$productCatalogsTable = $this->ProductCatalogs; $productCatalogsTable = $this->ProductCatalogs;
$productCatalog = $productCatalogsTable->get($id, contain: []); $productCatalog = $productCatalogsTable->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) { if ($this->request->is(['patch', 'post', 'put'])) {
@@ -110,11 +99,10 @@ class ProductCatalogsController extends AppController
* Delete method * Delete method
* *
* @param string|null $id Product Catalog id. * @param string|null $id Product Catalog id.
* @return Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @throws RecordNotFoundException When record not found. * @return \Cake\Http\Response|null Redirects to index.
*/ */
public function delete($id = null) public function delete($id = null) {
{
$this->request->allowMethod(['post', 'delete']); $this->request->allowMethod(['post', 'delete']);
$productCatalogsTable = $this->ProductCatalogs; $productCatalogsTable = $this->ProductCatalogs;
$productCatalog = $productCatalogsTable->get($id); $productCatalog = $productCatalogsTable->get($id);
@@ -126,4 +114,5 @@ class ProductCatalogsController extends AppController
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
} }
} }
+28 -40
View File
@@ -3,10 +3,7 @@ declare(strict_types=1);
namespace CakeProducts\Controller; namespace CakeProducts\Controller;
use Cake\Core\Configure;
use Cake\Log\Log; use Cake\Log\Log;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
use Cake\Utility\Text; use Cake\Utility\Text;
/** /**
@@ -14,16 +11,13 @@ use Cake\Utility\Text;
* *
* @property \CakeProducts\Model\Table\ProductCategoriesTable $ProductCategories * @property \CakeProducts\Model\Table\ProductCategoriesTable $ProductCategories
*/ */
class ProductCategoriesController extends AppController class ProductCategoriesController extends AppController {
{
/** /**
* @return void * @return void
*/ */
public function initialize(): void public function initialize(): void {
{
parent::initialize(); // TODO: Change the autogenerated stub parent::initialize(); // TODO: Change the autogenerated stub
// $this->_defaultTable = 'CakeProducts.ProductCategories';
// $this->_tableConfigKey = 'CakeProducts.ProductCategories.table';
} }
/** /**
@@ -31,8 +25,7 @@ class ProductCategoriesController extends AppController
* *
* @return \Cake\Http\Response|null|void Renders view * @return \Cake\Http\Response|null|void Renders view
*/ */
public function index() public function index() {
{
$query = $this->ProductCategories->find() $query = $this->ProductCategories->find()
->contain(['ProductCatalogs', 'ParentProductCategories']); ->contain(['ProductCatalogs', 'ParentProductCategories']);
$productCategories = $this->paginate($query); $productCategories = $this->paginate($query);
@@ -44,11 +37,10 @@ class ProductCategoriesController extends AppController
* View method * View method
* *
* @param string|null $id Product Category id. * @param string|null $id Product Category id.
* @return \Cake\Http\Response|null|void Renders view
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Renders view
*/ */
public function view($id = null) public function view($id = null) {
{
$productCategory = $this->ProductCategories->get($id, contain: [ $productCategory = $this->ProductCategories->get($id, contain: [
'ProductCatalogs', 'ProductCatalogs',
'ParentProductCategories', 'ParentProductCategories',
@@ -58,7 +50,7 @@ class ProductCategoriesController extends AppController
'PrimaryProductPhotos', 'PrimaryProductPhotos',
]); ]);
$productCategoryAttributes = $this->ProductCategories->ProductCategoryAttributes->getAllCategoryAttributesForCategoryId($productCategory->internal_id); $productCategoryAttributes = $this->fetchTable('CakeProducts.ProductCategoryAttributes')->getAllCategoryAttributesForCategoryId($productCategory->internal_id) ?? [];
$this->set(compact('productCategory', 'productCategoryAttributes')); $this->set(compact('productCategory', 'productCategoryAttributes'));
} }
@@ -67,8 +59,7 @@ class ProductCategoriesController extends AppController
* *
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise. * @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
*/ */
public function add() public function add() {
{
$productCategoriesTable = $this->ProductCategories; $productCategoriesTable = $this->ProductCategories;
$productCategory = $productCategoriesTable->newEmptyEntity(); $productCategory = $productCategoriesTable->newEmptyEntity();
if ($this->request->is('post')) { if ($this->request->is('post')) {
@@ -94,8 +85,8 @@ class ProductCategoriesController extends AppController
} }
$this->Flash->error(__('The product category could not be saved. Please, try again.')); $this->Flash->error(__('The product category could not be saved. Please, try again.'));
} }
$productCatalogs = $productCategoriesTable->ProductCatalogs->find('list', limit: 200)->all(); $productCatalogs = $this->fetchTable('ProductCatalogs')->find('list', limit: 200)->all();
$parentProductCategories = $productCategoriesTable->ParentProductCategories->find('treeList', limit: 200)->toArray(); $parentProductCategories = $this->fetchTable('ProductCategories')->find('list', limit: 200)->all();
$this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories')); $this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories'));
} }
@@ -103,25 +94,25 @@ class ProductCategoriesController extends AppController
* Edit method * Edit method
* *
* @param string|null $id Product Category id. * @param string|null $id Product Category id.
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
*/ */
public function edit($id = null) public function edit($id = null) {
{ $productCategoriesTable = $this->fetchTable();
$productCategoriesTable = $this->ProductCategories; $productCategory = $this->ProductCategories->get($id, contain: []);
$productCategory = $productCategoriesTable->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) { if ($this->request->is(['patch', 'post', 'put'])) {
$postData = $this->request->getData(); $postData = $this->request->getData();
$productCategory = $productCategoriesTable->patchEntity($productCategory, $postData); $productCategory = $this->ProductCategories->patchEntity($productCategory, $postData);
if ($productCategoriesTable->save($productCategory)) { if ($this->ProductCategories->save($productCategory)) {
$this->Flash->success(__('The product category has been saved.')); $this->Flash->success(__('The product category has been saved.'));
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
} }
$this->Flash->error(__('The product category could not be saved. Please, try again.')); $this->Flash->error(__('The product category could not be saved. Please, try again.'));
} }
$productCatalogs = $productCategoriesTable->ProductCatalogs->find('list', limit: 200)->all(); $productCatalogs = $this->fetchTable('ProductCatalogs')->find('list', limit: 200)->all();
$parentProductCategories = $productCategoriesTable->ParentProductCategories->find('list', limit: 200)->all(); $parentProductCategories = $this->fetchTable('ProductCategories')->find('list', limit: 200)->all();
$this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories')); $this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories'));
} }
@@ -129,21 +120,19 @@ class ProductCategoriesController extends AppController
* Delete method * Delete method
* *
* @param string|null $id Product Category id. * @param string|null $id Product Category id.
* @return \Cake\Http\Response|null Redirects to index.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null Redirects to index.
*/ */
public function delete($id = null) public function delete($id = null) {
{
$this->request->allowMethod(['post', 'delete']); $this->request->allowMethod(['post', 'delete']);
$productCategoriesTable = $this->ProductCategories;
$productCategory = $productCategoriesTable->get($id); $productCategory = $this->ProductCategories->get($id);
// $productCategoriesTable->behaviors()->get('Tree')->setConfig([ // $productCategoriesTable->behaviors()->get('Tree')->setConfig([
// 'scope' => [ // 'scope' => [
// 'product_catalog_id' => $productCategory->product_catalog_id, // 'product_catalog_id' => $productCategory->product_catalog_id,
// ], // ],
// ]); // ]);
if ($productCategoriesTable->delete($productCategory)) { if ($this->ProductCategories->delete($productCategory)) {
$this->Flash->success(__('The product category has been deleted.')); $this->Flash->success(__('The product category has been deleted.'));
} else { } else {
$this->Flash->error(__('The product category could not be deleted. Please, try again.')); $this->Flash->error(__('The product category could not be deleted. Please, try again.'));
@@ -155,17 +144,15 @@ class ProductCategoriesController extends AppController
/** /**
* @return \Cake\Http\Response|null|void Renders view * @return \Cake\Http\Response|null|void Renders view
*/ */
public function select() public function select() {
{ $this->ProductCategories->getBehavior('Tree')->setConfig([
$productCategoriesTable = $this->ProductCategories;
$productCategoriesTable->behaviors()->get('Tree')->setConfig([
'scope' => [ 'scope' => [
'product_catalog_id' => $this->request->getQuery('product_catalog_id', -1), 'product_catalog_id' => $this->request->getQuery('product_catalog_id', -1),
], ],
]); ]);
$productCategoriesQ = $this->request->getQuery('form', 'product_category') === 'product' ? $productCategoriesQ = $this->request->getQuery('form', 'product_category') === 'product' ?
$productCategoriesTable->find('treeList', keyPath: 'internal_id', valuePath: 'name') : $this->ProductCategories->find('treeList', keyPath: 'internal_id', valuePath: 'name') :
$productCategoriesTable->find('treeList'); $this->ProductCategories->find('treeList');
$productCategories = $productCategoriesQ $productCategories = $productCategoriesQ
->orderBy(['ProductCategories.name']) ->orderBy(['ProductCategories.name'])
@@ -173,4 +160,5 @@ class ProductCategoriesController extends AppController
$this->set(compact('productCategories')); $this->set(compact('productCategories'));
} }
} }
@@ -3,23 +3,19 @@ declare(strict_types=1);
namespace CakeProducts\Controller; namespace CakeProducts\Controller;
use Cake\Core\Configure;
use Cake\Log\Log; use Cake\Log\Log;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
/** /**
* ProductCategoryAttributeOptions Controller * ProductCategoryAttributeOptions Controller
* *
* @property \CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable $ProductCategoryAttributeOptions * @property \CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable $ProductCategoryAttributeOptions
*/ */
class ProductCategoryAttributeOptionsController extends AppController class ProductCategoryAttributeOptionsController extends AppController {
{
/** /**
* @return void * @return void
*/ */
public function initialize(): void public function initialize(): void {
{
parent::initialize(); // TODO: Change the autogenerated stub parent::initialize(); // TODO: Change the autogenerated stub
// $this->_defaultTable = 'CakeProducts.ProductCategoryAttributeOptions'; // $this->_defaultTable = 'CakeProducts.ProductCategoryAttributeOptions';
// $this->_tableConfigKey = 'CakeProducts.ProductCategoryAttributeOptions.table'; // $this->_tableConfigKey = 'CakeProducts.ProductCategoryAttributeOptions.table';
@@ -30,8 +26,7 @@ class ProductCategoryAttributeOptionsController extends AppController
* *
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise. * @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
*/ */
public function add() public function add() {
{
Log::debug('inside product category attribute options controller add'); Log::debug('inside product category attribute options controller add');
$productCategoryAttributeOption = $this->ProductCategoryAttributeOptions->newEmptyEntity(); $productCategoryAttributeOption = $this->ProductCategoryAttributeOptions->newEmptyEntity();
@@ -42,11 +37,10 @@ class ProductCategoryAttributeOptionsController extends AppController
* Delete method * Delete method
* *
* @param string|null $id Product Category Attribute Option id. * @param string|null $id Product Category Attribute Option id.
* @return \Cake\Http\Response|null Redirects to index.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null Redirects to index.
*/ */
public function delete($id = null) public function delete($id = null) {
{
$this->request->allowMethod(['post', 'delete']); $this->request->allowMethod(['post', 'delete']);
$productCategoryAttributeOptionsTable = $this->ProductCategoryAttributeOptions; $productCategoryAttributeOptionsTable = $this->ProductCategoryAttributeOptions;
@@ -59,4 +53,5 @@ class ProductCategoryAttributeOptionsController extends AppController
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,40 +3,29 @@ declare(strict_types=1);
namespace CakeProducts\Controller; namespace CakeProducts\Controller;
use Cake\Core\Configure;
use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Http\Response;
use Cake\Log\Log; use Cake\Log\Log;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
use CakeProducts\Model\Enum\ProductCategoryAttributeTypeId;
use CakeProducts\Model\Table\ProductCategoryAttributesTable;
/** /**
* ProductCategoryAttributes Controller * ProductCategoryAttributes Controller
* *
* @property ProductCategoryAttributesTable $ProductCategoryAttributes * @property \CakeProducts\Model\Table\ProductCategoryAttributesTable $ProductCategoryAttributes
*/ */
class ProductCategoryAttributesController extends AppController class ProductCategoryAttributesController extends AppController {
{
/** /**
* @return void * @return void
*/ */
public function initialize(): void public function initialize(): void {
{
parent::initialize(); // TODO: Change the autogenerated stub parent::initialize(); // TODO: Change the autogenerated stub
// $this->_defaultTable = 'CakeProducts.ProductCategoryAttributes';
// $this->_tableConfigKey = 'CakeProducts.ProductCategoryAttributes.table';
} }
/** /**
* Index method * Index method
* *
* @return Response|null|void Renders view * @return \Cake\Http\Response|null|void Renders view
*/ */
public function index() public function index() {
{ $query = $this->fetchTable()->find()
$query = $this->ProductCategoryAttributes->find()
->contain(['ProductCategories']); ->contain(['ProductCategories']);
$productCategoryAttributes = $this->paginate($query); $productCategoryAttributes = $this->paginate($query);
@@ -47,12 +36,11 @@ class ProductCategoryAttributesController extends AppController
* View method * View method
* *
* @param string|null $id Product Category Attribute id. * @param string|null $id Product Category Attribute id.
* @return Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @throws RecordNotFoundException When record not found. * @return \Cake\Http\Response|null|void Renders view
*/ */
public function view($id = null) public function view($id = null) {
{ $productCategoryAttribute = $this->fetchTable()->get($id, contain: [
$productCategoryAttribute = $this->ProductCategoryAttributes->get($id, contain: [
'ProductCategories', 'ProductCategories',
'ProductCategoryAttributeOptions', 'ProductCategoryAttributeOptions',
]); ]);
@@ -63,12 +51,10 @@ class ProductCategoryAttributesController extends AppController
/** /**
* Add method * Add method
* *
* @return Response|null|void Redirects on successful add, renders view otherwise. * @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
*/ */
public function add() public function add() {
{ $productCategoryAttribute = $this->fetchTable()->newEmptyEntity();
$productCategoryAttributesTable = $this->ProductCategoryAttributes;
$productCategoryAttribute = $productCategoryAttributesTable->newEmptyEntity();
if ($this->request->is('post')) { if ($this->request->is('post')) {
$postData = $this->request->getData(); $postData = $this->request->getData();
if ($this->request->getSession()->read('Auth.User.id')) { if ($this->request->getSession()->read('Auth.User.id')) {
@@ -78,15 +64,15 @@ class ProductCategoryAttributesController extends AppController
Log::debug(print_r($postData, true)); Log::debug(print_r($postData, true));
$saveOptions = [ $saveOptions = [
'associated' => [ 'associated' => [
'ProductCategoryAttributeOptions' 'ProductCategoryAttributeOptions',
], ],
]; ];
$productCategoryAttribute = $productCategoryAttributesTable->patchEntity($productCategoryAttribute, $postData, $saveOptions); $productCategoryAttribute = $this->fetchTable()->patchEntity($productCategoryAttribute, $postData, $saveOptions);
if ($productCategoryAttribute->getErrors()) { if ($productCategoryAttribute->getErrors()) {
Log::debug(print_r('$productCategoryAttribute->getErrors() next - failed to save from create new product category attribute', true)); Log::debug(print_r('$productCategoryAttribute->getErrors() next - failed to save from create new product category attribute', true));
Log::debug(print_r($productCategoryAttribute->getErrors(), true)); Log::debug(print_r($productCategoryAttribute->getErrors(), true));
} }
if ($productCategoryAttributesTable->save($productCategoryAttribute, $saveOptions)) { if ($this->fetchTable()->save($productCategoryAttribute, $saveOptions)) {
$this->Flash->success(__('The product category attribute has been saved.')); $this->Flash->success(__('The product category attribute has been saved.'));
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
@@ -96,7 +82,7 @@ class ProductCategoryAttributesController extends AppController
Log::debug(print_r($productCategoryAttribute->getErrors(), true)); Log::debug(print_r($productCategoryAttribute->getErrors(), true));
$this->Flash->error(__('The product category attribute could not be saved. Please, try again.')); $this->Flash->error(__('The product category attribute could not be saved. Please, try again.'));
} }
$productCategories = $productCategoryAttributesTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all(); $productCategories = $this->fetchTable()->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all();
$this->set(compact('productCategoryAttribute', 'productCategories')); $this->set(compact('productCategoryAttribute', 'productCategories'));
} }
@@ -104,13 +90,11 @@ class ProductCategoryAttributesController extends AppController
* Edit method * Edit method
* *
* @param string|null $id Product Category Attribute id. * @param string|null $id Product Category Attribute id.
* @return Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @throws RecordNotFoundException When record not found. * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
*/ */
public function edit($id = null) public function edit($id = null) {
{ $productCategoryAttribute = $this->fetchTable()->get($id, contain: ['ProductCategoryAttributeOptions']);
$productCategoryAttributesTable = $this->ProductCategoryAttributes;
$productCategoryAttribute = $productCategoryAttributesTable->get($id, contain: ['ProductCategoryAttributeOptions']);
if ($this->request->is(['patch', 'post', 'put'])) { if ($this->request->is(['patch', 'post', 'put'])) {
$postData = $this->request->getData(); $postData = $this->request->getData();
$saveOptions = [ $saveOptions = [
@@ -124,9 +108,9 @@ class ProductCategoryAttributesController extends AppController
// } // }
Log::debug(print_r('$postData', true)); Log::debug(print_r('$postData', true));
Log::debug(print_r($postData, true)); Log::debug(print_r($postData, true));
$productCategoryAttribute = $productCategoryAttributesTable->patchEntity($productCategoryAttribute, $postData, $saveOptions); $productCategoryAttribute = $this->fetchTable()->patchEntity($productCategoryAttribute, $postData, $saveOptions);
if ($productCategoryAttributesTable->save($productCategoryAttribute, $saveOptions)) { if ($this->fetchTable()->save($productCategoryAttribute, $saveOptions)) {
$this->Flash->success(__('The product category attribute has been saved.')); $this->Flash->success(__('The product category attribute has been saved.'));
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
@@ -136,7 +120,7 @@ class ProductCategoryAttributesController extends AppController
Log::debug(print_r($productCategoryAttribute->getErrors(), true)); Log::debug(print_r($productCategoryAttribute->getErrors(), true));
$this->Flash->error(__('The product category attribute could not be saved. Please, try again.')); $this->Flash->error(__('The product category attribute could not be saved. Please, try again.'));
} }
$productCategories = $productCategoryAttributesTable->ProductCategories->find('list', limit: 200, keyField: 'internal_id', valueField: 'name')->all(); $productCategories = $this->fetchTable('ProductCategories')->find('list', limit: 200, keyField: 'internal_id', valueField: 'name')->all();
$this->set(compact('productCategoryAttribute', 'productCategories')); $this->set(compact('productCategoryAttribute', 'productCategories'));
} }
@@ -144,16 +128,14 @@ class ProductCategoryAttributesController extends AppController
* Delete method * Delete method
* *
* @param string|null $id Product Category Attribute id. * @param string|null $id Product Category Attribute id.
* @return Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @throws RecordNotFoundException When record not found. * @return \Cake\Http\Response|null Redirects to index.
*/ */
public function delete($id = null) public function delete($id = null) {
{
$this->request->allowMethod(['post', 'delete']); $this->request->allowMethod(['post', 'delete']);
$productCategoryAttributesTable = $this->ProductCategoryAttributes; $productCategoryAttribute = $this->fetchTable()->get($id);
$productCategoryAttribute = $productCategoryAttributesTable->get($id); if ($this->fetchTable()->delete($productCategoryAttribute)) {
if ($productCategoryAttributesTable->delete($productCategoryAttribute)) {
$this->Flash->success(__('The product category attribute has been deleted.')); $this->Flash->success(__('The product category attribute has been deleted.'));
} else { } else {
$this->Flash->error(__('The product category attribute could not be deleted. Please, try again.')); $this->Flash->error(__('The product category attribute could not be deleted. Please, try again.'));
@@ -165,10 +147,10 @@ class ProductCategoryAttributesController extends AppController
/** /**
* @return void * @return void
*/ */
public function form() public function form() {
{ $productCategories = $this->fetchTable()->getAllCategoryAttributesForCategoryId($this->request->getQuery('product_category_id', '-1'));
$productCategories = $this->ProductCategoryAttributes->getAllCategoryAttributesForCategoryId($this->request->getQuery('product_category_id', '-1'));
$this->set(compact('productCategories')); $this->set(compact('productCategories'));
} }
} }
@@ -3,26 +3,20 @@ declare(strict_types=1);
namespace CakeProducts\Controller; namespace CakeProducts\Controller;
use Cake\Core\Configure;
use Cake\Log\Log; use Cake\Log\Log;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
/** /**
* ProductCategoryVariants Controller * ProductCategoryVariants Controller
* *
* @property \App\Model\Table\ProductCategoryVariantsTable $ProductCategoryVariants * @property \CakeProducts\Model\Table\ProductCategoryVariantsTable $ProductCategoryVariants
*/ */
class ProductCategoryVariantsController extends AppController class ProductCategoryVariantsController extends AppController {
{
/** /**
* @return void * @return void
*/ */
public function initialize(): void public function initialize(): void {
{
parent::initialize(); // TODO: Change the autogenerated stub parent::initialize(); // TODO: Change the autogenerated stub
// $this->_defaultTable = 'CakeProducts.ProductCategoryVariants';
// $this->_tableConfigKey = 'CakeProducts.ProductCategoryVariants.table';
} }
/** /**
@@ -30,9 +24,8 @@ class ProductCategoryVariantsController extends AppController
* *
* @return \Cake\Http\Response|null|void Renders view * @return \Cake\Http\Response|null|void Renders view
*/ */
public function index() public function index() {
{ $query = $this->fetchTable()->find()
$query = $this->ProductCategoryVariants->find()
->contain(['ProductCategories', 'Products', 'ProductCategoryVariantOptions']); ->contain(['ProductCategories', 'Products', 'ProductCategoryVariantOptions']);
$productCategoryVariants = $this->paginate($query); $productCategoryVariants = $this->paginate($query);
@@ -43,12 +36,11 @@ class ProductCategoryVariantsController extends AppController
* View method * View method
* *
* @param string|null $id Product Category Variant id. * @param string|null $id Product Category Variant id.
* @return \Cake\Http\Response|null|void Renders view
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Renders view
*/ */
public function view($id = null) public function view($id = null) {
{ $productCategoryVariant = $this->fetchTable()->get($id, contain: [
$productCategoryVariant = $this->ProductCategoryVariants->get($id, contain: [
'ProductCategories', 'ProductCategories',
'Products', 'Products',
'ProductCategoryVariantOptions', 'ProductCategoryVariantOptions',
@@ -61,9 +53,8 @@ class ProductCategoryVariantsController extends AppController
* *
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise. * @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
*/ */
public function add() public function add() {
{ $productCategoryVariantsTable = $this->fetchTable();
$productCategoryVariantsTable = $this->ProductCategoryVariants;
$productCategoryVariant = $productCategoryVariantsTable->newEmptyEntity(); $productCategoryVariant = $productCategoryVariantsTable->newEmptyEntity();
if ($this->request->is('post')) { if ($this->request->is('post')) {
@@ -73,7 +64,7 @@ class ProductCategoryVariantsController extends AppController
} }
$saveOptions = [ $saveOptions = [
'associated' => [ 'associated' => [
'ProductCategoryVariantOptions' 'ProductCategoryVariantOptions',
], ],
]; ];
$productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $postData, $saveOptions); $productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $postData, $saveOptions);
@@ -95,13 +86,11 @@ class ProductCategoryVariantsController extends AppController
* Edit method * Edit method
* *
* @param string|null $id Product Category Variant id. * @param string|null $id Product Category Variant id.
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
*/ */
public function edit($id = null) public function edit($id = null) {
{ $productCategoryVariant = $this->fetchTable()->get($id, contain: []);
$productCategoryVariantsTable = $this->ProductCategoryVariants;
$productCategoryVariant = $productCategoryVariantsTable->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) { if ($this->request->is(['patch', 'post', 'put'])) {
$postData = $this->request->getData(); $postData = $this->request->getData();
// if ($this->request->getSession()->read('Auth.User.id')) { // if ($this->request->getSession()->read('Auth.User.id')) {
@@ -118,12 +107,12 @@ class ProductCategoryVariantsController extends AppController
'product_category_variant_options', 'product_category_variant_options',
], ],
'associated' => [ 'associated' => [
'ProductCategoryVariantOptions' 'ProductCategoryVariantOptions',
], ],
]; ];
$productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $postData, $saveOptions); $productCategoryVariant = $this->fetchTable()->patchEntity($productCategoryVariant, $postData, $saveOptions);
// dd($postData); // dd($postData);
if ($productCategoryVariantsTable->save($productCategoryVariant, $saveOptions)) { if ($this->fetchTable()->save($productCategoryVariant, $saveOptions)) {
$this->Flash->success(__('The product category variant has been saved.')); $this->Flash->success(__('The product category variant has been saved.'));
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
@@ -131,8 +120,9 @@ class ProductCategoryVariantsController extends AppController
// dd($productCategoryVariant->getErrors()); // dd($productCategoryVariant->getErrors());
$this->Flash->error(__('The product category variant could not be saved. Please, try again.')); $this->Flash->error(__('The product category variant could not be saved. Please, try again.'));
} }
$productCategories = $productCategoryVariantsTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all(); $productCategories = $this->fetchTable('ProductCategories')->find('list', keyField: 'internal_id', valueField: 'name')->all();
$products = isset($productCategoryVariant->product_category_id) ? $productCategoryVariantsTable->Products->find('list', limit: 200)->where(['product_category_id' => $productCategoryVariant->product_category_id])->all() : []; $products = isset($productCategoryVariant->product_category_id) ? $this->fetchTable('Products')->find('list', limit: 200)
->where(['product_category_id' => $productCategoryVariant->product_category_id])->all() : [];
$this->set(compact('productCategoryVariant', 'productCategories', 'products')); $this->set(compact('productCategoryVariant', 'productCategories', 'products'));
} }
@@ -140,16 +130,14 @@ class ProductCategoryVariantsController extends AppController
* Delete method * Delete method
* *
* @param string|null $id Product Category Variant id. * @param string|null $id Product Category Variant id.
* @return \Cake\Http\Response|null Redirects to index.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null Redirects to index.
*/ */
public function delete($id = null) public function delete($id = null) {
{
$this->request->allowMethod(['post', 'delete']); $this->request->allowMethod(['post', 'delete']);
$productCategoryVariantsTable = $this->ProductCategoryVariants;
$productCategoryVariant = $productCategoryVariantsTable->get($id); $productCategoryVariant = $this->fetchTable()->get($id);
if ($productCategoryVariantsTable->delete($productCategoryVariant)) { if ($this->fetchTable()->delete($productCategoryVariant)) {
$this->Flash->success(__('The product category variant has been deleted.')); $this->Flash->success(__('The product category variant has been deleted.'));
} else { } else {
$this->Flash->error(__('The product category variant could not be deleted. Please, try again.')); $this->Flash->error(__('The product category variant could not be deleted. Please, try again.'));
@@ -157,4 +145,5 @@ class ProductCategoryVariantsController extends AppController
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
} }
} }
+51 -52
View File
@@ -4,27 +4,22 @@ declare(strict_types=1);
namespace CakeProducts\Controller; namespace CakeProducts\Controller;
use Cake\Core\Configure; use Cake\Core\Configure;
use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Http\Exception\ForbiddenException; use Cake\Http\Exception\ForbiddenException;
use Cake\Http\Response;
use Cake\Utility\Text; use Cake\Utility\Text;
use CakeProducts\Model\Table\ProductPhotosTable;
use Psr\Http\Message\UploadedFileInterface;
/** /**
* ProductPhotos Controller * ProductPhotos Controller
* *
* @property ProductPhotosTable $ProductPhotos * @property \CakeProducts\Model\Table\ProductPhotosTable $ProductPhotos
*/ */
class ProductPhotosController extends AppController class ProductPhotosController extends AppController {
{
/** /**
* Index method * Index method
* *
* @return Response|null|void Renders view * @return \Cake\Http\Response|null|void Renders view
*/ */
public function index() public function index() {
{
$query = $this->ProductPhotos->find() $query = $this->ProductPhotos->find()
->contain(['Products', 'ProductSkus', 'ProductCategories']); ->contain(['Products', 'ProductSkus', 'ProductCategories']);
$productPhotos = $this->paginate($query); $productPhotos = $this->paginate($query);
@@ -36,11 +31,11 @@ class ProductPhotosController extends AppController
* View method * View method
* *
* @param string|null $id Product Photo id. * @param string|null $id Product Photo id.
* @return Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @throws RecordNotFoundException When record not found. *
* @return \Cake\Http\Response|null|void Renders view
*/ */
public function view($id = null) public function view($id = null) {
{
$productPhoto = $this->ProductPhotos->get($id, contain: ['Products', 'ProductSkus', 'ProductCategories']); $productPhoto = $this->ProductPhotos->get($id, contain: ['Products', 'ProductSkus', 'ProductCategories']);
$this->set(compact('productPhoto')); $this->set(compact('productPhoto'));
} }
@@ -48,17 +43,17 @@ class ProductPhotosController extends AppController
/** /**
* Add method * Add method
* *
* @return Response|null|void Redirects on successful add, renders view otherwise. * @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
*/ */
public function add() public function add() {
{ $productPhoto = $this->fetchTable()->newEmptyEntity();
$productPhotosTable = $this->ProductPhotos;
$productPhoto = $productPhotosTable->newEmptyEntity();
if ($this->request->is('post')) { if ($this->request->is('post')) {
// dd($this->request->getData());
if (!$this->request->getData('photo')) { if (!$this->request->getData('photo')) {
$this->Flash->error('Photo is required. Nothing was uploaded. Please try again.'); $this->Flash->error('Photo is required. Nothing was uploaded. Please try again.');
$productCategory = $productPhoto->product_category_id ? $productPhotosTable->ProductCategories->find()->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null; $productCategory = $productPhoto->product_category_id ? $this->fetchTable('CakeProducts.ProductCategories')->find()
$productCatalogs = $productPhotosTable->ProductCategories->ProductCatalogs->find('list')->toArray(); ->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null;
$productCatalogs = $this->fetchTable('CakeProducts.ProductCatalogs')->find('list')->toArray();
$this->set(compact('productPhoto', 'productCatalogs', 'productCategory')); $this->set(compact('productPhoto', 'productCatalogs', 'productCategory'));
return; return;
@@ -69,25 +64,31 @@ class ProductPhotosController extends AppController
$baseDir = Configure::readOrFail('CakeProducts.photos.directory'); $baseDir = Configure::readOrFail('CakeProducts.photos.directory');
$path = ''; $path = '';
if ($this->request->getData('product_sku_id')) { if ($this->request->getData('product_sku_id')) {
$productSku = $productPhotosTable->ProductSkus $productSku = $this->fetchTable('CakeProducts.ProductSkus')
->find() ->find()
->contain(['Products', 'Products.ProductCategories']) ->contain(['Products', 'Products.ProductCategories'])
->where([ ->where([
'ProductSkus.id' => $this->request->getData('product_sku_id'), 'ProductSkus.id' => $this->request->getData('product_sku_id'),
]) ])
->first(); ->first();
/**
* @var \CakeProducts\Model\Entity\ProductSku|null $productSku
*/
$path = $productSku ? $productSku->product_id . DS . 'skus' . DS . $productSku->id : $path; $path = $productSku ? $productSku->product_id . DS . 'skus' . DS . $productSku->id : $path;
$postData['product_id'] = $productSku->product->id ?? null; $postData['product_id'] = $productSku->product->id ?? null;
$postData['product_category_id'] = $productSku->product->product_category->internal_id ?? null; $postData['product_category_id'] = $productSku->product->product_category->internal_id ?? null;
} else if ($this->request->getData('product_id')) { } else if ($this->request->getData('product_id')) {
$product = $productPhotosTable->Products $product = $this->fetchTable('CakeProducts.Products')
->find() ->find()
->contain(['ProductCategories']) ->contain(['ProductCategories'])
->where([ ->where([
'Products.id' => $this->request->getData('product_id'), 'Products.id' => $this->request->getData('product_id'),
]) ])
->first(); ->first();
/**
* @var \CakeProducts\Model\Entity\Product|null $product
*/
$path = $product ? $product->id : $path; $path = $product ? $product->id : $path;
$postData['product_category_id'] = $product->product_category->internal_id ?? null; $postData['product_category_id'] = $product->product_category->internal_id ?? null;
@@ -96,7 +97,7 @@ class ProductPhotosController extends AppController
// @link https://developer.wordpress.org/reference/functions/wp_is_uuid/ // @link https://developer.wordpress.org/reference/functions/wp_is_uuid/
$regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/'; $regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/';
$field = preg_match($regex, $categoryId) ? 'ProductCategories.internal_id' : 'ProductCategories.id'; $field = preg_match($regex, $categoryId) ? 'ProductCategories.internal_id' : 'ProductCategories.id';
$productCategoryPosted = $productPhotosTable->ProductCategories $productCategoryPosted = $this->fetchTable('CakeProducts.ProductCategories')
->find() ->find()
->where([ ->where([
$field => $categoryId, $field => $categoryId,
@@ -106,7 +107,7 @@ class ProductPhotosController extends AppController
$path = $productCategoryPosted ? 'categories' : $path; $path = $productCategoryPosted ? 'categories' : $path;
} }
/** /**
* @var UploadedFileInterface $photoObject * @var \Psr\Http\Message\UploadedFileInterface $photoObject
*/ */
$photoObject = $this->request->getData('photo'); $photoObject = $this->request->getData('photo');
$ext = substr(strtolower($photoObject->getClientFilename()), -4); $ext = substr(strtolower($photoObject->getClientFilename()), -4);
@@ -134,8 +135,8 @@ class ProductPhotosController extends AppController
$postData['photo_filename'] = $uuid . '.' . $ext; $postData['photo_filename'] = $uuid . '.' . $ext;
// dd($postData); // dd($postData);
$productPhoto = $productPhotosTable->patchEntity($productPhoto, $postData); $productPhoto = $this->fetchTable()->patchEntity($productPhoto, $postData);
if ($productPhotosTable->save($productPhoto)) { if ($this->fetchTable()->save($productPhoto)) {
$this->Flash->success(__('The product photo has been saved.')); $this->Flash->success(__('The product photo has been saved.'));
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
@@ -143,8 +144,9 @@ class ProductPhotosController extends AppController
// dd($productPhoto->getErrors()); // dd($productPhoto->getErrors());
$this->Flash->error(__('The product photo could not be saved. Please, try again.')); $this->Flash->error(__('The product photo could not be saved. Please, try again.'));
} }
$productCategory = $productPhoto->product_category_id ? $productPhotosTable->ProductCategories->find()->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null; $productCategory = $productPhoto->product_category_id ? $this->fetchTable('ProductCategories')->find()
$productCatalogs = $productPhotosTable->ProductCategories->ProductCatalogs->find('list')->toArray(); ->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null;
$productCatalogs = $this->fetchTable('ProductCatalogs')->find('list')->toArray();
$this->set(compact('productPhoto', 'productCatalogs', 'productCategory')); $this->set(compact('productPhoto', 'productCatalogs', 'productCategory'));
} }
@@ -152,26 +154,25 @@ class ProductPhotosController extends AppController
* Edit method * Edit method
* *
* @param string|null $id Product Photo id. * @param string|null $id Product Photo id.
* @return Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @throws RecordNotFoundException When record not found. *
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
*/ */
public function edit($id = null) public function edit($id = null) {
{ $productPhoto = $this->fetchTable()->get($id, contain: []);
$productPhotosTable = $this->ProductPhotos;
$productPhoto = $productPhotosTable->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) { if ($this->request->is(['patch', 'post', 'put'])) {
$postData = $this->request->getData(); $postData = $this->request->getData();
$productPhoto = $productPhotosTable->patchEntity($productPhoto, $postData); $productPhoto = $this->fetchTable()->patchEntity($productPhoto, $postData);
if ($productPhotosTable->save($productPhoto)) { if ($this->fetchTable()->save($productPhoto)) {
$this->Flash->success(__('The product photo has been saved.')); $this->Flash->success(__('The product photo has been saved.'));
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
} }
$this->Flash->error(__('The product photo could not be saved. Please, try again.')); $this->Flash->error(__('The product photo could not be saved. Please, try again.'));
} }
$products = $productPhotosTable->Products->find('list', limit: 200)->all(); $products = $this->fetchTable('Products')->find('list', limit: 200)->all();
$productSkus = $productPhotosTable->ProductSkus->find('list', limit: 200)->all(); $productSkus = $this->fetchTable('ProductSkus')->find('list', limit: 200)->all();
$this->set(compact('productPhoto', 'products', 'productSkus')); $this->set(compact('productPhoto', 'products', 'productSkus'));
} }
@@ -179,16 +180,14 @@ class ProductPhotosController extends AppController
* Delete method * Delete method
* *
* @param string|null $id Product Photo id. * @param string|null $id Product Photo id.
* @return Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @throws RecordNotFoundException When record not found. * @return \Cake\Http\Response|null Redirects to index.
*/ */
public function delete($id = null) public function delete($id = null) {
{
$this->request->allowMethod(['post', 'delete']); $this->request->allowMethod(['post', 'delete']);
$productPhotosTable = $this->ProductPhotos;
$productPhoto = $productPhotosTable->get($id); $productPhoto = $this->fetchTable()->get($id);
if ($productPhotosTable->delete($productPhoto)) { if ($this->fetchTable()->delete($productPhoto)) {
$this->Flash->success(__('The product photo has been deleted.')); $this->Flash->success(__('The product photo has been deleted.'));
} else { } else {
$this->Flash->error(__('The product photo could not be deleted. Please, try again.')); $this->Flash->error(__('The product photo could not be deleted. Please, try again.'));
@@ -198,17 +197,17 @@ class ProductPhotosController extends AppController
} }
/** /**
* @param $id * @param string|null $id
* @return Response * @return \Cake\Http\Response
*/ */
public function image($id = null) public function image($id = null) {
{ $productPhoto = $this->fetchTable()->get($id);
$productPhoto = $this->ProductPhotos->get($id);
$fullPath = Configure::readOrFail('CakeProducts.photos.directory') . $productPhoto->photo_dir . DS . $productPhoto->photo_filename; $fullPath = Configure::readOrFail('CakeProducts.photos.directory') . $productPhoto->photo_dir . DS . $productPhoto->photo_filename;
return $this->response->withFile($fullPath, [ return $this->response->withFile($fullPath, [
'download' => $this->request->getQuery('download', false) === '1' 'download' => $this->request->getQuery('download', false) === '1',
]); ]);
} }
} }
+18 -25
View File
@@ -12,16 +12,13 @@ use function BenTools\CartesianProduct\combinations;
* *
* @property \CakeProducts\Model\Table\ProductSkusTable $ProductSkus * @property \CakeProducts\Model\Table\ProductSkusTable $ProductSkus
*/ */
class ProductSkusController extends AppController class ProductSkusController extends AppController {
{
/** /**
* @return void * @return void
*/ */
public function initialize(): void public function initialize(): void {
{
parent::initialize(); // TODO: Change the autogenerated stub parent::initialize(); // TODO: Change the autogenerated stub
// $this->_defaultTable = 'CakeProducts.ProductSkus';
// $this->_tableConfigKey = 'CakeProducts.ProductSkus.table';
} }
/** /**
@@ -29,8 +26,7 @@ class ProductSkusController extends AppController
* *
* @return \Cake\Http\Response|null|void Renders view * @return \Cake\Http\Response|null|void Renders view
*/ */
public function index() public function index() {
{
$query = $this->ProductSkus->find() $query = $this->ProductSkus->find()
->contain(['Products']); ->contain(['Products']);
$productSkus = $this->paginate($query); $productSkus = $this->paginate($query);
@@ -42,11 +38,10 @@ class ProductSkusController extends AppController
* View method * View method
* *
* @param string|null $id Product Skus id. * @param string|null $id Product Skus id.
* @return \Cake\Http\Response|null|void Renders view
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Renders view
*/ */
public function view($id = null) public function view($id = null) {
{
$productSku = $this->ProductSkus->get($id, contain: [ $productSku = $this->ProductSkus->get($id, contain: [
'Products', 'Products',
'ProductSkuVariantValues', 'ProductSkuVariantValues',
@@ -62,8 +57,7 @@ class ProductSkusController extends AppController
* *
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise. * @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
*/ */
public function add($productId = null) public function add($productId = null) {
{
$toGetCartesianProductsFrom = []; $toGetCartesianProductsFrom = [];
$productSkus = []; $productSkus = [];
$product = $this->ProductSkus->Products->get($productId, contain: [ $product = $this->ProductSkus->Products->get($productId, contain: [
@@ -79,7 +73,7 @@ class ProductSkusController extends AppController
foreach ($existingProductSkusForMapping as $existingProductSkuId => $existingProductSku) { foreach ($existingProductSkusForMapping as $existingProductSkuId => $existingProductSku) {
$existingSkusForCartesianComparison[$existingProductSkuId] = Hash::combine($existingProductSku, '{n}.product_variant_id', '{n}.product_category_variant_option_id'); $existingSkusForCartesianComparison[$existingProductSkuId] = Hash::combine($existingProductSku, '{n}.product_variant_id', '{n}.product_category_variant_option_id');
} }
$productVariants = isset($product->product_variants) ? $product->product_variants : []; $productVariants = $product->product_variants ?? [];
// dd($productVariants); // dd($productVariants);
$productVariantsMapping = Hash::combine($productVariants, '{n}.product_category_variant.id', '{n}.id'); $productVariantsMapping = Hash::combine($productVariants, '{n}.product_category_variant.id', '{n}.id');
$productCategoryVariants = Hash::extract($productVariants, '{n}.product_category_variant'); $productCategoryVariants = Hash::extract($productVariants, '{n}.product_category_variant');
@@ -110,7 +104,7 @@ class ProductSkusController extends AppController
'variantNameMapping', 'variantNameMapping',
'numSkusToAdd', 'numSkusToAdd',
'existingProductSkus', 'existingProductSkus',
'existingSkusForCartesianComparison' 'existingSkusForCartesianComparison',
)); ));
if ($this->request->is('post')) { if ($this->request->is('post')) {
@@ -163,7 +157,8 @@ class ProductSkusController extends AppController
if (!$this->ProductSkus->save($productSkuToSave, $saveOptions)) { if (!$this->ProductSkus->save($productSkuToSave, $saveOptions)) {
Log::debug(print_r('$productSkuToSave->getErrors()', true)); Log::debug(print_r('$productSkuToSave->getErrors()', true));
Log::debug(print_r($productSkuToSave->getErrors(), true)); Log::debug(print_r($productSkuToSave->getErrors(), true));
dd($productSkuToSave->getErrors()); // dd($productSkuToSave->getErrors());
continue; continue;
} }
$successes[] = $productSkuToSave; $successes[] = $productSkuToSave;
@@ -178,7 +173,7 @@ class ProductSkusController extends AppController
$this->Flash->error(__('The product SKU(s) could not be saved. Please, try again.')); $this->Flash->error(__('The product SKU(s) could not be saved. Please, try again.'));
} }
$this->set(compact( $this->set(compact(
'productSkus' 'productSkus',
)); ));
} }
@@ -186,11 +181,10 @@ class ProductSkusController extends AppController
* Edit method * Edit method
* *
* @param string|null $id Product Skus id. * @param string|null $id Product Skus id.
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
*/ */
public function edit($id = null) public function edit($id = null) {
{
$productSku = $this->ProductSkus->get($id, contain: []); $productSku = $this->ProductSkus->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) { if ($this->request->is(['patch', 'post', 'put'])) {
$postData = $this->request->getData(); $postData = $this->request->getData();
@@ -219,11 +213,10 @@ class ProductSkusController extends AppController
* Delete method * Delete method
* *
* @param string|null $id Product Skus id. * @param string|null $id Product Skus id.
* @return \Cake\Http\Response|null Redirects to index.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null Redirects to index.
*/ */
public function delete($id = null) public function delete($id = null) {
{
$this->request->allowMethod(['post', 'delete']); $this->request->allowMethod(['post', 'delete']);
$productSku = $this->ProductSkus->get($id); $productSku = $this->ProductSkus->get($id);
if ($this->ProductSkus->delete($productSku)) { if ($this->ProductSkus->delete($productSku)) {
@@ -238,8 +231,7 @@ class ProductSkusController extends AppController
/** /**
* @return \Cake\Http\Response|null|void Renders view * @return \Cake\Http\Response|null|void Renders view
*/ */
public function select() public function select() {
{
$productSkus = $this->ProductSkus $productSkus = $this->ProductSkus
->find('list') ->find('list')
->where(['product_id' => $this->request->getQuery('product_id', '-1')]) ->where(['product_id' => $this->request->getQuery('product_id', '-1')])
@@ -248,4 +240,5 @@ class ProductSkusController extends AppController
$this->set(compact('productSkus')); $this->set(compact('productSkus'));
} }
} }
+30 -31
View File
@@ -8,18 +8,17 @@ use Cake\Log\Log;
/** /**
* ProductVariants Controller * ProductVariants Controller
* *
* @property \App\Model\Table\ProductVariantsTable $ProductVariants * @property \CakeProducts\Model\Table\ProductVariantsTable $ProductVariants
*/ */
class ProductVariantsController extends AppController class ProductVariantsController extends AppController {
{
/** /**
* Index method * Index method
* *
* @return \Cake\Http\Response|null|void Renders view * @return \Cake\Http\Response|null|void Renders view
*/ */
public function index() public function index() {
{ $query = $this->fetchTable()->find()
$query = $this->ProductVariants->find()
->contain(['ProductCategoryVariants', 'Products']); ->contain(['ProductCategoryVariants', 'Products']);
$productVariants = $this->paginate($query); $productVariants = $this->paginate($query);
@@ -30,12 +29,11 @@ class ProductVariantsController extends AppController
* View method * View method
* *
* @param string|null $id Product Variant id. * @param string|null $id Product Variant id.
* @return \Cake\Http\Response|null|void Renders view
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Renders view
*/ */
public function view($id = null) public function view($id = null) {
{ $productVariant = $this->fetchTable()->get($id, contain: ['ProductCategoryVariants', 'Products']);
$productVariant = $this->ProductVariants->get($id, contain: ['ProductCategoryVariants', 'Products']);
$this->set(compact('productVariant')); $this->set(compact('productVariant'));
} }
@@ -44,18 +42,20 @@ class ProductVariantsController extends AppController
* *
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise. * @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
*/ */
public function add($productId) public function add($productId) {
{ $product = $this->fetchTable()->Products->get($productId);
$product = $this->ProductVariants->Products->get($productId); $productVariant = $this->fetchTable()->newEmptyEntity();
$productVariant = $this->ProductVariants->newEmptyEntity();
if ($this->request->is('post')) { if ($this->request->is('post')) {
$saveOptions = []; $saveOptions = [];
$postData = $this->request->getData(); $postData = $this->request->getData();
$productCategoryVariant = $this->ProductVariants->ProductCategoryVariants->get($this->request->getData('product_category_variant_id', '-1')); /**
* @var \CakeProducts\Model\Entity\ProductCategoryVariant $productCategoryVariant
*/
$productCategoryVariant = $this->fetchTable('ProductCategoryVariants')->get($this->request->getData('product_category_variant_id', '-1'));
$postData['name'] = $productCategoryVariant->name; $postData['name'] = $productCategoryVariant->name;
$postData['product_id'] = $productId; $postData['product_id'] = $productId;
$productVariant = $this->ProductVariants->patchEntity($productVariant, $postData); $productVariant = $this->fetchTable()->patchEntity($productVariant, $postData);
if ($this->ProductVariants->save($productVariant)) { if ($this->fetchTable()->save($productVariant)) {
$this->Flash->success(__('The product variant has been saved.')); $this->Flash->success(__('The product variant has been saved.'));
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
@@ -65,7 +65,7 @@ class ProductVariantsController extends AppController
Log::debug(print_r($productVariant->getErrors(), true)); Log::debug(print_r($productVariant->getErrors(), true));
$this->Flash->error(__('The product variant could not be saved. Please, try again.')); $this->Flash->error(__('The product variant could not be saved. Please, try again.'));
} }
$productCategoryVariants = $this->ProductVariants->ProductCategoryVariants $productCategoryVariants = $this->fetchTable('ProductCategoryVariants')
->find('list', limit: 200) ->find('list', limit: 200)
->where(['product_category_id' => $product->product_category_id]) ->where(['product_category_id' => $product->product_category_id])
->toArray(); ->toArray();
@@ -76,23 +76,22 @@ class ProductVariantsController extends AppController
* Edit method * Edit method
* *
* @param string|null $id Product Variant id. * @param string|null $id Product Variant id.
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
*/ */
public function edit($id = null) public function edit($id = null) {
{ $productVariant = $this->fetchTable()->get($id, contain: []);
$productVariant = $this->ProductVariants->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) { if ($this->request->is(['patch', 'post', 'put'])) {
$productVariant = $this->ProductVariants->patchEntity($productVariant, $this->request->getData()); $productVariant = $this->fetchTable()->patchEntity($productVariant, $this->request->getData());
if ($this->ProductVariants->save($productVariant)) { if ($this->fetchTable()->save($productVariant)) {
$this->Flash->success(__('The product variant has been saved.')); $this->Flash->success(__('The product variant has been saved.'));
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
} }
$this->Flash->error(__('The product variant could not be saved. Please, try again.')); $this->Flash->error(__('The product variant could not be saved. Please, try again.'));
} }
$productCategoryVariants = $this->ProductVariants->ProductCategoryVariants->find('list', limit: 200)->all(); $productCategoryVariants = $this->fetchTable('ProductCategoryVariants')->find('list', limit: 200)->all();
$products = $this->ProductVariants->Products->find('list', limit: 200)->all(); $products = $this->fetchTable('Products')->find('list', limit: 200)->all();
$this->set(compact('productVariant', 'productCategoryVariants', 'products')); $this->set(compact('productVariant', 'productCategoryVariants', 'products'));
} }
@@ -100,14 +99,13 @@ class ProductVariantsController extends AppController
* Delete method * Delete method
* *
* @param string|null $id Product Variant id. * @param string|null $id Product Variant id.
* @return \Cake\Http\Response|null Redirects to index.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null Redirects to index.
*/ */
public function delete($id = null) public function delete($id = null) {
{
$this->request->allowMethod(['post', 'delete']); $this->request->allowMethod(['post', 'delete']);
$productVariant = $this->ProductVariants->get($id); $productVariant = $this->fetchTable()->get($id);
if ($this->ProductVariants->delete($productVariant)) { if ($this->fetchTable()->delete($productVariant)) {
$this->Flash->success(__('The product variant has been deleted.')); $this->Flash->success(__('The product variant has been deleted.'));
} else { } else {
$this->Flash->error(__('The product variant could not be deleted. Please, try again.')); $this->Flash->error(__('The product variant could not be deleted. Please, try again.'));
@@ -115,4 +113,5 @@ class ProductVariantsController extends AppController
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
} }
} }
+35 -43
View File
@@ -3,26 +3,20 @@ declare(strict_types=1);
namespace CakeProducts\Controller; namespace CakeProducts\Controller;
use Cake\Core\Configure;
use Cake\Log\Log; use Cake\Log\Log;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
/** /**
* Products Controller * Products Controller
* *
* @property \CakeProducts\Model\Table\ProductsTable $Products * @property \CakeProducts\Model\Table\ProductsTable $Products
*/ */
class ProductsController extends AppController class ProductsController extends AppController {
{
/** /**
* @return void * @return void
*/ */
public function initialize(): void public function initialize(): void {
{
parent::initialize(); // TODO: Change the autogenerated stub parent::initialize(); // TODO: Change the autogenerated stub
// $this->_defaultTable = 'CakeProducts.Products';
// $this->_tableConfigKey = 'CakeProducts.Products.table';
} }
/** /**
@@ -30,9 +24,8 @@ class ProductsController extends AppController
* *
* @return \Cake\Http\Response|null|void Renders view * @return \Cake\Http\Response|null|void Renders view
*/ */
public function index() public function index() {
{ $query = $this->fetchTable()->find()
$query = $this->Products->find()
->contain(['ProductCategories']); ->contain(['ProductCategories']);
$products = $this->paginate($query); $products = $this->paginate($query);
@@ -43,12 +36,11 @@ class ProductsController extends AppController
* View method * View method
* *
* @param string|null $id Product id. * @param string|null $id Product id.
* @return \Cake\Http\Response|null|void Renders view
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Renders view
*/ */
public function view($id = null) public function view($id = null) {
{ $product = $this->fetchTable()->get($id, contain: [
$product = $this->Products->get($id, contain: [
'ProductCategories', 'ProductCategories',
'ProductAttributes', 'ProductAttributes',
'ProductAttributes.ProductCategoryAttributes', 'ProductAttributes.ProductCategoryAttributes',
@@ -67,10 +59,8 @@ class ProductsController extends AppController
* *
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise. * @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
*/ */
public function add() public function add() {
{ $product = $this->fetchTable()->newEmptyEntity();
$productsTable = $this->Products;
$product = $productsTable->newEmptyEntity();
if ($this->request->is('post')) { if ($this->request->is('post')) {
$postData = $this->request->getData(); $postData = $this->request->getData();
$saveOptions = [ $saveOptions = [
@@ -86,13 +76,17 @@ class ProductsController extends AppController
if (!isset($postedProductVariant['enabled']) || !$postedProductVariant['enabled'] || !isset($postedProductVariant['product_category_variant_id'])) { if (!isset($postedProductVariant['enabled']) || !$postedProductVariant['enabled'] || !isset($postedProductVariant['product_category_variant_id'])) {
continue; continue;
} }
$existingVariant = $this->Products->ProductCategories->ProductCategoryVariants->get($postedProductVariant['product_category_variant_id'], contain: ['ProductCategoryVariantOptions']); /**
* @var \CakeProducts\Model\Entity\ProductCategoryVariant $existingVariant
*/
$existingVariant = $this->fetchTable('CakeProducts.ProductCategoryVariants')
->get($postedProductVariant['product_category_variant_id'], contain: ['ProductCategoryVariantOptions']);
$optionsData = []; $optionsData = [];
foreach ($existingVariant->product_category_variant_options as $existingOption) { foreach ($existingVariant->product_category_variant_options as $existingOption) {
$optionsData[] = [ $optionsData[] = [
'variant_value' => $existingOption->variant_value, 'variant_value' => $existingOption->variant_value,
'variant_label' => $existingOption->variant_label ?? null, 'variant_label' => $existingOption->variant_label ?? null,
'enabled' => $existingOption->enabled, 'enabled' => $existingOption->enabled ?? false,
]; ];
} }
$tmpVariantData = [ $tmpVariantData = [
@@ -110,20 +104,20 @@ class ProductsController extends AppController
'product_category_id', 'product_category_id',
'product_type_id', 'product_type_id',
'product_attributes', 'product_attributes',
'product_category_variants' 'product_category_variants',
]; ];
$saveOptions['associated']['ProductCategoryVariants'] = [ $saveOptions['associated']['ProductCategoryVariants'] = [
'fields' => [ 'fields' => [
'name', 'name',
'enabled', 'enabled',
'product_category_variant_options', 'product_category_variant_options',
] ],
]; ];
$saveOptions['associated'][] = 'ProductCategoryVariants.ProductCategoryVariantOptions'; $saveOptions['associated'][] = 'ProductCategoryVariants.ProductCategoryVariantOptions';
$postData['product_category_variants'] = $productVariantsData; $postData['product_category_variants'] = $productVariantsData;
} }
$product = $productsTable->patchEntity($product, $postData, $saveOptions); $product = $this->fetchTable()->patchEntity($product, $postData, $saveOptions);
if ($productsTable->save($product, $saveOptions)) { if ($this->fetchTable()->save($product, $saveOptions)) {
$this->Flash->success(__('The product has been saved.')); $this->Flash->success(__('The product has been saved.'));
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
@@ -132,8 +126,10 @@ class ProductsController extends AppController
Log::debug(print_r($product->getErrors(), true)); Log::debug(print_r($product->getErrors(), true));
$this->Flash->error(__('The product could not be saved. Please, try again.')); $this->Flash->error(__('The product could not be saved. Please, try again.'));
} }
$productCategory = $product->product_category_id ? $productsTable->ProductCategories->find()->where(['internal_id' => $product->product_category_id])->first() : null; $productCategory = $product->product_category_id ? $this->fetchTable('ProductCategories')->find()
$productCatalogs = $productsTable->ProductCategories->ProductCatalogs->find('list')->toArray(); ->where(['internal_id' => $product->product_category_id])->first() : null;
$productCatalogs = $this->fetchTable('ProductCatalogs')->find('list')->toArray();
$this->set(compact('product', 'productCatalogs', 'productCategory')); $this->set(compact('product', 'productCatalogs', 'productCategory'));
} }
@@ -141,12 +137,11 @@ class ProductsController extends AppController
* Edit method * Edit method
* *
* @param string|null $id Product id. * @param string|null $id Product id.
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
*/ */
public function edit($id = null) public function edit($id = null) {
{ $productsTable = $this->fetchTable();
$productsTable = $this->Products;
$product = $productsTable->get($id, contain: [ $product = $productsTable->get($id, contain: [
'ProductAttributes', 'ProductAttributes',
'ProductAttributes.ProductCategoryAttributes', 'ProductAttributes.ProductCategoryAttributes',
@@ -175,16 +170,14 @@ class ProductsController extends AppController
* Delete method * Delete method
* *
* @param string|null $id Product id. * @param string|null $id Product id.
* @return \Cake\Http\Response|null Redirects to index.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return \Cake\Http\Response|null Redirects to index.
*/ */
public function delete($id = null) public function delete($id = null) {
{
$this->request->allowMethod(['post', 'delete']); $this->request->allowMethod(['post', 'delete']);
$productsTable = $this->Products; $product = $this->fetchTable()->get($id);
$product = $productsTable->get($id); if ($this->fetchTable()->delete($product)) {
if ($productsTable->delete($product)) {
$this->Flash->success(__('The product has been deleted.')); $this->Flash->success(__('The product has been deleted.'));
} else { } else {
$this->Flash->error(__('The product could not be deleted. Please, try again.')); $this->Flash->error(__('The product could not be deleted. Please, try again.'));
@@ -196,13 +189,11 @@ class ProductsController extends AppController
/** /**
* @return \Cake\Http\Response|null|void Renders view * @return \Cake\Http\Response|null|void Renders view
*/ */
public function select() public function select() {
{ $productCategory = $this->fetchTable()->ProductCategories->find()
$productsTable = $this->Products;
$productCategory = $productsTable->ProductCategories->find()
->where(['id' => $this->request->getQuery('product_category_id', '-1')]) ->where(['id' => $this->request->getQuery('product_category_id', '-1')])
->first(); ->first();
$products = $productsTable $products = $this->fetchTable()
->find('list') ->find('list')
->where(['product_category_id' => $productCategory->internal_id ?? '-1']) ->where(['product_category_id' => $productCategory->internal_id ?? '-1'])
->orderBy(['Products.name']) ->orderBy(['Products.name'])
@@ -210,4 +201,5 @@ class ProductsController extends AppController
$this->set(compact('products')); $this->set(compact('products'));
} }
} }
+1 -4
View File
@@ -2,11 +2,7 @@
namespace CakeProducts\Model\Behavior; namespace CakeProducts\Model\Behavior;
use ArrayObject;
use Cake\Datasource\EntityInterface; use Cake\Datasource\EntityInterface;
use Cake\Event\EventInterface;
use Cake\ORM\Behavior;
use LogicException;
use Tools\Model\Behavior\ToggleBehavior; use Tools\Model\Behavior\ToggleBehavior;
/** /**
@@ -54,4 +50,5 @@ class SecondToggleBehavior extends ToggleBehavior {
return $conditions; return $conditions;
} }
} }
+1 -4
View File
@@ -2,11 +2,7 @@
namespace CakeProducts\Model\Behavior; namespace CakeProducts\Model\Behavior;
use ArrayObject;
use Cake\Datasource\EntityInterface; use Cake\Datasource\EntityInterface;
use Cake\Event\EventInterface;
use Cake\ORM\Behavior;
use LogicException;
use Tools\Model\Behavior\ToggleBehavior; use Tools\Model\Behavior\ToggleBehavior;
/** /**
@@ -54,4 +50,5 @@ class ThirdToggleBehavior extends ToggleBehavior {
return $conditions; return $conditions;
} }
} }
@@ -1,42 +0,0 @@
<?php
declare(strict_types=1);
namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity;
/**
* ExternalProductCatalog Entity
*
* @property int $id
* @property string $base_url
* @property string $api_url
* @property DateTime $created
* @property DateTime|null $deleted
*
* @property ProductCatalog[] $product_catalogs
* @property ExternalProductCatalogsProductCatalog[] $external_product_catalogs_product_catalogs
*/
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
* be mass assigned. For security purposes, it is advised to set '*' to false
* (or remove it), and explicitly make individual fields accessible as needed.
*
* @var array<string, bool>
*/
protected array $_accessible = [
'base_url' => true,
'api_url' => true,
'created' => true,
'deleted' => true,
'enabled' => true,
// entities
'external_product_catalogs_product_catalogs' => true,
];
}
@@ -1,44 +0,0 @@
<?php
declare(strict_types=1);
namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity;
/**
* ExternalProductCatalogsProductCatalog Entity
*
* @property int $id
* @property string $external_product_catalog_id
* @property string $product_catalog_id
* @property DateTime $created
* @property bool $enabled
* @property DateTime|null $deleted
*
* @property ExternalProductCatalog $external_product_catalog
* @property ProductCatalog $product_catalog
*/
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
* be mass assigned. For security purposes, it is advised to set '*' to false
* (or remove it), and explicitly make individual fields accessible as needed.
*
* @var array<string, bool>
*/
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,
];
}
+5 -7
View File
@@ -3,9 +3,7 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity; namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity; use Cake\ORM\Entity;
use CakeProducts\Model\Enum\ProductProductTypeId;
/** /**
* Product Entity * Product Entity
@@ -13,16 +11,15 @@ use CakeProducts\Model\Enum\ProductProductTypeId;
* @property string $id * @property string $id
* @property string $name * @property string $name
* @property string $product_category_id * @property string $product_category_id
* @property ProductProductTypeId $product_type_id * @property \CakeProducts\Model\Enum\ProductProductTypeId $product_type_id
* @property DateTime|null $deleted * @property \Cake\I18n\DateTime|null $deleted
* *
* @property ProductCategory $product_category * @property ProductCategory $product_category
* @property ProductAttribute[] $product_attributes * @property ProductAttribute[] $product_attributes
* @property ProductCategoryVariant[] $product_category_variants * @property ProductCategoryVariant[] $product_category_variants
*
*/ */
class Product extends Entity class Product extends Entity {
{
/** /**
* Fields that can be mass assigned using newEntity() or patchEntity(). * Fields that can be mass assigned using newEntity() or patchEntity().
* *
@@ -44,4 +41,5 @@ class Product extends Entity
'product_category_variants' => true, 'product_category_variants' => true,
'primary_product_photo' => true, 'primary_product_photo' => true,
]; ];
} }
+4 -4
View File
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity; namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity; use Cake\ORM\Entity;
/** /**
@@ -14,14 +13,14 @@ use Cake\ORM\Entity;
* @property string $product_category_attribute_id * @property string $product_category_attribute_id
* @property string|null $attribute_value * @property string|null $attribute_value
* @property string|null $product_category_attribute_option_id * @property string|null $product_category_attribute_option_id
* @property DateTime|null $deleted * @property \Cake\I18n\DateTime|null $deleted
* *
* @property Product $product * @property Product $product
* @property ProductCategoryAttribute $product_category_attribute * @property ProductCategoryAttribute $product_category_attribute
* @property ProductCategoryAttributeOption $product_category_attribute_option * @property ProductCategoryAttributeOption $product_category_attribute_option
*/ */
class ProductAttribute extends Entity class ProductAttribute extends Entity {
{
/** /**
* Fields that can be mass assigned using newEntity() or patchEntity(). * Fields that can be mass assigned using newEntity() or patchEntity().
* *
@@ -43,4 +42,5 @@ class ProductAttribute extends Entity
'product_category_attribute' => false, 'product_category_attribute' => false,
'product_category_attribute_option' => false, 'product_category_attribute_option' => false,
]; ];
} }
+4 -6
View File
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity; namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity; use Cake\ORM\Entity;
/** /**
@@ -13,13 +12,12 @@ use Cake\ORM\Entity;
* @property string $name * @property string $name
* @property string|null $catalog_description * @property string|null $catalog_description
* @property bool $enabled * @property bool $enabled
* @property DateTime|null $deleted * @property \Cake\I18n\DateTime|null $deleted
* *
* @property ProductCategory[] $product_categories * @property ProductCategory[] $product_categories
* @property ExternalProductCatalog[] $external_product_catalogs
*/ */
class ProductCatalog extends Entity class ProductCatalog extends Entity {
{
/** /**
* Fields that can be mass assigned using newEntity() or patchEntity(). * Fields that can be mass assigned using newEntity() or patchEntity().
* *
@@ -37,6 +35,6 @@ class ProductCatalog extends Entity
// entities // entities
'product_categories' => true, 'product_categories' => true,
'external_product_catalogs' => true,
]; ];
} }
+8 -9
View File
@@ -3,9 +3,7 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity; namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity; use Cake\ORM\Entity;
use CakeProducts\Model\Enum\ProductProductTypeId;
/** /**
* ProductCategory Entity * ProductCategory Entity
@@ -19,15 +17,15 @@ use CakeProducts\Model\Enum\ProductProductTypeId;
* @property int $lft * @property int $lft
* @property int $rght * @property int $rght
* @property bool $enabled * @property bool $enabled
* @property DateTime|null $deleted * @property \Cake\I18n\DateTime|null $deleted
* @property ProductProductTypeId|null $default_product_type_id * @property \CakeProducts\Model\Enum\ProductProductTypeId|null $default_product_type_id
* *
* @property \CakeProducts\Model\Entity\ProductCatalog $product_catalog * @property ProductCatalog $product_catalog
* @property \CakeProducts\Model\Entity\ParentProductCategory $parent_product_category * @property ProductCategory $parent_product_category
* @property \CakeProducts\Model\Entity\ChildProductCategory[] $child_product_categories * @property ProductCategory[] $child_product_categories
*/ */
class ProductCategory extends Entity class ProductCategory extends Entity {
{
/** /**
* Fields that can be mass assigned using newEntity() or patchEntity(). * Fields that can be mass assigned using newEntity() or patchEntity().
* *
@@ -55,4 +53,5 @@ class ProductCategory extends Entity
'child_product_categories' => true, 'child_product_categories' => true,
'primary_product_photo' => true, 'primary_product_photo' => true,
]; ];
} }
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity; namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity; use Cake\ORM\Entity;
/** /**
@@ -14,13 +13,13 @@ use Cake\ORM\Entity;
* @property string|null $product_category_id * @property string|null $product_category_id
* @property int $attribute_type_id * @property int $attribute_type_id
* @property bool $enabled * @property bool $enabled
* @property DateTime|null $deleted * @property \Cake\I18n\DateTime|null $deleted
* *
* @property ProductCategory $product_category * @property ProductCategory $product_category
* @property ProductCategoryAttributeOption[] $product_category_attribute_options * @property ProductCategoryAttributeOption[] $product_category_attribute_options
*/ */
class ProductCategoryAttribute extends Entity class ProductCategoryAttribute extends Entity {
{
/** /**
* Fields that can be mass assigned using newEntity() or patchEntity(). * Fields that can be mass assigned using newEntity() or patchEntity().
* *
@@ -41,4 +40,5 @@ class ProductCategoryAttribute extends Entity
'product_category' => true, 'product_category' => true,
'product_category_attribute_options' => true, 'product_category_attribute_options' => true,
]; ];
} }
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity; namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity; use Cake\ORM\Entity;
/** /**
@@ -14,12 +13,12 @@ use Cake\ORM\Entity;
* @property string $attribute_value * @property string $attribute_value
* @property string $attribute_label * @property string $attribute_label
* @property bool $enabled * @property bool $enabled
* @property DateTime|null $deleted * @property \Cake\I18n\DateTime|null $deleted
* *
* @property ProductCategoryAttribute $product_category_attribute * @property ProductCategoryAttribute $product_category_attribute
*/ */
class ProductCategoryAttributeOption extends Entity class ProductCategoryAttributeOption extends Entity {
{
/** /**
* Fields that can be mass assigned using newEntity() or patchEntity(). * Fields that can be mass assigned using newEntity() or patchEntity().
* *
@@ -39,4 +38,5 @@ class ProductCategoryAttributeOption extends Entity
// entities // entities
'product_category_attribute' => true, 'product_category_attribute' => true,
]; ];
} }
+5 -5
View File
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity; namespace CakeProducts\Model\Entity;
use Cake\Datasource\EntityInterface;
use Cake\ORM\Entity; use Cake\ORM\Entity;
/** /**
@@ -16,11 +15,11 @@ use Cake\ORM\Entity;
* @property bool $enabled * @property bool $enabled
* @property bool $is_system_variant * @property bool $is_system_variant
* *
* @property ProductCategory|EntityInterface $product_category * @property ProductCategory $product_category
* @property ProductCategoryVariantOption[]|EntityInterface[] $product_category_variant_options * @property ProductCategoryVariantOption[] $product_category_variant_options
*/ */
class ProductCategoryVariant extends Entity class ProductCategoryVariant extends Entity {
{
/** /**
* Fields that can be mass assigned using newEntity() or patchEntity(). * Fields that can be mass assigned using newEntity() or patchEntity().
* *
@@ -42,4 +41,5 @@ class ProductCategoryVariant extends Entity
'product' => false, 'product' => false,
'product_category_variant_options' => true, 'product_category_variant_options' => true,
]; ];
} }
@@ -15,10 +15,10 @@ use Cake\ORM\Entity;
* @property \Cake\I18n\DateTime $modified * @property \Cake\I18n\DateTime $modified
* @property \Cake\I18n\DateTime|null $deleted * @property \Cake\I18n\DateTime|null $deleted
* *
* @property \App\Model\Entity\ProductCategoryVariant $product_category_variant * @property ProductCategoryVariant $product_category_variant
*/ */
class ProductCategoryVariantOption extends Entity class ProductCategoryVariantOption extends Entity {
{
/** /**
* Fields that can be mass assigned using newEntity() or patchEntity(). * Fields that can be mass assigned using newEntity() or patchEntity().
* *
@@ -38,4 +38,5 @@ class ProductCategoryVariantOption extends Entity
// entities // entities
'product_category_variant' => false, 'product_category_variant' => false,
]; ];
} }
+6 -6
View File
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity; namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity; use Cake\ORM\Entity;
/** /**
@@ -20,16 +19,16 @@ use Cake\ORM\Entity;
* @property bool $primary_sku_photo * @property bool $primary_sku_photo
* @property int $photo_position * @property int $photo_position
* @property bool $enabled * @property bool $enabled
* @property DateTime $created * @property \Cake\I18n\DateTime $created
* @property DateTime|null $modified * @property \Cake\I18n\DateTime|null $modified
* @property DateTime|null $deleted * @property \Cake\I18n\DateTime|null $deleted
* *
* @property Product|null $product * @property Product|null $product
* @property ProductSku|null $product_sku * @property ProductSku|null $product_sku
* @property ProductCategory $product_category * @property ProductCategory $product_category
*/ */
class ProductPhoto extends Entity class ProductPhoto extends Entity {
{
/** /**
* Fields that can be mass assigned using newEntity() or patchEntity(). * Fields that can be mass assigned using newEntity() or patchEntity().
* *
@@ -59,4 +58,5 @@ class ProductPhoto extends Entity
'product_sku' => false, 'product_sku' => false,
'product_category' => false, 'product_category' => false,
]; ];
} }
+6 -6
View File
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity; namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity; use Cake\ORM\Entity;
/** /**
@@ -15,16 +14,16 @@ use Cake\ORM\Entity;
* @property string|null $barcode * @property string|null $barcode
* @property string|null $price * @property string|null $price
* @property string|null $cost * @property string|null $cost
* @property DateTime $created * @property \Cake\I18n\DateTime $created
* @property DateTime|null $modified * @property \Cake\I18n\DateTime|null $modified
* @property DateTime|null $deleted * @property \Cake\I18n\DateTime|null $deleted
* @property bool $default_sku * @property bool $default_sku
* *
* @property Product $product * @property Product $product
* @property ProductSkuVariantValue[] $product_sku_variant_values * @property ProductSkuVariantValue[] $product_sku_variant_values
*/ */
class ProductSku extends Entity class ProductSku extends Entity {
{
/** /**
* Fields that can be mass assigned using newEntity() or patchEntity(). * Fields that can be mass assigned using newEntity() or patchEntity().
* *
@@ -49,4 +48,5 @@ class ProductSku extends Entity
'product' => false, 'product' => false,
'product_sku_variant_values' => true, 'product_sku_variant_values' => true,
]; ];
} }
+3 -2
View File
@@ -17,8 +17,8 @@ use Cake\ORM\Entity;
* @property ProductCategoryVariant $product_category_variant * @property ProductCategoryVariant $product_category_variant
* @property ProductCategoryVariantOption $product_category_variant_option * @property ProductCategoryVariantOption $product_category_variant_option
*/ */
class ProductSkuVariantValue extends Entity class ProductSkuVariantValue extends Entity {
{
/** /**
* Fields that can be mass assigned using newEntity() or patchEntity(). * Fields that can be mass assigned using newEntity() or patchEntity().
* *
@@ -38,4 +38,5 @@ class ProductSkuVariantValue extends Entity
'product_variant' => true, 'product_variant' => true,
'product_category_variant_option' => true, 'product_category_variant_option' => true,
]; ];
} }
+5 -4
View File
@@ -14,11 +14,11 @@ use Cake\ORM\Entity;
* @property string $product_id * @property string $product_id
* @property bool $enabled * @property bool $enabled
* *
* @property \App\Model\Entity\ProductCategoryVariant $product_category_variant * @property ProductCategoryVariant $product_category_variant
* @property \App\Model\Entity\Product $product * @property Product $product
*/ */
class ProductVariant extends Entity class ProductVariant extends Entity {
{
/** /**
* Fields that can be mass assigned using newEntity() or patchEntity(). * Fields that can be mass assigned using newEntity() or patchEntity().
* *
@@ -36,4 +36,5 @@ class ProductVariant extends Entity
'product_category_variant' => true, 'product_category_variant' => true,
'product' => true, 'product' => true,
]; ];
} }
@@ -1,23 +1,25 @@
<?php <?php
namespace CakeProducts\Model\Enum; namespace CakeProducts\Model\Enum;
use Cake\Database\Type\EnumLabelInterface; use Cake\Database\Type\EnumLabelInterface;
use Tools\Model\Enum\EnumOptionsTrait; use Tools\Model\Enum\EnumOptionsTrait;
enum ProductCategoryAttributeTypeId: int implements EnumLabelInterface enum ProductCategoryAttributeTypeId: int implements EnumLabelInterface {
{
use EnumOptionsTrait; use EnumOptionsTrait;
case Constrained = 1; case Constrained = 1;
case Text = 2; case Text = 2;
case Integer = 3; case Integer = 3;
public function label(): string /**
{ * @return string
*/
public function label(): string {
return match ($this) { return match ($this) {
self::Constrained => 'Constrained', ProductCategoryAttributeTypeId::Constrained => 'Constrained',
self::Text => 'Text', ProductCategoryAttributeTypeId::Text => 'Text',
self::Integer => 'Integer' ProductCategoryAttributeTypeId::Integer => 'Integer'
}; };
} }
} }
+11 -8
View File
@@ -1,4 +1,5 @@
<?php <?php
namespace CakeProducts\Model\Enum; namespace CakeProducts\Model\Enum;
use Cake\Database\Type\EnumLabelInterface; use Cake\Database\Type\EnumLabelInterface;
@@ -15,15 +16,17 @@ enum ProductProductTypeId: int implements EnumLabelInterface
case Subscription = 5; case Subscription = 5;
// case Event = 5; // case Event = 5;
public function label(): string /**
{ * @return string
*/
public function label(): string {
return match ($this) { return match ($this) {
self::Service => 'Service', ProductProductTypeId::Service => 'Service',
self::Product => 'Product', ProductProductTypeId::Product => 'Product',
self::Consumable => 'Consumable', ProductProductTypeId::Consumable => 'Consumable',
self::DigitalGood => 'Digital Good', ProductProductTypeId::DigitalGood => 'Digital Good',
self::Subscription => 'Subscription', ProductProductTypeId::Subscription => 'Subscription',
// self::Event => 'Event', // ProductProductTypeId::Event => 'Event',
}; };
} }
} }
@@ -1,125 +0,0 @@
<?php
declare(strict_types=1);
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
*
* @property ExternalProductCatalogsTable&BelongsTo $ExternalProductCatalogs
* @property ProductCatalogsTable&BelongsTo $ProductCatalogs
*
* @method ExternalProductCatalogsProductCatalog newEmptyEntity()
* @method ExternalProductCatalogsProductCatalog newEntity(array $data, array $options = [])
* @method array<ExternalProductCatalogsProductCatalog> newEntities(array $data, array $options = [])
* @method ExternalProductCatalogsProductCatalog get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
* @method ExternalProductCatalogsProductCatalog findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ExternalProductCatalogsProductCatalog patchEntity(EntityInterface $entity, array $data, array $options = [])
* @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 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 = [])
* @method iterable<ExternalProductCatalogsProductCatalog>|ResultSetInterface<ExternalProductCatalogsProductCatalog> deleteManyOrFail(iterable $entities, array $options = [])
*
* @mixin TimestampBehavior
*/
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);
$this->setTable('external_product_catalogs_product_catalogs');
$this->setDisplayField('external_product_catalog_id');
$this->setPrimaryKey('id');
$this->addBehavior('Timestamp');
$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',
// 'foreignKey' => 'product_catalog_id',
'joinType' => 'INNER',
]);
$this->addBehavior('Muffin/Trash.Trash');
}
/**
* Default validation rules.
*
* @param Validator $validator Validator instance.
* @return Validator
*/
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
->boolean('enabled');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
return $validator;
}
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
*/
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;
}
}
@@ -1,117 +0,0 @@
<?php
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 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 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 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 = [])
* @method iterable<ExternalProductCatalog>|ResultSetInterface<ExternalProductCatalog> deleteManyOrFail(iterable $entities, array $options = [])
*
* @mixin TimestampBehavior
*/
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);
$this->setTable('external_product_catalogs');
$this->setDisplayField('base_url');
$this->setPrimaryKey('id');
$this->addBehavior('Timestamp');
$this->setEntityClass(
Configure::read('CakeProducts.ExternalProductCatalogs.entity', 'CakeProducts\Model\Entity\ExternalProductCatalog')
);
$this->belongsToMany('ProductCatalogs', [
'through' => 'ExternalProductCatalogsProductCatalogs',
'className' => 'CakeProducts.ProductCatalogs',
]);
$this->hasMany('ExternalProductCatalogsProductCatalogs', [
'foreignKey' => 'external_product_catalog_id',
'className' => 'CakeProducts.ExternalProductCatalogsProductCatalogs',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->addBehavior('Muffin/Trash.Trash');
}
/**
* Default validation rules.
*
* @param Validator $validator Validator instance.
* @return Validator
*/
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');
// ->url('api_url');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
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
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
return $rules;
}
}
+23 -25
View File
@@ -11,34 +11,33 @@ use Cake\Validation\Validator;
/** /**
* ProductAttributes Model * ProductAttributes Model
* *
* @property \App\Model\Table\ProductsTable&\Cake\ORM\Association\BelongsTo $Products * @property ProductsTable&\Cake\ORM\Association\BelongsTo $Products
* @property \App\Model\Table\ProductCategoryAttributesTable&\Cake\ORM\Association\BelongsTo $ProductCategoryAttributes * @property ProductCategoryAttributesTable&\Cake\ORM\Association\BelongsTo $ProductCategoryAttributes
* @property \App\Model\Table\ProductCategoryAttributeOptionsTable&\Cake\ORM\Association\BelongsTo $ProductCategoryAttributeOptions * @property ProductCategoryAttributeOptionsTable&\Cake\ORM\Association\BelongsTo $ProductCategoryAttributeOptions
* *
* @method \App\Model\Entity\ProductAttribute newEmptyEntity() * @method \CakeProducts\Model\Entity\ProductAttribute newEmptyEntity()
* @method \App\Model\Entity\ProductAttribute newEntity(array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductAttribute newEntity(array $data, array $options = [])
* @method array<\App\Model\Entity\ProductAttribute> newEntities(array $data, array $options = []) * @method array<\CakeProducts\Model\Entity\ProductAttribute> newEntities(array $data, array $options = [])
* @method \App\Model\Entity\ProductAttribute get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args) * @method \CakeProducts\Model\Entity\ProductAttribute get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
* @method \App\Model\Entity\ProductAttribute findOrCreate($search, ?callable $callback = null, array $options = []) * @method \CakeProducts\Model\Entity\ProductAttribute findOrCreate($search, ?callable $callback = null, array $options = [])
* @method \App\Model\Entity\ProductAttribute patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductAttribute patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method array<\App\Model\Entity\ProductAttribute> patchEntities(iterable $entities, array $data, array $options = []) * @method array<\CakeProducts\Model\Entity\ProductAttribute> patchEntities(iterable $entities, array $data, array $options = [])
* @method \App\Model\Entity\ProductAttribute|false save(\Cake\Datasource\EntityInterface $entity, array $options = []) * @method \CakeProducts\Model\Entity\ProductAttribute|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method \App\Model\Entity\ProductAttribute saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = []) * @method \CakeProducts\Model\Entity\ProductAttribute saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method iterable<\App\Model\Entity\ProductAttribute>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\ProductAttribute>|false saveMany(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductAttribute>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductAttribute>|false saveMany(iterable $entities, array $options = [])
* @method iterable<\App\Model\Entity\ProductAttribute>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\ProductAttribute> saveManyOrFail(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductAttribute>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductAttribute> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<\App\Model\Entity\ProductAttribute>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\ProductAttribute>|false deleteMany(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductAttribute>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductAttribute>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<\App\Model\Entity\ProductAttribute>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\ProductAttribute> deleteManyOrFail(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductAttribute>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductAttribute> deleteManyOrFail(iterable $entities, array $options = [])
*/ */
class ProductAttributesTable extends Table class ProductAttributesTable extends Table {
{
/** /**
* Initialize method * Initialize method
* *
* @param array<string, mixed> $config The configuration for the Table. * @param array<string, mixed> $config The configuration for the Table.
* @return void * @return void
*/ */
public function initialize(array $config): void public function initialize(array $config): void {
{
parent::initialize($config); parent::initialize($config);
$this->setTable('product_attributes'); $this->setTable('product_attributes');
@@ -46,7 +45,7 @@ class ProductAttributesTable extends Table
$this->setPrimaryKey('id'); $this->setPrimaryKey('id');
$this->setEntityClass( $this->setEntityClass(
Configure::read('CakeProducts.ProductAttributes.entity', 'CakeProducts\Model\Entity\ProductAttribute') Configure::read('CakeProducts.ProductAttributes.entity', 'CakeProducts\Model\Entity\ProductAttribute'),
); );
$this->belongsTo('Products', [ $this->belongsTo('Products', [
@@ -72,8 +71,7 @@ class ProductAttributesTable extends Table
* @param \Cake\Validation\Validator $validator Validator instance. * @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator * @return \Cake\Validation\Validator
*/ */
public function validationDefault(Validator $validator): Validator public function validationDefault(Validator $validator): Validator {
{
$validator $validator
->uuid('product_id') ->uuid('product_id')
->notEmptyString('product_id'); ->notEmptyString('product_id');
@@ -105,12 +103,12 @@ class ProductAttributesTable extends Table
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified. * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return \Cake\ORM\RulesChecker * @return \Cake\ORM\RulesChecker
*/ */
public function buildRules(RulesChecker $rules): RulesChecker public function buildRules(RulesChecker $rules): RulesChecker {
{
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']); $rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
$rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']); $rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']);
$rules->add($rules->existsIn(['product_category_attribute_option_id'], 'ProductCategoryAttributeOptions'), ['errorField' => 'product_category_attribute_option_id']); $rules->add($rules->existsIn(['product_category_attribute_option_id'], 'ProductCategoryAttributeOptions'), ['errorField' => 'product_category_attribute_option_id']);
return $rules; return $rules;
} }
} }
+24 -36
View File
@@ -4,43 +4,36 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table; namespace CakeProducts\Model\Table;
use Cake\Core\Configure; use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker; use Cake\ORM\RulesChecker;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\Validation\Validator; use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductCatalog;
use Closure;
use Psr\SimpleCache\CacheInterface;
/** /**
* ProductCatalogs Model * ProductCatalogs Model
* *
* @method ProductCatalog newEmptyEntity() * @method \CakeProducts\Model\Entity\ProductCatalog newEmptyEntity()
* @method ProductCatalog newEntity(array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductCatalog newEntity(array $data, array $options = [])
* @method array<ProductCatalog> newEntities(array $data, array $options = []) * @method array<\CakeProducts\Model\Entity\ProductCatalog> newEntities(array $data, array $options = [])
* @method ProductCatalog get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args) * @method \CakeProducts\Model\Entity\ProductCatalog get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductCatalog findOrCreate($search, ?callable $callback = null, array $options = []) * @method \CakeProducts\Model\Entity\ProductCatalog findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductCatalog patchEntity(EntityInterface $entity, array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductCatalog patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method array<ProductCatalog> patchEntities(iterable $entities, array $data, array $options = []) * @method array<\CakeProducts\Model\Entity\ProductCatalog> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductCatalog|false save(EntityInterface $entity, array $options = []) * @method \CakeProducts\Model\Entity\ProductCatalog|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method ProductCatalog saveOrFail(EntityInterface $entity, array $options = []) * @method \CakeProducts\Model\Entity\ProductCatalog saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method iterable<ProductCatalog>|ResultSetInterface<ProductCatalog>|false saveMany(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductCatalog>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCatalog>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductCatalog>|ResultSetInterface<ProductCatalog> saveManyOrFail(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductCatalog>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCatalog> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductCatalog>|ResultSetInterface<ProductCatalog>|false deleteMany(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductCatalog>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCatalog>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductCatalog>|ResultSetInterface<ProductCatalog> deleteManyOrFail(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductCatalog>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCatalog> deleteManyOrFail(iterable $entities, array $options = [])
*/ */
class ProductCatalogsTable extends Table class ProductCatalogsTable extends Table {
{
/** /**
* Initialize method * Initialize method
* *
* @param array<string, mixed> $config The configuration for the Table. * @param array<string, mixed> $config The configuration for the Table.
* @return void * @return void
*/ */
public function initialize(array $config): void public function initialize(array $config): void {
{
parent::initialize($config); parent::initialize($config);
$this->setTable('product_catalogs'); $this->setTable('product_catalogs');
@@ -48,15 +41,11 @@ class ProductCatalogsTable extends Table
$this->setPrimaryKey('id'); $this->setPrimaryKey('id');
$this->setEntityClass( $this->setEntityClass(
Configure::read('CakeProducts.ProductCatalogs.entity', 'CakeProducts\Model\Entity\ProductCatalog') Configure::read('CakeProducts.ProductCatalogs.entity', 'CakeProducts\Model\Entity\ProductCatalog'),
); );
$this->hasMany('ProductCategories', [ $this->hasMany('ProductCategories', [
'className' => 'CakeProducts.ProductCategories', 'className' => 'CakeProducts.ProductCategories',
]); ]);
$this->belongsToMany('ExternalProductCatalogs', [
'through' => 'ExternalProductCatalogsProductCatalogs',
'className' => 'CakeProducts.ExternalProductCatalogs',
]);
$this->addBehavior('Muffin/Trash.Trash'); $this->addBehavior('Muffin/Trash.Trash');
} }
@@ -64,11 +53,10 @@ class ProductCatalogsTable extends Table
/** /**
* Default validation rules. * Default validation rules.
* *
* @param Validator $validator Validator instance. * @param \Cake\Validation\Validator $validator Validator instance.
* @return Validator * @return \Cake\Validation\Validator
*/ */
public function validationDefault(Validator $validator): Validator public function validationDefault(Validator $validator): Validator {
{
$validator $validator
->scalar('name') ->scalar('name')
->maxLength('name', 255) ->maxLength('name', 255)
@@ -97,13 +85,13 @@ class ProductCatalogsTable extends Table
* Returns a rules checker object that will be used for validating * Returns a rules checker object that will be used for validating
* application integrity. * application integrity.
* *
* @param RulesChecker $rules The rules object to be modified. * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return RulesChecker * @return \Cake\ORM\RulesChecker
*/ */
public function buildRules(RulesChecker $rules): RulesChecker public function buildRules(RulesChecker $rules): RulesChecker {
{
$rules->add($rules->isUnique(['name']), ['errorField' => 'name']); $rules->add($rules->isUnique(['name']), ['errorField' => 'name']);
return $rules; return $rules;
} }
} }
+42 -54
View File
@@ -6,47 +6,39 @@ namespace CakeProducts\Model\Table;
use Cake\Core\Configure; use Cake\Core\Configure;
use Cake\Database\Type\EnumType; use Cake\Database\Type\EnumType;
use Cake\Datasource\EntityInterface; use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Association\HasMany;
use Cake\ORM\Behavior\TreeBehavior;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker; use Cake\ORM\RulesChecker;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\Validation\Validator; use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductCategory;
use CakeProducts\Model\Enum\ProductProductTypeId; use CakeProducts\Model\Enum\ProductProductTypeId;
use Closure;
use Psr\SimpleCache\CacheInterface;
/** /**
* ProductCategories Model * ProductCategories Model
* *
* @property ProductCatalogsTable&BelongsTo $ProductCatalogs * @property ProductCatalogsTable&\Cake\ORM\Association\BelongsTo $ProductCatalogs
* @property ProductCategoriesTable&BelongsTo $ParentProductCategories * @property ProductCategoriesTable&\Cake\ORM\Association\BelongsTo $ParentProductCategories
* @property ProductCategoriesTable&HasMany $ChildProductCategories * @property ProductCategoriesTable&\Cake\ORM\Association\HasMany $ChildProductCategories
* *
* @method ProductCategory newEmptyEntity() * @method \CakeProducts\Model\Entity\ProductCategory newEmptyEntity()
* @method ProductCategory newEntity(array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategory newEntity(array $data, array $options = [])
* @method array<ProductCategory> newEntities(array $data, array $options = []) * @method array<\CakeProducts\Model\Entity\ProductCategory> newEntities(array $data, array $options = [])
* @method ProductCategory get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args) * @method \CakeProducts\Model\Entity\ProductCategory get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductCategory findOrCreate($search, ?callable $callback = null, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategory findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductCategory patchEntity(EntityInterface $entity, array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategory patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method array<ProductCategory> patchEntities(iterable $entities, array $data, array $options = []) * @method array<\CakeProducts\Model\Entity\ProductCategory> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductCategory saveOrFail(EntityInterface $entity, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategory saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method iterable<ProductCategory>|ResultSetInterface<ProductCategory>|false saveMany(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductCategory>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategory>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductCategory>|ResultSetInterface<ProductCategory> saveManyOrFail(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductCategory>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategory> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductCategory>|ResultSetInterface<ProductCategory>|false deleteMany(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductCategory>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategory>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductCategory>|ResultSetInterface<ProductCategory> deleteManyOrFail(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductCategory>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategory> deleteManyOrFail(iterable $entities, array $options = [])
* *
* @mixin TreeBehavior * @mixin \Cake\ORM\Behavior\TreeBehavior
*/ */
class ProductCategoriesTable extends Table class ProductCategoriesTable extends Table {
{
/** /**
* Current scope for Tree behavior - per catalog * Current scope for Tree behavior - per catalog
* *
* @var string * @var string|int
*/ */
protected $treeCatalogId; protected $treeCatalogId;
@@ -56,8 +48,7 @@ class ProductCategoriesTable extends Table
* @param array<string, mixed> $config The configuration for the Table. * @param array<string, mixed> $config The configuration for the Table.
* @return void * @return void
*/ */
public function initialize(array $config): void public function initialize(array $config): void {
{
parent::initialize($config); parent::initialize($config);
$this->treeCatalogId = 1; $this->treeCatalogId = 1;
@@ -65,16 +56,16 @@ class ProductCategoriesTable extends Table
$this->setDisplayField('name'); $this->setDisplayField('name');
$this->setPrimaryKey('id'); $this->setPrimaryKey('id');
$this->setEntityClass( $this->setEntityClass(
Configure::read('CakeProducts.ProductCategories.entity', 'CakeProducts\Model\Entity\ProductCategory') Configure::read('CakeProducts.ProductCategories.entity', 'CakeProducts\Model\Entity\ProductCategory'),
); );
$this->addBehavior('Tree', [ $this->addBehavior('Tree', [
'cascadeCallbacks' => true, 'cascadeCallbacks' => true,
]); ]);
$this->belongsTo('ProductCatalogs', [ $this->belongsTo('ProductCatalogs', [
'className' => 'CakeProducts.ProductCatalogs',
'foreignKey' => 'product_catalog_id', 'foreignKey' => 'product_catalog_id',
'joinType' => 'INNER', 'joinType' => 'INNER',
'className' => 'CakeProducts.ProductCatalogs',
]); ]);
$this->belongsTo('ParentProductCategories', [ $this->belongsTo('ParentProductCategories', [
'className' => 'CakeProducts.ProductCategories', 'className' => 'CakeProducts.ProductCategories',
@@ -87,55 +78,54 @@ class ProductCategoriesTable extends Table
'cascadeCallbacks' => true, 'cascadeCallbacks' => true,
]); ]);
$this->hasMany('ProductCategoryAttributes', [ $this->hasMany('ProductCategoryAttributes', [
'className' => 'CakeProducts.ProductCategoryAttributes',
'foreignKey' => 'product_category_id', 'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id', 'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductCategoryAttributes',
'dependent' => true, 'dependent' => true,
'cascadeCallbacks' => true, 'cascadeCallbacks' => true,
]); ]);
$this->hasMany('ProductCategoryVariants', [ $this->hasMany('ProductCategoryVariants', [
'className' => 'CakeProducts.ProductCategoryVariants',
'foreignKey' => 'product_category_id', 'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id', 'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductCategoryVariants',
'dependent' => true, 'dependent' => true,
'cascadeCallbacks' => true, 'cascadeCallbacks' => true,
]); ]);
$this->hasMany('Products', [ $this->hasMany('Products', [
'className' => 'CakeProducts.Products',
'foreignKey' => 'product_category_id', 'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id', 'bindingKey' => 'internal_id',
'className' => 'CakeProducts.Products',
'dependent' => true, 'dependent' => true,
'cascadeCallbacks' => true, 'cascadeCallbacks' => true,
]); ]);
$this->hasMany('ProductPhotos', [ $this->hasMany('ProductPhotos', [
'className' => 'CakeProducts.ProductPhotos',
'foreignKey' => 'product_category_id', 'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id', 'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductPhotos',
'dependent' => true, 'dependent' => true,
'cascadeCallbacks' => true, 'cascadeCallbacks' => true,
]); ]);
$this->hasOne('PrimaryProductPhotos', [ $this->hasOne('PrimaryProductPhotos', [
'className' => 'CakeProducts.ProductPhotos',
'foreignKey' => 'product_category_id', 'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id', 'bindingKey' => 'internal_id',
'conditions' => ['PrimaryProductPhotos.primary_category_photo' => true], 'conditions' => ['PrimaryProductPhotos.primary_category_photo' => true],
'className' => 'CakeProducts.ProductPhotos',
'dependent' => true, 'dependent' => true,
]); ]);
$this->getSchema()->setColumnType('default_product_type_id', EnumType::from(ProductProductTypeId::class)); $this->getSchema()->setColumnType('default_product_type_id', EnumType::from(ProductProductTypeId::class));
$this->behaviors()->Tree->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]); $this->getBehavior('Tree')->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]);
$this->addBehavior('Muffin/Trash.Trash'); $this->addBehavior('Muffin/Trash.Trash');
} }
/** /**
* Default validation rules. * Default validation rules.
* *
* @param Validator $validator Validator instance. * @param \Cake\Validation\Validator $validator Validator instance.
* @return Validator * @return \Cake\Validation\Validator
*/ */
public function validationDefault(Validator $validator): Validator public function validationDefault(Validator $validator): Validator {
{
$validator $validator
->uuid('product_catalog_id') ->uuid('product_catalog_id')
->notEmptyString('product_catalog_id'); ->notEmptyString('product_catalog_id');
@@ -173,11 +163,10 @@ class ProductCategoriesTable extends Table
* Returns a rules checker object that will be used for validating * Returns a rules checker object that will be used for validating
* application integrity. * application integrity.
* *
* @param RulesChecker $rules The rules object to be modified. * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return RulesChecker * @return \Cake\ORM\RulesChecker
*/ */
public function buildRules(RulesChecker $rules): RulesChecker public function buildRules(RulesChecker $rules): RulesChecker {
{
$rules->add($rules->isUnique(['product_catalog_id', 'name']), ['errorField' => 'product_catalog_id']); $rules->add($rules->isUnique(['product_catalog_id', 'name']), ['errorField' => 'product_catalog_id']);
$rules->add($rules->existsIn(['product_catalog_id'], 'ProductCatalogs'), ['errorField' => 'product_catalog_id']); $rules->add($rules->existsIn(['product_catalog_id'], 'ProductCatalogs'), ['errorField' => 'product_catalog_id']);
$rules->add($rules->existsIn(['parent_id'], 'ParentProductCategories'), ['errorField' => 'parent_id']); $rules->add($rules->existsIn(['parent_id'], 'ParentProductCategories'), ['errorField' => 'parent_id']);
@@ -186,30 +175,29 @@ class ProductCategoriesTable extends Table
} }
/** /**
* @param int $catalogId * @param string $catalogId
* *
* @return void * @return void
*/ */
public function setConfigureCatalogId(string $catalogId) public function setConfigureCatalogId(string $catalogId) {
{
$this->treeCatalogId = $catalogId; $this->treeCatalogId = $catalogId;
$this->behaviors()->Tree->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]); $this->getBehavior('Tree')->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]);
} }
/** /**
* @param EntityInterface $entity * @param \Cake\Datasource\EntityInterface $entity
* @param array $options * @param array $options
* *
* @return EntityInterface|false * @return \Cake\Datasource\EntityInterface|false
*/ */
public function save(EntityInterface $entity, array $options = []): EntityInterface|false public function save(EntityInterface $entity, array $options = []): EntityInterface|false {
{
$this->behaviors()->get('Tree')->setConfig([ $this->behaviors()->get('Tree')->setConfig([
'scope' => [ 'scope' => [
'product_catalog_id' => $entity->product_catalog_id, 'product_catalog_id' => $entity->product_catalog_id ?? null,
], ],
]); ]);
return parent::save($entity, $options); return parent::save($entity, $options);
} }
} }
@@ -4,46 +4,38 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table; namespace CakeProducts\Model\Table;
use Cake\Core\Configure; use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker; use Cake\ORM\RulesChecker;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\Validation\Validator; use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductCategoryAttributeOption;
use Closure;
use Psr\SimpleCache\CacheInterface;
/** /**
* ProductCategoryAttributeOptions Model * ProductCategoryAttributeOptions Model
* *
* @property ProductCategoryAttributesTable&BelongsTo $ProductCategoryAttributes * @property ProductCategoryAttributesTable&\Cake\ORM\Association\BelongsTo $ProductCategoryAttributes
* *
* @method ProductCategoryAttributeOption newEmptyEntity() * @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption newEmptyEntity()
* @method ProductCategoryAttributeOption newEntity(array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption newEntity(array $data, array $options = [])
* @method array<ProductCategoryAttributeOption> newEntities(array $data, array $options = []) * @method array<\CakeProducts\Model\Entity\ProductCategoryAttributeOption> newEntities(array $data, array $options = [])
* @method ProductCategoryAttributeOption get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args) * @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductCategoryAttributeOption findOrCreate($search, ?callable $callback = null, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductCategoryAttributeOption patchEntity(EntityInterface $entity, array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method array<ProductCategoryAttributeOption> patchEntities(iterable $entities, array $data, array $options = []) * @method array<\CakeProducts\Model\Entity\ProductCategoryAttributeOption> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductCategoryAttributeOption|false save(EntityInterface $entity, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method ProductCategoryAttributeOption saveOrFail(EntityInterface $entity, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method iterable<ProductCategoryAttributeOption>|ResultSetInterface<ProductCategoryAttributeOption>|false saveMany(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductCategoryAttributeOption>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategoryAttributeOption>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryAttributeOption>|ResultSetInterface<ProductCategoryAttributeOption> saveManyOrFail(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductCategoryAttributeOption>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategoryAttributeOption> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductCategoryAttributeOption>|ResultSetInterface<ProductCategoryAttributeOption>|false deleteMany(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductCategoryAttributeOption>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategoryAttributeOption>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryAttributeOption>|ResultSetInterface<ProductCategoryAttributeOption> deleteManyOrFail(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductCategoryAttributeOption>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategoryAttributeOption> deleteManyOrFail(iterable $entities, array $options = [])
*/ */
class ProductCategoryAttributeOptionsTable extends Table class ProductCategoryAttributeOptionsTable extends Table {
{
/** /**
* Initialize method * Initialize method
* *
* @param array<string, mixed> $config The configuration for the Table. * @param array<string, mixed> $config The configuration for the Table.
* @return void * @return void
*/ */
public function initialize(array $config): void public function initialize(array $config): void {
{
parent::initialize($config); parent::initialize($config);
$this->setTable('product_category_attribute_options'); $this->setTable('product_category_attribute_options');
@@ -51,7 +43,7 @@ class ProductCategoryAttributeOptionsTable extends Table
$this->setPrimaryKey('id'); $this->setPrimaryKey('id');
$this->setEntityClass( $this->setEntityClass(
Configure::read('CakeProducts.ProductCategoryAttributeOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryAttributeOption') Configure::read('CakeProducts.ProductCategoryAttributeOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryAttributeOption'),
); );
$this->belongsTo('ProductCategoryAttributes', [ $this->belongsTo('ProductCategoryAttributes', [
@@ -66,11 +58,10 @@ class ProductCategoryAttributeOptionsTable extends Table
/** /**
* Default validation rules. * Default validation rules.
* *
* @param Validator $validator Validator instance. * @param \Cake\Validation\Validator $validator Validator instance.
* @return Validator * @return \Cake\Validation\Validator
*/ */
public function validationDefault(Validator $validator): Validator public function validationDefault(Validator $validator): Validator {
{
$validator $validator
->uuid('product_category_attribute_id') ->uuid('product_category_attribute_id')
->notEmptyString('product_category_attribute_id'); ->notEmptyString('product_category_attribute_id');
@@ -102,14 +93,14 @@ class ProductCategoryAttributeOptionsTable extends Table
* Returns a rules checker object that will be used for validating * Returns a rules checker object that will be used for validating
* application integrity. * application integrity.
* *
* @param RulesChecker $rules The rules object to be modified. * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return RulesChecker * @return \Cake\ORM\RulesChecker
*/ */
public function buildRules(RulesChecker $rules): RulesChecker public function buildRules(RulesChecker $rules): RulesChecker {
{
$rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']); $rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']);
$rules->add($rules->isUnique(['attribute_value', 'product_category_attribute_id'])); $rules->add($rules->isUnique(['attribute_value', 'product_category_attribute_id']));
return $rules; return $rules;
} }
} }
@@ -5,47 +5,40 @@ namespace CakeProducts\Model\Table;
use Cake\Core\Configure; use Cake\Core\Configure;
use Cake\Database\Type\EnumType; use Cake\Database\Type\EnumType;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Query\SelectQuery; use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker; use Cake\ORM\RulesChecker;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\Validation\Validator; use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductCategoryAttribute;
use CakeProducts\Model\Enum\ProductCategoryAttributeTypeId; use CakeProducts\Model\Enum\ProductCategoryAttributeTypeId;
use Closure;
use Psr\SimpleCache\CacheInterface;
/** /**
* ProductCategoryAttributes Model * ProductCategoryAttributes Model
* *
* @property ProductCategoriesTable&BelongsTo $ProductCategories * @property ProductCategoriesTable&\Cake\ORM\Association\BelongsTo $ProductCategories
* *
* @method ProductCategoryAttribute newEmptyEntity() * @method \CakeProducts\Model\Entity\ProductCategoryAttribute newEmptyEntity()
* @method ProductCategoryAttribute newEntity(array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryAttribute newEntity(array $data, array $options = [])
* @method array<ProductCategoryAttribute> newEntities(array $data, array $options = []) * @method array<\CakeProducts\Model\Entity\ProductCategoryAttribute> newEntities(array $data, array $options = [])
* @method ProductCategoryAttribute get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args) * @method \CakeProducts\Model\Entity\ProductCategoryAttribute get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductCategoryAttribute findOrCreate($search, ?callable $callback = null, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryAttribute findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductCategoryAttribute patchEntity(EntityInterface $entity, array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryAttribute patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method array<ProductCategoryAttribute> patchEntities(iterable $entities, array $data, array $options = []) * @method array<\CakeProducts\Model\Entity\ProductCategoryAttribute> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductCategoryAttribute|false save(EntityInterface $entity, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryAttribute|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method ProductCategoryAttribute saveOrFail(EntityInterface $entity, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryAttribute saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method iterable<ProductCategoryAttribute>|ResultSetInterface<ProductCategoryAttribute>|false saveMany(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductCategoryAttribute>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategoryAttribute>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryAttribute>|ResultSetInterface<ProductCategoryAttribute> saveManyOrFail(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductCategoryAttribute>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategoryAttribute> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductCategoryAttribute>|ResultSetInterface<ProductCategoryAttribute>|false deleteMany(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductCategoryAttribute>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategoryAttribute>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryAttribute>|ResultSetInterface<ProductCategoryAttribute> deleteManyOrFail(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductCategoryAttribute>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategoryAttribute> deleteManyOrFail(iterable $entities, array $options = [])
*/ */
class ProductCategoryAttributesTable extends Table class ProductCategoryAttributesTable extends Table {
{
/** /**
* Initialize method * Initialize method
* *
* @param array<string, mixed> $config The configuration for the Table. * @param array<string, mixed> $config The configuration for the Table.
* @return void * @return void
*/ */
public function initialize(array $config): void public function initialize(array $config): void {
{
parent::initialize($config); parent::initialize($config);
$this->setTable('product_category_attributes'); $this->setTable('product_category_attributes');
@@ -53,7 +46,7 @@ class ProductCategoryAttributesTable extends Table
$this->setPrimaryKey('id'); $this->setPrimaryKey('id');
$this->setEntityClass( $this->setEntityClass(
Configure::read('CakeProducts.ProductCategoryAttributes.entity', 'CakeProducts\Model\Entity\ProductCategoryAttribute') Configure::read('CakeProducts.ProductCategoryAttributes.entity', 'CakeProducts\Model\Entity\ProductCategoryAttribute'),
); );
$this->belongsTo('ProductCategories', [ $this->belongsTo('ProductCategories', [
'foreignKey' => 'product_category_id', 'foreignKey' => 'product_category_id',
@@ -76,11 +69,10 @@ class ProductCategoryAttributesTable extends Table
/** /**
* Default validation rules. * Default validation rules.
* *
* @param Validator $validator Validator instance. * @param \Cake\Validation\Validator $validator Validator instance.
* @return Validator * @return \Cake\Validation\Validator
*/ */
public function validationDefault(Validator $validator): Validator public function validationDefault(Validator $validator): Validator {
{
$validator $validator
->scalar('name') ->scalar('name')
->maxLength('name', 255) ->maxLength('name', 255)
@@ -112,11 +104,10 @@ class ProductCategoryAttributesTable extends Table
* Returns a rules checker object that will be used for validating * Returns a rules checker object that will be used for validating
* application integrity. * application integrity.
* *
* @param RulesChecker $rules The rules object to be modified. * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return RulesChecker * @return \Cake\ORM\RulesChecker
*/ */
public function buildRules(RulesChecker $rules): RulesChecker public function buildRules(RulesChecker $rules): RulesChecker {
{
$rules->add($rules->isUnique(['name', 'product_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'name']); $rules->add($rules->isUnique(['name', 'product_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'name']);
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']); $rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
@@ -124,13 +115,12 @@ class ProductCategoryAttributesTable extends Table
} }
/** /**
* @param SelectQuery $query * @param \Cake\ORM\Query\SelectQuery $query
* @param string $internalCategoryId * @param string $internalCategoryId
* *
* @return array|\Cake\ORM\Query|SelectQuery * @return \Cake\ORM\Query|\Cake\ORM\Query\SelectQuery|array
*/ */
public function findAllCategoryAttributesForCategoryId(SelectQuery $query, string $internalCategoryId) public function findAllCategoryAttributesForCategoryId(SelectQuery $query, string $internalCategoryId) {
{
$category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail(); $category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail();
$this->ProductCategories->behaviors()->get('Tree')->setConfig([ $this->ProductCategories->behaviors()->get('Tree')->setConfig([
@@ -143,8 +133,13 @@ class ProductCategoryAttributesTable extends Table
->find('path', for: $category->id) ->find('path', for: $category->id)
->contain(['ProductCategoryAttributes', 'ProductCategoryAttributes.ProductCategoryAttributeOptions']); ->contain(['ProductCategoryAttributes', 'ProductCategoryAttributes.ProductCategoryAttributeOptions']);
} }
public function getAllCategoryAttributesForCategoryId(string $internalCategoryId)
{ /**
return $this->find('allCategoryAttributesForCategoryId', $internalCategoryId)->toArray(); * @param string $internalCategoryId
* @return \Cake\Datasource\EntityInterface[]|array[]
*/
public function getAllCategoryAttributesForCategoryId(string $internalCategoryId) {
return $this->find('allCategoryAttributesForCategoryId', internalCategoryId: $internalCategoryId)->toArray();
} }
} }
@@ -4,50 +4,40 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table; namespace CakeProducts\Model\Table;
use Cake\Core\Configure; use Cake\Core\Configure;
use CakeProducts\Model\Entity\ProductCategoryVariantOption;
use CakeProducts\Model\Table\ProductCategoryVariantsTable;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Behavior\TimestampBehavior;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker; use Cake\ORM\RulesChecker;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\Validation\Validator; use Cake\Validation\Validator;
use Closure;
use Psr\SimpleCache\CacheInterface;
/** /**
* ProductCategoryVariantOptions Model * ProductCategoryVariantOptions Model
* *
* @property ProductCategoryVariantsTable&BelongsTo $ProductCategoryVariants * @property ProductCategoryVariantsTable&\Cake\ORM\Association\BelongsTo $ProductCategoryVariants
* *
* @method ProductCategoryVariantOption newEmptyEntity() * @method \CakeProducts\Model\Entity\ProductCategoryVariantOption newEmptyEntity()
* @method ProductCategoryVariantOption newEntity(array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryVariantOption newEntity(array $data, array $options = [])
* @method array<ProductCategoryVariantOption> newEntities(array $data, array $options = []) * @method array<\CakeProducts\Model\Entity\ProductCategoryVariantOption> newEntities(array $data, array $options = [])
* @method ProductCategoryVariantOption get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args) * @method \CakeProducts\Model\Entity\ProductCategoryVariantOption get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductCategoryVariantOption findOrCreate($search, ?callable $callback = null, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryVariantOption findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductCategoryVariantOption patchEntity(EntityInterface $entity, array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryVariantOption patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method array<ProductCategoryVariantOption> patchEntities(iterable $entities, array $data, array $options = []) * @method array<\CakeProducts\Model\Entity\ProductCategoryVariantOption> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductCategoryVariantOption|false save(EntityInterface $entity, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryVariantOption|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method ProductCategoryVariantOption saveOrFail(EntityInterface $entity, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryVariantOption saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method iterable<ProductCategoryVariantOption>|ResultSetInterface<ProductCategoryVariantOption>|false saveMany(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductCategoryVariantOption>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategoryVariantOption>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryVariantOption>|ResultSetInterface<ProductCategoryVariantOption> saveManyOrFail(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductCategoryVariantOption>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategoryVariantOption> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductCategoryVariantOption>|ResultSetInterface<ProductCategoryVariantOption>|false deleteMany(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductCategoryVariantOption>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategoryVariantOption>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryVariantOption>|ResultSetInterface<ProductCategoryVariantOption> deleteManyOrFail(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductCategoryVariantOption>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategoryVariantOption> deleteManyOrFail(iterable $entities, array $options = [])
* *
* @mixin TimestampBehavior * @mixin \Cake\ORM\Behavior\TimestampBehavior
*/ */
class ProductCategoryVariantOptionsTable extends Table class ProductCategoryVariantOptionsTable extends Table {
{
/** /**
* Initialize method * Initialize method
* *
* @param array<string, mixed> $config The configuration for the Table. * @param array<string, mixed> $config The configuration for the Table.
* @return void * @return void
*/ */
public function initialize(array $config): void public function initialize(array $config): void {
{
parent::initialize($config); parent::initialize($config);
$this->setTable('product_category_variant_options'); $this->setTable('product_category_variant_options');
@@ -55,11 +45,12 @@ class ProductCategoryVariantOptionsTable extends Table
$this->setPrimaryKey('id'); $this->setPrimaryKey('id');
$this->setEntityClass( $this->setEntityClass(
Configure::read('CakeProducts.ProductCategoryVariantOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryVariantOption') Configure::read('CakeProducts.ProductCategoryVariantOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryVariantOption'),
); );
$this->addBehavior('Timestamp'); $this->addBehavior('Timestamp');
$this->belongsTo('ProductCategoryVariants', [ $this->belongsTo('ProductCategoryVariants', [
'className' => 'CakeProducts.ProductCategoryVariants',
'foreignKey' => 'product_category_variant_id', 'foreignKey' => 'product_category_variant_id',
'joinType' => 'INNER', 'joinType' => 'INNER',
]); ]);
@@ -68,11 +59,10 @@ class ProductCategoryVariantOptionsTable extends Table
/** /**
* Default validation rules. * Default validation rules.
* *
* @param Validator $validator Validator instance. * @param \Cake\Validation\Validator $validator Validator instance.
* @return Validator * @return \Cake\Validation\Validator
*/ */
public function validationDefault(Validator $validator): Validator public function validationDefault(Validator $validator): Validator {
{
$validator $validator
->uuid('product_category_variant_id') ->uuid('product_category_variant_id')
->notEmptyString('product_category_variant_id'); ->notEmptyString('product_category_variant_id');
@@ -99,14 +89,14 @@ class ProductCategoryVariantOptionsTable extends Table
* Returns a rules checker object that will be used for validating * Returns a rules checker object that will be used for validating
* application integrity. * application integrity.
* *
* @param RulesChecker $rules The rules object to be modified. * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return RulesChecker * @return \Cake\ORM\RulesChecker
*/ */
public function buildRules(RulesChecker $rules): RulesChecker public function buildRules(RulesChecker $rules): RulesChecker {
{
$rules->add($rules->existsIn(['product_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']); $rules->add($rules->existsIn(['product_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']);
$rules->add($rules->isUnique(['variant_value', 'product_category_variant_id'])); $rules->add($rules->isUnique(['variant_value', 'product_category_variant_id']));
return $rules; return $rules;
} }
} }
@@ -4,48 +4,41 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table; namespace CakeProducts\Model\Table;
use Cake\Core\Configure; use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Query;
use Cake\ORM\Query\SelectQuery; use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker; use Cake\ORM\RulesChecker;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\Validation\Validator; use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductCategoryVariant;
use Closure;
use Psr\SimpleCache\CacheInterface;
/** /**
* ProductCategoryVariants Model * ProductCategoryVariants Model
* *
* @property ProductCategoriesTable&BelongsTo $ProductCategories * @property ProductCategoriesTable&\Cake\ORM\Association\BelongsTo $ProductCategories
* @property ProductsTable&BelongsTo $Products * @property ProductsTable&\Cake\ORM\Association\BelongsTo $Products
* *
* @method ProductCategoryVariant newEmptyEntity() * @method \CakeProducts\Model\Entity\ProductCategoryVariant newEmptyEntity()
* @method ProductCategoryVariant newEntity(array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryVariant newEntity(array $data, array $options = [])
* @method array<ProductCategoryVariant> newEntities(array $data, array $options = []) * @method array<\CakeProducts\Model\Entity\ProductCategoryVariant> newEntities(array $data, array $options = [])
* @method ProductCategoryVariant get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args) * @method \CakeProducts\Model\Entity\ProductCategoryVariant get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductCategoryVariant findOrCreate($search, ?callable $callback = null, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryVariant findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductCategoryVariant patchEntity(EntityInterface $entity, array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryVariant patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method array<ProductCategoryVariant> patchEntities(iterable $entities, array $data, array $options = []) * @method array<\CakeProducts\Model\Entity\ProductCategoryVariant> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductCategoryVariant|false save(EntityInterface $entity, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryVariant|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method ProductCategoryVariant saveOrFail(EntityInterface $entity, array $options = []) * @method \CakeProducts\Model\Entity\ProductCategoryVariant saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method iterable<ProductCategoryVariant>|ResultSetInterface<ProductCategoryVariant>|false saveMany(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductCategoryVariant>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategoryVariant>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryVariant>|ResultSetInterface<ProductCategoryVariant> saveManyOrFail(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductCategoryVariant>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategoryVariant> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductCategoryVariant>|ResultSetInterface<ProductCategoryVariant>|false deleteMany(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductCategoryVariant>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategoryVariant>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryVariant>|ResultSetInterface<ProductCategoryVariant> deleteManyOrFail(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductCategoryVariant>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategoryVariant> deleteManyOrFail(iterable $entities, array $options = [])
* / * /
class ProductCategoryVariantsTable extends Table */
{ class ProductCategoryVariantsTable extends Table {
/** /**
* Initialize method * Initialize method
* *
* @param array<string, mixed> $config The configuration for the Table. * @param array<string, mixed> $config The configuration for the Table.
* @return void * @return void
*/ */
public function initialize(array $config): void public function initialize(array $config): void {
{
parent::initialize($config); parent::initialize($config);
$this->setTable('product_category_variants'); $this->setTable('product_category_variants');
@@ -53,7 +46,7 @@ class ProductCategoryVariantsTable extends Table
$this->setPrimaryKey('id'); $this->setPrimaryKey('id');
$this->setEntityClass( $this->setEntityClass(
Configure::read('CakeProducts.ProductCategoryVariants.entity', 'CakeProducts\Model\Entity\ProductCategoryVariant') Configure::read('CakeProducts.ProductCategoryVariants.entity', 'CakeProducts\Model\Entity\ProductCategoryVariant'),
); );
$this->belongsTo('ProductCategories', [ $this->belongsTo('ProductCategories', [
@@ -84,11 +77,10 @@ class ProductCategoryVariantsTable extends Table
/** /**
* Default validation rules. * Default validation rules.
* *
* @param Validator $validator Validator instance. * @param \Cake\Validation\Validator $validator Validator instance.
* @return Validator * @return \Cake\Validation\Validator
*/ */
public function validationDefault(Validator $validator): Validator public function validationDefault(Validator $validator): Validator {
{
$validator $validator
->scalar('name') ->scalar('name')
->maxLength('name', 255) ->maxLength('name', 255)
@@ -119,11 +111,10 @@ class ProductCategoryVariantsTable extends Table
* Returns a rules checker object that will be used for validating * Returns a rules checker object that will be used for validating
* application integrity. * application integrity.
* *
* @param RulesChecker $rules The rules object to be modified. * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return RulesChecker * @return \Cake\ORM\RulesChecker
*/ */
public function buildRules(RulesChecker $rules): RulesChecker public function buildRules(RulesChecker $rules): RulesChecker {
{
$rules->add($rules->isUnique(['name', 'product_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_category_id']); $rules->add($rules->isUnique(['name', 'product_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_category_id']);
$rules->add($rules->isUnique(['name', 'product_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_id']); $rules->add($rules->isUnique(['name', 'product_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_id']);
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']); $rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
@@ -133,13 +124,12 @@ class ProductCategoryVariantsTable extends Table
} }
/** /**
* @param SelectQuery $query * @param \Cake\ORM\Query\SelectQuery $query
* @param string $internalCategoryId * @param string $internalCategoryId
* *
* @return array|Query|SelectQuery * @return \Cake\ORM\Query\SelectQuery
*/ */
public function findAllCategoryVariantsForCategoryId(SelectQuery $query, string $internalCategoryId) public function findAllCategoryVariantsForCategoryId(SelectQuery $query, string $internalCategoryId): SelectQuery {
{
$category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail(); $category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail();
$this->ProductCategories->behaviors()->get('Tree')->setConfig([ $this->ProductCategories->behaviors()->get('Tree')->setConfig([
@@ -155,10 +145,11 @@ class ProductCategoryVariantsTable extends Table
/** /**
* @param string $internalCategoryId * @param string $internalCategoryId
*
* @return array * @return array
*/ */
public function getAllCategoryVariantsForCategoryId(string $internalCategoryId) public function getAllCategoryVariantsForCategoryId(string $internalCategoryId): array {
{ return $this->find('allCategoryVariantsForCategoryId', internalCategoryId: $internalCategoryId)->toArray();
return $this->find('allCategoryVariantsForCategoryId', $internalCategoryId)->toArray();
} }
} }
+27 -36
View File
@@ -4,49 +4,41 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table; namespace CakeProducts\Model\Table;
use Cake\Core\Configure; use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Behavior\TimestampBehavior;
use Cake\ORM\RulesChecker; use Cake\ORM\RulesChecker;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\Validation\Validator; use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductPhoto;
use Closure;
use Psr\SimpleCache\CacheInterface;
/** /**
* ProductPhotos Model * ProductPhotos Model
* *
* @property ProductsTable&BelongsTo $Products * @property ProductsTable&\Cake\ORM\Association\BelongsTo $Products
* @property ProductSkusTable&BelongsTo $ProductSkus * @property ProductSkusTable&\Cake\ORM\Association\BelongsTo $ProductSkus
* *
* @method ProductPhoto newEmptyEntity() * @method \CakeProducts\Model\Entity\ProductPhoto newEmptyEntity()
* @method ProductPhoto newEntity(array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductPhoto newEntity(array $data, array $options = [])
* @method array<ProductPhoto> newEntities(array $data, array $options = []) * @method array<\CakeProducts\Model\Entity\ProductPhoto> newEntities(array $data, array $options = [])
* @method ProductPhoto get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args) * @method \CakeProducts\Model\Entity\ProductPhoto get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductPhoto findOrCreate($search, ?callable $callback = null, array $options = []) * @method \CakeProducts\Model\Entity\ProductPhoto findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductPhoto patchEntity(EntityInterface $entity, array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductPhoto patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method array<ProductPhoto> patchEntities(iterable $entities, array $data, array $options = []) * @method array<\CakeProducts\Model\Entity\ProductPhoto> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductPhoto|false save(EntityInterface $entity, array $options = []) * @method \CakeProducts\Model\Entity\ProductPhoto|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method ProductPhoto saveOrFail(EntityInterface $entity, array $options = []) * @method \CakeProducts\Model\Entity\ProductPhoto saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method iterable<ProductPhoto>|ResultSetInterface<ProductPhoto>|false saveMany(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductPhoto>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductPhoto>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductPhoto>|ResultSetInterface<ProductPhoto> saveManyOrFail(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductPhoto>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductPhoto> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductPhoto>|ResultSetInterface<ProductPhoto>|false deleteMany(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductPhoto>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductPhoto>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductPhoto>|ResultSetInterface<ProductPhoto> deleteManyOrFail(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductPhoto>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductPhoto> deleteManyOrFail(iterable $entities, array $options = [])
* *
* @mixin TimestampBehavior * @mixin \Cake\ORM\Behavior\TimestampBehavior
*/ */
class ProductPhotosTable extends Table class ProductPhotosTable extends Table {
{
/** /**
* Initialize method * Initialize method
* *
* @param array<string, mixed> $config The configuration for the Table. * @param array<string, mixed> $config The configuration for the Table.
* @return void * @return void
*/ */
public function initialize(array $config): void public function initialize(array $config): void {
{
parent::initialize($config); parent::initialize($config);
$this->setTable('product_photos'); $this->setTable('product_photos');
@@ -54,7 +46,7 @@ class ProductPhotosTable extends Table
$this->setPrimaryKey('id'); $this->setPrimaryKey('id');
$this->setEntityClass( $this->setEntityClass(
Configure::read('CakeProducts.ProductPhotos.entity', 'CakeProducts\Model\Entity\ProductPhoto') Configure::read('CakeProducts.ProductPhotos.entity', 'CakeProducts\Model\Entity\ProductPhoto'),
); );
$this->addBehavior('Timestamp'); $this->addBehavior('Timestamp');
@@ -105,11 +97,10 @@ class ProductPhotosTable extends Table
/** /**
* Default validation rules. * Default validation rules.
* *
* @param Validator $validator Validator instance. * @param \Cake\Validation\Validator $validator Validator instance.
* @return Validator * @return \Cake\Validation\Validator
*/ */
public function validationDefault(Validator $validator): Validator public function validationDefault(Validator $validator): Validator {
{
$validator $validator
->uuid('product_id') ->uuid('product_id')
->allowEmptyString('product_id'); ->allowEmptyString('product_id');
@@ -158,15 +149,15 @@ class ProductPhotosTable extends Table
* Returns a rules checker object that will be used for validating * Returns a rules checker object that will be used for validating
* application integrity. * application integrity.
* *
* @param RulesChecker $rules The rules object to be modified. * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return RulesChecker * @return \Cake\ORM\RulesChecker
*/ */
public function buildRules(RulesChecker $rules): RulesChecker public function buildRules(RulesChecker $rules): RulesChecker {
{
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']); $rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
$rules->add($rules->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']); $rules->add($rules->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']);
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']); $rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
return $rules; return $rules;
} }
} }
@@ -3,48 +3,40 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table; namespace CakeProducts\Model\Table;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker; use Cake\ORM\RulesChecker;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\Validation\Validator; use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductSkuVariantValue;
use Closure;
use Psr\SimpleCache\CacheInterface;
/** /**
* ProductSkuVariantValues Model * ProductSkuVariantValues Model
* *
* @property ProductSkusTable&BelongsTo $ProductSkus * @property ProductSkusTable&\Cake\ORM\Association\BelongsTo $ProductSkus
* @property ProductCategoryVariantsTable&BelongsTo $ProductCategoryVariants * @property ProductCategoryVariantsTable&\Cake\ORM\Association\BelongsTo $ProductCategoryVariants
* @property ProductCategoryVariantOptionsTable&BelongsTo $ProductCategoryVariantOptions * @property ProductCategoryVariantOptionsTable&\Cake\ORM\Association\BelongsTo $ProductCategoryVariantOptions
* *
* @method ProductSkuVariantValue newEmptyEntity() * @method \CakeProducts\Model\Entity\ProductSkuVariantValue newEmptyEntity()
* @method ProductSkuVariantValue newEntity(array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductSkuVariantValue newEntity(array $data, array $options = [])
* @method array<ProductSkuVariantValue> newEntities(array $data, array $options = []) * @method array<\CakeProducts\Model\Entity\ProductSkuVariantValue> newEntities(array $data, array $options = [])
* @method ProductSkuVariantValue get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args) * @method \CakeProducts\Model\Entity\ProductSkuVariantValue get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductSkuVariantValue findOrCreate($search, ?callable $callback = null, array $options = []) * @method \CakeProducts\Model\Entity\ProductSkuVariantValue findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductSkuVariantValue patchEntity(EntityInterface $entity, array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductSkuVariantValue patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method array<ProductSkuVariantValue> patchEntities(iterable $entities, array $data, array $options = []) * @method array<\CakeProducts\Model\Entity\ProductSkuVariantValue> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductSkuVariantValue|false save(EntityInterface $entity, array $options = []) * @method \CakeProducts\Model\Entity\ProductSkuVariantValue|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method ProductSkuVariantValue saveOrFail(EntityInterface $entity, array $options = []) * @method \CakeProducts\Model\Entity\ProductSkuVariantValue saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method iterable<ProductSkuVariantValue>|ResultSetInterface<ProductSkuVariantValue>|false saveMany(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductSkuVariantValue>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductSkuVariantValue>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductSkuVariantValue>|ResultSetInterface<ProductSkuVariantValue> saveManyOrFail(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductSkuVariantValue>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductSkuVariantValue> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductSkuVariantValue>|ResultSetInterface<ProductSkuVariantValue>|false deleteMany(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductSkuVariantValue>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductSkuVariantValue>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductSkuVariantValue>|ResultSetInterface<ProductSkuVariantValue> deleteManyOrFail(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductSkuVariantValue>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductSkuVariantValue> deleteManyOrFail(iterable $entities, array $options = [])
*/ */
class ProductSkuVariantValuesTable extends Table class ProductSkuVariantValuesTable extends Table {
{
/** /**
* Initialize method * Initialize method
* *
* @param array<string, mixed> $config The configuration for the Table. * @param array<string, mixed> $config The configuration for the Table.
* @return void * @return void
*/ */
public function initialize(array $config): void public function initialize(array $config): void {
{
parent::initialize($config); parent::initialize($config);
$this->setTable('product_sku_variant_values'); $this->setTable('product_sku_variant_values');
@@ -72,11 +64,10 @@ class ProductSkuVariantValuesTable extends Table
/** /**
* Default validation rules. * Default validation rules.
* *
* @param Validator $validator Validator instance. * @param \Cake\Validation\Validator $validator Validator instance.
* @return Validator * @return \Cake\Validation\Validator
*/ */
public function validationDefault(Validator $validator): Validator public function validationDefault(Validator $validator): Validator {
{
$validator $validator
->uuid('product_sku_id') ->uuid('product_sku_id')
->notEmptyString('product_sku_id'); ->notEmptyString('product_sku_id');
@@ -96,11 +87,10 @@ class ProductSkuVariantValuesTable extends Table
* Returns a rules checker object that will be used for validating * Returns a rules checker object that will be used for validating
* application integrity. * application integrity.
* *
* @param RulesChecker $rules The rules object to be modified. * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return RulesChecker * @return \Cake\ORM\RulesChecker
*/ */
public function buildRules(RulesChecker $rules): RulesChecker public function buildRules(RulesChecker $rules): RulesChecker {
{
$rules->add($rules->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']); $rules->add($rules->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']);
// @TODO why not working?? causing tests to fail / associated variant values not saving on product-skus/add // @TODO why not working?? causing tests to fail / associated variant values not saving on product-skus/add
@@ -109,4 +99,5 @@ class ProductSkuVariantValuesTable extends Table
return $rules; return $rules;
} }
} }
+26 -37
View File
@@ -4,50 +4,40 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table; namespace CakeProducts\Model\Table;
use Cake\Core\Configure; use Cake\Core\Configure;
use Cake\ORM\Query\SelectQuery;
use CakeProducts\Model\Table\ProductsTable;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Behavior\TimestampBehavior;
use Cake\ORM\RulesChecker; use Cake\ORM\RulesChecker;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\Validation\Validator; use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductSku;
use Closure;
use Psr\SimpleCache\CacheInterface;
/** /**
* ProductSkus Model * ProductSkus Model
* *
* @property ProductsTable&BelongsTo $Products * @property ProductsTable&\Cake\ORM\Association\BelongsTo $Products
* *
* @method ProductSku newEmptyEntity() * @method \CakeProducts\Model\Entity\ProductSku newEmptyEntity()
* @method ProductSku newEntity(array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductSku newEntity(array $data, array $options = [])
* @method array<ProductSku> newEntities(array $data, array $options = []) * @method array<\CakeProducts\Model\Entity\ProductSku> newEntities(array $data, array $options = [])
* @method ProductSku get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args) * @method \CakeProducts\Model\Entity\ProductSku get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductSku findOrCreate($search, ?callable $callback = null, array $options = []) * @method \CakeProducts\Model\Entity\ProductSku findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductSku patchEntity(EntityInterface $entity, array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductSku patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method array<ProductSku> patchEntities(iterable $entities, array $data, array $options = []) * @method array<\CakeProducts\Model\Entity\ProductSku> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductSku|false save(EntityInterface $entity, array $options = []) * @method \CakeProducts\Model\Entity\ProductSku|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method ProductSku saveOrFail(EntityInterface $entity, array $options = []) * @method \CakeProducts\Model\Entity\ProductSku saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method iterable<ProductSku>|ResultSetInterface<ProductSku>|false saveMany(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductSku>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductSku>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductSku>|ResultSetInterface<ProductSku> saveManyOrFail(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductSku>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductSku> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductSku>|ResultSetInterface<ProductSku>|false deleteMany(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductSku>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductSku>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductSku>|ResultSetInterface<ProductSku> deleteManyOrFail(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductSku>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductSku> deleteManyOrFail(iterable $entities, array $options = [])
* *
* @mixin TimestampBehavior * @mixin \Cake\ORM\Behavior\TimestampBehavior
*/ */
class ProductSkusTable extends Table class ProductSkusTable extends Table {
{
/** /**
* Initialize method * Initialize method
* *
* @param array<string, mixed> $config The configuration for the Table. * @param array<string, mixed> $config The configuration for the Table.
* @return void * @return void
*/ */
public function initialize(array $config): void public function initialize(array $config): void {
{
parent::initialize($config); parent::initialize($config);
$this->setTable('product_skus'); $this->setTable('product_skus');
@@ -55,7 +45,7 @@ class ProductSkusTable extends Table
$this->setPrimaryKey('id'); $this->setPrimaryKey('id');
$this->setEntityClass( $this->setEntityClass(
Configure::read('CakeProducts.ProductSkus.entity', 'CakeProducts\Model\Entity\ProductSku') Configure::read('CakeProducts.ProductSkus.entity', 'CakeProducts\Model\Entity\ProductSku'),
); );
$this->addBehavior('Timestamp'); $this->addBehavior('Timestamp');
@@ -99,11 +89,10 @@ class ProductSkusTable extends Table
/** /**
* Default validation rules. * Default validation rules.
* *
* @param Validator $validator Validator instance. * @param \Cake\Validation\Validator $validator Validator instance.
* @return Validator * @return \Cake\Validation\Validator
*/ */
public function validationDefault(Validator $validator): Validator public function validationDefault(Validator $validator): Validator {
{
$validator $validator
->uuid('product_id') ->uuid('product_id')
->notEmptyString('product_id'); ->notEmptyString('product_id');
@@ -138,14 +127,14 @@ class ProductSkusTable extends Table
* Returns a rules checker object that will be used for validating * Returns a rules checker object that will be used for validating
* application integrity. * application integrity.
* *
* @param RulesChecker $rules The rules object to be modified. * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return RulesChecker * @return \Cake\ORM\RulesChecker
*/ */
public function buildRules(RulesChecker $rules): RulesChecker public function buildRules(RulesChecker $rules): RulesChecker {
{
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']); $rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
$rules->add($rules->isUnique(['sku'], 'SKU must be unique'), ['errorField' => 'sku']); $rules->add($rules->isUnique(['sku'], 'SKU must be unique'), ['errorField' => 'sku']);
return $rules; return $rules;
} }
} }
+25 -36
View File
@@ -3,49 +3,39 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table; namespace CakeProducts\Model\Table;
use CakeProducts\Model\Entity\ProductVariant;
use CakeProducts\Model\Table\ProductCategoryVariantsTable;
use CakeProducts\Model\Table\ProductsTable;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker; use Cake\ORM\RulesChecker;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\Validation\Validator; use Cake\Validation\Validator;
use Closure;
use Psr\SimpleCache\CacheInterface;
/** /**
* ProductVariants Model * ProductVariants Model
* *
* @property ProductCategoryVariantsTable&BelongsTo $ProductCategoryVariants * @property ProductCategoryVariantsTable&\Cake\ORM\Association\BelongsTo $ProductCategoryVariants
* @property ProductsTable&BelongsTo $Products * @property ProductsTable&\Cake\ORM\Association\BelongsTo $Products
* *
* @method ProductVariant newEmptyEntity() * @method \CakeProducts\Model\Entity\ProductVariant newEmptyEntity()
* @method ProductVariant newEntity(array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductVariant newEntity(array $data, array $options = [])
* @method array<ProductVariant> newEntities(array $data, array $options = []) * @method array<\CakeProducts\Model\Entity\ProductVariant> newEntities(array $data, array $options = [])
* @method ProductVariant get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args) * @method \CakeProducts\Model\Entity\ProductVariant get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductVariant findOrCreate($search, ?callable $callback = null, array $options = []) * @method \CakeProducts\Model\Entity\ProductVariant findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductVariant patchEntity(EntityInterface $entity, array $data, array $options = []) * @method \CakeProducts\Model\Entity\ProductVariant patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method array<ProductVariant> patchEntities(iterable $entities, array $data, array $options = []) * @method array<\CakeProducts\Model\Entity\ProductVariant> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductVariant|false save(EntityInterface $entity, array $options = []) * @method \CakeProducts\Model\Entity\ProductVariant|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method ProductVariant saveOrFail(EntityInterface $entity, array $options = []) * @method \CakeProducts\Model\Entity\ProductVariant saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method iterable<ProductVariant>|ResultSetInterface<ProductVariant>|false saveMany(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductVariant>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductVariant>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductVariant>|ResultSetInterface<ProductVariant> saveManyOrFail(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductVariant>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductVariant> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductVariant>|ResultSetInterface<ProductVariant>|false deleteMany(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductVariant>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductVariant>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductVariant>|ResultSetInterface<ProductVariant> deleteManyOrFail(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductVariant>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductVariant> deleteManyOrFail(iterable $entities, array $options = [])
*/ */
class ProductVariantsTable extends Table class ProductVariantsTable extends Table {
{
/** /**
* Initialize method * Initialize method
* *
* @param array<string, mixed> $config The configuration for the Table. * @param array<string, mixed> $config The configuration for the Table.
* @return void * @return void
*/ */
public function initialize(array $config): void public function initialize(array $config): void {
{
parent::initialize($config); parent::initialize($config);
$this->setTable('product_variants'); $this->setTable('product_variants');
@@ -73,11 +63,10 @@ class ProductVariantsTable extends Table
/** /**
* Default validation rules. * Default validation rules.
* *
* @param Validator $validator Validator instance. * @param \Cake\Validation\Validator $validator Validator instance.
* @return Validator * @return \Cake\Validation\Validator
*/ */
public function validationDefault(Validator $validator): Validator public function validationDefault(Validator $validator): Validator {
{
$validator $validator
->scalar('name') ->scalar('name')
->maxLength('name', 255) ->maxLength('name', 255)
@@ -104,14 +93,14 @@ class ProductVariantsTable extends Table
* Returns a rules checker object that will be used for validating * Returns a rules checker object that will be used for validating
* application integrity. * application integrity.
* *
* @param RulesChecker $rules The rules object to be modified. * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return RulesChecker * @return \Cake\ORM\RulesChecker
*/ */
public function buildRules(RulesChecker $rules): RulesChecker public function buildRules(RulesChecker $rules): RulesChecker {
{
$rules->add($rules->existsIn(['product_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']); $rules->add($rules->existsIn(['product_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']);
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']); $rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
return $rules; return $rules;
} }
} }
+25 -34
View File
@@ -5,47 +5,39 @@ namespace CakeProducts\Model\Table;
use Cake\Core\Configure; use Cake\Core\Configure;
use Cake\Database\Type\EnumType; use Cake\Database\Type\EnumType;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker; use Cake\ORM\RulesChecker;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\Validation\Validator; use Cake\Validation\Validator;
use CakeProducts\Model\Entity\Product;
use CakeProducts\Model\Enum\ProductProductTypeId; use CakeProducts\Model\Enum\ProductProductTypeId;
use Closure;
use Psr\SimpleCache\CacheInterface;
/** /**
* Products Model * Products Model
* *
* @property ProductCategoriesTable&BelongsTo $ProductCategories * @property ProductCategoriesTable&\Cake\ORM\Association\BelongsTo $ProductCategories
* *
* @method Product newEmptyEntity() * @method \CakeProducts\Model\Entity\Product newEmptyEntity()
* @method Product newEntity(array $data, array $options = []) * @method \CakeProducts\Model\Entity\Product newEntity(array $data, array $options = [])
* @method array<Product> newEntities(array $data, array $options = []) * @method array<\CakeProducts\Model\Entity\Product> newEntities(array $data, array $options = [])
* @method Product get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args) * @method \CakeProducts\Model\Entity\Product get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
* @method Product findOrCreate($search, ?callable $callback = null, array $options = []) * @method \CakeProducts\Model\Entity\Product findOrCreate($search, ?callable $callback = null, array $options = [])
* @method Product patchEntity(EntityInterface $entity, array $data, array $options = []) * @method \CakeProducts\Model\Entity\Product patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method array<Product> patchEntities(iterable $entities, array $data, array $options = []) * @method array<\CakeProducts\Model\Entity\Product> patchEntities(iterable $entities, array $data, array $options = [])
* @method Product|false save(EntityInterface $entity, array $options = []) * @method \CakeProducts\Model\Entity\Product|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method Product saveOrFail(EntityInterface $entity, array $options = []) * @method \CakeProducts\Model\Entity\Product saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method iterable<Product>|ResultSetInterface<Product>|false saveMany(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\Product>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\Product>|false saveMany(iterable $entities, array $options = [])
* @method iterable<Product>|ResultSetInterface<Product> saveManyOrFail(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\Product>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\Product> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<Product>|ResultSetInterface<Product>|false deleteMany(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\Product>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\Product>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<Product>|ResultSetInterface<Product> deleteManyOrFail(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\Product>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\Product> deleteManyOrFail(iterable $entities, array $options = [])
*/ */
class ProductsTable extends Table class ProductsTable extends Table {
{
/** /**
* Initialize method * Initialize method
* *
* @param array<string, mixed> $config The configuration for the Table. * @param array<string, mixed> $config The configuration for the Table.
* @return void * @return void
*/ */
public function initialize(array $config): void public function initialize(array $config): void {
{
parent::initialize($config); parent::initialize($config);
$this->setTable('products'); $this->setTable('products');
@@ -53,7 +45,7 @@ class ProductsTable extends Table
$this->setPrimaryKey('id'); $this->setPrimaryKey('id');
$this->setEntityClass( $this->setEntityClass(
Configure::read('CakeProducts.Products.entity', 'CakeProducts\Model\Entity\Product') Configure::read('CakeProducts.Products.entity', 'CakeProducts\Model\Entity\Product'),
); );
$this->belongsTo('ProductCategories', [ $this->belongsTo('ProductCategories', [
@@ -113,11 +105,10 @@ class ProductsTable extends Table
/** /**
* Default validation rules. * Default validation rules.
* *
* @param Validator $validator Validator instance. * @param \Cake\Validation\Validator $validator Validator instance.
* @return Validator * @return \Cake\Validation\Validator
*/ */
public function validationDefault(Validator $validator): Validator public function validationDefault(Validator $validator): Validator {
{
$validator $validator
->scalar('name') ->scalar('name')
->maxLength('name', 255) ->maxLength('name', 255)
@@ -144,15 +135,15 @@ class ProductsTable extends Table
* Returns a rules checker object that will be used for validating * Returns a rules checker object that will be used for validating
* application integrity. * application integrity.
* *
* @param RulesChecker $rules The rules object to be modified. * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return RulesChecker * @return \Cake\ORM\RulesChecker
*/ */
public function buildRules(RulesChecker $rules): RulesChecker public function buildRules(RulesChecker $rules): RulesChecker {
{
$rules->add($rules->isUnique(['product_category_id', 'name']), ['errorField' => 'product_category_id']); $rules->add($rules->isUnique(['product_category_id', 'name']), ['errorField' => 'product_category_id']);
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']); $rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
// $rules->add($rules->validCount('product_attributes', 0, '<=', 'You must not have any tags')); // $rules->add($rules->validCount('product_attributes', 0, '<=', 'You must not have any tags'));
return $rules; return $rules;
} }
} }
-31
View File
@@ -1,31 +0,0 @@
<?php
/**
* @var \App\View\AppView $this
* @var \Cake\Datasource\EntityInterface $externalProductCatalog
* @var \Cake\Collection\CollectionInterface|string[] $productCatalogs
*/
?>
<div class="row">
<aside class="column">
<div class="side-nav">
<h4 class="heading"><?= __('Actions') ?></h4>
<?= $this->Html->link(__('List External Product Catalogs'), ['action' => 'index'], ['class' => 'side-nav-item']) ?>
</div>
</aside>
<div class="column column-80">
<div class="externalProductCatalogs form content">
<?= $this->Form->create($externalProductCatalog) ?>
<fieldset>
<legend><?= __('Add External Product Catalog') ?></legend>
<?php
echo $this->Form->control('product_catalog_id', ['options' => $productCatalogs]);
echo $this->Form->control('base_url');
echo $this->Form->control('api_url');
echo $this->Form->control('enabled');
?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
</div>
</div>
</div>
@@ -1,36 +0,0 @@
<?php
/**
* @var \App\View\AppView $this
* @var \Cake\Datasource\EntityInterface $externalProductCatalog
* @var string[]|\Cake\Collection\CollectionInterface $productCatalogs
*/
?>
<div class="row">
<aside class="column">
<div class="side-nav">
<h4 class="heading"><?= __('Actions') ?></h4>
<?= $this->Form->postLink(
__('Delete'),
['action' => 'delete', $externalProductCatalog->id],
['confirm' => __('Are you sure you want to delete # {0}?', $externalProductCatalog->id), 'class' => 'side-nav-item']
) ?>
<?= $this->Html->link(__('List External Product Catalogs'), ['action' => 'index'], ['class' => 'side-nav-item']) ?>
</div>
</aside>
<div class="column column-80">
<div class="externalProductCatalogs form content">
<?= $this->Form->create($externalProductCatalog) ?>
<fieldset>
<legend><?= __('Edit External Product Catalog') ?></legend>
<?php
echo $this->Form->control('product_catalog_id', ['options' => $productCatalogs]);
echo $this->Form->control('base_url');
echo $this->Form->control('api_url');
echo $this->Form->control('enabled');
?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
</div>
</div>
</div>
@@ -1,52 +0,0 @@
<?php
/**
* @var \App\View\AppView $this
* @var iterable<\Cake\Datasource\EntityInterface> $externalProductCatalogs
*/
?>
<div class="externalProductCatalogs index content">
<?= $this->Html->link(__('New External Product Catalog'), ['action' => 'add'], ['class' => 'button float-right']) ?>
<h3><?= __('External Product Catalogs') ?></h3>
<div class="table-responsive">
<table>
<thead>
<tr>
<th><?= $this->Paginator->sort('product_catalog_id') ?></th>
<th><?= $this->Paginator->sort('base_url') ?></th>
<th><?= $this->Paginator->sort('api_url') ?></th>
<th><?= $this->Paginator->sort('created') ?></th>
<th><?= $this->Paginator->sort('deleted') ?></th>
<th><?= $this->Paginator->sort('enabled') ?></th>
<th class="actions"><?= __('Actions') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($externalProductCatalogs as $externalProductCatalog): ?>
<tr>
<td><?= $externalProductCatalog->hasValue('product_catalog') ? $this->Html->link($externalProductCatalog->product_catalog->name, ['controller' => 'ProductCatalogs', 'action' => 'view', $externalProductCatalog->product_catalog->id]) : '' ?></td>
<td><?= h($externalProductCatalog->base_url) ?></td>
<td><?= h($externalProductCatalog->api_url) ?></td>
<td><?= h($externalProductCatalog->created) ?></td>
<td><?= h($externalProductCatalog->deleted) ?></td>
<td><?= h($externalProductCatalog->enabled) ?></td>
<td class="actions">
<?= $this->Html->link(__('View'), ['action' => 'view', $externalProductCatalog->id]) ?>
<?= $this->Html->link(__('Edit'), ['action' => 'edit', $externalProductCatalog->id]) ?>
<?= $this->Form->postLink(__('Delete'), ['action' => 'delete', $externalProductCatalog->id], ['confirm' => __('Are you sure you want to delete # {0}?', $externalProductCatalog->id)]) ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<div class="paginator">
<ul class="pagination">
<?= $this->Paginator->first('<< ' . __('first')) ?>
<?= $this->Paginator->prev('< ' . __('previous')) ?>
<?= $this->Paginator->numbers() ?>
<?= $this->Paginator->next(__('next') . ' >') ?>
<?= $this->Paginator->last(__('last') . ' >>') ?>
</ul>
<p><?= $this->Paginator->counter(__('Page {{page}} of {{pages}}, showing {{current}} record(s) out of {{count}} total')) ?></p>
</div>
</div>
@@ -1,71 +0,0 @@
<?php
/**
* @var \App\View\AppView $this
* @var \App\Model\Entity\ExternalProductCatalog $externalProductCatalog
*/
?>
<div class="row">
<aside class="column">
<div class="side-nav">
<h4 class="heading"><?= __('Actions') ?></h4>
<?= $this->Html->link(__('Edit External Product Catalog'), ['action' => 'edit', $externalProductCatalog->id], ['class' => 'side-nav-item']) ?>
<?= $this->Form->postLink(__('Delete External Product Catalog'), ['action' => 'delete', $externalProductCatalog->id], ['confirm' => __('Are you sure you want to delete # {0}?', $externalProductCatalog->id), 'class' => 'side-nav-item']) ?>
<?= $this->Html->link(__('List External Product Catalogs'), ['action' => 'index'], ['class' => 'side-nav-item']) ?>
<?= $this->Html->link(__('New External Product Catalog'), ['action' => 'add'], ['class' => 'side-nav-item']) ?>
</div>
</aside>
<div class="column column-80">
<div class="externalProductCatalogs view content">
<h3><?= h($externalProductCatalog->base_url) ?></h3>
<table>
<tr>
<th><?= __('Base Url') ?></th>
<td><?= h($externalProductCatalog->base_url) ?></td>
</tr>
<tr>
<th><?= __('Api Url') ?></th>
<td><?= h($externalProductCatalog->api_url) ?></td>
</tr>
<tr>
<th><?= __('Id') ?></th>
<td><?= $this->Number->format($externalProductCatalog->id) ?></td>
</tr>
<tr>
<th><?= __('Created') ?></th>
<td><?= h($externalProductCatalog->created) ?></td>
</tr>
<tr>
<th><?= __('Deleted') ?></th>
<td><?= h($externalProductCatalog->deleted) ?></td>
</tr>
</table>
<div class="related">
<h4><?= __('Related Product Catalogs') ?></h4>
<?php if (!empty($externalProductCatalog->product_catalogs)) : ?>
<div class="table-responsive">
<table>
<tr>
<th><?= __('Name') ?></th>
<th><?= __('Catalog Description') ?></th>
<th><?= __('Enabled') ?></th>
<th class="actions"><?= __('Actions') ?></th>
</tr>
<?php foreach ($externalProductCatalog->product_catalogs as $productCatalog) : ?>
<tr>
<td><?= h($productCatalog->name) ?></td>
<td><?= h($productCatalog->catalog_description) ?></td>
<td><?= h($productCatalog->_joinData->enabled) ?></td>
<td class="actions">
<?= $this->Html->link(__('View'), ['controller' => 'ProductCatalogs', 'action' => 'view', $productCatalog->id]) ?>
<?= $this->Html->link(__('Edit'), ['controller' => 'ProductCatalogs', 'action' => 'edit', $productCatalog->id]) ?>
<?= $this->Form->postLink(__('Delete'), ['controller' => 'ProductCatalogs', 'action' => 'delete', $productCatalog->id], ['confirm' => __('Are you sure you want to delete # {0}?', $productCatalog->id)]) ?>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
@@ -1,8 +0,0 @@
<?php
/**
* @var \App\View\AppView $this
* @var \Cake\Collection\CollectionInterface|string[] $productCatalogs
*/
$this->setLayout('ajax');
echo $this->element('ExternalProductCatalogs/catalog_form'); ?>
-32
View File
@@ -58,38 +58,6 @@
</div> </div>
<?php endif; ?> <?php endif; ?>
</div> </div>
<div class="related">
<h4><?= __('External Product Catalog API\'s ') ?></h4>
<?php if (!empty($productCatalog->external_product_catalogs)) : ?>
<div class="table-responsive">
<table>
<tr>
<th><?= __('Name') ?></th>
<th><?= __('Category Description') ?></th>
<th><?= __('Enabled') ?></th>
<th class="actions"><?= __('Actions') ?></th>
</tr>
<?php foreach ($productCatalog->external_product_catalogs as $externalProductCatalog) : ?>
<?php
/**
* @var \CakeProducts\Model\Entity\ExternalProductCatalog $externalProductCatalog
*/
?>
<tr>
<td><?= h($externalProductCatalog->base_url) ?></td>
<td><?= h($externalProductCatalog->api_url) ?></td>
<td><?= h($externalProductCatalog->_joinData->enabled) ?></td>
<td class="actions">
<?= $this->Html->link(__('View'), ['controller' => 'ExternalProductCatalogs', 'action' => 'view', $externalProductCatalog->id]) ?>
<?= $this->Html->link(__('Edit'), ['controller' => 'ExternalProductCatalogs', 'action' => 'edit', $externalProductCatalog->id]) ?>
<?= $this->Form->postLink(__('Delete'), ['controller' => 'ExternalProductCatalogsProductCatalogs', 'action' => 'delete', $externalProductCatalog->_joinData->id], ['confirm' => __('Are you sure you want to delete # {0}?', $externalProductCatalog->id)]) ?>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php endif; ?>
</div>
</div> </div>
</div> </div>
</div> </div>
@@ -1,31 +0,0 @@
<?php
declare(strict_types=1);
namespace CakeProducts\Test\Fixture;
use Cake\TestSuite\Fixture\TestFixture;
/**
* ExternalProductCatalogsFixture
*/
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();
}
}
@@ -1,32 +0,0 @@
<?php
declare(strict_types=1);
namespace CakeProducts\Test\Fixture;
use Cake\TestSuite\Fixture\TestFixture;
/**
* ExternalProductCatalogsProductCatalogsFixture
*/
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();
}
}
+5 -7
View File
@@ -8,18 +8,16 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* ProductAttributesFixture * ProductAttributesFixture
*/ */
class ProductAttributesFixture extends TestFixture class ProductAttributesFixture extends TestFixture {
{
/** /**
* Init method * Init method
* *
* @return void * @return void
*/ */
public function init(): void public function init(): void {
{ $this->records = [];
$this->records = [
];
parent::init(); parent::init();
} }
} }
+4 -4
View File
@@ -8,15 +8,14 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* ProductCatalogsFixture * ProductCatalogsFixture
*/ */
class ProductCatalogsFixture extends TestFixture class ProductCatalogsFixture extends TestFixture {
{
/** /**
* Init method * Init method
* *
* @return void * @return void
*/ */
public function init(): void public function init(): void {
{
$this->records = [ $this->records = [
[ [
'id' => '115153f3-2f59-4234-8ff8-e1b205761428', 'id' => '115153f3-2f59-4234-8ff8-e1b205761428',
@@ -35,4 +34,5 @@ class ProductCatalogsFixture extends TestFixture
]; ];
parent::init(); parent::init();
} }
} }
+4 -4
View File
@@ -8,15 +8,14 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* ProductCategoriesFixture * ProductCategoriesFixture
*/ */
class ProductCategoriesFixture extends TestFixture class ProductCategoriesFixture extends TestFixture {
{
/** /**
* Init method * Init method
* *
* @return void * @return void
*/ */
public function init(): void public function init(): void {
{
$this->records = [ $this->records = [
[ [
'id' => 1, 'id' => 1,
@@ -105,4 +104,5 @@ class ProductCategoriesFixture extends TestFixture
]; ];
parent::init(); parent::init();
} }
} }
@@ -8,15 +8,14 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* ProductCategoryAttributeOptionsFixture * ProductCategoryAttributeOptionsFixture
*/ */
class ProductCategoryAttributeOptionsFixture extends TestFixture class ProductCategoryAttributeOptionsFixture extends TestFixture {
{
/** /**
* Init method * Init method
* *
* @return void * @return void
*/ */
public function init(): void public function init(): void {
{
$this->records = [ $this->records = [
[ [
'id' => 'e06f1723-2456-483a-b3c4-004603e032a8', 'id' => 'e06f1723-2456-483a-b3c4-004603e032a8',
@@ -41,8 +40,9 @@ class ProductCategoryAttributeOptionsFixture extends TestFixture
'attribute_label' => 'Green', 'attribute_label' => 'Green',
'enabled' => 1, 'enabled' => 1,
'deleted' => null, 'deleted' => null,
] ],
]; ];
parent::init(); parent::init();
} }
} }
@@ -8,15 +8,14 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* ProductCategoryAttributesFixture * ProductCategoryAttributesFixture
*/ */
class ProductCategoryAttributesFixture extends TestFixture class ProductCategoryAttributesFixture extends TestFixture {
{
/** /**
* Init method * Init method
* *
* @return void * @return void
*/ */
public function init(): void public function init(): void {
{
$this->records = [ $this->records = [
[ [
'id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c', 'id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
@@ -29,4 +28,5 @@ class ProductCategoryAttributesFixture extends TestFixture
]; ];
parent::init(); parent::init();
} }
} }
@@ -8,15 +8,14 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* ProductCategoryVariantsFixture * ProductCategoryVariantsFixture
*/ */
class ProductCategoryVariantOptionsFixture extends TestFixture class ProductCategoryVariantOptionsFixture extends TestFixture {
{
/** /**
* Init method * Init method
* *
* @return void * @return void
*/ */
public function init(): void public function init(): void {
{
$this->records = [ $this->records = [
[ [
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d23', 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d23',
@@ -37,7 +36,6 @@ class ProductCategoryVariantOptionsFixture extends TestFixture
'enabled' => 1, 'enabled' => 1,
], ],
[ [
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d21', 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d21',
'variant_value' => '12AWG', 'variant_value' => '12AWG',
@@ -96,4 +94,5 @@ class ProductCategoryVariantOptionsFixture extends TestFixture
]; ];
parent::init(); parent::init();
} }
} }
@@ -8,15 +8,14 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* ProductCategoryVariantsFixture * ProductCategoryVariantsFixture
*/ */
class ProductCategoryVariantsFixture extends TestFixture class ProductCategoryVariantsFixture extends TestFixture {
{
/** /**
* Init method * Init method
* *
* @return void * @return void
*/ */
public function init(): void public function init(): void {
{
$this->records = [ $this->records = [
[ [
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78111', 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78111',
@@ -50,4 +49,5 @@ class ProductCategoryVariantsFixture extends TestFixture
]; ];
parent::init(); parent::init();
} }
} }
+4 -4
View File
@@ -8,15 +8,14 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* ProductPhotosFixture * ProductPhotosFixture
*/ */
class ProductPhotosFixture extends TestFixture class ProductPhotosFixture extends TestFixture {
{
/** /**
* Init method * Init method
* *
* @return void * @return void
*/ */
public function init(): void public function init(): void {
{
$this->records = [ $this->records = [
[ [
'id' => '2c386086-f4c5-4093-bea5-ee9c29479f58', 'id' => '2c386086-f4c5-4093-bea5-ee9c29479f58',
@@ -120,4 +119,5 @@ class ProductPhotosFixture extends TestFixture
]; ];
parent::init(); parent::init();
} }
} }
@@ -8,8 +8,8 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* ProductSkuVariantValuesFixture * ProductSkuVariantValuesFixture
*/ */
class ProductSkuVariantValuesFixture extends TestFixture class ProductSkuVariantValuesFixture extends TestFixture {
{
/** /**
* Table name * Table name
* *
@@ -22,8 +22,7 @@ class ProductSkuVariantValuesFixture extends TestFixture
* *
* @return void * @return void
*/ */
public function init(): void public function init(): void {
{
$this->records = [ $this->records = [
[ [
'id' => '98b609d8-1d4f-484c-a13a-6adb7102da56', 'id' => '98b609d8-1d4f-484c-a13a-6adb7102da56',
@@ -34,4 +33,5 @@ class ProductSkuVariantValuesFixture extends TestFixture
]; ];
parent::init(); parent::init();
} }
} }
+5 -4
View File
@@ -8,21 +8,21 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* ProductSkusFixture * ProductSkusFixture
*/ */
class ProductSkusFixture extends TestFixture class ProductSkusFixture extends TestFixture {
{
/** /**
* Table name * Table name
* *
* @var string * @var string
*/ */
public string $table = 'product_skus'; public string $table = 'product_skus';
/** /**
* Init method * Init method
* *
* @return void * @return void
*/ */
public function init(): void public function init(): void {
{
$this->records = [ $this->records = [
[ [
'id' => '3a477e3e-7977-4813-81f6-f85949613979', 'id' => '3a477e3e-7977-4813-81f6-f85949613979',
@@ -38,4 +38,5 @@ class ProductSkusFixture extends TestFixture
]; ];
parent::init(); parent::init();
} }
} }
+5 -5
View File
@@ -8,15 +8,14 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* ProductVariantsFixture * ProductVariantsFixture
*/ */
class ProductVariantsFixture extends TestFixture class ProductVariantsFixture extends TestFixture {
{
/** /**
* Init method * Init method
* *
* @return void * @return void
*/ */
public function init(): void public function init(): void {
{
$this->records = [ $this->records = [
[ [
'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72568', 'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72568',
@@ -45,8 +44,9 @@ class ProductVariantsFixture extends TestFixture
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94', 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05318', 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05318',
'enabled' => 1, 'enabled' => 1,
] ],
]; ];
parent::init(); parent::init();
} }
} }
+4 -4
View File
@@ -8,15 +8,14 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* ProductsFixture * ProductsFixture
*/ */
class ProductsFixture extends TestFixture class ProductsFixture extends TestFixture {
{
/** /**
* Init method * Init method
* *
* @return void * @return void
*/ */
public function init(): void public function init(): void {
{
$this->records = [ $this->records = [
[ [
'id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', 'id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
@@ -35,4 +34,5 @@ class ProductsFixture extends TestFixture
]; ];
parent::init(); parent::init();
} }
} }
@@ -14,12 +14,11 @@ use RecursiveIteratorIterator;
* *
* Used to make logging in easier and to handle folder structure for product images * Used to make logging in easier and to handle folder structure for product images
*/ */
class BaseControllerTest extends TestCase class BaseControllerTest extends TestCase {
{
use IntegrationTestTrait; use IntegrationTestTrait;
public function loginUserByRole(string $role = 'admin'): void public function loginUserByRole(string $role = 'admin'): void {
{
$this->session(['Auth.User.id' => 1]); $this->session(['Auth.User.id' => 1]);
$this->session(['Auth.id' => 1]); $this->session(['Auth.id' => 1]);
} }
@@ -27,8 +26,7 @@ class BaseControllerTest extends TestCase
/** /**
* @return void * @return void
*/ */
public function testTest() public function testTest() {
{
$this->assertEquals(1, 1); $this->assertEquals(1, 1);
} }
@@ -37,12 +35,11 @@ class BaseControllerTest extends TestCase
* *
* @return void * @return void
*/ */
protected function setUp(): void protected function setUp(): void {
{
parent::setUp(); parent::setUp();
$toCopy = PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'webroot' . DS . 'images' . DS . '2c386086-f4c5-4093-bea5-ee9c29479f58.png'; $toCopy = PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'webroot' . DS . 'images' . DS . '2c386086-f4c5-4093-bea5-ee9c29479f58.png';
$productsFolder = PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'webroot' . DS . 'uploads' . DS . $productsFolder = PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'webroot' . DS . 'uploads' . DS
'images' . DS . 'products' . DS . 'cfc98a9a-29b2-44c8-b587-8156adc05317'; . 'images' . DS . 'products' . DS . 'cfc98a9a-29b2-44c8-b587-8156adc05317';
$newName = $productsFolder . DS . '2c386086-f4c5-4093-bea5-ee9c29479f58.png'; $newName = $productsFolder . DS . '2c386086-f4c5-4093-bea5-ee9c29479f58.png';
if (file_exists($toCopy)) { if (file_exists($toCopy)) {
if (!file_exists($productsFolder)) { if (!file_exists($productsFolder)) {
@@ -52,8 +49,7 @@ class BaseControllerTest extends TestCase
} }
} }
protected function tearDown(): void protected function tearDown(): void {
{
parent::tearDown(); // TODO: Change the autogenerated stub parent::tearDown(); // TODO: Change the autogenerated stub
$path = Configure::readOrFail('CakeProducts.photos.directory'); $path = Configure::readOrFail('CakeProducts.photos.directory');
@@ -65,4 +61,5 @@ class BaseControllerTest extends TestCase
} }
} }
} }
} }
@@ -1,335 +0,0 @@
<?php
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
{
/**
* Test subject table
*
* @var ExternalProductCatalogsTable|Table
*/
protected $ExternalProductCatalogs;
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeProducts.ExternalProductCatalogs',
'plugin.CakeProducts.ExternalProductCatalogsProductCatalogs',
'plugin.CakeProducts.ProductCatalogs',
];
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
// $this->enableCsrfToken();
// $this->enableSecurityToken();
$this->disableErrorHandlerMiddleware();
$this->ExternalProductCatalogs = $this->getTableLocator()->get('CakeProducts.ExternalProductCatalogs');
}
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->ExternalProductCatalogs);
parent::tearDown();
}
/**
* Test index method
*
* Tests the index action with a logged in user
*
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::index()
* @throws 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);
}
/**
* Test view method
*
* Tests the view action with a logged in user
*
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::view()
* @throws 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);
}
/**
* Test add method
*
* Tests the add action with a logged in user
*
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::add()
* @throws Exception
*
* @return void
*/
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);
$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
*
* @return void
*/
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');
$cntAfter = $this->ExternalProductCatalogs->find()->count();
$linksAfter = $linksTable->find()->count();
$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
*
* @return void
*/
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);
$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
*
* @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);
}
/**
* Test edit method
*
* Tests a PUT request to the edit action with a logged in user
*
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::edit()
* @throws 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);
$this->assertResponseCode(302);
$this->assertRedirectContains('external-product-catalogs');
$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
*
* @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);
// assert save failed below
}
/**
* Test delete method
*
* Tests the delete action with a logged in user
*
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::delete()
* @throws Exception
*
* @return void
*/
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');
$cntAfter = $this->ExternalProductCatalogs->find()->count();
$this->assertEquals($cntBefore - 1, $cntAfter);
}
}
@@ -1,121 +0,0 @@
<?php
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
{
/**
* Test subject table
*
* @var ExternalProductCatalogsProductCatalogsTable|Table
*/
protected $ExternalProductCatalogsProductCatalogs;
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeProducts.ExternalProductCatalogsProductCatalogs',
'plugin.CakeProducts.ExternalProductCatalogs',
'plugin.CakeProducts.ProductCatalogs',
];
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
// $this->enableCsrfToken();
// $this->enableSecurityToken();
$this->disableErrorHandlerMiddleware();
$this->ExternalProductCatalogsProductCatalogs = $this->getTableLocator()->get('CakeProducts.ExternalProductCatalogsProductCatalogs');
}
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->ExternalProductCatalogsProductCatalogs);
parent::tearDown();
}
/**
* Test add method
*
* Tests the add action with a logged in user
*
* @uses \CakeProducts\Controller\ExternalProductCatalogsProductCatalogsController::add()
* @throws Exception
*
* @return void
*/
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);
$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
*
* @return void
*/
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');
$cntAfterWithTrashed = $this->ExternalProductCatalogsProductCatalogs->find('withTrashed')->count();
$cntAfter = $this->ExternalProductCatalogsProductCatalogs->find()->count();
$this->assertEquals($cntBefore - 1, $cntAfter);
$this->assertEquals($cntBeforeWithTrashed, $cntAfterWithTrashed);
}
}
@@ -3,24 +3,20 @@ declare(strict_types=1);
namespace CakeProducts\Test\TestCase\Controller; namespace CakeProducts\Test\TestCase\Controller;
use Cake\ORM\Table;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
use CakeProducts\Controller\ProductCatalogsController; use CakeProducts\Controller\ProductCatalogsController;
use CakeProducts\Model\Table\ProductCatalogsTable; use CakeProducts\Model\Table\ProductCatalogsTable;
use PHPUnit\Exception;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
/** /**
* CakeProducts\Controller\ProductCatalogsController Test Case * CakeProducts\Controller\ProductCatalogsController Test Case
*/ */
#[CoversClass(ProductCatalogsController::class)] #[CoversClass(ProductCatalogsController::class)]
class ProductCatalogsControllerTest extends BaseControllerTest class ProductCatalogsControllerTest extends BaseControllerTest {
{
/** /**
* Test subject table * Test subject table
* *
* @var ProductCatalogsTable|Table * @var \CakeProducts\Model\Table\ProductCatalogsTable|\Cake\ORM\Table
*/ */
protected $ProductCatalogs; protected $ProductCatalogs;
@@ -39,8 +35,7 @@ class ProductCatalogsControllerTest extends BaseControllerTest
* *
* @return void * @return void
*/ */
protected function setUp(): void protected function setUp(): void {
{
parent::setUp(); parent::setUp();
// $this->enableCsrfToken(); // $this->enableCsrfToken();
// $this->enableSecurityToken(); // $this->enableSecurityToken();
@@ -54,8 +49,7 @@ class ProductCatalogsControllerTest extends BaseControllerTest
* *
* @return void * @return void
*/ */
protected function tearDown(): void protected function tearDown(): void {
{
unset($this->ProductCatalogs); unset($this->ProductCatalogs);
parent::tearDown(); parent::tearDown();
@@ -67,12 +61,11 @@ class ProductCatalogsControllerTest extends BaseControllerTest
* Tests the index action with a logged in user * Tests the index action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductCatalogsController::index() * @uses \CakeProducts\Controller\ProductCatalogsController::index()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testIndexGet(): void public function testIndexGet(): void {
{
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
@@ -89,12 +82,11 @@ class ProductCatalogsControllerTest extends BaseControllerTest
* Tests the view action with a logged in user * Tests the view action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductCatalogsController::view() * @uses \CakeProducts\Controller\ProductCatalogsController::view()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testViewGet(): void public function testViewGet(): void {
{
$id = '115153f3-2f59-4234-8ff8-e1b205761428'; $id = '115153f3-2f59-4234-8ff8-e1b205761428';
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
@@ -113,12 +105,11 @@ class ProductCatalogsControllerTest extends BaseControllerTest
* Tests the add action with a logged in user * Tests the add action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductCatalogsController::add() * @uses \CakeProducts\Controller\ProductCatalogsController::add()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testAddGet(): void public function testAddGet(): void {
{
$cntBefore = $this->ProductCatalogs->find()->count(); $cntBefore = $this->ProductCatalogs->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
@@ -140,12 +131,11 @@ class ProductCatalogsControllerTest extends BaseControllerTest
* Tests a POST request to the add action with a logged in user * Tests a POST request to the add action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductCatalogsController::add() * @uses \CakeProducts\Controller\ProductCatalogsController::add()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testAddPostSuccess(): void public function testAddPostSuccess(): void {
{
$cntBefore = $this->ProductCatalogs->find()->count(); $cntBefore = $this->ProductCatalogs->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
@@ -173,12 +163,11 @@ class ProductCatalogsControllerTest extends BaseControllerTest
* Tests a POST request to the add action with a logged in user * Tests a POST request to the add action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductCatalogsController::add() * @uses \CakeProducts\Controller\ProductCatalogsController::add()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testAddPostFailure(): void public function testAddPostFailure(): void {
{
$cntBefore = $this->ProductCatalogs->find()->count(); $cntBefore = $this->ProductCatalogs->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
@@ -205,12 +194,11 @@ class ProductCatalogsControllerTest extends BaseControllerTest
* Tests the edit action with a logged in user * Tests the edit action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductCatalogsController::edit() * @uses \CakeProducts\Controller\ProductCatalogsController::edit()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testEditGet(): void public function testEditGet(): void {
{
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$id = '115153f3-2f59-4234-8ff8-e1b205761428'; $id = '115153f3-2f59-4234-8ff8-e1b205761428';
$url = [ $url = [
@@ -229,12 +217,11 @@ class ProductCatalogsControllerTest extends BaseControllerTest
* Tests a PUT request to the edit action with a logged in user * Tests a PUT request to the edit action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductCatalogsController::edit() * @uses \CakeProducts\Controller\ProductCatalogsController::edit()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testEditPutSuccess(): void public function testEditPutSuccess(): void {
{
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$id = '115153f3-2f59-4234-8ff8-e1b205761428'; $id = '115153f3-2f59-4234-8ff8-e1b205761428';
// $before = $this->ProductCatalogs->get($id); // $before = $this->ProductCatalogs->get($id);
@@ -267,12 +254,11 @@ class ProductCatalogsControllerTest extends BaseControllerTest
* Tests a PUT request to the edit action with a logged in user * Tests a PUT request to the edit action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductCatalogsController::edit() * @uses \CakeProducts\Controller\ProductCatalogsController::edit()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testEditPutFailure(): void public function testEditPutFailure(): void {
{
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$id = '115153f3-2f59-4234-8ff8-e1b205761428'; $id = '115153f3-2f59-4234-8ff8-e1b205761428';
$before = $this->ProductCatalogs->get($id); $before = $this->ProductCatalogs->get($id);
@@ -301,12 +287,11 @@ class ProductCatalogsControllerTest extends BaseControllerTest
* Tests the delete action with a logged in user * Tests the delete action with a logged in user
* *
* @uses \CakeProducts\Controller\ProductCatalogsController::delete() * @uses \CakeProducts\Controller\ProductCatalogsController::delete()
* @throws Exception * @throws \PHPUnit\Exception
* *
* @return void * @return void
*/ */
public function testDelete(): void public function testDelete(): void {
{
$cntBefore = $this->ProductCatalogs->find()->count(); $cntBefore = $this->ProductCatalogs->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
@@ -324,4 +309,5 @@ class ProductCatalogsControllerTest extends BaseControllerTest
$cntAfter = $this->ProductCatalogs->find()->count(); $cntAfter = $this->ProductCatalogs->find()->count();
$this->assertEquals($cntBefore - 1, $cntAfter); $this->assertEquals($cntBefore - 1, $cntAfter);
} }
} }
@@ -3,24 +3,19 @@ declare(strict_types=1);
namespace CakeProducts\Test\TestCase\Controller; namespace CakeProducts\Test\TestCase\Controller;
use Cake\ORM\Table;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
use CakeProducts\Controller\ProductCategoriesController; use CakeProducts\Controller\ProductCategoriesController;
use CakeProducts\Model\Table\ProductCategoriesTable;
use PHPUnit\Exception;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
/** /**
* CakeProducts\Controller\ProductCategoriesController Test Case * CakeProducts\Controller\ProductCategoriesController Test Case
*/ */
#[CoversClass(ProductCategoriesController::class)] #[CoversClass(ProductCategoriesController::class)]
class ProductCategoriesControllerTest extends BaseControllerTest class ProductCategoriesControllerTest extends BaseControllerTest {
{
/** /**
* Test subject table * Test subject table
* *
* @var ProductCategoriesTable|Table * @var \CakeProducts\Model\Table\ProductCategoriesTable|\Cake\ORM\Table
*/ */
protected $ProductCategories; protected $ProductCategories;
@@ -39,8 +34,7 @@ class ProductCategoriesControllerTest extends BaseControllerTest
* *
* @return void * @return void
*/ */
protected function setUp(): void protected function setUp(): void {
{
parent::setUp(); parent::setUp();
// $this->enableCsrfToken(); // $this->enableCsrfToken();
// $this->enableSecurityToken(); // $this->enableSecurityToken();
@@ -53,8 +47,7 @@ class ProductCategoriesControllerTest extends BaseControllerTest
* *
* @return void * @return void
*/ */
protected function tearDown(): void protected function tearDown(): void {
{
unset($this->ProductCategories); unset($this->ProductCategories);
parent::tearDown(); parent::tearDown();
@@ -65,13 +58,11 @@ class ProductCategoriesControllerTest extends BaseControllerTest
* *
* Tests the index action with a logged in user * Tests the index action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoriesController::index * @uses \CakeProducts\Controller\ProductCategoriesController::index
* @throws Exception
* @return void
*/ */
public function testIndexGet(): void public function testIndexGet(): void {
{
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
@@ -87,13 +78,11 @@ class ProductCategoriesControllerTest extends BaseControllerTest
* *
* Tests the view action with a logged in user * Tests the view action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoriesController::view * @uses \CakeProducts\Controller\ProductCategoriesController::view
* @throws Exception
* @return void
*/ */
public function testViewGet(): void public function testViewGet(): void {
{
$id = 1; $id = 1;
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
@@ -111,13 +100,11 @@ class ProductCategoriesControllerTest extends BaseControllerTest
* *
* Tests the add action with a logged in user * Tests the add action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoriesController::add * @uses \CakeProducts\Controller\ProductCategoriesController::add
* @throws Exception
* @return void
*/ */
public function testAddGet(): void public function testAddGet(): void {
{
$cntBefore = $this->ProductCategories->find()->count(); $cntBefore = $this->ProductCategories->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
@@ -138,13 +125,11 @@ class ProductCategoriesControllerTest extends BaseControllerTest
* *
* Tests a POST request to the add action with a logged in user * Tests a POST request to the add action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoriesController::add * @uses \CakeProducts\Controller\ProductCategoriesController::add
* @throws Exception
* @return void
*/ */
public function testAddPostSuccess(): void public function testAddPostSuccess(): void {
{
$cntBefore = $this->ProductCategories->find()->count(); $cntBefore = $this->ProductCategories->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
@@ -173,13 +158,11 @@ class ProductCategoriesControllerTest extends BaseControllerTest
* *
* Tests a POST request to the add action with a logged in user * Tests a POST request to the add action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoriesController::add * @uses \CakeProducts\Controller\ProductCategoriesController::add
* @throws Exception
* @return void
*/ */
public function testAddPostFailure(): void public function testAddPostFailure(): void {
{
$cntBefore = $this->ProductCategories->find()->count(); $cntBefore = $this->ProductCategories->find()->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
@@ -207,13 +190,11 @@ class ProductCategoriesControllerTest extends BaseControllerTest
* *
* Tests the edit action with a logged in user * Tests the edit action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoriesController::edit * @uses \CakeProducts\Controller\ProductCategoriesController::edit
* @throws Exception
* @return void
*/ */
public function testEditGet(): void public function testEditGet(): void {
{
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$url = [ $url = [
'plugin' => 'CakeProducts', 'plugin' => 'CakeProducts',
@@ -230,13 +211,11 @@ class ProductCategoriesControllerTest extends BaseControllerTest
* *
* Tests a PUT request to the edit action with a logged in user * Tests a PUT request to the edit action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoriesController::edit * @uses \CakeProducts\Controller\ProductCategoriesController::edit
* @throws Exception
* @return void
*/ */
public function testEditPutSuccess(): void public function testEditPutSuccess(): void {
{
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$id = 1; $id = 1;
$before = $this->ProductCategories->get($id); $before = $this->ProductCategories->get($id);
@@ -272,13 +251,11 @@ class ProductCategoriesControllerTest extends BaseControllerTest
* *
* Tests a PUT request to the edit action with a logged in user * Tests a PUT request to the edit action with a logged in user
* *
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductCategoriesController::edit * @uses \CakeProducts\Controller\ProductCategoriesController::edit
* @throws Exception
* @return void
*/ */
public function testEditPutFailure(): void public function testEditPutFailure(): void {
{
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
$id = 1; $id = 1;
$before = $this->ProductCategories->get($id); $before = $this->ProductCategories->get($id);
@@ -306,14 +283,12 @@ class ProductCategoriesControllerTest extends BaseControllerTest
* Test delete method * Test delete method
* *
* Tests the delete action with a logged in user * Tests the delete action with a logged in user
*
* @return void
*@throws Exception
* *
* @uses \CakeProducts\Controller\ProductCategoriesController::delete * @uses \CakeProducts\Controller\ProductCategoriesController::delete
*@throws Exception
* @return void
*/ */
public function testDelete(): void public function testDelete(): void {
{
$cntBefore = $this->ProductCategories->find()->count(); $cntBefore = $this->ProductCategories->find()->count();
$cntBeforeWithTrashed = $this->ProductCategories->find('withTrashed')->count(); $cntBeforeWithTrashed = $this->ProductCategories->find('withTrashed')->count();
$this->loginUserByRole('admin'); $this->loginUserByRole('admin');
@@ -333,4 +308,5 @@ class ProductCategoriesControllerTest extends BaseControllerTest
$this->assertEquals($cntBefore - 2, $cntAfter); // has 1 child category $this->assertEquals($cntBefore - 2, $cntAfter); // has 1 child category
$this->assertEquals($cntBeforeWithTrashed, $cntAfterWithTrashed); $this->assertEquals($cntBeforeWithTrashed, $cntAfterWithTrashed);
} }
} }

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