historyFactory = $historyFactory; $this->historyRepository = $historyRepository; } /** * Adds comment to case related order. * Throws an exception if cannot save history comment. * * @param CaseInterface $case * @param Phrase $message * @param string $status * @return void */ public function addComment(CaseInterface $case, Phrase $message, $status = '') { if (!$message->getText()) { return; } /** @var \Magento\Sales\Api\Data\OrderStatusHistoryInterface $history */ $history = $this->historyFactory->create(); $history->setParentId($case->getOrderId()) ->setComment($message) ->setEntityName('order') ->setStatus($status); $this->historyRepository->save($history); } }