From d239a98e8e001196084066ebdac30d2c02d72742 Mon Sep 17 00:00:00 2001 From: Brandon Shipley Date: Sat, 1 Nov 2025 23:16:59 -0700 Subject: [PATCH] unique rules, allow product id to be null in product photos --- ..._AllowProductIdToBeNullInProductPhotos.php | 25 +++++++++++++++++++ src/Model/Entity/ProductPhoto.php | 6 +++-- .../ProductCategoryAttributeOptionsTable.php | 1 + .../ProductCategoryVariantOptionsTable.php | 1 + 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 config/Migrations/20251101150009_AllowProductIdToBeNullInProductPhotos.php diff --git a/config/Migrations/20251101150009_AllowProductIdToBeNullInProductPhotos.php b/config/Migrations/20251101150009_AllowProductIdToBeNullInProductPhotos.php new file mode 100644 index 0000000..a18fb7c --- /dev/null +++ b/config/Migrations/20251101150009_AllowProductIdToBeNullInProductPhotos.php @@ -0,0 +1,25 @@ +table('product_photos'); + $table->changeColumn('product_id', 'uuid', [ + 'default' => null, + 'limit' => 11, + 'null' => true, + ]); + $table->update(); + } +} diff --git a/src/Model/Entity/ProductPhoto.php b/src/Model/Entity/ProductPhoto.php index a925d3a..4a3056e 100644 --- a/src/Model/Entity/ProductPhoto.php +++ b/src/Model/Entity/ProductPhoto.php @@ -10,7 +10,7 @@ use Cake\ORM\Entity; * ProductPhoto Entity * * @property string $id - * @property string $product_id + * @property string|null $product_id * @property string|null $product_category_id * @property string|null $product_sku_id * @property string $photo_dir @@ -55,6 +55,8 @@ class ProductPhoto extends Entity 'deleted' => true, // entities - 'product' => true, + 'product' => false, + 'product_sku' => false, + 'product_category' => false, ]; } diff --git a/src/Model/Table/ProductCategoryAttributeOptionsTable.php b/src/Model/Table/ProductCategoryAttributeOptionsTable.php index e224c6a..54e1e57 100644 --- a/src/Model/Table/ProductCategoryAttributeOptionsTable.php +++ b/src/Model/Table/ProductCategoryAttributeOptionsTable.php @@ -108,6 +108,7 @@ class ProductCategoryAttributeOptionsTable extends Table public function buildRules(RulesChecker $rules): RulesChecker { $rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']); + $rules->add($rules->isUnique(['attribute_value', 'product_category_attribute_id'])); return $rules; } diff --git a/src/Model/Table/ProductCategoryVariantOptionsTable.php b/src/Model/Table/ProductCategoryVariantOptionsTable.php index 954ec11..f564fa4 100644 --- a/src/Model/Table/ProductCategoryVariantOptionsTable.php +++ b/src/Model/Table/ProductCategoryVariantOptionsTable.php @@ -105,6 +105,7 @@ class ProductCategoryVariantOptionsTable extends Table 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; }