-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuypage.php
60 lines (51 loc) · 1.39 KB
/
buypage.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
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
56
57
58
59
60
<?php
session_start();
require 'vendor/autoload.php';
$client = new MongoDB\Client;
$ecommerce = $client->ecommerce;
$products = $ecommerce->products;
$cart = $ecommerce->cart;
$orders = $ecommerce->orders;
if (isset($_GET['customerid'])) {
$customer_id = $_GET['customerid'];
$userProducts = $cart->find([
"customer_id" => (int)$customer_id
]);
foreach($userProducts as $userProduct){
$product_id = $userProduct->product_id;
$quantity = $userProduct->quantity;
$id = $userProduct->id;
$currentdate = date('d-m-y');
$product_query = $products->findOne([
"product_id" => (int)$product_id
]);
$productname = $product_query->name;
$price = $product_query->price;
$grosstotal = $quantity * $price;
$lastDocument = $orders->findOne(
[],
[
'limit' => 1,
'sort' => ['id' => -1]
]
);
$lastInsertedId = $lastDocument->id;
if($lastInsertedId == null){
$lastInsertedId = 0;
}
$orders->insertOne([
"id" => $lastInsertedId + 1,
"customer_id" => (int)$customer_id,
"product_id" => (int)$id,
"quantity" => (int)$quantity,
"date" => $currentdate,
"price" => (int)$price
]);
// Delete from cart after order is completed
$cart->deleteMany([
"customer_id" => (int)$customer_id
]);
header("Location:order_success.php");
}
}
?>