public function create(RegisterBindingModel $user)
 {
     if ($user->getPassword() != $user->getConfirmPassword()) {
         throw new InvalidUserInputException('Passwords does not match');
     }
     $isCreated = $this->db->insertEntity(self::USERS_TABLENAME, array('username' => $user->getUsername(), 'password' => password_hash($user->getPassword(), AppConfig::PASSWORD_CRYPT_METHOD), 'email' => $user->getEmail(), 'cash' => $user->getCash(), 'role_id' => $user->getRole()));
     return $isCreated;
 }
 public function putCategoryProductsOnPromotion($categoryId, $discount, $categoryName)
 {
     $productsInCategory = $this->db->getAllEntitiesWithCondition(self::PRODUCTS_TABLENAME, "category_id={$categoryId}", 'id');
     foreach ($productsInCategory as $product) {
         $priceWithDiscount = $product['price'] - $product['price'] * ($discount / 100);
         $isUpdated = $this->db->updateEntityById(self::PRODUCTS_TABLENAME, array("price" => $priceWithDiscount), $product['id']);
     }
     if ($isUpdated) {
         $isAdded = $this->db->insertEntity(self::PROMO_CATEGORIES_TABLENAME, array("category_id" => $categoryId, "discount" => $discount, "category_name" => $categoryName));
     }
     return $isAdded;
 }
 public function putAllProductsOnPromotion($discount)
 {
     $allProducts = $this->getAll();
     foreach ($allProducts as $product) {
         $priceWithDiscount = $product->getPrice() - $product->getPrice() * ($discount / 100);
         $isUpdated = $this->db->updateEntityById(self::PRODUCTS_TABLENAME, array("price" => $priceWithDiscount), $product->getId());
         if (!$isUpdated) {
             throw new InvalidUserOperationException("Invalid operation");
         }
     }
     if ($isUpdated) {
         $isAdded = $this->db->insertEntity(self::ALL_PRODUCTS_PROMO_TABLENAME, array("discount" => $discount));
     }
     return $isAdded;
 }
 public function addToCart($cartId, $productId)
 {
     $isAdded = $this->db->insertEntity(self::CART_PRODUCTS_TABLENAME, array('cart_id' => $cartId, 'product_id' => $productId));
     return $isAdded;
 }