public function getUserCard($userId) { $query = "SELECT * FROM carts WHERE carts.ownerId = ?"; $this->db->query($query, [$userId]); $result = $this->db->row(); $query = "SELECT * FROM cartsproducts where cartId = ?"; $this->db->query($query, [$result['id']]); $cartProducts = $this->db->fetchAll(); $productRepo = ProductRepository::create(); foreach ($cartProducts as $key => $value) { $cartProducts[$key]['product'] = $productRepo->getProduct(intval($value['productId'])); } $user = UserRepository::create()->getOne($userId); $_SESSION['cash'] = $user['cash']; $result['cartProducts'] = $cartProducts; return $result; }
public function checkIfExist($name) { $products = ProductRepository::create()->getAll(); foreach ($products as $key => $value) { if ($value['name'] === $name) { echo 'Product with this name exists!'; die; } } }