From ce498a2d456e19c178ceebf15277f40b2b356f9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Witold=20Wis=CC=81niewski?= Date: Thu, 5 Dec 2024 07:17:59 +0100 Subject: [PATCH 1/4] fix docs --- docs/api.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/api.yml b/docs/api.yml index 3124d537b..4311b2df5 100644 --- a/docs/api.yml +++ b/docs/api.yml @@ -342,6 +342,10 @@ paths: $ref: './paths/Redirects.yml#/RedirectsParams' /email: $ref: './paths/Emails.yml#/Emails' + /manufacturers: + $ref: './paths/Manufacturers.yml#/Manufacturers' + /manufacturers/id:{id}: + $ref: './paths/Manufacturers.yml#/ManufacturersParams' components: schemas: Error: From d571655bce0763b78b3758c3f0c472688b27db80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Witold=20Wis=CC=81niewski?= Date: Thu, 5 Dec 2024 11:39:26 +0100 Subject: [PATCH 2/4] Fix manufacturers --- app/Http/Requests/ProductCreateRequest.php | 3 ++- app/Http/Requests/ProductUpdateRequest.php | 2 +- .../Criteria/ManufacturerSearch.php | 26 ++++++++++++------- src/Domain/Product/Dtos/ProductCreateDto.php | 1 - src/Domain/Product/Dtos/ProductUpdateDto.php | 1 - 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/app/Http/Requests/ProductCreateRequest.php b/app/Http/Requests/ProductCreateRequest.php index 55fbd58fa..de282b54b 100644 --- a/app/Http/Requests/ProductCreateRequest.php +++ b/app/Http/Requests/ProductCreateRequest.php @@ -29,11 +29,12 @@ public function rules(): array 'id' => ['uuid'], 'translations' => [ 'required', - new Translations(['name', 'description_html', 'description_short']), + new Translations(['name', 'description_html', 'description_short', 'safety_information']), ], 'translations.*.name' => ['required', 'string', 'max:255'], 'translations.*.description_html' => ['nullable', 'string'], 'translations.*.description_short' => ['nullable', 'string'], + 'translations.*.safety_information' => ['nullable', 'string'], 'published' => ['required', 'array', 'min:1'], 'published.*' => ['uuid', 'exists:languages,id'], diff --git a/app/Http/Requests/ProductUpdateRequest.php b/app/Http/Requests/ProductUpdateRequest.php index 2cd4324d3..7fa7f2b75 100644 --- a/app/Http/Requests/ProductUpdateRequest.php +++ b/app/Http/Requests/ProductUpdateRequest.php @@ -33,7 +33,7 @@ public function rules(): array $rules['published'] = ['nullable', 'array', 'min:1']; $rules['translations'] = [ 'nullable', - new Translations(['name', 'description_html', 'description_short']), + new Translations(['name', 'description_html', 'description_short', 'safety_information']), ]; $rules['banner'] = ['nullable', 'array']; diff --git a/src/Domain/Manufacturer/Criteria/ManufacturerSearch.php b/src/Domain/Manufacturer/Criteria/ManufacturerSearch.php index 6d39ea989..1392c399e 100644 --- a/src/Domain/Manufacturer/Criteria/ManufacturerSearch.php +++ b/src/Domain/Manufacturer/Criteria/ManufacturerSearch.php @@ -19,19 +19,25 @@ public function query(Builder $query): Builder { return $query->where( fn (Builder $query) => $query - ->where('name', 'LIKE', '%' . $this->value . '%') - ->orWhere('first_name', 'LIKE', '%' . $this->value . '%') - ->orWhere('last_name', 'LIKE', '%' . $this->value . '%') + ->where(fn (Builder $query) => $query + ->where('name', 'LIKE', '%' . $this->value . '%') + ->orWhere('first_name', 'LIKE', '%' . $this->value . '%') + ->orWhere('last_name', 'LIKE', '%' . $this->value . '%') + ->orWhereRaw("CONCAT(first_name, ' ', last_name) LIKE ?", ['%' . $this->value . '%']) + ) ->orWhereHas( 'address', fn (Builder $query) => $query - ->orWhere('name', 'LIKE', '%' . $this->value . '%') - ->orWhere('phone', 'LIKE', '%' . $this->value . '%') - ->orWhere('address', 'LIKE', '%' . $this->value . '%') - ->orWhere('vat', 'LIKE', '%' . $this->value . '%') - ->orWhere('zip', 'LIKE', '%' . $this->value . '%') - ->orWhere('city', 'LIKE', '%' . $this->value . '%') - ->orWhere('country', 'LIKE', '%' . $this->value . '%'), + ->where(fn (Builder $query) => $query + ->orWhere('addresses.name', 'LIKE', '%' . $this->value . '%') + ->orWhere('addresses.phone', 'LIKE', '%' . $this->value . '%') + ->orWhere('addresses.address', 'LIKE', '%' . $this->value . '%') + ->orWhere('addresses.vat', 'LIKE', '%' . $this->value . '%') + ->orWhere('addresses.zip', 'LIKE', '%' . $this->value . '%') + ->orWhere('addresses.city', 'LIKE', '%' . $this->value . '%') + ->orWhere('addresses.country', 'LIKE', '%' . $this->value . '%'), + ) + ), ); } diff --git a/src/Domain/Product/Dtos/ProductCreateDto.php b/src/Domain/Product/Dtos/ProductCreateDto.php index 14ac0b1d7..3549c09a9 100644 --- a/src/Domain/Product/Dtos/ProductCreateDto.php +++ b/src/Domain/Product/Dtos/ProductCreateDto.php @@ -72,7 +72,6 @@ public function __construct( public array $published, public Optional|ProductBannerMediaCreateDto|null $banner, public Optional|string|null $manufacturer_id, - public Optional|string|null $safety_information, ) { $this->metadata_computed = Map::toMetadata($metadata_public, $metadata_private); } diff --git a/src/Domain/Product/Dtos/ProductUpdateDto.php b/src/Domain/Product/Dtos/ProductUpdateDto.php index fd11d749e..e9986ed1e 100644 --- a/src/Domain/Product/Dtos/ProductUpdateDto.php +++ b/src/Domain/Product/Dtos/ProductUpdateDto.php @@ -61,7 +61,6 @@ public function __construct( public array|Optional $published, public Optional|ProductBannerMediaUpdateDto|null $banner, public Optional|string|null $manufacturer_id, - public Optional|string|null $safety_information, ) { $this->metadata_computed = new Optional(); } From 1255cae04e90d665145d321e00a667e758302d79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Witold=20Wis=CC=81niewski?= Date: Thu, 5 Dec 2024 11:43:42 +0100 Subject: [PATCH 3/4] Fix style --- src/Domain/Manufacturer/Criteria/ManufacturerSearch.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Domain/Manufacturer/Criteria/ManufacturerSearch.php b/src/Domain/Manufacturer/Criteria/ManufacturerSearch.php index 1392c399e..eb08959e7 100644 --- a/src/Domain/Manufacturer/Criteria/ManufacturerSearch.php +++ b/src/Domain/Manufacturer/Criteria/ManufacturerSearch.php @@ -19,11 +19,12 @@ public function query(Builder $query): Builder { return $query->where( fn (Builder $query) => $query + // @phpstan-ignore-next-line ->where(fn (Builder $query) => $query ->where('name', 'LIKE', '%' . $this->value . '%') ->orWhere('first_name', 'LIKE', '%' . $this->value . '%') ->orWhere('last_name', 'LIKE', '%' . $this->value . '%') - ->orWhereRaw("CONCAT(first_name, ' ', last_name) LIKE ?", ['%' . $this->value . '%']) + ->orWhereRaw("CONCAT(first_name, ' ', last_name) LIKE ?", ['%' . $this->value . '%']), ) ->orWhereHas( 'address', @@ -36,8 +37,7 @@ public function query(Builder $query): Builder ->orWhere('addresses.zip', 'LIKE', '%' . $this->value . '%') ->orWhere('addresses.city', 'LIKE', '%' . $this->value . '%') ->orWhere('addresses.country', 'LIKE', '%' . $this->value . '%'), - ) - + ), ), ); } From 5b5011ff22357c7827a23d10c2575a3fd1313d09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Witold=20Wis=CC=81niewski?= Date: Thu, 5 Dec 2024 11:51:23 +0100 Subject: [PATCH 4/4] fix tests --- tests/Feature/Products/ProductCreateTest.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/Feature/Products/ProductCreateTest.php b/tests/Feature/Products/ProductCreateTest.php index ffc4843b8..1b59fdc35 100644 --- a/tests/Feature/Products/ProductCreateTest.php +++ b/tests/Feature/Products/ProductCreateTest.php @@ -295,6 +295,7 @@ public function testCreateWithManufacturer(string $user): void 'translations' => [ $this->lang => [ 'name' => 'Test', + 'safety_information' => 'Safety', ], ], 'published' => [$this->lang], @@ -303,7 +304,6 @@ public function testCreateWithManufacturer(string $user): void 'public' => true, 'shipping_digital' => false, 'manufacturer_id' => $manufacturer->getKey(), - 'safety_information' => 'Safety', ]) ->assertCreated() ->assertJsonFragment([ @@ -666,7 +666,12 @@ public function testUpdateManufacturer(string $user): void ->actingAs($this->{$user}) ->json('PATCH', "/products/id:{$product->getKey()}", [ 'manufacturer_id' => $manufacturer->getKey(), - 'safety_information' => 'Safety', + 'translations' => [ + $this->lang => [ + 'name' => $product->name, + 'safety_information' => 'Safety', + ] + ], ]) ->assertOk() ->assertJsonFragment([