generated from boboko/starter
Chore: Moving Recovery Consent to Core
This commit is contained in:
@@ -75,7 +75,7 @@ public function update(string $locale, Request $request): RedirectResponse
|
||||
|
||||
$invoice = $request->boolean('invoice');
|
||||
|
||||
$customer = $this->account->updateProfile($user, [
|
||||
$this->account->updateProfile($user, [
|
||||
'first_name' => $data['first_name'] ?? null,
|
||||
'last_name' => $data['last_name'] ?? null,
|
||||
'company_name' => $invoice ? $data['company_name'] : null,
|
||||
@@ -100,28 +100,20 @@ public function update(string $locale, Request $request): RedirectResponse
|
||||
: $this->account->createAddress($user, $addressData);
|
||||
}
|
||||
|
||||
$this->updateRecoveryConsent($customer, $request->boolean('recovery_consent'));
|
||||
$this->updateRecoveryConsent($user, $request->boolean('recovery_consent'));
|
||||
|
||||
return redirect()->route('account')->with('status', __('storefront.account.saved'));
|
||||
}
|
||||
|
||||
/**
|
||||
* "Email me a reminder if I don't finish my order", as a standing choice.
|
||||
* Stored on the customer in the same meta shape the checkout writes (see
|
||||
* CheckoutController::rememberRecoveryConsent()), and applied to the
|
||||
* "Email me a reminder if I don't finish my order", as a standing
|
||||
* choice — stored on the customer via boboko-core's
|
||||
* CustomerAccountService::setRecoveryConsent(), and applied to the
|
||||
* current cart too, so opting out stops reminders for it right away.
|
||||
*/
|
||||
private function updateRecoveryConsent($customer, bool $consent): void
|
||||
private function updateRecoveryConsent($user, bool $consent): void
|
||||
{
|
||||
if ((bool) data_get($customer, 'meta.recovery_consent') !== $consent) {
|
||||
$customer->meta = [
|
||||
...($customer->meta?->toArray() ?? []),
|
||||
'recovery_consent' => $consent,
|
||||
'recovery_consent_at' => $consent ? now()->toIso8601String() : null,
|
||||
'recovery_consent_policy_version' => $consent ? config('legal.privacy_policy_version') : null,
|
||||
];
|
||||
$customer->save();
|
||||
}
|
||||
$this->account->setRecoveryConsent($user, $consent);
|
||||
|
||||
// Only an existing cart; never create one just to record this.
|
||||
$cart = app(CartService::class)->current();
|
||||
|
||||
@@ -242,7 +242,7 @@ public function saveAddress(string $locale, Request $request): JsonResponse
|
||||
$this->checkout->setRecoveryConsent($request->boolean('recovery_consent'));
|
||||
|
||||
if (Auth::check()) {
|
||||
$this->rememberRecoveryConsent($request->boolean('recovery_consent'));
|
||||
$this->account->setRecoveryConsent(Auth::user(), $request->boolean('recovery_consent'));
|
||||
}
|
||||
|
||||
$rateKeyAfter = $cart->shippingAddress?->only(['postcode', 'state', 'country_id']);
|
||||
@@ -665,29 +665,6 @@ private function prefillFromAccount(Cart $cart): Cart
|
||||
return $cart;
|
||||
}
|
||||
|
||||
/**
|
||||
* The shopper's latest reminder choice, kept on their customer record
|
||||
* (meta, same shape CheckoutService::setRecoveryConsent() writes on the
|
||||
* cart) so their next checkout starts from it. The storefront's account
|
||||
* page reads/writes the same keys. Candidate for a boboko-core method.
|
||||
*/
|
||||
private function rememberRecoveryConsent(bool $consent): void
|
||||
{
|
||||
$customer = $this->account->customer(Auth::user());
|
||||
|
||||
if (! $customer || (bool) data_get($customer, 'meta.recovery_consent') === $consent) {
|
||||
return;
|
||||
}
|
||||
|
||||
$customer->meta = [
|
||||
...($customer->meta?->toArray() ?? []),
|
||||
'recovery_consent' => $consent,
|
||||
'recovery_consent_at' => $consent ? now()->toIso8601String() : null,
|
||||
'recovery_consent_policy_version' => $consent ? config('legal.privacy_policy_version') : null,
|
||||
];
|
||||
$customer->save();
|
||||
}
|
||||
|
||||
private function storeCountry(): ?Country
|
||||
{
|
||||
if (self::STORE_COUNTRY_ISO3 === null) {
|
||||
|
||||
Reference in New Issue
Block a user