src/Backend/Modules/Commerce/Domain/Cart/CartRepository.php
/**
     * Find by a cart by session id. When there is no cart found create a new one.
     *
     * @return Cart
     */
Find by a cart by session id. When there is no cart found create a new one.
@return Cart
Find by a cart by session id . When there is no cart found create a new one . @return Cart
public function findBySessionId(string $hash, string $ip)
    {
        $query_builder = $this->createQueryBuilder('i');
        try {
            $entity = $query_builder->where('i.sessionId = :sessionId')
                ->setParameter('sessionId', $hash)
                ->getQuery()
                ->getOneOrNullResult();
        } catch (NonUniqueResultException $e) {
            $entity = null;
        }
        if (!$entity) {
            $entity = new Cart();
            $entity->setSessionId($hash);
            $entity->setIp($ip);
            $this->save($entity);
        }
        return $entity;
    }
public function findBySessionId ( string $ hash , string $ ip ) { $ query_builder = $ this -> createQueryBuilder ( 'i' ) ; try { $ entity = $ query_builder -> where ( 'i.sessionId = :sessionId' ) -> setParameter ( 'sessionId' , $ hash ) -> getQuery ( ) -> getOneOrNullResult ( ) ; } catch ( NonUniqueResultException $ e ) { $ entity = null ; } if ( ! $ entity ) { $ entity = new Cart ( ) ; $ entity -> setSessionId ( $ hash ) ; $ entity -> setIp ( $ ip ) ; $ this -> save ( $ entity ) ; } return $ entity ; }
Find by a cart by session id.
Find by a cart by session id .