From 7f6c1e6307057acb503c2b8becc556cbf8e82294 Mon Sep 17 00:00:00 2001 From: Konstantinos Arvanitakis Date: Fri, 25 Sep 2026 14:13:15 +0300 Subject: [PATCH] Chore: Moving Recovery Consent to Core --- .../Controllers/Account/AccountController.php | 22 ++++++---------- .../Checkout/CheckoutController.php | 25 +------------------ 2 files changed, 8 insertions(+), 39 deletions(-) diff --git a/app/Http/Controllers/Account/AccountController.php b/app/Http/Controllers/Account/AccountController.php index a1488bc..6a65ec0 100644 --- a/app/Http/Controllers/Account/AccountController.php +++ b/app/Http/Controllers/Account/AccountController.php @@ -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(); diff --git a/app/Http/Controllers/Checkout/CheckoutController.php b/app/Http/Controllers/Checkout/CheckoutController.php index 46c3375..cd3e84c 100644 --- a/app/Http/Controllers/Checkout/CheckoutController.php +++ b/app/Http/Controllers/Checkout/CheckoutController.php @@ -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) {