-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathosc_cart_retriever.php
92 lines (72 loc) · 2.24 KB
/
osc_cart_retriever.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
class OscCartRetriever {
public function retrieve() {
if(!isset($_COOKIE['osCsid'])) {
return NULL;
}
$mysqli = new mysqli($GLOBALS['OSC_CART_RETRIEVER_HOST'], $GLOBALS['OSC_CART_RETRIEVER_USER'], $GLOBALS['OSC_CART_RETRIEVER_PASS'], $GLOBALS['OSC_CART_RETRIEVER_DB']);
$sessSql = "SELECT * FROM Sessions WHERE sesskey = ?";
$cart = NULL;
if ($stmt = $mysqli->prepare($sessSql)) {
$stmt->bind_param("s", $_COOKIE['osCsid']);
$stmt->execute();
$stmt->bind_result($key, $expiry, $val);
/* fetch values */
while ($stmt->fetch()) {
preg_match('/cart\|(.*)language\|/', $val, $matches);
$cartSer = $matches[1];
$oscCart = unserialize($cartSer);
$cart = new oscCart($oscCart);
}
$stmt->fetch();
$stmt->close();
}
$mysqli->close();
return $cart;
}
}
class shoppingCart {
var $contents;
}
class oscCart {
public $items = array();
public $total = 0;
public $weight = 0;
public $totalItems = 0;
function __construct($oscCart) {
$this->total = $oscCart->total;
$this->weight = $oscCart->weight;
foreach($oscCart->contents as $k => $v) {
$id = $k;
$qty = $v['qty'];
$this->totalItems += $qty;
array_push($this->items, new oscCartItem($id, $qty));
}
}
}
class oscCartItem {
public $name = "";
public $quantity;
public $url = "";
public $id;
function __construct($_id, $_qty) {
$mysqli = new mysqli($GLOBALS['OSC_CART_RETRIEVER_HOST'], $GLOBALS['OSC_CART_RETRIEVER_USER'], $GLOBALS['OSC_CART_RETRIEVER_PASS'], $GLOBALS['OSC_CART_RETRIEVER_DB']);
preg_match('/(\d+)\{?/', $_id, $matches);
$productId = $matches[1];
if ($stmt = $mysqli->prepare("SELECT products_name FROM products_description WHERE products_id = ?")) {
$stmt->bind_param("s", $productId);
$stmt->execute();
$stmt->bind_result($productName);
$stmt->fetch();
$stmt->close();
} else {
echo $mysqli->error;
}
$mysqli->close();
$this->name = $productName;
$this->quantity = $_qty;
$this->id = $_id;
$this->url = "/product_info.php?products_id=$_id";
}
}
?>