Skip to content

Commit

Permalink
Merge branch '1.x' into vi-translations
Browse files Browse the repository at this point in the history
  • Loading branch information
Ngô Quốc Đạt authored Feb 1, 2025
2 parents e9c9462 + 8f6966f commit 3f1e901
Show file tree
Hide file tree
Showing 22 changed files with 302 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public function getDefaultTable(Table $table): Table
__('lunarpanel::user.form.password_confirmation.label')
)
->password()
->minLength(8),
->minLength(8)
->dehydrated(false),
])->columns(2),

]),
Expand Down
7 changes: 3 additions & 4 deletions packages/admin/src/Filament/Resources/DiscountResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Filament\Forms;
use Filament\Forms\Components\Component;
use Filament\Forms\Form;
use Filament\Pages\Page;
use Filament\Pages\SubNavigationPosition;
use Filament\Support\Facades\FilamentIcon;
use Filament\Tables;
Expand Down Expand Up @@ -377,13 +376,13 @@ protected static function getTableColumns(): array
];
}

public static function getRecordSubNavigation(Page $page): array
public static function getDefaultSubNavigation(): array
{
return $page->generateNavigationItems([
return [
Pages\EditDiscount::class,
Pages\ManageDiscountAvailability::class,
Pages\ManageDiscountLimitations::class,
]);
];
}

protected static function getDefaultRelations(): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function getDefaultTable(Table $table): Table
->paginated(false)
->modifyQueryUsing(
fn ($query) => $query->whereIn('type', ['condition'])
->wherePurchasableType(Product::class)
->wherePurchasableType(Product::morphName())
->whereHas('purchasable')
)
->headerActions([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
use Lunar\Admin\Support\RelationManagers\BaseRelationManager;
use Lunar\Facades\ModelManifest;
use Lunar\Models\Product;

class ProductLimitationRelationManager extends BaseRelationManager
Expand All @@ -33,9 +32,7 @@ public function getDefaultTable(Table $table): Table
->paginated(false)
->modifyQueryUsing(
fn ($query) => $query->whereIn('type', ['limitation', 'exclusion'])
->wherePurchasableType(
ModelManifest::getMorphMapKey(Product::class)
)
->wherePurchasableType(Product::morphName())
->whereHas('purchasable')
)
->headerActions([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function getDefaultTable(Table $table): Table
->paginated(false)
->modifyQueryUsing(
fn ($query) => $query->whereIn('type', ['reward'])
->wherePurchasableType(Product::class)
->wherePurchasableType(Product::morphName())
->whereHas('purchasable')
)
->headerActions([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
use Lunar\Admin\Support\RelationManagers\BaseRelationManager;
use Lunar\Facades\ModelManifest;
use Lunar\Models\Product;
use Lunar\Models\ProductVariant;

Expand Down Expand Up @@ -35,9 +34,7 @@ public function getDefaultTable(Table $table): Table
->paginated(false)
->modifyQueryUsing(
fn ($query) => $query->whereIn('type', ['limitation', 'exclusion'])
->wherePurchasableType(
ModelManifest::getMorphMapKey(ProductVariant::class)
)
->wherePurchasableType(ProductVariant::morphName())
->whereHas('purchasable')
)
->headerActions([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public function getDefaultTable(Table $table): Table

$data['min_quantity'] = 1;
$data['price'] = (int) ($data['price'] * $currencyModel->factor);
$data['compare_price'] = (int) ($data['compare_price'] * $currencyModel->factor);

return $data;
})->label(
Expand All @@ -162,6 +163,7 @@ public function getDefaultTable(Table $table): Table

$data['min_quantity'] = 1;
$data['price'] = (int) ($data['price'] * $currencyModel->factor);
$data['compare_price'] = (int) ($data['compare_price'] * $currencyModel->factor);

return $data;
})->after(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ trait ExtendsTablePagination
{
protected function getDefaultPaginationQuery(Builder $query): Paginator|CursorPaginator
{
return $query->paginate($this->getTableRecordsPerPage());
return parent::paginateTableQuery($query);
}

protected function paginateTableQuery(Builder $query): Paginator|CursorPaginator
Expand Down
5 changes: 5 additions & 0 deletions packages/admin/src/Support/Synthesizers/ListSynth.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public function dehydrate($target)
return parent::dehydrate($target); // TODO: Change the autogenerated stub
}

public function get(&$target, $key)
{
return (array) $target->getValue();
}

public function set(&$target, $key, $value)
{
$fieldValue = (array) $target->getValue();
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function sync_with_search(?Illuminate\Database\Eloquent\Model $model = null): vo
return;
}

$isSearchable = in_array(Searchable::class, class_uses($model));
$isSearchable = in_array(Searchable::class, class_uses_recursive($model));

if ($isSearchable) {
$model->searchable();
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/LunarServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
use Lunar\Models\Collection;
use Lunar\Models\Currency;
use Lunar\Models\CustomerGroup;
use Lunar\Models\Discount;
use Lunar\Models\Language;
use Lunar\Models\Order;
use Lunar\Models\OrderLine;
Expand All @@ -79,6 +80,7 @@
use Lunar\Observers\CollectionObserver;
use Lunar\Observers\CurrencyObserver;
use Lunar\Observers\CustomerGroupObserver;
use Lunar\Observers\DiscountObserver;
use Lunar\Observers\LanguageObserver;
use Lunar\Observers\MediaObserver;
use Lunar\Observers\OrderLineObserver;
Expand Down Expand Up @@ -298,6 +300,7 @@ protected function registerObservers(): void
{
Channel::observe(ChannelObserver::class);
CustomerGroup::observe(CustomerGroupObserver::class);
Discount::observe(DiscountObserver::class);
Language::observe(LanguageObserver::class);
Currency::observe(CurrencyObserver::class);
Url::observe(UrlObserver::class);
Expand Down
22 changes: 22 additions & 0 deletions packages/core/src/Observers/DiscountObserver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Lunar\Observers;

use Lunar\Models\Discount;

class DiscountObserver
{
/**
* Handle the Discount "deleting" event.
*
* @return void
*/
public function deleting(Discount $discount)
{
$discount->brands()->detach();
$discount->collections()->detach();
$discount->customerGroups()->detach();
$discount->purchasables()->detach();
$discount->users()->detach();
}
}
4 changes: 3 additions & 1 deletion packages/stripe/src/Jobs/ProcessStripeWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Lunar\Facades\Payments;
use Lunar\Models\Cart;
use Lunar\Models\Order;
use Lunar\Stripe\Models\StripePaymentIntent;

class ProcessStripeWebhook implements ShouldQueue
{
Expand Down Expand Up @@ -48,7 +49,8 @@ public function handle()
}

if (! $order) {
$cart = Cart::where('meta->payment_intent', '=', $this->paymentIntentId)->first();
$cart = StripePaymentIntent::where('intent_id', $this->paymentIntentId)->first()?->cart ?:
Cart::where('meta->payment_intent', '=', $this->paymentIntentId)->first();
}

if (! $cart && ! $order) {
Expand Down
2 changes: 1 addition & 1 deletion packages/stripe/src/Models/StripePaymentIntent.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ class StripePaymentIntent extends BaseModel

public function cart(): BelongsTo
{
return $this->belongsTo(Cart::class);
return $this->belongsTo(Cart::class, 'cart_id');
}
}
4 changes: 0 additions & 4 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
<directory suffix="Test.php">tests/core/Feature</directory>
<directory suffix="Test.php">tests/core/Unit</directory>
</testsuite>
<testsuite name="opayo">
<directory suffix="Test.php">tests/opayo/Unit</directory>
<directory suffix="Test.php">tests/opayo/Feature</directory>
</testsuite>
<testsuite name="stripe">
<directory suffix="Test.php">tests/stripe/Unit</directory>
</testsuite>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

use Livewire\Livewire;

uses(\Lunar\Tests\Admin\Feature\Filament\TestCase::class)
->group('extending.list');

it('can list all records', function () {
$this->asStaff();

$customers = \Lunar\Models\Customer::factory(30)->create();

Livewire::test(\Lunar\Admin\Filament\Resources\CustomerResource\Pages\ListCustomers::class)
->set('tableRecordsPerPage', 'all')
->assertCountTableRecords(30)
->assertCanSeeTableRecords($customers);
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
'pageClass' => $page,
])->assertSuccessful();
})->with([
'product' => [
'model' => \Lunar\Models\Product::class,
'page' => \Lunar\Admin\Filament\Resources\ProductResource\Pages\ManageProductMedia::class,
],
'brand' => [
'model' => \Lunar\Models\Brand::class,
'page' => \Lunar\Admin\Filament\Resources\BrandResource\Pages\ManageBrandMedia::class,
],
[\Lunar\Models\Product::class, \Lunar\Admin\Filament\Resources\ProductResource\Pages\ManageProductMedia::class],
[\Lunar\Models\Brand::class, \Lunar\Admin\Filament\Resources\BrandResource\Pages\ManageBrandMedia::class],
]);
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,5 @@
'pageClass' => $page,
])->assertSuccessful();
})->with([
'product' => [
'model' => \Lunar\Models\Product::class,
'page' => \Lunar\Admin\Filament\Resources\ProductResource\Pages\ManageProductPricing::class,
],
[\Lunar\Models\Product::class, \Lunar\Admin\Filament\Resources\ProductResource\Pages\ManageProductPricing::class],
]);
97 changes: 97 additions & 0 deletions tests/admin/Unit/Livewire/Synthesizers/ListSynthTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

use Lunar\Admin\Support\Synthesizers\ListSynth;
use Lunar\FieldTypes\ListField;

uses(\Lunar\Tests\Admin\Unit\Livewire\TestCase::class)
->group('support.synthesizers');

describe('list field synthesizer', function () {
beforeEach(function () {
$this->listSynth = Mockery::mock(ListSynth::class)->makePartial();
$this->listField = Mockery::mock(ListField::class)->makePartial();
});

test('sets a value in the list field', function () {
$key = 'item1';
$value = 'Test Value';

$this->listSynth->set($this->listField, $key, $value);

$result = $this->listField->getValue();

expect($result)->toBeObject()
->and($result)->toHaveKey($key, $value);
});

test('unsets a value from the list field', function () {
$key = 'item1';
$value = 'Test Value';

$this->listField->setValue([$key => $value]);

$this->listSynth->unset($this->listField, $key);

$result = $this->listField->getValue();

expect($result)->toBeArray()
->and($result)->not->toHaveKey($key);
});

test('gets values from the list field', function () {
$key = 'item1';
$value = 'Test Value';
$this->listField->setValue([$key => $value]);

$result = $this->listSynth->get($this->listField, $key);

expect($result)->toBeArray()
->and($result)->toEqual((array) $this->listField->getValue());
});

test('dehydrates the list field correctly', function () {
$this->listField->setValue(['item1' => 'Test Value']);

$result = $this->listSynth->dehydrate($this->listField)[0];

expect($result)->toEqual($this->listField->getValue());
});

test('handles empty keys and values', function () {
$key = '';
$value = '';

$this->listSynth->set($this->listField, $key, $value);

$result = $this->listField->getValue();

expect($result)->toBeObject()
->and($result)->toHaveKey($key, $value);

$this->listSynth->unset($this->listField, $key);

$result = $this->listField->getValue();

expect($result)->toBeArray()
->and($result)->not->toHaveKey($key);
});

test('handles keys and values with dot notation', function () {
$key = 'key.with.dots';
$value = 'Dot.Notation.Value';

$this->listSynth->set($this->listField, $key, $value);

$result = $this->listField->getValue();

expect($result)->toBeObject()
->and($result)->toHaveKey($key, $value);

$this->listSynth->unset($this->listField, $key);

$result = $this->listField->getValue();

expect($result)->toBeArray()
->and($result)->not->toHaveKey($key);
});
});
Loading

0 comments on commit 3f1e901

Please sign in to comment.