Skip to content

Commit

Permalink
Merge pull request #104 from heseya/feature/SK-923
Browse files Browse the repository at this point in the history
Fix manufacturers
  • Loading branch information
daVitekPL authored Dec 6, 2024
2 parents 6477b3f + 5b5011f commit ea533a9
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 16 deletions.
3 changes: 2 additions & 1 deletion app/Http/Requests/ProductCreateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/ProductUpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down
4 changes: 4 additions & 0 deletions docs/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 16 additions & 10 deletions src/Domain/Manufacturer/Criteria/ManufacturerSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 . '%')
// @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 . '%']),
)
->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 . '%'),
),
),
);
}
Expand Down
1 change: 0 additions & 1 deletion src/Domain/Product/Dtos/ProductCreateDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 0 additions & 1 deletion src/Domain/Product/Dtos/ProductUpdateDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
9 changes: 7 additions & 2 deletions tests/Feature/Products/ProductCreateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ public function testCreateWithManufacturer(string $user): void
'translations' => [
$this->lang => [
'name' => 'Test',
'safety_information' => 'Safety',
],
],
'published' => [$this->lang],
Expand All @@ -303,7 +304,6 @@ public function testCreateWithManufacturer(string $user): void
'public' => true,
'shipping_digital' => false,
'manufacturer_id' => $manufacturer->getKey(),
'safety_information' => 'Safety',
])
->assertCreated()
->assertJsonFragment([
Expand Down Expand Up @@ -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([
Expand Down

0 comments on commit ea533a9

Please sign in to comment.