public function getById(string $cartId) : Cart
{
$qb = $this->connection->createQueryBuilder();
$qb->select('id', 'currency', 'cart_items')->from('dumplie_customer_cart')->where('id = :id')->setParameter('id', $cartId);
$cartData = $this->connection->fetchAssoc($qb->getSQL(), $qb->getParameters());
if (empty($cartData)) {
throw QueryException::cartNotFound($cartId);
}
$itemsData = json_decode($cartData['cart_items'], true);
$items = [];
foreach ($itemsData as $item) {
$items[] = $this->getItemBySku($item['sku'], $item['quantity']);
}
return new Cart($cartData['currency'], $items);
}