-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmini_cart.php
172 lines (147 loc) · 6.53 KB
/
mini_cart.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
/*
Module developed for the Open Source Content Management System WebsiteBaker (http://websitebaker.org)
Copyright (C) 2007 - 2017, Christoph Marti
LICENCE TERMS:
This module is free software. You can redistribute it and/or modify it
under the terms of the GNU General Public License - version 2 or later,
as published by the Free Software Foundation: http://www.gnu.org/licenses/gpl.html.
DISCLAIMER:
This module is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
// Include WB template parser and create template object
require_once(WB_PATH.'/include/phplib/template.inc');
$tpl = new Template(WB_PATH.'/modules/bakery/templates/mini_cart');
// Define how to deal with unknown {PLACEHOLDERS} (remove:=default, keep, comment)
$tpl->set_unknowns('keep');
// Define debug mode (0:=disabled (default), 1:=variable assignments, 2:=calls to get variable, 4:=debug internals)
$tpl->debug = 0;
// Look for language file
if (LANGUAGE_LOADED && !isset($MOD_BAKERY)) {
include(WB_PATH.'/modules/bakery/languages/EN.php');
if (file_exists(WB_PATH.'/modules/bakery/languages/'.LANGUAGE.'.php')) {
include(WB_PATH.'/modules/bakery/languages/'.LANGUAGE.'.php');
}
}
// Check order id
if (isset($_SESSION['bakery']['order_id']) && is_numeric($_SESSION['bakery']['order_id']) && $_SESSION['bakery']['order_id'] >= 0) {
$order_id = $_SESSION['bakery']['order_id'];
// Look for items in the db
$query_order = $database->query("SELECT item_id, attributes, quantity, price FROM ".TABLE_PREFIX."mod_bakery_order WHERE order_id = '$order_id'");
$num_orders = $query_order->numRows();
if ($num_orders > 0) {
// Get the section id - if existing - of the last visited Bakery section...
if (isset($_SESSION['bakery']['last_section_id']) && is_numeric($_SESSION['bakery']['last_section_id'])) {
$section_id = $_SESSION['bakery']['last_section_id'];
$clause = "WHERE ps.section_id = '$section_id'";
}
// ...else get the highest section id
else {
$clause = "WHERE ps.section_id != '0' ORDER BY ps.section_id ASC LIMIT 1";
}
// Get continue url
$query_continue_url = $database->query("SELECT p.link FROM ".TABLE_PREFIX."pages p INNER JOIN ".TABLE_PREFIX."mod_bakery_page_settings ps ON p.page_id = ps.page_id $clause");
if ($query_continue_url->numRows() > 0) {
$fetch_continue_url = $query_continue_url->fetchRow();
$continue_url = WB_URL.PAGES_DIRECTORY.stripslashes($fetch_continue_url['link']).PAGE_EXTENSION;
}
// Get the general settings
$query_general_settings = $database->query("SELECT shop_currency, dec_point, thousands_sep, tax_included FROM ".TABLE_PREFIX."mod_bakery_general_settings");
if ($query_general_settings->numRows() > 0) {
$general_settings = $query_general_settings->fetchRow();
$shop_currency = stripslashes($general_settings['shop_currency']);
$dec_point = stripslashes($general_settings['dec_point']);
$thousands_sep = stripslashes($general_settings['thousands_sep']);
$tax_included = stripslashes($general_settings['tax_included']);
}
// Get item_id, attributes, quantity and price from db order table
$i = 1;
while ($order = $query_order->fetchRow()) {
foreach ($order as $key => $value) {
$items[$i][$key] = $value;
}
// Initialize var and set default if item has no attributes
$attribute['operator'] = '';
$items[$i]['attribute_price'] = 0;
// Get item attribute price and operator (+/-)
if ($items[$i]['attributes'] != "none") {
$attribute_ids = explode(",", $items[$i]['attributes']);
foreach ($attribute_ids as $attribute_id) {
// Get attribute price and operator (+/-)
$query_attributes = $database->query("SELECT price, operator FROM ".TABLE_PREFIX."mod_bakery_item_attributes WHERE item_id = {$items[$i]['item_id']} AND attribute_id = $attribute_id");
$attribute = $query_attributes->fetchRow();
// Calculate the item attribute prices sum depending on the operator
if ($attribute['operator'] == "+") {
$items[$i]['attribute_price'] = $items[$i]['attribute_price'] + $attribute['price'];
} elseif ($attribute['operator'] == "-") {
$items[$i]['attribute_price'] = $items[$i]['attribute_price'] - $attribute['price'];
// If operator is '=' then override the item price by the attribute price
} elseif ($attribute['operator'] == "=") {
$items[$i]['price'] = $attribute['price'];
}
}
// Now calculate item price including all attribute prices
$items[$i]['price'] = $items[$i]['price'] + $items[$i]['attribute_price'];
}
// Increment counter
$i++;
}
// Calculate order total
$quantity_sum = 0;
$total = 0;
for ($i = 1; $i <= sizeof($items); $i++) {
$quantity_sum = $quantity_sum + $items[$i]['quantity'];
$subtotal = $items[$i]['quantity'] * $items[$i]['price'];
$total = $total + $subtotal;
}
$f_total = number_format($total, 2, $dec_point, $thousands_sep);
// Change MiniCart note regarding sales tax depending on general settings
if ($tax_included == 'included') {
$txt_excl_shipping_tax = $MOD_BAKERY['TXT_EXCL_SHIPPING'];
}
else {
// Calculate tax amount for shipping excluding tax (netto)
$txt_excl_shipping_tax = $MOD_BAKERY['TXT_EXCL_SHIPPING_TAX'];
}
// Show MiniCart summary using template file
$tpl->set_file('mini_cart_summary', 'summary.htm');
$tpl->set_var(array(
'WB_URL' => WB_URL,
'TXT_CART' => $MOD_BAKERY['TXT_CART'],
'CONTINUE_URL' => $continue_url,
'TXT_ORDER_ID' => $MOD_BAKERY['TXT_ORDER_ID'],
'ORDER_ID' => $order_id,
'TXT_ITEMS' => $MOD_BAKERY['TXT_ITEMS'],
'QUANTITY_SUM' => $quantity_sum,
'SHOP_CURRENCY' => $shop_currency,
'TOTAL' => $f_total,
'TXT_SUM' => $MOD_BAKERY['TXT_SUM'],
'TXT_EXCL_SHIPPING' => $txt_excl_shipping_tax,
'TXT_VIEW_CART' => $MOD_BAKERY['TXT_VIEW_CART']
));
$tpl->pparse('output', 'mini_cart_summary');
}
else {
// Show empty MiniCart using template file
$tpl->set_file('mini_cart_empty', 'empty.htm');
$tpl->set_var(array(
'WB_URL' => WB_URL,
'TXT_CART' => $MOD_BAKERY['TXT_CART'],
'ERR_CART_EMPTY' => $MOD_BAKERY['ERR_CART_EMPTY']
));
$tpl->pparse('output', 'mini_cart_empty');
}
}
else {
// Show empty MiniCart using template file
$tpl->set_file('mini_cart_empty', 'empty.htm');
$tpl->set_var(array(
'WB_URL' => WB_URL,
'TXT_CART' => $MOD_BAKERY['TXT_CART'],
'ERR_CART_EMPTY' => $MOD_BAKERY['ERR_CART_EMPTY']
));
$tpl->pparse('output', 'mini_cart_empty');
}