<?php
namespace Plugin\AffiliateManager;
use Eccube\Plugin\AbstractPluginManager;
class PluginManager extends AbstractPluginManager
{
public function install($config, $app)
{
// インストール時の処理
}
public function uninstall($config, $app)
{
// アンインストール時の処理
}
public function enable($config, $app)
{
// 有効化時の処理
}
public function disable($config, $app)
{
// 無効化時の処理
}
public function update($config, $app)
{
// アップデート時の処理
}
}
<?php
namespace Plugin\AffiliateManager\Migration;
use Doctrine\DBAL\Schema\Schema;
use Eccube\Plugin\AbstractMigration;
class Version20240719000000 extends AbstractMigration
{
public function up(Schema $schema): void
{
$this->addSql("ALTER TABLE dtb_order ADD affiliate_id VARCHAR(255) DEFAULT NULL");
}
public function down(Schema $schema): void
{
$this->addSql("ALTER TABLE dtb_order DROP affiliate_id");
}
}
2. 注文時にアフィリエイトIDを保存
EventListener/OrderListener.php を作成
php
<?php
namespace Plugin\AffiliateManager\EventListener;
use Eccube\Event\EventArgs;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class OrderListener implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
'eccube.event.order.pre_complete' => 'onOrderPreComplete',
];
}
public function onOrderPreComplete(EventArgs $event)
{
$Order = $event->getArgument('Order');
// セッションやクッキーからアフィリエイトIDを取得
// 例: $affiliateId = $_SESSION['affiliate_id'] ?? null;
$affiliateId = $_COOKIE['affiliate_id'] ?? null;
if ($affiliateId) {
$Order->setAffiliateId($affiliateId);
}
}
}