/**
  * @param int $limit
  * @param int $offset
  * @return array
  */
 public function findAll(int $limit, int $offset = 0) : array
 {
     $qb = $this->connection->createQueryBuilder();
     $qb->select('*')->from('dumplie_inventory_product')->setFirstResult($offset)->setMaxResults($limit);
     $results = $this->connection->fetchAll($qb->getSQL(), $qb->getParameters());
     return array_map(function ($data) {
         return new Product($data['sku'], $data['price_amount'] / $data['price_precision'], $data['price_currency'], (bool) $data['is_in_stock'], $this->mao->getBy([Metadata::FIELD_SKU => $data['sku']]));
     }, $results);
 }
Exemple #2
0
 /**
  * @param string $sku
  * @param int    $quantity
  *
  * @return CartItem
  * @throws QueryException
  */
 private function getItemBySku(string $sku, int $quantity) : CartItem
 {
     $qb = $this->connection->createQueryBuilder();
     $qb->select('*')->from('dumplie_inventory_product')->where('sku = :sku')->setParameter('sku', $sku);
     $itemData = $this->connection->fetchAssoc($qb->getSQL(), $qb->getParameters());
     if (empty($itemData)) {
         throw QueryException::cartItemNotFound($sku);
     }
     return new CartItem($itemData['sku'], $quantity, $itemData['price_amount'] / $itemData['price_precision'], $itemData['price_currency'], $this->mao->getBy([Metadata::FIELD_SKU => $itemData['sku']]));
 }