-
Notifications
You must be signed in to change notification settings - Fork 12
/
e_sitelink.php
161 lines (120 loc) · 3.83 KB
/
e_sitelink.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
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2009 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* Sitelinks configuration module - gsitemap
*
* $Source: /cvs_backup/e107_0.8/e107_plugins/faqs/e_sitelink.php,v $
* $Revision$
* $Date$
* $Author$
*
*/
if (!defined('e107_INIT')) { exit; }
class vstore_sitelink // include plugin-folder in the name.
{
function config()
{
$links = array();
$links[] = array(
'name' => "Vstore Categories",
'function' => "storeCategories"
);
$links[] = array(
'name' => "Vstore Shopping Cart",
'function' => "storeCart"
);
return $links;
}
function storeCategories()
{
$sql = e107::getDb();
$tp = e107::getParser();
$sublinks = array();
//$sql->select("vstore_cat","*","cat_id != '' ORDER BY cat_order,cat_name");
$sql->gen('SELECT c.*, COUNT(i.item_id) AS items_count
FROM e107_vstore_cat c
LEFT JOIN e107_vstore_items i ON (c.cat_id = i.item_cat)
WHERE i.item_inventory != 0 AND i.item_active = 1
GROUP BY c.cat_id
ORDER BY cat_order');
while($row = $sql->fetch())
{
$sublinks[] = array(
'link_name' => $tp->toHTML($row['cat_name'], '', 'TITLE'),
'link_url' => e107::url('vstore','category', $row),
'link_description' => $tp->toHTML($row['cat_description'], '', 'DESCRIPTION'),
'link_button' => '',
'link_category' => '',
'link_order' => '',
'link_parent' => '',
'link_open' => '',
'link_class' => 0,
'link_badge' => $row['items_count']
);
}
return $sublinks;
}
function storeCart() // http://bootsnipp.com/snippets/33gmp
{
if (e_ADMIN_AREA) return;
$vst = e107::getSingleton('vstore',e_PLUGIN.'vstore/vstore.class.php');
$sc = e107::getScParser()->getScObject('vstore_shortcodes', 'vstore', false);
$data = $vst->getCartData();
$cust = $vst->getCustomerData();
$data = $vst->prepareCheckoutData($data, false, true);
$isBusiness = !empty($cust['vat_id']);
$country = isset($cust['country']) ? $cust['country'] : e107::pref('vstore', 'tax_business_country');
$isLocal = ($country === e107::pref('vstore', 'tax_business_country'));
$frm = e107::getForm();
$tp = e107::getParser();
$template = e107::getTemplate('vstore', 'vstore', 'navcart');
//TODO Move into class.
$text = '';
if (!e_AJAX_REQUEST)
{
$text = $tp->parseTemplate($template['start'], true, $sc);
}
if(empty($data))
{
$text .= $tp->parseTemplate($template['empty'], true, $sc);
if (!e_AJAX_REQUEST) {
$text .= $tp->parseTemplate($template['end'], true, $sc);
}
return $text;
}
$text .= $tp->parseTemplate($template['header'], true, $sc);
$total = 0;
$itemcount = 0;
foreach($data['items'] as $item)
{
$images = e107::unserialize($item['item_pic']);
$img = $tp->toImage($images[0]['path'],array('w'=>60));
$itemcount += $item['cart_qty'];
$sc->setVars(array(
'item' => array(
'pic' => $img,
'price' => ($isBusiness && !$isLocal ? $item['item_price_net'] : $item['item_price']),
'item_total' => ($isBusiness && !$isLocal ? $item['item_total_net'] : $item['item_total']),
'name' => '<span class="vstore-navcart-name">'.$item['item_name'].'</span>'.($item['itemvarstring'] ? '<br/>'.$item['itemvarstring'] : ''),
'quantity' => $item['cart_qty']
)
));
$text .= $tp->parseTemplate($template['item'], true, $sc);
//$total += $subtotal;
}
$sc->setVars(array(
'order_pay_amount' => ($isBusiness && !$isLocal ? $data['totals']['cart_subNet'] : $data['totals']['cart_subTotal']),
'item_count' => $itemcount,
));
$text .= $tp->parseTemplate($template['footer'], true, $sc);
if (!e_AJAX_REQUEST) {
$text .= $tp->parseTemplate($template['end'], true, $sc);
}
return $text;
}
}