84 Commits

Author SHA1 Message Date
c196dc2fe0 dont use cheese cake override table trait - dont think is necessary 2025-11-11 01:01:42 -08:00
c8e44f3705 read me update 2025-11-04 02:10:37 -08:00
a471be8ff9 subscribtion category variants / system category variants 2025-11-04 01:50:05 -08:00
868f9dbcce more product types (events, subscriptions, digital goods), photos templates index/view 2025-11-03 23:15:31 -08:00
46e8712161 extension not getting added properly - should now be solid 2025-11-02 01:20:42 -07:00
4ffafb781d handle internal id vs integer id category in product photos 2025-11-02 01:13:21 -07:00
f5da89cb19 photos working with categories better now 2025-11-01 23:52:49 -07:00
dc2f422247 category id not null but product id can be null same with sku id - product photos 2025-11-01 23:39:15 -07:00
d239a98e8e unique rules, allow product id to be null in product photos 2025-11-01 23:16:59 -07:00
2041fc78d3 more thorogh testing of toggle behavior on product photos 2025-11-01 17:00:15 -07:00
b145e901ef primary sku photo working with janky toggle workaround but w/e lol 2025-11-01 16:10:48 -07:00
41c5f7169e toggle behavior on skus for default product sku, photos for default category photo and default product photo 2025-10-31 01:29:56 -07:00
9f1959a0ee select options for products + skus, photos form 2025-10-12 02:20:02 -07:00
30aad1dea4 category photos should be working 2025-10-12 01:04:36 -07:00
66db31c7ad added suggested cart package 2025-10-11 22:50:44 -07:00
590e7e652c propertyName default product sku vskus 2025-10-09 02:39:55 -07:00
76876e04fa fix classname in default sku on products table 2025-10-07 20:40:29 -07:00
8e2165d991 product sku property name on sku variant values 2025-10-07 01:21:04 -07:00
44130c0cd2 fix sku variant values association on variants table
git st
2025-10-07 01:16:13 -07:00
e9ba1845ba add default sku flag to accessible fields in save options skus add 2025-10-06 23:49:48 -07:00
75714137b7 accessible field/entity update default ksu 2025-10-06 23:34:27 -07:00
25957f7d8b default sku boolean to product skus table 2025-10-06 23:21:50 -07:00
81a9f827db not sure if that index should be kept or if leave up to user to use soft delete - soft delete can break if readd product with same name/category after deleting 2025-10-05 17:42:07 -07:00
5a855374f9 existing sku bug using old field for variant id 2025-10-03 03:09:34 -07:00
73349b736e existing skus working now too 2025-10-03 03:04:57 -07:00
49912abd3a product variants table split off from category variants table, variant values table updated to reflect 2025-10-03 02:16:24 -07:00
d49a8784e6 primary photo on products table 2025-09-29 23:40:16 -07:00
fd0f9efa28 has many sku variant values on category variants table 2025-09-23 02:09:17 -07:00
5b38de39fc product id back on product category variants table...dumb 2025-09-22 21:51:52 -07:00
2d405d542b fix @uses warnings 2025-09-21 18:09:35 -07:00
892a85d30a remove product id from product category variants table 2025-09-21 17:51:54 -07:00
4549f30930 product attributes add/edit 2025-09-19 23:44:18 -07:00
25cb12d810 product attributes on edit product 2025-09-19 23:34:04 -07:00
f0f9ebeb8c fix @uses errors 2025-09-10 23:53:01 -07:00
77283191ef test if will fix ci actions 2025-09-10 23:29:40 -07:00
db79a636b3 wip 2025-09-10 22:58:37 -07:00
c061bd1133 entities update label related entities better 2025-09-10 22:19:27 -07:00
4d98343653 test fix for sku variant values 2025-09-10 22:09:15 -07:00
71c038a9a0 start of variant values 2025-09-10 22:06:12 -07:00
f3a6384c55 test fixes for product skus add 2025-09-06 01:11:51 -07:00
99f52422c1 missed php 8.1 in ci.yaml 2025-09-05 23:34:57 -07:00
ca1c8c614f php 8.2 min 2025-09-05 23:31:58 -07:00
43a7805b5e require cartesian product library, product skus add update 2025-09-05 02:51:43 -07:00
9d9c32f0b9 add the contain for product skus on products 2025-09-04 22:49:23 -07:00
4356dcd800 skus must be unique, add more variants and skus to products view contain 2025-09-04 22:46:09 -07:00
8cf8d7cfa0 show image on view product photos page, setEntityClass defaulting to all plugin entities 2025-09-01 00:46:18 -07:00
155095c25c test fixes product category variatns - trying to show attribute type id which isnt valid field on that table 2025-09-01 00:10:07 -07:00
9636cc9091 photos wip - almost there 2025-08-22 00:41:57 -07:00
803e161a9a get product skus table via product photos in product photos controller 2025-08-21 23:40:00 -07:00
b9bf47f385 variants controller tests failing 2025-08-21 22:43:06 -07:00
8bdb329828 gitignore, product photos fixture, copy/delete in base controller test setUp/tearDown 2025-08-19 01:13:13 -07:00
493068cc1c gitea ci workflow - change validation steps composer install 2025-08-12 01:33:38 -07:00
ac0dc3c9e3 fix @uses statements in controller tests 2025-08-12 01:30:30 -07:00
16f987b852 composer require sqlite extension 2025-08-12 01:11:11 -07:00
003f5d17f1 base it off of xorm gitea action mysql8 test 2025-08-12 00:43:28 -07:00
bfa8f8c9fd test runs on ubuntu latest for ci action 2025-08-12 00:37:17 -07:00
452ec31ba7 workflow test 2025-08-12 00:05:38 -07:00
0181c48907 product photos controller test fixes, test out 2025-08-11 23:35:46 -07:00
3a47f09e8c upload test passing + file not getting deleted every time - well it is but we now use a copy lol 2025-08-10 02:50:22 -07:00
a1012b4054 product photos first commit - only upload base photo 2025-08-10 02:35:25 -07:00
82b3ca59ed dont have any runners working anyway but sleep 120 to see if mysql will be available 2025-08-09 20:11:16 -07:00
9d777f12b2 default product type id on categories table 2025-07-05 23:18:54 -07:00
59a38758e9 variant options coming along - add test passing 2025-07-05 20:48:40 -07:00
5adc791c20 variant options wip 2025-07-05 20:08:56 -07:00
c9d34f7115 remove variant type id (enum) from variants table, use internal id for category field on variants form 2025-06-30 21:25:47 -07:00
5fb215c7fd fix variant type id vs attribute type id 2025-06-29 23:27:38 -07:00
46e68d8c56 use override table trait from cheesecake pluging 2025-06-29 23:07:42 -07:00
5cba7de890 test additions variants table 2025-06-29 22:25:38 -07:00
5bb1110e7f migration file name fix 2025-06-29 21:54:46 -07:00
f61a4161be wip product category variants 2025-06-29 21:52:07 -07:00
a01805dc53 product skus v1 2025-04-15 02:39:35 -07:00
4868064c44 product attributes deleted field not added to migration 2025-04-08 01:54:29 -07:00
cf7c67763c add soft delete via muffin/trash to all product related tables 2025-04-08 01:30:40 -07:00
013bec1b54 license update use MIT 2025-04-07 23:57:41 -07:00
b5926c260e product attributes increment was missing on form, view product attributes on view product page 2025-04-05 02:37:53 -07:00
bb1dab1f43 product attributes 2025-04-05 02:06:23 -07:00
4e6b7ca1ac categories not attributes fix 2025-04-02 01:39:07 -07:00
2f80ba1fa3 attributes form wip 2025-04-02 01:27:25 -07:00
732819ff73 keyField vs valueField switched oops 2025-04-02 00:36:54 -07:00
fce8cc6b8b form request query wrong request - now working 2025-04-02 00:29:05 -07:00
42f2b4f64b products form htmx attributes wip - bedtime though 2025-04-01 02:52:00 -07:00
9f94f7d0ed wip first not first or fail attributes form 2025-04-01 02:37:58 -07:00
56e526bc0f wip 2025-04-01 02:19:01 -07:00
f724b86674 products form wip 2025-04-01 01:24:18 -07:00
129 changed files with 6696 additions and 467 deletions

View File

@@ -7,51 +7,47 @@ on:
jobs: jobs:
testsuite: testsuite:
runs-on: ubuntu-22.04 runs-on: ubuntu-latest
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
php-version: ['8.1', '8.4'] php-version: ['8.2', '8.4']
db-type: ['sqlite', 'mysql', 'pgsql'] db-type: ['mysql']
# db-type: ['sqlite', 'mysql', 'pgsql']
prefer-lowest: [''] prefer-lowest: ['']
include: include:
- php-version: '8.1' - php-version: '8.2'
db-type: 'sqlite' db-type: 'sqlite'
prefer-lowest: 'prefer-lowest' prefer-lowest: 'prefer-lowest'
services: services:
postgres:
image: postgres
ports:
- 5432:5432
env:
POSTGRES_PASSWORD: postgres
mysql8: mysql8:
image: mysql:8.0 image: mysql:8.0
env: env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: test_db MYSQL_DATABASE: cakephp
ports: # services:
- 3306:3306 # 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
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Setup Service
if: matrix.db-type == 'mysql'
run: |
apt-get update && apt-get install -y lsb-release inetutils-tools
wget https://dev.mysql.com/get/mysql-apt-config_0.8.24-1_all.deb
DEBIAN_FRONTEND=noninteractive dpkg -i mysql-apt-config_0.8.24-1_all.deb
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B7B3B788A8D3785C
apt-get update
apt install -y default-mysql-client
mysql -h mysql8 -u root -e 'CREATE DATABASE cakephp;'
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v2
with: with:
php-version: ${{ matrix.php-version }} php-version: ${{ matrix.php-version }}
extensions: mbstring, intl, pdo_${{ matrix.db-type }} extensions: mbstring, intl, sqlite, pdo_${{ matrix.db-type }}
coverage: pcov coverage: pcov
- name: Get composer cache directory - name: Get composer cache directory
@@ -79,16 +75,16 @@ jobs:
if: matrix.db-type == 'mysql' if: matrix.db-type == 'mysql'
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Wait for MySQL
if: matrix.db-type == 'mysql'
run: while ! `mysqladmin ping -h 127.0.0.1 --silent`; do printf 'Waiting for MySQL...\n'; sleep 2; done;
- name: Run PHPUnit - name: Run PHPUnit tests
env:
TEST_MYSQL_HOST: mysql8
TEST_MYSQL_CHARSET: utf8mb4
TEST_MYSQL_DBNAME: cakephp
TEST_MYSQL_USERNAME: root
TEST_MYSQL_PASSWORD:
run: | run: |
if [[ ${{ matrix.db-type }} == 'sqlite' ]]; then export DB_URL='sqlite:///:memory:'; fi if [[ ${{ matrix.php-version }} == '8.2' ]]; then
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then export DB_URL='mysql://root:root@127.0.0.1/cakephp?encoding=utf8'; fi
if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export DB_URL='postgres://postgres:postgres@127.0.0.1/postgres'; fi
if [[ ${{ matrix.php-version }} == '8.1' ]]; then
vendor/bin/phpunit --coverage-clover=coverage.xml vendor/bin/phpunit --coverage-clover=coverage.xml
else else
vendor/bin/phpunit vendor/bin/phpunit
@@ -99,23 +95,21 @@ jobs:
run: vendor/bin/validate-prefer-lowest -m run: vendor/bin/validate-prefer-lowest -m
# - name: Upload coverage reports to Codecov # - name: Upload coverage reports to Codecov
# if: success() && matrix.php-version == '8.1' # if: success() && matrix.php-version == '8.2'
# uses: codecov/codecov-action@v4 # uses: codecov/codecov-action@v4
# with: # with:
# token: ${{ secrets.CODECOV_TOKEN }} # token: ${{ secrets.CODECOV_TOKEN }}
validation: validation:
name: Coding Standard & Static Analysis name: Coding Standard & Static Analysis
runs-on: ubuntu-22.04 runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v2
with: with:
php-version: '8.1' php-version: '8.1'
extensions: mbstring, intl extensions: mbstring, intl, sqlite
coverage: none coverage: none
- name: Get composer cache directory - name: Get composer cache directory
@@ -128,6 +122,17 @@ jobs:
path: ${{ steps.composercache.outputs.dir }} path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }} key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}
- name: Composer install
run: |
composer --version
if ${{ matrix.prefer-lowest == 'prefer-lowest' }}
then
composer update --prefer-lowest --prefer-stable
composer require --dev dereuromark/composer-prefer-lowest:dev-master
else
composer install --no-progress --prefer-dist --optimize-autoloader
fi
- name: Composer phpstan setup - name: Composer phpstan setup
run: composer stan-setup run: composer stan-setup

3
.gitignore vendored
View File

@@ -6,4 +6,5 @@
/config/Migrations/schema-dump-default.lock /config/Migrations/schema-dump-default.lock
/vendor/ /vendor/
/.idea/ /.idea/
tmp tmp
tests/test_app/webroot/images/products/

236
LICENSE
View File

@@ -1,235 +1,9 @@
GNU AFFERO GENERAL PUBLIC LICENSE MIT License
Version 3, 19 November 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> Copyright (c) 2025 HI POWERED DEV, LLC
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Preamble The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users.
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
Developers that use our General Public Licenses protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you legal permission to copy, distribute and/or modify the software.
A secondary benefit of defending all users' freedom is that improvements made in alternate versions of the program, if they receive widespread use, become available for other developers to incorporate. Many developers of free software are heartened and encouraged by the resulting cooperation. However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License permits making a modified version and letting the public access it on a server without ever releasing its source code to the public.
The GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified source code becomes available to the community. It requires the operator of a network server to provide the source code of the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source code of the modified version.
An older license, called the Affero General Public License and published by Affero, was designed to accomplish similar goals. This is a different license, not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this license.
The precise terms and conditions for copying, distribution and modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU Affero General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based on the Program.
To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work.
A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
The Corresponding Source for a work in source code form is that same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices".
c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
"Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
13. Remote Network Interaction; Use with the GNU General Public License.
Notwithstanding any other provision of this License, if you modify the Program, your modified version must prominently offer all users interacting with it remotely through a computer network (if your version supports such interaction) an opportunity to receive the Corresponding Source of your version by providing access to the Corresponding Source from a network server at no charge, through some standard or customary means of facilitating copying of software. This Corresponding Source shall include the Corresponding Source for any work covered by version 3 of the GNU General Public License that is incorporated pursuant to the following paragraph.
Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the work with which it is combined will remain governed by version 3 of the GNU General Public License.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of the GNU Affero General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU Affero General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU Affero General Public License, you may choose any version ever published by the Free Software Foundation.
If the Program specifies that a proxy can decide which future versions of the GNU Affero General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
CakeProducts
Copyright (C) 2024 HiPoweredDev
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If your software can interact with users remotely through a computer network, you should also make sure that it provides a way for users to get its source. For example, if your program is a web application, its interface could display a "Source" link that leads users to an archive of the code. There are many ways you could offer source, and different solutions will be better for different programs; see section 13 for the specific requirements.
You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see <http://www.gnu.org/licenses/>.

View File

@@ -4,12 +4,24 @@
You can install this plugin into your CakePHP application using [composer](https://getcomposer.org). You can install this plugin into your CakePHP application using [composer](https://getcomposer.org).
The recommended way to install composer packages is: The recommended way to install is:
``` ```
composer require hi-powered-dev/cake-products composer require hi-powered-dev/cake-products
``` ```
Be sure to run the DB migrations:
```
bin/cake migrations migrate -p CakeProducts
```
And the DB seed(s):
```
bin/cake migrations seed -p CakeProducts
```
You can either load the plugin with routes enabled to use default controller actions, or just use/extend the database structure and use your own controllers
## Database Structure ## Database Structure
Products belong to ProductCategories, ProductCategories is hierarchical and belongs to ProductCatalogs. Products belong to ProductCategories, ProductCategories is hierarchical and belongs to ProductCatalogs.
@@ -18,4 +30,21 @@ ProductCategoryAttributes belongs to ProductCategories and attributes are inheri
ProductCategoryAttributes can have many ProductCategoryAttributeOptions (constrained attributes) ProductCategoryAttributes can have many ProductCategoryAttributeOptions (constrained attributes)
You can either load the plugin with routes enabled to use default controller actions, or just use/extend the database structure and use your own controllers ProductCategoryVariants are templates/common starting points for variants - when adding a new product in that category it is easy to toggle on that category variant so the product uses the variant
ProductCategoryVariantOptions are the various options for each category variant
ProductVariants are the assigning of category variants to a product. A product can have as many variants as it's category has category variants. A variant must exist at the category level in order to be assigned to a product.
Products can have many ProductSkus. A ProductSku is a specific combination of variant options - using a T-Shirt with a size and a color variant for example,
the ProductSku would be a Red XL T-Shirt. Not all variant combinations need be used.
ProductSkuVariantValues is where the variant values of each SKU are stored.
## Suggested Plugins
Use the CakeCarts plugin to quickly enable shopping cart functionality with your products [CakeCarts](https://packagist.org/packages/hi-powered-dev/cake-carts)
```
composer require hi-powered-dev/cake-carts
```

View File

@@ -2,17 +2,21 @@
"name": "hi-powered-dev/cake-products", "name": "hi-powered-dev/cake-products",
"description": "A CakePHP plugin for managing product catalog(s)", "description": "A CakePHP plugin for managing product catalog(s)",
"type": "cakephp-plugin", "type": "cakephp-plugin",
"license": "AGPL-3.0-or-later", "license": "MIT",
"minimum-stability": "dev", "minimum-stability": "dev",
"require": { "require": {
"php": ">=8.1", "php": ">=8.2",
"dereuromark/cakephp-tools": "^3.9", "dereuromark/cakephp-tools": "^3.9",
"hi-powered-dev/cheese-cake": "dev-prod", "muffin/trash": "^4.2",
"cakephp/migrations": "^4.0.0", "cakephp/cakephp": "^5.0.1",
"cakephp/cakephp": "^5.0.1" "bentools/cartesian-product": "dev-master"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^10.1" "phpunit/phpunit": "^10.1",
"cakephp/migrations": "^4.0.0"
},
"suggest": {
"hi-powered-dev/cake-carts": "Allow users to add products/SKUs to a cart"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

View File

@@ -35,13 +35,13 @@ class CreateProducts extends AbstractMigration
]); ]);
$table->addIndex('product_category_id'); $table->addIndex('product_category_id');
$table->addIndex('product_type_id'); $table->addIndex('product_type_id');
$table->addIndex([ // $table->addIndex([
'product_category_id', // 'product_category_id',
'name', // 'name',
], [ // ], [
'name' => 'BY_NAME_AND_CATEGORY_ID', // 'name' => 'BY_NAME_AND_CATEGORY_ID',
'unique' => true, // 'unique' => true,
]); // ]);
$table->create(); $table->create();
} }
} }

View File

@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
use Migrations\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();
}
}

View File

@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
use Migrations\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();
$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_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('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();
}
}

View File

@@ -0,0 +1,62 @@
<?php
declare(strict_types=1);
use Migrations\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();
}
}

View File

@@ -0,0 +1,61 @@
<?php
declare(strict_types=1);
use Migrations\AbstractMigration;
class CreateProductCategoryVariants extends AbstractMigration
{
/**
* Change Method.
*
* More information on this method is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
* @return void
*/
public function change(): void
{
$table = $this->table('product_category_variants', ['id' => false, 'primary_key' => ['id']]);
$table->addColumn('id', 'uuid', [
'default' => null,
'null' => false,
]);
$table->addColumn('name', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('product_category_id', 'uuid', [
'default' => null,
'null' => true,
]);
$table->addColumn('product_id', 'uuid', [
'default' => null,
'null' => true,
]);
$table->addColumn('enabled', 'boolean', [
'default' => null,
'null' => false,
]);
$table->addIndex([
'product_category_id',
], [
'name' => 'VARIANTS_BY_PRODUCT_CATEGORY_ID',
'unique' => false,
]);
$table->addIndex([
'product_id',
], [
'name' => 'CATEGORY_VARIANTS_BY_PRODUCT_ID',
'unique' => false,
]);
// $table->addIndex([
// 'name',
// 'product_category_id',
// 'product_id',
// ], [
// 'name' => 'VARIANTS_BY_NAME_AND_PRODUCT_CATEGORY_ID_AND_PRODUCT_ID_UNIQUE',
// 'unique' => true,
// ]);
$table->create();
}
}

View File

@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
use Migrations\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,
]);
// $table->addForeignKey('product_category_variant_id', 'product_category_variants'); // @TODO why cant this be included??? breaks tests on tearDown
$table->create();
}
}

View File

@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
use Migrations\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();
}
}

View File

@@ -0,0 +1,87 @@
<?php
declare(strict_types=1);
use Migrations\BaseMigration;
class CreateProductPhotos 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', ['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('primary_photo', 'boolean', [
'default' => false,
'null' => false,
]);
$table->addColumn('photo_position', 'integer', [
'default' => 100,
'limit' => 11,
'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->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();
}
}

View File

@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
use Migrations\BaseMigration;
class CreateProductSkuVariantValues 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_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();
}
}

View File

@@ -0,0 +1,62 @@
<?php
declare(strict_types=1);
use Migrations\BaseMigration;
class CreateProductVariants 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_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',
// 'product_category_id',
// ], [
// 'name' => 'VARIANTS_BY_NAME_AND_PRODUCT_CATEGORY_ID_UNIQUE',
// 'unique' => true,
// ]);
$table->create();
}
}

View File

@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
use Migrations\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();
}
}

View File

@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
use Migrations\BaseMigration;
class AddProductCategoryIdToProductPhotos 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('product_category_id', 'uuid', [
'default' => null,
'null' => true,
]);
$table->addColumn('primary_category_photo', 'boolean', [
'default' => false,
'null' => false,
]);
$table->update();
}
}

View File

@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
use Migrations\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();
}
}

View File

@@ -0,0 +1,53 @@
<?php
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();
}
/**
* 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();
}
}

View File

@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
use Migrations\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();
}
}

View File

@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
namespace Seeds;
use Migrations\BaseSeed;
/**
* CreateSystemCategoryVariants seed.
*/
class CreateSystemCategoryVariantsSeed extends BaseSeed
{
/**
* Run Method.
*
* Write your database seeder using this method.
*
* More information on writing seeds is available here:
* https://book.cakephp.org/migrations/4/en/seeding.html
*
* @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();
}
}
}

View File

@@ -4,6 +4,9 @@
return [ return [
'CakeProducts' => [ 'CakeProducts' => [
'photos' => [
'directory' => WWW_ROOT . 'images' . DS . 'products' . DS,
],
/** /**
* internal CakeProducts settings - used in the source of truth/internal only system. * internal CakeProducts settings - used in the source of truth/internal only system.
* Can optionally manage external catalogs * Can optionally manage external catalogs

View File

@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace CakeProducts\Controller; namespace CakeProducts\Controller;
use App\Controller\AppController as BaseController; use App\Controller\AppController as BaseController;
use Cake\Log\Log;
class AppController extends BaseController class AppController extends BaseController
{ {

View File

@@ -7,8 +7,6 @@ use Cake\Core\Configure;
use Cake\Log\Log; use Cake\Log\Log;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\ORM\TableRegistry; use Cake\ORM\TableRegistry;
use CakeProducts\Controller\AppController;
use CheeseCake\Controller\Traits\OverrideTableTrait;
/** /**
* ExternalProductCatalogs Controller * ExternalProductCatalogs Controller
@@ -17,7 +15,7 @@ use CheeseCake\Controller\Traits\OverrideTableTrait;
*/ */
class ExternalProductCatalogsController extends AppController class ExternalProductCatalogsController extends AppController
{ {
use OverrideTableTrait; // use OverrideTableTrait;
/** /**
* @return void * @return void

View File

@@ -6,7 +6,6 @@ namespace CakeProducts\Controller;
use Cake\Datasource\Exception\RecordNotFoundException; use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Http\Response; use Cake\Http\Response;
use Cake\Log\Log; use Cake\Log\Log;
use CakeProducts\Controller\AppController;
/** /**
* ExternalProductCatalogsProductCatalogs Controller * ExternalProductCatalogsProductCatalogs Controller

View File

@@ -9,9 +9,6 @@ use Cake\Http\Response;
use Cake\Log\Log; use Cake\Log\Log;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\ORM\TableRegistry; use Cake\ORM\TableRegistry;
use CakeProducts\Controller\AppController;
use CheeseCake\Controller\Traits\OverrideTableTrait;
;
use CakeProducts\Model\Table\ProductCatalogsTable; use CakeProducts\Model\Table\ProductCatalogsTable;
/** /**
@@ -21,8 +18,6 @@ use CakeProducts\Model\Table\ProductCatalogsTable;
*/ */
class ProductCatalogsController extends AppController class ProductCatalogsController extends AppController
{ {
use OverrideTableTrait;
/** /**
* @return void * @return void
*/ */
@@ -40,7 +35,7 @@ class ProductCatalogsController extends AppController
*/ */
public function index() public function index()
{ {
$query = $this->getTable()->find(); $query = $this->ProductCatalogs->find();
$productCatalogs = $this->paginate($query); $productCatalogs = $this->paginate($query);
$this->set(compact('productCatalogs')); $this->set(compact('productCatalogs'));
@@ -59,7 +54,7 @@ class ProductCatalogsController extends AppController
if (Configure::read('CakeProducts.internal.syncExternally', false)) { if (Configure::read('CakeProducts.internal.syncExternally', false)) {
$contain[] = 'ExternalProductCatalogs'; $contain[] = 'ExternalProductCatalogs';
} }
$productCatalog = $this->getTable()->get($id, contain: $contain); $productCatalog = $this->ProductCatalogs->get($id, contain: $contain);
$this->set(compact('productCatalog')); $this->set(compact('productCatalog'));
} }
@@ -70,7 +65,7 @@ class ProductCatalogsController extends AppController
*/ */
public function add() public function add()
{ {
$productCatalogsTable = $this->getTable(); $productCatalogsTable = $this->ProductCatalogs;
$productCatalog = $productCatalogsTable->newEmptyEntity(); $productCatalog = $productCatalogsTable->newEmptyEntity();
if ($this->request->is('post')) { if ($this->request->is('post')) {
$productCatalog = $productCatalogsTable->patchEntity($productCatalog, $this->request->getData()); $productCatalog = $productCatalogsTable->patchEntity($productCatalog, $this->request->getData());
@@ -97,7 +92,7 @@ class ProductCatalogsController extends AppController
*/ */
public function edit($id = null) public function edit($id = null)
{ {
$productCatalogsTable = $this->getTable(); $productCatalogsTable = $this->ProductCatalogs;
$productCatalog = $productCatalogsTable->get($id, contain: []); $productCatalog = $productCatalogsTable->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) { if ($this->request->is(['patch', 'post', 'put'])) {
$productCatalog = $productCatalogsTable->patchEntity($productCatalog, $this->request->getData()); $productCatalog = $productCatalogsTable->patchEntity($productCatalog, $this->request->getData());
@@ -121,7 +116,7 @@ class ProductCatalogsController extends AppController
public function delete($id = null) public function delete($id = null)
{ {
$this->request->allowMethod(['post', 'delete']); $this->request->allowMethod(['post', 'delete']);
$productCatalogsTable = $this->getTable(); $productCatalogsTable = $this->ProductCatalogs;
$productCatalog = $productCatalogsTable->get($id); $productCatalog = $productCatalogsTable->get($id);
if ($productCatalogsTable->delete($productCatalog)) { if ($productCatalogsTable->delete($productCatalog)) {
$this->Flash->success(__('The product catalog has been deleted.')); $this->Flash->success(__('The product catalog has been deleted.'));
@@ -131,21 +126,4 @@ class ProductCatalogsController extends AppController
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
} }
/**
* Gets the users table instance
*
* @return Table
*/
public function getTable()
{
if ($this->_table instanceof Table) {
return $this->_table;
}
$this->_table = TableRegistry::getTableLocator()->get(
Configure::read('CakeProducts.ProductCatalogs.table', 'CakeProducts.ProductCatalogs')
);
return $this->_table;
}
} }

View File

@@ -8,8 +8,6 @@ use Cake\Log\Log;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\ORM\TableRegistry; use Cake\ORM\TableRegistry;
use Cake\Utility\Text; use Cake\Utility\Text;
use CheeseCake\Controller\Traits\OverrideTableTrait;
;
/** /**
* ProductCategories Controller * ProductCategories Controller
@@ -18,8 +16,6 @@ use CheeseCake\Controller\Traits\OverrideTableTrait;
*/ */
class ProductCategoriesController extends AppController class ProductCategoriesController extends AppController
{ {
use OverrideTableTrait;
/** /**
* @return void * @return void
*/ */
@@ -37,7 +33,7 @@ class ProductCategoriesController extends AppController
*/ */
public function index() public function index()
{ {
$query = $this->getTable()->find() $query = $this->ProductCategories->find()
->contain(['ProductCatalogs', 'ParentProductCategories']); ->contain(['ProductCatalogs', 'ParentProductCategories']);
$productCategories = $this->paginate($query); $productCategories = $this->paginate($query);
@@ -53,15 +49,16 @@ class ProductCategoriesController extends AppController
*/ */
public function view($id = null) public function view($id = null)
{ {
$productCategory = $this->getTable()->get($id, contain: [ $productCategory = $this->ProductCategories->get($id, contain: [
'ProductCatalogs', 'ProductCatalogs',
'ParentProductCategories', 'ParentProductCategories',
'ChildProductCategories', 'ChildProductCategories',
'ProductCategoryAttributes', 'ProductCategoryAttributes',
'ProductCategoryAttributes.ProductCategoryAttributeOptions', 'ProductCategoryAttributes.ProductCategoryAttributeOptions',
'PrimaryProductPhotos',
]); ]);
$productCategoryAttributes = $this->getTable()->ProductCategoryAttributes->getAllCategoryAttributesForCategoryId($productCategory->internal_id); $productCategoryAttributes = $this->ProductCategories->ProductCategoryAttributes->getAllCategoryAttributesForCategoryId($productCategory->internal_id);
$this->set(compact('productCategory', 'productCategoryAttributes')); $this->set(compact('productCategory', 'productCategoryAttributes'));
} }
@@ -72,7 +69,7 @@ class ProductCategoriesController extends AppController
*/ */
public function add() public function add()
{ {
$productCategoriesTable = $this->getTable(); $productCategoriesTable = $this->ProductCategories;
$productCategory = $productCategoriesTable->newEmptyEntity(); $productCategory = $productCategoriesTable->newEmptyEntity();
if ($this->request->is('post')) { if ($this->request->is('post')) {
$postData = $this->request->getData(); $postData = $this->request->getData();
@@ -111,7 +108,7 @@ class ProductCategoriesController extends AppController
*/ */
public function edit($id = null) public function edit($id = null)
{ {
$productCategoriesTable = $this->getTable(); $productCategoriesTable = $this->ProductCategories;
$productCategory = $productCategoriesTable->get($id, contain: []); $productCategory = $productCategoriesTable->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) { if ($this->request->is(['patch', 'post', 'put'])) {
$postData = $this->request->getData(); $postData = $this->request->getData();
@@ -138,9 +135,14 @@ class ProductCategoriesController extends AppController
public function delete($id = null) public function delete($id = null)
{ {
$this->request->allowMethod(['post', 'delete']); $this->request->allowMethod(['post', 'delete']);
$productCategoriesTable = $this->getTable(); $productCategoriesTable = $this->ProductCategories;
$productCategory = $productCategoriesTable->get($id); $productCategory = $productCategoriesTable->get($id);
// $productCategoriesTable->behaviors()->get('Tree')->setConfig([
// 'scope' => [
// 'product_catalog_id' => $productCategory->product_catalog_id,
// ],
// ]);
if ($productCategoriesTable->delete($productCategory)) { if ($productCategoriesTable->delete($productCategory)) {
$this->Flash->success(__('The product category has been deleted.')); $this->Flash->success(__('The product category has been deleted.'));
} else { } else {
@@ -155,15 +157,17 @@ class ProductCategoriesController extends AppController
*/ */
public function select() public function select()
{ {
$productCategoriesTable = $this->getTable(); $productCategoriesTable = $this->ProductCategories;
$productCategoriesTable->behaviors()->get('Tree')->setConfig([ $productCategoriesTable->behaviors()->get('Tree')->setConfig([
'scope' => [ 'scope' => [
'product_catalog_id' => $this->request->getQuery('product_catalog_id', -1), 'product_catalog_id' => $this->request->getQuery('product_catalog_id', -1),
], ],
]); ]);
$productCategories = $productCategoriesTable $productCategoriesQ = $this->request->getQuery('form', 'product_category') === 'product' ?
->find('treeList') $productCategoriesTable->find('treeList', keyPath: 'internal_id', valuePath: 'name') :
// ->where(['product_catalog_id' => $this->request->getQuery('product_catalog_id', -1)]) $productCategoriesTable->find('treeList');
$productCategories = $productCategoriesQ
->orderBy(['ProductCategories.name']) ->orderBy(['ProductCategories.name'])
->toArray(); ->toArray();

View File

@@ -7,9 +7,6 @@ use Cake\Core\Configure;
use Cake\Log\Log; use Cake\Log\Log;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\ORM\TableRegistry; use Cake\ORM\TableRegistry;
use CakeProducts\Controller\AppController;
use CheeseCake\Controller\Traits\OverrideTableTrait;
;
/** /**
* ProductCategoryAttributeOptions Controller * ProductCategoryAttributeOptions Controller
@@ -18,8 +15,6 @@ use CheeseCake\Controller\Traits\OverrideTableTrait;
*/ */
class ProductCategoryAttributeOptionsController extends AppController class ProductCategoryAttributeOptionsController extends AppController
{ {
use OverrideTableTrait;
/** /**
* @return void * @return void
*/ */
@@ -39,7 +34,7 @@ class ProductCategoryAttributeOptionsController extends AppController
{ {
Log::debug('inside product category attribute options controller add'); Log::debug('inside product category attribute options controller add');
$productCategoryAttributeOption = $this->getTable()->newEmptyEntity(); $productCategoryAttributeOption = $this->ProductCategoryAttributeOptions->newEmptyEntity();
$this->set(compact('productCategoryAttributeOption')); $this->set(compact('productCategoryAttributeOption'));
} }
@@ -53,7 +48,7 @@ class ProductCategoryAttributeOptionsController extends AppController
public function delete($id = null) public function delete($id = null)
{ {
$this->request->allowMethod(['post', 'delete']); $this->request->allowMethod(['post', 'delete']);
$productCategoryAttributeOptionsTable = $this->getTable(); $productCategoryAttributeOptionsTable = $this->ProductCategoryAttributeOptions;
$productCategoryAttributeOption = $productCategoryAttributeOptionsTable->get($id); $productCategoryAttributeOption = $productCategoryAttributeOptionsTable->get($id);
if ($productCategoryAttributeOptionsTable->delete($productCategoryAttributeOption)) { if ($productCategoryAttributeOptionsTable->delete($productCategoryAttributeOption)) {

View File

@@ -9,9 +9,6 @@ use Cake\Http\Response;
use Cake\Log\Log; use Cake\Log\Log;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\ORM\TableRegistry; use Cake\ORM\TableRegistry;
use CakeProducts\Controller\AppController;
use CheeseCake\Controller\Traits\OverrideTableTrait;
;
use CakeProducts\Model\Enum\ProductCategoryAttributeTypeId; use CakeProducts\Model\Enum\ProductCategoryAttributeTypeId;
use CakeProducts\Model\Table\ProductCategoryAttributesTable; use CakeProducts\Model\Table\ProductCategoryAttributesTable;
@@ -22,8 +19,6 @@ use CakeProducts\Model\Table\ProductCategoryAttributesTable;
*/ */
class ProductCategoryAttributesController extends AppController class ProductCategoryAttributesController extends AppController
{ {
use OverrideTableTrait;
/** /**
* @return void * @return void
*/ */
@@ -41,7 +36,7 @@ class ProductCategoryAttributesController extends AppController
*/ */
public function index() public function index()
{ {
$query = $this->getTable()->find() $query = $this->ProductCategoryAttributes->find()
->contain(['ProductCategories']); ->contain(['ProductCategories']);
$productCategoryAttributes = $this->paginate($query); $productCategoryAttributes = $this->paginate($query);
@@ -57,7 +52,7 @@ class ProductCategoryAttributesController extends AppController
*/ */
public function view($id = null) public function view($id = null)
{ {
$productCategoryAttribute = $this->getTable()->get($id, contain: [ $productCategoryAttribute = $this->ProductCategoryAttributes->get($id, contain: [
'ProductCategories', 'ProductCategories',
'ProductCategoryAttributeOptions', 'ProductCategoryAttributeOptions',
]); ]);
@@ -72,7 +67,7 @@ class ProductCategoryAttributesController extends AppController
*/ */
public function add() public function add()
{ {
$productCategoryAttributesTable = $this->getTable(); $productCategoryAttributesTable = $this->ProductCategoryAttributes;
$productCategoryAttribute = $productCategoryAttributesTable->newEmptyEntity(); $productCategoryAttribute = $productCategoryAttributesTable->newEmptyEntity();
if ($this->request->is('post')) { if ($this->request->is('post')) {
$postData = $this->request->getData(); $postData = $this->request->getData();
@@ -114,7 +109,7 @@ class ProductCategoryAttributesController extends AppController
*/ */
public function edit($id = null) public function edit($id = null)
{ {
$productCategoryAttributesTable = $this->getTable(); $productCategoryAttributesTable = $this->ProductCategoryAttributes;
$productCategoryAttribute = $productCategoryAttributesTable->get($id, contain: ['ProductCategoryAttributeOptions']); $productCategoryAttribute = $productCategoryAttributesTable->get($id, contain: ['ProductCategoryAttributeOptions']);
if ($this->request->is(['patch', 'post', 'put'])) { if ($this->request->is(['patch', 'post', 'put'])) {
$postData = $this->request->getData(); $postData = $this->request->getData();
@@ -156,7 +151,7 @@ class ProductCategoryAttributesController extends AppController
{ {
$this->request->allowMethod(['post', 'delete']); $this->request->allowMethod(['post', 'delete']);
$productCategoryAttributesTable = $this->getTable(); $productCategoryAttributesTable = $this->ProductCategoryAttributes;
$productCategoryAttribute = $productCategoryAttributesTable->get($id); $productCategoryAttribute = $productCategoryAttributesTable->get($id);
if ($productCategoryAttributesTable->delete($productCategoryAttribute)) { if ($productCategoryAttributesTable->delete($productCategoryAttribute)) {
$this->Flash->success(__('The product category attribute has been deleted.')); $this->Flash->success(__('The product category attribute has been deleted.'));
@@ -167,10 +162,13 @@ class ProductCategoryAttributesController extends AppController
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
} }
public function form($categoryId = null) /**
* @return void
*/
public function form()
{ {
$productCategoryAttributes = $this->getTable()->getAllCategoryAttributesForCategoryId($categoryId); $productCategories = $this->ProductCategoryAttributes->getAllCategoryAttributesForCategoryId($this->request->getQuery('product_category_id', '-1'));
$this->set(compact('productCategoryAttributes')); $this->set(compact('productCategories'));
} }
} }

View File

@@ -0,0 +1,160 @@
<?php
declare(strict_types=1);
namespace CakeProducts\Controller;
use Cake\Core\Configure;
use Cake\Log\Log;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
/**
* ProductCategoryVariants Controller
*
* @property \App\Model\Table\ProductCategoryVariantsTable $ProductCategoryVariants
*/
class ProductCategoryVariantsController extends AppController
{
/**
* @return void
*/
public function initialize(): void
{
parent::initialize(); // TODO: Change the autogenerated stub
// $this->_defaultTable = 'CakeProducts.ProductCategoryVariants';
// $this->_tableConfigKey = 'CakeProducts.ProductCategoryVariants.table';
}
/**
* Index method
*
* @return \Cake\Http\Response|null|void Renders view
*/
public function index()
{
$query = $this->ProductCategoryVariants->find()
->contain(['ProductCategories', 'Products', 'ProductCategoryVariantOptions']);
$productCategoryVariants = $this->paginate($query);
$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.
*/
public function view($id = null)
{
$productCategoryVariant = $this->ProductCategoryVariants->get($id, contain: [
'ProductCategories',
'Products',
'ProductCategoryVariantOptions',
]);
$this->set(compact('productCategoryVariant'));
}
/**
* Add method
*
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
*/
public function add()
{
$productCategoryVariantsTable = $this->ProductCategoryVariants;
$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'));
}
/**
* 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.
*/
public function edit($id = null)
{
$productCategoryVariantsTable = $this->ProductCategoryVariants;
$productCategoryVariant = $productCategoryVariantsTable->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) {
$postData = $this->request->getData();
// if ($this->request->getSession()->read('Auth.User.id')) {
// $postData['created_by'] = $this->request->getSession()->read('Auth.User.id');
// }
$postData = $productCategoryVariant->is_system_variant ? ['product_category_variant_options' => $this->request->getData('product_category_variant_options')] : $postData;
$saveOptions = [
'fields' => $productCategoryVariant->is_system_variant ? [
'product_category_variant_options',
] : [
'name',
'product_category_id',
'enabled',
'product_category_variant_options',
],
'associated' => [
'ProductCategoryVariantOptions'
],
];
$productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $postData, $saveOptions);
// dd($postData);
if ($productCategoryVariantsTable->save($productCategoryVariant, $saveOptions)) {
$this->Flash->success(__('The product category variant has been saved.'));
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'));
}
/**
* 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.
*/
public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$productCategoryVariantsTable = $this->ProductCategoryVariants;
$productCategoryVariant = $productCategoryVariantsTable->get($id);
if ($productCategoryVariantsTable->delete($productCategoryVariant)) {
$this->Flash->success(__('The product category variant has been deleted.'));
} else {
$this->Flash->error(__('The product category variant could not be deleted. Please, try again.'));
}
return $this->redirect(['action' => 'index']);
}
}

View File

@@ -0,0 +1,214 @@
<?php
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
*/
class ProductPhotosController extends AppController
{
/**
* Index method
*
* @return Response|null|void Renders view
*/
public function index()
{
$query = $this->ProductPhotos->find()
->contain(['Products', 'ProductSkus', 'ProductCategories']);
$productPhotos = $this->paginate($query);
$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.
*/
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.
*/
public function add()
{
$productPhotosTable = $this->ProductPhotos;
$productPhoto = $productPhotosTable->newEmptyEntity();
if ($this->request->is('post')) {
if (!$this->request->getData('photo')) {
$this->Flash->error('Photo is required. Nothing was uploaded. Please try again.');
$productCategory = $productPhoto->product_category_id ? $productPhotosTable->ProductCategories->find()->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null;
$productCatalogs = $productPhotosTable->ProductCategories->ProductCatalogs->find('list')->toArray();
$this->set(compact('productPhoto', 'productCatalogs', 'productCategory'));
return;
}
$uuid = Text::uuid();
$postData = $this->request->getData();
$postData['id'] = $uuid;
$baseDir = Configure::readOrFail('CakeProducts.photos.directory');
$path = '';
if ($this->request->getData('product_sku_id')) {
$productSku = $productPhotosTable->ProductSkus
->find()
->contain(['Products', 'Products.ProductCategories'])
->where([
'ProductSkus.id' => $this->request->getData('product_sku_id'),
])
->first();
$path = $productSku ? $productSku->product_id . DS . 'skus' . DS . $productSku->id : $path;
$postData['product_id'] = $productSku->product->id ?? null;
$postData['product_category_id'] = $productSku->product->product_category->internal_id ?? null;
} else if ($this->request->getData('product_id')) {
$product = $productPhotosTable->Products
->find()
->contain(['ProductCategories'])
->where([
'Products.id' => $this->request->getData('product_id'),
])
->first();
$path = $product ? $product->id : $path;
$postData['product_category_id'] = $product->product_category->internal_id ?? null;
} else if ($this->request->getData('product_category_id')) {
$categoryId = $this->request->getData('product_category_id');
// @link https://developer.wordpress.org/reference/functions/wp_is_uuid/
$regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/';
$field = preg_match($regex, $categoryId) ? 'ProductCategories.internal_id' : 'ProductCategories.id';
$productCategoryPosted = $productPhotosTable->ProductCategories
->find()
->where([
$field => $categoryId,
])
->first();
$postData['product_category_id'] = $productCategoryPosted->internal_id ?? null;
$path = $productCategoryPosted ? 'categories' : $path;
}
/**
* @var UploadedFileInterface $photoObject
*/
$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;
// 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;
// dd($postData);
$productPhoto = $productPhotosTable->patchEntity($productPhoto, $postData);
if ($productPhotosTable->save($productPhoto)) {
$this->Flash->success(__('The product photo has been saved.'));
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'));
}
/**
* 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.
*/
public function edit($id = null)
{
$productPhotosTable = $this->ProductPhotos;
$productPhoto = $productPhotosTable->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) {
$postData = $this->request->getData();
$productPhoto = $productPhotosTable->patchEntity($productPhoto, $postData);
if ($productPhotosTable->save($productPhoto)) {
$this->Flash->success(__('The product photo has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The product photo could not be saved. Please, try again.'));
}
$products = $productPhotosTable->Products->find('list', limit: 200)->all();
$productSkus = $productPhotosTable->ProductSkus->find('list', limit: 200)->all();
$this->set(compact('productPhoto', 'products', 'productSkus'));
}
/**
* Delete method
*
* @param string|null $id Product Photo id.
* @return Response|null Redirects to index.
* @throws RecordNotFoundException When record not found.
*/
public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$productPhotosTable = $this->ProductPhotos;
$productPhoto = $productPhotosTable->get($id);
if ($productPhotosTable->delete($productPhoto)) {
$this->Flash->success(__('The product photo has been deleted.'));
} else {
$this->Flash->error(__('The product photo could not be deleted. Please, try again.'));
}
return $this->redirect(['action' => 'index']);
}
/**
* @param $id
* @return Response
*/
public function image($id = null)
{
$productPhoto = $this->ProductPhotos->get($id);
$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'
]);
}
}

View File

@@ -0,0 +1,251 @@
<?php
declare(strict_types=1);
namespace CakeProducts\Controller;
use Cake\Log\Log;
use Cake\Utility\Hash;
use function BenTools\CartesianProduct\combinations;
/**
* ProductSkus Controller
*
* @property \CakeProducts\Model\Table\ProductSkusTable $ProductSkus
*/
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';
}
/**
* Index method
*
* @return \Cake\Http\Response|null|void Renders view
*/
public function index()
{
$query = $this->ProductSkus->find()
->contain(['Products']);
$productSkus = $this->paginate($query);
$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.
*/
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 : [];
// dd($productVariants);
$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');
// dd($optionMapping);
$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;
}
// 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'
));
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]);
continue;
}
$finalPostData[$postedSkuCnt] = $postedSku;
}
if (!$productSkus || !$postedSkus) {
$this->Flash->error('Nothing to save! Add at least one SKU next time.');
return;
}
// dd($finalPostData);
$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 ($successes) {
$this->Flash->success(__(count($successes) . ' New SKUs have been saved.'));
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.
*/
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.'));
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.
*/
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 \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();
$this->set(compact('productSkus'));
}
}

View File

@@ -0,0 +1,118 @@
<?php
declare(strict_types=1);
namespace CakeProducts\Controller;
use Cake\Log\Log;
/**
* ProductVariants Controller
*
* @property \App\Model\Table\ProductVariantsTable $ProductVariants
*/
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);
$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.
*/
public function view($id = null)
{
$productVariant = $this->ProductVariants->get($id, contain: ['ProductCategoryVariants', 'Products']);
$this->set(compact('productVariant'));
}
/**
* Add method
*
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
*/
public function add($productId)
{
$product = $this->ProductVariants->Products->get($productId);
$productVariant = $this->ProductVariants->newEmptyEntity();
if ($this->request->is('post')) {
$saveOptions = [];
$postData = $this->request->getData();
$productCategoryVariant = $this->ProductVariants->ProductCategoryVariants->get($this->request->getData('product_category_variant_id', '-1'));
$postData['name'] = $productCategoryVariant->name;
$postData['product_id'] = $productId;
$productVariant = $this->ProductVariants->patchEntity($productVariant, $postData);
if ($this->ProductVariants->save($productVariant)) {
$this->Flash->success(__('The product variant has been saved.'));
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'));
}
/**
* 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.
*/
public function edit($id = null)
{
$productVariant = $this->ProductVariants->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) {
$productVariant = $this->ProductVariants->patchEntity($productVariant, $this->request->getData());
if ($this->ProductVariants->save($productVariant)) {
$this->Flash->success(__('The product variant has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The product variant could not be saved. Please, try again.'));
}
$productCategoryVariants = $this->ProductVariants->ProductCategoryVariants->find('list', limit: 200)->all();
$products = $this->ProductVariants->Products->find('list', limit: 200)->all();
$this->set(compact('productVariant', 'productCategoryVariants', 'products'));
}
/**
* 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.
*/
public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$productVariant = $this->ProductVariants->get($id);
if ($this->ProductVariants->delete($productVariant)) {
$this->Flash->success(__('The product variant has been deleted.'));
} else {
$this->Flash->error(__('The product variant could not be deleted. Please, try again.'));
}
return $this->redirect(['action' => 'index']);
}
}

View File

@@ -7,9 +7,6 @@ use Cake\Core\Configure;
use Cake\Log\Log; use Cake\Log\Log;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\ORM\TableRegistry; use Cake\ORM\TableRegistry;
use CakeProducts\Controller\AppController;
use CheeseCake\Controller\Traits\OverrideTableTrait;
;
/** /**
* Products Controller * Products Controller
@@ -18,8 +15,6 @@ use CheeseCake\Controller\Traits\OverrideTableTrait;
*/ */
class ProductsController extends AppController class ProductsController extends AppController
{ {
use OverrideTableTrait;
/** /**
* @return void * @return void
*/ */
@@ -37,7 +32,7 @@ class ProductsController extends AppController
*/ */
public function index() public function index()
{ {
$query = $this->getTable()->find() $query = $this->Products->find()
->contain(['ProductCategories']); ->contain(['ProductCategories']);
$products = $this->paginate($query); $products = $this->paginate($query);
@@ -53,7 +48,17 @@ class ProductsController extends AppController
*/ */
public function view($id = null) public function view($id = null)
{ {
$product = $this->getTable()->get($id, contain: ['ProductCategories']); $product = $this->Products->get($id, contain: [
'ProductCategories',
'ProductAttributes',
'ProductAttributes.ProductCategoryAttributes',
'ProductAttributes.ProductCategoryAttributeOptions',
'ProductVariants',
'ProductVariants.ProductCategoryVariants',
'ProductVariants.ProductCategoryVariants.ProductCategoryVariantOptions',
'ProductSkus',
'ProductPhotos',
]);
$this->set(compact('product')); $this->set(compact('product'));
} }
@@ -64,11 +69,61 @@ class ProductsController extends AppController
*/ */
public function add() public function add()
{ {
$productsTable = $this->getTable(); $productsTable = $this->Products;
$product = $productsTable->newEmptyEntity(); $product = $productsTable->newEmptyEntity();
if ($this->request->is('post')) { if ($this->request->is('post')) {
$product = $productsTable->patchEntity($product, $this->request->getData()); $postData = $this->request->getData();
if ($productsTable->save($product)) { $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.')); $this->Flash->success(__('The product has been saved.'));
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
@@ -91,10 +146,17 @@ class ProductsController extends AppController
*/ */
public function edit($id = null) public function edit($id = null)
{ {
$productsTable = $this->getTable(); $productsTable = $this->Products;
$product = $productsTable->get($id, contain: []); $product = $productsTable->get($id, contain: [
'ProductAttributes',
'ProductAttributes.ProductCategoryAttributes',
'ProductAttributes.ProductCategoryAttributes.ProductCategoryAttributeOptions',
]);
if ($this->request->is(['patch', 'post', 'put'])) { if ($this->request->is(['patch', 'post', 'put'])) {
$product = $productsTable->patchEntity($product, $this->request->getData()); $saveOptions = [
'associated' => ['ProductAttributes'],
];
$product = $productsTable->patchEntity($product, $this->request->getData(), $saveOptions);
if ($productsTable->save($product)) { if ($productsTable->save($product)) {
$this->Flash->success(__('The product has been saved.')); $this->Flash->success(__('The product has been saved.'));
@@ -104,8 +166,9 @@ class ProductsController extends AppController
Log::debug(print_r($product->getErrors(), true)); Log::debug(print_r($product->getErrors(), true));
$this->Flash->error(__('The product could not be saved. Please, try again.')); $this->Flash->error(__('The product could not be saved. Please, try again.'));
} }
$productCategories = $productsTable->ProductCategories->find('list', limit: 200)->all(); $productCategory = $product->product_category_id ? $productsTable->ProductCategories->find()->where(['internal_id' => $product->product_category_id])->first() : null;
$this->set(compact('product', 'productCategories')); $productCatalogs = $productsTable->ProductCategories->ProductCatalogs->find('list')->toArray();
$this->set(compact('product', 'productCatalogs', 'productCategory'));
} }
/** /**
@@ -119,7 +182,7 @@ class ProductsController extends AppController
{ {
$this->request->allowMethod(['post', 'delete']); $this->request->allowMethod(['post', 'delete']);
$productsTable = $this->getTable(); $productsTable = $this->Products;
$product = $productsTable->get($id); $product = $productsTable->get($id);
if ($productsTable->delete($product)) { if ($productsTable->delete($product)) {
$this->Flash->success(__('The product has been deleted.')); $this->Flash->success(__('The product has been deleted.'));
@@ -129,4 +192,22 @@ class ProductsController extends AppController
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();
$this->set(compact('products'));
}
} }

View File

@@ -0,0 +1,57 @@
<?php
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;
/**
* ToggleBehavior
*
* An implementation of a unique field toggle per table or scope.
* This will ensure that on a set of records only one can be a "primary" one, setting the others to false then.
* On delete it will give the primary status to another record if applicable.
*
* @author Mark Scherer
* @license MIT
*/
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
];
/**
* @param \Cake\Datasource\EntityInterface $entity
*
* @return array
*/
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);
}
// dd($conditions);
return $conditions;
}
}

View File

@@ -0,0 +1,57 @@
<?php
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;
/**
* ToggleBehavior
*
* An implementation of a unique field toggle per table or scope.
* This will ensure that on a set of records only one can be a "primary" one, setting the others to false then.
* On delete it will give the primary status to another record if applicable.
*
* @author Mark Scherer
* @license MIT
*/
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
];
/**
* @param \Cake\Datasource\EntityInterface $entity
*
* @return array
*/
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);
}
// dd($conditions);
return $conditions;
}
}

View File

@@ -35,6 +35,8 @@ class ExternalProductCatalog extends Entity
'created' => true, 'created' => true,
'deleted' => true, 'deleted' => true,
'enabled' => true, 'enabled' => true,
// entities
'external_product_catalogs_product_catalogs' => true, 'external_product_catalogs_product_catalogs' => true,
]; ];
} }

View File

@@ -14,6 +14,7 @@ use Cake\ORM\Entity;
* @property string $product_catalog_id * @property string $product_catalog_id
* @property DateTime $created * @property DateTime $created
* @property bool $enabled * @property bool $enabled
* @property DateTime|null $deleted
* *
* @property ExternalProductCatalog $external_product_catalog * @property ExternalProductCatalog $external_product_catalog
* @property ProductCatalog $product_catalog * @property ProductCatalog $product_catalog
@@ -34,6 +35,9 @@ class ExternalProductCatalogsProductCatalog extends Entity
'product_catalog_id' => true, 'product_catalog_id' => true,
'created' => true, 'created' => true,
'enabled' => true, 'enabled' => true,
'deleted' => true,
// entities
'external_product_catalog' => true, 'external_product_catalog' => true,
'product_catalog' => true, 'product_catalog' => true,
]; ];

View File

@@ -3,7 +3,9 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity; namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity; use Cake\ORM\Entity;
use CakeProducts\Model\Enum\ProductProductTypeId;
/** /**
* Product Entity * Product Entity
@@ -11,9 +13,13 @@ use Cake\ORM\Entity;
* @property string $id * @property string $id
* @property string $name * @property string $name
* @property string $product_category_id * @property string $product_category_id
* @property \CakeProducts\Model\Enum\ProductProductTypeId $product_type_id * @property ProductProductTypeId $product_type_id
* @property DateTime|null $deleted
*
* @property ProductCategory $product_category
* @property ProductAttribute[] $product_attributes
* @property ProductCategoryVariant[] $product_category_variants
* *
* @property \CakeProducts\Model\Entity\ProductCategory $product_category
*/ */
class Product extends Entity class Product extends Entity
{ {
@@ -30,6 +36,12 @@ class Product extends Entity
'name' => true, 'name' => true,
'product_category_id' => true, 'product_category_id' => true,
'product_type_id' => true, 'product_type_id' => true,
'product_category' => true, 'deleted' => true,
// entities
'product_category' => false,
'product_attributes' => true,
'product_category_variants' => true,
'primary_product_photo' => true,
]; ];
} }

View File

@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity;
/**
* ProductAttribute Entity
*
* @property string $id
* @property string $product_id
* @property string $product_category_attribute_id
* @property string|null $attribute_value
* @property string|null $product_category_attribute_option_id
* @property DateTime|null $deleted
*
* @property Product $product
* @property ProductCategoryAttribute $product_category_attribute
* @property ProductCategoryAttributeOption $product_category_attribute_option
*/
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
* 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 = [
'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,
];
}

View File

@@ -3,6 +3,7 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity; namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity; use Cake\ORM\Entity;
/** /**
@@ -12,6 +13,7 @@ use Cake\ORM\Entity;
* @property string $name * @property string $name
* @property string|null $catalog_description * @property string|null $catalog_description
* @property bool $enabled * @property bool $enabled
* @property DateTime|null $deleted
* *
* @property ProductCategory[] $product_categories * @property ProductCategory[] $product_categories
* @property ExternalProductCatalog[] $external_product_catalogs * @property ExternalProductCatalog[] $external_product_catalogs
@@ -31,6 +33,9 @@ class ProductCatalog extends Entity
'name' => true, 'name' => true,
'catalog_description' => true, 'catalog_description' => true,
'enabled' => true, 'enabled' => true,
'deleted' => true,
// entities
'product_categories' => true, 'product_categories' => true,
'external_product_catalogs' => true, 'external_product_catalogs' => true,
]; ];

View File

@@ -3,7 +3,9 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity; namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity; use Cake\ORM\Entity;
use CakeProducts\Model\Enum\ProductProductTypeId;
/** /**
* ProductCategory Entity * ProductCategory Entity
@@ -17,6 +19,8 @@ use Cake\ORM\Entity;
* @property int $lft * @property int $lft
* @property int $rght * @property int $rght
* @property bool $enabled * @property bool $enabled
* @property DateTime|null $deleted
* @property ProductProductTypeId|null $default_product_type_id
* *
* @property \CakeProducts\Model\Entity\ProductCatalog $product_catalog * @property \CakeProducts\Model\Entity\ProductCatalog $product_catalog
* @property \CakeProducts\Model\Entity\ParentProductCategory $parent_product_category * @property \CakeProducts\Model\Entity\ParentProductCategory $parent_product_category
@@ -38,12 +42,17 @@ class ProductCategory extends Entity
'internal_id' => true, 'internal_id' => true,
'name' => true, 'name' => true,
'category_description' => true, 'category_description' => true,
'default_product_type_id' => true,
'parent_id' => true, 'parent_id' => true,
'lft' => true, 'lft' => true,
'rght' => true, 'rght' => true,
'enabled' => true, 'enabled' => true,
'deleted' => true,
// entities
'product_catalog' => true, 'product_catalog' => true,
'parent_product_category' => true, 'parent_product_category' => true,
'child_product_categories' => true, 'child_product_categories' => true,
'primary_product_photo' => true,
]; ];
} }

View File

@@ -3,6 +3,7 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity; namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity; use Cake\ORM\Entity;
/** /**
@@ -13,6 +14,7 @@ use Cake\ORM\Entity;
* @property string|null $product_category_id * @property string|null $product_category_id
* @property int $attribute_type_id * @property int $attribute_type_id
* @property bool $enabled * @property bool $enabled
* @property DateTime|null $deleted
* *
* @property ProductCategory $product_category * @property ProductCategory $product_category
* @property ProductCategoryAttributeOption[] $product_category_attribute_options * @property ProductCategoryAttributeOption[] $product_category_attribute_options
@@ -33,6 +35,9 @@ class ProductCategoryAttribute extends Entity
'product_category_id' => true, 'product_category_id' => true,
'attribute_type_id' => true, 'attribute_type_id' => true,
'enabled' => true, 'enabled' => true,
'deleted' => true,
// entities
'product_category' => true, 'product_category' => true,
'product_category_attribute_options' => true, 'product_category_attribute_options' => true,
]; ];

View File

@@ -3,6 +3,7 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity; namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity; use Cake\ORM\Entity;
/** /**
@@ -13,6 +14,7 @@ use Cake\ORM\Entity;
* @property string $attribute_value * @property string $attribute_value
* @property string $attribute_label * @property string $attribute_label
* @property bool $enabled * @property bool $enabled
* @property DateTime|null $deleted
* *
* @property ProductCategoryAttribute $product_category_attribute * @property ProductCategoryAttribute $product_category_attribute
*/ */
@@ -32,6 +34,9 @@ class ProductCategoryAttributeOption extends Entity
'attribute_value' => true, 'attribute_value' => true,
'attribute_label' => true, 'attribute_label' => true,
'enabled' => true, 'enabled' => true,
'deleted' => true,
// entities
'product_category_attribute' => true, 'product_category_attribute' => true,
]; ];
} }

View File

@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
namespace CakeProducts\Model\Entity;
use Cake\Datasource\EntityInterface;
use Cake\ORM\Entity;
/**
* ProductCategoryVariant Entity
*
* @property string $id
* @property string $name
* @property string|null $product_category_id
* @property string|null $product_id
* @property bool $enabled
* @property bool $is_system_variant
*
* @property ProductCategory|EntityInterface $product_category
* @property ProductCategoryVariantOption[]|EntityInterface[] $product_category_variant_options
*/
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
* 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 = [
'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,
];
}

View File

@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace CakeProducts\Model\Entity;
use Cake\ORM\Entity;
/**
* ProductCategoryVariantOption Entity
*
* @property string $id
* @property string $product_category_variant_id
* @property string $variant_value
* @property \Cake\I18n\DateTime $created
* @property \Cake\I18n\DateTime $modified
* @property \Cake\I18n\DateTime|null $deleted
*
* @property \App\Model\Entity\ProductCategoryVariant $product_category_variant
*/
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
* 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 = [
'product_category_variant_id' => true,
'variant_value' => true,
'created' => true,
'modified' => true,
'deleted' => true,
// entities
'product_category_variant' => false,
];
}

View File

@@ -0,0 +1,62 @@
<?php
declare(strict_types=1);
namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity;
/**
* ProductPhoto Entity
*
* @property string $id
* @property string|null $product_id
* @property string|null $product_category_id
* @property string|null $product_sku_id
* @property string $photo_dir
* @property string $photo_filename
* @property bool $primary_photo
* @property bool $primary_category_photo
* @property bool $primary_sku_photo
* @property int $photo_position
* @property bool $enabled
* @property DateTime $created
* @property DateTime|null $modified
* @property DateTime|null $deleted
*
* @property Product|null $product
* @property ProductSku|null $product_sku
* @property ProductCategory $product_category
*/
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
* 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 = [
'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,
];
}

View File

@@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity;
/**
* ProductSkus Entity
*
* @property string $id
* @property string $product_id
* @property string $sku
* @property string|null $barcode
* @property string|null $price
* @property string|null $cost
* @property DateTime $created
* @property DateTime|null $modified
* @property DateTime|null $deleted
* @property bool $default_sku
*
* @property Product $product
* @property ProductSkuVariantValue[] $product_sku_variant_values
*/
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
* 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 = [
'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,
];
}

View File

@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace CakeProducts\Model\Entity;
use Cake\ORM\Entity;
/**
* ProductSkuVariantValue Entity
*
* @property string $id
* @property string $product_sku_id
* @property string $product_variant_id
* @property string $product_category_variant_option_id
*
* @property ProductSku $product_sku
* @property ProductCategoryVariant $product_category_variant
* @property ProductCategoryVariantOption $product_category_variant_option
*/
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
* 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 = [
'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,
];
}

View File

@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace CakeProducts\Model\Entity;
use Cake\ORM\Entity;
/**
* ProductVariant Entity
*
* @property string $id
* @property string $name
* @property string|null $product_category_variant_id
* @property string $product_id
* @property bool $enabled
*
* @property \App\Model\Entity\ProductCategoryVariant $product_category_variant
* @property \App\Model\Entity\Product $product
*/
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
* 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 = [
'name' => true,
'product_category_variant_id' => true,
'product_id' => true,
'enabled' => true,
'product_category_variant' => true,
'product' => true,
];
}

View File

@@ -11,13 +11,19 @@ enum ProductProductTypeId: int implements EnumLabelInterface
case Service = 1; case Service = 1;
case Product = 2; case Product = 2;
case Consumable = 3; case Consumable = 3;
case DigitalGood = 4;
case Subscription = 5;
// case Event = 5;
public function label(): string public function label(): string
{ {
return match($this) { return match($this) {
self::Service => 'Service', self::Service => 'Service',
self::Product => 'Product', self::Product => 'Product',
self::Consumable => 'Consumable' self::Consumable => 'Consumable',
self::DigitalGood => 'Digital Good',
self::Subscription => 'Subscription',
// self::Event => 'Event',
}; };
} }
} }

View File

@@ -71,6 +71,8 @@ class ExternalProductCatalogsProductCatalogsTable extends Table
// 'foreignKey' => 'product_catalog_id', // 'foreignKey' => 'product_catalog_id',
'joinType' => 'INNER', 'joinType' => 'INNER',
]); ]);
$this->addBehavior('Muffin/Trash.Trash');
} }
/** /**
@@ -92,6 +94,10 @@ class ExternalProductCatalogsProductCatalogsTable extends Table
$validator $validator
->boolean('enabled'); ->boolean('enabled');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
return $validator; return $validator;
} }

View File

@@ -67,7 +67,11 @@ class ExternalProductCatalogsTable extends Table
$this->hasMany('ExternalProductCatalogsProductCatalogs', [ $this->hasMany('ExternalProductCatalogsProductCatalogs', [
'foreignKey' => 'external_product_catalog_id', 'foreignKey' => 'external_product_catalog_id',
'className' => 'CakeProducts.ExternalProductCatalogsProductCatalogs', 'className' => 'CakeProducts.ExternalProductCatalogsProductCatalogs',
'dependent' => true,
'cascadeCallbacks' => true,
]); ]);
$this->addBehavior('Muffin/Trash.Trash');
} }
/** /**

View File

@@ -0,0 +1,116 @@
<?php
declare(strict_types=1);
namespace CakeProducts\Model\Table;
use Cake\Core\Configure;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
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
*
* @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 = [])
*/
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);
$this->setTable('product_attributes');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$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',
]);
}
/**
* 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');
$validator
->uuid('product_category_attribute_id')
->notEmptyString('product_category_attribute_id');
$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
->dateTime('deleted')
->allowEmptyDateTime('deleted');
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']);
return $rules;
}
}

View File

@@ -57,6 +57,8 @@ class ProductCatalogsTable extends Table
'through' => 'ExternalProductCatalogsProductCatalogs', 'through' => 'ExternalProductCatalogsProductCatalogs',
'className' => 'CakeProducts.ExternalProductCatalogs', 'className' => 'CakeProducts.ExternalProductCatalogs',
]); ]);
$this->addBehavior('Muffin/Trash.Trash');
} }
/** /**
@@ -84,6 +86,10 @@ class ProductCatalogsTable extends Table
->requirePresence('enabled', 'create') ->requirePresence('enabled', 'create')
->notEmptyString('enabled'); ->notEmptyString('enabled');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
return $validator; return $validator;
} }

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table; namespace CakeProducts\Model\Table;
use Cake\Core\Configure; use Cake\Core\Configure;
use Cake\Database\Type\EnumType;
use Cake\Datasource\EntityInterface; use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface; use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo; use Cake\ORM\Association\BelongsTo;
@@ -14,6 +15,7 @@ use Cake\ORM\RulesChecker;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\Validation\Validator; use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductCategory; use CakeProducts\Model\Entity\ProductCategory;
use CakeProducts\Model\Enum\ProductProductTypeId;
use Closure; use Closure;
use Psr\SimpleCache\CacheInterface; use Psr\SimpleCache\CacheInterface;
@@ -65,7 +67,9 @@ class ProductCategoriesTable extends Table
$this->setEntityClass( $this->setEntityClass(
Configure::read('CakeProducts.ProductCategories.entity', 'CakeProducts\Model\Entity\ProductCategory') Configure::read('CakeProducts.ProductCategories.entity', 'CakeProducts\Model\Entity\ProductCategory')
); );
$this->addBehavior('Tree'); $this->addBehavior('Tree', [
'cascadeCallbacks' => true,
]);
$this->belongsTo('ProductCatalogs', [ $this->belongsTo('ProductCatalogs', [
'foreignKey' => 'product_catalog_id', 'foreignKey' => 'product_catalog_id',
@@ -79,13 +83,49 @@ class ProductCategoriesTable extends Table
$this->hasMany('ChildProductCategories', [ $this->hasMany('ChildProductCategories', [
'className' => 'CakeProducts.ProductCategories', 'className' => 'CakeProducts.ProductCategories',
'foreignKey' => 'parent_id', 'foreignKey' => 'parent_id',
'dependent' => true,
'cascadeCallbacks' => true,
]); ]);
$this->hasMany('ProductCategoryAttributes', [ $this->hasMany('ProductCategoryAttributes', [
'foreignKey' => 'product_category_id', 'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id', 'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductCategoryAttributes', 'className' => 'CakeProducts.ProductCategoryAttributes',
'dependent' => true,
'cascadeCallbacks' => true,
]); ]);
$this->hasMany('ProductCategoryVariants', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductCategoryVariants',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('Products', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.Products',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ProductPhotos', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductPhotos',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasOne('PrimaryProductPhotos', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'conditions' => ['PrimaryProductPhotos.primary_category_photo' => true],
'className' => 'CakeProducts.ProductPhotos',
'dependent' => true,
]);
$this->getSchema()->setColumnType('default_product_type_id', EnumType::from(ProductProductTypeId::class));
$this->behaviors()->Tree->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]); $this->behaviors()->Tree->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]);
$this->addBehavior('Muffin/Trash.Trash');
} }
/** /**
@@ -118,6 +158,14 @@ class ProductCategoriesTable extends Table
->boolean('enabled') ->boolean('enabled')
->notEmptyString('enabled'); ->notEmptyString('enabled');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
$validator
->integer('default_product_type_id')
->allowEmptyString('default_product_type_id');
return $validator; return $validator;
} }

View File

@@ -3,6 +3,7 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table; namespace CakeProducts\Model\Table;
use Cake\Core\Configure;
use Cake\Datasource\EntityInterface; use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface; use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo; use Cake\ORM\Association\BelongsTo;
@@ -49,11 +50,17 @@ class ProductCategoryAttributeOptionsTable extends Table
$this->setDisplayField('attribute_value'); $this->setDisplayField('attribute_value');
$this->setPrimaryKey('id'); $this->setPrimaryKey('id');
$this->setEntityClass(
Configure::read('CakeProducts.ProductCategoryAttributeOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryAttributeOption')
);
$this->belongsTo('ProductCategoryAttributes', [ $this->belongsTo('ProductCategoryAttributes', [
'foreignKey' => 'product_category_attribute_id', 'foreignKey' => 'product_category_attribute_id',
'joinType' => 'INNER', 'joinType' => 'INNER',
'className' => 'CakeProducts.ProductCategoryAttributes', 'className' => 'CakeProducts.ProductCategoryAttributes',
]); ]);
$this->addBehavior('Muffin/Trash.Trash');
} }
/** /**
@@ -84,6 +91,10 @@ class ProductCategoryAttributeOptionsTable extends Table
->boolean('enabled') ->boolean('enabled')
->notEmptyString('enabled'); ->notEmptyString('enabled');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
return $validator; return $validator;
} }
@@ -97,6 +108,7 @@ class ProductCategoryAttributeOptionsTable extends Table
public function buildRules(RulesChecker $rules): RulesChecker public function buildRules(RulesChecker $rules): RulesChecker
{ {
$rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']); $rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']);
$rules->add($rules->isUnique(['attribute_value', 'product_category_attribute_id']));
return $rules; return $rules;
} }

View File

@@ -3,6 +3,7 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table; namespace CakeProducts\Model\Table;
use Cake\Core\Configure;
use Cake\Database\Type\EnumType; use Cake\Database\Type\EnumType;
use Cake\Datasource\EntityInterface; use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface; use Cake\Datasource\ResultSetInterface;
@@ -51,6 +52,9 @@ class ProductCategoryAttributesTable extends Table
$this->setDisplayField('name'); $this->setDisplayField('name');
$this->setPrimaryKey('id'); $this->setPrimaryKey('id');
$this->setEntityClass(
Configure::read('CakeProducts.ProductCategoryAttributes.entity', 'CakeProducts\Model\Entity\ProductCategoryAttribute')
);
$this->belongsTo('ProductCategories', [ $this->belongsTo('ProductCategories', [
'foreignKey' => 'product_category_id', 'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id', 'bindingKey' => 'internal_id',
@@ -61,8 +65,12 @@ class ProductCategoryAttributesTable extends Table
'foreignKey' => 'product_category_attribute_id', 'foreignKey' => 'product_category_attribute_id',
'className' => 'CakeProducts.ProductCategoryAttributeOptions', 'className' => 'CakeProducts.ProductCategoryAttributeOptions',
'saveStrategy' => 'replace', 'saveStrategy' => 'replace',
'dependent' => true,
'cascadeCallbacks' => true,
]); ]);
$this->getSchema()->setColumnType('attribute_type_id', EnumType::from(ProductCategoryAttributeTypeId::class)); $this->getSchema()->setColumnType('attribute_type_id', EnumType::from(ProductCategoryAttributeTypeId::class));
$this->addBehavior('Muffin/Trash.Trash');
} }
/** /**
@@ -93,6 +101,10 @@ class ProductCategoryAttributesTable extends Table
->requirePresence('enabled', 'create') ->requirePresence('enabled', 'create')
->notEmptyString('enabled'); ->notEmptyString('enabled');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
return $validator; return $validator;
} }
@@ -111,11 +123,28 @@ class ProductCategoryAttributesTable extends Table
return $rules; return $rules;
} }
public function getAllCategoryAttributesForCategoryId(string $internalCategoryId) /**
* @param SelectQuery $query
* @param string $internalCategoryId
*
* @return array|\Cake\ORM\Query|SelectQuery
*/
public function findAllCategoryAttributesForCategoryId(SelectQuery $query, string $internalCategoryId)
{ {
$category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail(); $category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail();
$categories = $this->ProductCategories->find('path', for: $category->id)->all();
return $categories; $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']);
}
public function getAllCategoryAttributesForCategoryId(string $internalCategoryId)
{
return $this->find('allCategoryAttributesForCategoryId', $internalCategoryId)->toArray();
} }
} }

View File

@@ -0,0 +1,112 @@
<?php
declare(strict_types=1);
namespace CakeProducts\Model\Table;
use Cake\Core\Configure;
use CakeProducts\Model\Entity\ProductCategoryVariantOption;
use CakeProducts\Model\Table\ProductCategoryVariantsTable;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Behavior\TimestampBehavior;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ProductCategoryVariantOptions Model
*
* @property ProductCategoryVariantsTable&BelongsTo $ProductCategoryVariants
*
* @method ProductCategoryVariantOption newEmptyEntity()
* @method ProductCategoryVariantOption newEntity(array $data, array $options = [])
* @method 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 = [])
*
* @mixin TimestampBehavior
*/
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);
$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->belongsTo('ProductCategoryVariants', [
'foreignKey' => 'product_category_variant_id',
'joinType' => 'INNER',
]);
}
/**
* Default validation rules.
*
* @param Validator $validator Validator instance.
* @return Validator
*/
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_label')
->maxLength('variant_label', 255)
->allowEmptyString('variant_label');
$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
{
$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;
}
}

View File

@@ -0,0 +1,164 @@
<?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\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
*
* @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 = [])
*/
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);
$this->setTable('product_category_variants');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$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->hasMany('ProductVariants', [
'foreignKey' => 'product_category_variant_id',
'className' => 'CakeProducts.ProductVariants',
'dependent' => true,
'cascadeCallbacks' => true,
]);
}
/**
* Default validation rules.
*
* @param Validator $validator Validator instance.
* @return Validator
*/
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_id')
->allowEmptyString('product_id');
$validator
->boolean('is_system_variant')
->allowEmptyString('is_system_variant');
$validator
->boolean('enabled')
->requirePresence('enabled', 'create')
->notEmptyString('enabled');
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
{
$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;
}
/**
* @param SelectQuery $query
* @param string $internalCategoryId
*
* @return array|Query|SelectQuery
*/
public function findAllCategoryVariantsForCategoryId(SelectQuery $query, string $internalCategoryId)
{
$category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail();
$this->ProductCategories->behaviors()->get('Tree')->setConfig([
'scope' => [
'product_catalog_id' => $category->product_catalog_id ?? 1,
],
]);
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();
}
}

View File

@@ -0,0 +1,172 @@
<?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\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
*
* @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 = [])
*
* @mixin TimestampBehavior
*/
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);
$this->setTable('product_photos');
$this->setDisplayField('photo_filename');
$this->setPrimaryKey('id');
$this->setEntityClass(
Configure::read('CakeProducts.ProductPhotos.entity', 'CakeProducts\Model\Entity\ProductPhoto')
);
$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->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',
]);
}
/**
* Default validation rules.
*
* @param Validator $validator Validator instance.
* @return Validator
*/
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_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_filename')
->maxLength('photo_filename', 255)
->requirePresence('photo_filename', 'create')
->notEmptyString('photo_filename');
$validator
->boolean('primary_photo')
->notEmptyString('primary_photo');
$validator
->integer('photo_position')
->notEmptyString('photo_position');
$validator
->boolean('enabled')
->notEmptyString('enabled');
$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
{
$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;
}
}

View File

@@ -0,0 +1,112 @@
<?php
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
*
* @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 = [])
*/
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);
$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',
]);
}
/**
* Default validation rules.
*
* @param Validator $validator Validator instance.
* @return Validator
*/
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_category_variant_option_id')
->notEmptyString('product_category_variant_option_id');
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
{
$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']);
return $rules;
}
}

View File

@@ -0,0 +1,151 @@
<?php
declare(strict_types=1);
namespace CakeProducts\Model\Table;
use Cake\Core\Configure;
use Cake\ORM\Query\SelectQuery;
use CakeProducts\Model\Table\ProductsTable;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Behavior\TimestampBehavior;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductSku;
use Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ProductSkus Model
*
* @property ProductsTable&BelongsTo $Products
*
* @method ProductSku newEmptyEntity()
* @method ProductSku newEntity(array $data, array $options = [])
* @method 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 = [])
*
* @mixin TimestampBehavior
*/
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);
$this->setTable('product_skus');
$this->setDisplayField('sku');
$this->setPrimaryKey('id');
$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->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('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,
]);
}
/**
* Default validation rules.
*
* @param Validator $validator Validator instance.
* @return Validator
*/
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('barcode')
->maxLength('barcode', 255)
->allowEmptyString('barcode');
$validator
->decimal('price')
->allowEmptyString('price');
$validator
->decimal('cost')
->allowEmptyString('cost');
$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
{
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
$rules->add($rules->isUnique(['sku'], 'SKU must be unique'), ['errorField' => 'sku']);
return $rules;
}
}

View File

@@ -0,0 +1,117 @@
<?php
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
*
* @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 = [])
*/
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);
$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->hasMany('ProductSkuVariantValues', [
'className' => 'CakeProducts.ProductSkuVariantValues',
'foreignKey' => 'product_variant_id',
'dependent' => true,
'cascadeCallbacks' => true,
]);
}
/**
* Default validation rules.
*
* @param Validator $validator Validator instance.
* @return Validator
*/
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_id')
->notEmptyString('product_id');
$validator
->boolean('enabled')
->requirePresence('enabled', 'create')
->notEmptyString('enabled');
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
{
$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;
}
}

View File

@@ -3,6 +3,7 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table; namespace CakeProducts\Model\Table;
use Cake\Core\Configure;
use Cake\Database\Type\EnumType; use Cake\Database\Type\EnumType;
use Cake\Datasource\EntityInterface; use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface; use Cake\Datasource\ResultSetInterface;
@@ -51,6 +52,10 @@ class ProductsTable extends Table
$this->setDisplayField('name'); $this->setDisplayField('name');
$this->setPrimaryKey('id'); $this->setPrimaryKey('id');
$this->setEntityClass(
Configure::read('CakeProducts.Products.entity', 'CakeProducts\Model\Entity\Product')
);
$this->belongsTo('ProductCategories', [ $this->belongsTo('ProductCategories', [
'foreignKey' => 'product_category_id', 'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id', 'bindingKey' => 'internal_id',
@@ -58,8 +63,51 @@ class ProductsTable extends Table
'className' => 'CakeProducts.ProductCategories', 'className' => 'CakeProducts.ProductCategories',
]); ]);
$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('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->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->getSchema()->setColumnType('product_type_id', EnumType::from(ProductProductTypeId::class)); $this->getSchema()->setColumnType('product_type_id', EnumType::from(ProductProductTypeId::class));
$this->addBehavior('Muffin/Trash.Trash');
} }
/** /**
@@ -85,6 +133,10 @@ class ProductsTable extends Table
->requirePresence('product_type_id', 'create') ->requirePresence('product_type_id', 'create')
->notEmptyString('product_type_id'); ->notEmptyString('product_type_id');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
return $validator; return $validator;
} }
@@ -99,6 +151,7 @@ class ProductsTable extends Table
{ {
$rules->add($rules->isUnique(['product_category_id', 'name']), ['errorField' => 'product_category_id']); $rules->add($rules->isUnique(['product_category_id', 'name']), ['errorField' => 'product_category_id']);
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']); $rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
// $rules->add($rules->validCount('product_attributes', 0, '<=', 'You must not have any tags'));
return $rules; return $rules;
} }

View File

@@ -4,7 +4,10 @@
* @var \Cake\Datasource\EntityInterface $productCategory * @var \Cake\Datasource\EntityInterface $productCategory
* @var \Cake\Collection\CollectionInterface|string[] $productCatalogs * @var \Cake\Collection\CollectionInterface|string[] $productCatalogs
* @var \Cake\Collection\CollectionInterface|string[] $parentProductCategories * @var \Cake\Collection\CollectionInterface|string[] $parentProductCategories
*
*/ */
?> ?>
<div class="row"> <div class="row">
<aside class="column"> <aside class="column">

View File

@@ -7,7 +7,7 @@
$this->setLayout('ajax'); $this->setLayout('ajax');
?> ?>
<option value="">Select a parent (optional)</option> <option value="">Select a <?= $this->request->getQuery('form', 'product') == 'category' ? 'parent (optional) ' : 'Category'; ?></option>
<?php foreach ($productCategories as $productCategoryId => $productCategoryName): ?> <?php foreach ($productCategories as $productCategoryId => $productCategoryName): ?>
<option value="<?= $productCategoryId; ?>" <?= $this->request->getQuery('category_id') == $productCategoryId ? 'selected="selected"' : ''; ?>><?= $productCategoryName; ?></option> <option value="<?= $productCategoryId; ?>" <?= $this->request->getQuery('category_id') == $productCategoryId ? 'selected="selected"' : ''; ?>><?= $productCategoryName; ?></option>
<?php endforeach; ?> <?php endforeach; ?>

View File

@@ -0,0 +1,47 @@
<?php
/**
* @var \App\View\AppView $this
* @var \Cake\Datasource\EntityInterface[]|ProductCategoryAttribute[] $productCategoryAttributes
*/
use Cake\Utility\Hash;
use CakeProducts\Model\Entity\ProductCategoryAttribute;
use CakeProducts\Model\Enum\ProductCategoryAttributeTypeId;
$this->setLayout('ajax');
?>
<?php
$cnt = 0;
foreach ($productCategories as $productCategory) {
foreach ($productCategory->product_category_attributes as $productCategoryAttribute) {
echo $this->Form->hidden('product_attributes.' . $cnt . '.product_category_attribute_id', [
'value' => $productCategoryAttribute->id,
]);
$inputType = 'text';
$options = [];
if ($productCategoryAttribute->attribute_type_id === ProductCategoryAttributeTypeId::Integer) {
$inputType = 'number';
}
if ($productCategoryAttribute->attribute_type_id === ProductCategoryAttributeTypeId::Constrained) {
echo $this->Form->hidden('product_attributes.' . $cnt . '.attribute_value', [
'value' => '',
]);
$options = !empty($productCategoryAttribute->product_category_attribute_options) ?
Hash::combine($productCategoryAttribute->product_category_attribute_options, '{n}.id', '{n}.attribute_label') :
[];
echo $this->Form->control('product_attributes.' . $cnt . '.product_category_attribute_option_id', [
'type' => 'select',
'label' => $productCategoryAttribute->name,
'options' => $options,
]);
} else {
echo $this->Form->control('product_attributes.' . $cnt . '.attribute_value', [
'type' => $inputType,
'label' => $productCategoryAttribute->name,
'options' => $options,
]);
}
$cnt++;
}
}

View File

@@ -0,0 +1,20 @@
<?php
use App\View\AppView;
use Cake\Datasource\EntityInterface;
/**
* @var AppView $this
* @var EntityInterface $productCategoryAttributeOption
*/
$this->setLayout('ajax');
$prefix = $prefix ?? '';
if ($this->request->getQuery('prefix') !== null) {
$prefix = 'product_category_variant_options.' . $this->request->getQuery('prefix') . '.';
}
echo '<hr class="my-2">';
echo $this->element('ProductCategoryVariants/product_category_variant_option_form', [
'prefix' => $prefix
]);
?>

View File

@@ -0,0 +1,28 @@
<?php
/**
* @var \App\View\AppView $this
* @var \App\Model\Entity\ProductCategoryVariant $productCategoryVariant
* @var \Cake\Collection\CollectionInterface|string[] $productCategories
* @var \Cake\Collection\CollectionInterface|string[] $products
*/
?>
<div class="row">
<aside class="column">
<div class="side-nav">
<h4 class="heading"><?= __('Actions') ?></h4>
<?= $this->Html->link(__('List Product Category Variants'), ['action' => 'index'], ['class' => 'side-nav-item']) ?>
</div>
</aside>
<div class="column column-80">
<div class="productCategoryVariants form content">
<?= $this->Form->create($productCategoryVariant) ?>
<fieldset>
<legend><?= __('Add Product Category Variant') ?></legend>
<?= $this->element('ProductCategoryVariants/form', ['productCategoryVariant' => $productCategoryVariant]); ?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
</div>
</div>
</div>
<?= $this->Html->script('CakeProducts.product_category_variant_options.js'); ?>

View File

@@ -0,0 +1,33 @@
<?php
/**
* @var \App\View\AppView $this
* @var \App\Model\Entity\ProductCategoryVariant $productCategoryVariant
* @var string[]|\Cake\Collection\CollectionInterface $productCategories
* @var string[]|\Cake\Collection\CollectionInterface $products
*/
?>
<div class="row">
<aside class="column">
<div class="side-nav">
<h4 class="heading"><?= __('Actions') ?></h4>
<?= $this->Form->postLink(
__('Delete'),
['action' => 'delete', $productCategoryVariant->id],
['confirm' => __('Are you sure you want to delete # {0}?', $productCategoryVariant->id), 'class' => 'side-nav-item']
) ?>
<?= $this->Html->link(__('List Product Category Variants'), ['action' => 'index'], ['class' => 'side-nav-item']) ?>
</div>
</aside>
<div class="column column-80">
<div class="productCategoryVariants form content">
<?= $this->Form->create($productCategoryVariant) ?>
<fieldset>
<legend><?= __('Edit Product Category Variant') ?></legend>
<?= $this->element('ProductCategoryVariants/form', ['productCategoryVariant' => $productCategoryVariant]); ?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
</div>
</div>
</div>
<?= $this->Html->script('CakeProducts.product_category_variant_options.js'); ?>

View File

@@ -0,0 +1,62 @@
<?php
/**
* @var \App\View\AppView $this
* @var iterable<\App\Model\Entity\ProductCategoryVariant>|iterable<\Cake\ORM\Entity> $productCategoryVariants
*/
?>
<div class="productCategoryVariants index content">
<?= $this->Html->link(__('New Product Category Variant'), ['action' => 'add'], ['class' => 'button float-right']) ?>
<h3><?= __('Product Category Variants') ?></h3>
<div class="table-responsive" id="table-container">
<table>
<thead>
<tr>
<th><?= $this->Paginator->sort('id') ?></th>
<th><?= $this->Paginator->sort('name') ?></th>
<th><?= $this->Paginator->sort('product_category_id') ?></th>
<th><?= $this->Paginator->sort('product_id') ?></th>
<th><?= $this->Paginator->sort('enabled') ?></th>
<th><?= 'Options' ?></th>
<th class="actions"><?= __('Actions') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($productCategoryVariants as $productCategoryVariant): ?>
<tr>
<td><?= h($productCategoryVariant->id) ?></td>
<td><?= h($productCategoryVariant->name) ?></td>
<td><?= $productCategoryVariant->hasValue('product_category') ? $this->Html->link($productCategoryVariant->product_category->name, ['controller' => 'ProductCategories', 'action' => 'view', $productCategoryVariant->product_category->id]) : '' ?></td>
<td><?= $productCategoryVariant->hasValue('product') ? $this->Html->link($productCategoryVariant->product->name, ['controller' => 'Products', 'action' => 'view', $productCategoryVariant->product->id]) : '' ?></td>
<td><?= h($productCategoryVariant->enabled) ?></td>
<td>
<small>
<?php
$cnt = isset($productCategoryVariant->product_category_variant_options) && $productCategoryVariant->product_category_variant_options ? count($productCategoryVariant->product_category_variant_options) : 0;
foreach ($productCategoryVariant->product_category_variant_options as $index => $productCategoryVariantOption) : ?>
<?= h($productCategoryVariantOption->variant_value); ?><?= $index < ($cnt -1) ? ', ' : ''; ?>
<?php endforeach; ?>
</small>
</td>
<td class="actions">
<?= $this->Html->link(__('View'), ['action' => 'view', $productCategoryVariant->id]) ?>
<?= $this->Html->link(__('Edit'), ['action' => 'edit', $productCategoryVariant->id]) ?>
<?= $this->Form->postLink(__('Delete'), ['action' => 'delete', $productCategoryVariant->id], ['confirm' => __('Are you sure you want to delete # {0}?', $productCategoryVariant->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>

View File

@@ -0,0 +1,72 @@
<?php
/**
* @var \App\View\AppView $this
* @var \App\Model\Entity\ProductCategoryVariant $productCategoryVariant
*/
?>
<div class="row">
<aside class="column">
<div class="side-nav">
<h4 class="heading"><?= __('Actions') ?></h4>
<?= $this->Html->link(__('Edit Product Category Variant'), ['action' => 'edit', $productCategoryVariant->id], ['class' => 'side-nav-item']) ?>
<?= $this->Form->postLink(__('Delete Product Category Variant'), ['action' => 'delete', $productCategoryVariant->id], ['confirm' => __('Are you sure you want to delete # {0}?', $productCategoryVariant->id), 'class' => 'side-nav-item']) ?>
<?= $this->Html->link(__('List Product Category Variants'), ['action' => 'index'], ['class' => 'side-nav-item']) ?>
<?= $this->Html->link(__('New Product Category Variant'), ['action' => 'add'], ['class' => 'side-nav-item']) ?>
</div>
</aside>
<div class="column column-80">
<div class="productCategoryVariants view content">
<h3><?= h($productCategoryVariant->name) ?></h3>
<table>
<tr>
<th><?= __('Id') ?></th>
<td><?= h($productCategoryVariant->id) ?></td>
</tr>
<tr>
<th><?= __('Name') ?></th>
<td><?= h($productCategoryVariant->name) ?></td>
</tr>
<tr>
<th><?= __('Product Category') ?></th>
<td><?= $productCategoryVariant->hasValue('product_category') ? $this->Html->link($productCategoryVariant->product_category->name, ['controller' => 'ProductCategories', 'action' => 'view', $productCategoryVariant->product_category->id]) : '' ?></td>
</tr>
<tr>
<th><?= __('Product') ?></th>
<td><?= $productCategoryVariant->hasValue('product') ? $this->Html->link($productCategoryVariant->product->name, ['controller' => 'Products', 'action' => 'view', $productCategoryVariant->product->id]) : '' ?></td>
</tr>
<tr>
<th><?= __('Enabled') ?></th>
<td><?= $productCategoryVariant->enabled ? __('Yes') : __('No'); ?></td>
</tr>
</table>
<div class="related">
<h4><?= __('Related Product Category Variant Options') ?></h4>
<?php if (!empty($productCategoryVariant->product_category_variant_options)) : ?>
<div class="table-responsive">
<table>
<tr>
<th><?= __('Variant Value') ?></th>
<th><?= __('Variant Label') ?></th>
<th><?= __('Enabled') ?></th>
<th class="actions"><?= __('Actions') ?></th>
</tr>
<?php foreach ($productCategoryVariant->product_category_variant_options as $productCategoryVariantOption) : ?>
<tr>
<td><?= h($productCategoryVariantOption->variant_value) ?></td>
<td><?= h($productCategoryVariantOption->variant_label) ?></td>
<td><?= h($productCategoryVariantOption->enabled) ?></td>
<td class="actions">
<?= $this->Html->link(__('View'), ['controller' => 'ProductCategoryVariantOptions', 'action' => 'view', $productCategoryVariantOption->id]) ?>
<?= $this->Html->link(__('Edit'), ['controller' => 'ProductCategoryVariantOptions', 'action' => 'edit', $productCategoryVariantOption->id]) ?>
<?= $this->Form->postLink(__('Delete'), ['controller' => 'ProductCategoryVariantOptions', 'action' => 'delete', $productCategoryVariantOption->id], ['confirm' => __('Are you sure you want to delete # {0}?', $productCategoryVariantOption->id)]) ?>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,26 @@
<?php
/**
* @var \App\View\AppView $this
* @var \Cake\Datasource\EntityInterface $productPhoto
* @var \Cake\Collection\CollectionInterface|string[] $products
*/
?>
<div class="row">
<aside class="column">
<div class="side-nav">
<h4 class="heading"><?= __('Actions') ?></h4>
<?= $this->Html->link(__('List Product Photos'), ['action' => 'index'], ['class' => 'side-nav-item']) ?>
</div>
</aside>
<div class="column column-80">
<div class="productPhotos form content">
<?= $this->Form->create($productPhoto, ['type' => 'file']) ?>
<fieldset>
<legend><?= __('Add Product Photo') ?></legend>
<?= $this->element('ProductPhotos/form', ['includeFile' => true]); ?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
</div>
</div>
</div>

View File

@@ -0,0 +1,31 @@
<?php
/**
* @var \App\View\AppView $this
* @var \Cake\Datasource\EntityInterface $productPhoto
* @var string[]|\Cake\Collection\CollectionInterface $products
*/
?>
<div class="row">
<aside class="column">
<div class="side-nav">
<h4 class="heading"><?= __('Actions') ?></h4>
<?= $this->Form->postLink(
__('Delete'),
['action' => 'delete', $productPhoto->id],
['confirm' => __('Are you sure you want to delete # {0}?', $productPhoto->id), 'class' => 'side-nav-item']
) ?>
<?= $this->Html->link(__('List Product Photos'), ['action' => 'index'], ['class' => 'side-nav-item']) ?>
</div>
</aside>
<div class="column column-80">
<div class="productPhotos form content">
<?= $this->Form->create($productPhoto) ?>
<fieldset>
<legend><?= __('Edit Product Photo') ?></legend>
<?= $this->element('ProductPhotos/form', ['includeFile' => false]); ?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
</div>
</div>
</div>

View File

@@ -0,0 +1,62 @@
<?php
/**
* @var \App\View\AppView $this
* @var iterable<\Cake\Datasource\EntityInterface> $productPhotos
*/
?>
<div class="productPhotos index content">
<?= $this->Html->link(__('New Product Photo'), ['action' => 'add'], ['class' => 'button float-right']) ?>
<h3><?= __('Product Photos') ?></h3>
<div class="table-responsive" id="table-container">
<table>
<thead>
<tr>
<th><?= $this->Paginator->sort('id') ?></th>
<th><?= $this->Paginator->sort('product_category_id') ?></th>
<th><?= $this->Paginator->sort('product_id') ?></th>
<th><?= $this->Paginator->sort('product_sku_id') ?></th>
<th><?= $this->Paginator->sort('photo_filename') ?></th>
<th><?= $this->Paginator->sort('primary_photo') ?></th>
<th><?= $this->Paginator->sort('photo_position') ?></th>
<th><?= $this->Paginator->sort('enabled') ?></th>
<th><?= $this->Paginator->sort('created') ?></th>
<th><?= $this->Paginator->sort('modified') ?></th>
<th><?= $this->Paginator->sort('deleted') ?></th>
<th class="actions"><?= __('Actions') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($productPhotos as $productPhoto): ?>
<tr>
<td><?= h($productPhoto->id) ?></td>
<td><?= $productPhoto->hasValue('product_category') ? $this->Html->link($productPhoto->product_category->name, ['controller' => 'ProductCategories', 'action' => 'view', $productPhoto->product_category->internal_id]) : '' ?></td>
<td><?= $productPhoto->hasValue('product') ? $this->Html->link($productPhoto->product->name, ['controller' => 'Products', 'action' => 'view', $productPhoto->product->id]) : '' ?></td>
<td><?= $productPhoto->hasValue('product_sku') ? $this->Html->link($productPhoto->product_sku->sku, ['controller' => 'ProductSkus', 'action' => 'view', $productPhoto->product_sku->id]) : '' ?></td>
<td><?= h($productPhoto->photo_filename) ?></td>
<td><?= h($productPhoto->primary_photo) ?></td>
<td><?= $this->Number->format($productPhoto->photo_position) ?></td>
<td><?= h($productPhoto->enabled) ?></td>
<td><?= h($productPhoto->created) ?></td>
<td><?= h($productPhoto->modified) ?></td>
<td><?= h($productPhoto->deleted) ?></td>
<td class="actions">
<?= $this->Html->link(__('View'), ['action' => 'view', $productPhoto->id]) ?>
<?= $this->Html->link(__('Edit'), ['action' => 'edit', $productPhoto->id]) ?>
<?= $this->Form->postLink(__('Delete'), ['action' => 'delete', $productPhoto->id], ['confirm' => __('Are you sure you want to delete # {0}?', $productPhoto->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>

View File

@@ -0,0 +1,86 @@
<?php
/**
* @var \App\View\AppView $this
* @var \Cake\Datasource\EntityInterface $productPhoto
*/
?>
<div class="row">
<aside class="column">
<div class="side-nav">
<h4 class="heading"><?= __('Actions') ?></h4>
<?= $this->Html->link(__('Edit Product Photo'), ['action' => 'edit', $productPhoto->id], ['class' => 'side-nav-item']) ?>
<?= $this->Form->postLink(__('Delete Product Photo'), ['action' => 'delete', $productPhoto->id], ['confirm' => __('Are you sure you want to delete # {0}?', $productPhoto->id), 'class' => 'side-nav-item']) ?>
<?= $this->Html->link(__('List Product Photos'), ['action' => 'index'], ['class' => 'side-nav-item']) ?>
<?= $this->Html->link(__('New Product Photo'), ['action' => 'add'], ['class' => 'side-nav-item']) ?>
</div>
</aside>
<div class="column column-80">
<div class="productPhotos view content">
<h3><?= h($productPhoto->photo_filename) ?></h3>
<img src="<?= $this->Url->build([
'action' => 'image',
$productPhoto->id,
]); ?>" alt="<?= $productPhoto->id; ?>"/>
<table>
<tr>
<th><?= __('Id') ?></th>
<td><?= h($productPhoto->id) ?></td>
</tr>
<tr>
<th><?= __('Product Category') ?></th>
<td><?= $productPhoto->hasValue('product_category') ? $this->Html->link($productPhoto->product_category->name, ['controller' => 'ProductCategories', 'action' => 'view', $productPhoto->product_category->internal_id]) : '' ?></td>
</tr>
<tr>
<th><?= __('Product') ?></th>
<td><?= $productPhoto->hasValue('product') ? $this->Html->link($productPhoto->product->name, ['controller' => 'Products', 'action' => 'view', $productPhoto->product->id]) : '' ?></td>
</tr>
<tr>
<th><?= __('SKU') ?></th>
<td><?= $productPhoto->hasValue('product_sku') ? $this->Html->link($productPhoto->product_sku->sku, ['controller' => 'ProductSkus', 'action' => 'view', $productPhoto->product_sku->id]) : '' ?></td>
</tr>
<tr>
<th><?= __('Photo Filename') ?></th>
<td><?= h($productPhoto->photo_filename) ?></td>
</tr>
<tr>
<th><?= __('Photo Position') ?></th>
<td><?= $this->Number->format($productPhoto->photo_position) ?></td>
</tr>
<tr>
<th><?= __('Created') ?></th>
<td><?= h($productPhoto->created) ?></td>
</tr>
<tr>
<th><?= __('Modified') ?></th>
<td><?= h($productPhoto->modified) ?></td>
</tr>
<tr>
<th><?= __('Deleted') ?></th>
<td><?= h($productPhoto->deleted) ?></td>
</tr>
<tr>
<th><?= __('Primary Category Photo') ?></th>
<td><?= $productPhoto->primary_category_photo ? __('Yes') : __('No'); ?></td>
</tr>
<tr>
<th><?= __('Primary Photo') ?></th>
<td><?= $productPhoto->primary_photo ? __('Yes') : __('No'); ?></td>
</tr>
<tr>
<th><?= __('Primary SKU Photo') ?></th>
<td><?= $productPhoto->primary_sku_photo ? __('Yes') : __('No'); ?></td>
</tr>
<tr>
<th><?= __('Enabled') ?></th>
<td><?= $productPhoto->enabled ? __('Yes') : __('No'); ?></td>
</tr>
</table>
<div class="text">
<strong><?= __('Photo Dir') ?></strong>
<blockquote>
<?= $this->Text->autoParagraph(h($productPhoto->photo_dir)); ?>
</blockquote>
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,136 @@
<?php
use Cake\Log\Log;
use function BenTools\CartesianProduct\combinations;
/**
* @var \App\View\AppView $this
* @var \App\Model\Entity\ProductSku[] $productSkus
* @var \App\Model\Entity\ProductSku $product
* @var array $toGetCartesianProductsFrom
*/
?>
<div class="row">
<aside class="column">
<div class="side-nav">
<h4 class="heading"><?= __('Actions') ?></h4>
<?= $this->Html->link(__('View Product'), [
'controller' => 'Products',
'action' => 'view',
$product->id,
], ['class' => 'side-nav-item']) ?>
<?= $this->Html->link(__('List Product SKUs'), ['action' => 'index'], ['class' => 'side-nav-item']) ?>
</div>
</aside>
<div class="column column-80">
<div class="productSkus form content">
<?= $this->Form->create($productSkus) ?>
<fieldset>
<legend><?= __('Add Product SKU(s) for Product: ' . $product->name) ?></legend>
<div id="product-skus-container" class="container">
<table class="table">
<thead>
<tr>
<th>SKU</th>
<th>Barcode</th>
<th>Price</th>
<th>Cost</th>
<?php
$cnt = 0;
foreach ($variantNameMapping as $singleVariantName) : ?>
<th><?= $singleVariantName; ?></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php
$cnt = 0;
$labelFalse = ['label' => false];
$found = [];
foreach (combinations($toGetCartesianProductsFrom) as $c => $combination) : ?>
<?php
// $singleVariantId
$foundSku = null;
// dd($existingSkusForCartesianComparison);
foreach($existingSkusForCartesianComparison as $existingSkuForCartesianComparisonId => $existingSkuForCartesianComparison) {
$allMatch = false;
Log::debug(print_r(['$combination' => $combination, '$existingSkuForCartesianComparison' => $existingSkuForCartesianComparison], true));
if ($existingSkuForCartesianComparison == $combination) {
$foundSku = $existingSkuForCartesianComparisonId;
}
}
$found[$c] = $foundSku;
$addInputOptions = [
'label' => false,
'type' => 'checkbox',
'checked' => true,
'readonly' => isset($foundSku),
];
$skuInputOptions = [
'label' => false,
'required' => isset($foundSku),
'value' => $foundSku && isset($existingProductSkus[$foundSku]['sku']) ? $existingProductSkus[$foundSku]['sku'] : '',
];
// if ($foundSku) {
// dd($existingProductSkus[$foundSku]['sku']);
// }
?>
<tr>
<td>
<?= $this->Form->hidden($cnt . '.id', ['value' => $foundSku]); ?>
<?= $this->Form->control($cnt . '.sku', $skuInputOptions); ?>
</td>
<td><?= $this->Form->control($cnt . '.barcode', $labelFalse); ?></td>
<td><?= $this->Form->control($cnt . '.price', $labelFalse); ?></td>
<td><?= $this->Form->control($cnt . '.cost', $labelFalse); ?></td>
<?php
$variantCnt = 0;
if (isset($foundSku) && isset($existingProductSkus[$foundSku])) : ?>
<?php foreach ($existingProductSkus[$foundSku]['product_sku_variant_values'] as $existingVariantValueRecord) : ?>
<td>
<?= $this->Form->hidden($cnt . '.product_sku_variant_values.' . $variantCnt . '.id', ['value' => $existingVariantValueRecord->id]); ?>
<?= $this->Form->hidden($cnt . '.product_sku_variant_values.' . $variantCnt . '.product_sku_id', ['value' => $foundSku]); ?>
<?= $this->Form->hidden($cnt . '.product_sku_variant_values.' . $variantCnt . '.product_variant_id', ['value' => $existingVariantValueRecord->product_variant_id ?? null]); ?>
<?= $this->Form->hidden($cnt . '.product_sku_variant_values.' . $variantCnt . '.product_category_variant_option_id', ['value' => $existingVariantValueRecord->product_category_variant_option_id ?? null]); ?>
<?= $optionMapping[$combination[$existingVariantValueRecord->product_variant_id]]; ?>
</td>
<?php
$variantCnt++;
endforeach; ?>
<?php else : ?>
<?php foreach ($variantNameMapping as $singleVariantId => $singleVariantName) : ?>
<td>
<?= isset($foundSku) ? $this->Form->hidden($cnt . '.product_sku_variant_values.' . $variantCnt . '.product_sku_id', ['value' => $foundSku]) : ''; ?>
<?= $this->Form->hidden($cnt . '.product_sku_variant_values.' . $variantCnt . '.product_variant_id', ['value' => $productVariantsMapping[$singleVariantId] ?? null]); ?>
<?= $this->Form->hidden($cnt . '.product_sku_variant_values.' . $variantCnt . '.product_category_variant_option_id', ['value' => $combination[$productVariantsMapping[$singleVariantId]] ?? null]); ?>
<?= $optionMapping[$combination[$productVariantsMapping[$singleVariantId]]]; ?>
</td>
<?php
$variantCnt++;
endforeach; ?>
<?php endif; ?>
</tr>
<?php
$cnt++;
endforeach;
// dd($found);
?>
</tbody>
</table>
</div>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
</div>
</div>
</div>

View File

@@ -0,0 +1,30 @@
<?php
/**
* @var \App\View\AppView $this
* @var \Cake\Datasource\EntityInterface $productSku
*/
?>
<div class="row">
<aside class="column">
<div class="side-nav">
<h4 class="heading"><?= __('Actions') ?></h4>
<?= $this->Form->postLink(
__('Delete'),
['action' => 'delete', $productSku->id],
['confirm' => __('Are you sure you want to delete # {0}?', $productSku->id), 'class' => 'side-nav-item']
) ?>
<?= $this->Html->link(__('List Product Skus'), ['action' => 'index'], ['class' => 'side-nav-item']) ?>
</div>
</aside>
<div class="column column-80">
<div class="productSkus form content">
<?= $this->Form->create($productSku) ?>
<fieldset>
<legend><?= __('Edit Product Skus') ?></legend>
<?= $this->element('ProductSkus/form'); ?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
</div>
</div>
</div>

View File

@@ -0,0 +1,58 @@
<?php
/**
* @var \App\View\AppView $this
* @var iterable<\Cake\Datasource\EntityInterface> $productSkus
*/
?>
<div class="productSkus index content">
<?= $this->Html->link(__('New Product Skus'), ['action' => 'add'], ['class' => 'button float-right']) ?>
<h3><?= __('Product Skus') ?></h3>
<div class="table-responsive">
<table>
<thead>
<tr>
<th><?= $this->Paginator->sort('id') ?></th>
<th><?= $this->Paginator->sort('product_id') ?></th>
<th><?= $this->Paginator->sort('sku') ?></th>
<th><?= $this->Paginator->sort('barcode') ?></th>
<th><?= $this->Paginator->sort('price') ?></th>
<th><?= $this->Paginator->sort('cost') ?></th>
<th><?= $this->Paginator->sort('created') ?></th>
<th><?= $this->Paginator->sort('modified') ?></th>
<th><?= $this->Paginator->sort('deleted') ?></th>
<th class="actions"><?= __('Actions') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($productSkus as $productSku): ?>
<tr>
<td><?= h($productSku->id) ?></td>
<td><?= h($productSku->product_id) ?></td>
<td><?= h($productSku->sku) ?></td>
<td><?= h($productSku->barcode) ?></td>
<td><?= $productSku->price === null ? '' : $this->Number->format($productSku->price) ?></td>
<td><?= $productSku->cost === null ? '' : $this->Number->format($productSku->cost) ?></td>
<td><?= h($productSku->created) ?></td>
<td><?= h($productSku->modified) ?></td>
<td><?= h($productSku->deleted) ?></td>
<td class="actions">
<?= $this->Html->link(__('View'), ['action' => 'view', $productSku->id]) ?>
<?= $this->Html->link(__('Edit'), ['action' => 'edit', $productSku->id]) ?>
<?= $this->Form->postLink(__('Delete'), ['action' => 'delete', $productSku->id], ['confirm' => __('Are you sure you want to delete # {0}?', $productSku->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>

View File

@@ -0,0 +1,13 @@
<?php
/**
* @var \App\View\AppView $this
* @var iterable<\Cake\Datasource\EntityInterface> $productSkus
*/
$this->setLayout('ajax');
?>
<option value="">Select a SKU</option>
<?php foreach ($productSkus as $productSkuId => $productSku): ?>
<option value="<?= $productSkuId; ?>" <?= $this->request->getQuery('product_sku_id') == $productSkuId ? 'selected="selected"' : ''; ?>><?= $productSku; ?></option>
<?php endforeach; ?>

View File

@@ -0,0 +1,81 @@
<?php
/**
* @var \App\View\AppView $this
* @var \App\Model\Entity\ProductSkus $productSku
*/
?>
<div class="row">
<aside class="column">
<div class="side-nav">
<h4 class="heading"><?= __('Actions') ?></h4>
<?= $this->Html->link(__('Edit Product SKU'), ['action' => 'edit', $productSku->id], ['class' => 'side-nav-item']) ?>
<?= $this->Form->postLink(__('Delete Product SKU'), ['action' => 'delete', $productSku->id], ['confirm' => __('Are you sure you want to delete # {0}?', $productSku->id), 'class' => 'side-nav-item']) ?>
<?= $this->Html->link(__('List Product SKU'), ['action' => 'index'], ['class' => 'side-nav-item']) ?>
<?= $this->Html->link(__('New Product SKU'), ['action' => 'add'], ['class' => 'side-nav-item']) ?>
</div>
</aside>
<div class="column column-80">
<div class="productSkus view content">
<h3><?= h($productSku->sku) ?></h3>
<table>
<tr>
<th><?= __('Product') ?></th>
<td><?= $productSku->hasValue('product') ? $this->Html->link($productSku->product->name, ['controller' => 'Products', 'action' => 'view', $productSku->product->id]) : '' ?></td>
</tr>
<tr>
<th><?= __('Sku') ?></th>
<td><?= h($productSku->sku) ?></td>
</tr>
<tr>
<th><?= __('Barcode') ?></th>
<td><?= h($productSku->barcode) ?></td>
</tr>
<tr>
<th><?= __('Price') ?></th>
<td><?= $productSku->price === null ? '' : $this->Number->format($productSku->price) ?></td>
</tr>
<tr>
<th><?= __('Cost') ?></th>
<td><?= $productSku->cost === null ? '' : $this->Number->format($productSku->cost) ?></td>
</tr>
<tr>
<th><?= __('Created') ?></th>
<td><?= h($productSku->created) ?></td>
</tr>
<tr>
<th><?= __('Modified') ?></th>
<td><?= h($productSku->modified) ?></td>
</tr>
<tr>
<th><?= __('Deleted') ?></th>
<td><?= h($productSku->deleted) ?></td>
</tr>
</table>
<div class="related">
<h4><?= __('SKU Variant Attributes') ?></h4>
<?php if (!empty($productSku->product_sku_variant_values)) : ?>
<div class="table-responsive">
<table>
<?php foreach ($productSku->product_sku_variant_values as $variantValue) : ?>
<?php
if (!isset($variantValue->product_variant->product_category_variant)) {
continue;
}
if (!isset($variantValue->product_category_variant_option)) {
continue;
}
?>
<tr>
<th><?= h($variantValue->product_variant->product_category_variant->name) ?></th>
<td><?= h($variantValue->product_category_variant_option->variant_label ?? $variantValue->product_category_variant_option->variant_value) ?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>

View File

@@ -14,7 +14,7 @@
</aside> </aside>
<div class="column column-80"> <div class="column column-80">
<div class="products form content"> <div class="products form content">
<?= $this->Form->create($product) ?> <?= $this->Form->create($product, ['id' => 'main-form']) ?>
<fieldset> <fieldset>
<legend><?= __('Add Product') ?></legend> <legend><?= __('Add Product') ?></legend>
<?= $this->element('Products/form'); ?> <?= $this->element('Products/form'); ?>

View File

@@ -0,0 +1,13 @@
<?php
/**
* @var \App\View\AppView $this
* @var iterable<\Cake\Datasource\EntityInterface> $products
*/
$this->setLayout('ajax');
?>
<option value="">Select a Product</option>
<?php foreach ($products as $productId => $productName): ?>
<option value="<?= $productId; ?>" <?= $this->request->getQuery('product_id') == $productId ? 'selected="selected"' : ''; ?>><?= $productName; ?></option>
<?php endforeach; ?>

View File

@@ -32,5 +32,26 @@
</tr> </tr>
</table> </table>
</div> </div>
<div class="related">
<h4><?= __('Product Attributes') ?></h4>
<?php if (!empty($product->product_attributes)) : ?>
<div class="table-responsive">
<table>
<?php foreach ($product->product_attributes as $productAttribute) : ?>
<?php if (!$productAttribute->hasValue('product_category_attribute')) {
continue;
} ?>
<tr>
<th><?= h($productAttribute->product_category_attribute->name) ?></th>
<td>
<?= $productAttribute->hasValue('product_category_attribute_option') ? h($productAttribute->product_category_attribute_option->attribute_label) : ''; ?>
<?= !$productAttribute->hasValue('product_category_attribute_option') ? h($productAttribute->attribute_value) : ''; ?>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php endif; ?>
</div>
</div> </div>
</div> </div>

View File

@@ -26,5 +26,6 @@ echo $this->Form->control('parent_id', [
'empty' => true, 'empty' => true,
'id' => 'product_category_parent_id', 'id' => 'product_category_parent_id',
]); ]);
echo $this->Form->control('default_product_type_id');
echo $this->Form->control('enabled'); echo $this->Form->control('enabled');
?> ?>

View File

@@ -0,0 +1,42 @@
<?php
/**
* @var int $cnt
* @var \App\Model\Entity\ProductCategoryAttribute|\Cake\Datasource\EntityInterface $productCategoryAttribute
* @var \App\Model\Entity\ProductAttribute|\Cake\Datasource\EntityInterface|null $productAttribute
*/
use Cake\Utility\Hash;
use CakeProducts\Model\Enum\ProductCategoryAttributeTypeId;
if (($productAttribute ?? false)) {
echo $this->Form->hidden('product_attributes.' . $cnt . '.id', ['value' => $productAttribute->id]);
}
echo $this->Form->hidden('product_attributes.' . $cnt . '.product_category_attribute_id', [
'value' => $productCategoryAttribute->id,
]);
$inputType = 'text';
$options = [];
if ($productCategoryAttribute->attribute_type_id === ProductCategoryAttributeTypeId::Integer) {
$inputType = 'number';
}
if ($productCategoryAttribute->attribute_type_id === ProductCategoryAttributeTypeId::Constrained) {
echo $this->Form->hidden('product_attributes.' . $cnt . '.attribute_value', [
'value' => '',
]);
$options = !empty($productCategoryAttribute->product_category_attribute_options) ?
Hash::combine($productCategoryAttribute->product_category_attribute_options, '{n}.id', '{n}.attribute_label') :
[];
echo $this->Form->control('product_attributes.' . $cnt . '.product_category_attribute_option_id', [
'type' => 'select',
'label' => $productCategoryAttribute->name,
'options' => $options,
'value' => $productAttribute->product_category_attribute_option_id ?? '',
]);
} else {
echo $this->Form->control('product_attributes.' . $cnt . '.attribute_value', [
'type' => $inputType,
'label' => $productCategoryAttribute->name,
]);
}
?>

View File

@@ -0,0 +1,31 @@
<?php
/**
* @var array $productCategories
* @var array $products
* @var \CakeProducts\Model\Entity\ProductCategoryVariant|\Cake\Datasource\EntityInterface $productCategoryVariant
*/
$nameOptions = [];
$categoryOptions = ['options' => $productCategories, 'empty' => true];
$enabledOptions = [];
if ($productCategoryVariant->is_system_variant) {
$nameOptions = [
'disabled' => true,
'readonly' => true,
];
$categoryOptions = $categoryOptions + [
'disabled' => true,
'readonly' => true,
];
$enabledOptions = [
'disabled' => true,
'readonly' => true,
];
}
echo $this->Form->control('name', $nameOptions);
echo $this->Form->control('product_category_id', $categoryOptions);
echo $this->Form->control('enabled', $enabledOptions);
?>
<legend><?= __('Variant Options') . '<small class="ms-2">' . $this->Html->link('Add Option', '#', [
'id' => 'add-option-button',
]) . '</small>'; ?></legend>

View File

@@ -0,0 +1,32 @@
<?php
/**
* @var \App\View\AppView $this
* @var \Cake\Datasource\EntityInterface $productCategoryAttributeOption
*/
$cnt = 0;
$prefix = $prefix ?? '';
\Cake\Log\Log::debug('$prefix');
\Cake\Log\Log::debug($prefix);
?>
<div class="container product-category-variant-options-container" data-test="1" data-prefix="<?= $prefix; ?>">
<div class="row">
<div class="col">
<?= $this->Form->control($prefix . 'variant_value', [
'label' => 'Value',
]); ?>
</div>
<div class="col">
<?= $this->Form->control($prefix . 'variant_label', [
'label' => 'Label',
]); ?>
</div>
<div class="col">
<?= $this->Form->control($prefix . 'enabled', [
'type' => 'checkbox',
'checked' => true,
'label' => 'Enabled',
]); ?>
</div>
</div>
</div>

View File

@@ -0,0 +1,60 @@
<?php
/**
* @var \App\View\AppView $this
* @var \CakeProducts\Model\Entity\Product[]|\Cake\Datasource\EntityInterface[] $products
* @var \CakeProducts\Model\Entity\Product[]|\Cake\Datasource\EntityInterface[] $productSkus
* @var bool $includeFile
*/
$includeFile = $includeFile ?? false;
echo $this->Form->control('product_catalog_id', [
'empty' => 'Select a Catalog',
'options' => $productCatalogs ?? [],
'hx-trigger' => 'change, load delay:500ms',
'hx-get' => $this->Url->build([
'controller' => 'ProductCategories',
'action' => 'select',
'?' => ['form' => 'product_photo'],
]),
'hx-target' => '#product_category_id',
]);
echo $this->Form->control('product_category_id', [
'options' => [],
'empty' => true,
'id' => 'product_category_id',
'hx-trigger' => 'change, load delay:1s',
'hx-get' => $this->Url->build([
'controller' => 'Products',
'action' => 'select',
'?' => ['form' => 'product_photo'],
]),
'hx-target' => '#product_id',
]);
echo $this->Form->control('product_id', [
'options' => $products ?? [],
'empty' => true,
'hx-trigger' => 'change, load delay:1s',
'id' => 'product_id',
'hx-get' => $this->Url->build([
'controller' => 'ProductSkus',
'action' => 'select',
'?' => ['form' => 'product'],
]),
'hx-target' => '#product_sku_id',
]);
echo $this->Form->control('product_sku_id', [
'options' => $productSkus ?? [],
'empty' => true,
'id' => 'product_sku_id',
]);
echo $includeFile ? $this->Form->control('photo', [
'type' => 'file',
]) : '';
echo $this->Form->control('primary_photo');
echo $this->Form->control('primary_category_photo');
echo $this->Form->control('photo_position');
echo $this->Form->control('enabled');
?>

View File

@@ -0,0 +1,7 @@
<?php
echo $this->Form->control('product_id');
echo $this->Form->control('sku');
echo $this->Form->control('barcode');
echo $this->Form->control('price');
echo $this->Form->control('cost');
?>

View File

@@ -12,33 +12,60 @@
<?php <?php
echo $this->Form->control('name'); echo $this->Form->control('name');
echo $this->Form->control('product_catalog_id', [ echo $this->Form->control('product_catalog_id', [
'empty' => 'Select a Catalog',
'options' => $productCatalogs, 'options' => $productCatalogs,
'hx-trigger' => 'change, load delay:1s', 'hx-trigger' => 'change, load delay:500ms',
'hx-get' => $this->Url->build([ 'hx-get' => $this->Url->build([
'controller' => 'ProductCategories', 'controller' => 'ProductCategories',
'action' => 'select', 'action' => 'select',
'?' => ['form' => 'product'],
0 => $productCategory ? $productCategory->product_catalog_id : '', 0 => $productCategory ? $productCategory->product_catalog_id : '',
]), ]),
'hx-target' => '#product_category_id', 'hx-target' => '#product_category_id',
]); ]);
echo $this->Form->control('product_category_id', [ echo $this->Form->control('product_category_id', [
'options' => $productCategories ?? [], 'options' => [],
'empty' => true, 'empty' => true,
'id' => 'product_category_id', 'id' => 'product_category_id',
'hx-trigger' => 'change, load delay:1s',
'hx-get' => $this->Url->build([
'controller' => 'ProductCategoryAttributes',
'action' => 'form',
'?' => ['form' => 'product'],
0 => $productCategory ? $productCategory->product_catalog_id : '',
]),
'hx-target' => '#product-attributes-container',
]); ]);
echo $this->Form->control('product_type_id'); echo $this->Form->control('product_type_id');
?> ?>
<hr> <hr>
<h4 class="mb-4">Product Attributes</h4> <h4 class="mb-4">Product Attributes</h4>
<div id="product-attributes-container" class="container"> <div
<?php if (false && $product->hasValue('product_attributes')) : ?> id="product-attributes-container"
<?php class="container"
<?php if ($product->isNew()) : ?>
hx-get="<?= $this->Url->build([
'controller' => 'ProductCategoryAttributes',
'action' => 'form',
]); ?>"
hx-trigger="change target:#product_category_id from:body"
hx-target="this"
hx-include="#form, #product_category_id"
hx-swap="innerHTML"
<?php endif; ?>
>
<?php if ($product->hasValue('product_attributes')) : ?>
<?php
$cnt = 0; $cnt = 0;
foreach ($product->product_attributes as $productAttribute) { foreach ($product->product_attributes as $productAttribute) {
$prefix = 'product_attributes.' . $cnt . '.'; $prefix = 'product_attributes.' . $cnt . '.';
echo '<hr class="my-2">'; echo $this->element('ProductCategoryAttributes/product_form', [
'productCategoryAttribute' => $productAttribute->hasValue('product_category_attribute') ? $productAttribute->product_category_attribute : null,
'productAttribute' => $productAttribute,
'cnt' => $cnt,
]);
$cnt++; $cnt++;
} ?> } ?>
<?php endif; ?> <?php endif; ?>

View File

@@ -23,7 +23,7 @@ class ExternalProductCatalogsFixture extends TestFixture
'base_url' => 'http://localhost:8766', 'base_url' => 'http://localhost:8766',
'api_url' => 'http://localhost:8766/api', 'api_url' => 'http://localhost:8766/api',
'created' => '2024-11-22 09:39:37', 'created' => '2024-11-22 09:39:37',
'deleted' => '2024-11-22 09:39:37', 'deleted' => null,
], ],
]; ];
parent::init(); parent::init();

View File

@@ -19,10 +19,12 @@ class ExternalProductCatalogsProductCatalogsFixture extends TestFixture
{ {
$this->records = [ $this->records = [
[ [
'id' => 1,
'external_product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205769999', 'external_product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205769999',
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
'created' => '2024-11-22 09:39:37', 'created' => '2024-11-22 09:39:37',
'enabled' => false, 'enabled' => false,
'deleted' => null,
], ],
]; ];
parent::init(); parent::init();

View File

@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace CakeProducts\Test\Fixture;
use Cake\TestSuite\Fixture\TestFixture;
/**
* ProductAttributesFixture
*/
class ProductAttributesFixture extends TestFixture
{
/**
* Init method
*
* @return void
*/
public function init(): void
{
$this->records = [
];
parent::init();
}
}

View File

@@ -23,12 +23,14 @@ class ProductCatalogsFixture extends TestFixture
'name' => 'Automotive', 'name' => 'Automotive',
'catalog_description' => '', 'catalog_description' => '',
'enabled' => true, 'enabled' => true,
'deleted' => null,
], ],
[ [
'id' => 'f56f3412-ed23-490b-be6e-016208c415d2', 'id' => 'f56f3412-ed23-490b-be6e-016208c415d2',
'name' => 'Software', 'name' => 'Software',
'catalog_description' => '', 'catalog_description' => '',
'enabled' => true, 'enabled' => true,
'deleted' => null,
], ],
]; ];
parent::init(); parent::init();

View File

@@ -28,6 +28,7 @@ class ProductCategoriesFixture extends TestFixture
'lft' => 1, 'lft' => 1,
'rght' => 4, 'rght' => 4,
'enabled' => true, 'enabled' => true,
'deleted' => null,
], ],
[ [
'id' => 2, 'id' => 2,
@@ -39,6 +40,7 @@ class ProductCategoriesFixture extends TestFixture
'lft' => 2, 'lft' => 2,
'rght' => 3, 'rght' => 3,
'enabled' => true, 'enabled' => true,
'deleted' => null,
], ],
[ [
'id' => 3, 'id' => 3,
@@ -50,6 +52,7 @@ class ProductCategoriesFixture extends TestFixture
'lft' => 5, 'lft' => 5,
'rght' => 8, 'rght' => 8,
'enabled' => true, 'enabled' => true,
'deleted' => null,
], ],
[ [
'id' => 4, 'id' => 4,
@@ -61,6 +64,7 @@ class ProductCategoriesFixture extends TestFixture
'lft' => 6, 'lft' => 6,
'rght' => 7, 'rght' => 7,
'enabled' => true, 'enabled' => true,
'deleted' => null,
], ],
[ [
'id' => 5, 'id' => 5,
@@ -72,6 +76,7 @@ class ProductCategoriesFixture extends TestFixture
'lft' => 9, 'lft' => 9,
'rght' => 12, 'rght' => 12,
'enabled' => true, 'enabled' => true,
'deleted' => null,
], ],
[ [
'id' => 6, 'id' => 6,
@@ -83,6 +88,7 @@ class ProductCategoriesFixture extends TestFixture
'lft' => 10, 'lft' => 10,
'rght' => 11, 'rght' => 11,
'enabled' => true, 'enabled' => true,
'deleted' => null,
], ],
[ [
'id' => 7, 'id' => 7,
@@ -94,6 +100,7 @@ class ProductCategoriesFixture extends TestFixture
'lft' => 1, 'lft' => 1,
'rght' => 2, 'rght' => 2,
'enabled' => true, 'enabled' => true,
'deleted' => null,
], ],
]; ];
parent::init(); parent::init();

View File

@@ -21,10 +21,27 @@ class ProductCategoryAttributeOptionsFixture extends TestFixture
[ [
'id' => 'e06f1723-2456-483a-b3c4-004603e032a8', 'id' => 'e06f1723-2456-483a-b3c4-004603e032a8',
'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c', 'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
'attribute_value' => 'Lorem ipsum dolor sit amet', 'attribute_value' => 'Red',
'attribute_label' => 'Lorem ipsum dolor sit amet', 'attribute_label' => 'Red',
'enabled' => 1, '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(); parent::init();
} }

View File

@@ -24,6 +24,7 @@ class ProductCategoryAttributesFixture extends TestFixture
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'attribute_type_id' => 1, 'attribute_type_id' => 1,
'enabled' => 1, 'enabled' => 1,
'deleted' => null,
], ],
]; ];
parent::init(); parent::init();

View File

@@ -0,0 +1,99 @@
<?php
declare(strict_types=1);
namespace CakeProducts\Test\Fixture;
use Cake\TestSuite\Fixture\TestFixture;
/**
* ProductCategoryVariantsFixture
*/
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,
],
[
'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();
}
}

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