Compare commits
2
Commits
v0.21.0
...
f416e207eb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f416e207eb | ||
|
|
c55019d04a |
@@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
||||
|
||||
## [0.21.1] - 2026-09-25
|
||||
|
||||
### Changed
|
||||
- `GuestOrderClaimer` and its `UserAuthenticated` listener moved from 3dealer's own
|
||||
`App\Services`/`App\Listeners` into `Modules\Core\Customer\Services\GuestOrderClaimer` /
|
||||
`Listeners\ClaimGuestOrdersOnLogin`, registered in `CustomerServiceProvider` — attaching a
|
||||
placed guest order to an account once its billing `contact_email` case-insensitively matches
|
||||
the account's email (only ever safe right after the shopper has proved they own that email: a
|
||||
login code, or 3dealer's own email-change confirmation) was already core-appropriate logic
|
||||
with no 3dealer-specific behavior. `Account\EmailController::verify()` now calls the core
|
||||
service directly.
|
||||
|
||||
## [0.21.0] - 2026-09-25
|
||||
|
||||
### Added
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
"name": "boboko/core",
|
||||
"description": "Core module — authentication and shared panel behaviour",
|
||||
"type": "library",
|
||||
"version": "0.21.0",
|
||||
"version": "0.21.1",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Modules\\Core\\": "src/"
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Core\Customer\Listeners;
|
||||
|
||||
use Modules\Core\Auth\Events\UserAuthenticated;
|
||||
use Modules\Core\Customer\Services\GuestOrderClaimer;
|
||||
|
||||
/**
|
||||
* Registered from Providers\CustomerServiceProvider — UserAuthenticated
|
||||
* only fires after a valid login code, which is what makes matching
|
||||
* placed guest orders by email safe (see GuestOrderClaimer's own
|
||||
* docblock).
|
||||
*/
|
||||
class ClaimGuestOrdersOnLogin
|
||||
{
|
||||
public function __construct(
|
||||
private readonly GuestOrderClaimer $claimer,
|
||||
) {}
|
||||
|
||||
public function handle(UserAuthenticated $event): void
|
||||
{
|
||||
$this->claimer->claim($event->user);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Core\Customer\Services;
|
||||
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Lunar\Base\LunarUser;
|
||||
use Lunar\Models\Order;
|
||||
|
||||
/**
|
||||
* Attaches placed guest orders to an account when their billing email
|
||||
* matches the account's email, case-insensitively. Only ever called right
|
||||
* after the shopper has proved they own that email — a login code
|
||||
* (Auth\Events\UserAuthenticated), or the code confirming an email change
|
||||
* (a consuming app's own email-change flow, e.g. 3dealer's Account\
|
||||
* EmailController::verify()) — which is what makes matching on email safe.
|
||||
*
|
||||
* Only orders with no customer_id AND no user_id are touched: an order
|
||||
* already attached to any account (guest or otherwise) is left alone.
|
||||
*/
|
||||
class GuestOrderClaimer
|
||||
{
|
||||
public function claim(Authenticatable&LunarUser $user): int
|
||||
{
|
||||
$customer = $user->latestCustomer();
|
||||
|
||||
if (! $customer || ! $user->email) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Order::query()
|
||||
->whereNotNull('placed_at')
|
||||
->whereNull('customer_id')
|
||||
->whereNull('user_id')
|
||||
->whereHas('billingAddress', fn ($query) => $query
|
||||
->whereRaw('lower(contact_email) = ?', [strtolower($user->email)]))
|
||||
->update([
|
||||
'customer_id' => $customer->id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,13 @@ use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Lunar\Facades\ModelManifest;
|
||||
use Lunar\Models\Contracts\Customer as LunarCustomer;
|
||||
use Modules\Core\Auth\Events\UserAuthenticated;
|
||||
use Modules\Core\Auth\Events\UserCreated;
|
||||
use Modules\Core\Customer\Events\CustomerAddressCreated;
|
||||
use Modules\Core\Customer\Events\CustomerAddressDeleted;
|
||||
use Modules\Core\Customer\Events\CustomerAddressUpdated;
|
||||
use Modules\Core\Customer\Events\CustomerProfileUpdated;
|
||||
use Modules\Core\Customer\Listeners\ClaimGuestOrdersOnLogin;
|
||||
use Modules\Core\Customer\Listeners\CreateCustomerForUser;
|
||||
use Modules\Core\Customer\Listeners\LogCustomerAccountActivity;
|
||||
use Modules\Core\Customer\Models\Customer;
|
||||
@@ -35,6 +37,7 @@ class CustomerServiceProvider extends ServiceProvider
|
||||
$this->app->booted(fn () => ModelManifest::replace(LunarCustomer::class, Customer::class));
|
||||
|
||||
Event::listen(UserCreated::class, CreateCustomerForUser::class);
|
||||
Event::listen(UserAuthenticated::class, ClaimGuestOrdersOnLogin::class);
|
||||
|
||||
Event::listen(CustomerAddressCreated::class, [LogCustomerAccountActivity::class, 'handleAddressCreated']);
|
||||
Event::listen(CustomerAddressUpdated::class, [LogCustomerAccountActivity::class, 'handleAddressUpdated']);
|
||||
|
||||
Reference in New Issue
Block a user