This commit is contained in:
2026-09-15 10:35:56 +08:00
commit 782f8ea7aa
4086 changed files with 631288 additions and 0 deletions
@@ -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'])
]);
}
}