public function addtocart() { if (isset($_SESSION['account'])) { $account = $_SESSION['account']; $productId = $_POST['productid']; $quantity = $_POST['quantity']; /* Checking availability */ $database = new Database('localhost', 'pdo_ret', 'root', ''); $sql = "select product_name, quantity_left, price from product where product_id='{$productId}';"; $result = $database->query($sql); $result = $result[0]; $product_name = $result[0]; $quantity_left = $result[1]; $price = $result[2]; if ($quantity <= $quantity_left) { /* Adding to cart */ $product = new Product($productId, $product_name, $price); $product->setQuantity($quantity); $bool = $account->getCart()->addToCart($product, (double) $quantity); if ($bool == TRUE) { echo '<script>window.location.href=\'?controller=pages&action=shop\';</script>'; } else { echo '<script>alert(\'Unknown error occurred\');</script>'; echo '<script>window.location.href=\'?controller=pages&action=shop\';</script>'; } } else { echo '<script>alert(\'Quantity not available\');</script>'; echo '<script>window.location.href=\'?controller=pages&action=shop\';</script>'; } } else { echo '<script>window.location.href=\'?controller=pages&action=login\';</script>'; } }
public function testQuantity() { $this->assertSame($this->entity, $this->entity->setQuantity(5)); $this->assertSame(5, $this->entity->getQuantity()); }