metadataPool = $metadataPool; $this->resourceConnection = $resourceConnection; } public function execute(int $productId): ?int { $metadata = $this->metadataPool->getMetadata(ProductInterface::class); if ($metadata->getLinkField() == $metadata->getIdentifierField()) { return $productId; } $connection = $this->resourceConnection->getConnectionByName($metadata->getEntityConnectionName()); $select = $connection->select() ->from($metadata->getEntityTable(), [$metadata->getIdentifierField()]) ->where($metadata->getLinkField() . ' = ?', $productId); $productId = $connection->fetchOne($select); return $productId ? (int)$productId : null; } }