Files
2026-09-15 10:35:56 +08:00

38 lines
1021 B
PHP

<?php
declare(strict_types=1);
namespace Esun\Catalog\Model\MixStepPricing;
use Magento\Framework\Exception\LocalizedException;
class DeleteService
{
public function __construct(
private readonly SpreadsheetReader $reader,
private readonly BatchValidator $validator,
private readonly AttributeWriter $attributeWriter
) {
}
public function validate(string $path): array
{
return $this->validator->validateDelete($this->reader->readDelete($path));
}
/**
* @throws LocalizedException
*/
public function run(string $path): array
{
$result = $this->validate($path);
if (!$result['valid']) {
throw new LocalizedException(__('Validation failed. No prices were deleted.'));
}
if ($result['groups'] === []) {
throw new LocalizedException(__('There are no existing configurable products to delete.'));
}
return $this->attributeWriter->write($result['groups'], true);
}
}