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
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:
+20
-30
@@ -11,9 +11,9 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
php-version: ['8.2', '8.4']
|
||||
db-type: ['mysql']
|
||||
# db-type: ['sqlite', 'mysql', 'pgsql']
|
||||
php-version: ['8.2', '8.5']
|
||||
# db-type: ['mysql']
|
||||
db-type: ['sqlite', 'mysql', 'pgsql']
|
||||
prefer-lowest: ['']
|
||||
include:
|
||||
- php-version: '8.2'
|
||||
@@ -26,20 +26,13 @@ jobs:
|
||||
env:
|
||||
MYSQL_ALLOW_EMPTY_PASSWORD: yes
|
||||
MYSQL_DATABASE: cakephp
|
||||
# services:
|
||||
# postgres:
|
||||
# image: postgres
|
||||
# ports:
|
||||
# - 5432:5432
|
||||
# env:
|
||||
# POSTGRES_PASSWORD: postgres
|
||||
# mysql8:
|
||||
# image: mysql:8.0
|
||||
# env:
|
||||
# MYSQL_ALLOW_EMPTY_PASSWORD: yes
|
||||
# MYSQL_DATABASE: test_db
|
||||
# ports:
|
||||
# - 3306:3306
|
||||
# services:
|
||||
# postgres:
|
||||
# image: postgres
|
||||
# ports:
|
||||
# - 5432:5432
|
||||
# env:
|
||||
# POSTGRES_PASSWORD: postgres
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
@@ -47,7 +40,7 @@ jobs:
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php-version }}
|
||||
extensions: mbstring, intl, sqlite, pdo_${{ matrix.db-type }}
|
||||
extensions: mbstring, intl, bcmath, sqlite, pdo_${{ matrix.db-type }}
|
||||
coverage: pcov
|
||||
|
||||
- name: Get composer cache directory
|
||||
@@ -94,11 +87,11 @@ jobs:
|
||||
if: matrix.prefer-lowest == 'prefer-lowest'
|
||||
run: vendor/bin/validate-prefer-lowest -m
|
||||
|
||||
# - name: Upload coverage reports to Codecov
|
||||
# if: success() && matrix.php-version == '8.2'
|
||||
# uses: codecov/codecov-action@v4
|
||||
# with:
|
||||
# token: ${{ secrets.CODECOV_TOKEN }}
|
||||
# - name: Upload coverage reports to Codecov
|
||||
# if: success() && matrix.php-version == '8.2'
|
||||
# uses: codecov/codecov-action@v4
|
||||
# with:
|
||||
# token: ${{ secrets.CODECOV_TOKEN }}
|
||||
|
||||
validation:
|
||||
name: Coding Standard & Static Analysis
|
||||
@@ -108,8 +101,8 @@ jobs:
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.1'
|
||||
extensions: mbstring, intl, sqlite
|
||||
php-version: '8.2'
|
||||
extensions: mbstring, intl, sqlite, bcmath
|
||||
coverage: none
|
||||
|
||||
- name: Get composer cache directory
|
||||
@@ -133,11 +126,8 @@ jobs:
|
||||
composer install --no-progress --prefer-dist --optimize-autoloader
|
||||
fi
|
||||
|
||||
- name: Composer phpstan setup
|
||||
run: composer stan-setup
|
||||
|
||||
- name: Run phpstan
|
||||
run: vendor/bin/phpstan analyse --error-format=github
|
||||
run: vendor/bin/phpstan analyse src --error-format=github
|
||||
|
||||
- name: Run phpcs
|
||||
run: composer cs-check
|
||||
run: composer cs-check
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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\""
|
||||
@@ -8,3 +8,4 @@
|
||||
/.idea/
|
||||
tmp
|
||||
tests/test_app/webroot/images/products/
|
||||
tests/test_app/webroot/uploads/
|
||||
|
||||
+23
-3
@@ -9,11 +9,14 @@
|
||||
"dereuromark/cakephp-tools": "^3.9",
|
||||
"muffin/trash": "^4.2",
|
||||
"cakephp/cakephp": "^5.0.1",
|
||||
"bentools/cartesian-product": "dev-master"
|
||||
"bentools/cartesian-product": "^2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^10.1",
|
||||
"cakephp/migrations": "^4.0.0"
|
||||
"phpunit/phpunit": "^10.3",
|
||||
"cakephp/migrations": "^4.5.0",
|
||||
"cakedc/cakephp-phpstan": "^4.1",
|
||||
"dereuromark/composer-prefer-lowest": "^0.1.10",
|
||||
"fig-r/psr2r-sniffer": "^2.7"
|
||||
},
|
||||
"suggest": {
|
||||
"hi-powered-dev/cake-carts": "Allow users to add products/SKUs to a cart"
|
||||
@@ -29,5 +32,22 @@
|
||||
"Cake\\Test\\": "vendor/cakephp/cakephp/tests/",
|
||||
"TestApp\\": "tests/test_app/src/"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"check": [
|
||||
"@test",
|
||||
"@cs-check"
|
||||
],
|
||||
"test": "phpunit --colors=always",
|
||||
"cs-check": "vendor/bin/phpcs --colors",
|
||||
"cs-fix": "vendor/bin/phpcbf --colors",
|
||||
"lowest": "validate-prefer-lowest",
|
||||
"lowest-setup": "composer update --prefer-lowest --prefer-stable --prefer-dist --no-interaction && cp composer.json composer.backup && composer require --dev dereuromark/composer-prefer-lowest && mv composer.backup composer.json",
|
||||
"stan": "phpstan analyze"
|
||||
},
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
"dealerdirect/phpcodesniffer-composer-installer": false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Migrations\AbstractMigration;
|
||||
use Migrations\BaseMigration;
|
||||
|
||||
class CreateProductCatalogs extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
class CreateProductCatalogs extends BaseMigration {
|
||||
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* More information on this method is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
* @return void
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$table = $this->table('product_catalogs', ['id' => false, 'primary_key' => ['id']]);
|
||||
$table->addColumn('id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('name', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('catalog_description', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('enabled', 'boolean', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addIndex([
|
||||
'name',
|
||||
], [
|
||||
'name' => 'BY_NAME',
|
||||
'unique' => true,
|
||||
]);
|
||||
$table->create();
|
||||
}
|
||||
public function change(): void {
|
||||
$table = $this->table('product_catalogs', ['id' => false, 'primary_key' => ['id']]);
|
||||
$table->addColumn('id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('name', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('catalog_description', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('enabled', 'boolean', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addIndex([
|
||||
'name',
|
||||
], [
|
||||
'name' => 'BY_NAME',
|
||||
'unique' => true,
|
||||
]);
|
||||
$table->create();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,38 +1,37 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Migrations\AbstractMigration;
|
||||
use Migrations\BaseMigration;
|
||||
|
||||
class CreateProductCategories extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
class CreateProductCategories extends BaseMigration {
|
||||
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* More information on this method is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
* @return void
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$table = $this->table('product_categories');
|
||||
public function change(): void {
|
||||
$table = $this->table('product_categories');
|
||||
|
||||
$table->addColumn('product_catalog_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('internal_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('name', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('category_description', 'text', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('product_catalog_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('internal_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('name', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('category_description', 'text', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
// $table->addColumn('shopify_v1_id', 'integer', [
|
||||
// 'default' => null,
|
||||
// 'limit' => 11,
|
||||
@@ -43,36 +42,37 @@ class CreateProductCategories extends AbstractMigration
|
||||
// 'limit' => 255,
|
||||
// 'null' => true,
|
||||
// ]);
|
||||
$table->addColumn('parent_id', 'integer', [
|
||||
'default' => null,
|
||||
'limit' => 11,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('lft', 'integer', [
|
||||
'default' => null,
|
||||
'limit' => 11,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('rght', 'integer', [
|
||||
'default' => null,
|
||||
'limit' => 11,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('enabled', 'boolean', [
|
||||
'default' => false,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('parent_id', 'integer', [
|
||||
'default' => null,
|
||||
'limit' => 11,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('lft', 'integer', [
|
||||
'default' => null,
|
||||
'limit' => 11,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('rght', 'integer', [
|
||||
'default' => null,
|
||||
'limit' => 11,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('enabled', 'boolean', [
|
||||
'default' => false,
|
||||
'null' => false,
|
||||
]);
|
||||
|
||||
$table->addIndex('parent_id');
|
||||
$table->addIndex('lft');
|
||||
$table->addIndex('product_catalog_id');
|
||||
$table->addIndex([
|
||||
'product_catalog_id',
|
||||
'name',
|
||||
], [
|
||||
'name' => 'BY_NAME_AND_CATALOG_ID',
|
||||
'unique' => true,
|
||||
]);
|
||||
$table->create();
|
||||
}
|
||||
|
||||
$table->addIndex('parent_id');
|
||||
$table->addIndex('lft');
|
||||
$table->addIndex('product_catalog_id');
|
||||
$table->addIndex([
|
||||
'product_catalog_id',
|
||||
'name',
|
||||
], [
|
||||
'name' => 'BY_NAME_AND_CATALOG_ID',
|
||||
'unique' => true,
|
||||
]);
|
||||
$table->create();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +1,39 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Migrations\AbstractMigration;
|
||||
use Migrations\BaseMigration;
|
||||
|
||||
class CreateProducts extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
class CreateProducts extends BaseMigration {
|
||||
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* More information on this method is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
* @return void
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$table = $this->table('products', ['id' => false, 'primary_key' => ['id']]);
|
||||
$table->addColumn('id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('name', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_category_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_type_id', 'integer', [
|
||||
'default' => null,
|
||||
'limit' => 11,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addIndex('product_category_id');
|
||||
$table->addIndex('product_type_id');
|
||||
public function change(): void {
|
||||
$table = $this->table('products', ['id' => false, 'primary_key' => ['id']]);
|
||||
$table->addColumn('id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('name', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_category_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_type_id', 'integer', [
|
||||
'default' => null,
|
||||
'limit' => 11,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addIndex('product_category_id');
|
||||
$table->addIndex('product_type_id');
|
||||
// $table->addIndex([
|
||||
// 'product_category_id',
|
||||
// 'name',
|
||||
@@ -42,6 +41,7 @@ class CreateProducts extends AbstractMigration
|
||||
// 'name' => 'BY_NAME_AND_CATEGORY_ID',
|
||||
// 'unique' => true,
|
||||
// ]);
|
||||
$table->create();
|
||||
}
|
||||
$table->create();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,55 +1,55 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Migrations\AbstractMigration;
|
||||
use Migrations\BaseMigration;
|
||||
|
||||
class CreateProductCategoryAttributes extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
class CreateProductCategoryAttributes extends BaseMigration {
|
||||
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* More information on this method is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
* @return void
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$table = $this->table('product_category_attributes', ['id' => false, 'primary_key' => ['id']]);
|
||||
$table->addColumn('id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('name', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_category_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('attribute_type_id', 'integer', [
|
||||
'default' => null,
|
||||
'limit' => 11,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('enabled', 'boolean', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addIndex([
|
||||
'product_category_id',
|
||||
], [
|
||||
'name' => 'BY_PRODUCT_CATEGORY_ID',
|
||||
'unique' => false,
|
||||
]);
|
||||
$table->addIndex([
|
||||
'name',
|
||||
'product_category_id',
|
||||
], [
|
||||
'name' => 'BY_NAME_AND_PRODUCT_CATEGORY_ID_UNIQUE',
|
||||
'unique' => true,
|
||||
]);
|
||||
$table->create();
|
||||
}
|
||||
public function change(): void {
|
||||
$table = $this->table('product_category_attributes', ['id' => false, 'primary_key' => ['id']]);
|
||||
$table->addColumn('id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('name', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_category_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('attribute_type_id', 'integer', [
|
||||
'default' => null,
|
||||
'limit' => 11,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('enabled', 'boolean', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addIndex([
|
||||
'product_category_id',
|
||||
], [
|
||||
'name' => 'BY_PRODUCT_CATEGORY_ID',
|
||||
'unique' => false,
|
||||
]);
|
||||
$table->addIndex([
|
||||
'name',
|
||||
'product_category_id',
|
||||
], [
|
||||
'name' => 'BY_NAME_AND_PRODUCT_CATEGORY_ID_UNIQUE',
|
||||
'unique' => true,
|
||||
]);
|
||||
$table->create();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,48 +1,48 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Migrations\AbstractMigration;
|
||||
use Migrations\BaseMigration;
|
||||
|
||||
class CreateProductCategoryAttributeOptions extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
class CreateProductCategoryAttributeOptions extends BaseMigration {
|
||||
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* More information on this method is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
* @return void
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$table = $this->table('product_category_attribute_options', ['id' => false, 'primary_key' => ['id']]);
|
||||
$table->addColumn('id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_category_attribute_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('attribute_value', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('attribute_label', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('enabled', 'boolean', [
|
||||
'default' => true,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addIndex([
|
||||
'product_category_attribute_id',
|
||||
], [
|
||||
'name' => 'BY_PRODUCT_CATEGORY_ATTRIBUTE_ID',
|
||||
'unique' => false,
|
||||
]);
|
||||
$table->create();
|
||||
}
|
||||
public function change(): void {
|
||||
$table = $this->table('product_category_attribute_options', ['id' => false, 'primary_key' => ['id']]);
|
||||
$table->addColumn('id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_category_attribute_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('attribute_value', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('attribute_label', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('enabled', 'boolean', [
|
||||
'default' => true,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addIndex([
|
||||
'product_category_attribute_id',
|
||||
], [
|
||||
'name' => 'BY_PRODUCT_CATEGORY_ATTRIBUTE_ID',
|
||||
'unique' => false,
|
||||
]);
|
||||
$table->create();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,39 +3,39 @@ declare(strict_types=1);
|
||||
|
||||
use Migrations\BaseMigration;
|
||||
|
||||
class CreateProductAttributes extends BaseMigration
|
||||
{
|
||||
/**
|
||||
class CreateProductAttributes extends BaseMigration {
|
||||
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* More information on this method is available here:
|
||||
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
|
||||
* @return void
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$table = $this->table('product_attributes', ['id' => false, 'primary_key' => ['id']]);
|
||||
$table->addColumn('id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_category_attribute_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('attribute_value', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('product_category_attribute_option_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->create();
|
||||
}
|
||||
public function change(): void {
|
||||
$table = $this->table('product_attributes', ['id' => false, 'primary_key' => ['id']]);
|
||||
$table->addColumn('id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_category_attribute_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('attribute_value', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('product_category_attribute_option_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->create();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,64 +3,57 @@ declare(strict_types=1);
|
||||
|
||||
use Migrations\BaseMigration;
|
||||
|
||||
class AddSoftDeleteToAllTables extends BaseMigration
|
||||
{
|
||||
/**
|
||||
class AddSoftDeleteToAllTables extends BaseMigration {
|
||||
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* More information on this method is available here:
|
||||
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
|
||||
* @return void
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$table = $this->table('products');
|
||||
$table->addColumn('deleted', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->update();
|
||||
public function change(): void {
|
||||
$table = $this->table('products');
|
||||
$table->addColumn('deleted', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->update();
|
||||
|
||||
$table = $this->table('product_category_attributes');
|
||||
$table->addColumn('deleted', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->update();
|
||||
$table = $this->table('product_category_attributes');
|
||||
$table->addColumn('deleted', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->update();
|
||||
|
||||
$table = $this->table('product_category_attribute_options');
|
||||
$table->addColumn('deleted', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->update();
|
||||
$table = $this->table('product_category_attribute_options');
|
||||
$table->addColumn('deleted', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->update();
|
||||
|
||||
$table = $this->table('product_categories');
|
||||
$table->addColumn('deleted', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->update();
|
||||
$table = $this->table('product_categories');
|
||||
$table->addColumn('deleted', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->update();
|
||||
|
||||
$table = $this->table('product_catalogs');
|
||||
$table->addColumn('deleted', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->update();
|
||||
$table = $this->table('product_catalogs');
|
||||
$table->addColumn('deleted', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->update();
|
||||
|
||||
$table = $this->table('external_product_catalogs_product_catalogs');
|
||||
$table->addColumn('deleted', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->update();
|
||||
$table = $this->table('product_attributes');
|
||||
$table->addColumn('deleted', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->update();
|
||||
}
|
||||
|
||||
$table = $this->table('product_attributes');
|
||||
$table->addColumn('deleted', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,60 +3,60 @@ declare(strict_types=1);
|
||||
|
||||
use Migrations\BaseMigration;
|
||||
|
||||
class CreateProductSkus extends BaseMigration
|
||||
{
|
||||
/**
|
||||
class CreateProductSkus extends BaseMigration {
|
||||
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* More information on this method is available here:
|
||||
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
|
||||
* @return void
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$table = $this->table('product_skus', ['id' => false, 'primary_key' => ['id']]);
|
||||
$table->addColumn('id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('sku', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('barcode', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('price', 'decimal', [
|
||||
'default' => null,
|
||||
'precision' => 15,
|
||||
'scale' => 6,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('cost', 'decimal', [
|
||||
'default' => null,
|
||||
'precision' => 15,
|
||||
'scale' => 6,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('created', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('modified', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('deleted', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->create();
|
||||
}
|
||||
public function change(): void {
|
||||
$table = $this->table('product_skus', ['id' => false, 'primary_key' => ['id']]);
|
||||
$table->addColumn('id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('sku', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('barcode', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('price', 'decimal', [
|
||||
'default' => null,
|
||||
'precision' => 15,
|
||||
'scale' => 6,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('cost', 'decimal', [
|
||||
'default' => null,
|
||||
'precision' => 15,
|
||||
'scale' => 6,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('created', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('modified', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('deleted', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->create();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,53 +1,52 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Migrations\AbstractMigration;
|
||||
use Migrations\BaseMigration;
|
||||
|
||||
class CreateProductCategoryVariants extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
class CreateProductCategoryVariants extends BaseMigration {
|
||||
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* More information on this method is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
* @return void
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$table = $this->table('product_category_variants', ['id' => false, 'primary_key' => ['id']]);
|
||||
$table->addColumn('id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('name', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_category_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('product_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('enabled', 'boolean', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addIndex([
|
||||
'product_category_id',
|
||||
], [
|
||||
'name' => 'VARIANTS_BY_PRODUCT_CATEGORY_ID',
|
||||
'unique' => false,
|
||||
]);
|
||||
$table->addIndex([
|
||||
'product_id',
|
||||
], [
|
||||
'name' => 'CATEGORY_VARIANTS_BY_PRODUCT_ID',
|
||||
'unique' => false,
|
||||
]);
|
||||
public function change(): void {
|
||||
$table = $this->table('product_category_variants', ['id' => false, 'primary_key' => ['id']]);
|
||||
$table->addColumn('id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('name', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_category_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('product_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('enabled', 'boolean', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addIndex([
|
||||
'product_category_id',
|
||||
], [
|
||||
'name' => 'VARIANTS_BY_PRODUCT_CATEGORY_ID',
|
||||
'unique' => false,
|
||||
]);
|
||||
$table->addIndex([
|
||||
'product_id',
|
||||
], [
|
||||
'name' => 'CATEGORY_VARIANTS_BY_PRODUCT_ID',
|
||||
'unique' => false,
|
||||
]);
|
||||
// $table->addIndex([
|
||||
// 'name',
|
||||
// 'product_category_id',
|
||||
@@ -56,6 +55,7 @@ class CreateProductCategoryVariants extends AbstractMigration
|
||||
// 'name' => 'VARIANTS_BY_NAME_AND_PRODUCT_CATEGORY_ID_AND_PRODUCT_ID_UNIQUE',
|
||||
// 'unique' => true,
|
||||
// ]);
|
||||
$table->create();
|
||||
}
|
||||
$table->create();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,54 +3,54 @@ declare(strict_types=1);
|
||||
|
||||
use Migrations\BaseMigration;
|
||||
|
||||
class CreateProductCategoryVariantOptions extends BaseMigration
|
||||
{
|
||||
/**
|
||||
class CreateProductCategoryVariantOptions extends BaseMigration {
|
||||
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* More information on this method is available here:
|
||||
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
|
||||
* @return void
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$table = $this->table('product_category_variant_options', ['id' => false, 'primary_key' => ['id']]);
|
||||
$table->addColumn('id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_category_variant_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('variant_value', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('variant_label', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('created', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('modified', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('deleted', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('enabled', 'boolean', [
|
||||
'default' => true,
|
||||
'null' => false,
|
||||
]);
|
||||
public function change(): void {
|
||||
$table = $this->table('product_category_variant_options', ['id' => false, 'primary_key' => ['id']]);
|
||||
$table->addColumn('id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_category_variant_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('variant_value', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('variant_label', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('created', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('modified', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('deleted', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('enabled', 'boolean', [
|
||||
'default' => true,
|
||||
'null' => false,
|
||||
]);
|
||||
// $table->addForeignKey('product_category_variant_id', 'product_category_variants'); // @TODO why cant this be included??? breaks tests on tearDown
|
||||
|
||||
$table->create();
|
||||
}
|
||||
$table->create();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,23 +3,23 @@ declare(strict_types=1);
|
||||
|
||||
use Migrations\BaseMigration;
|
||||
|
||||
class AddDefaultProductTypeIdToProductCategories extends BaseMigration
|
||||
{
|
||||
/**
|
||||
class AddDefaultProductTypeIdToProductCategories extends BaseMigration {
|
||||
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* More information on this method is available here:
|
||||
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
|
||||
* @return void
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$table = $this->table('product_categories');
|
||||
$table->addColumn('default_product_type_id', 'integer', [
|
||||
'default' => null,
|
||||
'limit' => 11,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->update();
|
||||
}
|
||||
public function change(): void {
|
||||
$table = $this->table('product_categories');
|
||||
$table->addColumn('default_product_type_id', 'integer', [
|
||||
'default' => null,
|
||||
'limit' => 11,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->update();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ declare(strict_types=1);
|
||||
|
||||
use Migrations\BaseMigration;
|
||||
|
||||
class CreateProductPhotos extends BaseMigration
|
||||
{
|
||||
/**
|
||||
class CreateProductPhotos extends BaseMigration {
|
||||
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* More information on this method is available here:
|
||||
@@ -13,75 +13,75 @@ class CreateProductPhotos extends BaseMigration
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$table = $this->table('product_photos', ['id' => false, 'primary_key' => ['id']]);
|
||||
$table->addColumn('id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_sku_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
public function change(): void {
|
||||
$table = $this->table('product_photos', ['id' => false, 'primary_key' => ['id']]);
|
||||
$table->addColumn('id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_sku_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
|
||||
$table->addColumn('photo_dir', 'text', [
|
||||
'default' => null,
|
||||
'length' => 255,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('photo_filename', 'string', [
|
||||
'default' => null,
|
||||
'length' => 255,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('photo_dir', 'text', [
|
||||
'default' => null,
|
||||
'length' => 255,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('photo_filename', 'string', [
|
||||
'default' => null,
|
||||
'length' => 255,
|
||||
'null' => false,
|
||||
]);
|
||||
|
||||
$table->addColumn('primary_photo', 'boolean', [
|
||||
'default' => false,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('primary_photo', 'boolean', [
|
||||
'default' => false,
|
||||
'null' => false,
|
||||
]);
|
||||
|
||||
$table->addColumn('photo_position', 'integer', [
|
||||
'default' => 100,
|
||||
'limit' => 11,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('photo_position', 'integer', [
|
||||
'default' => 100,
|
||||
'limit' => 11,
|
||||
'null' => false,
|
||||
]);
|
||||
|
||||
$table->addColumn('enabled', 'boolean', [
|
||||
'default' => false,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('enabled', 'boolean', [
|
||||
'default' => false,
|
||||
'null' => false,
|
||||
]);
|
||||
|
||||
$table->addColumn('created', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('modified', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('deleted', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('created', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('modified', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('deleted', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
|
||||
$table->addIndex([
|
||||
'product_id',
|
||||
], [
|
||||
'name' => 'PRODUCT_PHOTOS_BY_PRODUCT_ID',
|
||||
'unique' => false,
|
||||
]);
|
||||
$table->addIndex([
|
||||
'product_sku_id',
|
||||
], [
|
||||
'name' => 'PRODUCT_PHOTOS_BY_PRODUCT_SKU_ID',
|
||||
'unique' => false,
|
||||
]);
|
||||
$table->addIndex([
|
||||
'product_id',
|
||||
], [
|
||||
'name' => 'PRODUCT_PHOTOS_BY_PRODUCT_ID',
|
||||
'unique' => false,
|
||||
]);
|
||||
$table->addIndex([
|
||||
'product_sku_id',
|
||||
], [
|
||||
'name' => 'PRODUCT_PHOTOS_BY_PRODUCT_SKU_ID',
|
||||
'unique' => false,
|
||||
]);
|
||||
|
||||
$table->create();
|
||||
}
|
||||
|
||||
$table->create();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ declare(strict_types=1);
|
||||
|
||||
use Migrations\BaseMigration;
|
||||
|
||||
class CreateProductSkuVariantValues extends BaseMigration
|
||||
{
|
||||
/**
|
||||
class CreateProductSkuVariantValues extends BaseMigration {
|
||||
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* More information on this method is available here:
|
||||
@@ -13,25 +13,25 @@ class CreateProductSkuVariantValues extends BaseMigration
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$table = $this->table('product_sku_variant_values', ['id' => false, 'primary_key' => ['id']]);
|
||||
$table->addColumn('id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_sku_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_variant_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_category_variant_option_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->create();
|
||||
}
|
||||
public function change(): void {
|
||||
$table = $this->table('product_sku_variant_values', ['id' => false, 'primary_key' => ['id']]);
|
||||
$table->addColumn('id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_sku_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_variant_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_category_variant_option_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->create();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ declare(strict_types=1);
|
||||
|
||||
use Migrations\BaseMigration;
|
||||
|
||||
class CreateProductVariants extends BaseMigration
|
||||
{
|
||||
/**
|
||||
class CreateProductVariants extends BaseMigration {
|
||||
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* More information on this method is available here:
|
||||
@@ -13,42 +13,41 @@ class CreateProductVariants extends BaseMigration
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$table = $this->table('product_variants', ['id' => false, 'primary_key' => ['id']]);
|
||||
$table->addColumn('id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('name', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_category_variant_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('product_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('enabled', 'boolean', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addIndex([
|
||||
'product_category_variant_id',
|
||||
], [
|
||||
'name' => 'VARIANTS_BY_PARENT_PRODUCT_CATEGORY_VARIANT_ID',
|
||||
'unique' => false,
|
||||
]);
|
||||
$table->addIndex([
|
||||
'product_id',
|
||||
], [
|
||||
'name' => 'VARIANTS_BY_PRODUCT_ID',
|
||||
'unique' => false,
|
||||
]);
|
||||
public function change(): void {
|
||||
$table = $this->table('product_variants', ['id' => false, 'primary_key' => ['id']]);
|
||||
$table->addColumn('id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('name', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_category_variant_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('product_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('enabled', 'boolean', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addIndex([
|
||||
'product_category_variant_id',
|
||||
], [
|
||||
'name' => 'VARIANTS_BY_PARENT_PRODUCT_CATEGORY_VARIANT_ID',
|
||||
'unique' => false,
|
||||
]);
|
||||
$table->addIndex([
|
||||
'product_id',
|
||||
], [
|
||||
'name' => 'VARIANTS_BY_PRODUCT_ID',
|
||||
'unique' => false,
|
||||
]);
|
||||
|
||||
// $table->addIndex([
|
||||
// 'name',
|
||||
@@ -57,6 +56,7 @@ class CreateProductVariants extends BaseMigration
|
||||
// 'name' => 'VARIANTS_BY_NAME_AND_PRODUCT_CATEGORY_ID_UNIQUE',
|
||||
// 'unique' => true,
|
||||
// ]);
|
||||
$table->create();
|
||||
}
|
||||
$table->create();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,23 +3,23 @@ declare(strict_types=1);
|
||||
|
||||
use Migrations\BaseMigration;
|
||||
|
||||
class AddDefaultSkuToProductSkus extends BaseMigration
|
||||
{
|
||||
/**
|
||||
class AddDefaultSkuToProductSkus extends BaseMigration {
|
||||
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* More information on this method is available here:
|
||||
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
|
||||
* @return void
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$table = $this->table('product_skus');
|
||||
$table->addColumn('default_sku', 'boolean', [
|
||||
'default' => false,
|
||||
'limit' => 11,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->update();
|
||||
}
|
||||
public function change(): void {
|
||||
$table = $this->table('product_skus');
|
||||
$table->addColumn('default_sku', 'boolean', [
|
||||
'default' => false,
|
||||
'limit' => 11,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->update();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ declare(strict_types=1);
|
||||
|
||||
use Migrations\BaseMigration;
|
||||
|
||||
class AddProductCategoryIdToProductPhotos extends BaseMigration
|
||||
{
|
||||
/**
|
||||
class AddProductCategoryIdToProductPhotos extends BaseMigration {
|
||||
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* More information on this method is available here:
|
||||
@@ -13,17 +13,17 @@ class AddProductCategoryIdToProductPhotos extends BaseMigration
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$table = $this->table('product_photos');
|
||||
$table->addColumn('product_category_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('primary_category_photo', 'boolean', [
|
||||
'default' => false,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->update();
|
||||
}
|
||||
public function change(): void {
|
||||
$table = $this->table('product_photos');
|
||||
$table->addColumn('product_category_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('primary_category_photo', 'boolean', [
|
||||
'default' => false,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->update();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,23 +3,23 @@ declare(strict_types=1);
|
||||
|
||||
use Migrations\BaseMigration;
|
||||
|
||||
class AddPrimarySkuPhotoToProductPhotos extends BaseMigration
|
||||
{
|
||||
/**
|
||||
class AddPrimarySkuPhotoToProductPhotos extends BaseMigration {
|
||||
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* More information on this method is available here:
|
||||
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
|
||||
* @return void
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$table = $this->table('product_photos');
|
||||
$table->addColumn('primary_sku_photo', 'boolean', [
|
||||
'default' => false,
|
||||
'limit' => 11,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->update();
|
||||
}
|
||||
public function change(): void {
|
||||
$table = $this->table('product_photos');
|
||||
$table->addColumn('primary_sku_photo', 'boolean', [
|
||||
'default' => false,
|
||||
'limit' => 11,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->update();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,51 +3,50 @@ declare(strict_types=1);
|
||||
|
||||
use Migrations\BaseMigration;
|
||||
|
||||
class AllowProductIdToBeNullInProductPhotos extends BaseMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* More information on this method is available here:
|
||||
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
|
||||
* @return void
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
$table = $this->table('product_photos');
|
||||
$table->changeColumn('product_id', 'uuid', [
|
||||
'default' => null,
|
||||
'limit' => 11,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->changeColumn('product_category_id', 'uuid', [
|
||||
'default' => null,
|
||||
'limit' => 11,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->update();
|
||||
}
|
||||
class AllowProductIdToBeNullInProductPhotos extends BaseMigration {
|
||||
|
||||
/**
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* More information on this method is available here:
|
||||
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
|
||||
* @return void
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
$table = $this->table('product_photos');
|
||||
$table->changeColumn('product_id', 'uuid', [
|
||||
'default' => null,
|
||||
'limit' => 11,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->changeColumn('product_category_id', 'uuid', [
|
||||
'default' => null,
|
||||
'limit' => 11,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->update();
|
||||
}
|
||||
public function up(): void {
|
||||
$table = $this->table('product_photos');
|
||||
$table->changeColumn('product_id', 'uuid', [
|
||||
'default' => null,
|
||||
'limit' => 11,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->changeColumn('product_category_id', 'uuid', [
|
||||
'default' => null,
|
||||
'limit' => 11,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* More information on this method is available here:
|
||||
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
|
||||
* @return void
|
||||
*/
|
||||
public function down(): void {
|
||||
$table = $this->table('product_photos');
|
||||
$table->changeColumn('product_id', 'uuid', [
|
||||
'default' => null,
|
||||
'limit' => 11,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->changeColumn('product_category_id', 'uuid', [
|
||||
'default' => null,
|
||||
'limit' => 11,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->update();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,23 +3,23 @@ declare(strict_types=1);
|
||||
|
||||
use Migrations\BaseMigration;
|
||||
|
||||
class AddIsSystemToProductCategoryVariants extends BaseMigration
|
||||
{
|
||||
/**
|
||||
class AddIsSystemToProductCategoryVariants extends BaseMigration {
|
||||
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* More information on this method is available here:
|
||||
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
|
||||
* @return void
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$table = $this->table('product_category_variants');
|
||||
$table->addColumn('is_system_variant', 'boolean', [
|
||||
'default' => false,
|
||||
'limit' => 11,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->update();
|
||||
}
|
||||
public function change(): void {
|
||||
$table = $this->table('product_category_variants');
|
||||
$table->addColumn('is_system_variant', 'boolean', [
|
||||
'default' => false,
|
||||
'limit' => 11,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->update();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,14 +3,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace Seeds;
|
||||
|
||||
use Cake\Utility\Text;
|
||||
use Migrations\BaseSeed;
|
||||
|
||||
/**
|
||||
* CreateSystemCategoryVariants seed.
|
||||
*/
|
||||
class CreateSystemCategoryVariantsSeed extends BaseSeed
|
||||
{
|
||||
/**
|
||||
class CreateSystemCategoryVariantsSeed extends BaseSeed {
|
||||
|
||||
/**
|
||||
* Run Method.
|
||||
*
|
||||
* Write your database seeder using this method.
|
||||
@@ -20,36 +21,36 @@ class CreateSystemCategoryVariantsSeed extends BaseSeed
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$data = [
|
||||
[
|
||||
'id' => \Cake\Utility\Text::uuid(),
|
||||
'name' => 'Subscription Length',
|
||||
'product_category_id' => null,
|
||||
'enabled' => true,
|
||||
'is_system_variant' => true,
|
||||
],
|
||||
[
|
||||
'id' => \Cake\Utility\Text::uuid(),
|
||||
'name' => 'Subscription Length Units',
|
||||
'product_category_id' => null,
|
||||
'enabled' => true,
|
||||
'is_system_variant' => true,
|
||||
],
|
||||
];
|
||||
$table = $this->table('product_category_variants');
|
||||
$toInsert = [];
|
||||
foreach ($data as $singleRecordToInsert) {
|
||||
$stmt = $this->query('SELECT * FROM product_category_variants WHERE name="' . $singleRecordToInsert['name'] . '" AND product_category_id IS NULL;'); // returns PDOStatement
|
||||
$rows = $stmt->fetchAll(); // returns the result as an array
|
||||
if ($rows) {
|
||||
continue;
|
||||
}
|
||||
$toInsert[] = $singleRecordToInsert;
|
||||
}
|
||||
if ($toInsert) {
|
||||
$table->insert($data)->save();
|
||||
}
|
||||
}
|
||||
public function run(): void {
|
||||
$data = [
|
||||
[
|
||||
'id' => Text::uuid(),
|
||||
'name' => 'Subscription Length',
|
||||
'product_category_id' => null,
|
||||
'enabled' => true,
|
||||
'is_system_variant' => true,
|
||||
],
|
||||
[
|
||||
'id' => Text::uuid(),
|
||||
'name' => 'Subscription Length Units',
|
||||
'product_category_id' => null,
|
||||
'enabled' => true,
|
||||
'is_system_variant' => true,
|
||||
],
|
||||
];
|
||||
$table = $this->table('product_category_variants');
|
||||
$toInsert = [];
|
||||
foreach ($data as $singleRecordToInsert) {
|
||||
$stmt = $this->query('SELECT * FROM product_category_variants WHERE name="' . $singleRecordToInsert['name'] . '" AND product_category_id IS NULL;'); // returns PDOStatement
|
||||
$rows = $stmt->fetchAll(); // returns the result as an array
|
||||
if ($rows) {
|
||||
continue;
|
||||
}
|
||||
$toInsert[] = $singleRecordToInsert;
|
||||
}
|
||||
if ($toInsert) {
|
||||
$table->insert($data)->save();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+12
-12
@@ -4,10 +4,10 @@
|
||||
|
||||
return [
|
||||
'CakeProducts' => [
|
||||
'photos' => [
|
||||
'directory' => WWW_ROOT . 'images' . DS . 'products' . DS,
|
||||
],
|
||||
/**
|
||||
'photos' => [
|
||||
'directory' => WWW_ROOT . 'images' . DS . 'products' . DS,
|
||||
],
|
||||
/**
|
||||
* internal CakeProducts settings - used in the source of truth/internal only system.
|
||||
* Can optionally manage external catalogs
|
||||
*
|
||||
@@ -15,17 +15,17 @@ return [
|
||||
* which will receive changes to the catalogs and optionally allow for external API access.
|
||||
* Will have no effect if true but no external catalogs have been added or none are enabled
|
||||
*/
|
||||
'internal' => [
|
||||
'enabled' => true,
|
||||
/**
|
||||
'internal' => [
|
||||
'enabled' => true,
|
||||
/**
|
||||
* syncExternally defaults to false - product catalogs can have 1 or more external catalogs linked to them
|
||||
* which will receive changes to the catalogs and optionally allow for external API access.
|
||||
* Will have no effect if true but no external catalogs have been added or none are enabled
|
||||
*/
|
||||
'syncExternally' => false,
|
||||
],
|
||||
'external' => [ // product catalog settings for external use (as an API server to power an ecommerce site for example)
|
||||
'enabled' => false,
|
||||
],
|
||||
'syncExternally' => false,
|
||||
],
|
||||
'external' => [ // product catalog settings for external use (as an API server to power an ecommerce site for example)
|
||||
'enabled' => false,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
@@ -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>
|
||||
@@ -0,0 +1,10 @@
|
||||
includes:
|
||||
- vendor/cakedc/cakephp-phpstan/extension.neon
|
||||
|
||||
parameters:
|
||||
level: 4
|
||||
paths:
|
||||
- src
|
||||
bootstrapFiles:
|
||||
- tests/bootstrap.php
|
||||
treatPhpDocTypesAsCertain: false
|
||||
+34
-38
@@ -13,9 +13,9 @@ use Cake\Routing\RouteBuilder;
|
||||
/**
|
||||
* Plugin for CakeProducts
|
||||
*/
|
||||
class CakeProductsPlugin extends BasePlugin
|
||||
{
|
||||
/**
|
||||
class CakeProductsPlugin extends BasePlugin {
|
||||
|
||||
/**
|
||||
* Load all the plugin configuration and bootstrap logic.
|
||||
*
|
||||
* The host application is provided as an argument. This allows you to load
|
||||
@@ -24,11 +24,10 @@ class CakeProductsPlugin extends BasePlugin
|
||||
* @param \Cake\Core\PluginApplicationInterface $app The host application
|
||||
* @return void
|
||||
*/
|
||||
public function bootstrap(PluginApplicationInterface $app): void
|
||||
{
|
||||
}
|
||||
public function bootstrap(PluginApplicationInterface $app): void {
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add routes for the plugin.
|
||||
*
|
||||
* If your plugin has many routes and you would like to isolate them into a separate file,
|
||||
@@ -37,57 +36,54 @@ class CakeProductsPlugin extends BasePlugin
|
||||
* @param \Cake\Routing\RouteBuilder $routes The route builder to update.
|
||||
* @return void
|
||||
*/
|
||||
public function routes(RouteBuilder $routes): void
|
||||
{
|
||||
$routes->plugin(
|
||||
'CakeProducts',
|
||||
['path' => '/cake-products'],
|
||||
function (RouteBuilder $builder) {
|
||||
// Add custom routes here
|
||||
public function routes(RouteBuilder $routes): void {
|
||||
$routes->plugin(
|
||||
'CakeProducts',
|
||||
['path' => '/cake-products'],
|
||||
function (RouteBuilder $builder) {
|
||||
// Add custom routes here
|
||||
|
||||
$builder->fallbacks();
|
||||
}
|
||||
);
|
||||
parent::routes($routes);
|
||||
}
|
||||
$builder->fallbacks();
|
||||
},
|
||||
);
|
||||
parent::routes($routes);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add middleware for the plugin.
|
||||
*
|
||||
* @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to update.
|
||||
* @return \Cake\Http\MiddlewareQueue
|
||||
*/
|
||||
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
|
||||
{
|
||||
// Add your middlewares here
|
||||
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue {
|
||||
// Add your middlewares here
|
||||
|
||||
return $middlewareQueue;
|
||||
}
|
||||
return $middlewareQueue;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add commands for the plugin.
|
||||
*
|
||||
* @param \Cake\Console\CommandCollection $commands The command collection to update.
|
||||
* @return \Cake\Console\CommandCollection
|
||||
*/
|
||||
public function console(CommandCollection $commands): CommandCollection
|
||||
{
|
||||
// Add your commands here
|
||||
public function console(CommandCollection $commands): CommandCollection {
|
||||
// Add your commands here
|
||||
|
||||
$commands = parent::console($commands);
|
||||
$commands = parent::console($commands);
|
||||
|
||||
return $commands;
|
||||
}
|
||||
return $commands;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Register application container services.
|
||||
*
|
||||
* @link https://book.cakephp.org/4/en/development/dependency-injection.html#dependency-injection
|
||||
* @param \Cake\Core\ContainerInterface $container The Container to update.
|
||||
* @return void
|
||||
* @link https://book.cakephp.org/4/en/development/dependency-injection.html#dependency-injection
|
||||
*/
|
||||
public function services(ContainerInterface $container): void
|
||||
{
|
||||
// Add your services here
|
||||
}
|
||||
public function services(ContainerInterface $container): void {
|
||||
// Add your services here
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,5 @@ namespace CakeProducts\Controller;
|
||||
|
||||
use App\Controller\AppController as BaseController;
|
||||
|
||||
class AppController extends BaseController
|
||||
{
|
||||
class AppController extends BaseController {
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
]));
|
||||
}
|
||||
}
|
||||
@@ -4,126 +4,115 @@ declare(strict_types=1);
|
||||
namespace CakeProducts\Controller;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Datasource\Exception\RecordNotFoundException;
|
||||
use Cake\Http\Response;
|
||||
use Cake\Log\Log;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\ORM\TableRegistry;
|
||||
use CakeProducts\Model\Table\ProductCatalogsTable;
|
||||
|
||||
/**
|
||||
* ProductCatalogs Controller
|
||||
*
|
||||
* @property ProductCatalogsTable $ProductCatalogs
|
||||
* @property \CakeProducts\Model\Table\ProductCatalogsTable $ProductCatalogs
|
||||
*/
|
||||
class ProductCatalogsController extends AppController
|
||||
{
|
||||
/**
|
||||
class ProductCatalogsController extends AppController {
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
// $this->_defaultTable = 'CakeProducts.ProductCatalogs';
|
||||
// $this->_tableConfigKey = 'CakeProducts.ProductCatalogs.table';
|
||||
}
|
||||
public function initialize(): void {
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Index method
|
||||
*
|
||||
* @return Response|null|void Renders view
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$query = $this->ProductCatalogs->find();
|
||||
$productCatalogs = $this->paginate($query);
|
||||
public function index() {
|
||||
$query = $this->ProductCatalogs->find();
|
||||
$productCatalogs = $this->paginate($query);
|
||||
|
||||
$this->set(compact('productCatalogs'));
|
||||
}
|
||||
$this->set(compact('productCatalogs'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* View method
|
||||
*
|
||||
* @param string|null $id Product Catalog id.
|
||||
* @return Response|null|void Renders view
|
||||
* @throws RecordNotFoundException When record not found.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function view($id = null)
|
||||
{
|
||||
$contain = ['ProductCategories'];
|
||||
if (Configure::read('CakeProducts.internal.syncExternally', false)) {
|
||||
$contain[] = 'ExternalProductCatalogs';
|
||||
}
|
||||
$productCatalog = $this->ProductCatalogs->get($id, contain: $contain);
|
||||
$this->set(compact('productCatalog'));
|
||||
}
|
||||
public function view($id = null) {
|
||||
$contain = ['ProductCategories'];
|
||||
if (Configure::read('CakeProducts.internal.syncExternally', false)) {
|
||||
$contain[] = 'ExternalProductCatalogs';
|
||||
}
|
||||
$productCatalog = $this->ProductCatalogs->get($id, contain: $contain);
|
||||
$this->set(compact('productCatalog'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add method
|
||||
*
|
||||
* @return Response|null|void Redirects on successful add, renders view otherwise.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$productCatalogsTable = $this->ProductCatalogs;
|
||||
$productCatalog = $productCatalogsTable->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
$productCatalog = $productCatalogsTable->patchEntity($productCatalog, $this->request->getData());
|
||||
if ($productCatalogsTable->save($productCatalog)) {
|
||||
$this->Flash->success(__('The product catalog has been saved.'));
|
||||
public function add() {
|
||||
$productCatalogsTable = $this->ProductCatalogs;
|
||||
$productCatalog = $productCatalogsTable->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
$productCatalog = $productCatalogsTable->patchEntity($productCatalog, $this->request->getData());
|
||||
if ($productCatalogsTable->save($productCatalog)) {
|
||||
$this->Flash->success(__('The product catalog has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
Log::debug('failed to save new product catalog errors next');
|
||||
Log::debug(print_r('$productCatalog->getErrors()', true));
|
||||
Log::debug(print_r($productCatalog->getErrors(), true));
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
Log::debug('failed to save new product catalog errors next');
|
||||
Log::debug(print_r('$productCatalog->getErrors()', true));
|
||||
Log::debug(print_r($productCatalog->getErrors(), true));
|
||||
|
||||
$this->Flash->error(__('The product catalog could not be saved. Please, try again.'));
|
||||
}
|
||||
$this->set(compact('productCatalog'));
|
||||
}
|
||||
$this->Flash->error(__('The product catalog could not be saved. Please, try again.'));
|
||||
}
|
||||
$this->set(compact('productCatalog'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Edit method
|
||||
*
|
||||
* @param string|null $id Product Catalog id.
|
||||
* @return Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
* @throws RecordNotFoundException When record not found.
|
||||
* @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)
|
||||
{
|
||||
$productCatalogsTable = $this->ProductCatalogs;
|
||||
$productCatalog = $productCatalogsTable->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$productCatalog = $productCatalogsTable->patchEntity($productCatalog, $this->request->getData());
|
||||
if ($productCatalogsTable->save($productCatalog)) {
|
||||
$this->Flash->success(__('The product catalog has been saved.'));
|
||||
public function edit($id = null) {
|
||||
$productCatalogsTable = $this->ProductCatalogs;
|
||||
$productCatalog = $productCatalogsTable->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$productCatalog = $productCatalogsTable->patchEntity($productCatalog, $this->request->getData());
|
||||
if ($productCatalogsTable->save($productCatalog)) {
|
||||
$this->Flash->success(__('The product catalog has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
$this->Flash->error(__('The product catalog could not be saved. Please, try again.'));
|
||||
}
|
||||
$this->set(compact('productCatalog'));
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
$this->Flash->error(__('The product catalog could not be saved. Please, try again.'));
|
||||
}
|
||||
$this->set(compact('productCatalog'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Delete method
|
||||
*
|
||||
* @param string|null $id Product Catalog id.
|
||||
* @return Response|null Redirects to index.
|
||||
* @throws RecordNotFoundException When record not found.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productCatalogsTable = $this->ProductCatalogs;
|
||||
$productCatalog = $productCatalogsTable->get($id);
|
||||
if ($productCatalogsTable->delete($productCatalog)) {
|
||||
$this->Flash->success(__('The product catalog has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product catalog could not be deleted. Please, try again.'));
|
||||
}
|
||||
public function delete($id = null) {
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productCatalogsTable = $this->ProductCatalogs;
|
||||
$productCatalog = $productCatalogsTable->get($id);
|
||||
if ($productCatalogsTable->delete($productCatalog)) {
|
||||
$this->Flash->success(__('The product catalog has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product catalog could not be deleted. Please, try again.'));
|
||||
}
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Controller;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Log\Log;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\ORM\TableRegistry;
|
||||
use Cake\Utility\Text;
|
||||
|
||||
/**
|
||||
@@ -14,163 +11,154 @@ use Cake\Utility\Text;
|
||||
*
|
||||
* @property \CakeProducts\Model\Table\ProductCategoriesTable $ProductCategories
|
||||
*/
|
||||
class ProductCategoriesController extends AppController
|
||||
{
|
||||
/**
|
||||
class ProductCategoriesController extends AppController {
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
// $this->_defaultTable = 'CakeProducts.ProductCategories';
|
||||
// $this->_tableConfigKey = 'CakeProducts.ProductCategories.table';
|
||||
}
|
||||
public function initialize(): void {
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Index method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$query = $this->ProductCategories->find()
|
||||
->contain(['ProductCatalogs', 'ParentProductCategories']);
|
||||
$productCategories = $this->paginate($query);
|
||||
public function index() {
|
||||
$query = $this->ProductCategories->find()
|
||||
->contain(['ProductCatalogs', 'ParentProductCategories']);
|
||||
$productCategories = $this->paginate($query);
|
||||
|
||||
$this->set(compact('productCategories'));
|
||||
}
|
||||
$this->set(compact('productCategories'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* View method
|
||||
*
|
||||
* @param string|null $id Product Category id.
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function view($id = null)
|
||||
{
|
||||
$productCategory = $this->ProductCategories->get($id, contain: [
|
||||
'ProductCatalogs',
|
||||
'ParentProductCategories',
|
||||
'ChildProductCategories',
|
||||
'ProductCategoryAttributes',
|
||||
'ProductCategoryAttributes.ProductCategoryAttributeOptions',
|
||||
'PrimaryProductPhotos',
|
||||
]);
|
||||
public function view($id = null) {
|
||||
$productCategory = $this->ProductCategories->get($id, contain: [
|
||||
'ProductCatalogs',
|
||||
'ParentProductCategories',
|
||||
'ChildProductCategories',
|
||||
'ProductCategoryAttributes',
|
||||
'ProductCategoryAttributes.ProductCategoryAttributeOptions',
|
||||
'PrimaryProductPhotos',
|
||||
]);
|
||||
|
||||
$productCategoryAttributes = $this->ProductCategories->ProductCategoryAttributes->getAllCategoryAttributesForCategoryId($productCategory->internal_id);
|
||||
$this->set(compact('productCategory', 'productCategoryAttributes'));
|
||||
}
|
||||
$productCategoryAttributes = $this->fetchTable('CakeProducts.ProductCategoryAttributes')->getAllCategoryAttributesForCategoryId($productCategory->internal_id) ?? [];
|
||||
$this->set(compact('productCategory', 'productCategoryAttributes'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$productCategoriesTable = $this->ProductCategories;
|
||||
$productCategory = $productCategoriesTable->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
$postData = $this->request->getData();
|
||||
$saveOptions = [
|
||||
'associated' => [],
|
||||
];
|
||||
if ($this->request->getSession()->read('Auth.User.id')) {
|
||||
$postData['created_by'] = $this->request->getSession()->read('Auth.User.id');
|
||||
}
|
||||
if (!array_key_exists('internal_id', $postData) || !$postData['internal_id']) {
|
||||
$postData['internal_id'] = Text::uuid();
|
||||
}
|
||||
$productCategory = $productCategoriesTable->patchEntity($productCategory, $postData, $saveOptions);
|
||||
if ($productCategory->getErrors()) {
|
||||
Log::debug(print_r('$productCategory->getErrors() next - failed to save from create new product category', true));
|
||||
Log::debug(print_r($productCategory->getErrors(), true));
|
||||
}
|
||||
if ($this->ProductCategories->save($productCategory, $saveOptions)) {
|
||||
$this->Flash->success(__('The product category has been saved.'));
|
||||
public function add() {
|
||||
$productCategoriesTable = $this->ProductCategories;
|
||||
$productCategory = $productCategoriesTable->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
$postData = $this->request->getData();
|
||||
$saveOptions = [
|
||||
'associated' => [],
|
||||
];
|
||||
if ($this->request->getSession()->read('Auth.User.id')) {
|
||||
$postData['created_by'] = $this->request->getSession()->read('Auth.User.id');
|
||||
}
|
||||
if (!array_key_exists('internal_id', $postData) || !$postData['internal_id']) {
|
||||
$postData['internal_id'] = Text::uuid();
|
||||
}
|
||||
$productCategory = $productCategoriesTable->patchEntity($productCategory, $postData, $saveOptions);
|
||||
if ($productCategory->getErrors()) {
|
||||
Log::debug(print_r('$productCategory->getErrors() next - failed to save from create new product category', true));
|
||||
Log::debug(print_r($productCategory->getErrors(), true));
|
||||
}
|
||||
if ($this->ProductCategories->save($productCategory, $saveOptions)) {
|
||||
$this->Flash->success(__('The product category has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
$this->Flash->error(__('The product category could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCatalogs = $productCategoriesTable->ProductCatalogs->find('list', limit: 200)->all();
|
||||
$parentProductCategories = $productCategoriesTable->ParentProductCategories->find('treeList', limit: 200)->toArray();
|
||||
$this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories'));
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
$this->Flash->error(__('The product category could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCatalogs = $this->fetchTable('ProductCatalogs')->find('list', limit: 200)->all();
|
||||
$parentProductCategories = $this->fetchTable('ProductCategories')->find('list', limit: 200)->all();
|
||||
$this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Edit method
|
||||
*
|
||||
* @param string|null $id Product Category id.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
$productCategoriesTable = $this->ProductCategories;
|
||||
$productCategory = $productCategoriesTable->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$postData = $this->request->getData();
|
||||
$productCategory = $productCategoriesTable->patchEntity($productCategory, $postData);
|
||||
if ($productCategoriesTable->save($productCategory)) {
|
||||
$this->Flash->success(__('The product category has been saved.'));
|
||||
public function edit($id = null) {
|
||||
$productCategoriesTable = $this->fetchTable();
|
||||
$productCategory = $this->ProductCategories->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$postData = $this->request->getData();
|
||||
$productCategory = $this->ProductCategories->patchEntity($productCategory, $postData);
|
||||
if ($this->ProductCategories->save($productCategory)) {
|
||||
$this->Flash->success(__('The product category has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
$this->Flash->error(__('The product category could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCatalogs = $productCategoriesTable->ProductCatalogs->find('list', limit: 200)->all();
|
||||
$parentProductCategories = $productCategoriesTable->ParentProductCategories->find('list', limit: 200)->all();
|
||||
$this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories'));
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
$this->Flash->error(__('The product category could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCatalogs = $this->fetchTable('ProductCatalogs')->find('list', limit: 200)->all();
|
||||
$parentProductCategories = $this->fetchTable('ProductCategories')->find('list', limit: 200)->all();
|
||||
|
||||
/**
|
||||
$this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete method
|
||||
*
|
||||
* @param string|null $id Product Category id.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productCategoriesTable = $this->ProductCategories;
|
||||
public function delete($id = null) {
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
|
||||
$productCategory = $productCategoriesTable->get($id);
|
||||
$productCategory = $this->ProductCategories->get($id);
|
||||
// $productCategoriesTable->behaviors()->get('Tree')->setConfig([
|
||||
// 'scope' => [
|
||||
// 'product_catalog_id' => $productCategory->product_catalog_id,
|
||||
// ],
|
||||
// ]);
|
||||
if ($productCategoriesTable->delete($productCategory)) {
|
||||
$this->Flash->success(__('The product category has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product category could not be deleted. Please, try again.'));
|
||||
}
|
||||
if ($this->ProductCategories->delete($productCategory)) {
|
||||
$this->Flash->success(__('The product category has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product category could not be deleted. Please, try again.'));
|
||||
}
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function select()
|
||||
{
|
||||
$productCategoriesTable = $this->ProductCategories;
|
||||
$productCategoriesTable->behaviors()->get('Tree')->setConfig([
|
||||
'scope' => [
|
||||
'product_catalog_id' => $this->request->getQuery('product_catalog_id', -1),
|
||||
],
|
||||
]);
|
||||
$productCategoriesQ = $this->request->getQuery('form', 'product_category') === 'product' ?
|
||||
$productCategoriesTable->find('treeList', keyPath: 'internal_id', valuePath: 'name') :
|
||||
$productCategoriesTable->find('treeList');
|
||||
public function select() {
|
||||
$this->ProductCategories->getBehavior('Tree')->setConfig([
|
||||
'scope' => [
|
||||
'product_catalog_id' => $this->request->getQuery('product_catalog_id', -1),
|
||||
],
|
||||
]);
|
||||
$productCategoriesQ = $this->request->getQuery('form', 'product_category') === 'product' ?
|
||||
$this->ProductCategories->find('treeList', keyPath: 'internal_id', valuePath: 'name') :
|
||||
$this->ProductCategories->find('treeList');
|
||||
|
||||
$productCategories = $productCategoriesQ
|
||||
->orderBy(['ProductCategories.name'])
|
||||
->toArray();
|
||||
$productCategories = $productCategoriesQ
|
||||
->orderBy(['ProductCategories.name'])
|
||||
->toArray();
|
||||
|
||||
$this->set(compact('productCategories'));
|
||||
}
|
||||
|
||||
$this->set(compact('productCategories'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,60 +3,55 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Controller;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Log\Log;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\ORM\TableRegistry;
|
||||
|
||||
/**
|
||||
* ProductCategoryAttributeOptions Controller
|
||||
*
|
||||
* @property \CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable $ProductCategoryAttributeOptions
|
||||
*/
|
||||
class ProductCategoryAttributeOptionsController extends AppController
|
||||
{
|
||||
/**
|
||||
class ProductCategoryAttributeOptionsController extends AppController {
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
public function initialize(): void {
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
// $this->_defaultTable = 'CakeProducts.ProductCategoryAttributeOptions';
|
||||
// $this->_tableConfigKey = 'CakeProducts.ProductCategoryAttributeOptions.table';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
Log::debug('inside product category attribute options controller add');
|
||||
public function add() {
|
||||
Log::debug('inside product category attribute options controller add');
|
||||
|
||||
$productCategoryAttributeOption = $this->ProductCategoryAttributeOptions->newEmptyEntity();
|
||||
$this->set(compact('productCategoryAttributeOption'));
|
||||
}
|
||||
$productCategoryAttributeOption = $this->ProductCategoryAttributeOptions->newEmptyEntity();
|
||||
$this->set(compact('productCategoryAttributeOption'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Delete method
|
||||
*
|
||||
* @param string|null $id Product Category Attribute Option id.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productCategoryAttributeOptionsTable = $this->ProductCategoryAttributeOptions;
|
||||
public function delete($id = null) {
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productCategoryAttributeOptionsTable = $this->ProductCategoryAttributeOptions;
|
||||
|
||||
$productCategoryAttributeOption = $productCategoryAttributeOptionsTable->get($id);
|
||||
if ($productCategoryAttributeOptionsTable->delete($productCategoryAttributeOption)) {
|
||||
$this->Flash->success(__('The product category attribute option has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product category attribute option could not be deleted. Please, try again.'));
|
||||
}
|
||||
$productCategoryAttributeOption = $productCategoryAttributeOptionsTable->get($id);
|
||||
if ($productCategoryAttributeOptionsTable->delete($productCategoryAttributeOption)) {
|
||||
$this->Flash->success(__('The product category attribute option has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product category attribute option could not be deleted. Please, try again.'));
|
||||
}
|
||||
|
||||
return $this->redirect(['controller' => 'ProductCategoryAttributes', 'action' => 'view', $productCategoryAttributeOption->product_category_attribute_id]);
|
||||
}
|
||||
|
||||
return $this->redirect(['controller' => 'ProductCategoryAttributes', 'action' => 'view', $productCategoryAttributeOption->product_category_attribute_id]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,172 +3,154 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Controller;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Datasource\Exception\RecordNotFoundException;
|
||||
use Cake\Http\Response;
|
||||
use Cake\Log\Log;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\ORM\TableRegistry;
|
||||
use CakeProducts\Model\Enum\ProductCategoryAttributeTypeId;
|
||||
use CakeProducts\Model\Table\ProductCategoryAttributesTable;
|
||||
|
||||
/**
|
||||
* ProductCategoryAttributes Controller
|
||||
*
|
||||
* @property ProductCategoryAttributesTable $ProductCategoryAttributes
|
||||
* @property \CakeProducts\Model\Table\ProductCategoryAttributesTable $ProductCategoryAttributes
|
||||
*/
|
||||
class ProductCategoryAttributesController extends AppController
|
||||
{
|
||||
/**
|
||||
class ProductCategoryAttributesController extends AppController {
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
// $this->_defaultTable = 'CakeProducts.ProductCategoryAttributes';
|
||||
// $this->_tableConfigKey = 'CakeProducts.ProductCategoryAttributes.table';
|
||||
}
|
||||
public function initialize(): void {
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Index method
|
||||
*
|
||||
* @return Response|null|void Renders view
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$query = $this->ProductCategoryAttributes->find()
|
||||
->contain(['ProductCategories']);
|
||||
$productCategoryAttributes = $this->paginate($query);
|
||||
public function index() {
|
||||
$query = $this->fetchTable()->find()
|
||||
->contain(['ProductCategories']);
|
||||
$productCategoryAttributes = $this->paginate($query);
|
||||
|
||||
$this->set(compact('productCategoryAttributes'));
|
||||
}
|
||||
$this->set(compact('productCategoryAttributes'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* View method
|
||||
*
|
||||
* @param string|null $id Product Category Attribute id.
|
||||
* @return Response|null|void Renders view
|
||||
* @throws RecordNotFoundException When record not found.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function view($id = null)
|
||||
{
|
||||
$productCategoryAttribute = $this->ProductCategoryAttributes->get($id, contain: [
|
||||
'ProductCategories',
|
||||
'ProductCategoryAttributeOptions',
|
||||
]);
|
||||
public function view($id = null) {
|
||||
$productCategoryAttribute = $this->fetchTable()->get($id, contain: [
|
||||
'ProductCategories',
|
||||
'ProductCategoryAttributeOptions',
|
||||
]);
|
||||
|
||||
$this->set(compact('productCategoryAttribute'));
|
||||
}
|
||||
$this->set(compact('productCategoryAttribute'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add method
|
||||
*
|
||||
* @return Response|null|void Redirects on successful add, renders view otherwise.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$productCategoryAttributesTable = $this->ProductCategoryAttributes;
|
||||
$productCategoryAttribute = $productCategoryAttributesTable->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
$postData = $this->request->getData();
|
||||
if ($this->request->getSession()->read('Auth.User.id')) {
|
||||
$postData['created_by'] = $this->request->getSession()->read('Auth.User.id');
|
||||
}
|
||||
Log::debug(print_r('$postData', true));
|
||||
Log::debug(print_r($postData, true));
|
||||
$saveOptions = [
|
||||
'associated' => [
|
||||
'ProductCategoryAttributeOptions'
|
||||
],
|
||||
];
|
||||
$productCategoryAttribute = $productCategoryAttributesTable->patchEntity($productCategoryAttribute, $postData, $saveOptions);
|
||||
if ($productCategoryAttribute->getErrors()) {
|
||||
Log::debug(print_r('$productCategoryAttribute->getErrors() next - failed to save from create new product category attribute', true));
|
||||
Log::debug(print_r($productCategoryAttribute->getErrors(), true));
|
||||
}
|
||||
if ($productCategoryAttributesTable->save($productCategoryAttribute, $saveOptions)) {
|
||||
$this->Flash->success(__('The product category attribute has been saved.'));
|
||||
public function add() {
|
||||
$productCategoryAttribute = $this->fetchTable()->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
$postData = $this->request->getData();
|
||||
if ($this->request->getSession()->read('Auth.User.id')) {
|
||||
$postData['created_by'] = $this->request->getSession()->read('Auth.User.id');
|
||||
}
|
||||
Log::debug(print_r('$postData', true));
|
||||
Log::debug(print_r($postData, true));
|
||||
$saveOptions = [
|
||||
'associated' => [
|
||||
'ProductCategoryAttributeOptions',
|
||||
],
|
||||
];
|
||||
$productCategoryAttribute = $this->fetchTable()->patchEntity($productCategoryAttribute, $postData, $saveOptions);
|
||||
if ($productCategoryAttribute->getErrors()) {
|
||||
Log::debug(print_r('$productCategoryAttribute->getErrors() next - failed to save from create new product category attribute', true));
|
||||
Log::debug(print_r($productCategoryAttribute->getErrors(), true));
|
||||
}
|
||||
if ($this->fetchTable()->save($productCategoryAttribute, $saveOptions)) {
|
||||
$this->Flash->success(__('The product category attribute has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
Log::debug('failed to save new product category attribute errors next');
|
||||
Log::debug(print_r('$productCategoryAttribute->getErrors()', true));
|
||||
Log::debug(print_r($productCategoryAttribute->getErrors(), true));
|
||||
$this->Flash->error(__('The product category attribute could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategories = $productCategoryAttributesTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all();
|
||||
$this->set(compact('productCategoryAttribute', 'productCategories'));
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
Log::debug('failed to save new product category attribute errors next');
|
||||
Log::debug(print_r('$productCategoryAttribute->getErrors()', true));
|
||||
Log::debug(print_r($productCategoryAttribute->getErrors(), true));
|
||||
$this->Flash->error(__('The product category attribute could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategories = $this->fetchTable()->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all();
|
||||
$this->set(compact('productCategoryAttribute', 'productCategories'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Edit method
|
||||
*
|
||||
* @param string|null $id Product Category Attribute id.
|
||||
* @return Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
* @throws RecordNotFoundException When record not found.
|
||||
* @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)
|
||||
{
|
||||
$productCategoryAttributesTable = $this->ProductCategoryAttributes;
|
||||
$productCategoryAttribute = $productCategoryAttributesTable->get($id, contain: ['ProductCategoryAttributeOptions']);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$postData = $this->request->getData();
|
||||
$saveOptions = [
|
||||
'associated' => ['ProductCategoryAttributeOptions'],
|
||||
];
|
||||
Log::debug(print_r('$postData', true));
|
||||
Log::debug(print_r($postData, true));
|
||||
public function edit($id = null) {
|
||||
$productCategoryAttribute = $this->fetchTable()->get($id, contain: ['ProductCategoryAttributeOptions']);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$postData = $this->request->getData();
|
||||
$saveOptions = [
|
||||
'associated' => ['ProductCategoryAttributeOptions'],
|
||||
];
|
||||
Log::debug(print_r('$postData', true));
|
||||
Log::debug(print_r($postData, true));
|
||||
// if ($this->request->getData('attribute_type_id') != ProductCategoryAttributeTypeId::Constrained) {
|
||||
// $saveOptions['associated'] = [];
|
||||
// $postData['product_category_attribute_options'] = [];
|
||||
// }
|
||||
Log::debug(print_r('$postData', true));
|
||||
Log::debug(print_r($postData, true));
|
||||
$productCategoryAttribute = $productCategoryAttributesTable->patchEntity($productCategoryAttribute, $postData, $saveOptions);
|
||||
Log::debug(print_r('$postData', true));
|
||||
Log::debug(print_r($postData, true));
|
||||
$productCategoryAttribute = $this->fetchTable()->patchEntity($productCategoryAttribute, $postData, $saveOptions);
|
||||
|
||||
if ($productCategoryAttributesTable->save($productCategoryAttribute, $saveOptions)) {
|
||||
$this->Flash->success(__('The product category attribute has been saved.'));
|
||||
if ($this->fetchTable()->save($productCategoryAttribute, $saveOptions)) {
|
||||
$this->Flash->success(__('The product category attribute has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
Log::debug('failed to save product category attribute on edit errors next');
|
||||
Log::debug(print_r('$productCategoryAttribute->getErrors()', true));
|
||||
Log::debug(print_r($productCategoryAttribute->getErrors(), true));
|
||||
$this->Flash->error(__('The product category attribute could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategories = $productCategoryAttributesTable->ProductCategories->find('list', limit: 200, keyField: 'internal_id', valueField: 'name')->all();
|
||||
$this->set(compact('productCategoryAttribute', 'productCategories'));
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
Log::debug('failed to save product category attribute on edit errors next');
|
||||
Log::debug(print_r('$productCategoryAttribute->getErrors()', true));
|
||||
Log::debug(print_r($productCategoryAttribute->getErrors(), true));
|
||||
$this->Flash->error(__('The product category attribute could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategories = $this->fetchTable('ProductCategories')->find('list', limit: 200, keyField: 'internal_id', valueField: 'name')->all();
|
||||
$this->set(compact('productCategoryAttribute', 'productCategories'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Delete method
|
||||
*
|
||||
* @param string|null $id Product Category Attribute id.
|
||||
* @return Response|null Redirects to index.
|
||||
* @throws RecordNotFoundException When record not found.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
public function delete($id = null) {
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
|
||||
$productCategoryAttributesTable = $this->ProductCategoryAttributes;
|
||||
$productCategoryAttribute = $productCategoryAttributesTable->get($id);
|
||||
if ($productCategoryAttributesTable->delete($productCategoryAttribute)) {
|
||||
$this->Flash->success(__('The product category attribute has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product category attribute could not be deleted. Please, try again.'));
|
||||
}
|
||||
$productCategoryAttribute = $this->fetchTable()->get($id);
|
||||
if ($this->fetchTable()->delete($productCategoryAttribute)) {
|
||||
$this->Flash->success(__('The product category attribute has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product category attribute could not be deleted. Please, try again.'));
|
||||
}
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form()
|
||||
{
|
||||
$productCategories = $this->ProductCategoryAttributes->getAllCategoryAttributesForCategoryId($this->request->getQuery('product_category_id', '-1'));
|
||||
public function form() {
|
||||
$productCategories = $this->fetchTable()->getAllCategoryAttributesForCategoryId($this->request->getQuery('product_category_id', '-1'));
|
||||
|
||||
$this->set(compact('productCategories'));
|
||||
}
|
||||
|
||||
$this->set(compact('productCategories'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,158 +3,147 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Controller;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Log\Log;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\ORM\TableRegistry;
|
||||
|
||||
/**
|
||||
* ProductCategoryVariants Controller
|
||||
*
|
||||
* @property \App\Model\Table\ProductCategoryVariantsTable $ProductCategoryVariants
|
||||
* @property \CakeProducts\Model\Table\ProductCategoryVariantsTable $ProductCategoryVariants
|
||||
*/
|
||||
class ProductCategoryVariantsController extends AppController
|
||||
{
|
||||
/**
|
||||
class ProductCategoryVariantsController extends AppController {
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
// $this->_defaultTable = 'CakeProducts.ProductCategoryVariants';
|
||||
// $this->_tableConfigKey = 'CakeProducts.ProductCategoryVariants.table';
|
||||
}
|
||||
public function initialize(): void {
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Index method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$query = $this->ProductCategoryVariants->find()
|
||||
->contain(['ProductCategories', 'Products', 'ProductCategoryVariantOptions']);
|
||||
$productCategoryVariants = $this->paginate($query);
|
||||
public function index() {
|
||||
$query = $this->fetchTable()->find()
|
||||
->contain(['ProductCategories', 'Products', 'ProductCategoryVariantOptions']);
|
||||
$productCategoryVariants = $this->paginate($query);
|
||||
|
||||
$this->set(compact('productCategoryVariants'));
|
||||
}
|
||||
$this->set(compact('productCategoryVariants'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* View method
|
||||
*
|
||||
* @param string|null $id Product Category Variant id.
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function view($id = null)
|
||||
{
|
||||
$productCategoryVariant = $this->ProductCategoryVariants->get($id, contain: [
|
||||
'ProductCategories',
|
||||
'Products',
|
||||
'ProductCategoryVariantOptions',
|
||||
]);
|
||||
$this->set(compact('productCategoryVariant'));
|
||||
}
|
||||
public function view($id = null) {
|
||||
$productCategoryVariant = $this->fetchTable()->get($id, contain: [
|
||||
'ProductCategories',
|
||||
'Products',
|
||||
'ProductCategoryVariantOptions',
|
||||
]);
|
||||
$this->set(compact('productCategoryVariant'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$productCategoryVariantsTable = $this->ProductCategoryVariants;
|
||||
public function add() {
|
||||
$productCategoryVariantsTable = $this->fetchTable();
|
||||
|
||||
$productCategoryVariant = $productCategoryVariantsTable->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
$postData = $this->request->getData();
|
||||
if ($this->request->getSession()->read('Auth.User.id')) {
|
||||
$postData['created_by'] = $this->request->getSession()->read('Auth.User.id');
|
||||
}
|
||||
$saveOptions = [
|
||||
'associated' => [
|
||||
'ProductCategoryVariantOptions'
|
||||
],
|
||||
];
|
||||
$productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $postData, $saveOptions);
|
||||
if ($productCategoryVariantsTable->save($productCategoryVariant, $saveOptions)) {
|
||||
$this->Flash->success(__('The product category variant has been saved.'));
|
||||
$productCategoryVariant = $productCategoryVariantsTable->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
$postData = $this->request->getData();
|
||||
if ($this->request->getSession()->read('Auth.User.id')) {
|
||||
$postData['created_by'] = $this->request->getSession()->read('Auth.User.id');
|
||||
}
|
||||
$saveOptions = [
|
||||
'associated' => [
|
||||
'ProductCategoryVariantOptions',
|
||||
],
|
||||
];
|
||||
$productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $postData, $saveOptions);
|
||||
if ($productCategoryVariantsTable->save($productCategoryVariant, $saveOptions)) {
|
||||
$this->Flash->success(__('The product category variant has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
Log::debug('print_r($productCategoryVariant->getErrors(), true) failed to save in product category variants add');
|
||||
Log::debug(print_r($productCategoryVariant->getErrors(), true));
|
||||
$this->Flash->error(__('The product category variant could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategories = $productCategoryVariantsTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all();
|
||||
$products = $productCategoryVariantsTable->Products->find('list')->all();
|
||||
$this->set(compact('productCategoryVariant', 'productCategories', 'products'));
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
Log::debug('print_r($productCategoryVariant->getErrors(), true) failed to save in product category variants add');
|
||||
Log::debug(print_r($productCategoryVariant->getErrors(), true));
|
||||
$this->Flash->error(__('The product category variant could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategories = $productCategoryVariantsTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all();
|
||||
$products = $productCategoryVariantsTable->Products->find('list')->all();
|
||||
$this->set(compact('productCategoryVariant', 'productCategories', 'products'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Edit method
|
||||
*
|
||||
* @param string|null $id Product Category Variant id.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
$productCategoryVariantsTable = $this->ProductCategoryVariants;
|
||||
$productCategoryVariant = $productCategoryVariantsTable->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$postData = $this->request->getData();
|
||||
public function edit($id = null) {
|
||||
$productCategoryVariant = $this->fetchTable()->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$postData = $this->request->getData();
|
||||
// if ($this->request->getSession()->read('Auth.User.id')) {
|
||||
// $postData['created_by'] = $this->request->getSession()->read('Auth.User.id');
|
||||
// }
|
||||
$postData = $productCategoryVariant->is_system_variant ? ['product_category_variant_options' => $this->request->getData('product_category_variant_options')] : $postData;
|
||||
$saveOptions = [
|
||||
'fields' => $productCategoryVariant->is_system_variant ? [
|
||||
'product_category_variant_options',
|
||||
] : [
|
||||
'name',
|
||||
'product_category_id',
|
||||
'enabled',
|
||||
'product_category_variant_options',
|
||||
],
|
||||
'associated' => [
|
||||
'ProductCategoryVariantOptions'
|
||||
],
|
||||
];
|
||||
$productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $postData, $saveOptions);
|
||||
$postData = $productCategoryVariant->is_system_variant ? ['product_category_variant_options' => $this->request->getData('product_category_variant_options')] : $postData;
|
||||
$saveOptions = [
|
||||
'fields' => $productCategoryVariant->is_system_variant ? [
|
||||
'product_category_variant_options',
|
||||
] : [
|
||||
'name',
|
||||
'product_category_id',
|
||||
'enabled',
|
||||
'product_category_variant_options',
|
||||
],
|
||||
'associated' => [
|
||||
'ProductCategoryVariantOptions',
|
||||
],
|
||||
];
|
||||
$productCategoryVariant = $this->fetchTable()->patchEntity($productCategoryVariant, $postData, $saveOptions);
|
||||
// dd($postData);
|
||||
if ($productCategoryVariantsTable->save($productCategoryVariant, $saveOptions)) {
|
||||
$this->Flash->success(__('The product category variant has been saved.'));
|
||||
if ($this->fetchTable()->save($productCategoryVariant, $saveOptions)) {
|
||||
$this->Flash->success(__('The product category variant has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
// dd($productCategoryVariant->getErrors());
|
||||
$this->Flash->error(__('The product category variant could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategories = $productCategoryVariantsTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all();
|
||||
$products = isset($productCategoryVariant->product_category_id) ? $productCategoryVariantsTable->Products->find('list', limit: 200)->where(['product_category_id' => $productCategoryVariant->product_category_id])->all() : [];
|
||||
$this->set(compact('productCategoryVariant', 'productCategories', 'products'));
|
||||
}
|
||||
$this->Flash->error(__('The product category variant could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategories = $this->fetchTable('ProductCategories')->find('list', keyField: 'internal_id', valueField: 'name')->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'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Delete method
|
||||
*
|
||||
* @param string|null $id Product Category Variant id.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productCategoryVariantsTable = $this->ProductCategoryVariants;
|
||||
public function delete($id = null) {
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
|
||||
$productCategoryVariant = $productCategoryVariantsTable->get($id);
|
||||
if ($productCategoryVariantsTable->delete($productCategoryVariant)) {
|
||||
$this->Flash->success(__('The product category variant has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product category variant could not be deleted. Please, try again.'));
|
||||
}
|
||||
$productCategoryVariant = $this->fetchTable()->get($id);
|
||||
if ($this->fetchTable()->delete($productCategoryVariant)) {
|
||||
$this->Flash->success(__('The product category variant has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product category variant could not be deleted. Please, try again.'));
|
||||
}
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,211 +4,210 @@ declare(strict_types=1);
|
||||
namespace CakeProducts\Controller;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Datasource\Exception\RecordNotFoundException;
|
||||
use Cake\Http\Exception\ForbiddenException;
|
||||
use Cake\Http\Response;
|
||||
use Cake\Utility\Text;
|
||||
use CakeProducts\Model\Table\ProductPhotosTable;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
|
||||
/**
|
||||
* ProductPhotos Controller
|
||||
*
|
||||
* @property ProductPhotosTable $ProductPhotos
|
||||
* @property \CakeProducts\Model\Table\ProductPhotosTable $ProductPhotos
|
||||
*/
|
||||
class ProductPhotosController extends AppController
|
||||
{
|
||||
/**
|
||||
class ProductPhotosController extends AppController {
|
||||
|
||||
/**
|
||||
* Index method
|
||||
*
|
||||
* @return Response|null|void Renders view
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$query = $this->ProductPhotos->find()
|
||||
->contain(['Products', 'ProductSkus', 'ProductCategories']);
|
||||
$productPhotos = $this->paginate($query);
|
||||
public function index() {
|
||||
$query = $this->ProductPhotos->find()
|
||||
->contain(['Products', 'ProductSkus', 'ProductCategories']);
|
||||
$productPhotos = $this->paginate($query);
|
||||
|
||||
$this->set(compact('productPhotos'));
|
||||
}
|
||||
$this->set(compact('productPhotos'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* View method
|
||||
*
|
||||
* @param string|null $id Product Photo id.
|
||||
* @return Response|null|void Renders view
|
||||
* @throws RecordNotFoundException When record not found.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function view($id = null)
|
||||
{
|
||||
$productPhoto = $this->ProductPhotos->get($id, contain: ['Products', 'ProductSkus', 'ProductCategories']);
|
||||
$this->set(compact('productPhoto'));
|
||||
}
|
||||
public function view($id = null) {
|
||||
$productPhoto = $this->ProductPhotos->get($id, contain: ['Products', 'ProductSkus', 'ProductCategories']);
|
||||
$this->set(compact('productPhoto'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add method
|
||||
*
|
||||
* @return Response|null|void Redirects on successful add, renders view otherwise.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$productPhotosTable = $this->ProductPhotos;
|
||||
$productPhoto = $productPhotosTable->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
if (!$this->request->getData('photo')) {
|
||||
$this->Flash->error('Photo is required. Nothing was uploaded. Please try again.');
|
||||
$productCategory = $productPhoto->product_category_id ? $productPhotosTable->ProductCategories->find()->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null;
|
||||
$productCatalogs = $productPhotosTable->ProductCategories->ProductCatalogs->find('list')->toArray();
|
||||
$this->set(compact('productPhoto', 'productCatalogs', 'productCategory'));
|
||||
public function add() {
|
||||
$productPhoto = $this->fetchTable()->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
// dd($this->request->getData());
|
||||
if (!$this->request->getData('photo')) {
|
||||
$this->Flash->error('Photo is required. Nothing was uploaded. Please try again.');
|
||||
$productCategory = $productPhoto->product_category_id ? $this->fetchTable('CakeProducts.ProductCategories')->find()
|
||||
->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null;
|
||||
$productCatalogs = $this->fetchTable('CakeProducts.ProductCatalogs')->find('list')->toArray();
|
||||
$this->set(compact('productPhoto', 'productCatalogs', 'productCategory'));
|
||||
|
||||
return;
|
||||
}
|
||||
$uuid = Text::uuid();
|
||||
$postData = $this->request->getData();
|
||||
$postData['id'] = $uuid;
|
||||
$baseDir = Configure::readOrFail('CakeProducts.photos.directory');
|
||||
$path = '';
|
||||
if ($this->request->getData('product_sku_id')) {
|
||||
$productSku = $productPhotosTable->ProductSkus
|
||||
->find()
|
||||
->contain(['Products', 'Products.ProductCategories'])
|
||||
->where([
|
||||
'ProductSkus.id' => $this->request->getData('product_sku_id'),
|
||||
])
|
||||
->first();
|
||||
$path = $productSku ? $productSku->product_id . DS . 'skus' . DS . $productSku->id : $path;
|
||||
return;
|
||||
}
|
||||
$uuid = Text::uuid();
|
||||
$postData = $this->request->getData();
|
||||
$postData['id'] = $uuid;
|
||||
$baseDir = Configure::readOrFail('CakeProducts.photos.directory');
|
||||
$path = '';
|
||||
if ($this->request->getData('product_sku_id')) {
|
||||
$productSku = $this->fetchTable('CakeProducts.ProductSkus')
|
||||
->find()
|
||||
->contain(['Products', 'Products.ProductCategories'])
|
||||
->where([
|
||||
'ProductSkus.id' => $this->request->getData('product_sku_id'),
|
||||
])
|
||||
->first();
|
||||
/**
|
||||
* @var \CakeProducts\Model\Entity\ProductSku|null $productSku
|
||||
*/
|
||||
$path = $productSku ? $productSku->product_id . DS . 'skus' . DS . $productSku->id : $path;
|
||||
|
||||
$postData['product_id'] = $productSku->product->id ?? null;
|
||||
$postData['product_category_id'] = $productSku->product->product_category->internal_id ?? null;
|
||||
} else if ($this->request->getData('product_id')) {
|
||||
$product = $productPhotosTable->Products
|
||||
->find()
|
||||
->contain(['ProductCategories'])
|
||||
->where([
|
||||
'Products.id' => $this->request->getData('product_id'),
|
||||
])
|
||||
->first();
|
||||
$path = $product ? $product->id : $path;
|
||||
$postData['product_category_id'] = $product->product_category->internal_id ?? null;
|
||||
$postData['product_id'] = $productSku->product->id ?? null;
|
||||
$postData['product_category_id'] = $productSku->product->product_category->internal_id ?? null;
|
||||
} else if ($this->request->getData('product_id')) {
|
||||
$product = $this->fetchTable('CakeProducts.Products')
|
||||
->find()
|
||||
->contain(['ProductCategories'])
|
||||
->where([
|
||||
'Products.id' => $this->request->getData('product_id'),
|
||||
])
|
||||
->first();
|
||||
/**
|
||||
* @var \CakeProducts\Model\Entity\Product|null $product
|
||||
*/
|
||||
$path = $product ? $product->id : $path;
|
||||
$postData['product_category_id'] = $product->product_category->internal_id ?? null;
|
||||
|
||||
} else if ($this->request->getData('product_category_id')) {
|
||||
$categoryId = $this->request->getData('product_category_id');
|
||||
// @link https://developer.wordpress.org/reference/functions/wp_is_uuid/
|
||||
$regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/';
|
||||
$field = preg_match($regex, $categoryId) ? 'ProductCategories.internal_id' : 'ProductCategories.id';
|
||||
$productCategoryPosted = $productPhotosTable->ProductCategories
|
||||
->find()
|
||||
->where([
|
||||
$field => $categoryId,
|
||||
])
|
||||
->first();
|
||||
$postData['product_category_id'] = $productCategoryPosted->internal_id ?? null;
|
||||
$path = $productCategoryPosted ? 'categories' : $path;
|
||||
}
|
||||
/**
|
||||
* @var UploadedFileInterface $photoObject
|
||||
} else if ($this->request->getData('product_category_id')) {
|
||||
$categoryId = $this->request->getData('product_category_id');
|
||||
// @link https://developer.wordpress.org/reference/functions/wp_is_uuid/
|
||||
$regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/';
|
||||
$field = preg_match($regex, $categoryId) ? 'ProductCategories.internal_id' : 'ProductCategories.id';
|
||||
$productCategoryPosted = $this->fetchTable('CakeProducts.ProductCategories')
|
||||
->find()
|
||||
->where([
|
||||
$field => $categoryId,
|
||||
])
|
||||
->first();
|
||||
$postData['product_category_id'] = $productCategoryPosted->internal_id ?? null;
|
||||
$path = $productCategoryPosted ? 'categories' : $path;
|
||||
}
|
||||
/**
|
||||
* @var \Psr\Http\Message\UploadedFileInterface $photoObject
|
||||
*/
|
||||
$photoObject = $this->request->getData('photo');
|
||||
$ext = substr(strtolower($photoObject->getClientFilename()), -4);
|
||||
$ext = str_starts_with($ext, '.') ? substr($ext, 1) : $ext;
|
||||
$allowedFileTypes = ['png', 'jpeg', 'jpg'];
|
||||
if (!in_array($ext, $allowedFileTypes)) {
|
||||
throw new ForbiddenException('Invalid file type. Only PNG and JPG types are allowed.');
|
||||
}
|
||||
$photoObject = $this->request->getData('photo');
|
||||
$ext = substr(strtolower($photoObject->getClientFilename()), -4);
|
||||
$ext = str_starts_with($ext, '.') ? substr($ext, 1) : $ext;
|
||||
$allowedFileTypes = ['png', 'jpeg', 'jpg'];
|
||||
if (!in_array($ext, $allowedFileTypes)) {
|
||||
throw new ForbiddenException('Invalid file type. Only PNG and JPG types are allowed.');
|
||||
}
|
||||
|
||||
$fullPath = $baseDir . $path;
|
||||
if (!file_exists($fullPath)) {
|
||||
if (!mkdir($fullPath, 0777, true)) {
|
||||
throw new ForbiddenException('Failed to create the required folders. Please check the folder permissions and try again.');
|
||||
}
|
||||
}
|
||||
$destination = $fullPath . DS . $uuid . '.' . $ext;
|
||||
$fullPath = $baseDir . $path;
|
||||
if (!file_exists($fullPath)) {
|
||||
if (!mkdir($fullPath, 0777, true)) {
|
||||
throw new ForbiddenException('Failed to create the required folders. Please check the folder permissions and try again.');
|
||||
}
|
||||
}
|
||||
$destination = $fullPath . DS . $uuid . '.' . $ext;
|
||||
|
||||
// Existing files with the same name will be replaced.
|
||||
$photoObject->moveTo($destination);
|
||||
if (!file_exists($destination)) {
|
||||
throw new ForbiddenException('Failed to move the uploaded image to the appropriate folder. Please try again.');
|
||||
}
|
||||
// Existing files with the same name will be replaced.
|
||||
$photoObject->moveTo($destination);
|
||||
if (!file_exists($destination)) {
|
||||
throw new ForbiddenException('Failed to move the uploaded image to the appropriate folder. Please try again.');
|
||||
}
|
||||
|
||||
$postData['photo_dir'] = $path;
|
||||
$postData['photo_filename'] = $uuid . '.' . $ext;
|
||||
$postData['photo_dir'] = $path;
|
||||
$postData['photo_filename'] = $uuid . '.' . $ext;
|
||||
// dd($postData);
|
||||
|
||||
$productPhoto = $productPhotosTable->patchEntity($productPhoto, $postData);
|
||||
if ($productPhotosTable->save($productPhoto)) {
|
||||
$this->Flash->success(__('The product photo has been saved.'));
|
||||
$productPhoto = $this->fetchTable()->patchEntity($productPhoto, $postData);
|
||||
if ($this->fetchTable()->save($productPhoto)) {
|
||||
$this->Flash->success(__('The product photo has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
// dd($productPhoto->getErrors());
|
||||
$this->Flash->error(__('The product photo could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategory = $productPhoto->product_category_id ? $productPhotosTable->ProductCategories->find()->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null;
|
||||
$productCatalogs = $productPhotosTable->ProductCategories->ProductCatalogs->find('list')->toArray();
|
||||
$this->set(compact('productPhoto', 'productCatalogs', 'productCategory'));
|
||||
}
|
||||
$this->Flash->error(__('The product photo could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategory = $productPhoto->product_category_id ? $this->fetchTable('ProductCategories')->find()
|
||||
->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null;
|
||||
$productCatalogs = $this->fetchTable('ProductCatalogs')->find('list')->toArray();
|
||||
$this->set(compact('productPhoto', 'productCatalogs', 'productCategory'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Edit method
|
||||
*
|
||||
* @param string|null $id Product Photo id.
|
||||
* @return Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
* @throws RecordNotFoundException When record not found.
|
||||
* @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)
|
||||
{
|
||||
$productPhotosTable = $this->ProductPhotos;
|
||||
$productPhoto = $productPhotosTable->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$postData = $this->request->getData();
|
||||
public function edit($id = null) {
|
||||
$productPhoto = $this->fetchTable()->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$postData = $this->request->getData();
|
||||
|
||||
$productPhoto = $productPhotosTable->patchEntity($productPhoto, $postData);
|
||||
if ($productPhotosTable->save($productPhoto)) {
|
||||
$this->Flash->success(__('The product photo has been saved.'));
|
||||
$productPhoto = $this->fetchTable()->patchEntity($productPhoto, $postData);
|
||||
if ($this->fetchTable()->save($productPhoto)) {
|
||||
$this->Flash->success(__('The product photo has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
$this->Flash->error(__('The product photo could not be saved. Please, try again.'));
|
||||
}
|
||||
$products = $productPhotosTable->Products->find('list', limit: 200)->all();
|
||||
$productSkus = $productPhotosTable->ProductSkus->find('list', limit: 200)->all();
|
||||
$this->set(compact('productPhoto', 'products', 'productSkus'));
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
$this->Flash->error(__('The product photo could not be saved. Please, try again.'));
|
||||
}
|
||||
$products = $this->fetchTable('Products')->find('list', limit: 200)->all();
|
||||
$productSkus = $this->fetchTable('ProductSkus')->find('list', limit: 200)->all();
|
||||
$this->set(compact('productPhoto', 'products', 'productSkus'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Delete method
|
||||
*
|
||||
* @param string|null $id Product Photo id.
|
||||
* @return Response|null Redirects to index.
|
||||
* @throws RecordNotFoundException When record not found.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productPhotosTable = $this->ProductPhotos;
|
||||
public function delete($id = null) {
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
|
||||
$productPhoto = $productPhotosTable->get($id);
|
||||
if ($productPhotosTable->delete($productPhoto)) {
|
||||
$this->Flash->success(__('The product photo has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product photo could not be deleted. Please, try again.'));
|
||||
}
|
||||
$productPhoto = $this->fetchTable()->get($id);
|
||||
if ($this->fetchTable()->delete($productPhoto)) {
|
||||
$this->Flash->success(__('The product photo has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product photo could not be deleted. Please, try again.'));
|
||||
}
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return Response
|
||||
/**
|
||||
* @param string|null $id
|
||||
* @return \Cake\Http\Response
|
||||
*/
|
||||
public function image($id = null)
|
||||
{
|
||||
$productPhoto = $this->ProductPhotos->get($id);
|
||||
public function image($id = null) {
|
||||
$productPhoto = $this->fetchTable()->get($id);
|
||||
|
||||
$fullPath = Configure::readOrFail('CakeProducts.photos.directory') . $productPhoto->photo_dir . DS . $productPhoto->photo_filename;
|
||||
$fullPath = Configure::readOrFail('CakeProducts.photos.directory') . $productPhoto->photo_dir . DS . $productPhoto->photo_filename;
|
||||
|
||||
return $this->response->withFile($fullPath, [
|
||||
'download' => $this->request->getQuery('download', false) === '1',
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->response->withFile($fullPath, [
|
||||
'download' => $this->request->getQuery('download', false) === '1'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,240 +12,233 @@ use function BenTools\CartesianProduct\combinations;
|
||||
*
|
||||
* @property \CakeProducts\Model\Table\ProductSkusTable $ProductSkus
|
||||
*/
|
||||
class ProductSkusController extends AppController
|
||||
{
|
||||
/**
|
||||
class ProductSkusController extends AppController {
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
// $this->_defaultTable = 'CakeProducts.ProductSkus';
|
||||
// $this->_tableConfigKey = 'CakeProducts.ProductSkus.table';
|
||||
}
|
||||
public function initialize(): void {
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Index method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$query = $this->ProductSkus->find()
|
||||
->contain(['Products']);
|
||||
$productSkus = $this->paginate($query);
|
||||
public function index() {
|
||||
$query = $this->ProductSkus->find()
|
||||
->contain(['Products']);
|
||||
$productSkus = $this->paginate($query);
|
||||
|
||||
$this->set(compact('productSkus'));
|
||||
}
|
||||
$this->set(compact('productSkus'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* View method
|
||||
*
|
||||
* @param string|null $id Product Skus id.
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function view($id = null)
|
||||
{
|
||||
$productSku = $this->ProductSkus->get($id, contain: [
|
||||
'Products',
|
||||
'ProductSkuVariantValues',
|
||||
'ProductSkuVariantValues.ProductVariants',
|
||||
'ProductSkuVariantValues.ProductVariants.ProductCategoryVariants',
|
||||
'ProductSkuVariantValues.ProductCategoryVariantOptions',
|
||||
]);
|
||||
$this->set(compact('productSku'));
|
||||
}
|
||||
public function view($id = null) {
|
||||
$productSku = $this->ProductSkus->get($id, contain: [
|
||||
'Products',
|
||||
'ProductSkuVariantValues',
|
||||
'ProductSkuVariantValues.ProductVariants',
|
||||
'ProductSkuVariantValues.ProductVariants.ProductCategoryVariants',
|
||||
'ProductSkuVariantValues.ProductCategoryVariantOptions',
|
||||
]);
|
||||
$this->set(compact('productSku'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add($productId = null)
|
||||
{
|
||||
$toGetCartesianProductsFrom = [];
|
||||
$productSkus = [];
|
||||
$product = $this->ProductSkus->Products->get($productId, contain: [
|
||||
'ProductSkus',
|
||||
'ProductSkus.ProductSkuVariantValues',
|
||||
'ProductVariants',
|
||||
'ProductVariants.ProductCategoryVariants',
|
||||
'ProductVariants.ProductCategoryVariants.ProductCategoryVariantOptions',
|
||||
]);
|
||||
$existingProductSkus = Hash::combine($product->product_skus ?? [], '{n}.id', '{n}');
|
||||
$existingProductSkusForMapping = Hash::combine($product->product_skus ?? [], '{n}.id', '{n}.product_sku_variant_values');
|
||||
$existingSkusForCartesianComparison = [];
|
||||
foreach ($existingProductSkusForMapping as $existingProductSkuId => $existingProductSku) {
|
||||
$existingSkusForCartesianComparison[$existingProductSkuId] = Hash::combine($existingProductSku, '{n}.product_variant_id', '{n}.product_category_variant_option_id');
|
||||
}
|
||||
$productVariants = isset($product->product_variants) ? $product->product_variants : [];
|
||||
public function add($productId = null) {
|
||||
$toGetCartesianProductsFrom = [];
|
||||
$productSkus = [];
|
||||
$product = $this->ProductSkus->Products->get($productId, contain: [
|
||||
'ProductSkus',
|
||||
'ProductSkus.ProductSkuVariantValues',
|
||||
'ProductVariants',
|
||||
'ProductVariants.ProductCategoryVariants',
|
||||
'ProductVariants.ProductCategoryVariants.ProductCategoryVariantOptions',
|
||||
]);
|
||||
$existingProductSkus = Hash::combine($product->product_skus ?? [], '{n}.id', '{n}');
|
||||
$existingProductSkusForMapping = Hash::combine($product->product_skus ?? [], '{n}.id', '{n}.product_sku_variant_values');
|
||||
$existingSkusForCartesianComparison = [];
|
||||
foreach ($existingProductSkusForMapping as $existingProductSkuId => $existingProductSku) {
|
||||
$existingSkusForCartesianComparison[$existingProductSkuId] = Hash::combine($existingProductSku, '{n}.product_variant_id', '{n}.product_category_variant_option_id');
|
||||
}
|
||||
$productVariants = $product->product_variants ?? [];
|
||||
// dd($productVariants);
|
||||
$productVariantsMapping = Hash::combine($productVariants, '{n}.product_category_variant.id', '{n}.id');
|
||||
$productCategoryVariants = Hash::extract($productVariants, '{n}.product_category_variant');
|
||||
$productVariantsMapping = Hash::combine($productVariants, '{n}.product_category_variant.id', '{n}.id');
|
||||
$productCategoryVariants = Hash::extract($productVariants, '{n}.product_category_variant');
|
||||
// dd($productCategoryVariants);
|
||||
$optionMapping = Hash::combine($productCategoryVariants, '{n}.product_category_variant_options.{n}.id', '{n}.product_category_variant_options.{n}.variant_value');
|
||||
$optionMapping = Hash::combine($productCategoryVariants, '{n}.product_category_variant_options.{n}.id', '{n}.product_category_variant_options.{n}.variant_value');
|
||||
// dd($optionMapping);
|
||||
|
||||
$variantNameMapping = Hash::combine($productCategoryVariants, '{n}.id', '{n}.name');
|
||||
$variantNameMapping = Hash::combine($productCategoryVariants, '{n}.id', '{n}.name');
|
||||
// dd($variantNameMapping);
|
||||
|
||||
foreach ($productCategoryVariants as $productCategoryVariant) {
|
||||
$options = Hash::extract($productCategoryVariant['product_category_variant_options'] ?? [], '{n}.id');
|
||||
$toGetCartesianProductsFrom[$productVariantsMapping[$productCategoryVariant['id']]] = $options;
|
||||
}
|
||||
foreach ($productCategoryVariants as $productCategoryVariant) {
|
||||
$options = Hash::extract($productCategoryVariant['product_category_variant_options'] ?? [], '{n}.id');
|
||||
$toGetCartesianProductsFrom[$productVariantsMapping[$productCategoryVariant['id']]] = $options;
|
||||
}
|
||||
// dd($toGetCartesianProductsFrom);
|
||||
|
||||
$numSkusToAdd = count(combinations($toGetCartesianProductsFrom));
|
||||
for ($i = 0; $i < $numSkusToAdd; $i++) {
|
||||
$productSkus[$i] = $this->ProductSkus->newEmptyEntity();
|
||||
}
|
||||
$this->set(compact(
|
||||
'product',
|
||||
'productSkus',
|
||||
'productCategoryVariants',
|
||||
'productVariantsMapping',
|
||||
'toGetCartesianProductsFrom',
|
||||
'optionMapping',
|
||||
'variantNameMapping',
|
||||
'numSkusToAdd',
|
||||
'existingProductSkus',
|
||||
'existingSkusForCartesianComparison'
|
||||
));
|
||||
$numSkusToAdd = count(combinations($toGetCartesianProductsFrom));
|
||||
for ($i = 0; $i < $numSkusToAdd; $i++) {
|
||||
$productSkus[$i] = $this->ProductSkus->newEmptyEntity();
|
||||
}
|
||||
$this->set(compact(
|
||||
'product',
|
||||
'productSkus',
|
||||
'productCategoryVariants',
|
||||
'productVariantsMapping',
|
||||
'toGetCartesianProductsFrom',
|
||||
'optionMapping',
|
||||
'variantNameMapping',
|
||||
'numSkusToAdd',
|
||||
'existingProductSkus',
|
||||
'existingSkusForCartesianComparison',
|
||||
));
|
||||
|
||||
if ($this->request->is('post')) {
|
||||
$postedSkus = $this->request->getData();
|
||||
$saveOptions = [
|
||||
'fields' => [
|
||||
'product_id',
|
||||
'sku',
|
||||
'barcode',
|
||||
'price',
|
||||
'cost',
|
||||
'product_sku_variant_values',
|
||||
'created',
|
||||
'modified',
|
||||
'enabled',
|
||||
'default_sku',
|
||||
],
|
||||
'associated' => [
|
||||
'ProductSkuVariantValues' => [
|
||||
'fields' => [
|
||||
'product_variant_id',
|
||||
'product_category_variant_option_id',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
$finalPostData = [];
|
||||
$postedSkus = Hash::insert($postedSkus, '{n}.product_id', $productId);
|
||||
if ($this->request->is('post')) {
|
||||
$postedSkus = $this->request->getData();
|
||||
$saveOptions = [
|
||||
'fields' => [
|
||||
'product_id',
|
||||
'sku',
|
||||
'barcode',
|
||||
'price',
|
||||
'cost',
|
||||
'product_sku_variant_values',
|
||||
'created',
|
||||
'modified',
|
||||
'enabled',
|
||||
'default_sku',
|
||||
],
|
||||
'associated' => [
|
||||
'ProductSkuVariantValues' => [
|
||||
'fields' => [
|
||||
'product_variant_id',
|
||||
'product_category_variant_option_id',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
$finalPostData = [];
|
||||
$postedSkus = Hash::insert($postedSkus, '{n}.product_id', $productId);
|
||||
|
||||
foreach ($postedSkus as $postedSkuCnt => $postedSku) {
|
||||
if (!isset($postedSku['sku']) || !$postedSku['sku']) {
|
||||
unset($productSkus[$postedSkuCnt]);
|
||||
foreach ($postedSkus as $postedSkuCnt => $postedSku) {
|
||||
if (!isset($postedSku['sku']) || !$postedSku['sku']) {
|
||||
unset($productSkus[$postedSkuCnt]);
|
||||
|
||||
continue;
|
||||
}
|
||||
$finalPostData[$postedSkuCnt] = $postedSku;
|
||||
}
|
||||
if (!$productSkus || !$postedSkus) {
|
||||
$this->Flash->error('Nothing to save! Add at least one SKU next time.');
|
||||
continue;
|
||||
}
|
||||
$finalPostData[$postedSkuCnt] = $postedSku;
|
||||
}
|
||||
if (!$productSkus || !$postedSkus) {
|
||||
$this->Flash->error('Nothing to save! Add at least one SKU next time.');
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
// dd($finalPostData);
|
||||
$productSkus = $this->ProductSkus->patchEntities($productSkus, $finalPostData, $saveOptions);
|
||||
$errors = [];
|
||||
$successes = [];
|
||||
foreach ($productSkus as $productSkuToSave) {
|
||||
$productSkus = $this->ProductSkus->patchEntities($productSkus, $finalPostData, $saveOptions);
|
||||
$errors = [];
|
||||
$successes = [];
|
||||
foreach ($productSkus as $productSkuToSave) {
|
||||
// dd($productSkuToSave);
|
||||
|
||||
if (!$this->ProductSkus->save($productSkuToSave, $saveOptions)) {
|
||||
Log::debug(print_r('$productSkuToSave->getErrors()', true));
|
||||
Log::debug(print_r($productSkuToSave->getErrors(), true));
|
||||
dd($productSkuToSave->getErrors());
|
||||
continue;
|
||||
}
|
||||
$successes[] = $productSkuToSave;
|
||||
}
|
||||
if (!$this->ProductSkus->save($productSkuToSave, $saveOptions)) {
|
||||
Log::debug(print_r('$productSkuToSave->getErrors()', true));
|
||||
Log::debug(print_r($productSkuToSave->getErrors(), true));
|
||||
// dd($productSkuToSave->getErrors());
|
||||
|
||||
if ($successes) {
|
||||
$this->Flash->success(__(count($successes) . ' New SKUs have been saved.'));
|
||||
continue;
|
||||
}
|
||||
$successes[] = $productSkuToSave;
|
||||
}
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
if ($successes) {
|
||||
$this->Flash->success(__(count($successes) . ' New SKUs have been saved.'));
|
||||
|
||||
$this->Flash->error(__('The product SKU(s) could not be saved. Please, try again.'));
|
||||
}
|
||||
$this->set(compact(
|
||||
'productSkus'
|
||||
));
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
|
||||
/**
|
||||
$this->Flash->error(__('The product SKU(s) could not be saved. Please, try again.'));
|
||||
}
|
||||
$this->set(compact(
|
||||
'productSkus',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit method
|
||||
*
|
||||
* @param string|null $id Product Skus id.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
$productSku = $this->ProductSkus->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$postData = $this->request->getData();
|
||||
$saveOptions = [
|
||||
'associated' => [],
|
||||
];
|
||||
// Log::debug(print_r('$postData', true));
|
||||
public function edit($id = null) {
|
||||
$productSku = $this->ProductSkus->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$postData = $this->request->getData();
|
||||
$saveOptions = [
|
||||
'associated' => [],
|
||||
];
|
||||
// Log::debug(print_r('$postData', true));
|
||||
// Log::debug(print_r($postData, true));
|
||||
// Log::debug(print_r('$saveOptions', true));
|
||||
// Log::debug(print_r($saveOptions, true));
|
||||
$productSku = $this->ProductSkus->patchEntity($productSku, $postData, $saveOptions);
|
||||
if ($this->ProductSkus->save($productSku)) {
|
||||
$this->Flash->success(__('The product skus has been saved.'));
|
||||
$productSku = $this->ProductSkus->patchEntity($productSku, $postData, $saveOptions);
|
||||
if ($this->ProductSkus->save($productSku)) {
|
||||
$this->Flash->success(__('The product skus has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
Log::debug(print_r('$productSku->getErrors() next - failed in productSkus/edit', true));
|
||||
Log::debug(print_r($productSku->getErrors(), true));
|
||||
$this->Flash->error(__('The product skus could not be saved. Please, try again.'));
|
||||
}
|
||||
$products = $this->ProductSkus->Products->find('list', limit: 200)->all();
|
||||
$this->set(compact('productSku', 'products'));
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
Log::debug(print_r('$productSku->getErrors() next - failed in productSkus/edit', true));
|
||||
Log::debug(print_r($productSku->getErrors(), true));
|
||||
$this->Flash->error(__('The product skus could not be saved. Please, try again.'));
|
||||
}
|
||||
$products = $this->ProductSkus->Products->find('list', limit: 200)->all();
|
||||
$this->set(compact('productSku', 'products'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Delete method
|
||||
*
|
||||
* @param string|null $id Product Skus id.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productSku = $this->ProductSkus->get($id);
|
||||
if ($this->ProductSkus->delete($productSku)) {
|
||||
$this->Flash->success(__('The product skus has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product skus could not be deleted. Please, try again.'));
|
||||
}
|
||||
public function delete($id = null) {
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productSku = $this->ProductSkus->get($id);
|
||||
if ($this->ProductSkus->delete($productSku)) {
|
||||
$this->Flash->success(__('The product skus has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product skus could not be deleted. Please, try again.'));
|
||||
}
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function select()
|
||||
{
|
||||
$productSkus = $this->ProductSkus
|
||||
->find('list')
|
||||
->where(['product_id' => $this->request->getQuery('product_id', '-1')])
|
||||
->orderBy(['sku'])
|
||||
->toArray();
|
||||
public function select() {
|
||||
$productSkus = $this->ProductSkus
|
||||
->find('list')
|
||||
->where(['product_id' => $this->request->getQuery('product_id', '-1')])
|
||||
->orderBy(['sku'])
|
||||
->toArray();
|
||||
|
||||
$this->set(compact('productSkus'));
|
||||
}
|
||||
|
||||
$this->set(compact('productSkus'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,111 +8,110 @@ use Cake\Log\Log;
|
||||
/**
|
||||
* ProductVariants Controller
|
||||
*
|
||||
* @property \App\Model\Table\ProductVariantsTable $ProductVariants
|
||||
* @property \CakeProducts\Model\Table\ProductVariantsTable $ProductVariants
|
||||
*/
|
||||
class ProductVariantsController extends AppController
|
||||
{
|
||||
/**
|
||||
class ProductVariantsController extends AppController {
|
||||
|
||||
/**
|
||||
* Index method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$query = $this->ProductVariants->find()
|
||||
->contain(['ProductCategoryVariants', 'Products']);
|
||||
$productVariants = $this->paginate($query);
|
||||
public function index() {
|
||||
$query = $this->fetchTable()->find()
|
||||
->contain(['ProductCategoryVariants', 'Products']);
|
||||
$productVariants = $this->paginate($query);
|
||||
|
||||
$this->set(compact('productVariants'));
|
||||
}
|
||||
$this->set(compact('productVariants'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* View method
|
||||
*
|
||||
* @param string|null $id Product Variant id.
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function view($id = null)
|
||||
{
|
||||
$productVariant = $this->ProductVariants->get($id, contain: ['ProductCategoryVariants', 'Products']);
|
||||
$this->set(compact('productVariant'));
|
||||
}
|
||||
public function view($id = null) {
|
||||
$productVariant = $this->fetchTable()->get($id, contain: ['ProductCategoryVariants', 'Products']);
|
||||
$this->set(compact('productVariant'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add($productId)
|
||||
{
|
||||
$product = $this->ProductVariants->Products->get($productId);
|
||||
$productVariant = $this->ProductVariants->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
$saveOptions = [];
|
||||
$postData = $this->request->getData();
|
||||
$productCategoryVariant = $this->ProductVariants->ProductCategoryVariants->get($this->request->getData('product_category_variant_id', '-1'));
|
||||
$postData['name'] = $productCategoryVariant->name;
|
||||
$postData['product_id'] = $productId;
|
||||
$productVariant = $this->ProductVariants->patchEntity($productVariant, $postData);
|
||||
if ($this->ProductVariants->save($productVariant)) {
|
||||
$this->Flash->success(__('The product variant has been saved.'));
|
||||
public function add($productId) {
|
||||
$product = $this->fetchTable()->Products->get($productId);
|
||||
$productVariant = $this->fetchTable()->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
$saveOptions = [];
|
||||
$postData = $this->request->getData();
|
||||
/**
|
||||
* @var \CakeProducts\Model\Entity\ProductCategoryVariant $productCategoryVariant
|
||||
*/
|
||||
$productCategoryVariant = $this->fetchTable('ProductCategoryVariants')->get($this->request->getData('product_category_variant_id', '-1'));
|
||||
$postData['name'] = $productCategoryVariant->name;
|
||||
$postData['product_id'] = $productId;
|
||||
$productVariant = $this->fetchTable()->patchEntity($productVariant, $postData);
|
||||
if ($this->fetchTable()->save($productVariant)) {
|
||||
$this->Flash->success(__('The product variant has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
|
||||
Log::debug(print_r('$productVariant->getErrors()', true));
|
||||
Log::debug(print_r($productVariant->getErrors(), true));
|
||||
$this->Flash->error(__('The product variant could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategoryVariants = $this->ProductVariants->ProductCategoryVariants
|
||||
->find('list', limit: 200)
|
||||
->where(['product_category_id' => $product->product_category_id])
|
||||
->toArray();
|
||||
$this->set(compact('productVariant', 'productCategoryVariants', 'product'));
|
||||
}
|
||||
Log::debug(print_r('$productVariant->getErrors()', true));
|
||||
Log::debug(print_r($productVariant->getErrors(), true));
|
||||
$this->Flash->error(__('The product variant could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategoryVariants = $this->fetchTable('ProductCategoryVariants')
|
||||
->find('list', limit: 200)
|
||||
->where(['product_category_id' => $product->product_category_id])
|
||||
->toArray();
|
||||
$this->set(compact('productVariant', 'productCategoryVariants', 'product'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Edit method
|
||||
*
|
||||
* @param string|null $id Product Variant id.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
$productVariant = $this->ProductVariants->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$productVariant = $this->ProductVariants->patchEntity($productVariant, $this->request->getData());
|
||||
if ($this->ProductVariants->save($productVariant)) {
|
||||
$this->Flash->success(__('The product variant has been saved.'));
|
||||
public function edit($id = null) {
|
||||
$productVariant = $this->fetchTable()->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$productVariant = $this->fetchTable()->patchEntity($productVariant, $this->request->getData());
|
||||
if ($this->fetchTable()->save($productVariant)) {
|
||||
$this->Flash->success(__('The product variant has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
$this->Flash->error(__('The product variant could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategoryVariants = $this->ProductVariants->ProductCategoryVariants->find('list', limit: 200)->all();
|
||||
$products = $this->ProductVariants->Products->find('list', limit: 200)->all();
|
||||
$this->set(compact('productVariant', 'productCategoryVariants', 'products'));
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
$this->Flash->error(__('The product variant could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategoryVariants = $this->fetchTable('ProductCategoryVariants')->find('list', limit: 200)->all();
|
||||
$products = $this->fetchTable('Products')->find('list', limit: 200)->all();
|
||||
$this->set(compact('productVariant', 'productCategoryVariants', 'products'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Delete method
|
||||
*
|
||||
* @param string|null $id Product Variant id.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productVariant = $this->ProductVariants->get($id);
|
||||
if ($this->ProductVariants->delete($productVariant)) {
|
||||
$this->Flash->success(__('The product variant has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product variant could not be deleted. Please, try again.'));
|
||||
}
|
||||
public function delete($id = null) {
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productVariant = $this->fetchTable()->get($id);
|
||||
if ($this->fetchTable()->delete($productVariant)) {
|
||||
$this->Flash->success(__('The product variant has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product variant could not be deleted. Please, try again.'));
|
||||
}
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,211 +3,203 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Controller;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Log\Log;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\ORM\TableRegistry;
|
||||
|
||||
/**
|
||||
* Products Controller
|
||||
*
|
||||
* @property \CakeProducts\Model\Table\ProductsTable $Products
|
||||
*/
|
||||
class ProductsController extends AppController
|
||||
{
|
||||
/**
|
||||
class ProductsController extends AppController {
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
// $this->_defaultTable = 'CakeProducts.Products';
|
||||
// $this->_tableConfigKey = 'CakeProducts.Products.table';
|
||||
}
|
||||
public function initialize(): void {
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Index method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$query = $this->Products->find()
|
||||
->contain(['ProductCategories']);
|
||||
$products = $this->paginate($query);
|
||||
public function index() {
|
||||
$query = $this->fetchTable()->find()
|
||||
->contain(['ProductCategories']);
|
||||
$products = $this->paginate($query);
|
||||
|
||||
$this->set(compact('products'));
|
||||
}
|
||||
$this->set(compact('products'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* View method
|
||||
*
|
||||
* @param string|null $id Product id.
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function view($id = null)
|
||||
{
|
||||
$product = $this->Products->get($id, contain: [
|
||||
'ProductCategories',
|
||||
'ProductAttributes',
|
||||
'ProductAttributes.ProductCategoryAttributes',
|
||||
'ProductAttributes.ProductCategoryAttributeOptions',
|
||||
'ProductVariants',
|
||||
'ProductVariants.ProductCategoryVariants',
|
||||
'ProductVariants.ProductCategoryVariants.ProductCategoryVariantOptions',
|
||||
'ProductSkus',
|
||||
'ProductPhotos',
|
||||
]);
|
||||
$this->set(compact('product'));
|
||||
}
|
||||
public function view($id = null) {
|
||||
$product = $this->fetchTable()->get($id, contain: [
|
||||
'ProductCategories',
|
||||
'ProductAttributes',
|
||||
'ProductAttributes.ProductCategoryAttributes',
|
||||
'ProductAttributes.ProductCategoryAttributeOptions',
|
||||
'ProductVariants',
|
||||
'ProductVariants.ProductCategoryVariants',
|
||||
'ProductVariants.ProductCategoryVariants.ProductCategoryVariantOptions',
|
||||
'ProductSkus',
|
||||
'ProductPhotos',
|
||||
]);
|
||||
$this->set(compact('product'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$productsTable = $this->Products;
|
||||
$product = $productsTable->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
$postData = $this->request->getData();
|
||||
$saveOptions = [
|
||||
'associated' => ['ProductAttributes'],
|
||||
];
|
||||
Log::debug(print_r('$postData', true));
|
||||
Log::debug(print_r($postData, true));
|
||||
Log::debug(print_r('$saveOptions', true));
|
||||
Log::debug(print_r($saveOptions, true));
|
||||
$productVariantsData = [];
|
||||
if (isset($postData['product_variants']) && $postData['product_variants']) {
|
||||
foreach ($postData['product_variants'] as $postedProductVariant) {
|
||||
if (!isset($postedProductVariant['enabled']) || !$postedProductVariant['enabled'] || !isset($postedProductVariant['product_category_variant_id'])) {
|
||||
continue;
|
||||
}
|
||||
$existingVariant = $this->Products->ProductCategories->ProductCategoryVariants->get($postedProductVariant['product_category_variant_id'], contain: ['ProductCategoryVariantOptions']);
|
||||
$optionsData = [];
|
||||
foreach ($existingVariant->product_category_variant_options as $existingOption) {
|
||||
$optionsData[] = [
|
||||
'variant_value' => $existingOption->variant_value,
|
||||
'variant_label' => $existingOption->variant_label ?? null,
|
||||
'enabled' => $existingOption->enabled,
|
||||
];
|
||||
}
|
||||
$tmpVariantData = [
|
||||
'name' => $existingVariant->name,
|
||||
'product_category_variant_id' => $postedProductVariant['product_category_variant_id'],
|
||||
'enabled' => true,
|
||||
'product_category_variant_options' => $optionsData,
|
||||
];
|
||||
$productVariantsData[] = $tmpVariantData;
|
||||
}
|
||||
}
|
||||
if ($productVariantsData) {
|
||||
$saveOptions['fields'] = [
|
||||
'name',
|
||||
'product_category_id',
|
||||
'product_type_id',
|
||||
'product_attributes',
|
||||
'product_category_variants'
|
||||
];
|
||||
$saveOptions['associated']['ProductCategoryVariants'] = [
|
||||
'fields' => [
|
||||
'name',
|
||||
'enabled',
|
||||
'product_category_variant_options',
|
||||
]
|
||||
];
|
||||
$saveOptions['associated'][] = 'ProductCategoryVariants.ProductCategoryVariantOptions';
|
||||
$postData['product_category_variants'] = $productVariantsData;
|
||||
}
|
||||
$product = $productsTable->patchEntity($product, $postData, $saveOptions);
|
||||
if ($productsTable->save($product, $saveOptions)) {
|
||||
$this->Flash->success(__('The product has been saved.'));
|
||||
public function add() {
|
||||
$product = $this->fetchTable()->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
$postData = $this->request->getData();
|
||||
$saveOptions = [
|
||||
'associated' => ['ProductAttributes'],
|
||||
];
|
||||
Log::debug(print_r('$postData', true));
|
||||
Log::debug(print_r($postData, true));
|
||||
Log::debug(print_r('$saveOptions', true));
|
||||
Log::debug(print_r($saveOptions, true));
|
||||
$productVariantsData = [];
|
||||
if (isset($postData['product_variants']) && $postData['product_variants']) {
|
||||
foreach ($postData['product_variants'] as $postedProductVariant) {
|
||||
if (!isset($postedProductVariant['enabled']) || !$postedProductVariant['enabled'] || !isset($postedProductVariant['product_category_variant_id'])) {
|
||||
continue;
|
||||
}
|
||||
/**
|
||||
* @var \CakeProducts\Model\Entity\ProductCategoryVariant $existingVariant
|
||||
*/
|
||||
$existingVariant = $this->fetchTable('CakeProducts.ProductCategoryVariants')
|
||||
->get($postedProductVariant['product_category_variant_id'], contain: ['ProductCategoryVariantOptions']);
|
||||
$optionsData = [];
|
||||
foreach ($existingVariant->product_category_variant_options as $existingOption) {
|
||||
$optionsData[] = [
|
||||
'variant_value' => $existingOption->variant_value,
|
||||
'variant_label' => $existingOption->variant_label ?? null,
|
||||
'enabled' => $existingOption->enabled ?? false,
|
||||
];
|
||||
}
|
||||
$tmpVariantData = [
|
||||
'name' => $existingVariant->name,
|
||||
'product_category_variant_id' => $postedProductVariant['product_category_variant_id'],
|
||||
'enabled' => true,
|
||||
'product_category_variant_options' => $optionsData,
|
||||
];
|
||||
$productVariantsData[] = $tmpVariantData;
|
||||
}
|
||||
}
|
||||
if ($productVariantsData) {
|
||||
$saveOptions['fields'] = [
|
||||
'name',
|
||||
'product_category_id',
|
||||
'product_type_id',
|
||||
'product_attributes',
|
||||
'product_category_variants',
|
||||
];
|
||||
$saveOptions['associated']['ProductCategoryVariants'] = [
|
||||
'fields' => [
|
||||
'name',
|
||||
'enabled',
|
||||
'product_category_variant_options',
|
||||
],
|
||||
];
|
||||
$saveOptions['associated'][] = 'ProductCategoryVariants.ProductCategoryVariantOptions';
|
||||
$postData['product_category_variants'] = $productVariantsData;
|
||||
}
|
||||
$product = $this->fetchTable()->patchEntity($product, $postData, $saveOptions);
|
||||
if ($this->fetchTable()->save($product, $saveOptions)) {
|
||||
$this->Flash->success(__('The product has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
Log::debug(print_r('$product->getErrors() next - failed in products/add', true));
|
||||
Log::debug(print_r($product->getErrors(), true));
|
||||
$this->Flash->error(__('The product could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategory = $product->product_category_id ? $productsTable->ProductCategories->find()->where(['internal_id' => $product->product_category_id])->first() : null;
|
||||
$productCatalogs = $productsTable->ProductCategories->ProductCatalogs->find('list')->toArray();
|
||||
$this->set(compact('product', 'productCatalogs', 'productCategory'));
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
Log::debug(print_r('$product->getErrors() next - failed in products/add', true));
|
||||
Log::debug(print_r($product->getErrors(), true));
|
||||
$this->Flash->error(__('The product could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategory = $product->product_category_id ? $this->fetchTable('ProductCategories')->find()
|
||||
->where(['internal_id' => $product->product_category_id])->first() : null;
|
||||
$productCatalogs = $this->fetchTable('ProductCatalogs')->find('list')->toArray();
|
||||
|
||||
/**
|
||||
$this->set(compact('product', 'productCatalogs', 'productCategory'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit method
|
||||
*
|
||||
* @param string|null $id Product id.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
$productsTable = $this->Products;
|
||||
$product = $productsTable->get($id, contain: [
|
||||
'ProductAttributes',
|
||||
'ProductAttributes.ProductCategoryAttributes',
|
||||
'ProductAttributes.ProductCategoryAttributes.ProductCategoryAttributeOptions',
|
||||
]);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$saveOptions = [
|
||||
'associated' => ['ProductAttributes'],
|
||||
];
|
||||
$product = $productsTable->patchEntity($product, $this->request->getData(), $saveOptions);
|
||||
if ($productsTable->save($product)) {
|
||||
$this->Flash->success(__('The product has been saved.'));
|
||||
public function edit($id = null) {
|
||||
$productsTable = $this->fetchTable();
|
||||
$product = $productsTable->get($id, contain: [
|
||||
'ProductAttributes',
|
||||
'ProductAttributes.ProductCategoryAttributes',
|
||||
'ProductAttributes.ProductCategoryAttributes.ProductCategoryAttributeOptions',
|
||||
]);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$saveOptions = [
|
||||
'associated' => ['ProductAttributes'],
|
||||
];
|
||||
$product = $productsTable->patchEntity($product, $this->request->getData(), $saveOptions);
|
||||
if ($productsTable->save($product)) {
|
||||
$this->Flash->success(__('The product has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
Log::debug(print_r('$product->getErrors() next - failed in products/edit', true));
|
||||
Log::debug(print_r($product->getErrors(), true));
|
||||
$this->Flash->error(__('The product could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategory = $product->product_category_id ? $productsTable->ProductCategories->find()->where(['internal_id' => $product->product_category_id])->first() : null;
|
||||
$productCatalogs = $productsTable->ProductCategories->ProductCatalogs->find('list')->toArray();
|
||||
$this->set(compact('product', 'productCatalogs', 'productCategory'));
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
Log::debug(print_r('$product->getErrors() next - failed in products/edit', true));
|
||||
Log::debug(print_r($product->getErrors(), true));
|
||||
$this->Flash->error(__('The product could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategory = $product->product_category_id ? $productsTable->ProductCategories->find()->where(['internal_id' => $product->product_category_id])->first() : null;
|
||||
$productCatalogs = $productsTable->ProductCategories->ProductCatalogs->find('list')->toArray();
|
||||
$this->set(compact('product', 'productCatalogs', 'productCategory'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Delete method
|
||||
*
|
||||
* @param string|null $id Product id.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
public function delete($id = null) {
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
|
||||
$productsTable = $this->Products;
|
||||
$product = $productsTable->get($id);
|
||||
if ($productsTable->delete($product)) {
|
||||
$this->Flash->success(__('The product has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product could not be deleted. Please, try again.'));
|
||||
}
|
||||
$product = $this->fetchTable()->get($id);
|
||||
if ($this->fetchTable()->delete($product)) {
|
||||
$this->Flash->success(__('The product has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product could not be deleted. Please, try again.'));
|
||||
}
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function select()
|
||||
{
|
||||
$productsTable = $this->Products;
|
||||
$productCategory = $productsTable->ProductCategories->find()
|
||||
->where(['id' => $this->request->getQuery('product_category_id', '-1')])
|
||||
->first();
|
||||
$products = $productsTable
|
||||
->find('list')
|
||||
->where(['product_category_id' => $productCategory->internal_id ?? '-1'])
|
||||
->orderBy(['Products.name'])
|
||||
->toArray();
|
||||
public function select() {
|
||||
$productCategory = $this->fetchTable()->ProductCategories->find()
|
||||
->where(['id' => $this->request->getQuery('product_category_id', '-1')])
|
||||
->first();
|
||||
$products = $this->fetchTable()
|
||||
->find('list')
|
||||
->where(['product_category_id' => $productCategory->internal_id ?? '-1'])
|
||||
->orderBy(['Products.name'])
|
||||
->toArray();
|
||||
|
||||
$this->set(compact('products'));
|
||||
}
|
||||
|
||||
$this->set(compact('products'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,7 @@
|
||||
|
||||
namespace CakeProducts\Model\Behavior;
|
||||
|
||||
use ArrayObject;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Event\EventInterface;
|
||||
use Cake\ORM\Behavior;
|
||||
use LogicException;
|
||||
use Tools\Model\Behavior\ToggleBehavior;
|
||||
|
||||
/**
|
||||
@@ -21,37 +17,38 @@ use Tools\Model\Behavior\ToggleBehavior;
|
||||
*/
|
||||
class SecondToggleBehavior extends ToggleBehavior {
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default config
|
||||
*
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
protected array $_defaultConfig = [
|
||||
'field' => 'primary',
|
||||
'on' => 'afterSave', // afterSave (without transactions) or beforeSave (with transactions)
|
||||
'scopeFields' => [],
|
||||
'scope' => [],
|
||||
'findOrder' => null, // null = autodetect modified/created, false to disable
|
||||
'implementedMethods' => [], // to prevent conflict with public toggleField method
|
||||
];
|
||||
protected array $_defaultConfig = [
|
||||
'field' => 'primary',
|
||||
'on' => 'afterSave', // afterSave (without transactions) or beforeSave (with transactions)
|
||||
'scopeFields' => [],
|
||||
'scope' => [],
|
||||
'findOrder' => null, // null = autodetect modified/created, false to disable
|
||||
'implementedMethods' => [], // to prevent conflict with public toggleField method
|
||||
];
|
||||
|
||||
/**
|
||||
/**
|
||||
* @param \Cake\Datasource\EntityInterface $entity
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function buildConditions(EntityInterface $entity) {
|
||||
$conditions = $this->getConfig('scope');
|
||||
$scopeFields = (array)$this->getConfig('scopeFields');
|
||||
protected function buildConditions(EntityInterface $entity) {
|
||||
$conditions = $this->getConfig('scope');
|
||||
$scopeFields = (array)$this->getConfig('scopeFields');
|
||||
|
||||
foreach ($scopeFields as $scopeField) {
|
||||
if ($entity->get($scopeField) === null) {
|
||||
continue;
|
||||
}
|
||||
$conditions[$scopeField] = $entity->get($scopeField);
|
||||
}
|
||||
foreach ($scopeFields as $scopeField) {
|
||||
if ($entity->get($scopeField) === null) {
|
||||
continue;
|
||||
}
|
||||
$conditions[$scopeField] = $entity->get($scopeField);
|
||||
}
|
||||
// dd($conditions);
|
||||
|
||||
return $conditions;
|
||||
}
|
||||
return $conditions;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,11 +2,7 @@
|
||||
|
||||
namespace CakeProducts\Model\Behavior;
|
||||
|
||||
use ArrayObject;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Event\EventInterface;
|
||||
use Cake\ORM\Behavior;
|
||||
use LogicException;
|
||||
use Tools\Model\Behavior\ToggleBehavior;
|
||||
|
||||
/**
|
||||
@@ -21,37 +17,38 @@ use Tools\Model\Behavior\ToggleBehavior;
|
||||
*/
|
||||
class ThirdToggleBehavior extends ToggleBehavior {
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default config
|
||||
*
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
protected array $_defaultConfig = [
|
||||
'field' => 'primary',
|
||||
'on' => 'afterSave', // afterSave (without transactions) or beforeSave (with transactions)
|
||||
'scopeFields' => [],
|
||||
'scope' => [],
|
||||
'findOrder' => null, // null = autodetect modified/created, false to disable
|
||||
'implementedMethods' => [], // to prevent conflict with public toggleField method
|
||||
];
|
||||
protected array $_defaultConfig = [
|
||||
'field' => 'primary',
|
||||
'on' => 'afterSave', // afterSave (without transactions) or beforeSave (with transactions)
|
||||
'scopeFields' => [],
|
||||
'scope' => [],
|
||||
'findOrder' => null, // null = autodetect modified/created, false to disable
|
||||
'implementedMethods' => [], // to prevent conflict with public toggleField method
|
||||
];
|
||||
|
||||
/**
|
||||
/**
|
||||
* @param \Cake\Datasource\EntityInterface $entity
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function buildConditions(EntityInterface $entity) {
|
||||
$conditions = $this->getConfig('scope');
|
||||
$scopeFields = (array)$this->getConfig('scopeFields');
|
||||
protected function buildConditions(EntityInterface $entity) {
|
||||
$conditions = $this->getConfig('scope');
|
||||
$scopeFields = (array)$this->getConfig('scopeFields');
|
||||
|
||||
foreach ($scopeFields as $scopeField) {
|
||||
if ($entity->get($scopeField) === null) {
|
||||
continue;
|
||||
}
|
||||
$conditions[$scopeField] = $entity->get($scopeField);
|
||||
}
|
||||
foreach ($scopeFields as $scopeField) {
|
||||
if ($entity->get($scopeField) === null) {
|
||||
continue;
|
||||
}
|
||||
$conditions[$scopeField] = $entity->get($scopeField);
|
||||
}
|
||||
// dd($conditions);
|
||||
|
||||
return $conditions;
|
||||
}
|
||||
return $conditions;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
];
|
||||
}
|
||||
@@ -3,9 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\I18n\DateTime;
|
||||
use Cake\ORM\Entity;
|
||||
use CakeProducts\Model\Enum\ProductProductTypeId;
|
||||
|
||||
/**
|
||||
* Product Entity
|
||||
@@ -13,17 +11,16 @@ use CakeProducts\Model\Enum\ProductProductTypeId;
|
||||
* @property string $id
|
||||
* @property string $name
|
||||
* @property string $product_category_id
|
||||
* @property ProductProductTypeId $product_type_id
|
||||
* @property DateTime|null $deleted
|
||||
* @property \CakeProducts\Model\Enum\ProductProductTypeId $product_type_id
|
||||
* @property \Cake\I18n\DateTime|null $deleted
|
||||
*
|
||||
* @property ProductCategory $product_category
|
||||
* @property ProductAttribute[] $product_attributes
|
||||
* @property ProductCategoryVariant[] $product_category_variants
|
||||
*
|
||||
*/
|
||||
class Product extends Entity
|
||||
{
|
||||
/**
|
||||
class Product extends Entity {
|
||||
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
@@ -32,16 +29,17 @@ class Product extends Entity
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'name' => true,
|
||||
'product_category_id' => true,
|
||||
'product_type_id' => true,
|
||||
'deleted' => true,
|
||||
protected array $_accessible = [
|
||||
'name' => true,
|
||||
'product_category_id' => true,
|
||||
'product_type_id' => true,
|
||||
'deleted' => true,
|
||||
|
||||
// entities
|
||||
'product_category' => false,
|
||||
'product_attributes' => true,
|
||||
'product_category_variants' => true,
|
||||
'primary_product_photo' => true,
|
||||
];
|
||||
|
||||
// entities
|
||||
'product_category' => false,
|
||||
'product_attributes' => true,
|
||||
'product_category_variants' => true,
|
||||
'primary_product_photo' => true,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\I18n\DateTime;
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
@@ -14,15 +13,15 @@ use Cake\ORM\Entity;
|
||||
* @property string $product_category_attribute_id
|
||||
* @property string|null $attribute_value
|
||||
* @property string|null $product_category_attribute_option_id
|
||||
* @property DateTime|null $deleted
|
||||
* @property \Cake\I18n\DateTime|null $deleted
|
||||
*
|
||||
* @property Product $product
|
||||
* @property ProductCategoryAttribute $product_category_attribute
|
||||
* @property ProductCategoryAttributeOption $product_category_attribute_option
|
||||
*/
|
||||
class ProductAttribute extends Entity
|
||||
{
|
||||
/**
|
||||
class ProductAttribute extends Entity {
|
||||
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
@@ -31,16 +30,17 @@ class ProductAttribute extends Entity
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'product_id' => true,
|
||||
'product_category_attribute_id' => true,
|
||||
'attribute_value' => true,
|
||||
'product_category_attribute_option_id' => true,
|
||||
'deleted' => true,
|
||||
protected array $_accessible = [
|
||||
'product_id' => true,
|
||||
'product_category_attribute_id' => true,
|
||||
'attribute_value' => true,
|
||||
'product_category_attribute_option_id' => true,
|
||||
'deleted' => true,
|
||||
|
||||
// entities
|
||||
'product' => false,
|
||||
'product_category_attribute' => false,
|
||||
'product_category_attribute_option' => false,
|
||||
];
|
||||
|
||||
// entities
|
||||
'product' => false,
|
||||
'product_category_attribute' => false,
|
||||
'product_category_attribute_option' => false,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\I18n\DateTime;
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
@@ -13,14 +12,13 @@ use Cake\ORM\Entity;
|
||||
* @property string $name
|
||||
* @property string|null $catalog_description
|
||||
* @property bool $enabled
|
||||
* @property DateTime|null $deleted
|
||||
* @property \Cake\I18n\DateTime|null $deleted
|
||||
*
|
||||
* @property ProductCategory[] $product_categories
|
||||
* @property ExternalProductCatalog[] $external_product_catalogs
|
||||
*/
|
||||
class ProductCatalog extends Entity
|
||||
{
|
||||
/**
|
||||
class ProductCatalog extends Entity {
|
||||
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
@@ -29,14 +27,14 @@ class ProductCatalog extends Entity
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'name' => true,
|
||||
'catalog_description' => true,
|
||||
'enabled' => true,
|
||||
'deleted' => true,
|
||||
protected array $_accessible = [
|
||||
'name' => true,
|
||||
'catalog_description' => true,
|
||||
'enabled' => true,
|
||||
'deleted' => true,
|
||||
|
||||
// entities
|
||||
'product_categories' => true,
|
||||
];
|
||||
|
||||
// entities
|
||||
'product_categories' => true,
|
||||
'external_product_catalogs' => true,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -3,9 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\I18n\DateTime;
|
||||
use Cake\ORM\Entity;
|
||||
use CakeProducts\Model\Enum\ProductProductTypeId;
|
||||
|
||||
/**
|
||||
* ProductCategory Entity
|
||||
@@ -19,16 +17,16 @@ use CakeProducts\Model\Enum\ProductProductTypeId;
|
||||
* @property int $lft
|
||||
* @property int $rght
|
||||
* @property bool $enabled
|
||||
* @property DateTime|null $deleted
|
||||
* @property ProductProductTypeId|null $default_product_type_id
|
||||
* @property \Cake\I18n\DateTime|null $deleted
|
||||
* @property \CakeProducts\Model\Enum\ProductProductTypeId|null $default_product_type_id
|
||||
*
|
||||
* @property \CakeProducts\Model\Entity\ProductCatalog $product_catalog
|
||||
* @property \CakeProducts\Model\Entity\ParentProductCategory $parent_product_category
|
||||
* @property \CakeProducts\Model\Entity\ChildProductCategory[] $child_product_categories
|
||||
* @property ProductCatalog $product_catalog
|
||||
* @property ProductCategory $parent_product_category
|
||||
* @property ProductCategory[] $child_product_categories
|
||||
*/
|
||||
class ProductCategory extends Entity
|
||||
{
|
||||
/**
|
||||
class ProductCategory extends Entity {
|
||||
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
@@ -37,22 +35,23 @@ class ProductCategory extends Entity
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'product_catalog_id' => true,
|
||||
'internal_id' => true,
|
||||
'name' => true,
|
||||
'category_description' => true,
|
||||
'default_product_type_id' => true,
|
||||
'parent_id' => true,
|
||||
'lft' => true,
|
||||
'rght' => true,
|
||||
'enabled' => true,
|
||||
'deleted' => true,
|
||||
protected array $_accessible = [
|
||||
'product_catalog_id' => true,
|
||||
'internal_id' => true,
|
||||
'name' => true,
|
||||
'category_description' => true,
|
||||
'default_product_type_id' => true,
|
||||
'parent_id' => true,
|
||||
'lft' => true,
|
||||
'rght' => true,
|
||||
'enabled' => true,
|
||||
'deleted' => true,
|
||||
|
||||
// entities
|
||||
'product_catalog' => true,
|
||||
'parent_product_category' => true,
|
||||
'child_product_categories' => true,
|
||||
'primary_product_photo' => true,
|
||||
];
|
||||
|
||||
// entities
|
||||
'product_catalog' => true,
|
||||
'parent_product_category' => true,
|
||||
'child_product_categories' => true,
|
||||
'primary_product_photo' => true,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\I18n\DateTime;
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
@@ -14,14 +13,14 @@ use Cake\ORM\Entity;
|
||||
* @property string|null $product_category_id
|
||||
* @property int $attribute_type_id
|
||||
* @property bool $enabled
|
||||
* @property DateTime|null $deleted
|
||||
* @property \Cake\I18n\DateTime|null $deleted
|
||||
*
|
||||
* @property ProductCategory $product_category
|
||||
* @property ProductCategoryAttributeOption[] $product_category_attribute_options
|
||||
*/
|
||||
class ProductCategoryAttribute extends Entity
|
||||
{
|
||||
/**
|
||||
class ProductCategoryAttribute extends Entity {
|
||||
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
@@ -30,15 +29,16 @@ class ProductCategoryAttribute extends Entity
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'name' => true,
|
||||
'product_category_id' => true,
|
||||
'attribute_type_id' => true,
|
||||
'enabled' => true,
|
||||
'deleted' => true,
|
||||
protected array $_accessible = [
|
||||
'name' => true,
|
||||
'product_category_id' => true,
|
||||
'attribute_type_id' => true,
|
||||
'enabled' => true,
|
||||
'deleted' => true,
|
||||
|
||||
// entities
|
||||
'product_category' => true,
|
||||
'product_category_attribute_options' => true,
|
||||
];
|
||||
|
||||
// entities
|
||||
'product_category' => true,
|
||||
'product_category_attribute_options' => true,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\I18n\DateTime;
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
@@ -14,13 +13,13 @@ use Cake\ORM\Entity;
|
||||
* @property string $attribute_value
|
||||
* @property string $attribute_label
|
||||
* @property bool $enabled
|
||||
* @property DateTime|null $deleted
|
||||
* @property \Cake\I18n\DateTime|null $deleted
|
||||
*
|
||||
* @property ProductCategoryAttribute $product_category_attribute
|
||||
*/
|
||||
class ProductCategoryAttributeOption extends Entity
|
||||
{
|
||||
/**
|
||||
class ProductCategoryAttributeOption extends Entity {
|
||||
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
@@ -29,14 +28,15 @@ class ProductCategoryAttributeOption extends Entity
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'product_category_attribute_id' => true,
|
||||
'attribute_value' => true,
|
||||
'attribute_label' => true,
|
||||
'enabled' => true,
|
||||
'deleted' => true,
|
||||
protected array $_accessible = [
|
||||
'product_category_attribute_id' => true,
|
||||
'attribute_value' => true,
|
||||
'attribute_label' => true,
|
||||
'enabled' => true,
|
||||
'deleted' => true,
|
||||
|
||||
// entities
|
||||
'product_category_attribute' => true,
|
||||
];
|
||||
|
||||
// entities
|
||||
'product_category_attribute' => true,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
@@ -16,12 +15,12 @@ use Cake\ORM\Entity;
|
||||
* @property bool $enabled
|
||||
* @property bool $is_system_variant
|
||||
*
|
||||
* @property ProductCategory|EntityInterface $product_category
|
||||
* @property ProductCategoryVariantOption[]|EntityInterface[] $product_category_variant_options
|
||||
* @property ProductCategory $product_category
|
||||
* @property ProductCategoryVariantOption[] $product_category_variant_options
|
||||
*/
|
||||
class ProductCategoryVariant extends Entity
|
||||
{
|
||||
/**
|
||||
class ProductCategoryVariant extends Entity {
|
||||
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
@@ -30,16 +29,17 @@ class ProductCategoryVariant extends Entity
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'name' => true,
|
||||
'product_category_id' => true,
|
||||
'product_id' => true,
|
||||
'enabled' => true,
|
||||
'is_system_variant' => true,
|
||||
protected array $_accessible = [
|
||||
'name' => true,
|
||||
'product_category_id' => true,
|
||||
'product_id' => true,
|
||||
'enabled' => true,
|
||||
'is_system_variant' => true,
|
||||
|
||||
// entities
|
||||
'product_category' => false,
|
||||
'product' => false,
|
||||
'product_category_variant_options' => true,
|
||||
];
|
||||
|
||||
// entities
|
||||
'product_category' => false,
|
||||
'product' => false,
|
||||
'product_category_variant_options' => true,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -15,11 +15,11 @@ use Cake\ORM\Entity;
|
||||
* @property \Cake\I18n\DateTime $modified
|
||||
* @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().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
@@ -28,14 +28,15 @@ class ProductCategoryVariantOption extends Entity
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'product_category_variant_id' => true,
|
||||
'variant_value' => true,
|
||||
'created' => true,
|
||||
'modified' => true,
|
||||
'deleted' => true,
|
||||
protected array $_accessible = [
|
||||
'product_category_variant_id' => true,
|
||||
'variant_value' => true,
|
||||
'created' => true,
|
||||
'modified' => true,
|
||||
'deleted' => true,
|
||||
|
||||
// entities
|
||||
'product_category_variant' => false,
|
||||
];
|
||||
|
||||
// entities
|
||||
'product_category_variant' => false,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\I18n\DateTime;
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
@@ -20,17 +19,17 @@ use Cake\ORM\Entity;
|
||||
* @property bool $primary_sku_photo
|
||||
* @property int $photo_position
|
||||
* @property bool $enabled
|
||||
* @property DateTime $created
|
||||
* @property DateTime|null $modified
|
||||
* @property DateTime|null $deleted
|
||||
* @property \Cake\I18n\DateTime $created
|
||||
* @property \Cake\I18n\DateTime|null $modified
|
||||
* @property \Cake\I18n\DateTime|null $deleted
|
||||
*
|
||||
* @property Product|null $product
|
||||
* @property ProductSku|null $product_sku
|
||||
* @property ProductCategory $product_category
|
||||
*/
|
||||
class ProductPhoto extends Entity
|
||||
{
|
||||
/**
|
||||
class ProductPhoto extends Entity {
|
||||
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
@@ -39,24 +38,25 @@ class ProductPhoto extends Entity
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'product_id' => true,
|
||||
'product_sku_id' => true,
|
||||
'product_category_id' => true,
|
||||
'photo_dir' => true,
|
||||
'photo_filename' => true,
|
||||
'primary_photo' => true,
|
||||
'primary_category_photo' => true,
|
||||
'primary_sku_photo' => true,
|
||||
'photo_position' => true,
|
||||
'enabled' => true,
|
||||
'created' => true,
|
||||
'modified' => true,
|
||||
'deleted' => true,
|
||||
protected array $_accessible = [
|
||||
'product_id' => true,
|
||||
'product_sku_id' => true,
|
||||
'product_category_id' => true,
|
||||
'photo_dir' => true,
|
||||
'photo_filename' => true,
|
||||
'primary_photo' => true,
|
||||
'primary_category_photo' => true,
|
||||
'primary_sku_photo' => true,
|
||||
'photo_position' => true,
|
||||
'enabled' => true,
|
||||
'created' => true,
|
||||
'modified' => true,
|
||||
'deleted' => true,
|
||||
|
||||
// entities
|
||||
'product' => false,
|
||||
'product_sku' => false,
|
||||
'product_category' => false,
|
||||
];
|
||||
|
||||
// entities
|
||||
'product' => false,
|
||||
'product_sku' => false,
|
||||
'product_category' => false,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\I18n\DateTime;
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
@@ -15,17 +14,17 @@ use Cake\ORM\Entity;
|
||||
* @property string|null $barcode
|
||||
* @property string|null $price
|
||||
* @property string|null $cost
|
||||
* @property DateTime $created
|
||||
* @property DateTime|null $modified
|
||||
* @property DateTime|null $deleted
|
||||
* @property \Cake\I18n\DateTime $created
|
||||
* @property \Cake\I18n\DateTime|null $modified
|
||||
* @property \Cake\I18n\DateTime|null $deleted
|
||||
* @property bool $default_sku
|
||||
*
|
||||
* @property Product $product
|
||||
* @property ProductSkuVariantValue[] $product_sku_variant_values
|
||||
*/
|
||||
class ProductSku extends Entity
|
||||
{
|
||||
/**
|
||||
class ProductSku extends Entity {
|
||||
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
@@ -34,19 +33,20 @@ class ProductSku extends Entity
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'product_id' => true,
|
||||
'sku' => true,
|
||||
'barcode' => true,
|
||||
'price' => true,
|
||||
'cost' => true,
|
||||
'created' => true,
|
||||
'modified' => true,
|
||||
'deleted' => true,
|
||||
'default_sku' => true,
|
||||
protected array $_accessible = [
|
||||
'product_id' => true,
|
||||
'sku' => true,
|
||||
'barcode' => true,
|
||||
'price' => true,
|
||||
'cost' => true,
|
||||
'created' => true,
|
||||
'modified' => true,
|
||||
'deleted' => true,
|
||||
'default_sku' => true,
|
||||
|
||||
// entities
|
||||
'product' => false,
|
||||
'product_sku_variant_values' => true,
|
||||
];
|
||||
|
||||
// entities
|
||||
'product' => false,
|
||||
'product_sku_variant_values' => true,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ use Cake\ORM\Entity;
|
||||
* @property ProductCategoryVariant $product_category_variant
|
||||
* @property ProductCategoryVariantOption $product_category_variant_option
|
||||
*/
|
||||
class ProductSkuVariantValue extends Entity
|
||||
{
|
||||
/**
|
||||
class ProductSkuVariantValue extends Entity {
|
||||
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
@@ -28,14 +28,15 @@ class ProductSkuVariantValue extends Entity
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'product_sku_id' => true,
|
||||
'product_variant_id' => true,
|
||||
'product_category_variant_option_id' => true,
|
||||
protected array $_accessible = [
|
||||
'product_sku_id' => true,
|
||||
'product_variant_id' => true,
|
||||
'product_category_variant_option_id' => true,
|
||||
|
||||
// entities
|
||||
'product_sku' => true,
|
||||
'product_variant' => true,
|
||||
'product_category_variant_option' => true,
|
||||
];
|
||||
|
||||
// entities
|
||||
'product_sku' => true,
|
||||
'product_variant' => true,
|
||||
'product_category_variant_option' => true,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -14,12 +14,12 @@ use Cake\ORM\Entity;
|
||||
* @property string $product_id
|
||||
* @property bool $enabled
|
||||
*
|
||||
* @property \App\Model\Entity\ProductCategoryVariant $product_category_variant
|
||||
* @property \App\Model\Entity\Product $product
|
||||
* @property ProductCategoryVariant $product_category_variant
|
||||
* @property Product $product
|
||||
*/
|
||||
class ProductVariant extends Entity
|
||||
{
|
||||
/**
|
||||
class ProductVariant extends Entity {
|
||||
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
@@ -28,12 +28,13 @@ class ProductVariant extends Entity
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'name' => true,
|
||||
'product_category_variant_id' => true,
|
||||
'product_id' => true,
|
||||
'enabled' => true,
|
||||
'product_category_variant' => true,
|
||||
'product' => true,
|
||||
];
|
||||
protected array $_accessible = [
|
||||
'name' => true,
|
||||
'product_category_variant_id' => true,
|
||||
'product_id' => true,
|
||||
'enabled' => true,
|
||||
'product_category_variant' => true,
|
||||
'product' => true,
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
@@ -1,23 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace CakeProducts\Model\Enum;
|
||||
|
||||
use Cake\Database\Type\EnumLabelInterface;
|
||||
use Tools\Model\Enum\EnumOptionsTrait;
|
||||
|
||||
enum ProductCategoryAttributeTypeId: int implements EnumLabelInterface
|
||||
{
|
||||
use EnumOptionsTrait;
|
||||
enum ProductCategoryAttributeTypeId: int implements EnumLabelInterface {
|
||||
use EnumOptionsTrait;
|
||||
|
||||
case Constrained = 1;
|
||||
case Text = 2;
|
||||
case Integer = 3;
|
||||
case Constrained = 1;
|
||||
case Text = 2;
|
||||
case Integer = 3;
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match($this) {
|
||||
self::Constrained => 'Constrained',
|
||||
self::Text => 'Text',
|
||||
self::Integer => 'Integer'
|
||||
};
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function label(): string {
|
||||
return match ($this) {
|
||||
ProductCategoryAttributeTypeId::Constrained => 'Constrained',
|
||||
ProductCategoryAttributeTypeId::Text => 'Text',
|
||||
ProductCategoryAttributeTypeId::Integer => 'Integer'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace CakeProducts\Model\Enum;
|
||||
|
||||
use Cake\Database\Type\EnumLabelInterface;
|
||||
@@ -6,24 +7,26 @@ use Tools\Model\Enum\EnumOptionsTrait;
|
||||
|
||||
enum ProductProductTypeId: int implements EnumLabelInterface
|
||||
{
|
||||
use EnumOptionsTrait;
|
||||
use EnumOptionsTrait;
|
||||
|
||||
case Service = 1;
|
||||
case Product = 2;
|
||||
case Consumable = 3;
|
||||
case DigitalGood = 4;
|
||||
case Subscription = 5;
|
||||
case Service = 1;
|
||||
case Product = 2;
|
||||
case Consumable = 3;
|
||||
case DigitalGood = 4;
|
||||
case Subscription = 5;
|
||||
// case Event = 5;
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match($this) {
|
||||
self::Service => 'Service',
|
||||
self::Product => 'Product',
|
||||
self::Consumable => 'Consumable',
|
||||
self::DigitalGood => 'Digital Good',
|
||||
self::Subscription => 'Subscription',
|
||||
// self::Event => 'Event',
|
||||
};
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function label(): string {
|
||||
return match ($this) {
|
||||
ProductProductTypeId::Service => 'Service',
|
||||
ProductProductTypeId::Product => 'Product',
|
||||
ProductProductTypeId::Consumable => 'Consumable',
|
||||
ProductProductTypeId::DigitalGood => 'Digital Good',
|
||||
ProductProductTypeId::Subscription => 'Subscription',
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
@@ -11,106 +11,104 @@ use Cake\Validation\Validator;
|
||||
/**
|
||||
* ProductAttributes Model
|
||||
*
|
||||
* @property \App\Model\Table\ProductsTable&\Cake\ORM\Association\BelongsTo $Products
|
||||
* @property \App\Model\Table\ProductCategoryAttributesTable&\Cake\ORM\Association\BelongsTo $ProductCategoryAttributes
|
||||
* @property \App\Model\Table\ProductCategoryAttributeOptionsTable&\Cake\ORM\Association\BelongsTo $ProductCategoryAttributeOptions
|
||||
* @property ProductsTable&\Cake\ORM\Association\BelongsTo $Products
|
||||
* @property ProductCategoryAttributesTable&\Cake\ORM\Association\BelongsTo $ProductCategoryAttributes
|
||||
* @property ProductCategoryAttributeOptionsTable&\Cake\ORM\Association\BelongsTo $ProductCategoryAttributeOptions
|
||||
*
|
||||
* @method \App\Model\Entity\ProductAttribute newEmptyEntity()
|
||||
* @method \App\Model\Entity\ProductAttribute newEntity(array $data, array $options = [])
|
||||
* @method array<\App\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 \App\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 array<\App\Model\Entity\ProductAttribute> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method \App\Model\Entity\ProductAttribute|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
||||
* @method \App\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<\App\Model\Entity\ProductAttribute>|\Cake\Datasource\ResultSetInterface<\App\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<\App\Model\Entity\ProductAttribute>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\ProductAttribute> deleteManyOrFail(iterable $entities, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductAttribute newEmptyEntity()
|
||||
* @method \CakeProducts\Model\Entity\ProductAttribute newEntity(array $data, array $options = [])
|
||||
* @method array<\CakeProducts\Model\Entity\ProductAttribute> newEntities(array $data, array $options = [])
|
||||
* @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 \CakeProducts\Model\Entity\ProductAttribute findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductAttribute patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
|
||||
* @method array<\CakeProducts\Model\Entity\ProductAttribute> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductAttribute|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductAttribute saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
||||
* @method iterable<\CakeProducts\Model\Entity\ProductAttribute>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductAttribute>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<\CakeProducts\Model\Entity\ProductAttribute>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductAttribute> saveManyOrFail(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<\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
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('product_attributes');
|
||||
$this->setDisplayField('id');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setTable('product_attributes');
|
||||
$this->setDisplayField('id');
|
||||
$this->setPrimaryKey('id');
|
||||
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductAttributes.entity', 'CakeProducts\Model\Entity\ProductAttribute')
|
||||
);
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductAttributes.entity', 'CakeProducts\Model\Entity\ProductAttribute'),
|
||||
);
|
||||
|
||||
$this->belongsTo('Products', [
|
||||
'foreignKey' => 'product_id',
|
||||
'className' => 'CakeProducts.Products',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
$this->belongsTo('ProductCategoryAttributes', [
|
||||
'foreignKey' => 'product_category_attribute_id',
|
||||
'className' => 'CakeProducts.ProductCategoryAttributes',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
$this->belongsTo('ProductCategoryAttributeOptions', [
|
||||
'foreignKey' => 'product_category_attribute_option_id',
|
||||
'className' => 'CakeProducts.ProductCategoryAttributeOptions',
|
||||
]);
|
||||
$this->belongsTo('Products', [
|
||||
'foreignKey' => 'product_id',
|
||||
'className' => 'CakeProducts.Products',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
$this->belongsTo('ProductCategoryAttributes', [
|
||||
'foreignKey' => 'product_category_attribute_id',
|
||||
'className' => 'CakeProducts.ProductCategoryAttributes',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
$this->belongsTo('ProductCategoryAttributeOptions', [
|
||||
'foreignKey' => 'product_category_attribute_option_id',
|
||||
'className' => 'CakeProducts.ProductCategoryAttributeOptions',
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->uuid('product_id')
|
||||
->notEmptyString('product_id');
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->uuid('product_id')
|
||||
->notEmptyString('product_id');
|
||||
|
||||
$validator
|
||||
->uuid('product_category_attribute_id')
|
||||
->notEmptyString('product_category_attribute_id');
|
||||
$validator
|
||||
->uuid('product_category_attribute_id')
|
||||
->notEmptyString('product_category_attribute_id');
|
||||
|
||||
$validator
|
||||
->scalar('attribute_value')
|
||||
->maxLength('attribute_value', 255)
|
||||
->allowEmptyString('attribute_value');
|
||||
$validator
|
||||
->scalar('attribute_value')
|
||||
->maxLength('attribute_value', 255)
|
||||
->allowEmptyString('attribute_value');
|
||||
|
||||
$validator
|
||||
->uuid('product_category_attribute_option_id')
|
||||
->allowEmptyString('product_category_attribute_option_id');
|
||||
$validator
|
||||
->uuid('product_category_attribute_option_id')
|
||||
->allowEmptyString('product_category_attribute_option_id');
|
||||
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
|
||||
return $validator;
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
|
||||
$rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']);
|
||||
$rules->add($rules->existsIn(['product_category_attribute_option_id'], 'ProductCategoryAttributeOptions'), ['errorField' => 'product_category_attribute_option_id']);
|
||||
public function buildRules(RulesChecker $rules): RulesChecker {
|
||||
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
|
||||
$rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']);
|
||||
$rules->add($rules->existsIn(['product_category_attribute_option_id'], 'ProductCategoryAttributeOptions'), ['errorField' => 'product_category_attribute_option_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,106 +4,94 @@ declare(strict_types=1);
|
||||
namespace CakeProducts\Model\Table;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Datasource\ResultSetInterface;
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use CakeProducts\Model\Entity\ProductCatalog;
|
||||
use Closure;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
/**
|
||||
* ProductCatalogs Model
|
||||
*
|
||||
* @method ProductCatalog newEmptyEntity()
|
||||
* @method ProductCatalog newEntity(array $data, array $options = [])
|
||||
* @method array<ProductCatalog> newEntities(array $data, array $options = [])
|
||||
* @method ProductCatalog get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
|
||||
* @method ProductCatalog findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method ProductCatalog patchEntity(EntityInterface $entity, array $data, array $options = [])
|
||||
* @method array<ProductCatalog> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method ProductCatalog|false save(EntityInterface $entity, array $options = [])
|
||||
* @method ProductCatalog saveOrFail(EntityInterface $entity, array $options = [])
|
||||
* @method iterable<ProductCatalog>|ResultSetInterface<ProductCatalog>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCatalog>|ResultSetInterface<ProductCatalog> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCatalog>|ResultSetInterface<ProductCatalog>|false deleteMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCatalog>|ResultSetInterface<ProductCatalog> deleteManyOrFail(iterable $entities, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCatalog newEmptyEntity()
|
||||
* @method \CakeProducts\Model\Entity\ProductCatalog newEntity(array $data, array $options = [])
|
||||
* @method array<\CakeProducts\Model\Entity\ProductCatalog> newEntities(array $data, array $options = [])
|
||||
* @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 \CakeProducts\Model\Entity\ProductCatalog findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCatalog patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
|
||||
* @method array<\CakeProducts\Model\Entity\ProductCatalog> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCatalog|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCatalog saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
||||
* @method iterable<\CakeProducts\Model\Entity\ProductCatalog>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCatalog>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<\CakeProducts\Model\Entity\ProductCatalog>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCatalog> saveManyOrFail(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<\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
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('product_catalogs');
|
||||
$this->setDisplayField('name');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setTable('product_catalogs');
|
||||
$this->setDisplayField('name');
|
||||
$this->setPrimaryKey('id');
|
||||
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductCatalogs.entity', 'CakeProducts\Model\Entity\ProductCatalog')
|
||||
);
|
||||
$this->hasMany('ProductCategories', [
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
]);
|
||||
$this->belongsToMany('ExternalProductCatalogs', [
|
||||
'through' => 'ExternalProductCatalogsProductCatalogs',
|
||||
'className' => 'CakeProducts.ExternalProductCatalogs',
|
||||
]);
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductCatalogs.entity', 'CakeProducts\Model\Entity\ProductCatalog'),
|
||||
);
|
||||
$this->hasMany('ProductCategories', [
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
]);
|
||||
|
||||
$this->addBehavior('Muffin/Trash.Trash');
|
||||
}
|
||||
$this->addBehavior('Muffin/Trash.Trash');
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param Validator $validator Validator instance.
|
||||
* @return Validator
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->scalar('name')
|
||||
->maxLength('name', 255)
|
||||
->requirePresence('name', 'create')
|
||||
->notEmptyString('name')
|
||||
->add('name', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']);
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->scalar('name')
|
||||
->maxLength('name', 255)
|
||||
->requirePresence('name', 'create')
|
||||
->notEmptyString('name')
|
||||
->add('name', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']);
|
||||
|
||||
$validator
|
||||
->scalar('catalog_description')
|
||||
->maxLength('catalog_description', 255)
|
||||
->allowEmptyString('catalog_description');
|
||||
$validator
|
||||
->scalar('catalog_description')
|
||||
->maxLength('catalog_description', 255)
|
||||
->allowEmptyString('catalog_description');
|
||||
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
->requirePresence('enabled', 'create')
|
||||
->notEmptyString('enabled');
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
->requirePresence('enabled', 'create')
|
||||
->notEmptyString('enabled');
|
||||
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
|
||||
return $validator;
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param RulesChecker $rules The rules object to be modified.
|
||||
* @return RulesChecker
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
$rules->add($rules->isUnique(['name']), ['errorField' => 'name']);
|
||||
public function buildRules(RulesChecker $rules): RulesChecker {
|
||||
$rules->add($rules->isUnique(['name']), ['errorField' => 'name']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,210 +6,198 @@ namespace CakeProducts\Model\Table;
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Database\Type\EnumType;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Datasource\ResultSetInterface;
|
||||
use Cake\ORM\Association\BelongsTo;
|
||||
use Cake\ORM\Association\HasMany;
|
||||
use Cake\ORM\Behavior\TreeBehavior;
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use CakeProducts\Model\Entity\ProductCategory;
|
||||
use CakeProducts\Model\Enum\ProductProductTypeId;
|
||||
use Closure;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
/**
|
||||
* ProductCategories Model
|
||||
*
|
||||
* @property ProductCatalogsTable&BelongsTo $ProductCatalogs
|
||||
* @property ProductCategoriesTable&BelongsTo $ParentProductCategories
|
||||
* @property ProductCategoriesTable&HasMany $ChildProductCategories
|
||||
* @property ProductCatalogsTable&\Cake\ORM\Association\BelongsTo $ProductCatalogs
|
||||
* @property ProductCategoriesTable&\Cake\ORM\Association\BelongsTo $ParentProductCategories
|
||||
* @property ProductCategoriesTable&\Cake\ORM\Association\HasMany $ChildProductCategories
|
||||
*
|
||||
* @method ProductCategory newEmptyEntity()
|
||||
* @method ProductCategory newEntity(array $data, array $options = [])
|
||||
* @method array<ProductCategory> newEntities(array $data, array $options = [])
|
||||
* @method ProductCategory get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
|
||||
* @method ProductCategory findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method ProductCategory patchEntity(EntityInterface $entity, array $data, array $options = [])
|
||||
* @method array<ProductCategory> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method ProductCategory saveOrFail(EntityInterface $entity, array $options = [])
|
||||
* @method iterable<ProductCategory>|ResultSetInterface<ProductCategory>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategory>|ResultSetInterface<ProductCategory> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategory>|ResultSetInterface<ProductCategory>|false deleteMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategory>|ResultSetInterface<ProductCategory> deleteManyOrFail(iterable $entities, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategory newEmptyEntity()
|
||||
* @method \CakeProducts\Model\Entity\ProductCategory newEntity(array $data, array $options = [])
|
||||
* @method array<\CakeProducts\Model\Entity\ProductCategory> newEntities(array $data, array $options = [])
|
||||
* @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 \CakeProducts\Model\Entity\ProductCategory findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategory patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
|
||||
* @method array<\CakeProducts\Model\Entity\ProductCategory> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategory saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
||||
* @method iterable<\CakeProducts\Model\Entity\ProductCategory>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategory>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<\CakeProducts\Model\Entity\ProductCategory>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategory> saveManyOrFail(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<\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
|
||||
*
|
||||
* @var string
|
||||
* @var string|int
|
||||
*/
|
||||
protected $treeCatalogId;
|
||||
protected $treeCatalogId;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Initialize method
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
$this->treeCatalogId = 1;
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
$this->treeCatalogId = 1;
|
||||
|
||||
$this->setTable('product_categories');
|
||||
$this->setDisplayField('name');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductCategories.entity', 'CakeProducts\Model\Entity\ProductCategory')
|
||||
);
|
||||
$this->addBehavior('Tree', [
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->setTable('product_categories');
|
||||
$this->setDisplayField('name');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductCategories.entity', 'CakeProducts\Model\Entity\ProductCategory'),
|
||||
);
|
||||
$this->addBehavior('Tree', [
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
|
||||
$this->belongsTo('ProductCatalogs', [
|
||||
'foreignKey' => 'product_catalog_id',
|
||||
'joinType' => 'INNER',
|
||||
'className' => 'CakeProducts.ProductCatalogs',
|
||||
]);
|
||||
$this->belongsTo('ParentProductCategories', [
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
'foreignKey' => 'parent_id',
|
||||
]);
|
||||
$this->hasMany('ChildProductCategories', [
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
'foreignKey' => 'parent_id',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ProductCategoryAttributes', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'className' => 'CakeProducts.ProductCategoryAttributes',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ProductCategoryVariants', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'className' => 'CakeProducts.ProductCategoryVariants',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('Products', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'className' => 'CakeProducts.Products',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ProductPhotos', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'className' => 'CakeProducts.ProductPhotos',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasOne('PrimaryProductPhotos', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'conditions' => ['PrimaryProductPhotos.primary_category_photo' => true],
|
||||
'className' => 'CakeProducts.ProductPhotos',
|
||||
'dependent' => true,
|
||||
]);
|
||||
$this->belongsTo('ProductCatalogs', [
|
||||
'className' => 'CakeProducts.ProductCatalogs',
|
||||
'foreignKey' => 'product_catalog_id',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
$this->belongsTo('ParentProductCategories', [
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
'foreignKey' => 'parent_id',
|
||||
]);
|
||||
$this->hasMany('ChildProductCategories', [
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
'foreignKey' => 'parent_id',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ProductCategoryAttributes', [
|
||||
'className' => 'CakeProducts.ProductCategoryAttributes',
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ProductCategoryVariants', [
|
||||
'className' => 'CakeProducts.ProductCategoryVariants',
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('Products', [
|
||||
'className' => 'CakeProducts.Products',
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ProductPhotos', [
|
||||
'className' => 'CakeProducts.ProductPhotos',
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasOne('PrimaryProductPhotos', [
|
||||
'className' => 'CakeProducts.ProductPhotos',
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'conditions' => ['PrimaryProductPhotos.primary_category_photo' => 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->addBehavior('Muffin/Trash.Trash');
|
||||
}
|
||||
$this->getBehavior('Tree')->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]);
|
||||
$this->addBehavior('Muffin/Trash.Trash');
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param Validator $validator Validator instance.
|
||||
* @return Validator
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->uuid('product_catalog_id')
|
||||
->notEmptyString('product_catalog_id');
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->uuid('product_catalog_id')
|
||||
->notEmptyString('product_catalog_id');
|
||||
|
||||
$validator
|
||||
->scalar('name')
|
||||
->maxLength('name', 255)
|
||||
->requirePresence('name', 'create')
|
||||
->notEmptyString('name');
|
||||
$validator
|
||||
->scalar('name')
|
||||
->maxLength('name', 255)
|
||||
->requirePresence('name', 'create')
|
||||
->notEmptyString('name');
|
||||
|
||||
$validator
|
||||
->scalar('category_description')
|
||||
->allowEmptyString('category_description');
|
||||
$validator
|
||||
->scalar('category_description')
|
||||
->allowEmptyString('category_description');
|
||||
|
||||
$validator
|
||||
->integer('parent_id')
|
||||
->allowEmptyString('parent_id');
|
||||
$validator
|
||||
->integer('parent_id')
|
||||
->allowEmptyString('parent_id');
|
||||
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
->notEmptyString('enabled');
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
->notEmptyString('enabled');
|
||||
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
|
||||
$validator
|
||||
->integer('default_product_type_id')
|
||||
->allowEmptyString('default_product_type_id');
|
||||
$validator
|
||||
->integer('default_product_type_id')
|
||||
->allowEmptyString('default_product_type_id');
|
||||
|
||||
return $validator;
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param RulesChecker $rules The rules object to be modified.
|
||||
* @return RulesChecker
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
$rules->add($rules->isUnique(['product_catalog_id', 'name']), ['errorField' => 'product_catalog_id']);
|
||||
$rules->add($rules->existsIn(['product_catalog_id'], 'ProductCatalogs'), ['errorField' => 'product_catalog_id']);
|
||||
$rules->add($rules->existsIn(['parent_id'], 'ParentProductCategories'), ['errorField' => 'parent_id']);
|
||||
public function buildRules(RulesChecker $rules): RulesChecker {
|
||||
$rules->add($rules->isUnique(['product_catalog_id', 'name']), ['errorField' => 'product_catalog_id']);
|
||||
$rules->add($rules->existsIn(['product_catalog_id'], 'ProductCatalogs'), ['errorField' => 'product_catalog_id']);
|
||||
$rules->add($rules->existsIn(['parent_id'], 'ParentProductCategories'), ['errorField' => 'parent_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $catalogId
|
||||
/**
|
||||
* @param string $catalogId
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setConfigureCatalogId(string $catalogId)
|
||||
{
|
||||
$this->treeCatalogId = $catalogId;
|
||||
$this->behaviors()->Tree->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]);
|
||||
}
|
||||
public function setConfigureCatalogId(string $catalogId) {
|
||||
$this->treeCatalogId = $catalogId;
|
||||
$this->getBehavior('Tree')->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EntityInterface $entity
|
||||
/**
|
||||
* @param \Cake\Datasource\EntityInterface $entity
|
||||
* @param array $options
|
||||
*
|
||||
* @return EntityInterface|false
|
||||
* @return \Cake\Datasource\EntityInterface|false
|
||||
*/
|
||||
public function save(EntityInterface $entity, array $options = []): EntityInterface|false
|
||||
{
|
||||
$this->behaviors()->get('Tree')->setConfig([
|
||||
'scope' => [
|
||||
'product_catalog_id' => $entity->product_catalog_id,
|
||||
],
|
||||
]);
|
||||
public function save(EntityInterface $entity, array $options = []): EntityInterface|false {
|
||||
$this->behaviors()->get('Tree')->setConfig([
|
||||
'scope' => [
|
||||
'product_catalog_id' => $entity->product_catalog_id ?? null,
|
||||
],
|
||||
]);
|
||||
|
||||
return parent::save($entity, $options);
|
||||
}
|
||||
|
||||
return parent::save($entity, $options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,112 +4,103 @@ declare(strict_types=1);
|
||||
namespace CakeProducts\Model\Table;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Datasource\ResultSetInterface;
|
||||
use Cake\ORM\Association\BelongsTo;
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use CakeProducts\Model\Entity\ProductCategoryAttributeOption;
|
||||
use Closure;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
/**
|
||||
* ProductCategoryAttributeOptions Model
|
||||
*
|
||||
* @property ProductCategoryAttributesTable&BelongsTo $ProductCategoryAttributes
|
||||
* @property ProductCategoryAttributesTable&\Cake\ORM\Association\BelongsTo $ProductCategoryAttributes
|
||||
*
|
||||
* @method ProductCategoryAttributeOption newEmptyEntity()
|
||||
* @method ProductCategoryAttributeOption newEntity(array $data, array $options = [])
|
||||
* @method array<ProductCategoryAttributeOption> newEntities(array $data, array $options = [])
|
||||
* @method ProductCategoryAttributeOption get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
|
||||
* @method ProductCategoryAttributeOption findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method ProductCategoryAttributeOption patchEntity(EntityInterface $entity, array $data, array $options = [])
|
||||
* @method array<ProductCategoryAttributeOption> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method ProductCategoryAttributeOption|false save(EntityInterface $entity, array $options = [])
|
||||
* @method ProductCategoryAttributeOption saveOrFail(EntityInterface $entity, array $options = [])
|
||||
* @method iterable<ProductCategoryAttributeOption>|ResultSetInterface<ProductCategoryAttributeOption>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategoryAttributeOption>|ResultSetInterface<ProductCategoryAttributeOption> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategoryAttributeOption>|ResultSetInterface<ProductCategoryAttributeOption>|false deleteMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategoryAttributeOption>|ResultSetInterface<ProductCategoryAttributeOption> deleteManyOrFail(iterable $entities, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption newEmptyEntity()
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption newEntity(array $data, array $options = [])
|
||||
* @method array<\CakeProducts\Model\Entity\ProductCategoryAttributeOption> newEntities(array $data, array $options = [])
|
||||
* @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 \CakeProducts\Model\Entity\ProductCategoryAttributeOption findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
|
||||
* @method array<\CakeProducts\Model\Entity\ProductCategoryAttributeOption> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
||||
* @method iterable<\CakeProducts\Model\Entity\ProductCategoryAttributeOption>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategoryAttributeOption>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<\CakeProducts\Model\Entity\ProductCategoryAttributeOption>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategoryAttributeOption> saveManyOrFail(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<\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
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('product_category_attribute_options');
|
||||
$this->setDisplayField('attribute_value');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setTable('product_category_attribute_options');
|
||||
$this->setDisplayField('attribute_value');
|
||||
$this->setPrimaryKey('id');
|
||||
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductCategoryAttributeOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryAttributeOption')
|
||||
);
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductCategoryAttributeOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryAttributeOption'),
|
||||
);
|
||||
|
||||
$this->belongsTo('ProductCategoryAttributes', [
|
||||
'foreignKey' => 'product_category_attribute_id',
|
||||
'joinType' => 'INNER',
|
||||
'className' => 'CakeProducts.ProductCategoryAttributes',
|
||||
]);
|
||||
$this->belongsTo('ProductCategoryAttributes', [
|
||||
'foreignKey' => 'product_category_attribute_id',
|
||||
'joinType' => 'INNER',
|
||||
'className' => 'CakeProducts.ProductCategoryAttributes',
|
||||
]);
|
||||
|
||||
$this->addBehavior('Muffin/Trash.Trash');
|
||||
}
|
||||
$this->addBehavior('Muffin/Trash.Trash');
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param Validator $validator Validator instance.
|
||||
* @return Validator
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->uuid('product_category_attribute_id')
|
||||
->notEmptyString('product_category_attribute_id');
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->uuid('product_category_attribute_id')
|
||||
->notEmptyString('product_category_attribute_id');
|
||||
|
||||
$validator
|
||||
->scalar('attribute_value')
|
||||
->maxLength('attribute_value', 255)
|
||||
->requirePresence('attribute_value', 'create')
|
||||
->notEmptyString('attribute_value');
|
||||
$validator
|
||||
->scalar('attribute_value')
|
||||
->maxLength('attribute_value', 255)
|
||||
->requirePresence('attribute_value', 'create')
|
||||
->notEmptyString('attribute_value');
|
||||
|
||||
$validator
|
||||
->scalar('attribute_label')
|
||||
->maxLength('attribute_label', 255)
|
||||
->requirePresence('attribute_label', 'create')
|
||||
->notEmptyString('attribute_label');
|
||||
$validator
|
||||
->scalar('attribute_label')
|
||||
->maxLength('attribute_label', 255)
|
||||
->requirePresence('attribute_label', 'create')
|
||||
->notEmptyString('attribute_label');
|
||||
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
->notEmptyString('enabled');
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
->notEmptyString('enabled');
|
||||
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
|
||||
return $validator;
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param RulesChecker $rules The rules object to be modified.
|
||||
* @return RulesChecker
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
$rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']);
|
||||
$rules->add($rules->isUnique(['attribute_value', 'product_category_attribute_id']));
|
||||
public function buildRules(RulesChecker $rules): RulesChecker {
|
||||
$rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']);
|
||||
$rules->add($rules->isUnique(['attribute_value', 'product_category_attribute_id']));
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,146 +5,141 @@ namespace CakeProducts\Model\Table;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Database\Type\EnumType;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Datasource\ResultSetInterface;
|
||||
use Cake\ORM\Association\BelongsTo;
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use CakeProducts\Model\Entity\ProductCategoryAttribute;
|
||||
use CakeProducts\Model\Enum\ProductCategoryAttributeTypeId;
|
||||
use Closure;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
/**
|
||||
* ProductCategoryAttributes Model
|
||||
*
|
||||
* @property ProductCategoriesTable&BelongsTo $ProductCategories
|
||||
* @property ProductCategoriesTable&\Cake\ORM\Association\BelongsTo $ProductCategories
|
||||
*
|
||||
* @method ProductCategoryAttribute newEmptyEntity()
|
||||
* @method ProductCategoryAttribute newEntity(array $data, array $options = [])
|
||||
* @method array<ProductCategoryAttribute> newEntities(array $data, array $options = [])
|
||||
* @method ProductCategoryAttribute get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
|
||||
* @method ProductCategoryAttribute findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method ProductCategoryAttribute patchEntity(EntityInterface $entity, array $data, array $options = [])
|
||||
* @method array<ProductCategoryAttribute> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method ProductCategoryAttribute|false save(EntityInterface $entity, array $options = [])
|
||||
* @method ProductCategoryAttribute saveOrFail(EntityInterface $entity, array $options = [])
|
||||
* @method iterable<ProductCategoryAttribute>|ResultSetInterface<ProductCategoryAttribute>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategoryAttribute>|ResultSetInterface<ProductCategoryAttribute> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategoryAttribute>|ResultSetInterface<ProductCategoryAttribute>|false deleteMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategoryAttribute>|ResultSetInterface<ProductCategoryAttribute> deleteManyOrFail(iterable $entities, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryAttribute newEmptyEntity()
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryAttribute newEntity(array $data, array $options = [])
|
||||
* @method array<\CakeProducts\Model\Entity\ProductCategoryAttribute> newEntities(array $data, array $options = [])
|
||||
* @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 \CakeProducts\Model\Entity\ProductCategoryAttribute findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryAttribute patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
|
||||
* @method array<\CakeProducts\Model\Entity\ProductCategoryAttribute> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryAttribute|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryAttribute saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
||||
* @method iterable<\CakeProducts\Model\Entity\ProductCategoryAttribute>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategoryAttribute>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<\CakeProducts\Model\Entity\ProductCategoryAttribute>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategoryAttribute> saveManyOrFail(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<\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
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('product_category_attributes');
|
||||
$this->setDisplayField('name');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setTable('product_category_attributes');
|
||||
$this->setDisplayField('name');
|
||||
$this->setPrimaryKey('id');
|
||||
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductCategoryAttributes.entity', 'CakeProducts\Model\Entity\ProductCategoryAttribute')
|
||||
);
|
||||
$this->belongsTo('ProductCategories', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
]);
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductCategoryAttributes.entity', 'CakeProducts\Model\Entity\ProductCategoryAttribute'),
|
||||
);
|
||||
$this->belongsTo('ProductCategories', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
]);
|
||||
|
||||
$this->hasMany('ProductCategoryAttributeOptions', [
|
||||
'foreignKey' => 'product_category_attribute_id',
|
||||
'className' => 'CakeProducts.ProductCategoryAttributeOptions',
|
||||
'saveStrategy' => 'replace',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->getSchema()->setColumnType('attribute_type_id', EnumType::from(ProductCategoryAttributeTypeId::class));
|
||||
$this->hasMany('ProductCategoryAttributeOptions', [
|
||||
'foreignKey' => 'product_category_attribute_id',
|
||||
'className' => 'CakeProducts.ProductCategoryAttributeOptions',
|
||||
'saveStrategy' => 'replace',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->getSchema()->setColumnType('attribute_type_id', EnumType::from(ProductCategoryAttributeTypeId::class));
|
||||
|
||||
$this->addBehavior('Muffin/Trash.Trash');
|
||||
}
|
||||
$this->addBehavior('Muffin/Trash.Trash');
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param Validator $validator Validator instance.
|
||||
* @return Validator
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->scalar('name')
|
||||
->maxLength('name', 255)
|
||||
->requirePresence('name', 'create')
|
||||
->notEmptyString('name');
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->scalar('name')
|
||||
->maxLength('name', 255)
|
||||
->requirePresence('name', 'create')
|
||||
->notEmptyString('name');
|
||||
|
||||
$validator
|
||||
->uuid('product_category_id')
|
||||
->allowEmptyString('product_category_id');
|
||||
$validator
|
||||
->uuid('product_category_id')
|
||||
->allowEmptyString('product_category_id');
|
||||
|
||||
$validator
|
||||
->integer('attribute_type_id')
|
||||
->requirePresence('attribute_type_id', 'create')
|
||||
->notEmptyString('attribute_type_id');
|
||||
$validator
|
||||
->integer('attribute_type_id')
|
||||
->requirePresence('attribute_type_id', 'create')
|
||||
->notEmptyString('attribute_type_id');
|
||||
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
->requirePresence('enabled', 'create')
|
||||
->notEmptyString('enabled');
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
->requirePresence('enabled', 'create')
|
||||
->notEmptyString('enabled');
|
||||
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
|
||||
return $validator;
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param RulesChecker $rules The rules object to be modified.
|
||||
* @return RulesChecker
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
$rules->add($rules->isUnique(['name', 'product_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'name']);
|
||||
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
|
||||
public function buildRules(RulesChecker $rules): RulesChecker {
|
||||
$rules->add($rules->isUnique(['name', 'product_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'name']);
|
||||
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SelectQuery $query
|
||||
/**
|
||||
* @param \Cake\ORM\Query\SelectQuery $query
|
||||
* @param string $internalCategoryId
|
||||
*
|
||||
* @return array|\Cake\ORM\Query|SelectQuery
|
||||
* @return \Cake\ORM\Query|\Cake\ORM\Query\SelectQuery|array
|
||||
*/
|
||||
public function findAllCategoryAttributesForCategoryId(SelectQuery $query, string $internalCategoryId)
|
||||
{
|
||||
$category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail();
|
||||
public function findAllCategoryAttributesForCategoryId(SelectQuery $query, string $internalCategoryId) {
|
||||
$category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail();
|
||||
|
||||
$this->ProductCategories->behaviors()->get('Tree')->setConfig([
|
||||
'scope' => [
|
||||
'product_catalog_id' => $category->product_catalog_id ?? 1,
|
||||
],
|
||||
]);
|
||||
$this->ProductCategories->behaviors()->get('Tree')->setConfig([
|
||||
'scope' => [
|
||||
'product_catalog_id' => $category->product_catalog_id ?? 1,
|
||||
],
|
||||
]);
|
||||
|
||||
return $this->ProductCategories
|
||||
->find('path', for: $category->id)
|
||||
->contain(['ProductCategoryAttributes', 'ProductCategoryAttributes.ProductCategoryAttributeOptions']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $internalCategoryId
|
||||
* @return \Cake\Datasource\EntityInterface[]|array[]
|
||||
*/
|
||||
public function getAllCategoryAttributesForCategoryId(string $internalCategoryId) {
|
||||
return $this->find('allCategoryAttributesForCategoryId', internalCategoryId: $internalCategoryId)->toArray();
|
||||
}
|
||||
|
||||
return $this->ProductCategories
|
||||
->find('path', for: $category->id)
|
||||
->contain(['ProductCategoryAttributes', 'ProductCategoryAttributes.ProductCategoryAttributeOptions']);
|
||||
}
|
||||
public function getAllCategoryAttributesForCategoryId(string $internalCategoryId)
|
||||
{
|
||||
return $this->find('allCategoryAttributesForCategoryId', $internalCategoryId)->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,109 +4,99 @@ declare(strict_types=1);
|
||||
namespace CakeProducts\Model\Table;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use CakeProducts\Model\Entity\ProductCategoryVariantOption;
|
||||
use CakeProducts\Model\Table\ProductCategoryVariantsTable;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Datasource\ResultSetInterface;
|
||||
use Cake\ORM\Association\BelongsTo;
|
||||
use Cake\ORM\Behavior\TimestampBehavior;
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use Closure;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
/**
|
||||
* ProductCategoryVariantOptions Model
|
||||
*
|
||||
* @property ProductCategoryVariantsTable&BelongsTo $ProductCategoryVariants
|
||||
* @property ProductCategoryVariantsTable&\Cake\ORM\Association\BelongsTo $ProductCategoryVariants
|
||||
*
|
||||
* @method ProductCategoryVariantOption newEmptyEntity()
|
||||
* @method ProductCategoryVariantOption newEntity(array $data, array $options = [])
|
||||
* @method array<ProductCategoryVariantOption> newEntities(array $data, array $options = [])
|
||||
* @method ProductCategoryVariantOption get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
|
||||
* @method ProductCategoryVariantOption findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method ProductCategoryVariantOption patchEntity(EntityInterface $entity, array $data, array $options = [])
|
||||
* @method array<ProductCategoryVariantOption> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method ProductCategoryVariantOption|false save(EntityInterface $entity, array $options = [])
|
||||
* @method ProductCategoryVariantOption saveOrFail(EntityInterface $entity, array $options = [])
|
||||
* @method iterable<ProductCategoryVariantOption>|ResultSetInterface<ProductCategoryVariantOption>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategoryVariantOption>|ResultSetInterface<ProductCategoryVariantOption> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategoryVariantOption>|ResultSetInterface<ProductCategoryVariantOption>|false deleteMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategoryVariantOption>|ResultSetInterface<ProductCategoryVariantOption> deleteManyOrFail(iterable $entities, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryVariantOption newEmptyEntity()
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryVariantOption newEntity(array $data, array $options = [])
|
||||
* @method array<\CakeProducts\Model\Entity\ProductCategoryVariantOption> newEntities(array $data, array $options = [])
|
||||
* @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 \CakeProducts\Model\Entity\ProductCategoryVariantOption findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryVariantOption patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
|
||||
* @method array<\CakeProducts\Model\Entity\ProductCategoryVariantOption> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryVariantOption|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryVariantOption saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
||||
* @method iterable<\CakeProducts\Model\Entity\ProductCategoryVariantOption>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategoryVariantOption>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<\CakeProducts\Model\Entity\ProductCategoryVariantOption>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategoryVariantOption> saveManyOrFail(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<\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
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('product_category_variant_options');
|
||||
$this->setDisplayField('variant_value');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setTable('product_category_variant_options');
|
||||
$this->setDisplayField('variant_value');
|
||||
$this->setPrimaryKey('id');
|
||||
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductCategoryVariantOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryVariantOption')
|
||||
);
|
||||
$this->addBehavior('Timestamp');
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductCategoryVariantOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryVariantOption'),
|
||||
);
|
||||
$this->addBehavior('Timestamp');
|
||||
|
||||
$this->belongsTo('ProductCategoryVariants', [
|
||||
'foreignKey' => 'product_category_variant_id',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
}
|
||||
$this->belongsTo('ProductCategoryVariants', [
|
||||
'className' => 'CakeProducts.ProductCategoryVariants',
|
||||
'foreignKey' => 'product_category_variant_id',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param Validator $validator Validator instance.
|
||||
* @return Validator
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->uuid('product_category_variant_id')
|
||||
->notEmptyString('product_category_variant_id');
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->uuid('product_category_variant_id')
|
||||
->notEmptyString('product_category_variant_id');
|
||||
|
||||
$validator
|
||||
->scalar('variant_value')
|
||||
->maxLength('variant_value', 255)
|
||||
->requirePresence('variant_value', 'create')
|
||||
->notEmptyString('variant_value');
|
||||
$validator
|
||||
->scalar('variant_value')
|
||||
->maxLength('variant_value', 255)
|
||||
->requirePresence('variant_value', 'create')
|
||||
->notEmptyString('variant_value');
|
||||
|
||||
$validator
|
||||
->scalar('variant_label')
|
||||
->maxLength('variant_label', 255)
|
||||
->allowEmptyString('variant_label');
|
||||
$validator
|
||||
->scalar('variant_label')
|
||||
->maxLength('variant_label', 255)
|
||||
->allowEmptyString('variant_label');
|
||||
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
|
||||
return $validator;
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param RulesChecker $rules The rules object to be modified.
|
||||
* @return RulesChecker
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
$rules->add($rules->existsIn(['product_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']);
|
||||
$rules->add($rules->isUnique(['variant_value', 'product_category_variant_id']));
|
||||
public function buildRules(RulesChecker $rules): RulesChecker {
|
||||
$rules->add($rules->existsIn(['product_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']);
|
||||
$rules->add($rules->isUnique(['variant_value', 'product_category_variant_id']));
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,161 +4,152 @@ declare(strict_types=1);
|
||||
namespace CakeProducts\Model\Table;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Datasource\ResultSetInterface;
|
||||
use Cake\ORM\Association\BelongsTo;
|
||||
use Cake\ORM\Query;
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use CakeProducts\Model\Entity\ProductCategoryVariant;
|
||||
use Closure;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
/**
|
||||
* ProductCategoryVariants Model
|
||||
*
|
||||
* @property ProductCategoriesTable&BelongsTo $ProductCategories
|
||||
* @property ProductsTable&BelongsTo $Products
|
||||
* @property ProductCategoriesTable&\Cake\ORM\Association\BelongsTo $ProductCategories
|
||||
* @property ProductsTable&\Cake\ORM\Association\BelongsTo $Products
|
||||
*
|
||||
* @method ProductCategoryVariant newEmptyEntity()
|
||||
* @method ProductCategoryVariant newEntity(array $data, array $options = [])
|
||||
* @method array<ProductCategoryVariant> newEntities(array $data, array $options = [])
|
||||
* @method ProductCategoryVariant get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
|
||||
* @method ProductCategoryVariant findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method ProductCategoryVariant patchEntity(EntityInterface $entity, array $data, array $options = [])
|
||||
* @method array<ProductCategoryVariant> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method ProductCategoryVariant|false save(EntityInterface $entity, array $options = [])
|
||||
* @method ProductCategoryVariant saveOrFail(EntityInterface $entity, array $options = [])
|
||||
* @method iterable<ProductCategoryVariant>|ResultSetInterface<ProductCategoryVariant>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategoryVariant>|ResultSetInterface<ProductCategoryVariant> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategoryVariant>|ResultSetInterface<ProductCategoryVariant>|false deleteMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategoryVariant>|ResultSetInterface<ProductCategoryVariant> deleteManyOrFail(iterable $entities, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryVariant newEmptyEntity()
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryVariant newEntity(array $data, array $options = [])
|
||||
* @method array<\CakeProducts\Model\Entity\ProductCategoryVariant> newEntities(array $data, array $options = [])
|
||||
* @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 \CakeProducts\Model\Entity\ProductCategoryVariant findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryVariant patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
|
||||
* @method array<\CakeProducts\Model\Entity\ProductCategoryVariant> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryVariant|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductCategoryVariant saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
||||
* @method iterable<\CakeProducts\Model\Entity\ProductCategoryVariant>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategoryVariant>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<\CakeProducts\Model\Entity\ProductCategoryVariant>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductCategoryVariant> saveManyOrFail(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<\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
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('product_category_variants');
|
||||
$this->setDisplayField('name');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setTable('product_category_variants');
|
||||
$this->setDisplayField('name');
|
||||
$this->setPrimaryKey('id');
|
||||
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductCategoryVariants.entity', 'CakeProducts\Model\Entity\ProductCategoryVariant')
|
||||
);
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductCategoryVariants.entity', 'CakeProducts\Model\Entity\ProductCategoryVariant'),
|
||||
);
|
||||
|
||||
$this->belongsTo('ProductCategories', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
]);
|
||||
$this->belongsTo('Products', [
|
||||
'foreignKey' => 'product_id',
|
||||
'className' => 'CakeProducts.Products',
|
||||
]);
|
||||
$this->hasMany('ProductCategoryVariantOptions', [
|
||||
'foreignKey' => 'product_category_variant_id',
|
||||
'className' => 'CakeProducts.ProductCategoryVariantOptions',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
'saveStrategy' => 'replace',
|
||||
]);
|
||||
$this->belongsTo('ProductCategories', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
]);
|
||||
$this->belongsTo('Products', [
|
||||
'foreignKey' => 'product_id',
|
||||
'className' => 'CakeProducts.Products',
|
||||
]);
|
||||
$this->hasMany('ProductCategoryVariantOptions', [
|
||||
'foreignKey' => 'product_category_variant_id',
|
||||
'className' => 'CakeProducts.ProductCategoryVariantOptions',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
'saveStrategy' => 'replace',
|
||||
]);
|
||||
|
||||
$this->hasMany('ProductVariants', [
|
||||
'foreignKey' => 'product_category_variant_id',
|
||||
'className' => 'CakeProducts.ProductVariants',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
}
|
||||
$this->hasMany('ProductVariants', [
|
||||
'foreignKey' => 'product_category_variant_id',
|
||||
'className' => 'CakeProducts.ProductVariants',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param Validator $validator Validator instance.
|
||||
* @return Validator
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->scalar('name')
|
||||
->maxLength('name', 255)
|
||||
->requirePresence('name', 'create')
|
||||
->notEmptyString('name');
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->scalar('name')
|
||||
->maxLength('name', 255)
|
||||
->requirePresence('name', 'create')
|
||||
->notEmptyString('name');
|
||||
|
||||
$validator
|
||||
->uuid('product_category_id')
|
||||
->allowEmptyString('product_category_id');
|
||||
$validator
|
||||
->uuid('product_category_id')
|
||||
->allowEmptyString('product_category_id');
|
||||
|
||||
$validator
|
||||
->uuid('product_id')
|
||||
->allowEmptyString('product_id');
|
||||
$validator
|
||||
->uuid('product_id')
|
||||
->allowEmptyString('product_id');
|
||||
|
||||
$validator
|
||||
->boolean('is_system_variant')
|
||||
->allowEmptyString('is_system_variant');
|
||||
$validator
|
||||
->boolean('is_system_variant')
|
||||
->allowEmptyString('is_system_variant');
|
||||
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
->requirePresence('enabled', 'create')
|
||||
->notEmptyString('enabled');
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
->requirePresence('enabled', 'create')
|
||||
->notEmptyString('enabled');
|
||||
|
||||
return $validator;
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param RulesChecker $rules The rules object to be modified.
|
||||
* @return RulesChecker
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
$rules->add($rules->isUnique(['name', 'product_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_category_id']);
|
||||
$rules->add($rules->isUnique(['name', 'product_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_id']);
|
||||
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
|
||||
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
|
||||
public function buildRules(RulesChecker $rules): RulesChecker {
|
||||
$rules->add($rules->isUnique(['name', 'product_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_category_id']);
|
||||
$rules->add($rules->isUnique(['name', 'product_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_id']);
|
||||
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
|
||||
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SelectQuery $query
|
||||
/**
|
||||
* @param \Cake\ORM\Query\SelectQuery $query
|
||||
* @param string $internalCategoryId
|
||||
*
|
||||
* @return array|Query|SelectQuery
|
||||
* @return \Cake\ORM\Query\SelectQuery
|
||||
*/
|
||||
public function findAllCategoryVariantsForCategoryId(SelectQuery $query, string $internalCategoryId)
|
||||
{
|
||||
$category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail();
|
||||
public function findAllCategoryVariantsForCategoryId(SelectQuery $query, string $internalCategoryId): SelectQuery {
|
||||
$category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail();
|
||||
|
||||
$this->ProductCategories->behaviors()->get('Tree')->setConfig([
|
||||
'scope' => [
|
||||
'product_catalog_id' => $category->product_catalog_id ?? 1,
|
||||
],
|
||||
]);
|
||||
$this->ProductCategories->behaviors()->get('Tree')->setConfig([
|
||||
'scope' => [
|
||||
'product_catalog_id' => $category->product_catalog_id ?? 1,
|
||||
],
|
||||
]);
|
||||
|
||||
return $this->ProductCategories
|
||||
->find('path', for: $category->id)
|
||||
->contain(['ProductCategoryVariants']);
|
||||
}
|
||||
return $this->ProductCategories
|
||||
->find('path', for: $category->id)
|
||||
->contain(['ProductCategoryVariants']);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @param string $internalCategoryId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAllCategoryVariantsForCategoryId(string $internalCategoryId)
|
||||
{
|
||||
return $this->find('allCategoryVariantsForCategoryId', $internalCategoryId)->toArray();
|
||||
}
|
||||
public function getAllCategoryVariantsForCategoryId(string $internalCategoryId): array {
|
||||
return $this->find('allCategoryVariantsForCategoryId', internalCategoryId: $internalCategoryId)->toArray();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,169 +4,160 @@ declare(strict_types=1);
|
||||
namespace CakeProducts\Model\Table;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Datasource\ResultSetInterface;
|
||||
use Cake\ORM\Association\BelongsTo;
|
||||
use Cake\ORM\Behavior\TimestampBehavior;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use CakeProducts\Model\Entity\ProductPhoto;
|
||||
use Closure;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
/**
|
||||
* ProductPhotos Model
|
||||
*
|
||||
* @property ProductsTable&BelongsTo $Products
|
||||
* @property ProductSkusTable&BelongsTo $ProductSkus
|
||||
* @property ProductsTable&\Cake\ORM\Association\BelongsTo $Products
|
||||
* @property ProductSkusTable&\Cake\ORM\Association\BelongsTo $ProductSkus
|
||||
*
|
||||
* @method ProductPhoto newEmptyEntity()
|
||||
* @method ProductPhoto newEntity(array $data, array $options = [])
|
||||
* @method array<ProductPhoto> newEntities(array $data, array $options = [])
|
||||
* @method ProductPhoto get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
|
||||
* @method ProductPhoto findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method ProductPhoto patchEntity(EntityInterface $entity, array $data, array $options = [])
|
||||
* @method array<ProductPhoto> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method ProductPhoto|false save(EntityInterface $entity, array $options = [])
|
||||
* @method ProductPhoto saveOrFail(EntityInterface $entity, array $options = [])
|
||||
* @method iterable<ProductPhoto>|ResultSetInterface<ProductPhoto>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductPhoto>|ResultSetInterface<ProductPhoto> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductPhoto>|ResultSetInterface<ProductPhoto>|false deleteMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductPhoto>|ResultSetInterface<ProductPhoto> deleteManyOrFail(iterable $entities, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductPhoto newEmptyEntity()
|
||||
* @method \CakeProducts\Model\Entity\ProductPhoto newEntity(array $data, array $options = [])
|
||||
* @method array<\CakeProducts\Model\Entity\ProductPhoto> newEntities(array $data, array $options = [])
|
||||
* @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 \CakeProducts\Model\Entity\ProductPhoto findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductPhoto patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
|
||||
* @method array<\CakeProducts\Model\Entity\ProductPhoto> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductPhoto|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductPhoto saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
||||
* @method iterable<\CakeProducts\Model\Entity\ProductPhoto>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductPhoto>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<\CakeProducts\Model\Entity\ProductPhoto>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductPhoto> saveManyOrFail(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<\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
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('product_photos');
|
||||
$this->setDisplayField('photo_filename');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setTable('product_photos');
|
||||
$this->setDisplayField('photo_filename');
|
||||
$this->setPrimaryKey('id');
|
||||
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductPhotos.entity', 'CakeProducts\Model\Entity\ProductPhoto')
|
||||
);
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductPhotos.entity', 'CakeProducts\Model\Entity\ProductPhoto'),
|
||||
);
|
||||
|
||||
$this->addBehavior('Timestamp');
|
||||
$this->addBehavior('Timestamp');
|
||||
|
||||
$this->addBehavior('Tools.Toggle', [
|
||||
'field' => 'primary_category_photo',
|
||||
'scopeFields' => ['product_category_id'],
|
||||
'scope' => [
|
||||
'deleted IS' => null,
|
||||
],
|
||||
]);
|
||||
$this->addBehavior('CakeProducts.SecondToggle', [
|
||||
'field' => 'primary_photo',
|
||||
'scopeFields' => ['product_id'],
|
||||
'scope' => [
|
||||
'deleted IS' => null,
|
||||
'product_id IS NOT' => null,
|
||||
],
|
||||
]);
|
||||
$this->addBehavior('CakeProducts.ThirdToggle', [
|
||||
'field' => 'primary_sku_photo',
|
||||
'scopeFields' => ['product_sku_id'],
|
||||
'scope' => [
|
||||
'deleted IS' => null,
|
||||
'product_sku_id IS NOT' => null,
|
||||
],
|
||||
]);
|
||||
$this->belongsTo('Products', [
|
||||
'foreignKey' => 'product_id',
|
||||
'joinType' => 'LEFT',
|
||||
'className' => 'CakeProducts.Products',
|
||||
]);
|
||||
$this->addBehavior('Tools.Toggle', [
|
||||
'field' => 'primary_category_photo',
|
||||
'scopeFields' => ['product_category_id'],
|
||||
'scope' => [
|
||||
'deleted IS' => null,
|
||||
],
|
||||
]);
|
||||
$this->addBehavior('CakeProducts.SecondToggle', [
|
||||
'field' => 'primary_photo',
|
||||
'scopeFields' => ['product_id'],
|
||||
'scope' => [
|
||||
'deleted IS' => null,
|
||||
'product_id IS NOT' => null,
|
||||
],
|
||||
]);
|
||||
$this->addBehavior('CakeProducts.ThirdToggle', [
|
||||
'field' => 'primary_sku_photo',
|
||||
'scopeFields' => ['product_sku_id'],
|
||||
'scope' => [
|
||||
'deleted IS' => null,
|
||||
'product_sku_id IS NOT' => null,
|
||||
],
|
||||
]);
|
||||
$this->belongsTo('Products', [
|
||||
'foreignKey' => 'product_id',
|
||||
'joinType' => 'LEFT',
|
||||
'className' => 'CakeProducts.Products',
|
||||
]);
|
||||
|
||||
$this->belongsTo('ProductCategories', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'joinType' => 'INNER',
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
]);
|
||||
$this->belongsTo('ProductCategories', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'joinType' => 'INNER',
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
]);
|
||||
|
||||
$this->belongsTo('ProductSkus', [
|
||||
'foreignKey' => 'product_sku_id',
|
||||
'joinType' => 'LEFT',
|
||||
'className' => 'CakeProducts.ProductSkus',
|
||||
]);
|
||||
}
|
||||
$this->belongsTo('ProductSkus', [
|
||||
'foreignKey' => 'product_sku_id',
|
||||
'joinType' => 'LEFT',
|
||||
'className' => 'CakeProducts.ProductSkus',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param Validator $validator Validator instance.
|
||||
* @return Validator
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->uuid('product_id')
|
||||
->allowEmptyString('product_id');
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->uuid('product_id')
|
||||
->allowEmptyString('product_id');
|
||||
|
||||
$validator
|
||||
->uuid('product_sku_id')
|
||||
->allowEmptyString('product_sku_id');
|
||||
$validator
|
||||
->uuid('product_sku_id')
|
||||
->allowEmptyString('product_sku_id');
|
||||
|
||||
$validator
|
||||
->uuid('product_category_id')
|
||||
->requirePresence('product_category_id', 'create')
|
||||
->notEmptyString('product_category_id');
|
||||
$validator
|
||||
->uuid('product_category_id')
|
||||
->requirePresence('product_category_id', 'create')
|
||||
->notEmptyString('product_category_id');
|
||||
|
||||
$validator
|
||||
->scalar('photo_dir')
|
||||
->maxLength('photo_dir', 255)
|
||||
->requirePresence('photo_dir', 'create')
|
||||
->notEmptyString('photo_dir');
|
||||
$validator
|
||||
->scalar('photo_dir')
|
||||
->maxLength('photo_dir', 255)
|
||||
->requirePresence('photo_dir', 'create')
|
||||
->notEmptyString('photo_dir');
|
||||
|
||||
$validator
|
||||
->scalar('photo_filename')
|
||||
->maxLength('photo_filename', 255)
|
||||
->requirePresence('photo_filename', 'create')
|
||||
->notEmptyString('photo_filename');
|
||||
$validator
|
||||
->scalar('photo_filename')
|
||||
->maxLength('photo_filename', 255)
|
||||
->requirePresence('photo_filename', 'create')
|
||||
->notEmptyString('photo_filename');
|
||||
|
||||
$validator
|
||||
->boolean('primary_photo')
|
||||
->notEmptyString('primary_photo');
|
||||
$validator
|
||||
->boolean('primary_photo')
|
||||
->notEmptyString('primary_photo');
|
||||
|
||||
$validator
|
||||
->integer('photo_position')
|
||||
->notEmptyString('photo_position');
|
||||
$validator
|
||||
->integer('photo_position')
|
||||
->notEmptyString('photo_position');
|
||||
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
->notEmptyString('enabled');
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
->notEmptyString('enabled');
|
||||
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
|
||||
return $validator;
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param RulesChecker $rules The rules object to be modified.
|
||||
* @return RulesChecker
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
|
||||
$rules->add($rules->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']);
|
||||
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
|
||||
public function buildRules(RulesChecker $rules): RulesChecker {
|
||||
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
|
||||
$rules->add($rules->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']);
|
||||
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,110 +3,101 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Table;
|
||||
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Datasource\ResultSetInterface;
|
||||
use Cake\ORM\Association\BelongsTo;
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use CakeProducts\Model\Entity\ProductSkuVariantValue;
|
||||
use Closure;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
/**
|
||||
* ProductSkuVariantValues Model
|
||||
*
|
||||
* @property ProductSkusTable&BelongsTo $ProductSkus
|
||||
* @property ProductCategoryVariantsTable&BelongsTo $ProductCategoryVariants
|
||||
* @property ProductCategoryVariantOptionsTable&BelongsTo $ProductCategoryVariantOptions
|
||||
* @property ProductSkusTable&\Cake\ORM\Association\BelongsTo $ProductSkus
|
||||
* @property ProductCategoryVariantsTable&\Cake\ORM\Association\BelongsTo $ProductCategoryVariants
|
||||
* @property ProductCategoryVariantOptionsTable&\Cake\ORM\Association\BelongsTo $ProductCategoryVariantOptions
|
||||
*
|
||||
* @method ProductSkuVariantValue newEmptyEntity()
|
||||
* @method ProductSkuVariantValue newEntity(array $data, array $options = [])
|
||||
* @method array<ProductSkuVariantValue> newEntities(array $data, array $options = [])
|
||||
* @method ProductSkuVariantValue get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
|
||||
* @method ProductSkuVariantValue findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method ProductSkuVariantValue patchEntity(EntityInterface $entity, array $data, array $options = [])
|
||||
* @method array<ProductSkuVariantValue> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method ProductSkuVariantValue|false save(EntityInterface $entity, array $options = [])
|
||||
* @method ProductSkuVariantValue saveOrFail(EntityInterface $entity, array $options = [])
|
||||
* @method iterable<ProductSkuVariantValue>|ResultSetInterface<ProductSkuVariantValue>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductSkuVariantValue>|ResultSetInterface<ProductSkuVariantValue> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductSkuVariantValue>|ResultSetInterface<ProductSkuVariantValue>|false deleteMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductSkuVariantValue>|ResultSetInterface<ProductSkuVariantValue> deleteManyOrFail(iterable $entities, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductSkuVariantValue newEmptyEntity()
|
||||
* @method \CakeProducts\Model\Entity\ProductSkuVariantValue newEntity(array $data, array $options = [])
|
||||
* @method array<\CakeProducts\Model\Entity\ProductSkuVariantValue> newEntities(array $data, array $options = [])
|
||||
* @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 \CakeProducts\Model\Entity\ProductSkuVariantValue findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductSkuVariantValue patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
|
||||
* @method array<\CakeProducts\Model\Entity\ProductSkuVariantValue> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductSkuVariantValue|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductSkuVariantValue saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
||||
* @method iterable<\CakeProducts\Model\Entity\ProductSkuVariantValue>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductSkuVariantValue>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<\CakeProducts\Model\Entity\ProductSkuVariantValue>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductSkuVariantValue> saveManyOrFail(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<\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
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('product_sku_variant_values');
|
||||
$this->setDisplayField('id');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setTable('product_sku_variant_values');
|
||||
$this->setDisplayField('id');
|
||||
$this->setPrimaryKey('id');
|
||||
|
||||
$this->belongsTo('ProductSkus', [
|
||||
'className' => 'CakeProducts.ProductSkus',
|
||||
'foreignKey' => 'product_sku_id',
|
||||
'propertyName' => 'product_sku',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
$this->belongsTo('ProductVariants', [
|
||||
'className' => 'CakeProducts.ProductVariants',
|
||||
'foreignKey' => 'product_variant_id',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
$this->belongsTo('ProductCategoryVariantOptions', [
|
||||
'className' => 'CakeProducts.ProductCategoryVariantOptions',
|
||||
'foreignKey' => 'product_category_variant_option_id',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
}
|
||||
$this->belongsTo('ProductSkus', [
|
||||
'className' => 'CakeProducts.ProductSkus',
|
||||
'foreignKey' => 'product_sku_id',
|
||||
'propertyName' => 'product_sku',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
$this->belongsTo('ProductVariants', [
|
||||
'className' => 'CakeProducts.ProductVariants',
|
||||
'foreignKey' => 'product_variant_id',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
$this->belongsTo('ProductCategoryVariantOptions', [
|
||||
'className' => 'CakeProducts.ProductCategoryVariantOptions',
|
||||
'foreignKey' => 'product_category_variant_option_id',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param Validator $validator Validator instance.
|
||||
* @return Validator
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->uuid('product_sku_id')
|
||||
->notEmptyString('product_sku_id');
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->uuid('product_sku_id')
|
||||
->notEmptyString('product_sku_id');
|
||||
|
||||
$validator
|
||||
->uuid('product_variant_id')
|
||||
->notEmptyString('product_variant_id');
|
||||
$validator
|
||||
->uuid('product_variant_id')
|
||||
->notEmptyString('product_variant_id');
|
||||
|
||||
$validator
|
||||
->uuid('product_category_variant_option_id')
|
||||
->notEmptyString('product_category_variant_option_id');
|
||||
$validator
|
||||
->uuid('product_category_variant_option_id')
|
||||
->notEmptyString('product_category_variant_option_id');
|
||||
|
||||
return $validator;
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param RulesChecker $rules The rules object to be modified.
|
||||
* @return RulesChecker
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
$rules->add($rules->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']);
|
||||
public function buildRules(RulesChecker $rules): RulesChecker {
|
||||
$rules->add($rules->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']);
|
||||
|
||||
// @TODO why not working?? causing tests to fail / associated variant values not saving on product-skus/add
|
||||
$rules->add($rules->existsIn(['product_variant_id'], 'ProductVariants'), ['errorField' => 'product_variant_id']);
|
||||
$rules->add($rules->existsIn(['product_category_variant_option_id'], 'ProductCategoryVariantOptions'), ['errorField' => 'product_category_variant_option_id']);
|
||||
// @TODO why not working?? causing tests to fail / associated variant values not saving on product-skus/add
|
||||
$rules->add($rules->existsIn(['product_variant_id'], 'ProductVariants'), ['errorField' => 'product_variant_id']);
|
||||
$rules->add($rules->existsIn(['product_category_variant_option_id'], 'ProductCategoryVariantOptions'), ['errorField' => 'product_category_variant_option_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,148 +4,137 @@ declare(strict_types=1);
|
||||
namespace CakeProducts\Model\Table;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use CakeProducts\Model\Table\ProductsTable;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Datasource\ResultSetInterface;
|
||||
use Cake\ORM\Association\BelongsTo;
|
||||
use Cake\ORM\Behavior\TimestampBehavior;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use CakeProducts\Model\Entity\ProductSku;
|
||||
use Closure;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
/**
|
||||
* ProductSkus Model
|
||||
*
|
||||
* @property ProductsTable&BelongsTo $Products
|
||||
* @property ProductsTable&\Cake\ORM\Association\BelongsTo $Products
|
||||
*
|
||||
* @method ProductSku newEmptyEntity()
|
||||
* @method ProductSku newEntity(array $data, array $options = [])
|
||||
* @method array<ProductSku> newEntities(array $data, array $options = [])
|
||||
* @method ProductSku get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
|
||||
* @method ProductSku findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method ProductSku patchEntity(EntityInterface $entity, array $data, array $options = [])
|
||||
* @method array<ProductSku> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method ProductSku|false save(EntityInterface $entity, array $options = [])
|
||||
* @method ProductSku saveOrFail(EntityInterface $entity, array $options = [])
|
||||
* @method iterable<ProductSku>|ResultSetInterface<ProductSku>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductSku>|ResultSetInterface<ProductSku> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductSku>|ResultSetInterface<ProductSku>|false deleteMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductSku>|ResultSetInterface<ProductSku> deleteManyOrFail(iterable $entities, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductSku newEmptyEntity()
|
||||
* @method \CakeProducts\Model\Entity\ProductSku newEntity(array $data, array $options = [])
|
||||
* @method array<\CakeProducts\Model\Entity\ProductSku> newEntities(array $data, array $options = [])
|
||||
* @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 \CakeProducts\Model\Entity\ProductSku findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductSku patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
|
||||
* @method array<\CakeProducts\Model\Entity\ProductSku> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductSku|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductSku saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
||||
* @method iterable<\CakeProducts\Model\Entity\ProductSku>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductSku>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<\CakeProducts\Model\Entity\ProductSku>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductSku> saveManyOrFail(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<\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
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('product_skus');
|
||||
$this->setDisplayField('sku');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setTable('product_skus');
|
||||
$this->setDisplayField('sku');
|
||||
$this->setPrimaryKey('id');
|
||||
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductSkus.entity', 'CakeProducts\Model\Entity\ProductSku')
|
||||
);
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.ProductSkus.entity', 'CakeProducts\Model\Entity\ProductSku'),
|
||||
);
|
||||
|
||||
$this->addBehavior('Timestamp');
|
||||
$this->addBehavior('Tools.Toggle', [
|
||||
'field' => 'default_sku',
|
||||
'scopeFields' => ['product_id'],
|
||||
'scope' => [
|
||||
'deleted IS' => null,
|
||||
],
|
||||
]);
|
||||
$this->addBehavior('Timestamp');
|
||||
$this->addBehavior('Tools.Toggle', [
|
||||
'field' => 'default_sku',
|
||||
'scopeFields' => ['product_id'],
|
||||
'scope' => [
|
||||
'deleted IS' => null,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->belongsTo('Products', [
|
||||
'className' => 'CakeProducts.Products',
|
||||
'foreignKey' => 'product_id',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
$this->belongsTo('Products', [
|
||||
'className' => 'CakeProducts.Products',
|
||||
'foreignKey' => 'product_id',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
|
||||
$this->hasMany('ProductSkuVariantValues', [
|
||||
'foreignKey' => 'product_sku_id',
|
||||
'className' => 'CakeProducts.ProductSkuVariantValues',
|
||||
'saveStrategy' => 'replace',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ProductSkuVariantValues', [
|
||||
'foreignKey' => 'product_sku_id',
|
||||
'className' => 'CakeProducts.ProductSkuVariantValues',
|
||||
'saveStrategy' => 'replace',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
|
||||
$this->hasMany('ProductPhotos', [
|
||||
'foreignKey' => 'product_sku_id',
|
||||
'className' => 'CakeProducts.ProductPhotos',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ProductPhotos', [
|
||||
'foreignKey' => 'product_sku_id',
|
||||
'className' => 'CakeProducts.ProductPhotos',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
|
||||
$this->hasOne('PrimaryProductPhotos', [
|
||||
'foreignKey' => 'product_sku_id',
|
||||
'conditions' => ['PrimaryProductPhotos.primary_photo' => true],
|
||||
'className' => 'CakeProducts.ProductPhotos',
|
||||
'dependent' => true,
|
||||
]);
|
||||
}
|
||||
$this->hasOne('PrimaryProductPhotos', [
|
||||
'foreignKey' => 'product_sku_id',
|
||||
'conditions' => ['PrimaryProductPhotos.primary_photo' => true],
|
||||
'className' => 'CakeProducts.ProductPhotos',
|
||||
'dependent' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param Validator $validator Validator instance.
|
||||
* @return Validator
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->uuid('product_id')
|
||||
->notEmptyString('product_id');
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->uuid('product_id')
|
||||
->notEmptyString('product_id');
|
||||
|
||||
$validator
|
||||
->scalar('sku')
|
||||
->maxLength('sku', 255)
|
||||
->requirePresence('sku', 'create')
|
||||
->notEmptyString('sku');
|
||||
$validator
|
||||
->scalar('sku')
|
||||
->maxLength('sku', 255)
|
||||
->requirePresence('sku', 'create')
|
||||
->notEmptyString('sku');
|
||||
|
||||
$validator
|
||||
->scalar('barcode')
|
||||
->maxLength('barcode', 255)
|
||||
->allowEmptyString('barcode');
|
||||
$validator
|
||||
->scalar('barcode')
|
||||
->maxLength('barcode', 255)
|
||||
->allowEmptyString('barcode');
|
||||
|
||||
$validator
|
||||
->decimal('price')
|
||||
->allowEmptyString('price');
|
||||
$validator
|
||||
->decimal('price')
|
||||
->allowEmptyString('price');
|
||||
|
||||
$validator
|
||||
->decimal('cost')
|
||||
->allowEmptyString('cost');
|
||||
$validator
|
||||
->decimal('cost')
|
||||
->allowEmptyString('cost');
|
||||
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
|
||||
return $validator;
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param RulesChecker $rules The rules object to be modified.
|
||||
* @return RulesChecker
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
|
||||
$rules->add($rules->isUnique(['sku'], 'SKU must be unique'), ['errorField' => 'sku']);
|
||||
public function buildRules(RulesChecker $rules): RulesChecker {
|
||||
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
|
||||
$rules->add($rules->isUnique(['sku'], 'SKU must be unique'), ['errorField' => 'sku']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,115 +3,104 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Table;
|
||||
|
||||
use CakeProducts\Model\Entity\ProductVariant;
|
||||
use CakeProducts\Model\Table\ProductCategoryVariantsTable;
|
||||
use CakeProducts\Model\Table\ProductsTable;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Datasource\ResultSetInterface;
|
||||
use Cake\ORM\Association\BelongsTo;
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use Closure;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
/**
|
||||
* ProductVariants Model
|
||||
*
|
||||
* @property ProductCategoryVariantsTable&BelongsTo $ProductCategoryVariants
|
||||
* @property ProductsTable&BelongsTo $Products
|
||||
* @property ProductCategoryVariantsTable&\Cake\ORM\Association\BelongsTo $ProductCategoryVariants
|
||||
* @property ProductsTable&\Cake\ORM\Association\BelongsTo $Products
|
||||
*
|
||||
* @method ProductVariant newEmptyEntity()
|
||||
* @method ProductVariant newEntity(array $data, array $options = [])
|
||||
* @method array<ProductVariant> newEntities(array $data, array $options = [])
|
||||
* @method ProductVariant get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
|
||||
* @method ProductVariant findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method ProductVariant patchEntity(EntityInterface $entity, array $data, array $options = [])
|
||||
* @method array<ProductVariant> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method ProductVariant|false save(EntityInterface $entity, array $options = [])
|
||||
* @method ProductVariant saveOrFail(EntityInterface $entity, array $options = [])
|
||||
* @method iterable<ProductVariant>|ResultSetInterface<ProductVariant>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductVariant>|ResultSetInterface<ProductVariant> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductVariant>|ResultSetInterface<ProductVariant>|false deleteMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductVariant>|ResultSetInterface<ProductVariant> deleteManyOrFail(iterable $entities, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductVariant newEmptyEntity()
|
||||
* @method \CakeProducts\Model\Entity\ProductVariant newEntity(array $data, array $options = [])
|
||||
* @method array<\CakeProducts\Model\Entity\ProductVariant> newEntities(array $data, array $options = [])
|
||||
* @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 \CakeProducts\Model\Entity\ProductVariant findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductVariant patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
|
||||
* @method array<\CakeProducts\Model\Entity\ProductVariant> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductVariant|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\ProductVariant saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
||||
* @method iterable<\CakeProducts\Model\Entity\ProductVariant>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductVariant>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<\CakeProducts\Model\Entity\ProductVariant>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductVariant> saveManyOrFail(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<\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
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('product_variants');
|
||||
$this->setDisplayField('name');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setTable('product_variants');
|
||||
$this->setDisplayField('name');
|
||||
$this->setPrimaryKey('id');
|
||||
|
||||
$this->belongsTo('ProductCategoryVariants', [
|
||||
'className' => 'CakeProducts.ProductCategoryVariants',
|
||||
'foreignKey' => 'product_category_variant_id',
|
||||
]);
|
||||
$this->belongsTo('Products', [
|
||||
'className' => 'CakeProducts.Products',
|
||||
'foreignKey' => 'product_id',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
$this->belongsTo('ProductCategoryVariants', [
|
||||
'className' => 'CakeProducts.ProductCategoryVariants',
|
||||
'foreignKey' => 'product_category_variant_id',
|
||||
]);
|
||||
$this->belongsTo('Products', [
|
||||
'className' => 'CakeProducts.Products',
|
||||
'foreignKey' => 'product_id',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
|
||||
$this->hasMany('ProductSkuVariantValues', [
|
||||
'className' => 'CakeProducts.ProductSkuVariantValues',
|
||||
'foreignKey' => 'product_variant_id',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
}
|
||||
$this->hasMany('ProductSkuVariantValues', [
|
||||
'className' => 'CakeProducts.ProductSkuVariantValues',
|
||||
'foreignKey' => 'product_variant_id',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param Validator $validator Validator instance.
|
||||
* @return Validator
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->scalar('name')
|
||||
->maxLength('name', 255)
|
||||
->requirePresence('name', 'create')
|
||||
->notEmptyString('name');
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->scalar('name')
|
||||
->maxLength('name', 255)
|
||||
->requirePresence('name', 'create')
|
||||
->notEmptyString('name');
|
||||
|
||||
$validator
|
||||
->uuid('product_category_variant_id')
|
||||
->allowEmptyString('product_category_variant_id');
|
||||
$validator
|
||||
->uuid('product_category_variant_id')
|
||||
->allowEmptyString('product_category_variant_id');
|
||||
|
||||
$validator
|
||||
->uuid('product_id')
|
||||
->notEmptyString('product_id');
|
||||
$validator
|
||||
->uuid('product_id')
|
||||
->notEmptyString('product_id');
|
||||
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
->requirePresence('enabled', 'create')
|
||||
->notEmptyString('enabled');
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
->requirePresence('enabled', 'create')
|
||||
->notEmptyString('enabled');
|
||||
|
||||
return $validator;
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param RulesChecker $rules The rules object to be modified.
|
||||
* @return RulesChecker
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
$rules->add($rules->existsIn(['product_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']);
|
||||
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
|
||||
public function buildRules(RulesChecker $rules): RulesChecker {
|
||||
$rules->add($rules->existsIn(['product_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']);
|
||||
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
+100
-109
@@ -5,154 +5,145 @@ namespace CakeProducts\Model\Table;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Database\Type\EnumType;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Datasource\ResultSetInterface;
|
||||
use Cake\ORM\Association\BelongsTo;
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use CakeProducts\Model\Entity\Product;
|
||||
use CakeProducts\Model\Enum\ProductProductTypeId;
|
||||
use Closure;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
/**
|
||||
* Products Model
|
||||
*
|
||||
* @property ProductCategoriesTable&BelongsTo $ProductCategories
|
||||
* @property ProductCategoriesTable&\Cake\ORM\Association\BelongsTo $ProductCategories
|
||||
*
|
||||
* @method Product newEmptyEntity()
|
||||
* @method Product newEntity(array $data, array $options = [])
|
||||
* @method array<Product> newEntities(array $data, array $options = [])
|
||||
* @method Product get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
|
||||
* @method Product findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method Product patchEntity(EntityInterface $entity, array $data, array $options = [])
|
||||
* @method array<Product> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method Product|false save(EntityInterface $entity, array $options = [])
|
||||
* @method Product saveOrFail(EntityInterface $entity, array $options = [])
|
||||
* @method iterable<Product>|ResultSetInterface<Product>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<Product>|ResultSetInterface<Product> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<Product>|ResultSetInterface<Product>|false deleteMany(iterable $entities, array $options = [])
|
||||
* @method iterable<Product>|ResultSetInterface<Product> deleteManyOrFail(iterable $entities, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\Product newEmptyEntity()
|
||||
* @method \CakeProducts\Model\Entity\Product newEntity(array $data, array $options = [])
|
||||
* @method array<\CakeProducts\Model\Entity\Product> newEntities(array $data, array $options = [])
|
||||
* @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 \CakeProducts\Model\Entity\Product findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\Product patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
|
||||
* @method array<\CakeProducts\Model\Entity\Product> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\Product|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\Product saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
||||
* @method iterable<\CakeProducts\Model\Entity\Product>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\Product>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<\CakeProducts\Model\Entity\Product>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\Product> saveManyOrFail(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<\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
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('products');
|
||||
$this->setDisplayField('name');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setTable('products');
|
||||
$this->setDisplayField('name');
|
||||
$this->setPrimaryKey('id');
|
||||
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.Products.entity', 'CakeProducts\Model\Entity\Product')
|
||||
);
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.Products.entity', 'CakeProducts\Model\Entity\Product'),
|
||||
);
|
||||
|
||||
$this->belongsTo('ProductCategories', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'joinType' => 'INNER',
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
]);
|
||||
$this->belongsTo('ProductCategories', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'joinType' => 'INNER',
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
]);
|
||||
|
||||
$this->hasMany('ProductAttributes', [
|
||||
'className' => 'CakeProducts.ProductAttributes',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ProductAttributes', [
|
||||
'className' => 'CakeProducts.ProductAttributes',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
|
||||
$this->hasMany('ProductVariants', [
|
||||
'foreignKey' => 'product_id',
|
||||
'className' => 'CakeProducts.ProductVariants',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ProductVariants', [
|
||||
'foreignKey' => 'product_id',
|
||||
'className' => 'CakeProducts.ProductVariants',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
|
||||
$this->hasMany('ProductSkus', [
|
||||
'foreignKey' => 'product_id',
|
||||
'className' => 'CakeProducts.ProductSkus',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ProductSkus', [
|
||||
'foreignKey' => 'product_id',
|
||||
'className' => 'CakeProducts.ProductSkus',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
|
||||
$this->hasMany('ProductPhotos', [
|
||||
'foreignKey' => 'product_id',
|
||||
'className' => 'CakeProducts.ProductPhotos',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ProductPhotos', [
|
||||
'foreignKey' => 'product_id',
|
||||
'className' => 'CakeProducts.ProductPhotos',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
|
||||
$this->hasOne('PrimaryProductPhotos', [
|
||||
'foreignKey' => 'product_id',
|
||||
'conditions' => ['PrimaryProductPhotos.primary_photo' => true],
|
||||
'className' => 'CakeProducts.ProductPhotos',
|
||||
'dependent' => true,
|
||||
]);
|
||||
$this->hasOne('PrimaryProductPhotos', [
|
||||
'foreignKey' => 'product_id',
|
||||
'conditions' => ['PrimaryProductPhotos.primary_photo' => true],
|
||||
'className' => 'CakeProducts.ProductPhotos',
|
||||
'dependent' => true,
|
||||
]);
|
||||
|
||||
$this->hasOne('DefaultProductSkus', [
|
||||
'foreignKey' => 'product_id',
|
||||
'conditions' => ['DefaultProductSkus.default_sku' => true],
|
||||
'className' => 'CakeProducts.ProductSkus',
|
||||
'propertyName' => 'default_product_sku',
|
||||
'dependent' => true,
|
||||
]);
|
||||
$this->hasOne('DefaultProductSkus', [
|
||||
'foreignKey' => 'product_id',
|
||||
'conditions' => ['DefaultProductSkus.default_sku' => true],
|
||||
'className' => 'CakeProducts.ProductSkus',
|
||||
'propertyName' => 'default_product_sku',
|
||||
'dependent' => true,
|
||||
]);
|
||||
|
||||
$this->getSchema()->setColumnType('product_type_id', EnumType::from(ProductProductTypeId::class));
|
||||
$this->getSchema()->setColumnType('product_type_id', EnumType::from(ProductProductTypeId::class));
|
||||
|
||||
$this->addBehavior('Muffin/Trash.Trash');
|
||||
}
|
||||
$this->addBehavior('Muffin/Trash.Trash');
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param Validator $validator Validator instance.
|
||||
* @return Validator
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->scalar('name')
|
||||
->maxLength('name', 255)
|
||||
->requirePresence('name', 'create')
|
||||
->notEmptyString('name');
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->scalar('name')
|
||||
->maxLength('name', 255)
|
||||
->requirePresence('name', 'create')
|
||||
->notEmptyString('name');
|
||||
|
||||
$validator
|
||||
->uuid('product_category_id')
|
||||
->notEmptyString('product_category_id');
|
||||
$validator
|
||||
->uuid('product_category_id')
|
||||
->notEmptyString('product_category_id');
|
||||
|
||||
$validator
|
||||
->integer('product_type_id')
|
||||
->requirePresence('product_type_id', 'create')
|
||||
->notEmptyString('product_type_id');
|
||||
$validator
|
||||
->integer('product_type_id')
|
||||
->requirePresence('product_type_id', 'create')
|
||||
->notEmptyString('product_type_id');
|
||||
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
|
||||
return $validator;
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param RulesChecker $rules The rules object to be modified.
|
||||
* @return RulesChecker
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
$rules->add($rules->isUnique(['product_category_id', 'name']), ['errorField' => 'product_category_id']);
|
||||
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
|
||||
public function buildRules(RulesChecker $rules): RulesChecker {
|
||||
$rules->add($rules->isUnique(['product_category_id', 'name']), ['errorField' => 'product_category_id']);
|
||||
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
|
||||
// $rules->add($rules->validCount('product_attributes', 0, '<=', 'You must not have any tags'));
|
||||
|
||||
return $rules;
|
||||
}
|
||||
return $rules;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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'); ?>
|
||||
@@ -58,38 +58,6 @@
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</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>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -8,18 +8,16 @@ use Cake\TestSuite\Fixture\TestFixture;
|
||||
/**
|
||||
* ProductAttributesFixture
|
||||
*/
|
||||
class ProductAttributesFixture extends TestFixture
|
||||
{
|
||||
/**
|
||||
class ProductAttributesFixture extends TestFixture {
|
||||
|
||||
/**
|
||||
* Init method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->records = [
|
||||
public function init(): void {
|
||||
$this->records = [];
|
||||
parent::init();
|
||||
}
|
||||
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,31 +8,31 @@ use Cake\TestSuite\Fixture\TestFixture;
|
||||
/**
|
||||
* ProductCatalogsFixture
|
||||
*/
|
||||
class ProductCatalogsFixture extends TestFixture
|
||||
{
|
||||
/**
|
||||
class ProductCatalogsFixture extends TestFixture {
|
||||
|
||||
/**
|
||||
* Init method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->records = [
|
||||
[
|
||||
'id' => '115153f3-2f59-4234-8ff8-e1b205761428',
|
||||
'name' => 'Automotive',
|
||||
'catalog_description' => '',
|
||||
'enabled' => true,
|
||||
'deleted' => null,
|
||||
],
|
||||
[
|
||||
'id' => 'f56f3412-ed23-490b-be6e-016208c415d2',
|
||||
'name' => 'Software',
|
||||
'catalog_description' => '',
|
||||
'enabled' => true,
|
||||
'deleted' => null,
|
||||
],
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
public function init(): void {
|
||||
$this->records = [
|
||||
[
|
||||
'id' => '115153f3-2f59-4234-8ff8-e1b205761428',
|
||||
'name' => 'Automotive',
|
||||
'catalog_description' => '',
|
||||
'enabled' => true,
|
||||
'deleted' => null,
|
||||
],
|
||||
[
|
||||
'id' => 'f56f3412-ed23-490b-be6e-016208c415d2',
|
||||
'name' => 'Software',
|
||||
'catalog_description' => '',
|
||||
'enabled' => true,
|
||||
'deleted' => null,
|
||||
],
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,101 +8,101 @@ use Cake\TestSuite\Fixture\TestFixture;
|
||||
/**
|
||||
* ProductCategoriesFixture
|
||||
*/
|
||||
class ProductCategoriesFixture extends TestFixture
|
||||
{
|
||||
/**
|
||||
class ProductCategoriesFixture extends TestFixture {
|
||||
|
||||
/**
|
||||
* Init method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->records = [
|
||||
[
|
||||
'id' => 1,
|
||||
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
|
||||
'internal_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
|
||||
'name' => 'Engine',
|
||||
'category_description' => '',
|
||||
'parent_id' => null,
|
||||
'lft' => 1,
|
||||
'rght' => 4,
|
||||
'enabled' => true,
|
||||
'deleted' => null,
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
|
||||
'internal_id' => '3c2377c5-b97c-4bc9-9660-8f77b4893d8b',
|
||||
'name' => 'Engine Internals',
|
||||
'category_description' => '',
|
||||
'parent_id' => 1,
|
||||
'lft' => 2,
|
||||
'rght' => 3,
|
||||
'enabled' => true,
|
||||
'deleted' => null,
|
||||
],
|
||||
[
|
||||
'id' => 3,
|
||||
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
|
||||
'internal_id' => 'fbee6709-396f-4bb4-b60b-e125b0bc4e83',
|
||||
'name' => 'Electrical',
|
||||
'category_description' => '',
|
||||
'parent_id' => null,
|
||||
'lft' => 5,
|
||||
'rght' => 8,
|
||||
'enabled' => true,
|
||||
'deleted' => null,
|
||||
],
|
||||
[
|
||||
'id' => 4,
|
||||
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
|
||||
'internal_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||
'name' => 'Wiring',
|
||||
'category_description' => '',
|
||||
'parent_id' => 3,
|
||||
'lft' => 6,
|
||||
'rght' => 7,
|
||||
'enabled' => true,
|
||||
'deleted' => null,
|
||||
],
|
||||
[
|
||||
'id' => 5,
|
||||
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
|
||||
'internal_id' => 'c447b6f4-0fb1-4d59-ba45-5613829a725a',
|
||||
'name' => 'Suspension',
|
||||
'category_description' => '',
|
||||
'parent_id' => null,
|
||||
'lft' => 9,
|
||||
'rght' => 12,
|
||||
'enabled' => true,
|
||||
'deleted' => null,
|
||||
],
|
||||
[
|
||||
'id' => 6,
|
||||
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
|
||||
'internal_id' => '1e749d3b-aee0-48a5-8d6c-8cf2b83e9b6e',
|
||||
'name' => 'Coilovers',
|
||||
'category_description' => '',
|
||||
'parent_id' => 5,
|
||||
'lft' => 10,
|
||||
'rght' => 11,
|
||||
'enabled' => true,
|
||||
'deleted' => null,
|
||||
],
|
||||
[
|
||||
'id' => 7,
|
||||
'product_catalog_id' => 'f56f3412-ed23-490b-be6e-016208c415d2',
|
||||
'internal_id' => '8c89a3ca-d56f-46bf-a738-7e85b3342b2a',
|
||||
'name' => 'Support',
|
||||
'category_description' => '',
|
||||
'parent_id' => null,
|
||||
'lft' => 1,
|
||||
'rght' => 2,
|
||||
'enabled' => true,
|
||||
'deleted' => null,
|
||||
],
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
public function init(): void {
|
||||
$this->records = [
|
||||
[
|
||||
'id' => 1,
|
||||
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
|
||||
'internal_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
|
||||
'name' => 'Engine',
|
||||
'category_description' => '',
|
||||
'parent_id' => null,
|
||||
'lft' => 1,
|
||||
'rght' => 4,
|
||||
'enabled' => true,
|
||||
'deleted' => null,
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
|
||||
'internal_id' => '3c2377c5-b97c-4bc9-9660-8f77b4893d8b',
|
||||
'name' => 'Engine Internals',
|
||||
'category_description' => '',
|
||||
'parent_id' => 1,
|
||||
'lft' => 2,
|
||||
'rght' => 3,
|
||||
'enabled' => true,
|
||||
'deleted' => null,
|
||||
],
|
||||
[
|
||||
'id' => 3,
|
||||
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
|
||||
'internal_id' => 'fbee6709-396f-4bb4-b60b-e125b0bc4e83',
|
||||
'name' => 'Electrical',
|
||||
'category_description' => '',
|
||||
'parent_id' => null,
|
||||
'lft' => 5,
|
||||
'rght' => 8,
|
||||
'enabled' => true,
|
||||
'deleted' => null,
|
||||
],
|
||||
[
|
||||
'id' => 4,
|
||||
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
|
||||
'internal_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||
'name' => 'Wiring',
|
||||
'category_description' => '',
|
||||
'parent_id' => 3,
|
||||
'lft' => 6,
|
||||
'rght' => 7,
|
||||
'enabled' => true,
|
||||
'deleted' => null,
|
||||
],
|
||||
[
|
||||
'id' => 5,
|
||||
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
|
||||
'internal_id' => 'c447b6f4-0fb1-4d59-ba45-5613829a725a',
|
||||
'name' => 'Suspension',
|
||||
'category_description' => '',
|
||||
'parent_id' => null,
|
||||
'lft' => 9,
|
||||
'rght' => 12,
|
||||
'enabled' => true,
|
||||
'deleted' => null,
|
||||
],
|
||||
[
|
||||
'id' => 6,
|
||||
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
|
||||
'internal_id' => '1e749d3b-aee0-48a5-8d6c-8cf2b83e9b6e',
|
||||
'name' => 'Coilovers',
|
||||
'category_description' => '',
|
||||
'parent_id' => 5,
|
||||
'lft' => 10,
|
||||
'rght' => 11,
|
||||
'enabled' => true,
|
||||
'deleted' => null,
|
||||
],
|
||||
[
|
||||
'id' => 7,
|
||||
'product_catalog_id' => 'f56f3412-ed23-490b-be6e-016208c415d2',
|
||||
'internal_id' => '8c89a3ca-d56f-46bf-a738-7e85b3342b2a',
|
||||
'name' => 'Support',
|
||||
'category_description' => '',
|
||||
'parent_id' => null,
|
||||
'lft' => 1,
|
||||
'rght' => 2,
|
||||
'enabled' => true,
|
||||
'deleted' => null,
|
||||
],
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,41 +8,41 @@ use Cake\TestSuite\Fixture\TestFixture;
|
||||
/**
|
||||
* ProductCategoryAttributeOptionsFixture
|
||||
*/
|
||||
class ProductCategoryAttributeOptionsFixture extends TestFixture
|
||||
{
|
||||
/**
|
||||
class ProductCategoryAttributeOptionsFixture extends TestFixture {
|
||||
|
||||
/**
|
||||
* Init method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->records = [
|
||||
[
|
||||
'id' => 'e06f1723-2456-483a-b3c4-004603e032a8',
|
||||
'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
|
||||
'attribute_value' => 'Red',
|
||||
'attribute_label' => 'Red',
|
||||
'enabled' => 1,
|
||||
'deleted' => null,
|
||||
],
|
||||
[
|
||||
'id' => 'e06f1723-2456-483a-b3c4-004603e032a1',
|
||||
'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
|
||||
'attribute_value' => 'Blue',
|
||||
'attribute_label' => 'Blue',
|
||||
'enabled' => 1,
|
||||
'deleted' => null,
|
||||
],
|
||||
[
|
||||
'id' => 'e06f1723-2456-483a-b3c4-004603e032a2',
|
||||
'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
|
||||
'attribute_value' => 'Green',
|
||||
'attribute_label' => 'Green',
|
||||
'enabled' => 1,
|
||||
'deleted' => null,
|
||||
]
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
public function init(): void {
|
||||
$this->records = [
|
||||
[
|
||||
'id' => 'e06f1723-2456-483a-b3c4-004603e032a8',
|
||||
'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
|
||||
'attribute_value' => 'Red',
|
||||
'attribute_label' => 'Red',
|
||||
'enabled' => 1,
|
||||
'deleted' => null,
|
||||
],
|
||||
[
|
||||
'id' => 'e06f1723-2456-483a-b3c4-004603e032a1',
|
||||
'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
|
||||
'attribute_value' => 'Blue',
|
||||
'attribute_label' => 'Blue',
|
||||
'enabled' => 1,
|
||||
'deleted' => null,
|
||||
],
|
||||
[
|
||||
'id' => 'e06f1723-2456-483a-b3c4-004603e032a2',
|
||||
'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
|
||||
'attribute_value' => 'Green',
|
||||
'attribute_label' => 'Green',
|
||||
'enabled' => 1,
|
||||
'deleted' => null,
|
||||
],
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,25 +8,25 @@ use Cake\TestSuite\Fixture\TestFixture;
|
||||
/**
|
||||
* ProductCategoryAttributesFixture
|
||||
*/
|
||||
class ProductCategoryAttributesFixture extends TestFixture
|
||||
{
|
||||
/**
|
||||
class ProductCategoryAttributesFixture extends TestFixture {
|
||||
|
||||
/**
|
||||
* Init method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->records = [
|
||||
[
|
||||
'id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
|
||||
'name' => 'Color',
|
||||
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||
'attribute_type_id' => 1,
|
||||
'enabled' => 1,
|
||||
'deleted' => null,
|
||||
],
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
public function init(): void {
|
||||
$this->records = [
|
||||
[
|
||||
'id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
|
||||
'name' => 'Color',
|
||||
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||
'attribute_type_id' => 1,
|
||||
'enabled' => 1,
|
||||
'deleted' => null,
|
||||
],
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,92 +8,91 @@ use Cake\TestSuite\Fixture\TestFixture;
|
||||
/**
|
||||
* ProductCategoryVariantsFixture
|
||||
*/
|
||||
class ProductCategoryVariantOptionsFixture extends TestFixture
|
||||
{
|
||||
/**
|
||||
class ProductCategoryVariantOptionsFixture extends TestFixture {
|
||||
|
||||
/**
|
||||
* Init method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->records = [
|
||||
[
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d23',
|
||||
'variant_value' => 'Blue',
|
||||
'variant_label' => null,
|
||||
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
|
||||
'created' => '2025-07-04 12:00:00',
|
||||
'modified' => '2025-07-04 12:00:00',
|
||||
'enabled' => 1,
|
||||
],
|
||||
[
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d24',
|
||||
'variant_value' => 'Red',
|
||||
'variant_label' => null,
|
||||
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
|
||||
'created' => '2025-07-04 12:00:00',
|
||||
'modified' => '2025-07-04 12:00:00',
|
||||
'enabled' => 1,
|
||||
],
|
||||
public function init(): void {
|
||||
$this->records = [
|
||||
[
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d23',
|
||||
'variant_value' => 'Blue',
|
||||
'variant_label' => null,
|
||||
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
|
||||
'created' => '2025-07-04 12:00:00',
|
||||
'modified' => '2025-07-04 12:00:00',
|
||||
'enabled' => 1,
|
||||
],
|
||||
[
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d24',
|
||||
'variant_value' => 'Red',
|
||||
'variant_label' => null,
|
||||
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
|
||||
'created' => '2025-07-04 12:00:00',
|
||||
'modified' => '2025-07-04 12:00:00',
|
||||
'enabled' => 1,
|
||||
],
|
||||
|
||||
[
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d21',
|
||||
'variant_value' => '12AWG',
|
||||
'variant_label' => null,
|
||||
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
|
||||
'created' => '2025-07-04 12:00:00',
|
||||
'modified' => '2025-07-04 12:00:00',
|
||||
'enabled' => 1,
|
||||
],
|
||||
[
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d22',
|
||||
'variant_value' => '14AWG',
|
||||
'variant_label' => null,
|
||||
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
|
||||
'created' => '2025-07-04 12:00:00',
|
||||
'modified' => '2025-07-04 12:00:00',
|
||||
'enabled' => 1,
|
||||
],
|
||||
|
||||
[
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d21',
|
||||
'variant_value' => '12AWG',
|
||||
'variant_label' => null,
|
||||
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
|
||||
'created' => '2025-07-04 12:00:00',
|
||||
'modified' => '2025-07-04 12:00:00',
|
||||
'enabled' => 1,
|
||||
],
|
||||
[
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d22',
|
||||
'variant_value' => '14AWG',
|
||||
'variant_label' => null,
|
||||
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
|
||||
'created' => '2025-07-04 12:00:00',
|
||||
'modified' => '2025-07-04 12:00:00',
|
||||
'enabled' => 1,
|
||||
],
|
||||
[
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78111',
|
||||
'variant_value' => 'Months',
|
||||
'variant_label' => 'Months',
|
||||
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78111',
|
||||
'created' => '2025-07-04 12:00:00',
|
||||
'modified' => '2025-07-04 12:00:00',
|
||||
'enabled' => 1,
|
||||
],
|
||||
[
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78112',
|
||||
'variant_value' => 'Years',
|
||||
'variant_label' => 'Years',
|
||||
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78111',
|
||||
'created' => '2025-07-04 12:00:00',
|
||||
'modified' => '2025-07-04 12:00:00',
|
||||
'enabled' => 1,
|
||||
],
|
||||
[
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f22221',
|
||||
'variant_value' => '6',
|
||||
'variant_label' => '6',
|
||||
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78222',
|
||||
'created' => '2025-07-04 12:00:00',
|
||||
'modified' => '2025-07-04 12:00:00',
|
||||
'enabled' => 1,
|
||||
],
|
||||
[
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f22222',
|
||||
'variant_value' => 12,
|
||||
'variant_label' => 12,
|
||||
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78222',
|
||||
'created' => '2025-07-04 12:00:00',
|
||||
'modified' => '2025-07-04 12:00:00',
|
||||
'enabled' => 1,
|
||||
],
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
|
||||
[
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78111',
|
||||
'variant_value' => 'Months',
|
||||
'variant_label' => 'Months',
|
||||
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78111',
|
||||
'created' => '2025-07-04 12:00:00',
|
||||
'modified' => '2025-07-04 12:00:00',
|
||||
'enabled' => 1,
|
||||
],
|
||||
[
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78112',
|
||||
'variant_value' => 'Years',
|
||||
'variant_label' => 'Years',
|
||||
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78111',
|
||||
'created' => '2025-07-04 12:00:00',
|
||||
'modified' => '2025-07-04 12:00:00',
|
||||
'enabled' => 1,
|
||||
],
|
||||
[
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f22221',
|
||||
'variant_value' => '6',
|
||||
'variant_label' => '6',
|
||||
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78222',
|
||||
'created' => '2025-07-04 12:00:00',
|
||||
'modified' => '2025-07-04 12:00:00',
|
||||
'enabled' => 1,
|
||||
],
|
||||
[
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f22222',
|
||||
'variant_value' => 12,
|
||||
'variant_label' => 12,
|
||||
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78222',
|
||||
'created' => '2025-07-04 12:00:00',
|
||||
'modified' => '2025-07-04 12:00:00',
|
||||
'enabled' => 1,
|
||||
],
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,46 +8,46 @@ use Cake\TestSuite\Fixture\TestFixture;
|
||||
/**
|
||||
* ProductCategoryVariantsFixture
|
||||
*/
|
||||
class ProductCategoryVariantsFixture extends TestFixture
|
||||
{
|
||||
/**
|
||||
class ProductCategoryVariantsFixture extends TestFixture {
|
||||
|
||||
/**
|
||||
* Init method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->records = [
|
||||
[
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78111',
|
||||
'name' => 'Subscription Length Units',
|
||||
'product_category_id' => null,
|
||||
'enabled' => true,
|
||||
'is_system_variant' => true,
|
||||
],
|
||||
[
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78222',
|
||||
'name' => 'Subscription Length',
|
||||
'product_category_id' => null,
|
||||
'enabled' => true,
|
||||
'is_system_variant' => true,
|
||||
],
|
||||
public function init(): void {
|
||||
$this->records = [
|
||||
[
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78111',
|
||||
'name' => 'Subscription Length Units',
|
||||
'product_category_id' => null,
|
||||
'enabled' => true,
|
||||
'is_system_variant' => true,
|
||||
],
|
||||
[
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78222',
|
||||
'name' => 'Subscription Length',
|
||||
'product_category_id' => null,
|
||||
'enabled' => true,
|
||||
'is_system_variant' => true,
|
||||
],
|
||||
|
||||
[
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
|
||||
'name' => 'Color',
|
||||
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
|
||||
'enabled' => true,
|
||||
'is_system_variant' => false,
|
||||
],
|
||||
[
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
|
||||
'name' => 'AWG',
|
||||
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
|
||||
'enabled' => true,
|
||||
'is_system_variant' => false,
|
||||
],
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
|
||||
[
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
|
||||
'name' => 'Color',
|
||||
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
|
||||
'enabled' => true,
|
||||
'is_system_variant' => false,
|
||||
],
|
||||
[
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
|
||||
'name' => 'AWG',
|
||||
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
|
||||
'enabled' => true,
|
||||
'is_system_variant' => false,
|
||||
],
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,116 +8,116 @@ use Cake\TestSuite\Fixture\TestFixture;
|
||||
/**
|
||||
* ProductPhotosFixture
|
||||
*/
|
||||
class ProductPhotosFixture extends TestFixture
|
||||
{
|
||||
/**
|
||||
class ProductPhotosFixture extends TestFixture {
|
||||
|
||||
/**
|
||||
* Init method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->records = [
|
||||
[
|
||||
'id' => '2c386086-f4c5-4093-bea5-ee9c29479f58',
|
||||
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'product_sku_id' => null,
|
||||
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||
'photo_dir' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f58.png',
|
||||
'primary_photo' => 1,
|
||||
'primary_category_photo' => 0,
|
||||
'primary_sku_photo' => 0,
|
||||
'photo_position' => 100,
|
||||
'enabled' => 1,
|
||||
'created' => '2025-08-10 04:32:10',
|
||||
'modified' => '2025-08-10 04:32:10',
|
||||
'deleted' => null,
|
||||
],
|
||||
public function init(): void {
|
||||
$this->records = [
|
||||
[
|
||||
'id' => '2c386086-f4c5-4093-bea5-ee9c29479f58',
|
||||
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'product_sku_id' => null,
|
||||
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||
'photo_dir' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f58.png',
|
||||
'primary_photo' => 1,
|
||||
'primary_category_photo' => 0,
|
||||
'primary_sku_photo' => 0,
|
||||
'photo_position' => 100,
|
||||
'enabled' => 1,
|
||||
'created' => '2025-08-10 04:32:10',
|
||||
'modified' => '2025-08-10 04:32:10',
|
||||
'deleted' => null,
|
||||
],
|
||||
|
||||
[
|
||||
'id' => '2c386086-f4c5-4093-bea5-ee9c29479f51',
|
||||
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'product_sku_id' => null,
|
||||
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||
'photo_dir' => 'categories',
|
||||
'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f51.png',
|
||||
'primary_photo' => 0,
|
||||
'primary_category_photo' => 1,
|
||||
'primary_sku_photo' => 0,
|
||||
'photo_position' => 100,
|
||||
'enabled' => 1,
|
||||
'created' => '2025-08-10 04:32:10',
|
||||
'modified' => '2025-08-10 04:32:10',
|
||||
'deleted' => null,
|
||||
],
|
||||
[
|
||||
'id' => '2c386086-f4c5-4093-bea5-ee9c29479f51',
|
||||
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'product_sku_id' => null,
|
||||
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||
'photo_dir' => 'categories',
|
||||
'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f51.png',
|
||||
'primary_photo' => 0,
|
||||
'primary_category_photo' => 1,
|
||||
'primary_sku_photo' => 0,
|
||||
'photo_position' => 100,
|
||||
'enabled' => 1,
|
||||
'created' => '2025-08-10 04:32:10',
|
||||
'modified' => '2025-08-10 04:32:10',
|
||||
'deleted' => null,
|
||||
],
|
||||
|
||||
[
|
||||
'id' => '2c386086-f4c5-4093-bea5-ee9c29479f50',
|
||||
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'product_sku_id' => null,
|
||||
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||
'photo_dir' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f58.png',
|
||||
'primary_photo' => 0,
|
||||
'primary_category_photo' => 0,
|
||||
'primary_sku_photo' => 0,
|
||||
'photo_position' => 100,
|
||||
'enabled' => 1,
|
||||
'created' => '2025-08-10 04:32:10',
|
||||
'modified' => '2025-08-10 04:32:10',
|
||||
'deleted' => null,
|
||||
],
|
||||
[
|
||||
'id' => '2c386086-f4c5-4093-bea5-ee9c29479f53',
|
||||
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'product_sku_id' => null,
|
||||
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||
'photo_dir' => 'categories',
|
||||
'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f51.png',
|
||||
'primary_photo' => 0,
|
||||
'primary_category_photo' => 0,
|
||||
'primary_sku_photo' => 0,
|
||||
'photo_position' => 100,
|
||||
'enabled' => 1,
|
||||
'created' => '2025-08-10 04:32:10',
|
||||
'modified' => '2025-08-10 04:32:10',
|
||||
'deleted' => null,
|
||||
],
|
||||
[
|
||||
'id' => '2c386086-f4c5-4093-bea5-ee9c29479f50',
|
||||
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'product_sku_id' => null,
|
||||
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||
'photo_dir' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f58.png',
|
||||
'primary_photo' => 0,
|
||||
'primary_category_photo' => 0,
|
||||
'primary_sku_photo' => 0,
|
||||
'photo_position' => 100,
|
||||
'enabled' => 1,
|
||||
'created' => '2025-08-10 04:32:10',
|
||||
'modified' => '2025-08-10 04:32:10',
|
||||
'deleted' => null,
|
||||
],
|
||||
[
|
||||
'id' => '2c386086-f4c5-4093-bea5-ee9c29479f53',
|
||||
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'product_sku_id' => null,
|
||||
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||
'photo_dir' => 'categories',
|
||||
'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f51.png',
|
||||
'primary_photo' => 0,
|
||||
'primary_category_photo' => 0,
|
||||
'primary_sku_photo' => 0,
|
||||
'photo_position' => 100,
|
||||
'enabled' => 1,
|
||||
'created' => '2025-08-10 04:32:10',
|
||||
'modified' => '2025-08-10 04:32:10',
|
||||
'deleted' => null,
|
||||
],
|
||||
|
||||
[
|
||||
'id' => '2c386086-f4c5-4093-bea5-ee9c29479f11',
|
||||
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'product_sku_id' => '3a477e3e-7977-4813-81f6-f85949613979',
|
||||
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||
'photo_dir' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f58.png',
|
||||
'primary_photo' => 0,
|
||||
'primary_category_photo' => 0,
|
||||
'primary_sku_photo' => 1,
|
||||
'photo_position' => 100,
|
||||
'enabled' => 1,
|
||||
'created' => '2025-08-10 04:32:10',
|
||||
'modified' => '2025-08-10 04:32:10',
|
||||
'deleted' => null,
|
||||
],
|
||||
[
|
||||
'id' => '2c386086-f4c5-4093-bea5-ee9c29479f12',
|
||||
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'product_sku_id' => '3a477e3e-7977-4813-81f6-f85949613979',
|
||||
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||
'photo_dir' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f51.png',
|
||||
'primary_photo' => 0,
|
||||
'primary_category_photo' => 0,
|
||||
'primary_sku_photo' => 0,
|
||||
'photo_position' => 100,
|
||||
'enabled' => 1,
|
||||
'created' => '2025-08-10 04:32:10',
|
||||
'modified' => '2025-08-10 04:32:10',
|
||||
'deleted' => null,
|
||||
],
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
|
||||
[
|
||||
'id' => '2c386086-f4c5-4093-bea5-ee9c29479f11',
|
||||
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'product_sku_id' => '3a477e3e-7977-4813-81f6-f85949613979',
|
||||
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||
'photo_dir' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f58.png',
|
||||
'primary_photo' => 0,
|
||||
'primary_category_photo' => 0,
|
||||
'primary_sku_photo' => 1,
|
||||
'photo_position' => 100,
|
||||
'enabled' => 1,
|
||||
'created' => '2025-08-10 04:32:10',
|
||||
'modified' => '2025-08-10 04:32:10',
|
||||
'deleted' => null,
|
||||
],
|
||||
[
|
||||
'id' => '2c386086-f4c5-4093-bea5-ee9c29479f12',
|
||||
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'product_sku_id' => '3a477e3e-7977-4813-81f6-f85949613979',
|
||||
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||
'photo_dir' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f51.png',
|
||||
'primary_photo' => 0,
|
||||
'primary_category_photo' => 0,
|
||||
'primary_sku_photo' => 0,
|
||||
'photo_position' => 100,
|
||||
'enabled' => 1,
|
||||
'created' => '2025-08-10 04:32:10',
|
||||
'modified' => '2025-08-10 04:32:10',
|
||||
'deleted' => null,
|
||||
],
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,30 +8,30 @@ use Cake\TestSuite\Fixture\TestFixture;
|
||||
/**
|
||||
* ProductSkuVariantValuesFixture
|
||||
*/
|
||||
class ProductSkuVariantValuesFixture extends TestFixture
|
||||
{
|
||||
/**
|
||||
class ProductSkuVariantValuesFixture extends TestFixture {
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public string $table = 'product_sku_variant_values';
|
||||
public string $table = 'product_sku_variant_values';
|
||||
|
||||
/**
|
||||
/**
|
||||
* Init method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->records = [
|
||||
[
|
||||
'id' => '98b609d8-1d4f-484c-a13a-6adb7102da56',
|
||||
'product_sku_id' => '3a477e3e-7977-4813-81f6-f85949613979',
|
||||
'product_variant_id' => '2e6e4031-c430-4d07-b8d6-a4e759b72569',
|
||||
'product_category_variant_option_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d23',
|
||||
],
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
public function init(): void {
|
||||
$this->records = [
|
||||
[
|
||||
'id' => '98b609d8-1d4f-484c-a13a-6adb7102da56',
|
||||
'product_sku_id' => '3a477e3e-7977-4813-81f6-f85949613979',
|
||||
'product_variant_id' => '2e6e4031-c430-4d07-b8d6-a4e759b72569',
|
||||
'product_category_variant_option_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d23',
|
||||
],
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,34 +8,35 @@ use Cake\TestSuite\Fixture\TestFixture;
|
||||
/**
|
||||
* ProductSkusFixture
|
||||
*/
|
||||
class ProductSkusFixture extends TestFixture
|
||||
{
|
||||
/**
|
||||
class ProductSkusFixture extends TestFixture {
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public string $table = 'product_skus';
|
||||
/**
|
||||
public string $table = 'product_skus';
|
||||
|
||||
/**
|
||||
* Init method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->records = [
|
||||
[
|
||||
'id' => '3a477e3e-7977-4813-81f6-f85949613979',
|
||||
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'sku' => '3a477e3e-7977-4813-81f6-f85949613979',
|
||||
'barcode' => '3a477e3e-7977-4813-81f6-f85949613979',
|
||||
'price' => 1.5,
|
||||
'cost' => 1.5,
|
||||
'created' => '2025-04-15 09:09:15',
|
||||
'modified' => '2025-04-15 09:09:15',
|
||||
'deleted' => null,
|
||||
],
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
public function init(): void {
|
||||
$this->records = [
|
||||
[
|
||||
'id' => '3a477e3e-7977-4813-81f6-f85949613979',
|
||||
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'sku' => '3a477e3e-7977-4813-81f6-f85949613979',
|
||||
'barcode' => '3a477e3e-7977-4813-81f6-f85949613979',
|
||||
'price' => 1.5,
|
||||
'cost' => 1.5,
|
||||
'created' => '2025-04-15 09:09:15',
|
||||
'modified' => '2025-04-15 09:09:15',
|
||||
'deleted' => null,
|
||||
],
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,45 +8,45 @@ use Cake\TestSuite\Fixture\TestFixture;
|
||||
/**
|
||||
* ProductVariantsFixture
|
||||
*/
|
||||
class ProductVariantsFixture extends TestFixture
|
||||
{
|
||||
/**
|
||||
class ProductVariantsFixture extends TestFixture {
|
||||
|
||||
/**
|
||||
* Init method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->records = [
|
||||
[
|
||||
'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72568',
|
||||
'name' => 'Color',
|
||||
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
|
||||
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'enabled' => 1,
|
||||
],
|
||||
[
|
||||
'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72569',
|
||||
'name' => 'Color',
|
||||
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
|
||||
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05318',
|
||||
'enabled' => 1,
|
||||
],
|
||||
[
|
||||
'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72561',
|
||||
'name' => 'AWG',
|
||||
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
|
||||
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'enabled' => 1,
|
||||
],
|
||||
[
|
||||
'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72562',
|
||||
'name' => 'AWG',
|
||||
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
|
||||
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05318',
|
||||
'enabled' => 1,
|
||||
]
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
public function init(): void {
|
||||
$this->records = [
|
||||
[
|
||||
'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72568',
|
||||
'name' => 'Color',
|
||||
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
|
||||
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'enabled' => 1,
|
||||
],
|
||||
[
|
||||
'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72569',
|
||||
'name' => 'Color',
|
||||
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
|
||||
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05318',
|
||||
'enabled' => 1,
|
||||
],
|
||||
[
|
||||
'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72561',
|
||||
'name' => 'AWG',
|
||||
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
|
||||
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'enabled' => 1,
|
||||
],
|
||||
[
|
||||
'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72562',
|
||||
'name' => 'AWG',
|
||||
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
|
||||
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05318',
|
||||
'enabled' => 1,
|
||||
],
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,31 +8,31 @@ use Cake\TestSuite\Fixture\TestFixture;
|
||||
/**
|
||||
* ProductsFixture
|
||||
*/
|
||||
class ProductsFixture extends TestFixture
|
||||
{
|
||||
/**
|
||||
class ProductsFixture extends TestFixture {
|
||||
|
||||
/**
|
||||
* Init method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->records = [
|
||||
[
|
||||
'id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'name' => '12AWG RED TXL Wire',
|
||||
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||
'product_type_id' => 1,
|
||||
'deleted' => null,
|
||||
],
|
||||
[
|
||||
'id' => 'cfc98a9a-29b2-44c8-b587-8156adc05318',
|
||||
'name' => 'Heat Shrink',
|
||||
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||
'product_type_id' => 1,
|
||||
'deleted' => null,
|
||||
],
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
public function init(): void {
|
||||
$this->records = [
|
||||
[
|
||||
'id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'name' => '12AWG RED TXL Wire',
|
||||
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||
'product_type_id' => 1,
|
||||
'deleted' => null,
|
||||
],
|
||||
[
|
||||
'id' => 'cfc98a9a-29b2-44c8-b587-8156adc05318',
|
||||
'name' => 'Heat Shrink',
|
||||
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||
'product_type_id' => 1,
|
||||
'deleted' => null,
|
||||
],
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,55 +14,52 @@ use RecursiveIteratorIterator;
|
||||
*
|
||||
* Used to make logging in easier and to handle folder structure for product images
|
||||
*/
|
||||
class BaseControllerTest extends TestCase
|
||||
{
|
||||
use IntegrationTestTrait;
|
||||
class BaseControllerTest extends TestCase {
|
||||
|
||||
public function loginUserByRole(string $role = 'admin'): void
|
||||
{
|
||||
$this->session(['Auth.User.id' => 1]);
|
||||
$this->session(['Auth.id' => 1]);
|
||||
}
|
||||
use IntegrationTestTrait;
|
||||
|
||||
/**
|
||||
public function loginUserByRole(string $role = 'admin'): void {
|
||||
$this->session(['Auth.User.id' => 1]);
|
||||
$this->session(['Auth.id' => 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testTest()
|
||||
{
|
||||
$this->assertEquals(1, 1);
|
||||
}
|
||||
public function testTest() {
|
||||
$this->assertEquals(1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$toCopy = PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'webroot' . DS . 'images' . DS . '2c386086-f4c5-4093-bea5-ee9c29479f58.png';
|
||||
$productsFolder = PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'webroot' . DS . 'uploads' . DS .
|
||||
'images' . DS . 'products' . DS . 'cfc98a9a-29b2-44c8-b587-8156adc05317';
|
||||
$newName = $productsFolder . DS . '2c386086-f4c5-4093-bea5-ee9c29479f58.png';
|
||||
if (file_exists($toCopy)) {
|
||||
if (!file_exists($productsFolder)) {
|
||||
mkdir($productsFolder, 0775, true);
|
||||
}
|
||||
copy($toCopy, $newName);
|
||||
}
|
||||
}
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
$toCopy = PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'webroot' . DS . 'images' . DS . '2c386086-f4c5-4093-bea5-ee9c29479f58.png';
|
||||
$productsFolder = PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'webroot' . DS . 'uploads' . DS
|
||||
. 'images' . DS . 'products' . DS . 'cfc98a9a-29b2-44c8-b587-8156adc05317';
|
||||
$newName = $productsFolder . DS . '2c386086-f4c5-4093-bea5-ee9c29479f58.png';
|
||||
if (file_exists($toCopy)) {
|
||||
if (!file_exists($productsFolder)) {
|
||||
mkdir($productsFolder, 0775, true);
|
||||
}
|
||||
copy($toCopy, $newName);
|
||||
}
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
parent::tearDown(); // TODO: Change the autogenerated stub
|
||||
protected function tearDown(): void {
|
||||
parent::tearDown(); // TODO: Change the autogenerated stub
|
||||
|
||||
$path = Configure::readOrFail('CakeProducts.photos.directory');
|
||||
if (file_exists($path)) {
|
||||
$di = new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS);
|
||||
$ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
|
||||
foreach ($ri as $file) {
|
||||
$file->isDir() ? rmdir($file->getRealPath()) : unlink($file->getRealPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$path = Configure::readOrFail('CakeProducts.photos.directory');
|
||||
if (file_exists($path)) {
|
||||
$di = new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS);
|
||||
$ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
|
||||
foreach ( $ri as $file ) {
|
||||
$file->isDir() ? rmdir($file->getRealPath()) : unlink($file->getRealPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,325 +3,311 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Test\TestCase\Controller;
|
||||
|
||||
use Cake\ORM\Table;
|
||||
use Cake\TestSuite\IntegrationTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
use CakeProducts\Controller\ProductCatalogsController;
|
||||
use CakeProducts\Model\Table\ProductCatalogsTable;
|
||||
use PHPUnit\Exception;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
|
||||
/**
|
||||
* CakeProducts\Controller\ProductCatalogsController Test Case
|
||||
*/
|
||||
#[CoversClass(ProductCatalogsController::class)]
|
||||
class ProductCatalogsControllerTest extends BaseControllerTest
|
||||
{
|
||||
/**
|
||||
class ProductCatalogsControllerTest extends BaseControllerTest {
|
||||
|
||||
/**
|
||||
* Test subject table
|
||||
*
|
||||
* @var ProductCatalogsTable|Table
|
||||
* @var \CakeProducts\Model\Table\ProductCatalogsTable|\Cake\ORM\Table
|
||||
*/
|
||||
protected $ProductCatalogs;
|
||||
protected $ProductCatalogs;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Fixtures
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected array $fixtures = [
|
||||
'plugin.CakeProducts.ProductCatalogs',
|
||||
'plugin.CakeProducts.ProductCategories',
|
||||
];
|
||||
protected array $fixtures = [
|
||||
'plugin.CakeProducts.ProductCatalogs',
|
||||
'plugin.CakeProducts.ProductCategories',
|
||||
];
|
||||
|
||||
/**
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
// $this->enableCsrfToken();
|
||||
// $this->enableSecurityToken();
|
||||
$this->disableErrorHandlerMiddleware();
|
||||
$config = $this->getTableLocator()->exists('ProductCatalogs') ? [] : ['className' => ProductCatalogsTable::class];
|
||||
$this->ProductCatalogs = $this->getTableLocator()->get('ProductCatalogs', $config);
|
||||
}
|
||||
$this->disableErrorHandlerMiddleware();
|
||||
$config = $this->getTableLocator()->exists('ProductCatalogs') ? [] : ['className' => ProductCatalogsTable::class];
|
||||
$this->ProductCatalogs = $this->getTableLocator()->get('ProductCatalogs', $config);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
unset($this->ProductCatalogs);
|
||||
protected function tearDown(): void {
|
||||
unset($this->ProductCatalogs);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Test index method
|
||||
*
|
||||
* Tests the index action with a logged in user
|
||||
*
|
||||
* @uses \CakeProducts\Controller\ProductCatalogsController::index()
|
||||
* @throws Exception
|
||||
* @throws \PHPUnit\Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIndexGet(): void
|
||||
{
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'index',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
}
|
||||
public function testIndexGet(): void {
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'index',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Test view method
|
||||
*
|
||||
* Tests the view action with a logged in user
|
||||
*
|
||||
* @uses \CakeProducts\Controller\ProductCatalogsController::view()
|
||||
* @throws Exception
|
||||
* @throws \PHPUnit\Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testViewGet(): void
|
||||
{
|
||||
$id = '115153f3-2f59-4234-8ff8-e1b205761428';
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'view',
|
||||
$id,
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
}
|
||||
public function testViewGet(): void {
|
||||
$id = '115153f3-2f59-4234-8ff8-e1b205761428';
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'view',
|
||||
$id,
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* Tests the add action with a logged in user
|
||||
*
|
||||
* @uses \CakeProducts\Controller\ProductCatalogsController::add()
|
||||
* @throws Exception
|
||||
* @throws \PHPUnit\Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddGet(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCatalogs->find()->count();
|
||||
public function testAddGet(): void {
|
||||
$cntBefore = $this->ProductCatalogs->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'add',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'add',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
|
||||
$cntAfter = $this->ProductCatalogs->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
$cntAfter = $this->ProductCatalogs->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* Tests a POST request to the add action with a logged in user
|
||||
*
|
||||
* @uses \CakeProducts\Controller\ProductCatalogsController::add()
|
||||
* @throws Exception
|
||||
* @throws \PHPUnit\Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddPostSuccess(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCatalogs->find()->count();
|
||||
public function testAddPostSuccess(): void {
|
||||
$cntBefore = $this->ProductCatalogs->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'add',
|
||||
];
|
||||
$data = [
|
||||
'name' => 'new catalog',
|
||||
'catalog_description' => 'description',
|
||||
'enabled' => true,
|
||||
];
|
||||
$this->post($url, $data);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('product-catalogs');
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'add',
|
||||
];
|
||||
$data = [
|
||||
'name' => 'new catalog',
|
||||
'catalog_description' => 'description',
|
||||
'enabled' => true,
|
||||
];
|
||||
$this->post($url, $data);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('product-catalogs');
|
||||
|
||||
$cntAfter = $this->ProductCatalogs->find()->count();
|
||||
$this->assertEquals($cntBefore + 1, $cntAfter);
|
||||
}
|
||||
$cntAfter = $this->ProductCatalogs->find()->count();
|
||||
$this->assertEquals($cntBefore + 1, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* Tests a POST request to the add action with a logged in user
|
||||
*
|
||||
* @uses \CakeProducts\Controller\ProductCatalogsController::add()
|
||||
* @throws Exception
|
||||
* @throws \PHPUnit\Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddPostFailure(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCatalogs->find()->count();
|
||||
public function testAddPostFailure(): void {
|
||||
$cntBefore = $this->ProductCatalogs->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'add',
|
||||
];
|
||||
$data = [
|
||||
'name' => '',
|
||||
'catalog_description' => '',
|
||||
'enabled' => '',
|
||||
];
|
||||
$this->post($url, $data);
|
||||
$this->assertResponseCode(200);
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'add',
|
||||
];
|
||||
$data = [
|
||||
'name' => '',
|
||||
'catalog_description' => '',
|
||||
'enabled' => '',
|
||||
];
|
||||
$this->post($url, $data);
|
||||
$this->assertResponseCode(200);
|
||||
|
||||
$cntAfter = $this->ProductCatalogs->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
$cntAfter = $this->ProductCatalogs->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Test edit method
|
||||
*
|
||||
* Tests the edit action with a logged in user
|
||||
*
|
||||
* @uses \CakeProducts\Controller\ProductCatalogsController::edit()
|
||||
* @throws Exception
|
||||
* @throws \PHPUnit\Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEditGet(): void
|
||||
{
|
||||
$this->loginUserByRole('admin');
|
||||
$id = '115153f3-2f59-4234-8ff8-e1b205761428';
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'edit',
|
||||
$id,
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
}
|
||||
public function testEditGet(): void {
|
||||
$this->loginUserByRole('admin');
|
||||
$id = '115153f3-2f59-4234-8ff8-e1b205761428';
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'edit',
|
||||
$id,
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Test edit method
|
||||
*
|
||||
* Tests a PUT request to the edit action with a logged in user
|
||||
*
|
||||
* @uses \CakeProducts\Controller\ProductCatalogsController::edit()
|
||||
* @throws Exception
|
||||
* @throws \PHPUnit\Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEditPutSuccess(): void
|
||||
{
|
||||
$this->loginUserByRole('admin');
|
||||
$id = '115153f3-2f59-4234-8ff8-e1b205761428';
|
||||
public function testEditPutSuccess(): void {
|
||||
$this->loginUserByRole('admin');
|
||||
$id = '115153f3-2f59-4234-8ff8-e1b205761428';
|
||||
// $before = $this->ProductCatalogs->get($id);
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'edit',
|
||||
$id,
|
||||
];
|
||||
$data = [
|
||||
// test new data here
|
||||
'name' => 'edited name',
|
||||
'catalog_description' => 'new catalog description',
|
||||
'enabled' => true,
|
||||
];
|
||||
$this->put($url, $data);
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'edit',
|
||||
$id,
|
||||
];
|
||||
$data = [
|
||||
// test new data here
|
||||
'name' => 'edited name',
|
||||
'catalog_description' => 'new catalog description',
|
||||
'enabled' => true,
|
||||
];
|
||||
$this->put($url, $data);
|
||||
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('product-catalogs');
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('product-catalogs');
|
||||
|
||||
$after = $this->ProductCatalogs->get($id);
|
||||
$this->assertEquals($data['name'], $after->name);
|
||||
$this->assertEquals($data['catalog_description'], $after->catalog_description);
|
||||
// assert saved properly below
|
||||
}
|
||||
$after = $this->ProductCatalogs->get($id);
|
||||
$this->assertEquals($data['name'], $after->name);
|
||||
$this->assertEquals($data['catalog_description'], $after->catalog_description);
|
||||
// assert saved properly below
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Test edit method
|
||||
*
|
||||
* Tests a PUT request to the edit action with a logged in user
|
||||
*
|
||||
* @uses \CakeProducts\Controller\ProductCatalogsController::edit()
|
||||
* @throws Exception
|
||||
* @throws \PHPUnit\Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEditPutFailure(): void
|
||||
{
|
||||
$this->loginUserByRole('admin');
|
||||
$id = '115153f3-2f59-4234-8ff8-e1b205761428';
|
||||
$before = $this->ProductCatalogs->get($id);
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'edit',
|
||||
$id,
|
||||
];
|
||||
$data = [
|
||||
'name' => '',
|
||||
'catalog_description' => 'edited description',
|
||||
'enabled' => '',
|
||||
];
|
||||
$this->put($url, $data);
|
||||
$this->assertResponseCode(200);
|
||||
$after = $this->ProductCatalogs->get($id);
|
||||
$this->assertEquals($before->name, $after->name);
|
||||
$this->assertEquals($before->catalog_description, $after->catalog_description);
|
||||
// assert save failed below
|
||||
}
|
||||
public function testEditPutFailure(): void {
|
||||
$this->loginUserByRole('admin');
|
||||
$id = '115153f3-2f59-4234-8ff8-e1b205761428';
|
||||
$before = $this->ProductCatalogs->get($id);
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'edit',
|
||||
$id,
|
||||
];
|
||||
$data = [
|
||||
'name' => '',
|
||||
'catalog_description' => 'edited description',
|
||||
'enabled' => '',
|
||||
];
|
||||
$this->put($url, $data);
|
||||
$this->assertResponseCode(200);
|
||||
$after = $this->ProductCatalogs->get($id);
|
||||
$this->assertEquals($before->name, $after->name);
|
||||
$this->assertEquals($before->catalog_description, $after->catalog_description);
|
||||
// assert save failed below
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Test delete method
|
||||
*
|
||||
* Tests the delete action with a logged in user
|
||||
*
|
||||
* @uses \CakeProducts\Controller\ProductCatalogsController::delete()
|
||||
* @throws Exception
|
||||
* @throws \PHPUnit\Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCatalogs->find()->count();
|
||||
public function testDelete(): void {
|
||||
$cntBefore = $this->ProductCatalogs->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$id = '115153f3-2f59-4234-8ff8-e1b205761428';
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'delete',
|
||||
$id,
|
||||
];
|
||||
$this->delete($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('product-catalogs');
|
||||
$this->loginUserByRole('admin');
|
||||
$id = '115153f3-2f59-4234-8ff8-e1b205761428';
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'delete',
|
||||
$id,
|
||||
];
|
||||
$this->delete($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('product-catalogs');
|
||||
|
||||
$cntAfter = $this->ProductCatalogs->find()->count();
|
||||
$this->assertEquals($cntBefore - 1, $cntAfter);
|
||||
}
|
||||
|
||||
$cntAfter = $this->ProductCatalogs->find()->count();
|
||||
$this->assertEquals($cntBefore - 1, $cntAfter);
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user