Files
2026-09-15 10:35:56 +08:00

42 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Esun\AiMascotCampaign\Model;
use Magento\Framework\App\ResourceConnection;
class RegistrationRecorder
{
private const TABLE_NAME = 'esun_campaign_registration';
public function __construct(private readonly ResourceConnection $resourceConnection)
{
}
public function record(
string $campaignCode,
int $customerId,
string $email,
int $websiteId,
int $storeId
): void {
$normalizedEmail = strtolower(trim($email));
if ($customerId <= 0 || $normalizedEmail === '') {
return;
}
$connection = $this->resourceConnection->getConnection();
$connection->insertOnDuplicate(
$this->resourceConnection->getTableName(self::TABLE_NAME),
[
'campaign_code' => $campaignCode,
'customer_id' => $customerId,
'email' => $normalizedEmail,
'website_id' => $websiteId,
'store_id' => $storeId,
],
[]
);
}
}