From 91f13c9e9fc8c86b03cbca45477f9909dfbf8cf7 Mon Sep 17 00:00:00 2001 From: Ervin Molnar <58359015+molnarerwin@users.noreply.github.com> Date: Mon, 3 Feb 2025 10:22:51 +0200 Subject: [PATCH 1/5] Added GTIN field to products and master_product_variants tables --- Changelog.md | 3 +- ..._gtin_to_master_product_variants_table.php | 28 +++++++++++++++++++ ...2_03_091939_add_gtin_to_products_table.php | 28 +++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/MasterProduct/resources/database/migrations/2025_02_03_092306_add_gtin_to_master_product_variants_table.php create mode 100644 src/Product/resources/database/migrations/2025_02_03_091939_add_gtin_to_products_table.php diff --git a/Changelog.md b/Changelog.md index 282138bd..d5986512 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,11 +3,12 @@ ## 5.x Series ## Unreleased -##### 2024-04-XX +##### 2025-XX-XX - Dropped PHP 8.2 Support - Dropped Laravel 10 Support - Added Laravel 12 Support +- Added the `gtin` field to the products and master product variants tables ## 4.x Series diff --git a/src/MasterProduct/resources/database/migrations/2025_02_03_092306_add_gtin_to_master_product_variants_table.php b/src/MasterProduct/resources/database/migrations/2025_02_03_092306_add_gtin_to_master_product_variants_table.php new file mode 100644 index 00000000..dc60a59f --- /dev/null +++ b/src/MasterProduct/resources/database/migrations/2025_02_03_092306_add_gtin_to_master_product_variants_table.php @@ -0,0 +1,28 @@ +string('gtin')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('master_product_variants', function (Blueprint $table) { + $table->dropColumn('gtin'); + }); + } +}; diff --git a/src/Product/resources/database/migrations/2025_02_03_091939_add_gtin_to_products_table.php b/src/Product/resources/database/migrations/2025_02_03_091939_add_gtin_to_products_table.php new file mode 100644 index 00000000..6e410408 --- /dev/null +++ b/src/Product/resources/database/migrations/2025_02_03_091939_add_gtin_to_products_table.php @@ -0,0 +1,28 @@ +string('gtin')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('products', function (Blueprint $table) { + $table->dropColumn('gtin'); + }); + } +}; From d6be48dded825d7d5d45d162395b0dab39135a3f Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Mon, 3 Feb 2025 08:23:49 +0000 Subject: [PATCH 2/5] Apply fixes from StyleCI --- ...2_03_092306_add_gtin_to_master_product_variants_table.php | 5 +++-- .../2025_02_03_091939_add_gtin_to_products_table.php | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/MasterProduct/resources/database/migrations/2025_02_03_092306_add_gtin_to_master_product_variants_table.php b/src/MasterProduct/resources/database/migrations/2025_02_03_092306_add_gtin_to_master_product_variants_table.php index dc60a59f..7fe38c8d 100644 --- a/src/MasterProduct/resources/database/migrations/2025_02_03_092306_add_gtin_to_master_product_variants_table.php +++ b/src/MasterProduct/resources/database/migrations/2025_02_03_092306_add_gtin_to_master_product_variants_table.php @@ -1,11 +1,12 @@ Date: Mon, 3 Feb 2025 10:33:05 +0200 Subject: [PATCH 3/5] Updated the GTIN field related changelog entry --- Changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index d5986512..aefe9c4f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,7 +8,7 @@ - Dropped PHP 8.2 Support - Dropped Laravel 10 Support - Added Laravel 12 Support -- Added the `gtin` field to the products and master product variants tables +- Added the `gtin` field to products and master product variants tables ## 4.x Series From 995ea53779d361e90aca1486a9f64e60ee9dc487 Mon Sep 17 00:00:00 2001 From: Ervin Molnar <58359015+molnarerwin@users.noreply.github.com> Date: Mon, 3 Feb 2025 10:45:18 +0200 Subject: [PATCH 4/5] Just for CI trigger --- Changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index aefe9c4f..d5986512 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,7 +8,7 @@ - Dropped PHP 8.2 Support - Dropped Laravel 10 Support - Added Laravel 12 Support -- Added the `gtin` field to products and master product variants tables +- Added the `gtin` field to the products and master product variants tables ## 4.x Series From 7d48d99ec910797547f9354d9e41b80ea18b8982 Mon Sep 17 00:00:00 2001 From: Ervin Molnar <58359015+molnarerwin@users.noreply.github.com> Date: Mon, 3 Feb 2025 11:20:26 +0200 Subject: [PATCH 5/5] Added product and variant gtin field tests --- .../Tests/Unit/MasterProductVariantTest.php | 38 +++++++++++++++++++ .../Tests/BaseProductAttributesTest.php | 22 ++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/src/MasterProduct/Tests/Unit/MasterProductVariantTest.php b/src/MasterProduct/Tests/Unit/MasterProductVariantTest.php index 669616d7..5ba43876 100644 --- a/src/MasterProduct/Tests/Unit/MasterProductVariantTest.php +++ b/src/MasterProduct/Tests/Unit/MasterProductVariantTest.php @@ -125,4 +125,42 @@ public function a_variant_does_not_have_meta_description() $this->assertNull($variant->meta_description); } + + /** @test */ + public function the_variant_gtin_field_can_be_set(): void + { + $master = MasterProduct::create([ + 'name' => 'Kosmodisk', + ]); + + $variant = MasterProductVariant::create([ + 'master_product_id' => $master->id, + 'sku' => 'kosmodisk', + 'gtin' => '777888999' + ]); + + $this->assertEquals('777888999', $variant->gtin); + } + + /** @test */ + public function the_variant_gtin_field_is_nullable(): void + { + $master = MasterProduct::create([ + 'name' => 'Kosmodisk', + ]); + + $variant = MasterProductVariant::create([ + 'master_product_id' => $master->id, + 'sku' => 'kosmodisk', + 'gtin' => '777888999' + ]); + + $variant->update([ + 'gtin' => null, + ]); + + $variant->fresh(); + + $this->assertNull($variant->gtin); + } } diff --git a/src/Product/Tests/BaseProductAttributesTest.php b/src/Product/Tests/BaseProductAttributesTest.php index 01ce752a..5626b7c0 100644 --- a/src/Product/Tests/BaseProductAttributesTest.php +++ b/src/Product/Tests/BaseProductAttributesTest.php @@ -63,7 +63,8 @@ public function all_fields_can_be_properly_set() 'description' => 'Maxi Baxi 2000 makes your dreams come true. See: https://youtu.be/5RKM_VLEbOc', 'state' => 'active', 'meta_keywords' => 'maxi, baxi, dreams', - 'meta_description' => 'The THING you always have dreamt of' + 'meta_description' => 'The THING you always have dreamt of', + 'gtin' => '8675309', ]); $this->assertGreaterThanOrEqual(1, $product->id); @@ -80,6 +81,7 @@ public function all_fields_can_be_properly_set() $this->assertEquals('active', $product->state->value()); $this->assertEquals('maxi, baxi, dreams', $product->meta_keywords); $this->assertEquals('The THING you always have dreamt of', $product->meta_description); + $this->assertEquals('8675309', $product->gtin); } /** @@ -160,4 +162,22 @@ public function find_by_sku_returns_null_if_no_product_was_found_by_the_requeste { $this->assertNull(Product::findBySku('Oh man such SKU could not exist in the Wild. Nor in a lab')); } + + /** @test */ + public function the_product_gtin_field_is_nullable(): void + { + $product = Product::create([ + 'name' => 'Kosmodisk', + 'sku' => 'kosmodisk', + 'gtin' => '9876543210', + ]); + + $product->update([ + 'gtin' => null, + ]); + + $product->fresh(); + + $this->assertNull($product->gtin); + } }