jsonFactory->create(); try { $type = (string)$this->getRequest()->getParam('entity_type', 'product'); $entityId = (int)$this->getRequest()->getParam('entity_id', $this->getRequest()->getParam('product_id')); $language = (string)$this->getRequest()->getParam('language'); $fields = $this->getRequest()->getParam('fields', []); if ($entityId <= 0) { throw new \InvalidArgumentException('A valid content ID is required.'); } if (!is_array($fields)) { throw new \InvalidArgumentException('Fields payload is invalid.'); } $response = $this->applyService->apply($type, $entityId, $language, $fields); return $result->setData(array_merge(['success' => true], $response)); } catch (\Throwable $exception) { return $result->setData([ 'success' => false, 'message' => $exception->getMessage(), ]); } } protected function _isAllowed(): bool { return $this->_authorization->isAllowed($this->getApplyResource()); } private function getApplyResource(): string { return match ((string)$this->getRequest()->getParam('entity_type', 'product')) { 'cms_page' => 'Esun_Translation::apply_cms_page_translation', 'cms_block' => 'Esun_Translation::apply_cms_block_translation', default => 'Esun_Translation::apply_product_translation', }; } }