Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix add products in collection #304

Merged
merged 3 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
// 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
Loading