Skip to content

Commit

Permalink
Merge branch 'release/5.2' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
bvlinsky committed Sep 20, 2023
2 parents 6dc7e49 + 6368228 commit d7a6067
Show file tree
Hide file tree
Showing 86 changed files with 1,269 additions and 4,357 deletions.
3 changes: 0 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ REDIS_CACHE_HOST=redis
REDIS_CACHE_PASSWORD=null
REDIS_CACHE_PORT=6379

SCOUT_DRIVER=database
SCOUT_QUEUE=false

EMAIL_HOST=mail.example.com
EMAIL_PORT=587
EMAIL_ENCRYPTION=tls
Expand Down
1 change: 0 additions & 1 deletion app/Console/Commands/RefreshProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public function handle(): int

$productService = app(ProductServiceContract::class);
$productService->updateMinMaxPrices($product);
$product->searchable();

$this->info('Done.');

Expand Down
11 changes: 7 additions & 4 deletions app/Criteria/MediaSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ class MediaSearch extends Criterion
public function query(Builder $query): Builder
{
if ($this->value) {
$query->where('url', 'like', "%{$this->value}%")
->orWhere('slug', 'like', "%{$this->value}%")
->orWhere('alt', 'like', "%{$this->value}%")
->orWhere('type', 'like', "%{$this->value}%");
$query->where(function (Builder $query): void {
$query
->where('url', 'like', "%{$this->value}%")
->orWhere('slug', 'like', "%{$this->value}%")
->orWhere('alt', 'like', "%{$this->value}%")
->orWhere('type', 'like', "%{$this->value}%");
});
}

return $query;
Expand Down
17 changes: 7 additions & 10 deletions app/Criteria/ProductSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ class ProductSearch extends Criterion
{
public function query(Builder $query): Builder
{
if ($this->value === null) {
return $query;
}

return $query->where(function (Builder $query): void {
$query->where('id', 'LIKE', '%' . $this->value . '%')
->orWhere('slug', 'LIKE', '%' . $this->value . '%')
->orWhere('name', 'LIKE', '%' . $this->value . '%')
->orWhere('description_html', 'LIKE', '%' . $this->value . '%');
});
return $query->whereFullText([
'name',
'slug',
'description_html',
'description_short',
'search_values',
], $this->value);
}
}
19 changes: 2 additions & 17 deletions app/Dtos/ProductSearchDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class ProductSearchDto extends Dto implements InstantiateFromRequest
{
private ?string $search;
private Missing|string $search;
private ?string $sort;

private array|Missing $ids;
Expand Down Expand Up @@ -46,7 +46,7 @@ public static function instantiateFromRequest(FormRequest|ProductIndexRequest $r
? Str::replace('price:desc', 'price_max:desc', $sort) : $sort;

return new self(
search: $request->input('search'),
search: $request->input('search', new Missing()),
sort: $sort,
ids: $request->input('ids', new Missing()),
slug: $request->input('slug', new Missing()),
Expand All @@ -70,26 +70,11 @@ public static function instantiateFromRequest(FormRequest|ProductIndexRequest $r
);
}

public function getSearch(): ?string
{
return $this->search;
}

public function getSort(): ?string
{
return $this->sort;
}

public function getPriceMin(): float|Missing
{
return $this->price_min;
}

public function getPriceMax(): float|Missing
{
return $this->price_max;
}

private static function boolean(string $key, FormRequest|ProductIndexRequest $request): bool|Missing
{
if (!$request->has($key)) {
Expand Down
10 changes: 5 additions & 5 deletions app/Events/ProductPriceUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class ProductPriceUpdated extends WebHookEvent
private string $updatedAt;

public function __construct(
private string $id,
private ?float $oldPriceMin,
private ?float $oldPriceMax,
private float $newPriceMin,
private float $newPriceMax,
private readonly string $id,
private readonly ?float $oldPriceMin,
private readonly ?float $oldPriceMax,
private readonly float $newPriceMin,
private readonly float $newPriceMax,
) {
$this->updatedAt = Carbon::now()->toIso8601String();
parent::__construct();
Expand Down
16 changes: 16 additions & 0 deletions app/Events/ProductSearchValueEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Events;

use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class ProductSearchValueEvent
{
use Dispatchable;
use SerializesModels;

public function __construct(
public readonly array $product_ids,
) {}
}
8 changes: 4 additions & 4 deletions app/Http/Controllers/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use App\Http\Resources\ResourceCollection;
use App\Models\MediaAttachment;
use App\Models\Product;
use App\Repositories\Contracts\ProductRepositoryContract;
use App\Repositories\ProductRepository;
use App\Services\Contracts\MediaAttachmentServiceContract;
use App\Services\Contracts\ProductServiceContract;
use Illuminate\Http\JsonResponse;
Expand All @@ -29,9 +29,9 @@
class ProductController extends Controller
{
public function __construct(
private ProductServiceContract $productService,
private ProductRepositoryContract $productRepository,
private MediaAttachmentServiceContract $attachmentService,
private readonly ProductRepository $productRepository,
private readonly ProductServiceContract $productService,
private readonly MediaAttachmentServiceContract $attachmentService,
) {}

public function index(ProductIndexRequest $request): JsonResource
Expand Down
18 changes: 7 additions & 11 deletions app/Http/Controllers/TagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace App\Http\Controllers;

use App\Events\ProductSearchValueEvent;
use App\Http\Requests\TagCreateRequest;
use App\Http\Requests\TagIndexRequest;
use App\Http\Requests\TagUpdateRequest;
use App\Http\Resources\TagResource;
use App\Models\Product;
use App\Models\Tag;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Http\Response as HttpResponse;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Response;

Expand All @@ -35,21 +35,17 @@ public function store(TagCreateRequest $request): JsonResource
public function update(Tag $tag, TagUpdateRequest $request): JsonResource
{
$tag->update($request->validated());

// @phpstan-ignore-next-line
$tag->products()->searchable();
ProductSearchValueEvent::dispatch($tag->products->pluck('id')->toArray());

return TagResource::make($tag);
}

public function destroy(Tag $tag): JsonResponse
public function destroy(Tag $tag): HttpResponse
{
$productsIds = $tag->products()->pluck('id');
$products = $tag->products->pluck('id')->toArray();
$tag->delete();
ProductSearchValueEvent::dispatch($products);

// @phpstan-ignore-next-line
Product::query()->whereIn('id', $productsIds)->searchable();

return Response::json(null, 204);
return Response::noContent();
}
}
2 changes: 1 addition & 1 deletion app/Http/Requests/ProductIndexRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function rules(): array
}

return [
'search' => ['nullable', 'string', 'max:255'],
'search' => ['sometimes', 'string', 'max:255'],

'ids' => ['array'],
'ids.*' => ['uuid'],
Expand Down
5 changes: 0 additions & 5 deletions app/Listeners/ItemUpdatedQuantityListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@

use App\Events\ItemUpdatedQuantity;
use App\Services\Contracts\AvailabilityServiceContract;
use App\Services\Contracts\ItemServiceContract;

final readonly class ItemUpdatedQuantityListener
{
public function __construct(
private AvailabilityServiceContract $availabilityService,
private ItemServiceContract $itemServiceContract,
) {}

public function handle(ItemUpdatedQuantity $event): void
{
$this->availabilityService->calculateItemAvailability($event->getItem());

// TODO: remove this with elastic refactor
$this->itemServiceContract->refreshSearchable($event->getItem());
}
}
22 changes: 0 additions & 22 deletions app/Listeners/MakeSetProductsSearchable.php

This file was deleted.

18 changes: 18 additions & 0 deletions app/Listeners/ProductSearchValueListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Listeners;

use App\Events\ProductSearchValueEvent;
use App\Services\Contracts\ProductServiceContract;

readonly class ProductSearchValueListener
{
public function __construct(
private ProductServiceContract $productService,
) {}

public function handle(ProductSearchValueEvent $event): void
{
$this->productService->updateProductsSearchValues($event->product_ids);
}
}
11 changes: 11 additions & 0 deletions app/Models/AttributeOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Heseya\Searchable\Traits\HasCriteria;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
Expand Down Expand Up @@ -50,4 +51,14 @@ public function attribute(): BelongsTo
{
return $this->belongsTo(Attribute::class);
}

public function productAttributes(): BelongsToMany
{
return $this->belongsToMany(
ProductAttribute::class,
'product_attribute_attribute_option',
'attribute_option_id',
'product_attribute_id',
);
}
}
6 changes: 1 addition & 5 deletions app/Models/Contracts/SortableContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@

interface SortableContract
{
public function scopeSort(Builder $query, ?string $sortString = null): Builder|\Laravel\Scout\Builder;
public function scopeSort(Builder $query, ?string $sortString = null): Builder;

public function getSortable(): array;

public function getDefaultSortBy(): string;

public function getDefaultSortDirection(): string;
}
3 changes: 0 additions & 3 deletions app/Models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@ class Order extends Model implements AuditableContract, SortableContract
'summary',
];

protected string $defaultSortBy = 'created_at';
protected string $defaultSortDirection = 'desc';

protected $casts = [
'paid' => 'boolean',
'invoice_requested' => 'boolean',
Expand Down
Loading

0 comments on commit d7a6067

Please sign in to comment.