init
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\Reward\Observer;
|
||||
|
||||
use Esun\Reward\Model\BalanceManager;
|
||||
use Esun\Reward\Model\Config;
|
||||
use Magento\Framework\Event\Observer;
|
||||
use Magento\Framework\Event\ObserverInterface;
|
||||
|
||||
class AwardRegistrationPoints implements ObserverInterface
|
||||
{
|
||||
public function __construct(private readonly BalanceManager $balanceManager, private readonly Config $config) {}
|
||||
|
||||
public function execute(Observer $observer): void
|
||||
{
|
||||
$customer = $observer->getEvent()->getCustomer();
|
||||
$customerId = (int)($customer?->getId() ?? 0);
|
||||
$websiteId = (int)($customer?->getWebsiteId() ?? 0);
|
||||
if (!$this->config->isEnabled() || $customerId <= 0) { return; }
|
||||
$rule = $this->config->earningRule('registration');
|
||||
$this->balanceManager->change($customerId, $websiteId, (int)$rule['points'], 'registration', 'registration:' . $customerId, [
|
||||
'reference_type' => 'customer', 'reference_id' => $customerId, 'reason' => (string)__($rule['reason'])
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user