diff --git a/src/Repository/DiscussionRepository.php b/src/Repository/DiscussionRepository.php index f30db0e..1a21545 100644 --- a/src/Repository/DiscussionRepository.php +++ b/src/Repository/DiscussionRepository.php @@ -277,4 +277,36 @@ public function andWhereDiscussionFilter(QueryBuilder $queryBuilder, $user_id = return $queryBuilder; } + + /** + * Get a discussion by order Id + * + * @param integer $orderId + * + * @return DiscussionInterface | null + * + * @throws \Exception + */ + public function getByOrderId(int $orderId) + { + $qb = $this->_getRepo()->createQueryBuilder('Discussion'); + $expr = $qb->expr(); + + $query = $qb + ->join( + 'Discussion.meta_data', + 'MetaData' + ) + ->where($expr->eq('MetaData.name', ':name')) + ->andWhere($expr->eq('MetaData.value', ':orderId')) + ->setParameters( + [ + 'name' => 'order_id', + 'orderId' => $orderId, + ] + ) + ->getQuery(); + + return $query->getOneOrNullResult(); + } }