Skip to content

Commit

Permalink
Fix add products in collection (#304)
Browse files Browse the repository at this point in the history
* fix: search products in collection and related products list

* feat: add search test for CollectionProductsList

* chore: run phpstan
  • Loading branch information
mckenziearts authored Oct 25, 2024
1 parent 7b252c7 commit 460cb11
Show file tree
Hide file tree
Showing 13 changed files with 78,682 additions and 21,470 deletions.
10,685 changes: 10,684 additions & 1 deletion packages/admin/public/shopper.css

Large diffs are not rendered by default.

86,473 changes: 66,322 additions & 20,151 deletions packages/admin/public/shopper.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
</div>
<x-shopper::forms.input
type="search"
id="search-filter"
wire:model.live.debounce.550ms="search"
id="{{ $for }}"
class="pl-10"
:placeholder="$placeholder"
{{ $attributes->except(['placeholder']) }}
/>
<div class="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3">
<x-shopper::loader wire:loading wire:target="search" class="text-primary-600" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
<x-shopper::forms.search
:label="__('shopper::pages/collections.modal.search')"
:placeholder="__('shopper::pages/collections.modal.search_placeholder')"
wire:model.live.debounce.550ms="search"
/>
</div>
<div class="h-92 -mx-2 my-2 divide-y divide-gray-200 overflow-auto dark:divide-gray-700">
<div class="h-80 -mx-2 my-2 divide-y divide-gray-200 overflow-auto dark:divide-gray-700">
@foreach ($this->products as $product)
<x-shopper::forms.label-product :product="$product" wire:key="{{ $product->id }}" />
@endforeach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<x-shopper::forms.search
:label="__('shopper::pages/products.related.modal.search')"
:placeholder="__('shopper::pages/products.related.modal.search_placeholder')"
wire:model.live.debounce.550ms="search"
/>
</div>
<div class="-mx-2 my-2 h-80 divide-y divide-gray-200 overflow-auto dark:divide-gray-700">
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/Components/Form/SelectTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function setUp(): void
// Check if the relationship is a BelongsToMany relationship.
if ($relationship instanceof BelongsToMany) {
// Retrieve related model instances and extract their IDs into an array.
$state = $relationship->getResults() // @phpstan-ignore-line
$state = $relationship->getResults()

Check failure on line 95 in packages/admin/src/Components/Form/SelectTree.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - L10.* prefer-stable

Call to an undefined method Traversable<int, Illuminate\Database\Eloquent\Model>::pluck().

Check failure on line 95 in packages/admin/src/Components/Form/SelectTree.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - L10.* prefer-stable

Call to an undefined method Traversable<int, Illuminate\Database\Eloquent\Model>::pluck().
->pluck($relationship->getRelatedKeyName())
->toArray();

Expand Down
11 changes: 8 additions & 3 deletions packages/admin/src/Livewire/Modals/CollectionProductsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Collection;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Locked;
use Shopper\Core\Repositories\CollectionRepository;
use Shopper\Core\Repositories\ProductRepository;
use Shopper\Livewire\Components\ModalComponent;
Expand All @@ -18,7 +19,8 @@ class CollectionProductsList extends ModalComponent

public string $search = '';

public array $exceptProductIds;
#[Locked]
public array $exceptProductIds = [];

public array $selectedProducts = [];

Expand All @@ -38,8 +40,11 @@ public function products(): Collection
{
return (new ProductRepository) // @phpstan-ignore-line
->query()
->where('name', '%' . $this->search . '%', 'like')
->whereNull('parent_id')
->where(
column: 'name',
operator: 'like',
value: '%' . $this->search . '%'
)
->get(['name', 'price_amount', 'id'])
->except($this->exceptProductIds);
}
Expand Down
15 changes: 12 additions & 3 deletions packages/admin/src/Livewire/Modals/RelatedProductsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use Filament\Notifications\Notification;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Collection;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Locked;
use Shopper\Core\Repositories\ProductRepository;
use Shopper\Livewire\Components\ModalComponent;

Expand All @@ -15,6 +18,7 @@ class RelatedProductsList extends ModalComponent

public string $search = '';

#[Locked]
public array $exceptProductIds = [];

public array $selectedProducts = [];
Expand All @@ -25,11 +29,16 @@ public function mount(int $productId, array $ids = []): void
$this->exceptProductIds = $ids;
}

public function getProductsProperty()
#[Computed]
public function products(): Collection
{
return (new ProductRepository) // @phpstan-ignore-line
->where('name', '%' . $this->search . '%', 'like')
->whereNull('parent_id')
->query()
->where(
column: 'name',
operator: 'like',
value: '%' . $this->search . '%'
)
->get(['name', 'price_amount', 'id'])
->except($this->exceptProductIds);
}
Expand Down
Loading

0 comments on commit 460cb11

Please sign in to comment.