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

61 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace Esun\Translation\Model\Entity;
use Esun\Translation\Api\TranslatableEntityInterface;
use Esun\Translation\Model\Product\TranslatableFieldProvider;
use Esun\Translation\Model\Product\TranslationApplier;
use Magento\Catalog\Api\ProductRepositoryInterface;
class ProductEntity implements TranslatableEntityInterface
{
public function __construct(
private readonly ProductRepositoryInterface $productRepository,
private readonly TranslatableFieldProvider $fieldProvider,
private readonly TranslationApplier $translationApplier
) {
}
public function getType(): string
{
return 'product';
}
public function getLabel(): string
{
return 'Product';
}
public function getTitle(int $entityId): string
{
return (string)$this->productRepository->getById($entityId)->getName();
}
public function getEditUrlPath(): string
{
return 'catalog/product/edit';
}
public function getEditIdParam(): string
{
return 'id';
}
public function getFields(int $entityId, array $targetStoreIds = []): array
{
return $this->fieldProvider->getFields($entityId, $targetStoreIds);
}
public function apply(int $entityId, array $storeIds, array $fields): array
{
$updated = $this->translationApplier->apply($entityId, $storeIds, $fields);
return [
'updated' => $updated,
'message' => __('Translations applied to %1 store view(s).', $updated)->render(),
];
}
}