Skip to content

Commit

Permalink
Merge branch '1.x' into patch-4
Browse files Browse the repository at this point in the history
  • Loading branch information
wychoong committed Nov 19, 2024
2 parents 03493ad + 4635e1c commit 6a32144
Show file tree
Hide file tree
Showing 26 changed files with 63 additions and 43 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<p align="center"><a href="https://lunarphp.io/" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/lunarphp/art/main/lunar-logo-dark.svg"><img alt="Lunar" width="200" src="https://raw.githubusercontent.com/lunarphp/art/main/lunar-logo.svg"></picture></a></p>

> [!CAUTION]
> Version 1.x is currently in alpha release. We recommend this version for new projects, however, it is not feature-complete and therefore may not be deemed production-ready.
> Version 1.x is currently in beta release. We recommend this version for new projects, however, it is not feature-complete and therefore may not be deemed production-ready.

[Lunar](https://lunarphp.io) is a set of Laravel packages that bring functionality akin to Shopify and other e-commerce platforms to
Expand Down
4 changes: 2 additions & 2 deletions docs/admin/overview.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Introduction

::: danger Alpha Release
::: danger Beta Release
Although many Lunar sites have been launched using v1.x, you may not consider this version production-ready for your own
use and should exercise the same amount of caution as you would with any software in an alpha state. 🚀
use and should exercise the same amount of caution as you would with any software in an beta state. 🚀
:::

Lunar's admin panel is powered by Filament v3. It allows you to easily extend the admin panel to suit your project.
Expand Down
6 changes: 3 additions & 3 deletions docs/core/installation.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Installation

::: danger Alpha Release
::: danger Beta Release
Although many Lunar sites have been launched using v1.x, you may not consider this version production-ready for your own
use and should exercise the same amount of caution as you would with any software in an alpha state. 🚀
use and should exercise the same amount of caution as you would with any software in an beta state. 🚀
:::

## Requirements
Expand All @@ -20,7 +20,7 @@ use and should exercise the same amount of caution as you would with any softwar
### Composer Require Package

```sh
composer require lunarphp/lunar:"^1.0.0-alpha" -W
composer require lunarphp/lunar:"^1.0.0-beta" -W
```

::: tip
Expand Down
6 changes: 3 additions & 3 deletions docs/core/overview.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Welcome to Lunar!

::: danger Alpha Release
Although many Lunar sites have been launched using v1.x, you may not consider this version production-ready for your own
use and should exercise the same amount of caution as you would with any software in an alpha state. 🚀
::: danger Beta Release
Although many Lunar sites have been launched using v1.x, you may not consider this version production-ready for your own
use and should exercise the same amount of caution as you would with any software in an beta state. 🚀
:::

We are delighted you are considering Lunar for your project. We've spent a lot of time developing this package to bring headless e-commerce functionality to Laravel.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Filament\Tables;
use Filament\Tables\Table;
use Lunar\Admin\Filament\Resources\OrderResource;
use Lunar\Admin\Filament\Resources\OrderResource\Pages\ManageOrder;
use Lunar\Admin\Support\RelationManagers\BaseRelationManager;
use Lunar\Models\Order;

Expand All @@ -18,7 +19,7 @@ public function getDefaultTable(Table $table): Table
OrderResource::getTableColumns()
)->actions([
Tables\Actions\Action::make('viewOrder')
->url(fn (Order $record): string => route('filament.lunar.resources.orders.order', $record)),
->url(fn (Order $record): string => ManageOrder::getUrl(['record' => $record])),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function getDefaultHeaderActions(): array

return response()->streamDownload(function () {
echo Pdf::loadView('lunarpanel::pdf.order', [
'order' => $this->record,
'record' => $this->record,
])->stream();
}, name: "Order-{$this->record->reference}.pdf");
}),
Expand Down
6 changes: 4 additions & 2 deletions packages/admin/src/Filament/Resources/ProductResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ public static function getNameTableColumn(): Tables\Columns\Column
->attributeData()
->limitedTooltip()
->limit(50)
->label(__('lunarpanel::product.table.name.label'));
->label(__('lunarpanel::product.table.name.label'))
->searchable();
}

public static function getSkuTableColumn(): Tables\Columns\Column
Expand All @@ -323,7 +324,8 @@ public static function getSkuTableColumn(): Tables\Columns\Column
})
->listWithLineBreaks()
->limitList(1)
->toggleable();
->toggleable()
->searchable();
}

public static function getDefaultRelations(): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function getDefaultHeaderActions(): array
static::createActionFormInputs()
)->using(
fn (array $data, string $model) => static::createRecord($data, $model)
)->successRedirectUrl(fn (Model $record): string => route('filament.lunar.resources.products.edit', [
)->successRedirectUrl(fn (Model $record): string => ProductResource::getUrl('edit', [
'record' => $record,
])),
];
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/Support/Forms/Components/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected function setUp(): void
}

foreach ($state as $key => $value) {
if (! $value instanceof \Lunar\Base\Fieldtype) {
if (! $value instanceof \Lunar\Base\FieldType) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function form(Form $form): Form
ignoreRecord: true,
modifyRuleUsing: function (Unique $rule, callable $get) {
return $rule
->where('element_type', static::$model)
->where('element_type', (new static::$model)->getMorphClass())
->where('language_id', $get('language_id'));
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function shouldRun()
protected function getOutdatedMediaQuery()
{
return DB::table(app(config('media-library.media_model'))->getTable())
->whereIn('model_type', [Product::class, Collection::class, Brand::class])
->whereIn('model_type', [Product::morphName(), Collection::morphName(), Brand::morphName()])
->where('collection_name', 'products');
}
}
2 changes: 1 addition & 1 deletion packages/core/src/DiscountTypes/AbstractDiscountType.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected function checkDiscountConditions(Cart $cart): bool

$validCoupon = $cartCoupon ? ($cartCoupon === $conditionCoupon) : blank($conditionCoupon);

$minSpend = ($data['min_prices'][$cart->currency->code] ?? 0) / $cart->currency->factor;
$minSpend = (int) ($data['min_prices'][$cart->currency->code] ?? 0) / (int) $cart->currency->factor;
$minSpend = (int) bcmul($minSpend, $cart->currency->factor);

$lines = $this->getEligibleLines($cart);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/DiscountTypes/AmountOff.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ protected function getEligibleLines(Cart $cart): \Illuminate\Support\Collection
/**
* Apply the percentage to the cart line.
*/
private function applyPercentage(int $value, Cart $cart): Cart
private function applyPercentage(float $value, Cart $cart): Cart
{
$lines = $this->getEligibleLines($cart);

Expand Down
8 changes: 6 additions & 2 deletions packages/core/src/Observers/OrderLineObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ public function creating(OrderLine $orderLine)
*/
public function updating(OrderLine $orderLine)
{
if (! in_array(Purchasable::class, class_implements($orderLine->purchasable_type, true))) {
throw new NonPurchasableItemException($orderLine->purchasable_type);
$purchasableModel = class_exists($orderLine->purchasable_type) ?
$orderLine->purchasable_type :
Relation::getMorphedModel($orderLine->purchasable_type);

if (! $purchasableModel || ! in_array(Purchasable::class, class_implements($purchasableModel, true))) {
throw new NonPurchasableItemException($purchasableModel);
}
}
}
2 changes: 1 addition & 1 deletion packages/core/src/Pipelines/Cart/ApplyDiscounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class ApplyDiscounts
/**
* Called just before cart totals are calculated.
*
* @return void
* @return mixed
*/
public function handle(Cart $cart, Closure $next)
{
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Pipelines/Cart/ApplyShipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class ApplyShipping
/**
* Called just before cart totals are calculated.
*
* @return void
* @return mixed
*/
public function handle(Cart $cart, Closure $next)
{
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Pipelines/Cart/Calculate.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Calculate
/**
* Called just before cart totals are calculated.
*
* @return void
* @return mixed
*/
public function handle(Cart $cart, Closure $next)
{
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Pipelines/Cart/CalculateLines.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CalculateLines
/**
* Called just before cart totals are calculated.
*
* @return void
* @return mixed
*/
public function handle(Cart $cart, Closure $next)
{
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Pipelines/Cart/CalculateTax.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CalculateTax
/**
* Called just before cart totals are calculated.
*
* @return void
* @return mixed
*/
public function handle(Cart $cart, Closure $next)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class CleanUpOrderLines
{
/**
* @return Closure
* @return mixed
*/
public function handle(Order $order, Closure $next)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class CreateOrderAddresses
{
/**
* @return Closure
* @return mixed
*/
public function handle(Order $order, Closure $next)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class CreateOrderLines
{
/**
* @return Closure
* @return mixed
*/
public function handle(Order $order, Closure $next)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class CreateShippingLine
{
/**
* @return Closure
* @return mixed
*/
public function handle(Order $order, Closure $next)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class FillOrderFromCart
{
/**
* @return Closure
* @return mixed
*/
public function handle(Order $order, Closure $next)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class MapDiscountBreakdown
{
/**
* @return Closure
* @return mixed
*/
public function handle(Order $order, Closure $next)
{
Expand Down
35 changes: 24 additions & 11 deletions tests/core/Unit/DiscountTypes/AmountOffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,16 @@
expect($lastLine->discountTotal->value)->toEqual(333);
});

test('can apply percentage discount', function () {
test('can apply percentage discount', function (
string $coupon,
float $percentage,
int $discountTotalForOne,
int $taxTotalForOne,
int $totalForOne,
int $discountTotalForTwo,
int $taxTotalForTwo,
int $totalForTwo
) {
$customerGroup = CustomerGroup::getDefault();

$channel = Channel::getDefault();
Expand All @@ -794,7 +803,7 @@
$cart = Cart::factory()->create([
'channel_id' => $channel->id,
'currency_id' => $currency->id,
'coupon_code' => '10PERCENTOFF',
'coupon_code' => $coupon,
]);

$purchasable = ProductVariant::factory()->create();
Expand All @@ -816,9 +825,9 @@
$discount = Discount::factory()->create([
'type' => AmountOff::class,
'name' => 'Test Coupon',
'coupon' => '10PERCENTOFF',
'coupon' => $coupon,
'data' => [
'percentage' => 10,
'percentage' => $percentage,
'fixed_value' => false,
],
]);
Expand All @@ -843,9 +852,9 @@

$cart = $cart->calculate();

expect($cart->discountTotal->value)->toEqual(100);
expect($cart->taxTotal->value)->toEqual(180);
expect($cart->total->value)->toEqual(1080);
expect($cart->discountTotal->value)->toEqual($discountTotalForOne);
expect($cart->taxTotal->value)->toEqual($taxTotalForOne);
expect($cart->total->value)->toEqual($totalForOne);

$cart->lines()->delete();

Expand All @@ -857,10 +866,14 @@

$cart = $cart->refresh()->calculate();

expect($cart->discountTotal->value)->toEqual(200);
expect($cart->taxTotal->value)->toEqual(360);
expect($cart->total->value)->toEqual(2160);
});
expect($cart->discountTotal->value)->toEqual($discountTotalForTwo);
expect($cart->taxTotal->value)->toEqual($taxTotalForTwo);
expect($cart->total->value)->toEqual($totalForTwo);
})->with([
'10% Discount' => ['10PERCENTOFF', 10, 100, 180, 1080, 200, 360, 2160],
'10.25% Discount' => ['10PT25PERCENTOFF', 10.25, 103, 179, 1076, 205, 359, 2154],
'10.5% Discount' => ['10PT5PERCENTOFF', 10.5, 105, 179, 1074, 210, 358, 2148],
]);

test('can only same discount to line once', function () {
$customerGroup = CustomerGroup::getDefault();
Expand Down

0 comments on commit 6a32144

Please sign in to comment.