From ec5cda36cf7cb35e2938812dc285d53bc96a5685 Mon Sep 17 00:00:00 2001 From: Ryan McAllen Date: Tue, 16 Jul 2024 02:48:26 -0400 Subject: [PATCH 01/18] Docs: Add missing semicolon (#1864) Please describe your Pull Request as best as possible, explaining what it provides and why it is of value, referencing any related Issues. Try to include the following in your Pull Request, where applicable... - Documentation updates - Automated tests --- docs/core/extending/models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/extending/models.md b/docs/core/extending/models.md index 646702b7ed..a5be10b02a 100644 --- a/docs/core/extending/models.md +++ b/docs/core/extending/models.md @@ -123,7 +123,7 @@ $newStaticMethod = \Lunar\Models\ProductOption::getSizesStatic(); ```php namespace App\Models; -use App\Concerns\SearchableTrait +use App\Concerns\SearchableTrait; class Product extends \Lunar\Models\Product { From 09c6be1cc91256deba6553324de80052aefe207c Mon Sep 17 00:00:00 2001 From: Ryan McAllen Date: Tue, 16 Jul 2024 02:49:49 -0400 Subject: [PATCH 02/18] Docs: stores -> store's (#1866) --- docs/core/reference/orders.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/reference/orders.md b/docs/core/reference/orders.md index 7ac62da223..1b269a74b0 100644 --- a/docs/core/reference/orders.md +++ b/docs/core/reference/orders.md @@ -17,7 +17,7 @@ Lunar\Models\Order | cart_id | The related cart | | channel_id | Which channel this was purchased through | | status | A status that makes sense to you as the store owner | -| reference | Your stores own reference +| reference | Your store's own reference | customer_reference | If you want customers to add their own reference, it goes here. | sub_total | The sub total minus any discounts, excl. tax | discount_breakdown | A json field for the discount breakdown e.g. `[{"discount_id": 1, "lines": [{"id": 1, "qty": 1}]], "total": 200}]` From 0deb716ed26b57d6bf862efd1df3f3e8ab839abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20S=C3=B8rensen?= Date: Wed, 17 Jul 2024 09:04:18 +0200 Subject: [PATCH 03/18] Updated DocBlock (#1869) Small DocBlock change for `OrderObserver` `updating` method. --- packages/core/src/Observers/OrderObserver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/Observers/OrderObserver.php b/packages/core/src/Observers/OrderObserver.php index 4bcfa24857..2604d73bfe 100644 --- a/packages/core/src/Observers/OrderObserver.php +++ b/packages/core/src/Observers/OrderObserver.php @@ -7,9 +7,9 @@ class OrderObserver { /** - * Handle the OrderLine "updated" event. + * Handle the Order "updating" event. * - * @param \Lunar\Models\OrderLine $orderLine + * @param \Lunar\Models\Order $order * @return void */ public function updating(Order $order) From c2c3422e59e85a3afacad7a1ce6144e7c7b59d11 Mon Sep 17 00:00:00 2001 From: alecritson Date: Wed, 17 Jul 2024 07:06:51 +0000 Subject: [PATCH 04/18] chore: fix code style --- packages/core/src/Observers/OrderObserver.php | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/core/src/Observers/OrderObserver.php b/packages/core/src/Observers/OrderObserver.php index 2604d73bfe..6d213bc134 100644 --- a/packages/core/src/Observers/OrderObserver.php +++ b/packages/core/src/Observers/OrderObserver.php @@ -9,7 +9,6 @@ class OrderObserver /** * Handle the Order "updating" event. * - * @param \Lunar\Models\Order $order * @return void */ public function updating(Order $order) From 747ccb4a2fc7b393d8b6af0a2dd6f86dc24eaf30 Mon Sep 17 00:00:00 2001 From: Alec Ritson Date: Wed, 17 Jul 2024 13:49:44 +0100 Subject: [PATCH 05/18] Fix status setting on Stripe webhook failures (#1871) --- .../stripe/src/Http/Controllers/WebhookController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/stripe/src/Http/Controllers/WebhookController.php b/packages/stripe/src/Http/Controllers/WebhookController.php index 95b0ee2344..b0e78423f8 100644 --- a/packages/stripe/src/Http/Controllers/WebhookController.php +++ b/packages/stripe/src/Http/Controllers/WebhookController.php @@ -31,10 +31,10 @@ public function __invoke(Request $request): JsonResponse $error = $e->getMessage() ); - return response(status: 400)->json([ + return response()->json([ 'webhook_successful' => false, 'message' => $error, - ]); + ], 400); } $paymentIntent = $event->data->object->id; @@ -46,10 +46,10 @@ public function __invoke(Request $request): JsonResponse $error = "Unable to find cart with intent {$paymentIntent}" ); - return response(status: 400)->json([ + return response()->json([ 'webhook_successful' => false, 'message' => $error, - ]); + ], 400); } $payment = Payments::driver('stripe')->cart($cart->calculate())->withData([ From 7d2fc357529912f52081f52366a4624d1b797b60 Mon Sep 17 00:00:00 2001 From: Alec Ritson Date: Tue, 23 Jul 2024 14:03:09 +0100 Subject: [PATCH 06/18] Tweak Stripe logic (#1877) --- docs/core/extending/payments.md | 2 +- docs/core/upgrading.md | 12 ++ ...100000_add_fingerprint_to_orders_table.php | 25 +++ .../core/src/Actions/Carts/CreateOrder.php | 3 +- .../src/Actions/Carts/GenerateFingerprint.php | 4 - .../core/src/Base/PaymentTypeInterface.php | 4 +- packages/core/src/Models/Cart.php | 11 ++ .../core/src/PaymentTypes/OfflinePayment.php | 2 +- packages/stripe/README.md | 25 ++- .../Http/Controllers/WebhookController.php | 26 +-- .../Middleware/StripeWebhookMiddleware.php | 5 +- .../stripe/src/Jobs/ProcessStripeWebhook.php | 74 +++++++ .../stripe/src/Managers/StripeManager.php | 7 +- packages/stripe/src/StripePaymentType.php | 8 +- tests/core/Stubs/TestPaymentDriver.php | 2 +- .../Unit/Actions/Carts/CreateOrderTest.php | 20 +- tests/core/Unit/Models/CartTest.php | 186 +++++++++++++++++- tests/opayo/Feature/OpayoPaymentTypeTest.php | 8 +- tests/stripe/TestCase.php | 2 +- tests/stripe/Unit/StripePaymentTypeTest.php | 14 +- 20 files changed, 370 insertions(+), 70 deletions(-) create mode 100644 packages/core/database/migrations/2024_07_23_100000_add_fingerprint_to_orders_table.php create mode 100644 packages/stripe/src/Jobs/ProcessStripeWebhook.php diff --git a/docs/core/extending/payments.md b/docs/core/extending/payments.md index 6338fb7cb4..e3792b382b 100644 --- a/docs/core/extending/payments.md +++ b/docs/core/extending/payments.md @@ -54,7 +54,7 @@ class CustomPayment extends AbstractPayment /** * {@inheritDoc} */ - public function authorize(): PaymentAuthorize + public function authorize(): ?PaymentAuthorize { if (!$this->order) { if (!$this->order = $this->cart->order) { diff --git a/docs/core/upgrading.md b/docs/core/upgrading.md index fcd578c740..e571d738f9 100644 --- a/docs/core/upgrading.md +++ b/docs/core/upgrading.md @@ -18,6 +18,18 @@ php artisan migrate Lunar currently provides bug fixes and security updates for only the latest minor release, e.g. `0.8`. +## 1.0.0-alpha.34 + +### Medium Impact + +#### Stripe Addon + +The Stripe driver will now check whether an order has a value for `placed_at` against an order and if so, no further processing will take place. + +Additionally, the logic in the webhook has been moved to the job queue, which is dispatched with a delay of 20 seconds, this is to allow storefronts to manually process a payment intent, in addition to the webhook, without having to worry about overlap. + +The Stripe webhook ENV entry has been changed from `STRIPE_WEBHOOK_PAYMENT_INTENT` to `LUNAR_STRIPE_WEBHOOK_SECRET` + ## 1.0.0-alpha.32 ### High Impact diff --git a/packages/core/database/migrations/2024_07_23_100000_add_fingerprint_to_orders_table.php b/packages/core/database/migrations/2024_07_23_100000_add_fingerprint_to_orders_table.php new file mode 100644 index 0000000000..2a3a7b9d80 --- /dev/null +++ b/packages/core/database/migrations/2024_07_23_100000_add_fingerprint_to_orders_table.php @@ -0,0 +1,25 @@ +prefix.'orders', function (Blueprint $table) { + $table->string('fingerprint')->nullable()->index(); + }); + } + + public function down(): void + { + Schema::table($this->prefix.'orders', function (Blueprint $table) { + $table->dropIndex(['fingerprint']); + }); + Schema::table($this->prefix.'orders', function (Blueprint $table) { + $table->dropColumn('fingerprint'); + }); + } +}; diff --git a/packages/core/src/Actions/Carts/CreateOrder.php b/packages/core/src/Actions/Carts/CreateOrder.php index 2ffc3f774d..f0276cef71 100644 --- a/packages/core/src/Actions/Carts/CreateOrder.php +++ b/packages/core/src/Actions/Carts/CreateOrder.php @@ -21,7 +21,7 @@ public function execute( ?int $orderIdToUpdate = null ): self { $this->passThrough = DB::transaction(function () use ($cart, $allowMultipleOrders, $orderIdToUpdate) { - $order = $cart->draftOrder($orderIdToUpdate)->first() ?: new Order; + $order = $cart->currentDraftOrder($orderIdToUpdate) ?: new Order; if ($cart->hasCompletedOrders() && ! $allowMultipleOrders) { throw new DisallowMultipleCartOrdersException; @@ -29,6 +29,7 @@ public function execute( $order->fill([ 'cart_id' => $cart->id, + 'fingerprint' => $cart->fingerprint(), ]); $order = app(Pipeline::class) diff --git a/packages/core/src/Actions/Carts/GenerateFingerprint.php b/packages/core/src/Actions/Carts/GenerateFingerprint.php index 1e52ea362d..548514bb71 100644 --- a/packages/core/src/Actions/Carts/GenerateFingerprint.php +++ b/packages/core/src/Actions/Carts/GenerateFingerprint.php @@ -10,18 +10,14 @@ class GenerateFingerprint public function execute(Cart $cart) { $value = $cart->lines->reduce(function (?string $carry, CartLine $line) { - $meta = $line->meta?->collect()->sortKeys()->toJson(); - return $carry. $line->purchasable_type. $line->purchasable_id. $line->quantity. - $meta. $line->subTotal; }); $value .= $cart->user_id.$cart->currency_id.$cart->coupon_code; - $value .= $cart->meta?->collect()->sortKeys()->toJson(); return sha1($value); } diff --git a/packages/core/src/Base/PaymentTypeInterface.php b/packages/core/src/Base/PaymentTypeInterface.php index efdc57e6a0..f1031ad0d7 100644 --- a/packages/core/src/Base/PaymentTypeInterface.php +++ b/packages/core/src/Base/PaymentTypeInterface.php @@ -35,10 +35,8 @@ public function setConfig(array $config): self; /** * Authorize the payment. - * - * @return void */ - public function authorize(): PaymentAuthorize; + public function authorize(): ?PaymentAuthorize; /** * Refund a transaction for a given amount. diff --git a/packages/core/src/Models/Cart.php b/packages/core/src/Models/Cart.php index eabb9ce91b..8bf9a3c546 100644 --- a/packages/core/src/Models/Cart.php +++ b/packages/core/src/Models/Cart.php @@ -293,6 +293,17 @@ public function draftOrder(?int $draftOrderId = null): HasOne })->whereNull('placed_at'); } + public function currentDraftOrder(?int $draftOrderId = null) + { + return $this->calculate() + ->draftOrder($draftOrderId) + ->where('fingerprint', $this->fingerprint()) + ->when( + $this->total, + fn (Builder $query, Price $price) => $query->where('total', $price->value) + )->first(); + } + /** * Return the completed order relationship. */ diff --git a/packages/core/src/PaymentTypes/OfflinePayment.php b/packages/core/src/PaymentTypes/OfflinePayment.php index e62490461e..ea3c68bec5 100644 --- a/packages/core/src/PaymentTypes/OfflinePayment.php +++ b/packages/core/src/PaymentTypes/OfflinePayment.php @@ -13,7 +13,7 @@ class OfflinePayment extends AbstractPayment /** * {@inheritDoc} */ - public function authorize(): PaymentAuthorize + public function authorize(): ?PaymentAuthorize { if (! $this->order) { if (! $this->order = $this->cart->draftOrder()->first()) { diff --git a/packages/stripe/README.md b/packages/stripe/README.md index 12b3e0b1d9..39f6ec0ac8 100644 --- a/packages/stripe/README.md +++ b/packages/stripe/README.md @@ -80,6 +80,9 @@ Make sure you have the Stripe credentials set in `config/services.php` 'stripe' => [ 'key' => env('STRIPE_SECRET'), 'public_key' => env('STRIPE_PK'), + 'webhooks' => [ + 'lunar' => env('LUNAR_STRIPE_WEBHOOK_SECRET'), + ], ], ``` @@ -224,9 +227,9 @@ Stripe::getCharges(string $paymentIntentId); ## Webhooks -The plugin provides a webhook you will need to add to Stripe. You can read the guide on how to do this on the Stripe website [https://stripe.com/docs/webhooks/quickstart](https://stripe.com/docs/webhooks/quickstart). +The add-on provides an optional webhook you may add to Stripe. You can read the guide on how to do this on the Stripe website [https://stripe.com/docs/webhooks/quickstart](https://stripe.com/docs/webhooks/quickstart). -The 3 events you should listen to are `payment_intent.payment_failed`,`payment_intent.processing`,`payment_intent.succeeded`. +The events you should listen to are `payment_intent.payment_failed`, `payment_intent.succeeded`. The path to the webhook will be `http:://yoursite.com/stripe/webhook`. @@ -248,6 +251,24 @@ return [ ]; ``` +If you do not wish to use the webhook, or would like to manually process an order as well, you are able to do so. + +```php +$cart = CartSession::current(); + +// With a draft order... +$draftOrder = $cart->createOrder(); +Payments::driver('stripe')->order($draftOrder)->withData([ + 'payment_intent' => $draftOrder->meta['payment_intent'], +])->authorize(); + +// Using just the cart... +Payments::driver('stripe')->cart($cart)->withData([ + 'payment_intent' => $cart->meta['payment_intent'], +])->authorize(); +``` + + ## Storefront Examples First we need to set up the backend API call to fetch or create the intent, this isn't Vue specific but will likely be different if you're using Livewire. diff --git a/packages/stripe/src/Http/Controllers/WebhookController.php b/packages/stripe/src/Http/Controllers/WebhookController.php index b0e78423f8..9eb83ee5c6 100644 --- a/packages/stripe/src/Http/Controllers/WebhookController.php +++ b/packages/stripe/src/Http/Controllers/WebhookController.php @@ -6,10 +6,8 @@ use Illuminate\Http\Request; use Illuminate\Routing\Controller; use Illuminate\Support\Facades\Log; -use Lunar\Events\PaymentAttemptEvent; -use Lunar\Facades\Payments; -use Lunar\Models\Cart; use Lunar\Stripe\Concerns\ConstructsWebhookEvent; +use Lunar\Stripe\Jobs\ProcessStripeWebhook; use Stripe\Exception\SignatureVerificationException; use Stripe\Exception\UnexpectedValueException; @@ -17,7 +15,7 @@ final class WebhookController extends Controller { public function __invoke(Request $request): JsonResponse { - $secret = config('services.stripe.webhooks.payment_intent'); + $secret = config('services.stripe.webhooks.lunar'); $stripeSig = $request->header('Stripe-Signature'); try { @@ -38,25 +36,9 @@ public function __invoke(Request $request): JsonResponse } $paymentIntent = $event->data->object->id; + $orderId = $event->data->object->metadata?->order_id; - $cart = Cart::where('meta->payment_intent', '=', $paymentIntent)->first(); - - if (! $cart) { - Log::error( - $error = "Unable to find cart with intent {$paymentIntent}" - ); - - return response()->json([ - 'webhook_successful' => false, - 'message' => $error, - ], 400); - } - - $payment = Payments::driver('stripe')->cart($cart->calculate())->withData([ - 'payment_intent' => $paymentIntent, - ])->authorize(); - - PaymentAttemptEvent::dispatch($payment); + ProcessStripeWebhook::dispatch($paymentIntent, $orderId)->delay(now()->addSeconds(20)); return response()->json([ 'webhook_successful' => true, diff --git a/packages/stripe/src/Http/Middleware/StripeWebhookMiddleware.php b/packages/stripe/src/Http/Middleware/StripeWebhookMiddleware.php index 309fb15422..07669da7f8 100644 --- a/packages/stripe/src/Http/Middleware/StripeWebhookMiddleware.php +++ b/packages/stripe/src/Http/Middleware/StripeWebhookMiddleware.php @@ -12,7 +12,7 @@ class StripeWebhookMiddleware { public function handle(Request $request, ?Closure $next = null) { - $secret = config('services.stripe.webhooks.payment_intent'); + $secret = config('services.stripe.webhooks.lunar'); $stripeSig = $request->header('Stripe-Signature'); try { @@ -28,10 +28,7 @@ public function handle(Request $request, ?Closure $next = null) if (! in_array( $event->type, [ - 'payment_intent.canceled', - 'payment_intent.created', 'payment_intent.payment_failed', - 'payment_intent.processing', 'payment_intent.succeeded', ] )) { diff --git a/packages/stripe/src/Jobs/ProcessStripeWebhook.php b/packages/stripe/src/Jobs/ProcessStripeWebhook.php new file mode 100644 index 0000000000..23a03b26d9 --- /dev/null +++ b/packages/stripe/src/Jobs/ProcessStripeWebhook.php @@ -0,0 +1,74 @@ +orderId) { + $order = Order::find($this->orderId); + + if ($order->placed_at) { + return; + } + } + + if (! $order) { + $cart = Cart::where('meta->payment_intent', '=', $this->paymentIntentId)->first(); + } + + if (! $cart && ! $order) { + Log::error( + "Unable to find cart with intent {$this->paymentIntentId}" + ); + + return; + } + + $payment = Payments::driver('stripe')->withData([ + 'payment_intent' => $this->paymentIntentId, + ]); + + if ($order) { + $payment->order($order)->authorize(); + + return; + } + + $payment->cart($cart->calculate())->authorize(); + } +} diff --git a/packages/stripe/src/Managers/StripeManager.php b/packages/stripe/src/Managers/StripeManager.php index 64b70a1c8c..f09d591b7e 100644 --- a/packages/stripe/src/Managers/StripeManager.php +++ b/packages/stripe/src/Managers/StripeManager.php @@ -98,8 +98,13 @@ public function updateIntent(Cart $cart, array $values): void return; } + $this->updateIntentById($meta['payment_intent'], $values); + } + + public function updateIntentById(string $id, array $values): void + { $this->getClient()->paymentIntents->update( - $meta['payment_intent'], + $id, $values ); } diff --git a/packages/stripe/src/StripePaymentType.php b/packages/stripe/src/StripePaymentType.php index c697b23c3b..0e873e2205 100644 --- a/packages/stripe/src/StripePaymentType.php +++ b/packages/stripe/src/StripePaymentType.php @@ -50,9 +50,13 @@ public function __construct() /** * Authorize the payment for processing. */ - final public function authorize(): PaymentAuthorize + final public function authorize(): ?PaymentAuthorize { - $this->order = $this->cart->draftOrder ?: $this->cart->completedOrder; + $this->order = $this->order ?: ($this->cart->draftOrder ?: $this->cart->completedOrder); + + if ($this->order && $this->order->placed_at) { + return null; + } if (! $this->order) { try { diff --git a/tests/core/Stubs/TestPaymentDriver.php b/tests/core/Stubs/TestPaymentDriver.php index a584a3be73..388e31475f 100644 --- a/tests/core/Stubs/TestPaymentDriver.php +++ b/tests/core/Stubs/TestPaymentDriver.php @@ -13,7 +13,7 @@ class TestPaymentDriver extends AbstractPayment /** * {@inheritDoc} */ - public function authorize(): PaymentAuthorize + public function authorize(): ?PaymentAuthorize { return new PaymentAuthorize(true); } diff --git a/tests/core/Unit/Actions/Carts/CreateOrderTest.php b/tests/core/Unit/Actions/Carts/CreateOrderTest.php index 7a0a07fc7d..c6933c96a5 100644 --- a/tests/core/Unit/Actions/Carts/CreateOrderTest.php +++ b/tests/core/Unit/Actions/Carts/CreateOrderTest.php @@ -216,16 +216,16 @@ function can_update_draft_order() 'tax_breakdown' => json_encode($breakdown), ]; - $cart = $cart->refresh(); + $cart = $cart->refresh()->calculate(); - expect($cart->draftOrder)->toBeInstanceOf(Order::class); - expect($order->cart_id)->toEqual($cart->id); - expect($cart->lines)->toHaveCount(1); - expect($order->lines)->toHaveCount(2); - expect($cart->addresses)->toHaveCount(2); - expect($order->addresses)->toHaveCount(2); - expect($order->shippingAddress)->toBeInstanceOf(OrderAddress::class); - expect($order->billingAddress)->toBeInstanceOf(OrderAddress::class); + expect($cart->currentDraftOrder())->toBeInstanceOf(Order::class) + ->and($order->cart_id)->toEqual($cart->id) + ->and($cart->lines)->toHaveCount(1) + ->and($order->lines)->toHaveCount(2) + ->and($cart->addresses)->toHaveCount(2) + ->and($order->addresses)->toHaveCount(2) + ->and($order->shippingAddress)->toBeInstanceOf(OrderAddress::class) + ->and($order->billingAddress)->toBeInstanceOf(OrderAddress::class); $this->assertDatabaseHas((new Order())->getTable(), $datacheck); $this->assertDatabaseHas((new OrderLine())->getTable(), [ @@ -349,7 +349,7 @@ function can_update_draft_order() 'tax_breakdown' => json_encode($breakdown), ]; - $cart = $cart->refresh(); + $cart = $cart->refresh()->calculate(); $this->assertDatabaseHas((new Order())->getTable(), $datacheck); }); diff --git a/tests/core/Unit/Models/CartTest.php b/tests/core/Unit/Models/CartTest.php index c19613abfc..3ad55a79eb 100644 --- a/tests/core/Unit/Models/CartTest.php +++ b/tests/core/Unit/Models/CartTest.php @@ -29,6 +29,8 @@ use Lunar\Models\TaxZonePostcode; use Lunar\Tests\Core\Stubs\User as StubUser; +use function Pest\Laravel\{assertDatabaseCount}; + uses(\Illuminate\Foundation\Testing\RefreshDatabase::class); //function setAuthUserConfig() @@ -280,15 +282,17 @@ $draftOrder = Order::factory()->create([ 'cart_id' => $cart->id, + 'fingerprint' => $cart->calculate()->fingerprint(), + 'total' => $cart->calculate()->total->value, 'placed_at' => null, ]); - expect($cart->draftOrder->id)->toEqual($draftOrder->id); + expect($cart->currentDraftOrder()->id)->toEqual($draftOrder->id); $draftOrder->delete(); - expect($cart->draftOrder()->first())->toBeNull(); -}); + expect($cart->currentDraftOrder())->toBeNull(); +})->group('nooo'); test('can get cart draft order by id', function () { $currency = Currency::factory()->create(); @@ -307,15 +311,19 @@ $draftOrder = Order::factory()->create([ 'cart_id' => $cart->id, + 'fingerprint' => $cart->calculate()->fingerprint(), + 'total' => $cart->calculate()->total->value, 'placed_at' => null, ]); $draftOrderTwo = Order::factory()->create([ 'cart_id' => $cart->id, + 'fingerprint' => $cart->calculate()->fingerprint(), + 'total' => $cart->calculate()->total->value, 'placed_at' => null, ]); - expect($cart->draftOrder->id)->toEqual($draftOrder->id); + expect($cart->currentDraftOrder()->id)->toEqual($draftOrder->id); expect($cart->draftOrder($draftOrderTwo->id)->first()->id)->toEqual($draftOrderTwo->id); }); @@ -966,4 +974,172 @@ expect($cart->shippingOptionOverride)->toBeInstanceOf(ShippingOption::class); expect($shippingOption->identifier)->toEqual($cart->shippingOptionOverride->identifier); -})->group('foofoo'); +}); + +test('can get new draft order when cart changes', function () { + $currency = Currency::factory() + ->state([ + 'code' => 'USD', + ]) + ->create(); + + $cart = Cart::factory()->create([ + 'currency_id' => $currency->id, + ]); + + $taxClass = TaxClass::factory()->create(); + + // Add product with unit qty + $purchasable = ProductVariant::factory() + ->state([ + 'unit_quantity' => 1, + ]) + ->create(); + + Price::factory()->create([ + 'price' => 158, + 'min_quantity' => 1, + 'currency_id' => $currency->id, + 'priceable_type' => get_class($purchasable), + 'priceable_id' => $purchasable->id, + ]); + + CartAddress::factory()->create([ + 'type' => 'billing', + 'cart_id' => $cart->id, + ]); + + CartAddress::factory()->create([ + 'type' => 'shipping', + 'cart_id' => $cart->id, + ]); + + $option = new ShippingOption( + name: 'Basic Delivery', + description: 'Basic Delivery', + identifier: 'BASDEL', + price: new \Lunar\DataTypes\Price(500, $cart->currency, 1), + taxClass: $taxClass + ); + + ShippingManifest::addOption($option); + + $cart->setShippingOption($option); + + $cart->lines()->create([ + 'purchasable_type' => get_class($purchasable), + 'purchasable_id' => $purchasable->id, + 'quantity' => 2, + ]); + + $order = $cart->createOrder(); + + assertDatabaseCount(Order::class, 1); + + expect($order->placed_at) + ->toBeNull() + ->and($order->fingerprint) + ->toBe($cart->fingerprint()) + ->and( + $cart->currentDraftOrder()->id + )->toBe($order->id); + + $cart->lines()->first()->update([ + 'quantity' => 5, + ]); + + $orderTwo = $cart->calculate()->createOrder(); + + assertDatabaseCount(Order::class, 2); + + expect($orderTwo->placed_at) + ->toBeNull() + ->and($orderTwo->fingerprint) + ->toBe($cart->fingerprint()) + ->and( + $cart->currentDraftOrder()->id + )->toBe($orderTwo->id); + +}); + +test('can get same draft order when cart does not change', function () { + $currency = Currency::factory() + ->state([ + 'code' => 'USD', + ]) + ->create(); + + $cart = Cart::factory()->create([ + 'currency_id' => $currency->id, + ]); + + $taxClass = TaxClass::factory()->create(); + + // Add product with unit qty + $purchasable = ProductVariant::factory() + ->state([ + 'unit_quantity' => 1, + ]) + ->create(); + + Price::factory()->create([ + 'price' => 158, + 'min_quantity' => 1, + 'currency_id' => $currency->id, + 'priceable_type' => get_class($purchasable), + 'priceable_id' => $purchasable->id, + ]); + + CartAddress::factory()->create([ + 'type' => 'billing', + 'cart_id' => $cart->id, + ]); + + CartAddress::factory()->create([ + 'type' => 'shipping', + 'cart_id' => $cart->id, + ]); + + $option = new ShippingOption( + name: 'Basic Delivery', + description: 'Basic Delivery', + identifier: 'BASDEL', + price: new \Lunar\DataTypes\Price(500, $cart->currency, 1), + taxClass: $taxClass + ); + + ShippingManifest::addOption($option); + + $cart->setShippingOption($option); + + $cart->lines()->create([ + 'purchasable_type' => get_class($purchasable), + 'purchasable_id' => $purchasable->id, + 'quantity' => 2, + ]); + + $order = $cart->createOrder(); + + assertDatabaseCount(Order::class, 1); + + expect($order->placed_at) + ->toBeNull() + ->and($order->fingerprint) + ->toBe($cart->fingerprint()) + ->and( + $cart->currentDraftOrder()->first()->id + )->toBe($order->id); + + $newOrder = $cart->createOrder(); + + assertDatabaseCount(Order::class, 1); + + expect($newOrder->placed_at) + ->toBeNull() + ->and($newOrder->fingerprint) + ->toBe($cart->fingerprint()) + ->and( + $cart->currentDraftOrder()->id + )->toBe($newOrder->id); + +}); diff --git a/tests/opayo/Feature/OpayoPaymentTypeTest.php b/tests/opayo/Feature/OpayoPaymentTypeTest.php index c4049b3f39..f23fae2824 100644 --- a/tests/opayo/Feature/OpayoPaymentTypeTest.php +++ b/tests/opayo/Feature/OpayoPaymentTypeTest.php @@ -46,7 +46,7 @@ expect($cart->completedOrder()->first())->toBeNull() ->and($response->status)->toEqual(\Lunar\Opayo\Facades\Opayo::AUTH_FAILED) - ->and($cart->draftOrder()->first()) + ->and($cart->currentDraftOrder()) ->toBeInstanceOf(\Lunar\Models\Order::class); assertDatabaseHas(\Lunar\Models\Transaction::class, [ @@ -71,7 +71,7 @@ expect($cart->completedOrder()->first())->toBeNull() ->and($response->status)->toEqual(\Lunar\Opayo\Facades\Opayo::THREED_AUTH) - ->and($cart->draftOrder()->first()) + ->and($cart->currentDraftOrder()) ->toBeInstanceOf(\Lunar\Models\Order::class); }); @@ -90,9 +90,9 @@ expect($cart->completedOrder()->first())->toBeNull() ->and($response->status) ->toEqual(\Lunar\Opayo\Facades\Opayo::AUTH_FAILED) - ->and($cart->draftOrder()->first()) + ->and($cart->currentDraftOrder()) ->toBeInstanceOf(\Lunar\Models\Order::class) - ->and($cart->draftOrder()->first()->placed_at) + ->and($cart->currentDraftOrder()->first()->placed_at) ->toBeNull(); assertDatabaseHas(\Lunar\Models\Transaction::class, [ diff --git a/tests/stripe/TestCase.php b/tests/stripe/TestCase.php index bb931625c6..ea9d950826 100644 --- a/tests/stripe/TestCase.php +++ b/tests/stripe/TestCase.php @@ -22,7 +22,7 @@ protected function setUp(): void // additional setup Config::set('providers.users.model', User::class); Config::set('services.stripe.key', 'SK_TESTER'); - Config::set('services.stripe.webhooks.payment_intent', 'FOOBAR'); + Config::set('services.stripe.webhooks.lunar', 'FOOBAR'); activity()->disableLogging(); diff --git a/tests/stripe/Unit/StripePaymentTypeTest.php b/tests/stripe/Unit/StripePaymentTypeTest.php index 0ad8f4e9f6..b33e66aa64 100644 --- a/tests/stripe/Unit/StripePaymentTypeTest.php +++ b/tests/stripe/Unit/StripePaymentTypeTest.php @@ -38,19 +38,17 @@ 'payment_intent' => 'PI_FAIL', ])->authorize(); - $order = $cart->refresh()->draftOrder; - - expect($response)->toBeInstanceOf(PaymentAuthorize::class); - expect($response->success)->toBeFalse(); - expect($cart->refresh()->completedOrder)->toBeNull(); - expect($cart->refresh()->draftOrder)->not()->toBeNull(); + expect($response)->toBeInstanceOf(PaymentAuthorize::class) + ->and($response->success)->toBeFalse() + ->and($cart->refresh()->completedOrder)->toBeNull() + ->and($cart->currentDraftOrder())->not()->toBeNull(); assertDatabaseHas((new Transaction)->getTable(), [ - 'order_id' => $order->id, + 'order_id' => $cart->currentDraftOrder()->id, 'type' => 'capture', 'success' => false, ]); -}); +})->group('noo'); it('can retrieve existing payment intent', function () { $cart = CartBuilder::build([ From 00b16e2c4d9964af5d9ba4b1d478d47012d45efb Mon Sep 17 00:00:00 2001 From: Alec Ritson Date: Tue, 23 Jul 2024 14:32:27 +0100 Subject: [PATCH 07/18] Update upgrading.md --- docs/core/upgrading.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/core/upgrading.md b/docs/core/upgrading.md index e571d738f9..272ff62a95 100644 --- a/docs/core/upgrading.md +++ b/docs/core/upgrading.md @@ -28,7 +28,19 @@ The Stripe driver will now check whether an order has a value for `placed_at` ag Additionally, the logic in the webhook has been moved to the job queue, which is dispatched with a delay of 20 seconds, this is to allow storefronts to manually process a payment intent, in addition to the webhook, without having to worry about overlap. -The Stripe webhook ENV entry has been changed from `STRIPE_WEBHOOK_PAYMENT_INTENT` to `LUNAR_STRIPE_WEBHOOK_SECRET` +The Stripe webhook ENV entry has been changed from `STRIPE_WEBHOOK_PAYMENT_INTENT` to `LUNAR_STRIPE_WEBHOOK_SECRET`. + +The stripe config Lunar looks for in `config/services.php` has changed and should now look like: + +```php +'stripe' => [ + 'key' => env('STRIPE_SECRET'), + 'public_key' => env('STRIPE_PK'), + 'webhooks' => [ + 'lunar' => env('LUNAR_STRIPE_WEBHOOK_SECRET'), + ], +], +``` ## 1.0.0-alpha.32 From a914bfdcdf734bbfcf3bbef5f4034e63a6fa27e0 Mon Sep 17 00:00:00 2001 From: Lionel Guichard Date: Wed, 24 Jul 2024 12:21:01 +0200 Subject: [PATCH 08/18] Fix - Cart session manager (#1878) --- .../core/src/Managers/CartSessionManager.php | 8 ++++---- .../Unit/Managers/CartSessionManagerTest.php | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/packages/core/src/Managers/CartSessionManager.php b/packages/core/src/Managers/CartSessionManager.php index d79b918147..975c104d6b 100644 --- a/packages/core/src/Managers/CartSessionManager.php +++ b/packages/core/src/Managers/CartSessionManager.php @@ -140,14 +140,14 @@ private function fetchOrCreate(bool $create = false, bool $estimateShipping = fa config('lunar.cart.eager_load', []) )->find($cartId); - if ($cart->hasCompletedOrders() && ! $this->allowsMultipleOrdersPerCart()) { - return $this->createNewCart(); - } - if (! $cart) { return $create ? $this->createNewCart() : null; } + if ($cart->hasCompletedOrders() && ! $this->allowsMultipleOrdersPerCart()) { + return $this->createNewCart(); + } + $this->cart = $cart; if ($calculate) { diff --git a/tests/core/Unit/Managers/CartSessionManagerTest.php b/tests/core/Unit/Managers/CartSessionManagerTest.php index 2fbdc92890..ee1ffae389 100644 --- a/tests/core/Unit/Managers/CartSessionManagerTest.php +++ b/tests/core/Unit/Managers/CartSessionManagerTest.php @@ -51,6 +51,25 @@ expect($sessionCart)->toEqual($cart->id); }); +test('can fetch current cart if session exist', function () { + $manager = app(CartSessionManager::class); + + Currency::factory()->create([ + 'default' => true, + ]); + + Channel::factory()->create([ + 'default' => true, + ]); + + Config::set('lunar.cart_session.auto_create', false); + Session::put(config('lunar.cart_session.session_key'), 1); + + $cart = $manager->current(); + + expect($cart)->toBeNull(); +}); + test('can create order from session cart and cleanup', function () { Currency::factory()->create([ 'default' => true, From 908f38a4ea064eb15c7156265b0d8cef03476030 Mon Sep 17 00:00:00 2001 From: alecritson Date: Wed, 24 Jul 2024 10:23:34 +0000 Subject: [PATCH 09/18] chore: fix code style --- .../Pages/ManageProductInventory.php | 2 +- packages/admin/src/LunarPanelProvider.php | 8 ++++---- .../core/database/factories/OrderFactory.php | 2 +- packages/core/src/Base/Casts/AsAttributeData.php | 4 ++-- .../core/src/Base/Casts/ShippingBreakdown.php | 2 +- packages/core/src/FieldTypes/TranslatedText.php | 2 +- packages/core/src/LunarServiceProvider.php | 14 +++++++------- packages/core/src/Managers/PricingManager.php | 2 +- .../src/Managers/StorefrontSessionManager.php | 2 +- packages/core/src/Models/Cart.php | 2 +- .../meilisearch/src/Console/MeilisearchSetup.php | 2 +- packages/opayo/src/OpayoPaymentType.php | 2 +- packages/stripe/src/Facades/Stripe.php | 2 +- .../DataTransferObjects/ShippingOptionLookup.php | 2 +- .../Pages/ManageShippingRates.php | 2 +- .../OrderResource/Pages/ManageOrderTest.php | 2 +- .../ProductResource/ListProductsTest.php | 6 +++--- .../Pages/ManageProductIdentifiersTest.php | 2 +- .../Pages/ManageProductInventoryTest.php | 2 +- .../Pages/ManageProductShippingTest.php | 4 ++-- .../Actions/Carts/AddOrUpdatePurchasableTest.php | 2 +- .../core/Unit/Actions/Carts/CreateOrderTest.php | 6 +++--- .../Actions/Carts/GenerateFingerprintTest.php | 2 +- .../Unit/Actions/Carts/UpdateCartLineTest.php | 2 +- .../Unit/Base/Casts/ShippingBreakdownTest.php | 4 ++-- tests/core/Unit/Base/Casts/TaxBreakdownTest.php | 4 ++-- tests/core/Unit/Base/MacroableModelTest.php | 4 ++-- tests/core/Unit/Base/ShippingModifiersTest.php | 2 +- tests/core/Unit/FieldTypes/ListFieldTest.php | 2 +- tests/core/Unit/FieldTypes/NumberTest.php | 2 +- tests/core/Unit/FieldTypes/TextTest.php | 10 +++++----- .../core/Unit/FieldTypes/TranslatedTextTest.php | 2 +- tests/core/Unit/Managers/PricingManagerTest.php | 16 ++++++++-------- tests/core/Unit/Models/CartLineTest.php | 4 ++-- tests/core/Unit/Models/CartTest.php | 10 +++++----- tests/core/Unit/Models/OrderLineTest.php | 6 +++--- tests/core/Unit/Models/OrderTest.php | 2 +- tests/core/Unit/Models/PriceTest.php | 2 +- tests/core/Unit/Models/TaxClassTest.php | 2 +- tests/core/Unit/Models/TaxRateTest.php | 4 ++-- tests/core/Unit/Models/TaxZoneCountryTest.php | 2 +- tests/core/Unit/Models/TaxZonePostcodeTest.php | 2 +- tests/core/Unit/Models/TaxZoneTest.php | 10 +++++----- tests/core/Unit/Models/TransactionTest.php | 6 +++--- .../core/Unit/Rules/MaxDecimalPlacesRuleTest.php | 8 ++++---- .../Validation/CartLine/CartLineStockTest.php | 2 +- tests/opayo/Feature/OpayoPaymentTypeTest.php | 10 +++++----- .../Drivers/ShippingMethods/CollectionTest.php | 2 +- .../Drivers/ShippingMethods/FlatRateTest.php | 2 +- .../Drivers/ShippingMethods/FreeShippingTest.php | 6 +++--- .../Unit/Drivers/ShippingMethods/ShipByTest.php | 8 ++++---- .../Unit/Models/ShippingZonePostcodeTest.php | 2 +- .../Unit/Resolvers/PostcodeResolverTest.php | 6 +++--- .../Unit/Resolvers/ShippingZoneResolverTest.php | 8 ++++---- 54 files changed, 114 insertions(+), 114 deletions(-) diff --git a/packages/admin/src/Filament/Resources/ProductResource/Pages/ManageProductInventory.php b/packages/admin/src/Filament/Resources/ProductResource/Pages/ManageProductInventory.php index 893a899b25..900356b578 100644 --- a/packages/admin/src/Filament/Resources/ProductResource/Pages/ManageProductInventory.php +++ b/packages/admin/src/Filament/Resources/ProductResource/Pages/ManageProductInventory.php @@ -94,7 +94,7 @@ protected function getFormActions(): array public function form(Form $form): Form { - return (new ManageVariantInventory())->form($form)->statePath(''); + return (new ManageVariantInventory)->form($form)->statePath(''); } public function getRelationManagers(): array diff --git a/packages/admin/src/LunarPanelProvider.php b/packages/admin/src/LunarPanelProvider.php index 34d2aba7a6..9f5f062b18 100644 --- a/packages/admin/src/LunarPanelProvider.php +++ b/packages/admin/src/LunarPanelProvider.php @@ -42,19 +42,19 @@ class LunarPanelProvider extends ServiceProvider public function register(): void { $this->app->scoped('lunar-panel', function (): LunarPanelManager { - return new LunarPanelManager(); + return new LunarPanelManager; }); $this->app->scoped('lunar-access-control', function (): Manifest { - return new Manifest(); + return new Manifest; }); $this->app->scoped('lunar-activity-log', function (): ActivityLogManifest { - return new ActivityLogManifest(); + return new ActivityLogManifest; }); $this->app->scoped('lunar-attribute-data', function (): AttributeData { - return new AttributeData(); + return new AttributeData; }); } diff --git a/packages/core/database/factories/OrderFactory.php b/packages/core/database/factories/OrderFactory.php index bee9510b23..32f40308a6 100644 --- a/packages/core/database/factories/OrderFactory.php +++ b/packages/core/database/factories/OrderFactory.php @@ -25,7 +25,7 @@ public function definition(): array 'sub_total' => $total - $taxTotal, 'discount_total' => 0, 'shipping_total' => 0, - 'tax_breakdown' => new TaxBreakdown(), + 'tax_breakdown' => new TaxBreakdown, 'tax_total' => $taxTotal, 'total' => $total, 'notes' => null, diff --git a/packages/core/src/Base/Casts/AsAttributeData.php b/packages/core/src/Base/Casts/AsAttributeData.php index c903105f75..c0eb262b0a 100644 --- a/packages/core/src/Base/Casts/AsAttributeData.php +++ b/packages/core/src/Base/Casts/AsAttributeData.php @@ -17,7 +17,7 @@ class AsAttributeData implements Castable */ public static function castUsing(array $arguments) { - return new class() implements CastsAttributes + return new class implements CastsAttributes { public function get($model, $key, $value, $attributes) { @@ -27,7 +27,7 @@ public function get($model, $key, $value, $attributes) $data = json_decode($attributes[$key], true); - $returnData = new Collection(); + $returnData = new Collection; foreach ($data as $key => $item) { if (! class_exists($item['field_type'])) { diff --git a/packages/core/src/Base/Casts/ShippingBreakdown.php b/packages/core/src/Base/Casts/ShippingBreakdown.php index 4cfe564621..a9a96b6d66 100644 --- a/packages/core/src/Base/Casts/ShippingBreakdown.php +++ b/packages/core/src/Base/Casts/ShippingBreakdown.php @@ -21,7 +21,7 @@ class ShippingBreakdown implements CastsAttributes, SerializesCastableAttributes */ public function get($model, $key, $value, $attributes) { - $breakdown = new \Lunar\Base\ValueObjects\Cart\ShippingBreakdown(); + $breakdown = new \Lunar\Base\ValueObjects\Cart\ShippingBreakdown; $breakdown->items = collect( json_decode($value, false) diff --git a/packages/core/src/FieldTypes/TranslatedText.php b/packages/core/src/FieldTypes/TranslatedText.php index 6e38b58be0..0cf2f20a8a 100644 --- a/packages/core/src/FieldTypes/TranslatedText.php +++ b/packages/core/src/FieldTypes/TranslatedText.php @@ -24,7 +24,7 @@ public function __construct($value = null) if ($value) { $this->setValue($value); } else { - $this->value = new Collection(); + $this->value = new Collection; } } diff --git a/packages/core/src/LunarServiceProvider.php b/packages/core/src/LunarServiceProvider.php index 3b1596a4cf..ced1c4b454 100644 --- a/packages/core/src/LunarServiceProvider.php +++ b/packages/core/src/LunarServiceProvider.php @@ -120,15 +120,15 @@ public function register(): void $this->registerAddonManifest(); $this->app->singleton(CartModifiers::class, function () { - return new CartModifiers(); + return new CartModifiers; }); $this->app->singleton(CartLineModifiers::class, function () { - return new CartLineModifiers(); + return new CartLineModifiers; }); $this->app->singleton(OrderModifiers::class, function () { - return new OrderModifiers(); + return new OrderModifiers; }); $this->app->singleton(CartSessionInterface::class, function ($app) { @@ -140,7 +140,7 @@ public function register(): void }); $this->app->singleton(ShippingModifiers::class, function ($app) { - return new ShippingModifiers(); + return new ShippingModifiers; }); $this->app->singleton(ShippingManifestInterface::class, function ($app) { @@ -250,7 +250,7 @@ public function boot(): void protected function registerAddonManifest() { $this->app->instance(Manifest::class, new Manifest( - new Filesystem(), + new Filesystem, $this->app->basePath(), $this->app->bootstrapPath().'/cache/lunar_addons.php' )); @@ -340,7 +340,7 @@ protected function registerBlueprintMacros(): void $this->foreignUuId($field_name) ->nullable($nullable) ->constrained( - (new $userModel())->getTable() + (new $userModel)->getTable() ); } elseif ($type == 'int') { $this->unsignedInteger($field_name)->nullable($nullable); @@ -349,7 +349,7 @@ protected function registerBlueprintMacros(): void $this->foreignId($field_name) ->nullable($nullable) ->constrained( - (new $userModel())->getTable() + (new $userModel)->getTable() ); } }); diff --git a/packages/core/src/Managers/PricingManager.php b/packages/core/src/Managers/PricingManager.php index a445e9cbae..d941fa3363 100644 --- a/packages/core/src/Managers/PricingManager.php +++ b/packages/core/src/Managers/PricingManager.php @@ -174,7 +174,7 @@ public function get() }); if (! $currencyPrices->count()) { - throw new MissingCurrencyPriceException(); + throw new MissingCurrencyPriceException; } $prices = $currencyPrices->filter(function ($price) { diff --git a/packages/core/src/Managers/StorefrontSessionManager.php b/packages/core/src/Managers/StorefrontSessionManager.php index be51bad691..5128295f8b 100644 --- a/packages/core/src/Managers/StorefrontSessionManager.php +++ b/packages/core/src/Managers/StorefrontSessionManager.php @@ -208,7 +208,7 @@ public function setCustomer(Customer $customer): self && is_lunar_user($this->authManager->user()) && ! $this->customerBelongsToUser($customer) ) { - throw new CustomerNotBelongsToUserException(); + throw new CustomerNotBelongsToUserException; } $this->customer = $customer; diff --git a/packages/core/src/Models/Cart.php b/packages/core/src/Models/Cart.php index 8bf9a3c546..e8ebd35e46 100644 --- a/packages/core/src/Models/Cart.php +++ b/packages/core/src/Models/Cart.php @@ -651,7 +651,7 @@ public function fingerprint(): string { $generator = config('lunar.cart.fingerprint_generator', GenerateFingerprint::class); - return (new $generator())->execute($this); + return (new $generator)->execute($this); } /** diff --git a/packages/meilisearch/src/Console/MeilisearchSetup.php b/packages/meilisearch/src/Console/MeilisearchSetup.php index 8ff8571d84..91001e335c 100644 --- a/packages/meilisearch/src/Console/MeilisearchSetup.php +++ b/packages/meilisearch/src/Console/MeilisearchSetup.php @@ -40,7 +40,7 @@ public function handle(EngineManager $engine): void // Make sure we have the relevant indexes ready to go. foreach ($searchables as $searchable) { - $model = (new $searchable()); + $model = (new $searchable); $indexName = $model->searchableAs(); diff --git a/packages/opayo/src/OpayoPaymentType.php b/packages/opayo/src/OpayoPaymentType.php index 2716301733..138483f095 100644 --- a/packages/opayo/src/OpayoPaymentType.php +++ b/packages/opayo/src/OpayoPaymentType.php @@ -518,7 +518,7 @@ private function saveCard(Order $order, object $details, ?string $authCode = nul OpayoToken::where('last_four', '=', $details->lastFourDigits) ->where('user_id', '=', $order->user_id)->delete(); - $payment = new OpayoToken(); + $payment = new OpayoToken; $payment->user_id = $this->order->user_id; $payment->card_type = strtolower($details->cardType); $payment->last_four = $details->lastFourDigits; diff --git a/packages/stripe/src/Facades/Stripe.php b/packages/stripe/src/Facades/Stripe.php index 43c707ab22..603529b96a 100644 --- a/packages/stripe/src/Facades/Stripe.php +++ b/packages/stripe/src/Facades/Stripe.php @@ -30,7 +30,7 @@ protected static function getFacadeAccessor(): string public static function fake(): void { - $mockClient = new MockClient(); + $mockClient = new MockClient; ApiRequestor::setHttpClient($mockClient); } } diff --git a/packages/table-rate-shipping/src/DataTransferObjects/ShippingOptionLookup.php b/packages/table-rate-shipping/src/DataTransferObjects/ShippingOptionLookup.php index edaba3b848..3c8bfc5e62 100644 --- a/packages/table-rate-shipping/src/DataTransferObjects/ShippingOptionLookup.php +++ b/packages/table-rate-shipping/src/DataTransferObjects/ShippingOptionLookup.php @@ -18,7 +18,7 @@ public function __construct( $this->shippingRates->filter( fn ($method) => get_class($method) != ShippingRate::class )->count(), - new InvalidArgument() + new InvalidArgument ); } } diff --git a/packages/table-rate-shipping/src/Filament/Resources/ShippingZoneResource/Pages/ManageShippingRates.php b/packages/table-rate-shipping/src/Filament/Resources/ShippingZoneResource/Pages/ManageShippingRates.php index 99475a1e5b..c0ee1ffd1a 100644 --- a/packages/table-rate-shipping/src/Filament/Resources/ShippingZoneResource/Pages/ManageShippingRates.php +++ b/packages/table-rate-shipping/src/Filament/Resources/ShippingZoneResource/Pages/ManageShippingRates.php @@ -150,7 +150,7 @@ public function table(Table $table): Table )->action(function (Table $table, ?ShippingRate $shippingRate = null, array $data = []) { $relationship = $table->getRelationship(); - $record = new ShippingRate(); + $record = new ShippingRate; $record->shipping_method_id = $data['shipping_method_id']; $relationship->save($record); diff --git a/tests/admin/Feature/Filament/Resources/OrderResource/Pages/ManageOrderTest.php b/tests/admin/Feature/Filament/Resources/OrderResource/Pages/ManageOrderTest.php index 76dda0bab9..7817b4e0de 100644 --- a/tests/admin/Feature/Filament/Resources/OrderResource/Pages/ManageOrderTest.php +++ b/tests/admin/Feature/Filament/Resources/OrderResource/Pages/ManageOrderTest.php @@ -71,7 +71,7 @@ $tax = (int) ($subTotal * .2); $options = $variant->values->map(fn ($value) => $value->translate('name')); - $itemTax = (new TaxBreakdown()); + $itemTax = (new TaxBreakdown); $itemTax->addAmount(new TaxBreakdownAmount( price: new Price( value: $tax, diff --git a/tests/admin/Feature/Filament/Resources/ProductResource/ListProductsTest.php b/tests/admin/Feature/Filament/Resources/ProductResource/ListProductsTest.php index 04f55ccc58..798252c396 100644 --- a/tests/admin/Feature/Filament/Resources/ProductResource/ListProductsTest.php +++ b/tests/admin/Feature/Filament/Resources/ProductResource/ListProductsTest.php @@ -40,7 +40,7 @@ 'product_type_id' => $productType->id, ])->assertHasNoActionErrors(); - $this->assertDatabaseHas((new \Lunar\Models\Product())->getTable(), [ + $this->assertDatabaseHas((new \Lunar\Models\Product)->getTable(), [ 'product_type_id' => $productType->id, 'status' => 'draft', 'attribute_data' => json_encode([ @@ -53,11 +53,11 @@ ]), ]); - $this->assertDatabaseHas((new \Lunar\Models\ProductVariant())->getTable(), [ + $this->assertDatabaseHas((new \Lunar\Models\ProductVariant)->getTable(), [ 'sku' => 'ABCABCAB', ]); - $this->assertDatabaseHas((new \Lunar\Models\Price())->getTable(), [ + $this->assertDatabaseHas((new \Lunar\Models\Price)->getTable(), [ 'price' => '1099', ]); }); diff --git a/tests/admin/Feature/Filament/Resources/ProductResource/Pages/ManageProductIdentifiersTest.php b/tests/admin/Feature/Filament/Resources/ProductResource/Pages/ManageProductIdentifiersTest.php index df97042dcb..2fdcfee3a0 100644 --- a/tests/admin/Feature/Filament/Resources/ProductResource/Pages/ManageProductIdentifiersTest.php +++ b/tests/admin/Feature/Filament/Resources/ProductResource/Pages/ManageProductIdentifiersTest.php @@ -103,7 +103,7 @@ 'ean' => 'FOOBAREAN', ])->call('save')->assertHasNoErrors(); - $this->assertDatabaseHas((new \Lunar\Models\ProductVariant())->getTable(), [ + $this->assertDatabaseHas((new \Lunar\Models\ProductVariant)->getTable(), [ 'sku' => 'FOOBARSKU', 'mpn' => 'FOOBARMPN', 'gtin' => 'FOOBARGTIN', diff --git a/tests/admin/Feature/Filament/Resources/ProductResource/Pages/ManageProductInventoryTest.php b/tests/admin/Feature/Filament/Resources/ProductResource/Pages/ManageProductInventoryTest.php index adbc903f8b..2a342d920c 100644 --- a/tests/admin/Feature/Filament/Resources/ProductResource/Pages/ManageProductInventoryTest.php +++ b/tests/admin/Feature/Filament/Resources/ProductResource/Pages/ManageProductInventoryTest.php @@ -102,7 +102,7 @@ 'purchasable' => 'in_stock_or_on_backorder', ])->call('save')->assertHasNoErrors(); - $this->assertDatabaseHas((new \Lunar\Models\ProductVariant())->getTable(), [ + $this->assertDatabaseHas((new \Lunar\Models\ProductVariant)->getTable(), [ 'stock' => 500, 'backorder' => 50, 'purchasable' => 'in_stock_or_on_backorder', diff --git a/tests/admin/Feature/Filament/Resources/ProductResource/Pages/ManageProductShippingTest.php b/tests/admin/Feature/Filament/Resources/ProductResource/Pages/ManageProductShippingTest.php index 5ba7c09991..f5671130f9 100644 --- a/tests/admin/Feature/Filament/Resources/ProductResource/Pages/ManageProductShippingTest.php +++ b/tests/admin/Feature/Filament/Resources/ProductResource/Pages/ManageProductShippingTest.php @@ -108,7 +108,7 @@ 'dimensions.weight_unit' => 'g', ])->call('save')->assertHasNoErrors(); - $this->assertDatabaseHas((new \Lunar\Models\ProductVariant())->getTable(), [ + $this->assertDatabaseHas((new \Lunar\Models\ProductVariant)->getTable(), [ 'shippable' => true, 'length_value' => 100, 'length_unit' => 'cm', @@ -154,7 +154,7 @@ 'dimensions.weight_unit' => 'g', ])->call('save')->assertHasNoErrors(); - $this->assertDatabaseHas((new \Lunar\Models\ProductVariant())->getTable(), [ + $this->assertDatabaseHas((new \Lunar\Models\ProductVariant)->getTable(), [ 'volume_value' => 1000, 'volume_unit' => 'l', ]); diff --git a/tests/core/Unit/Actions/Carts/AddOrUpdatePurchasableTest.php b/tests/core/Unit/Actions/Carts/AddOrUpdatePurchasableTest.php index 31b6da7d31..0776b2bd89 100644 --- a/tests/core/Unit/Actions/Carts/AddOrUpdatePurchasableTest.php +++ b/tests/core/Unit/Actions/Carts/AddOrUpdatePurchasableTest.php @@ -93,7 +93,7 @@ expect($cart->refresh()->lines)->toHaveCount(1); - $this->assertDatabaseHas((new CartLine())->getTable(), [ + $this->assertDatabaseHas((new CartLine)->getTable(), [ 'cart_id' => $cart->id, 'quantity' => 2, ]); diff --git a/tests/core/Unit/Actions/Carts/CreateOrderTest.php b/tests/core/Unit/Actions/Carts/CreateOrderTest.php index c6933c96a5..aefb26968e 100644 --- a/tests/core/Unit/Actions/Carts/CreateOrderTest.php +++ b/tests/core/Unit/Actions/Carts/CreateOrderTest.php @@ -227,8 +227,8 @@ function can_update_draft_order() ->and($order->shippingAddress)->toBeInstanceOf(OrderAddress::class) ->and($order->billingAddress)->toBeInstanceOf(OrderAddress::class); - $this->assertDatabaseHas((new Order())->getTable(), $datacheck); - $this->assertDatabaseHas((new OrderLine())->getTable(), [ + $this->assertDatabaseHas((new Order)->getTable(), $datacheck); + $this->assertDatabaseHas((new OrderLine)->getTable(), [ 'identifier' => $shippingOption->getIdentifier(), ]); @@ -351,5 +351,5 @@ function can_update_draft_order() $cart = $cart->refresh()->calculate(); - $this->assertDatabaseHas((new Order())->getTable(), $datacheck); + $this->assertDatabaseHas((new Order)->getTable(), $datacheck); }); diff --git a/tests/core/Unit/Actions/Carts/GenerateFingerprintTest.php b/tests/core/Unit/Actions/Carts/GenerateFingerprintTest.php index 7f12068663..8997eb3657 100644 --- a/tests/core/Unit/Actions/Carts/GenerateFingerprintTest.php +++ b/tests/core/Unit/Actions/Carts/GenerateFingerprintTest.php @@ -42,7 +42,7 @@ $cart->coupon_code = 'valid-coupon'; - $fingerprint = (new GenerateFingerprint())->execute($cart); + $fingerprint = (new GenerateFingerprint)->execute($cart); $fingerprintFromCart = $cart->fingerprint(); expect($fingerprintFromCart)->toBe($fingerprint); diff --git a/tests/core/Unit/Actions/Carts/UpdateCartLineTest.php b/tests/core/Unit/Actions/Carts/UpdateCartLineTest.php index 62f15cc6bb..8c219cfe05 100644 --- a/tests/core/Unit/Actions/Carts/UpdateCartLineTest.php +++ b/tests/core/Unit/Actions/Carts/UpdateCartLineTest.php @@ -36,7 +36,7 @@ $action = new UpdateCartLine; - $this->assertDatabaseHas((new CartLine())->getTable(), [ + $this->assertDatabaseHas((new CartLine)->getTable(), [ 'quantity' => 1, 'id' => $line->id, ]); diff --git a/tests/core/Unit/Base/Casts/ShippingBreakdownTest.php b/tests/core/Unit/Base/Casts/ShippingBreakdownTest.php index af990a5fb2..1be710b89d 100644 --- a/tests/core/Unit/Base/Casts/ShippingBreakdownTest.php +++ b/tests/core/Unit/Base/Casts/ShippingBreakdownTest.php @@ -14,7 +14,7 @@ $currency = Currency::factory()->create(); $order = Order::factory()->create(); - $shippingBreakdownValueObject = new ShippingBreakdown(); + $shippingBreakdownValueObject = new ShippingBreakdown; $shippingBreakdownValueObject->items->put('DELIV', new ShippingBreakdownItem( @@ -36,7 +36,7 @@ $currency = Currency::factory()->create(); $order = Order::factory()->create(); - $shippingBreakdownValueObject = new ShippingBreakdown(); + $shippingBreakdownValueObject = new ShippingBreakdown; $shippingBreakdownValueObject->items->put('DELIV', new ShippingBreakdownItem( diff --git a/tests/core/Unit/Base/Casts/TaxBreakdownTest.php b/tests/core/Unit/Base/Casts/TaxBreakdownTest.php index 8ee5445821..bf3b968de4 100644 --- a/tests/core/Unit/Base/Casts/TaxBreakdownTest.php +++ b/tests/core/Unit/Base/Casts/TaxBreakdownTest.php @@ -14,7 +14,7 @@ $currency = Currency::factory()->create(); $order = Order::factory()->create(); - $taxBreakdownValueObject = new TaxBreakdown(); + $taxBreakdownValueObject = new TaxBreakdown; $taxBreakdownValueObject->addAmount( new TaxBreakdownAmount( @@ -37,7 +37,7 @@ $currency = Currency::factory()->create(); $order = Order::factory()->create(); - $taxBreakdownValueObject = new TaxBreakdown(); + $taxBreakdownValueObject = new TaxBreakdown; $taxBreakdownValueObject->addAmount( new TaxBreakdownAmount( diff --git a/tests/core/Unit/Base/MacroableModelTest.php b/tests/core/Unit/Base/MacroableModelTest.php index 51e854cd35..104dc2af9e 100644 --- a/tests/core/Unit/Base/MacroableModelTest.php +++ b/tests/core/Unit/Base/MacroableModelTest.php @@ -5,7 +5,7 @@ use Lunar\Models\Product; beforeEach(function () { - $this->model = new Product(); + $this->model = new Product; }); test('can register a new macro', function () { @@ -18,7 +18,7 @@ }); test('can register a new macro and be invoked', function () { - $this->model::macro('newMethod', new class() + $this->model::macro('newMethod', new class { public function __invoke() { diff --git a/tests/core/Unit/Base/ShippingModifiersTest.php b/tests/core/Unit/Base/ShippingModifiersTest.php index 847fe69369..09d0effba6 100644 --- a/tests/core/Unit/Base/ShippingModifiersTest.php +++ b/tests/core/Unit/Base/ShippingModifiersTest.php @@ -26,7 +26,7 @@ public function handle(Cart $cart, Closure $next) } }; - $this->shippingModifiers = new ShippingModifiers(); + $this->shippingModifiers = new ShippingModifiers; }); test('can add modifier', function () { diff --git a/tests/core/Unit/FieldTypes/ListFieldTest.php b/tests/core/Unit/FieldTypes/ListFieldTest.php index 7453955984..7b4ac42750 100644 --- a/tests/core/Unit/FieldTypes/ListFieldTest.php +++ b/tests/core/Unit/FieldTypes/ListFieldTest.php @@ -5,7 +5,7 @@ use Lunar\FieldTypes\ListField; test('can set value', function () { - $field = new ListField(); + $field = new ListField; $field->setValue([ 'Foo', ]); diff --git a/tests/core/Unit/FieldTypes/NumberTest.php b/tests/core/Unit/FieldTypes/NumberTest.php index f2dde224e1..0ae89989a0 100644 --- a/tests/core/Unit/FieldTypes/NumberTest.php +++ b/tests/core/Unit/FieldTypes/NumberTest.php @@ -5,7 +5,7 @@ use Lunar\FieldTypes\Number; test('can set value', function () { - $field = new Number(); + $field = new Number; $field->setValue(12345); expect($field->getValue())->toEqual(12345); diff --git a/tests/core/Unit/FieldTypes/TextTest.php b/tests/core/Unit/FieldTypes/TextTest.php index 43cde5a69e..246e06b766 100644 --- a/tests/core/Unit/FieldTypes/TextTest.php +++ b/tests/core/Unit/FieldTypes/TextTest.php @@ -5,24 +5,24 @@ use Lunar\FieldTypes\Text; test('can set value', function () { - $field = new Text(); + $field = new Text; $field->setValue('I like cake'); expect($field->getValue())->toEqual('I like cake'); - $field = new Text(); + $field = new Text; $field->setValue(12345); expect($field->getValue())->toEqual(12345); - $field = new Text(); + $field = new Text; $field->setValue(true); expect($field->getValue())->toEqual(true); }); test('can set null value', function () { - $field = new Text(); + $field = new Text; $field->setValue(null); expect($field->getValue())->toEqual(null); @@ -37,5 +37,5 @@ test('check does not allow non strings', function () { $this->expectException(FieldTypeException::class); - $field = new Text(new \stdClass()); + $field = new Text(new \stdClass); }); diff --git a/tests/core/Unit/FieldTypes/TranslatedTextTest.php b/tests/core/Unit/FieldTypes/TranslatedTextTest.php index de3268dd31..4a0f01298f 100644 --- a/tests/core/Unit/FieldTypes/TranslatedTextTest.php +++ b/tests/core/Unit/FieldTypes/TranslatedTextTest.php @@ -8,7 +8,7 @@ use Lunar\FieldTypes\TranslatedText; test('can set value', function () { - $field = new TranslatedText(); + $field = new TranslatedText; $field->setValue(collect([ 'en' => new Text('Blue'), 'fr' => new Text('Bleu'), diff --git a/tests/core/Unit/Managers/PricingManagerTest.php b/tests/core/Unit/Managers/PricingManagerTest.php index 73a5447b79..94891eb4d6 100644 --- a/tests/core/Unit/Managers/PricingManagerTest.php +++ b/tests/core/Unit/Managers/PricingManagerTest.php @@ -16,11 +16,11 @@ uses(\Illuminate\Foundation\Testing\RefreshDatabase::class); test('can initialise the manager', function () { - expect(new PricingManager())->toBeInstanceOf(PricingManager::class); + expect(new PricingManager)->toBeInstanceOf(PricingManager::class); }); test('can set up available guest pricing', function () { - $manager = new PricingManager(); + $manager = new PricingManager; $currency = Currency::factory()->create([ 'default' => true, @@ -70,7 +70,7 @@ }); test('can get purchasable price with defaults', function () { - $manager = new PricingManager(); + $manager = new PricingManager; $currency = Currency::factory()->create([ 'default' => true, @@ -101,7 +101,7 @@ }); test('can fetch customer group price', function () { - $manager = new PricingManager(); + $manager = new PricingManager; $customerGroups = CustomerGroup::factory(5)->create(); @@ -153,7 +153,7 @@ }); test('can fetch quantity break price', function () { - $manager = new PricingManager(); + $manager = new PricingManager; $currency = Currency::factory()->create([ 'default' => true, @@ -242,7 +242,7 @@ }); test('can match based on currency', function () { - $manager = new PricingManager(); + $manager = new PricingManager; $defaultCurrency = Currency::factory()->create([ 'default' => true, @@ -292,7 +292,7 @@ /** @test */ function can_fetch_correct_price_for_user() { - $manager = new PricingManager(); + $manager = new PricingManager; $user = User::factory()->create(); @@ -352,7 +352,7 @@ function can_fetch_correct_price_for_user() } test('can pipeline purchasable price', function () { - $manager = new PricingManager(); + $manager = new PricingManager; $currency = Currency::factory()->create([ 'default' => true, diff --git a/tests/core/Unit/Models/CartLineTest.php b/tests/core/Unit/Models/CartLineTest.php index e7aeea4deb..657933d42d 100644 --- a/tests/core/Unit/Models/CartLineTest.php +++ b/tests/core/Unit/Models/CartLineTest.php @@ -25,7 +25,7 @@ CartLine::create($data); - $this->assertDatabaseHas((new CartLine())->getTable(), $data); + $this->assertDatabaseHas((new CartLine)->getTable(), $data); }); test('only purchasables can be added to a cart', function () { @@ -44,5 +44,5 @@ CartLine::create($data); - $this->assertDatabaseMissing((new CartLine())->getTable(), $data); + $this->assertDatabaseMissing((new CartLine)->getTable(), $data); }); diff --git a/tests/core/Unit/Models/CartTest.php b/tests/core/Unit/Models/CartTest.php index 3ad55a79eb..1efe360c9b 100644 --- a/tests/core/Unit/Models/CartTest.php +++ b/tests/core/Unit/Models/CartTest.php @@ -48,7 +48,7 @@ 'meta' => ['foo' => 'bar'], ]); - $this->assertDatabaseHas((new Cart())->getTable(), [ + $this->assertDatabaseHas((new Cart)->getTable(), [ 'currency_id' => $currency->id, 'channel_id' => $channel->id, 'meta' => json_encode(['foo' => 'bar']), @@ -128,7 +128,7 @@ 'user_id' => $user->getKey(), ]); - $this->assertDatabaseHas((new Cart())->getTable(), [ + $this->assertDatabaseHas((new Cart)->getTable(), [ 'currency_id' => $currency->id, 'channel_id' => $channel->id, 'user_id' => $user->getKey(), @@ -383,7 +383,7 @@ 'user_id' => $user->getKey(), ]); - $this->assertDatabaseHas((new Cart())->getTable(), [ + $this->assertDatabaseHas((new Cart)->getTable(), [ 'currency_id' => $currency->id, 'channel_id' => $channel->id, 'user_id' => $user->getKey(), @@ -630,14 +630,14 @@ $cartLine = $cart->refresh()->lines->first(); - $this->assertDatabaseHas((new CartLine())->getTable(), [ + $this->assertDatabaseHas((new CartLine)->getTable(), [ 'quantity' => 1, 'id' => $cartLine->id, ]); $cart->updateLine($cartLine->id, 2); - $this->assertDatabaseHas((new CartLine())->getTable(), [ + $this->assertDatabaseHas((new CartLine)->getTable(), [ 'quantity' => 2, 'id' => $cartLine->id, ]); diff --git a/tests/core/Unit/Models/OrderLineTest.php b/tests/core/Unit/Models/OrderLineTest.php index 9246e77d7f..c44a5d298c 100644 --- a/tests/core/Unit/Models/OrderLineTest.php +++ b/tests/core/Unit/Models/OrderLineTest.php @@ -28,7 +28,7 @@ OrderLine::factory()->create($data); $this->assertDatabaseHas( - (new OrderLine())->getTable(), + (new OrderLine)->getTable(), $data ); }); @@ -52,7 +52,7 @@ $orderLine = OrderLine::factory()->create($data); $this->assertDatabaseHas( - (new OrderLine())->getTable(), + (new OrderLine)->getTable(), $data ); @@ -75,5 +75,5 @@ OrderLine::factory()->create($data); - $this->assertDatabaseMissing((new CartLine())->getTable(), $data); + $this->assertDatabaseMissing((new CartLine)->getTable(), $data); }); diff --git a/tests/core/Unit/Models/OrderTest.php b/tests/core/Unit/Models/OrderTest.php index 027fa8e0fd..63ab62af75 100644 --- a/tests/core/Unit/Models/OrderTest.php +++ b/tests/core/Unit/Models/OrderTest.php @@ -59,7 +59,7 @@ $data = $order->getRawOriginal(); - $this->assertDatabaseHas((new Order())->getTable(), $data); + $this->assertDatabaseHas((new Order)->getTable(), $data); }); test('order has correct casting', function () { diff --git a/tests/core/Unit/Models/PriceTest.php b/tests/core/Unit/Models/PriceTest.php index 1488dc2eda..e0796e7000 100644 --- a/tests/core/Unit/Models/PriceTest.php +++ b/tests/core/Unit/Models/PriceTest.php @@ -28,7 +28,7 @@ Price::factory()->create($data); - $this->assertDatabaseHas((new Price())->getTable(), $data); + $this->assertDatabaseHas((new Price)->getTable(), $data); }); test('price is cast to a datatype', function () { diff --git a/tests/core/Unit/Models/TaxClassTest.php b/tests/core/Unit/Models/TaxClassTest.php index 4181be695a..f90154b3bf 100644 --- a/tests/core/Unit/Models/TaxClassTest.php +++ b/tests/core/Unit/Models/TaxClassTest.php @@ -10,7 +10,7 @@ 'name' => 'Clothing', ]); - $this->assertDatabaseHas((new TaxClass())->getTable(), [ + $this->assertDatabaseHas((new TaxClass)->getTable(), [ 'name' => 'Clothing', 'default' => false, ]); diff --git a/tests/core/Unit/Models/TaxRateTest.php b/tests/core/Unit/Models/TaxRateTest.php index 1288174510..860e552a02 100644 --- a/tests/core/Unit/Models/TaxRateTest.php +++ b/tests/core/Unit/Models/TaxRateTest.php @@ -15,7 +15,7 @@ $rate = TaxRate::factory()->create($data); - $this->assertDatabaseHas((new TaxRate())->getTable(), $data); + $this->assertDatabaseHas((new TaxRate)->getTable(), $data); expect($rate->taxZone)->toBeInstanceOf(TaxZone::class); }); @@ -28,7 +28,7 @@ $rate = TaxRate::factory()->create($data); - $this->assertDatabaseHas((new TaxRate())->getTable(), $data); + $this->assertDatabaseHas((new TaxRate)->getTable(), $data); expect($rate->taxRateAmounts)->toHaveCount(0); diff --git a/tests/core/Unit/Models/TaxZoneCountryTest.php b/tests/core/Unit/Models/TaxZoneCountryTest.php index 5cb9e36f5f..20d8c18425 100644 --- a/tests/core/Unit/Models/TaxZoneCountryTest.php +++ b/tests/core/Unit/Models/TaxZoneCountryTest.php @@ -15,5 +15,5 @@ TaxZoneCountry::factory()->create($data); - $this->assertDatabaseHas((new TaxZoneCountry())->getTable(), $data); + $this->assertDatabaseHas((new TaxZoneCountry)->getTable(), $data); }); diff --git a/tests/core/Unit/Models/TaxZonePostcodeTest.php b/tests/core/Unit/Models/TaxZonePostcodeTest.php index 3ccc4e5f61..f34e5b6e31 100644 --- a/tests/core/Unit/Models/TaxZonePostcodeTest.php +++ b/tests/core/Unit/Models/TaxZonePostcodeTest.php @@ -16,5 +16,5 @@ TaxZonePostcode::factory()->create($data); - $this->assertDatabaseHas((new TaxZonePostcode())->getTable(), $data); + $this->assertDatabaseHas((new TaxZonePostcode)->getTable(), $data); }); diff --git a/tests/core/Unit/Models/TaxZoneTest.php b/tests/core/Unit/Models/TaxZoneTest.php index 2684467c92..52f5efe064 100644 --- a/tests/core/Unit/Models/TaxZoneTest.php +++ b/tests/core/Unit/Models/TaxZoneTest.php @@ -19,7 +19,7 @@ TaxZone::factory()->create($data); - $this->assertDatabaseHas((new TaxZone())->getTable(), $data); + $this->assertDatabaseHas((new TaxZone)->getTable(), $data); }); test('tax zone can have countries', function () { @@ -33,7 +33,7 @@ $zone = TaxZone::factory()->create($data); - $this->assertDatabaseHas((new TaxZone())->getTable(), $data); + $this->assertDatabaseHas((new TaxZone)->getTable(), $data); $country = Country::factory()->create(); @@ -57,7 +57,7 @@ $zone = TaxZone::factory()->create($data); - $this->assertDatabaseHas((new TaxZone())->getTable(), $data); + $this->assertDatabaseHas((new TaxZone)->getTable(), $data); $country = Country::factory()->create(); $state = State::factory()->create([ @@ -84,7 +84,7 @@ $zone = TaxZone::factory()->create($data); - $this->assertDatabaseHas((new TaxZone())->getTable(), $data); + $this->assertDatabaseHas((new TaxZone)->getTable(), $data); $country = Country::factory()->create(); @@ -109,7 +109,7 @@ $zone = TaxZone::factory()->create($data); - $this->assertDatabaseHas((new TaxZone())->getTable(), $data); + $this->assertDatabaseHas((new TaxZone)->getTable(), $data); $country = Country::factory()->create(); diff --git a/tests/core/Unit/Models/TransactionTest.php b/tests/core/Unit/Models/TransactionTest.php index 1cc17625cb..300ecfb803 100644 --- a/tests/core/Unit/Models/TransactionTest.php +++ b/tests/core/Unit/Models/TransactionTest.php @@ -33,9 +33,9 @@ 'order_id' => $order->id, ]); - $this->assertDatabaseHas((new Order())->getTable(), $order->getRawOriginal()); + $this->assertDatabaseHas((new Order)->getTable(), $order->getRawOriginal()); - $this->assertDatabaseHas((new Transaction())->getTable(), $transaction->getRawOriginal()); + $this->assertDatabaseHas((new Transaction)->getTable(), $transaction->getRawOriginal()); }); test('can store last four correctly', function () { @@ -53,7 +53,7 @@ ]); $this->assertDatabaseHas( - (new Transaction())->getTable(), + (new Transaction)->getTable(), [ 'id' => $transaction->id, 'last_four' => $check, diff --git a/tests/core/Unit/Rules/MaxDecimalPlacesRuleTest.php b/tests/core/Unit/Rules/MaxDecimalPlacesRuleTest.php index eea6459ab1..73cef7f6d2 100644 --- a/tests/core/Unit/Rules/MaxDecimalPlacesRuleTest.php +++ b/tests/core/Unit/Rules/MaxDecimalPlacesRuleTest.php @@ -9,19 +9,19 @@ test('can validate decimal places using defaults', function () { $validator = Validator::make([ 'decimal' => 0.1, - ], ['decimal' => new MaxDecimalPlaces()]); + ], ['decimal' => new MaxDecimalPlaces]); expect($validator->passes())->toBeTrue(); $validator = Validator::make([ 'decimal' => 0.12, - ], ['decimal' => new MaxDecimalPlaces()]); + ], ['decimal' => new MaxDecimalPlaces]); expect($validator->passes())->toBeTrue(); $validator = Validator::make([ 'decimal' => 0.123, - ], ['decimal' => new MaxDecimalPlaces()]); + ], ['decimal' => new MaxDecimalPlaces]); expect($validator->fails())->toBeTrue(); }); @@ -71,7 +71,7 @@ test('rule works on integers', function () { $validator = Validator::make([ 'decimal' => 1, - ], ['decimal' => new MaxDecimalPlaces()]); + ], ['decimal' => new MaxDecimalPlaces]); expect($validator->passes())->toBeTrue(); diff --git a/tests/core/Unit/Validation/CartLine/CartLineStockTest.php b/tests/core/Unit/Validation/CartLine/CartLineStockTest.php index 499babcfb2..e602bf77a0 100644 --- a/tests/core/Unit/Validation/CartLine/CartLineStockTest.php +++ b/tests/core/Unit/Validation/CartLine/CartLineStockTest.php @@ -22,7 +22,7 @@ 'purchasable' => $purchasable, ]); - $validator = (new \Lunar\Validation\CartLine\CartLineStock())->using( + $validator = (new \Lunar\Validation\CartLine\CartLineStock)->using( cart: $cart, purchasable: $purchasable, quantity: $quantity, diff --git a/tests/opayo/Feature/OpayoPaymentTypeTest.php b/tests/opayo/Feature/OpayoPaymentTypeTest.php index f23fae2824..acfb33ae93 100644 --- a/tests/opayo/Feature/OpayoPaymentTypeTest.php +++ b/tests/opayo/Feature/OpayoPaymentTypeTest.php @@ -8,7 +8,7 @@ it('can handle a successful payment', function () { $cart = buildCart(); - $response = (new \Lunar\Opayo\OpayoPaymentType())->cart($cart)->withData([ + $response = (new \Lunar\Opayo\OpayoPaymentType)->cart($cart)->withData([ 'merchant_key' => 'SUCCESS', 'card_identifier' => 'CARDTOKEN', 'status' => 'payment-received', @@ -36,7 +36,7 @@ it('can handle a failed payment', function () { $cart = buildCart(); - $response = (new \Lunar\Opayo\OpayoPaymentType())->cart($cart)->withData([ + $response = (new \Lunar\Opayo\OpayoPaymentType)->cart($cart)->withData([ 'merchant_key' => 'FAILED', 'card_identifier' => 'CARDTOKEN', 'status' => 'payment-received', @@ -63,7 +63,7 @@ it('can handle a 3DSv2 response', function () { $cart = buildCart(); - $response = (new \Lunar\Opayo\OpayoPaymentType())->cart($cart)->withData([ + $response = (new \Lunar\Opayo\OpayoPaymentType)->cart($cart)->withData([ 'merchant_key' => 'SUCCESS_3DSV2', 'card_identifier' => 'CARDTOKEN', 'status' => 'payment-received', @@ -78,7 +78,7 @@ it('can process a failed 3DSv2 response', function () { $cart = buildCart(); - $response = (new \Lunar\Opayo\OpayoPaymentType())->cart($cart)->withData([ + $response = (new \Lunar\Opayo\OpayoPaymentType)->cart($cart)->withData([ 'cres' => '3DSV2_FAILURE', 'pares' => '3DSV2_FAILURE', 'transaction_id' => '3DSV2_FAILURE', @@ -109,7 +109,7 @@ it('can process a successful 3DSv2 response', function () { $cart = buildCart(); - $response = (new \Lunar\Opayo\OpayoPaymentType())->cart($cart)->withData([ + $response = (new \Lunar\Opayo\OpayoPaymentType)->cart($cart)->withData([ 'cres' => '3DSV2_SUCCESS', 'pares' => '3DSV2_SUCCESS', 'transaction_id' => '3DSV2_SUCCESS', diff --git a/tests/shipping/Unit/Drivers/ShippingMethods/CollectionTest.php b/tests/shipping/Unit/Drivers/ShippingMethods/CollectionTest.php index a16cb110c1..c4c83582af 100644 --- a/tests/shipping/Unit/Drivers/ShippingMethods/CollectionTest.php +++ b/tests/shipping/Unit/Drivers/ShippingMethods/CollectionTest.php @@ -38,7 +38,7 @@ $cart = $this->createCart($currency, 500); - $driver = new Collection(); + $driver = new Collection; $request = new ShippingOptionRequest( cart: $cart, diff --git a/tests/shipping/Unit/Drivers/ShippingMethods/FlatRateTest.php b/tests/shipping/Unit/Drivers/ShippingMethods/FlatRateTest.php index 6f3741219f..9c1fba6e42 100644 --- a/tests/shipping/Unit/Drivers/ShippingMethods/FlatRateTest.php +++ b/tests/shipping/Unit/Drivers/ShippingMethods/FlatRateTest.php @@ -51,7 +51,7 @@ $cart = $this->createCart($currency, 500); - $driver = new FlatRate(); + $driver = new FlatRate; $request = new ShippingOptionRequest( cart: $cart, diff --git a/tests/shipping/Unit/Drivers/ShippingMethods/FreeShippingTest.php b/tests/shipping/Unit/Drivers/ShippingMethods/FreeShippingTest.php index 2aeccd90e7..904bf6907c 100644 --- a/tests/shipping/Unit/Drivers/ShippingMethods/FreeShippingTest.php +++ b/tests/shipping/Unit/Drivers/ShippingMethods/FreeShippingTest.php @@ -43,7 +43,7 @@ $cart = $this->createCart($currency, 500); - $driver = new FreeShipping(); + $driver = new FreeShipping; $request = new ShippingOptionRequest( cart: $cart, @@ -85,7 +85,7 @@ $cart = $this->createCart($currency, 50); - $driver = new FreeShipping(); + $driver = new FreeShipping; $request = new ShippingOptionRequest( cart: $cart, @@ -127,7 +127,7 @@ $cart = $this->createCart($currency, 10000); - $driver = new FreeShipping(); + $driver = new FreeShipping; $request = new ShippingOptionRequest( shippingRate: $shippingRate, diff --git a/tests/shipping/Unit/Drivers/ShippingMethods/ShipByTest.php b/tests/shipping/Unit/Drivers/ShippingMethods/ShipByTest.php index 554df5da50..5891886981 100644 --- a/tests/shipping/Unit/Drivers/ShippingMethods/ShipByTest.php +++ b/tests/shipping/Unit/Drivers/ShippingMethods/ShipByTest.php @@ -56,7 +56,7 @@ $cart = $this->createCart($currency, 100); - $driver = new ShipBy(); + $driver = new ShipBy; $request = new ShippingOptionRequest( shippingRate: $shippingRate, @@ -71,7 +71,7 @@ $cart = $this->createCart($currency, 10000); - $driver = new ShipBy(); + $driver = new ShipBy; $request = new ShippingOptionRequest( shippingRate: $shippingRate, @@ -131,7 +131,7 @@ $cart = $this->createCart($currency, 700); - $driver = new ShipBy(); + $driver = new ShipBy; $request = new ShippingOptionRequest( shippingRate: $shippingRate, @@ -185,7 +185,7 @@ $cart = $this->createCart($currency, 100); - $driver = new ShipBy(); + $driver = new ShipBy; $request = new ShippingOptionRequest( shippingRate: $shippingRate, diff --git a/tests/shipping/Unit/Models/ShippingZonePostcodeTest.php b/tests/shipping/Unit/Models/ShippingZonePostcodeTest.php index aaae11e8d2..854899b92a 100644 --- a/tests/shipping/Unit/Models/ShippingZonePostcodeTest.php +++ b/tests/shipping/Unit/Models/ShippingZonePostcodeTest.php @@ -15,7 +15,7 @@ 'postcode' => 'AB1 2BA', ]); - $this->assertDatabaseHas((new ShippingZonePostcode())->getTable(), [ + $this->assertDatabaseHas((new ShippingZonePostcode)->getTable(), [ 'shipping_zone_id' => $shippingZone->id, 'postcode' => 'AB12BA', ]); diff --git a/tests/shipping/Unit/Resolvers/PostcodeResolverTest.php b/tests/shipping/Unit/Resolvers/PostcodeResolverTest.php index 8621aa268a..e8622ed00e 100644 --- a/tests/shipping/Unit/Resolvers/PostcodeResolverTest.php +++ b/tests/shipping/Unit/Resolvers/PostcodeResolverTest.php @@ -7,7 +7,7 @@ test('can get postcode query parts', function () { $postcode = 'ABC 123'; - $parts = (new PostcodeResolver())->getParts($postcode); + $parts = (new PostcodeResolver)->getParts($postcode); expect($parts)->toContain('ABC123'); expect($parts)->toContain('ABC'); @@ -15,7 +15,7 @@ $postcode = 'NW1 1TX'; - $parts = (new PostcodeResolver())->getParts($postcode); + $parts = (new PostcodeResolver)->getParts($postcode); expect($parts)->toContain('NW11TX'); expect($parts)->toContain('NW1'); @@ -23,7 +23,7 @@ $postcode = 90210; - $parts = (new PostcodeResolver())->getParts($postcode); + $parts = (new PostcodeResolver)->getParts($postcode); expect($parts)->toContain('90210'); expect($parts)->toContain('90'); }); diff --git a/tests/shipping/Unit/Resolvers/ShippingZoneResolverTest.php b/tests/shipping/Unit/Resolvers/ShippingZoneResolverTest.php index b083aeaceb..98d51c6a8f 100644 --- a/tests/shipping/Unit/Resolvers/ShippingZoneResolverTest.php +++ b/tests/shipping/Unit/Resolvers/ShippingZoneResolverTest.php @@ -27,7 +27,7 @@ expect($shippingZoneA->refresh()->countries)->toHaveCount(1); - $zones = (new ShippingZoneResolver())->country($countryA)->get(); + $zones = (new ShippingZoneResolver)->country($countryA)->get(); expect($zones)->toHaveCount(1); @@ -59,7 +59,7 @@ expect($shippingZoneA->refresh()->states)->toHaveCount(1); - $zones = (new ShippingZoneResolver())->state($stateA)->get(); + $zones = (new ShippingZoneResolver)->state($stateA)->get(); expect($zones)->toHaveCount(1); @@ -77,7 +77,7 @@ expect($shippingZoneA->refresh()->countries)->toHaveCount(1); - $zones = (new ShippingZoneResolver())->country($countryA)->get(); + $zones = (new ShippingZoneResolver)->country($countryA)->get(); expect($zones)->toBeEmpty(); }); @@ -103,7 +103,7 @@ 'ABC 123' ); - $zones = (new ShippingZoneResolver())->postcode($postcode)->get(); + $zones = (new ShippingZoneResolver)->postcode($postcode)->get(); expect($zones)->toHaveCount(1); From cde2ae70e1016dd7238723b739b63960f2987589 Mon Sep 17 00:00:00 2001 From: Alec Ritson Date: Wed, 24 Jul 2024 11:31:05 +0100 Subject: [PATCH 10/18] Update and lock pint to 1.17.0 (#1880) --- composer.json | 2 +- monorepo-builder.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 3163e66a68..b46339cb97 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ }, "require-dev": { "larastan/larastan": "^2.9", - "laravel/pint": "^1.16.1", + "laravel/pint": "1.17.0", "mockery/mockery": "^1.6.9", "orchestra/testbench": "^8.0|^9.0", "pestphp/pest": "^2.34.7", diff --git a/monorepo-builder.php b/monorepo-builder.php index 2a18eb017f..f4cbaeb6f5 100644 --- a/monorepo-builder.php +++ b/monorepo-builder.php @@ -39,7 +39,7 @@ // for "merge" command $parameters->set(Option::DATA_TO_APPEND, [ ComposerJsonSection::REQUIRE_DEV => [ - 'laravel/pint' => '^1.16.1', + 'laravel/pint' => '1.17.0', 'mockery/mockery' => '^1.6.9', 'pestphp/pest' => '^2.34.7', 'pestphp/pest-plugin-laravel' => '^2.4', From 97a90adc0581f0f0cb647070b629e33549de2bb2 Mon Sep 17 00:00:00 2001 From: Alec Ritson Date: Tue, 30 Jul 2024 12:44:09 +0100 Subject: [PATCH 11/18] Set payment order to null when setting the cart (#1888) --- packages/core/src/PaymentTypes/AbstractPayment.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/core/src/PaymentTypes/AbstractPayment.php b/packages/core/src/PaymentTypes/AbstractPayment.php index 88b11a4617..8992b2bf4c 100644 --- a/packages/core/src/PaymentTypes/AbstractPayment.php +++ b/packages/core/src/PaymentTypes/AbstractPayment.php @@ -36,6 +36,7 @@ abstract class AbstractPayment implements PaymentTypeInterface public function cart(Cart $cart): self { $this->cart = $cart; + $this->order = null; return $this; } @@ -46,6 +47,7 @@ public function cart(Cart $cart): self public function order(Order $order): self { $this->order = $order; + $this->cart = null; return $this; } From e63fb425a78925075c10436ad86d52e1cd6aa991 Mon Sep 17 00:00:00 2001 From: Maurice Ellis Date: Tue, 6 Aug 2024 02:17:13 -0700 Subject: [PATCH 12/18] Fixing handling of required for field types (#1853) Fixing reference to `required` on field types --- packages/admin/src/Support/FieldTypes/Dropdown.php | 2 +- packages/admin/src/Support/FieldTypes/File.php | 2 +- packages/admin/src/Support/FieldTypes/ListField.php | 2 +- packages/admin/src/Support/FieldTypes/Number.php | 2 +- packages/admin/src/Support/FieldTypes/TextField.php | 4 ++-- packages/admin/src/Support/FieldTypes/Toggle.php | 2 +- packages/admin/src/Support/FieldTypes/TranslatedText.php | 2 +- packages/admin/src/Support/FieldTypes/Vimeo.php | 2 +- packages/admin/src/Support/FieldTypes/YouTube.php | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/admin/src/Support/FieldTypes/Dropdown.php b/packages/admin/src/Support/FieldTypes/Dropdown.php index 38060577a4..b4144dcbe2 100644 --- a/packages/admin/src/Support/FieldTypes/Dropdown.php +++ b/packages/admin/src/Support/FieldTypes/Dropdown.php @@ -21,7 +21,7 @@ public static function getFilamentComponent(Attribute $attribute): Component ) ) ->when(filled($attribute->validation_rules), fn (Select $component) => $component->rules($attribute->validation_rules)) - ->required((bool) $attribute->configuration->get('required')) + ->required((bool) $attribute->required) ->helperText($attribute->translate('description')); } diff --git a/packages/admin/src/Support/FieldTypes/File.php b/packages/admin/src/Support/FieldTypes/File.php index 367bded625..19f4d83881 100644 --- a/packages/admin/src/Support/FieldTypes/File.php +++ b/packages/admin/src/Support/FieldTypes/File.php @@ -15,7 +15,7 @@ public static function getFilamentComponent(Attribute $attribute): Component { return FileUpload::make($attribute->handle) ->when(filled($attribute->validation_rules), fn (FileUpload $component) => $component->rules($attribute->validation_rules)) - ->required((bool) $attribute->configuration->get('required')) + ->required((bool) $attribute->required) ->helperText($attribute->translate('description')); } } diff --git a/packages/admin/src/Support/FieldTypes/ListField.php b/packages/admin/src/Support/FieldTypes/ListField.php index d033dd41f9..c27ec0e078 100644 --- a/packages/admin/src/Support/FieldTypes/ListField.php +++ b/packages/admin/src/Support/FieldTypes/ListField.php @@ -20,7 +20,7 @@ public static function getFilamentComponent(Attribute $attribute): Component return $state; }) ->when(filled($attribute->validation_rules), fn (KeyValue $component) => $component->rules($attribute->validation_rules)) - ->required((bool) $attribute->configuration->get('required')) + ->required((bool) $attribute->required) ->helperText($attribute->translate('description')); } } diff --git a/packages/admin/src/Support/FieldTypes/Number.php b/packages/admin/src/Support/FieldTypes/Number.php index c319471b7f..adb6000528 100644 --- a/packages/admin/src/Support/FieldTypes/Number.php +++ b/packages/admin/src/Support/FieldTypes/Number.php @@ -20,7 +20,7 @@ public static function getFilamentComponent(Attribute $attribute): Component $input = TextInput::make($attribute->handle) ->numeric() ->when(filled($attribute->validation_rules), fn (TextInput $component) => $component->rules($attribute->validation_rules)) - ->required((bool) $attribute->configuration->get('required')) + ->required((bool) $attribute->required) ->helperText($attribute->translate('description')); if ($min) { diff --git a/packages/admin/src/Support/FieldTypes/TextField.php b/packages/admin/src/Support/FieldTypes/TextField.php index 7f5f223794..942cda6ad4 100644 --- a/packages/admin/src/Support/FieldTypes/TextField.php +++ b/packages/admin/src/Support/FieldTypes/TextField.php @@ -26,13 +26,13 @@ public static function getFilamentComponent(Attribute $attribute): Component if ($attribute->configuration->get('richtext')) { return RichEditor::make($attribute->handle) ->when(filled($attribute->validation_rules), fn (RichEditor $component) => $component->rules($attribute->validation_rules)) - ->required((bool) $attribute->configuration->get('required')) + ->required((bool) $attribute->required) ->helperText($attribute->translate('description')); } return TextInput::make($attribute->handle) ->when(filled($attribute->validation_rules), fn (TextInput $component) => $component->rules($attribute->validation_rules)) - ->required((bool) $attribute->configuration->get('required')) + ->required((bool) $attribute->required) ->helperText($attribute->translate('description')); } } diff --git a/packages/admin/src/Support/FieldTypes/Toggle.php b/packages/admin/src/Support/FieldTypes/Toggle.php index a9a40dbc33..74e0c2e09e 100644 --- a/packages/admin/src/Support/FieldTypes/Toggle.php +++ b/packages/admin/src/Support/FieldTypes/Toggle.php @@ -20,6 +20,6 @@ public static function getFilamentComponent(Attribute $attribute): Component ->default(false) ->when(filled($attribute->validation_rules), fn (Toggle $component) => $component->rules($attribute->validation_rules)) ->rule('boolean') - ->required((bool) $attribute->configuration->get('required')); + ->required((bool) $attribute->required); } } diff --git a/packages/admin/src/Support/FieldTypes/TranslatedText.php b/packages/admin/src/Support/FieldTypes/TranslatedText.php index 565f44a5ca..e43e8c19ff 100644 --- a/packages/admin/src/Support/FieldTypes/TranslatedText.php +++ b/packages/admin/src/Support/FieldTypes/TranslatedText.php @@ -21,7 +21,7 @@ public static function getFilamentComponent(Attribute $attribute): Component return TranslatedTextComponent::make($attribute->handle) ->optionRichtext((bool) $attribute->configuration->get('richtext')) ->when(filled($attribute->validation_rules), fn (TranslatedTextComponent $component) => $component->rules($attribute->validation_rules)) - ->required((bool) $attribute->configuration->get('required')) + ->required((bool) $attribute->required) ->helperText($attribute->translate('description')); } } diff --git a/packages/admin/src/Support/FieldTypes/Vimeo.php b/packages/admin/src/Support/FieldTypes/Vimeo.php index 9feb7618a7..ad5795b430 100644 --- a/packages/admin/src/Support/FieldTypes/Vimeo.php +++ b/packages/admin/src/Support/FieldTypes/Vimeo.php @@ -16,7 +16,7 @@ public static function getFilamentComponent(Attribute $attribute): Component return VimeoInput::make($attribute->handle) ->live(debounce: 200) ->when(filled($attribute->validation_rules), fn (VimeoInput $component) => $component->rules($attribute->validation_rules)) - ->required((bool) $attribute->configuration->get('required')) + ->required((bool) $attribute->required) ->helperText( $attribute->translate('description') ?? __('lunarpanel::components.forms.youtube.helperText') ); diff --git a/packages/admin/src/Support/FieldTypes/YouTube.php b/packages/admin/src/Support/FieldTypes/YouTube.php index f7e2449e1b..64ea5fda9c 100644 --- a/packages/admin/src/Support/FieldTypes/YouTube.php +++ b/packages/admin/src/Support/FieldTypes/YouTube.php @@ -16,7 +16,7 @@ public static function getFilamentComponent(Attribute $attribute): Component return YouTubeInput::make($attribute->handle) ->live(debounce: 200) ->when(filled($attribute->validation_rules), fn (YouTubeInput $component) => $component->rules($attribute->validation_rules)) - ->required((bool) $attribute->configuration->get('required')) + ->required((bool) $attribute->required) ->helperText( $attribute->translate('description') ?? __('lunarpanel::components.forms.youtube.helperText') ); From 2fc9fb8072700df95305e8aecccffc103893c749 Mon Sep 17 00:00:00 2001 From: Lionel Guichard Date: Tue, 6 Aug 2024 12:47:04 +0200 Subject: [PATCH 13/18] Fix - SoftDeletes missing in ProductVariant (#1886) --- packages/core/src/Models/ProductVariant.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/core/src/Models/ProductVariant.php b/packages/core/src/Models/ProductVariant.php index c8a0223104..10c06066b6 100644 --- a/packages/core/src/Models/ProductVariant.php +++ b/packages/core/src/Models/ProductVariant.php @@ -5,6 +5,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Collection; use Lunar\Base\BaseModel; use Lunar\Base\Casts\AsAttributeData; @@ -59,6 +60,7 @@ class ProductVariant extends BaseModel implements Purchasable use HasPrices; use HasTranslations; use LogsActivity; + use SoftDeletes; /** * Define the guarded attributes. From 761be97f14a0da37bb9f67c5f226b1a623c61746 Mon Sep 17 00:00:00 2001 From: wychoong <67364036+wychoong@users.noreply.github.com> Date: Mon, 12 Aug 2024 18:29:22 +0800 Subject: [PATCH 14/18] Display product variants' option values using flex-col (#1890) --- .../product-resource/widgets/product-options.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/admin/resources/views/resources/product-resource/widgets/product-options.blade.php b/packages/admin/resources/views/resources/product-resource/widgets/product-options.blade.php index c5e1c1db15..4d33260c27 100644 --- a/packages/admin/resources/views/resources/product-resource/widgets/product-options.blade.php +++ b/packages/admin/resources/views/resources/product-resource/widgets/product-options.blade.php @@ -122,7 +122,7 @@ @endif
- + @foreach($permutation['values'] as $option => $value) {{ $option }}: {{ $value }} @endforeach From d20f0937b357cb4bfca094cd2b0eb7593e031c0f Mon Sep 17 00:00:00 2001 From: Ryan McAllen Date: Mon, 12 Aug 2024 06:47:21 -0400 Subject: [PATCH 15/18] Comments: orders -> order's (#1865) --- packages/core/config/orders.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/config/orders.php b/packages/core/config/orders.php index ba9d9b5d07..7e522cc9f8 100644 --- a/packages/core/config/orders.php +++ b/packages/core/config/orders.php @@ -67,7 +67,7 @@ | Order Pipelines |-------------------------------------------------------------------------- | - | Define which pipelines should be run throughout an orders lifecycle. + | Define which pipelines should be run throughout an order's lifecycle. | The default ones provided should suit most needs, however you are | free to add your own as you see fit. | From fbfcf85fd691f3ee41bde8b71a84a16c0bf94a1d Mon Sep 17 00:00:00 2001 From: Alec Ritson Date: Mon, 12 Aug 2024 12:40:36 +0100 Subject: [PATCH 16/18] Fix test runners (#1898) --- .../Resources/StaffResource/Pages/EditStaffTest.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tests/admin/Feature/Filament/Resources/StaffResource/Pages/EditStaffTest.php b/tests/admin/Feature/Filament/Resources/StaffResource/Pages/EditStaffTest.php index f212ee5526..59c5c0df3d 100644 --- a/tests/admin/Feature/Filament/Resources/StaffResource/Pages/EditStaffTest.php +++ b/tests/admin/Feature/Filament/Resources/StaffResource/Pages/EditStaffTest.php @@ -75,13 +75,10 @@ ->assertHasNoFormErrors(); expect($staff->hasExactRoles($roles)) - ->toBeTrue(); - - // check assigned permissions does not include role's permissions - expect($permissions->reject(fn ($val, $handle) => $handle == $rolePermission)->toArray()) - ->toEqualCanonicalizing($staff->getDirectPermissions()->pluck('name')->toArray()); - - // check role's permission - expect($rolePermission) + ->toBeTrue() + ->and( + $permissions->reject(fn ($val, $handle) => $handle == $rolePermission)->keys()->toArray() + )->toEqualCanonicalizing($staff->getDirectPermissions()->pluck('name')->toArray()) + ->and($rolePermission) ->toEqualCanonicalizing($staff->getPermissionsViaRoles()->pluck('name')->toArray()); }); From 6e0fffa4e9bd6f2cc1f4ab62f76a11af4adf2809 Mon Sep 17 00:00:00 2001 From: wychoong <67364036+wychoong@users.noreply.github.com> Date: Mon, 12 Aug 2024 21:07:52 +0800 Subject: [PATCH 17/18] Do not register Shipping addon resources if disabed (#1891) --- packages/table-rate-shipping/src/ShippingPlugin.php | 4 ++++ packages/table-rate-shipping/src/ShippingServiceProvider.php | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/table-rate-shipping/src/ShippingPlugin.php b/packages/table-rate-shipping/src/ShippingPlugin.php index 6ffd06719a..c81cc1371b 100644 --- a/packages/table-rate-shipping/src/ShippingPlugin.php +++ b/packages/table-rate-shipping/src/ShippingPlugin.php @@ -24,6 +24,10 @@ public function boot(Panel $panel): void public function register(Panel $panel): void { + if (! config('lunar.shipping-tables.enabled')) { + return; + } + $panel->navigationGroups([ NavigationGroup::make('shipping') ->label( diff --git a/packages/table-rate-shipping/src/ShippingServiceProvider.php b/packages/table-rate-shipping/src/ShippingServiceProvider.php index 384e3ac33c..246c9c663b 100644 --- a/packages/table-rate-shipping/src/ShippingServiceProvider.php +++ b/packages/table-rate-shipping/src/ShippingServiceProvider.php @@ -14,10 +14,13 @@ class ShippingServiceProvider extends ServiceProvider { - public function boot(ShippingModifiers $shippingModifiers) + public function register() { $this->mergeConfigFrom(__DIR__.'/../config/shipping-tables.php', 'lunar.shipping-tables'); + } + public function boot(ShippingModifiers $shippingModifiers) + { if (! config('lunar.shipping-tables.enabled')) { return; } From be449b047d663e21aaf0b6d499b46cff47f0eaed Mon Sep 17 00:00:00 2001 From: alecritson Date: Mon, 12 Aug 2024 13:10:27 +0000 Subject: [PATCH 18/18] chore: fix code style --- packages/table-rate-shipping/src/ShippingPlugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/table-rate-shipping/src/ShippingPlugin.php b/packages/table-rate-shipping/src/ShippingPlugin.php index c81cc1371b..671672eeef 100644 --- a/packages/table-rate-shipping/src/ShippingPlugin.php +++ b/packages/table-rate-shipping/src/ShippingPlugin.php @@ -27,7 +27,7 @@ public function register(Panel $panel): void if (! config('lunar.shipping-tables.enabled')) { return; } - + $panel->navigationGroups([ NavigationGroup::make('shipping') ->label(