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,53 @@
<?php
declare(strict_types=1);
namespace Esun\Catalog\Block\Adminhtml\CertificationType;
use Esun\Catalog\Model\CertificationType;
use Esun\Catalog\Model\CertificationTypeFactory;
use Magento\Backend\Block\Template;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\UrlInterface;
use Magento\Store\Model\StoreManagerInterface;
class EditBlock extends Template
{
private ?CertificationType $type = null;
public function __construct(
Context $context,
private readonly CertificationTypeFactory $typeFactory,
private readonly StoreManagerInterface $storeManager,
array $data = []
) {
parent::__construct($context, $data);
}
public function getTypeModel(): CertificationType
{
if ($this->type === null) {
$this->type = $this->typeFactory->create();
$id = (int)$this->getRequest()->getParam('id');
if ($id) {
$this->type->load($id);
}
}
return $this->type;
}
public function getSaveUrl(): string
{
return $this->getUrl('esun_catalog/certificationtype/save');
}
public function getBackUrl(): string
{
return $this->getUrl('esun_catalog/certificationtype/index');
}
public function getIconUrl(string $path): string
{
return $this->storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA) . ltrim($path, '/');
}
}
@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
namespace Esun\Catalog\Block\Adminhtml\CertificationType;
use Esun\Catalog\Model\ResourceModel\CertificationType\Collection;
use Esun\Catalog\Model\ResourceModel\CertificationType\CollectionFactory;
use Magento\Backend\Block\Template;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\UrlInterface;
use Magento\Store\Model\StoreManagerInterface;
class ListBlock extends Template
{
private ?Collection $types = null;
public function __construct(
Context $context,
private readonly CollectionFactory $collectionFactory,
private readonly StoreManagerInterface $storeManager,
array $data = []
) {
parent::__construct($context, $data);
}
public function getTypes(): Collection
{
if ($this->types === null) {
$this->types = $this->collectionFactory->create()
->setOrder('sort_order', 'ASC')
->setOrder('type_id', 'DESC');
}
return $this->types;
}
public function getNewUrl(): string
{
return $this->getUrl('esun_catalog/certificationtype/new');
}
public function getEditUrl(int $id): string
{
return $this->getUrl('esun_catalog/certificationtype/edit', ['id' => $id]);
}
public function getDeleteUrl(int $id): string
{
return $this->getUrl('esun_catalog/certificationtype/delete', ['id' => $id]);
}
public function getIconUrl(string $path): string
{
return $this->storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA) . ltrim($path, '/');
}
}
@@ -0,0 +1,60 @@
<?php
declare(strict_types=1);
namespace Esun\Catalog\Block\Adminhtml\ColorOption;
use Esun\Catalog\Model\ColorOption;
use Esun\Catalog\Model\ColorOptionFactory;
use Esun\Catalog\Model\Config\Source\ColorOptionOptions;
use Magento\Backend\Block\Template;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\UrlInterface;
use Magento\Store\Model\StoreManagerInterface;
class EditBlock extends Template
{
private ?ColorOption $item = null;
public function __construct(
Context $context,
private readonly ColorOptionFactory $colorOptionFactory,
private readonly ColorOptionOptions $colorOptionOptions,
private readonly StoreManagerInterface $storeManager,
array $data = []
) {
parent::__construct($context, $data);
}
public function getItem(): ColorOption
{
if ($this->item === null) {
$this->item = $this->colorOptionFactory->create();
$id = (int)$this->getRequest()->getParam('id');
if ($id) {
$this->item->load($id);
}
}
return $this->item;
}
public function getColorOptions(): array
{
return $this->colorOptionOptions->toOptionArray();
}
public function getSaveUrl(): string
{
return $this->getUrl('esun_catalog/coloroption/save');
}
public function getBackUrl(): string
{
return $this->getUrl('esun_catalog/coloroption/index');
}
public function getImageUrl(string $path): string
{
return $this->storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA) . ltrim($path, '/');
}
}
@@ -0,0 +1,76 @@
<?php
declare(strict_types=1);
namespace Esun\Catalog\Block\Adminhtml\ColorOption;
use Esun\Catalog\Model\Config\Source\ColorOptionOptions;
use Esun\Catalog\Model\ResourceModel\ColorOption\Collection;
use Esun\Catalog\Model\ResourceModel\ColorOption\CollectionFactory;
use Magento\Backend\Block\Template;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\UrlInterface;
use Magento\Store\Model\StoreManagerInterface;
class ListBlock extends Template
{
private ?Collection $items = null;
private ?array $optionLabels = null;
public function __construct(
Context $context,
private readonly CollectionFactory $collectionFactory,
private readonly ColorOptionOptions $colorOptionOptions,
private readonly StoreManagerInterface $storeManager,
array $data = []
) {
parent::__construct($context, $data);
}
public function getItems(): Collection
{
if ($this->items === null) {
$this->items = $this->collectionFactory->create()
->setOrder('sort_order', 'ASC')
->setOrder('entity_id', 'DESC');
}
return $this->items;
}
public function getColorOptionLabel(int $optionId): string
{
return $this->getOptionLabels()[$optionId] ?? (string)$optionId;
}
public function getNewUrl(): string
{
return $this->getUrl('esun_catalog/coloroption/new');
}
public function getEditUrl(int $id): string
{
return $this->getUrl('esun_catalog/coloroption/edit', ['id' => $id]);
}
public function getDeleteUrl(int $id): string
{
return $this->getUrl('esun_catalog/coloroption/delete', ['id' => $id]);
}
public function getImageUrl(string $path): string
{
return $this->storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA) . ltrim($path, '/');
}
private function getOptionLabels(): array
{
if ($this->optionLabels === null) {
$this->optionLabels = [];
foreach ($this->colorOptionOptions->toOptionArray() as $option) {
$this->optionLabels[(int)$option['value']] = (string)$option['label'];
}
}
return $this->optionLabels;
}
}
@@ -0,0 +1,78 @@
<?php
declare(strict_types=1);
namespace Esun\Catalog\Block\Adminhtml\Faq;
use Esun\Catalog\Model\Faq;
use Esun\Catalog\Model\FaqFactory;
use Magento\Backend\Block\Template;
use Magento\Backend\Block\Template\Context;
use Magento\Cms\Model\Wysiwyg\Config as WysiwygConfig;
use Magento\Framework\Data\FormFactory;
use Magento\Store\Model\System\Store;
class EditBlock extends Template
{
private ?Faq $faq = null;
public function __construct(
Context $context,
private readonly FaqFactory $faqFactory,
private readonly Store $storeSystem,
private readonly FormFactory $formFactory,
private readonly WysiwygConfig $wysiwygConfig,
array $data = []
) {
parent::__construct($context, $data);
}
public function getFaqModel(): Faq
{
if ($this->faq === null) {
$this->faq = $this->faqFactory->create();
$id = (int)$this->getRequest()->getParam('id');
if ($id) {
$this->faq->load($id);
}
}
return $this->faq;
}
public function getStoreOptions(): array
{
return $this->storeSystem->getStoreValuesForForm(false, true);
}
public function getSaveUrl(): string
{
return $this->getUrl('esun_catalog/faq/save');
}
public function getBackUrl(): string
{
return $this->getUrl('esun_catalog/faq/index');
}
public function getContentEditorHtml(): string
{
$form = $this->formFactory->create();
$editor = $form->addField('content', 'editor', [
'name' => 'content',
'label' => __('Content'),
'title' => __('Content'),
'style' => 'height:28em',
'required' => false,
'value' => (string)$this->getFaqModel()->getData('content'),
'config' => $this->wysiwygConfig->getConfig([
'add_variables' => false,
'add_widgets' => true,
'add_images' => true,
'is_pagebuilder_enabled' => true,
'pagebuilder_button' => true,
]),
]);
return $editor->getElementHtml();
}
}
@@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
namespace Esun\Catalog\Block\Adminhtml\Faq;
use Esun\Catalog\Model\ResourceModel\Faq\Collection;
use Esun\Catalog\Model\ResourceModel\Faq\CollectionFactory;
use Magento\Backend\Block\Template;
use Magento\Backend\Block\Template\Context;
class ListBlock extends Template
{
private ?Collection $faqs = null;
public function __construct(
Context $context,
private readonly CollectionFactory $collectionFactory,
array $data = []
) {
parent::__construct($context, $data);
}
public function getFaqs(): Collection
{
if ($this->faqs === null) {
$this->faqs = $this->collectionFactory->create()
->setOrder('sort_order', 'ASC')
->setOrder('faq_id', 'DESC');
}
return $this->faqs;
}
public function getNewUrl(): string
{
return $this->getUrl('esun_catalog/faq/new');
}
public function getEditUrl(int $id): string
{
return $this->getUrl('esun_catalog/faq/edit', ['id' => $id]);
}
public function getDeleteUrl(int $id): string
{
return $this->getUrl('esun_catalog/faq/delete', ['id' => $id]);
}
}
@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
namespace Esun\Catalog\Block\Adminhtml\MixStepPricing;
use Esun\Catalog\Model\MixStepPricing\ValidationState;
use Magento\Backend\Block\Template;
use Magento\Backend\Block\Template\Context;
class Form extends Template
{
protected $_template = 'Esun_Catalog::mix_step_pricing/form.phtml';
public function __construct(
Context $context,
private readonly ValidationState $validationState,
array $data = []
) {
parent::__construct($context, $data);
}
public function isDelete(): bool
{
return $this->getMode() === 'delete';
}
public function getMode(): string
{
return (string)$this->getData('mode');
}
public function getValidationState(): array
{
return $this->validationState->get($this->getMode());
}
public function getValidateUrl(): string
{
return $this->getUrl('esun_catalog/mixsteppricing/' . ($this->isDelete() ? 'validateDelete' : 'validateImport'));
}
public function getRunUrl(): string
{
return $this->getUrl('esun_catalog/mixsteppricing/' . ($this->isDelete() ? 'runDelete' : 'runImport'));
}
public function getTemplateUrl(): string
{
return $this->getUrl(
'esun_catalog/mixsteppricing/' . ($this->isDelete() ? 'downloadDeleteTemplate' : 'downloadImportTemplate')
);
}
}
@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
namespace Esun\Catalog\Block\Adminhtml\Product\Edit\Button;
use Magento\Catalog\Block\Adminhtml\Product\Edit\Button\Generic;
use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator;
use Magento\Framework\Registry;
use Magento\Framework\UrlInterface;
use Magento\Framework\View\Element\UiComponent\Context;
use Magento\Store\Model\StoreManagerInterface;
use Magento\UrlRewrite\Model\UrlFinderInterface;
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
class Preview extends Generic
{
private StoreManagerInterface $storeManager;
private UrlFinderInterface $urlFinder;
public function __construct(
Context $context,
Registry $registry,
StoreManagerInterface $storeManager,
UrlFinderInterface $urlFinder
) {
parent::__construct($context, $registry);
$this->storeManager = $storeManager;
$this->urlFinder = $urlFinder;
}
/**
* @return array<string, mixed>
*/
public function getButtonData(): array
{
$product = $this->getProduct();
if (!$product || !$product->getId()) {
return [];
}
$url = json_encode(
$this->getFrontendUrl((int) $product->getId(), (int) $product->getStoreId()),
JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT
);
return [
'label' => __('Preview'),
'class' => 'action-secondary',
'on_click' => sprintf('window.open(%s, "_blank", "noopener");', $url),
'sort_order' => 30,
];
}
private function getFrontendUrl(int $productId, int $storeId): string
{
$store = $storeId
? $this->storeManager->getStore($storeId)
: $this->storeManager->getDefaultStoreView();
$rewrites = $this->urlFinder->findAllByData([
UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE,
UrlRewrite::ENTITY_ID => $productId,
UrlRewrite::STORE_ID => (int) $store->getId(),
UrlRewrite::REDIRECT_TYPE => 0,
]);
$requestPath = sprintf('catalog/product/view/id/%d/', $productId);
foreach ($rewrites as $rewrite) {
if (!$rewrite->getMetadata()) {
$requestPath = $rewrite->getRequestPath();
break;
}
}
return rtrim($store->getBaseUrl(UrlInterface::URL_TYPE_LINK), '/')
. '/'
. ltrim($requestPath, '/');
}
}
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace Esun\Catalog\Block\Adminhtml\ProductRecommendation;
use Esun\Catalog\Model\ProductRecommendation\ValidationState;
use Magento\Backend\Block\Template;
use Magento\Backend\Block\Template\Context;
class ImportForm extends Template
{
protected $_template = 'Esun_Catalog::product_recommendation/import.phtml';
public function __construct(
Context $context,
private readonly ValidationState $validationState,
array $data = []
) {
parent::__construct($context, $data);
}
public function getValidationState(): array
{
return $this->validationState->get();
}
public function getValidateUrl(): string
{
return $this->getUrl('esun_catalog/productrecommendation/validateImport');
}
public function getRunUrl(): string
{
return $this->getUrl('esun_catalog/productrecommendation/runImport');
}
public function getTemplateUrl(): string
{
return $this->getUrl('esun_catalog/productrecommendation/downloadTemplate');
}
}
@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
namespace Esun\Catalog\Block\Adminhtml\SpecificationBrand;
use Esun\Catalog\Model\SpecificationBrand;
use Esun\Catalog\Model\SpecificationBrandFactory;
use Magento\Backend\Block\Template;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\UrlInterface;
use Magento\Store\Model\StoreManagerInterface;
class EditBlock extends Template
{
private ?SpecificationBrand $brand = null;
public function __construct(
Context $context,
private readonly SpecificationBrandFactory $brandFactory,
private readonly StoreManagerInterface $storeManager,
array $data = []
) {
parent::__construct($context, $data);
}
public function getBrand(): SpecificationBrand
{
if ($this->brand === null) {
$this->brand = $this->brandFactory->create();
$id = (int)$this->getRequest()->getParam('id');
if ($id > 0) {
$this->brand->load($id);
}
}
return $this->brand;
}
public function getSaveUrl(): string
{
return $this->getUrl('esun_catalog/specificationbrand/save');
}
public function getBackUrl(): string
{
return $this->getUrl('esun_catalog/specificationbrand/index');
}
public function getMediaUrl(string $path): string
{
return $this->storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA) . ltrim($path, '/');
}
}
@@ -0,0 +1,68 @@
<?php
declare(strict_types=1);
namespace Esun\Catalog\Block\Adminhtml\SpecificationImport;
use Esun\Catalog\Model\ResourceModel\SpecificationBrand\CollectionFactory as BrandCollectionFactory;
use Esun\Catalog\Model\SpecificationImport;
use Esun\Catalog\Model\SpecificationImportFactory;
use Magento\Backend\Block\Template;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\UrlInterface;
use Magento\Store\Model\StoreManagerInterface;
class EditBlock extends Template
{
private ?SpecificationImport $import = null;
public function __construct(
Context $context,
private readonly SpecificationImportFactory $importFactory,
private readonly BrandCollectionFactory $brandCollectionFactory,
private readonly StoreManagerInterface $storeManager,
array $data = []
) {
parent::__construct($context, $data);
}
public function getImport(): SpecificationImport
{
if ($this->import === null) {
$this->import = $this->importFactory->create();
$id = (int)$this->getRequest()->getParam('id');
if ($id > 0) {
$this->import->load($id);
}
}
return $this->import;
}
public function getBrands()
{
return $this->brandCollectionFactory->create()
->addFieldToFilter('status', 1)
->setOrder('sort_order', 'ASC')
->setOrder('brand_name', 'ASC');
}
public function getSaveUrl(): string
{
return $this->getUrl('esun_catalog/specificationimport/save');
}
public function getBackUrl(): string
{
return $this->getUrl('esun_catalog/specificationimport/index');
}
public function getBrandUrl(): string
{
return $this->getUrl('esun_catalog/specificationbrand/new');
}
public function getMediaUrl(string $path): string
{
return $this->storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA) . ltrim($path, '/');
}
}