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,19 @@
<?php
declare(strict_types=1);
namespace Esun\Agent\Block\Adminhtml\Agent\Edit;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
class BackButton extends GenericButton implements ButtonProviderInterface
{
public function getButtonData(): array
{
return [
'label' => __('Back'),
'on_click' => sprintf("location.href = '%s';", $this->getUrl('*/*/')),
'class' => 'back',
'sort_order' => 10,
];
}
}
@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Esun\Agent\Block\Adminhtml\Agent\Edit;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
class DeleteButton extends GenericButton implements ButtonProviderInterface
{
public function getButtonData(): array
{
if (!$this->getEntityId()) {
return [];
}
return [
'label' => __('Delete Agent'),
'class' => 'delete',
'on_click' => 'deleteConfirm('
. json_encode(__('Are you sure you want to delete this agent?')) . ', '
. json_encode($this->getUrl('*/*/delete', ['entity_id' => $this->getEntityId()]))
. ')',
'sort_order' => 20,
];
}
}
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace Esun\Agent\Block\Adminhtml\Agent\Edit;
use Magento\Backend\Block\Widget\Context;
class GenericButton
{
public function __construct(protected readonly Context $context)
{
}
public function getEntityId(): int
{
return (int) $this->context->getRequest()->getParam('entity_id');
}
public function getUrl(string $route = '', array $params = []): string
{
return $this->context->getUrlBuilder()->getUrl($route, $params);
}
}
@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace Esun\Agent\Block\Adminhtml\Agent\Edit;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
class SaveAndContinueButton extends GenericButton implements ButtonProviderInterface
{
public function getButtonData(): array
{
return [
'label' => __('Save and Continue Edit'),
'class' => 'save',
'data_attribute' => [
'mage-init' => ['button' => ['event' => 'saveAndContinueEdit']],
'form-role' => 'save',
],
'sort_order' => 80,
];
}
}
@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace Esun\Agent\Block\Adminhtml\Agent\Edit;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
class SaveButton extends GenericButton implements ButtonProviderInterface
{
public function getButtonData(): array
{
return [
'label' => __('Save Agent'),
'class' => 'save primary',
'data_attribute' => [
'mage-init' => ['button' => ['event' => 'save']],
'form-role' => 'save',
],
'sort_order' => 90,
];
}
}
+107
View File
@@ -0,0 +1,107 @@
<?php
declare(strict_types=1);
namespace Esun\Agent\Block;
use Esun\Agent\Model\Map\CountryPosition;
use Esun\Agent\Model\ResourceModel\Agent\CollectionFactory;
use Magento\Directory\Model\ResourceModel\Country\CollectionFactory as CountryCollectionFactory;
use Magento\Framework\Filesystem\Driver\File;
use Magento\Framework\Module\Dir\Reader as ModuleDirReader;
use Magento\Framework\UrlInterface;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Magento\Store\Model\StoreManagerInterface;
use RuntimeException;
class AgentLocator extends Template
{
public function __construct(
Context $context,
private readonly ModuleDirReader $moduleDirReader,
private readonly File $file,
private readonly CollectionFactory $collectionFactory,
private readonly StoreManagerInterface $storeManager,
private readonly CountryPosition $countryPosition,
private readonly CountryCollectionFactory $countryCollectionFactory,
array $data = []
) {
parent::__construct($context, $data);
}
public function getCountryOptions(): array
{
return $this->countryCollectionFactory->create()
->loadByStore()
->toOptionArray(false);
}
public function getContactBackgroundUrl(): string
{
return $this->storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA)
. 'wysiwyg/about/icons/esun-contact-bk.png';
}
public function getConfigJson(): string
{
$moduleDir = $this->moduleDirReader->getModuleDir('', 'Esun_Agent');
$dataFile = $moduleDir . '/view/frontend/web/data/agents.json';
if (!$this->file->isExists($dataFile)) {
throw new RuntimeException('Agent data file does not exist.');
}
$data = json_decode($this->file->fileGetContents($dataFile), true, 512, JSON_THROW_ON_ERROR);
$data['agents'] = [];
$mediaUrl = $this->storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA);
$collection = $this->collectionFactory->create()
->addFieldToFilter('is_active', 1)
->setOrder('sort_order', 'ASC')
->setOrder('entity_id', 'ASC');
foreach ($collection as $agentModel) {
$logo = (string) $agentModel->getData('logo');
$position = $this->countryPosition->get((string) $agentModel->getData('country_code'));
$data['agents'][] = [
'id' => (int) $agentModel->getId(),
'system_name' => (string) $agentModel->getData('system_name'),
'name' => (string) $agentModel->getData('name'),
'continent' => (string) $agentModel->getData('continent'),
'country_code' => (string) $agentModel->getData('country_code'),
'country' => (string) $agentModel->getData('country'),
'website' => (string) $agentModel->getData('website'),
'address' => (string) $agentModel->getData('address'),
'note' => (string) $agentModel->getData('note'),
'map_x' => $position['x'] ?? null,
'map_y' => $position['y'] ?? null,
'sort_order' => (int) $agentModel->getData('sort_order'),
'logo_url' => $logo !== ''
? $mediaUrl . ltrim($logo, '/')
: $this->getViewFileUrl('Esun_Agent::images/agents/placeholder.svg'),
];
}
unset($agent);
$config = [
'data' => $data,
'mapUrl' => $this->getViewFileUrl('Esun_Agent::images/world-map-dots.svg'),
'labels' => [
'agents' => (string) __('Agents'),
'exploreAll' => (string) __('Explore All'),
'noResults' => (string) __('No agents match the selected filters.'),
'website' => (string) __('Website'),
'filteredResults' => (string) __('Filtered Results (%1 matched partners)'),
'previousPage' => (string) __('Previous page'),
'nextPage' => (string) __('Next page'),
'page' => (string) __('Page %1'),
],
];
return (string) json_encode(
$config,
JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT
| JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR
);
}
}