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,26 @@
<?php
declare(strict_types=1);
namespace Esun\Catalog\Controller\Adminhtml\MixStepPricing;
use Magento\Backend\App\Action;
use Magento\Framework\View\Result\PageFactory;
class Delete extends Action
{
public const ADMIN_RESOURCE = 'Esun_Catalog::mix_step_pricing_delete';
public function __construct(Action\Context $context, private readonly PageFactory $pageFactory)
{
parent::__construct($context);
}
public function execute()
{
$page = $this->pageFactory->create();
$page->setActiveMenu(self::ADMIN_RESOURCE);
$page->getConfig()->getTitle()->prepend(__('Batch Delete Mix Step Pricing'));
return $page;
}
}
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace Esun\Catalog\Controller\Adminhtml\MixStepPricing;
use Esun\Catalog\Model\MixStepPricing\TemplateGenerator;
use Magento\Backend\App\Action;
use Magento\Framework\Controller\Result\RawFactory;
class DownloadDeleteTemplate extends Action
{
public const ADMIN_RESOURCE = 'Esun_Catalog::mix_step_pricing_delete';
public function __construct(
Action\Context $context,
private readonly TemplateGenerator $templateGenerator,
private readonly RawFactory $rawFactory
) {
parent::__construct($context);
}
public function execute()
{
return $this->rawFactory->create()
->setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
->setHeader('Content-Disposition', 'attachment; filename="mix_step_pricing_delete.xlsx"')
->setContents($this->templateGenerator->createDelete());
}
}
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace Esun\Catalog\Controller\Adminhtml\MixStepPricing;
use Esun\Catalog\Model\MixStepPricing\TemplateGenerator;
use Magento\Backend\App\Action;
use Magento\Framework\Controller\Result\RawFactory;
class DownloadImportTemplate extends Action
{
public const ADMIN_RESOURCE = 'Esun_Catalog::mix_step_pricing_import';
public function __construct(
Action\Context $context,
private readonly TemplateGenerator $templateGenerator,
private readonly RawFactory $rawFactory
) {
parent::__construct($context);
}
public function execute()
{
return $this->rawFactory->create()
->setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
->setHeader('Content-Disposition', 'attachment; filename="mix_step_pricing_import.xlsx"')
->setContents($this->templateGenerator->createImport());
}
}
@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Esun\Catalog\Controller\Adminhtml\MixStepPricing;
use Magento\Backend\App\Action;
use Magento\Framework\View\Result\PageFactory;
class Import extends Action
{
public const ADMIN_RESOURCE = 'Esun_Catalog::mix_step_pricing_import';
public function __construct(Action\Context $context, private readonly PageFactory $pageFactory)
{
parent::__construct($context);
}
public function execute()
{
$page = $this->pageFactory->create();
$page->setActiveMenu(self::ADMIN_RESOURCE);
$page->getConfig()->getTitle()->prepend(__('Batch Import Mix Step Pricing'));
return $page;
}
}
@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace Esun\Catalog\Controller\Adminhtml\MixStepPricing;
use Esun\Catalog\Model\MixStepPricing\DeleteService;
use Esun\Catalog\Model\MixStepPricing\ValidationState;
use Magento\Backend\App\Action;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Filesystem\DriverInterface;
class RunDelete extends Action
{
public const ADMIN_RESOURCE = 'Esun_Catalog::mix_step_pricing_delete';
public function __construct(
Action\Context $context,
private readonly DeleteService $deleteService,
private readonly ValidationState $validationState,
private readonly DriverInterface $filesystemDriver
) {
parent::__construct($context);
}
public function execute()
{
$state = $this->validationState->get('delete');
try {
if ((string)$this->getRequest()->getParam('confirm_delete') !== '1') {
throw new LocalizedException(__('Confirm that you understand this operation deletes all tiers.'));
}
$path = (string)($state['path'] ?? '');
if (empty($state['valid']) || $path === '' || !$this->filesystemDriver->isFile($path)) {
throw new LocalizedException(__('Validate an Excel file before running the delete.'));
}
$stats = $this->deleteService->run($path);
$this->validationState->clear('delete');
$this->filesystemDriver->deleteFile($path);
$this->messageManager->addSuccessMessage(__(
'Deleted Mix Step Pricing for %1 sku + website groups across %2 Store Views.',
$stats['groups'],
$stats['store_views']
));
} catch (\Throwable $exception) {
$this->messageManager->addErrorMessage($exception->getMessage());
}
return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('*/*/delete');
}
}
@@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
namespace Esun\Catalog\Controller\Adminhtml\MixStepPricing;
use Esun\Catalog\Model\MixStepPricing\ImportService;
use Esun\Catalog\Model\MixStepPricing\ValidationState;
use Magento\Backend\App\Action;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Filesystem\DriverInterface;
class RunImport extends Action
{
public const ADMIN_RESOURCE = 'Esun_Catalog::mix_step_pricing_import';
public function __construct(
Action\Context $context,
private readonly ImportService $importService,
private readonly ValidationState $validationState,
private readonly DriverInterface $filesystemDriver
) {
parent::__construct($context);
}
public function execute()
{
$state = $this->validationState->get('import');
try {
$path = (string)($state['path'] ?? '');
if (empty($state['valid']) || $path === '' || !$this->filesystemDriver->isFile($path)) {
throw new LocalizedException(__('Validate an Excel file before running the import.'));
}
$stats = $this->importService->run($path);
$this->validationState->clear('import');
$this->filesystemDriver->deleteFile($path);
$this->messageManager->addSuccessMessage(__(
'Imported %1 sku + website groups across %2 Store Views.',
$stats['groups'],
$stats['store_views']
));
} catch (\Throwable $exception) {
$this->messageManager->addErrorMessage($exception->getMessage());
}
return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('*/*/import');
}
}
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace Esun\Catalog\Controller\Adminhtml\MixStepPricing;
use Esun\Catalog\Model\MixStepPricing\DeleteService;
use Esun\Catalog\Model\MixStepPricing\FileUploader;
use Esun\Catalog\Model\MixStepPricing\ValidationState;
use Magento\Backend\App\Action;
use Magento\Framework\Controller\ResultFactory;
class ValidateDelete extends Action
{
public const ADMIN_RESOURCE = 'Esun_Catalog::mix_step_pricing_delete';
public function __construct(
Action\Context $context,
private readonly FileUploader $fileUploader,
private readonly DeleteService $deleteService,
private readonly ValidationState $validationState
) {
parent::__construct($context);
}
public function execute()
{
$this->validationState->clear('delete');
try {
$path = $this->fileUploader->upload('excel_file');
$result = $this->deleteService->validate($path);
$this->validationState->save('delete', $path, $result);
if ($result['valid']) {
$this->messageManager->addSuccessMessage(__('Delete validation passed. Review the preview carefully.'));
}
} catch (\Throwable $exception) {
$this->messageManager->addErrorMessage($exception->getMessage());
}
return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('*/*/delete');
}
}
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace Esun\Catalog\Controller\Adminhtml\MixStepPricing;
use Esun\Catalog\Model\MixStepPricing\FileUploader;
use Esun\Catalog\Model\MixStepPricing\ImportService;
use Esun\Catalog\Model\MixStepPricing\ValidationState;
use Magento\Backend\App\Action;
use Magento\Framework\Controller\ResultFactory;
class ValidateImport extends Action
{
public const ADMIN_RESOURCE = 'Esun_Catalog::mix_step_pricing_import';
public function __construct(
Action\Context $context,
private readonly FileUploader $fileUploader,
private readonly ImportService $importService,
private readonly ValidationState $validationState
) {
parent::__construct($context);
}
public function execute()
{
$this->validationState->clear('import');
try {
$path = $this->fileUploader->upload('excel_file');
$result = $this->importService->validate($path);
$this->validationState->save('import', $path, $result);
if ($result['valid']) {
$this->messageManager->addSuccessMessage(
__('Import validation passed. Review the preview before running the import.')
);
}
} catch (\Throwable $exception) {
$this->messageManager->addErrorMessage($exception->getMessage());
}
return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('*/*/import');
}
}