-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
55 lines (48 loc) · 1.27 KB
/
functions.php
File metadata and controls
55 lines (48 loc) · 1.27 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
session_start();
require 'data.php';
require 'goods.php';
function verify_user($username,$userpassword,$data_array){
if(is_array($data_array)){
foreach ($data_array as $key => $value) {
if($username === $key && md5($userpassword) === $value){
return true;
}
}
}
return false;
}
function cartRecalc() {
$products = getProducts();
$items = $_SESSION['cart']['items'];
$sum = 0;
foreach($items as $key=>$value){
$sum +=$products[$key]['cost']*$value['count'];
}
$_SESSION['cart']['sum']=$sum;
}
//
$errors = [];
$products = getProducts();
if(!empty($_POST)){
if(isset($_POST['goods'])&& $_POST['goods']!=0){
$product = $_POST['goods'];
}else{
$errors['goods'] ='Выберите товар';
}
if(isset($_POST['count'])&&$_POST['count']!=0){
$count = $_POST['count'];
}else{
$errors['count'] = 'Введите количество товара';
}
if(empty($errors)){
$index = $product;
$product = $products[$index];
if(isset($_SESSION['cart']['items'][$index])){
$count += $_SESSION['cart']['items'][$index]['count'];
}
$_SESSION['cart']['items'][$index] = ['name'=> $product["name"],'count'=>$count];
}
}
//
?>