hpdl
|
210
|
1
|
<?php
|
|
2
|
/*
|
|
3
|
$Id: account.php 207 2005-09-26 01:29:31 +0200 (Mo, 26 Sep 2005) hpdl $
|
|
4
|
|
|
5
|
osCommerce, Open Source E-Commerce Solutions
|
|
6
|
http://www.oscommerce.com
|
|
7
|
|
|
8
|
Copyright (c) 2005 osCommerce
|
|
9
|
|
|
10
|
Released under the GNU General Public License
|
|
11
|
*/
|
|
12
|
|
|
13
|
class osC_Product {
|
|
14
|
var $_data = array();
|
|
15
|
|
|
16
|
function osC_Product($id) {
|
hpdl
|
555
|
17
|
global $osC_Database, $osC_Services, $osC_Language, $osC_Image;
|
hpdl
|
210
|
18
|
|
hpdl
|
246
|
19
|
if (!empty($id)) {
|
hpdl
|
555
|
20
|
$Qproduct = $osC_Database->query('select p.products_id as id, p.products_quantity as quantity, p.products_price as price, p.products_tax_class_id as tax_class_id, p.products_date_added as date_added, p.products_date_available as date_available, p.manufacturers_id, pd.products_name as name, pd.products_description as description, pd.products_model as model, pd.products_keyword as keyword, pd.products_tags as tags, pd.products_url as url, i.image from :table_products p left join :table_images i on (p.products_id = i.for_id and i.images_groups_id = :images_groups_id), :table_products_description pd where');
|
hpdl
|
246
|
21
|
$Qproduct->bindTable(':table_products', TABLE_PRODUCTS);
|
hpdl
|
555
|
22
|
$Qproduct->bindTable(':table_images', TABLE_IMAGES);
|
hpdl
|
246
|
23
|
$Qproduct->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
|
hpdl
|
245
|
24
|
|
hpdl
|
246
|
25
|
if (is_numeric($id) || ereg('[0-9]+[{[0-9]+}[0-9]+]*$', $id)) {
|
|
26
|
$Qproduct->appendQuery('p.products_id = :products_id');
|
|
27
|
$Qproduct->bindInt(':products_id', tep_get_prid($id));
|
|
28
|
} else {
|
|
29
|
$Qproduct->appendQuery('pd.products_keyword = :products_keyword');
|
|
30
|
$Qproduct->bindValue(':products_keyword', $id);
|
|
31
|
}
|
hpdl
|
245
|
32
|
|
hpdl
|
246
|
33
|
$Qproduct->appendQuery('and p.products_status = 1 and p.products_id = pd.products_id and pd.language_id = :language_id');
|
hpdl
|
555
|
34
|
$Qproduct->bindInt(':images_groups_id', $osC_Image->getID('default'));
|
hpdl
|
377
|
35
|
$Qproduct->bindInt(':language_id', $osC_Language->getID());
|
hpdl
|
246
|
36
|
$Qproduct->execute();
|
hpdl
|
210
|
37
|
|
hpdl
|
248
|
38
|
if ($Qproduct->numberOfRows() === 1) {
|
|
39
|
$this->_data = $Qproduct->toArray();
|
hpdl
|
210
|
40
|
|
hpdl
|
300
|
41
|
$Qcategory = $osC_Database->query('select categories_id from :table_products_to_categories where products_id = :products_id limit 1');
|
|
42
|
$Qcategory->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES);
|
|
43
|
$Qcategory->bindInt(':products_id', $this->_data['id']);
|
|
44
|
$Qcategory->execute();
|
|
45
|
|
|
46
|
$this->_data['category_id'] = $Qcategory->valueInt('categories_id');
|
|
47
|
|
hpdl
|
248
|
48
|
$Qcheck = $osC_Database->query('select products_attributes_id from :table_products_attributes patrib where products_id = :products_id limit 1');
|
|
49
|
$Qcheck->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
|
|
50
|
$Qcheck->bindInt(':products_id', $this->_data['id']);
|
|
51
|
$Qcheck->execute();
|
hpdl
|
210
|
52
|
|
hpdl
|
248
|
53
|
if ($Qcheck->numberOfRows() === 1) {
|
|
54
|
$this->_data['attributes'] = array();
|
hpdl
|
210
|
55
|
|
hpdl
|
248
|
56
|
$Qattributes = $osC_Database->query('select pa.*, po.*, pov.* from :table_products_attributes pa, :table_products_options po, :table_products_options_values pov where pa.products_id = :products_id and pa.options_id = po.products_options_id and po.language_id = :language_id and pa.options_values_id = pov.products_options_values_id and pov.language_id = :language_id order by po.products_options_name, pov.products_options_values_name');
|
|
57
|
$Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
|
|
58
|
$Qattributes->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS);
|
|
59
|
$Qattributes->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES);
|
|
60
|
$Qattributes->bindInt(':products_id', $this->_data['id']);
|
hpdl
|
377
|
61
|
$Qattributes->bindInt(':language_id', $osC_Language->getID());
|
|
62
|
$Qattributes->bindInt(':language_id', $osC_Language->getID());
|
hpdl
|
248
|
63
|
$Qattributes->execute();
|
hpdl
|
210
|
64
|
|
hpdl
|
248
|
65
|
while ($Qattributes->next()) {
|
|
66
|
$this->_data['attributes'][] = array('options_id' => $Qattributes->valueInt('options_id'),
|
|
67
|
'options_name' => $Qattributes->value('products_options_name'),
|
|
68
|
'options_values_id' => $Qattributes->valueInt('options_values_id'),
|
|
69
|
'options_values_name' => $Qattributes->value('products_options_values_name'),
|
|
70
|
'options_values_price' => $Qattributes->value('options_values_price'),
|
|
71
|
'price_prefix' => $Qattributes->value('price_prefix'));
|
|
72
|
}
|
hpdl
|
246
|
73
|
}
|
hpdl
|
213
|
74
|
|
hpdl
|
248
|
75
|
if ($osC_Services->isStarted('reviews')) {
|
|
76
|
$Qavg = $osC_Database->query('select avg(reviews_rating) as rating from :table_reviews where products_id = :products_id and languages_id = :languages_id and reviews_status = 1');
|
|
77
|
$Qavg->bindTable(':table_reviews', TABLE_REVIEWS);
|
|
78
|
$Qavg->bindInt(':products_id', $this->_data['id']);
|
hpdl
|
377
|
79
|
$Qavg->bindInt(':languages_id', $osC_Language->getID());
|
hpdl
|
248
|
80
|
$Qavg->execute();
|
hpdl
|
213
|
81
|
|
hpdl
|
248
|
82
|
$this->_data['reviews_average_rating'] = round($Qavg->value('rating'));
|
|
83
|
}
|
hpdl
|
246
|
84
|
}
|
hpdl
|
213
|
85
|
}
|
hpdl
|
210
|
86
|
}
|
|
87
|
|
hpdl
|
246
|
88
|
function isValid() {
|
|
89
|
if (empty($this->_data)) {
|
|
90
|
return false;
|
|
91
|
}
|
|
92
|
|
|
93
|
return true;
|
|
94
|
}
|
|
95
|
|
hpdl
|
213
|
96
|
function getData($key) {
|
|
97
|
if (isset($this->_data[$key])) {
|
|
98
|
return $this->_data[$key];
|
|
99
|
}
|
|
100
|
|
|
101
|
return false;
|
|
102
|
}
|
|
103
|
|
hpdl
|
210
|
104
|
function getID() {
|
|
105
|
return $this->_data['id'];
|
|
106
|
}
|
|
107
|
|
|
108
|
function getTitle() {
|
|
109
|
return $this->_data['name'];
|
|
110
|
}
|
|
111
|
|
|
112
|
function getDescription() {
|
|
113
|
return $this->_data['description'];
|
|
114
|
}
|
|
115
|
|
|
116
|
function hasModel() {
|
|
117
|
return (isset($this->_data['model']) && !empty($this->_data['model']));
|
|
118
|
}
|
|
119
|
|
|
120
|
function getModel() {
|
|
121
|
return $this->_data['model'];
|
|
122
|
}
|
|
123
|
|
hpdl
|
248
|
124
|
function hasKeyword() {
|
|
125
|
return (isset($this->_data['keyword']) && !empty($this->_data['keyword']));
|
|
126
|
}
|
|
127
|
|
hpdl
|
246
|
128
|
function getKeyword() {
|
|
129
|
return $this->_data['keyword'];
|
|
130
|
}
|
|
131
|
|
hpdl
|
248
|
132
|
function hasTags() {
|
|
133
|
return (isset($this->_data['tags']) && !empty($this->_data['tags']));
|
|
134
|
}
|
|
135
|
|
|
136
|
function getTags() {
|
|
137
|
return $this->_data['tags'];
|
|
138
|
}
|
|
139
|
|
hpdl
|
210
|
140
|
function getPrice() {
|
|
141
|
}
|
|
142
|
|
|
143
|
function getPriceFormated($with_special = false) {
|
|
144
|
global $osC_Services, $osC_Specials, $osC_Currencies;
|
|
145
|
|
|
146
|
if (($with_special === true) && $osC_Services->isStarted('specials') && ($new_price = $osC_Specials->getPrice($this->_data['id']))) {
|
|
147
|
$price = '<s>' . $osC_Currencies->displayPrice($this->_data['price'], $this->_data['tax_class_id']) . '</s> <span class="productSpecialPrice">' . $osC_Currencies->displayPrice($new_price, $this->_data['tax_class_id']) . '</span>';
|
|
148
|
} else {
|
|
149
|
$price = $osC_Currencies->displayPrice($this->_data['price'], $this->_data['tax_class_id']);
|
|
150
|
}
|
|
151
|
|
|
152
|
return $price;
|
|
153
|
}
|
|
154
|
|
hpdl
|
300
|
155
|
function getCategoryID() {
|
|
156
|
return $this->_data['category_id'];
|
|
157
|
}
|
|
158
|
|
hpdl
|
210
|
159
|
function hasImage() {
|
|
160
|
return (isset($this->_data['image']) && !empty($this->_data['image']));
|
|
161
|
}
|
|
162
|
|
|
163
|
function getImage() {
|
|
164
|
return $this->_data['image'];
|
|
165
|
}
|
|
166
|
|
|
167
|
function hasURL() {
|
|
168
|
return (isset($this->_data['url']) && !empty($this->_data['url']));
|
|
169
|
}
|
|
170
|
|
|
171
|
function getURL() {
|
|
172
|
return $this->_data['url'];
|
|
173
|
}
|
|
174
|
|
|
175
|
function getDateAvailable() {
|
|
176
|
return $this->_data['date_available'];
|
|
177
|
}
|
|
178
|
|
|
179
|
function getDateAdded() {
|
|
180
|
return $this->_data['date_added'];
|
|
181
|
}
|
|
182
|
|
|
183
|
function hasAttributes() {
|
|
184
|
return (isset($this->_data['attributes']) && !empty($this->_data['attributes']));
|
|
185
|
}
|
|
186
|
|
|
187
|
function &getAttributes() {
|
|
188
|
global $osC_Currencies;
|
|
189
|
|
|
190
|
$array = array();
|
|
191
|
|
|
192
|
foreach ($this->_data['attributes'] as $attribute) {
|
|
193
|
if (!isset($array[$attribute['options_id']])) {
|
|
194
|
$array[$attribute['options_id']] = array('options_name' => $attribute['options_name'],
|
|
195
|
'values' => array(),
|
|
196
|
'data' => array());
|
|
197
|
}
|
|
198
|
|
|
199
|
$array[$attribute['options_id']]['values'][] = array('options_values_id' => $attribute['options_values_id'],
|
|
200
|
'options_values_name' => $attribute['options_values_name'],
|
|
201
|
'options_values_price' => $attribute['options_values_price'],
|
|
202
|
'price_prefix' => $attribute['price_prefix']);
|
|
203
|
|
|
204
|
$array[$attribute['options_id']]['data'][] = array('id' => $attribute['options_values_id'],
|
|
205
|
'text' => $attribute['options_values_name'] . ($attribute['options_values_price'] != '0' ? ' (' . $attribute['price_prefix'] . $osC_Currencies->displayPrice($attribute['options_values_price'], $this->_data['tax_class_id']) . ')' : ''));
|
|
206
|
}
|
|
207
|
|
|
208
|
return $array;
|
|
209
|
}
|
|
210
|
|
|
211
|
function checkEntry($id) {
|
|
212
|
global $osC_Database;
|
|
213
|
|
hpdl
|
246
|
214
|
$Qcheck = $osC_Database->query('select p.products_id from :table_products p');
|
hpdl
|
210
|
215
|
$Qcheck->bindTable(':table_products', TABLE_PRODUCTS);
|
hpdl
|
245
|
216
|
|
|
217
|
if (is_numeric($id) || ereg('[0-9]+[{[0-9]+}[0-9]+]*$', $id)) {
|
hpdl
|
246
|
218
|
$Qcheck->appendQuery('where p.products_id = :products_id');
|
hpdl
|
245
|
219
|
$Qcheck->bindInt(':products_id', tep_get_prid($id));
|
|
220
|
} else {
|
hpdl
|
246
|
221
|
$Qcheck->appendQuery(', :table_products_description pd where pd.products_keyword = :products_keyword and pd.products_id = p.products_id');
|
|
222
|
$Qcheck->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
|
|
223
|
$Qcheck->bindValue(':products_keyword', $id);
|
hpdl
|
245
|
224
|
}
|
|
225
|
|
hpdl
|
246
|
226
|
$Qcheck->appendQuery('and p.products_status = 1 limit 1');
|
hpdl
|
210
|
227
|
$Qcheck->execute();
|
|
228
|
|
|
229
|
if ($Qcheck->numberOfRows() === 1) {
|
|
230
|
return true;
|
|
231
|
}
|
|
232
|
|
|
233
|
return false;
|
|
234
|
}
|
|
235
|
|
|
236
|
function incrementCounter() {
|
hpdl
|
377
|
237
|
global $osC_Database, $osC_Language;
|
hpdl
|
210
|
238
|
|
|
239
|
$Qupdate = $osC_Database->query('update :table_products_description set products_viewed = products_viewed+1 where products_id = :products_id and language_id = :language_id');
|
|
240
|
$Qupdate->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
|
|
241
|
$Qupdate->bindInt(':products_id', tep_get_prid($this->_data['id']));
|
hpdl
|
377
|
242
|
$Qupdate->bindInt(':language_id', $osC_Language->getID());
|
hpdl
|
210
|
243
|
$Qupdate->execute();
|
|
244
|
}
|
hpdl
|
211
|
245
|
|
|
246
|
function &getListingNew() {
|
hpdl
|
555
|
247
|
global $osC_Database, $osC_Language, $osC_Image;
|
hpdl
|
211
|
248
|
|
hpdl
|
555
|
249
|
$Qproducts = $osC_Database->query('select p.products_id, p.products_price, p.products_tax_class_id, p.products_date_added, pd.products_name, pd.products_keyword, m.manufacturers_name, i.image from :table_products p left join :table_manufacturers m on (p.manufacturers_id = m.manufacturers_id) left join :table_images i on (p.products_id = i.for_id and i.images_groups_id = :images_groups_id), :table_products_description pd where p.products_status = 1 and p.products_id = pd.products_id and pd.language_id = :language_id order by p.products_date_added desc, pd.products_name');
|
hpdl
|
211
|
250
|
$Qproducts->bindTable(':table_products', TABLE_PRODUCTS);
|
|
251
|
$Qproducts->bindTable(':table_manufacturers', TABLE_MANUFACTURERS);
|
hpdl
|
555
|
252
|
$Qproducts->bindTable(':table_images', TABLE_IMAGES);
|
hpdl
|
211
|
253
|
$Qproducts->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
|
hpdl
|
555
|
254
|
$Qproducts->bindInt(':images_groups_id', $osC_Image->getID('default'));
|
hpdl
|
377
|
255
|
$Qproducts->bindInt(':language_id', $osC_Language->getID());
|
hpdl
|
211
|
256
|
$Qproducts->setBatchLimit($_GET['page'], MAX_DISPLAY_PRODUCTS_NEW);
|
|
257
|
$Qproducts->execute();
|
|
258
|
|
|
259
|
return $Qproducts;
|
|
260
|
}
|
hpdl
|
210
|
261
|
}
|
|
262
|
?>
|