forked from rocambille/mycart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
panier.php
30 lines (24 loc) · 870 Bytes
/
panier.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
session_start();
require __DIR__.'/models/Product.php';
$carts = $_SESSION['panier'];
function getArticle($id) {
return Product::read($id);
}
if(isset($_POST['deleteArticle'], $_POST['id']) && is_numeric($_POST['id'])) {
$index = array_search($_POST['id'], array_column($_SESSION['panier'], "id"));
if($index !== false) {
array_splice($_SESSION['panier'], $index, 1);
}
} else if(isset($_POST['editArticle'], $_POST['id'], $_POST['count']) && is_numeric($_POST['id']) && is_numeric($_POST['count']) && $_POST['count'] > 0) {
$index = array_search($_POST['id'], array_column($_SESSION['panier'], "id"));
if($index !== false) {
$numMax = getArticle($_POST['id'])['quantity'];
if($_POST['count'] > $numMax) {
$_POST['count'] = $numMax;
}
$_SESSION['panier'][$index]['num'] = $_POST['count'];
}
}
require __DIR__.'/views/users/panier.php';
?>