31 lines
737 B
PHP
31 lines
737 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\CustomerCoupon\Model;
|
|
|
|
use Magento\Customer\Model\Session;
|
|
|
|
class RegistrationCouponGrantContext
|
|
{
|
|
private const SESSION_KEY = 'esun_registration_coupon_granted_customer_id';
|
|
|
|
public function __construct(private readonly Session $customerSession)
|
|
{
|
|
}
|
|
|
|
public function markGranted(int $customerId): void
|
|
{
|
|
if ($customerId > 0) {
|
|
$this->customerSession->setData(self::SESSION_KEY, $customerId);
|
|
}
|
|
}
|
|
|
|
public function consumeGrantedCustomerId(): int
|
|
{
|
|
$customerId = (int)$this->customerSession->getData(self::SESSION_KEY);
|
|
$this->customerSession->unsetData(self::SESSION_KEY);
|
|
|
|
return $customerId;
|
|
}
|
|
}
|