Files
esun3d/app/code/Esun/CustomerCoupon/Observer/AddCustomerSelectToCouponForm.php
2026-09-15 10:35:56 +08:00

41 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Esun\CustomerCoupon\Observer;
use Esun\CustomerCoupon\Block\Adminhtml\Form\CustomerSelect;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\View\LayoutInterface;
class AddCustomerSelectToCouponForm implements ObserverInterface
{
public function __construct(private readonly LayoutInterface $layout)
{
}
public function execute(Observer $observer): void
{
$form = $observer->getData('form');
$fieldset = $form ? $form->getElement('information_fieldset') : null;
if (!$fieldset || $form->getElement('customer_ids')) {
return;
}
$html = $this->layout->createBlock(CustomerSelect::class)
->setTemplate('Esun_CustomerCoupon::form/customer-select.phtml')
->toHtml();
$fieldset->addField(
'customer_ids',
'note',
[
'label' => __('Assigned Customers'),
'text' => $html,
'note' => __('When customers are selected, one unique coupon is generated for each customer.'),
],
'dash'
);
}
}