getEvent()->getAccountController(); $subscriptionRequested = $controller?->getRequest()->getParam('is_subscribed', false); if (!in_array(strtolower((string)$subscriptionRequested), ['1', 'true', 'yes', 'on'], true)) { return; } $customer = $observer->getEvent()->getCustomer(); $customerId = (int)($customer?->getId() ?? 0); if ($customerId <= 0) { return; } try { $granted = $this->couponService->grant( $customerId, (int)$customer->getWebsiteId(), (int)$customer->getGroupId(), (int)$customer->getStoreId() ); if ($granted) { $this->grantContext->markGranted($customerId); } } catch (\Throwable $exception) { // Coupon delivery must never roll back an otherwise successful customer registration. $this->logger->error('Unable to grant registration subscription coupon.', [ 'customer_id' => $customerId, 'exception' => $exception, ]); } } }