hpdl
|
219
|
1
|
<?php
|
|
2
|
/*
|
|
3
|
$Id: $
|
|
4
|
|
|
5
|
osCommerce, Open Source E-Commerce Solutions
|
|
6
|
http://www.oscommerce.com
|
|
7
|
|
hpdl
|
608
|
8
|
Copyright (c) 2006 osCommerce
|
hpdl
|
219
|
9
|
|
|
10
|
Released under the GNU General Public License
|
|
11
|
*/
|
|
12
|
|
|
13
|
class osC_Products {
|
|
14
|
var $_category,
|
|
15
|
$_recursive = true,
|
|
16
|
$_manufacturer,
|
|
17
|
$_sql_query,
|
|
18
|
$_sort_by,
|
|
19
|
$_sort_by_direction;
|
|
20
|
|
|
21
|
/* Class constructor */
|
|
22
|
|
|
23
|
function osC_Products($id = null) {
|
|
24
|
if (is_numeric($id)) {
|
|
25
|
$this->_category = $id;
|
|
26
|
}
|
|
27
|
}
|
|
28
|
|
|
29
|
/* Public methods */
|
|
30
|
|
|
31
|
function hasCategory() {
|
|
32
|
return isset($this->_category) && !empty($this->_category);
|
|
33
|
}
|
|
34
|
|
|
35
|
function isRecursive() {
|
|
36
|
return $this->_recursive;
|
|
37
|
}
|
|
38
|
|
|
39
|
function hasManufacturer() {
|
|
40
|
return isset($this->_manufacturer) && !empty($this->_manufacturer);
|
|
41
|
}
|
|
42
|
|
|
43
|
function setCategory($id, $recursive = true) {
|
|
44
|
$this->_category = $id;
|
|
45
|
|
|
46
|
if ($recursive === false) {
|
|
47
|
$this->_recursive = false;
|
|
48
|
}
|
|
49
|
}
|
|
50
|
|
|
51
|
function setManufacturer($id) {
|
|
52
|
$this->_manufacturer = $id;
|
|
53
|
}
|
|
54
|
|
|
55
|
function setSortBy($field, $direction = '+') {
|
|
56
|
switch ($field) {
|
|
57
|
case 'model':
|
hpdl
|
246
|
58
|
$this->_sort_by = 'pd.products_model';
|
hpdl
|
219
|
59
|
break;
|
|
60
|
case 'manufacturer':
|
|
61
|
$this->_sort_by = 'm.manufacturers_name';
|
|
62
|
break;
|
|
63
|
case 'quantity':
|
|
64
|
$this->_sort_by = 'p.products_quantity';
|
|
65
|
break;
|
|
66
|
case 'weight':
|
|
67
|
$this->_sort_by = 'p.products_weight';
|
|
68
|
break;
|
|
69
|
case 'price':
|
|
70
|
$this->_sort_by = 'final_price';
|
|
71
|
break;
|
|
72
|
}
|
|
73
|
|
|
74
|
$this->_sort_by_direction = ($direction == '-') ? '-' : '+';
|
|
75
|
}
|
|
76
|
|
|
77
|
function setSortByDirection($direction) {
|
|
78
|
$this->_sort_by_direction = ($direction == '-') ? '-' : '+';
|
|
79
|
}
|
|
80
|
|
|
81
|
function &execute() {
|
hpdl
|
608
|
82
|
global $osC_Database, $osC_Language, $osC_Image;
|
hpdl
|
219
|
83
|
|
hpdl
|
608
|
84
|
$Qlisting = $osC_Database->query('select distinct p.*, pd.*, m.*, if(s.status, s.specials_new_products_price, null) as specials_new_products_price, if(s.status, s.specials_new_products_price, p.products_price) as final_price, i.image from :table_products p left join :table_manufacturers m using(manufacturers_id) left join :table_specials s on (p.products_id = s.products_id) left join :table_products_images i on (p.products_id = i.products_id and i.default_flag = :default_flag), :table_products_description pd, :table_categories c, :table_products_to_categories p2c where p.products_status = 1 and p.products_id = pd.products_id and pd.language_id = :language_id and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id');
|
hpdl
|
219
|
85
|
$Qlisting->bindTable(':table_products', TABLE_PRODUCTS);
|
|
86
|
$Qlisting->bindTable(':table_manufacturers', TABLE_MANUFACTURERS);
|
hpdl
|
608
|
87
|
$Qlisting->bindTable(':table_specials', TABLE_SPECIALS);
|
|
88
|
$Qlisting->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
|
hpdl
|
219
|
89
|
$Qlisting->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
|
|
90
|
$Qlisting->bindTable(':table_categories', TABLE_CATEGORIES);
|
|
91
|
$Qlisting->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES);
|
hpdl
|
608
|
92
|
$Qlisting->bindInt(':default_flag', 1);
|
hpdl
|
383
|
93
|
$Qlisting->bindInt(':language_id', $osC_Language->getID());
|
hpdl
|
219
|
94
|
|
|
95
|
if ($this->hasCategory()) {
|
|
96
|
if ($this->isRecursive()) {
|
|
97
|
$subcategories_array = array();
|
|
98
|
tep_get_subcategories($subcategories_array, $this->_category);
|
|
99
|
|
|
100
|
$Qlisting->appendQuery('and p2c.products_id = p.products_id and p2c.products_id = pd.products_id and (p2c.categories_id = :categories_id');
|
|
101
|
$Qlisting->bindInt(':categories_id', $this->_category);
|
|
102
|
|
|
103
|
foreach ($subcategories_array as $sc) {
|
|
104
|
$Qlisting->appendQuery('or p2c.categories_id = :categories_id');
|
|
105
|
$Qlisting->bindInt(':categories_id', $sc);
|
|
106
|
}
|
|
107
|
|
|
108
|
$Qlisting->appendQuery(')');
|
|
109
|
} else {
|
|
110
|
$Qlisting->appendQuery('and p2c.products_id = p.products_id and p2c.products_id = pd.products_id and pd.language_id = :language_id and p2c.categories_id = :categories_id');
|
hpdl
|
383
|
111
|
$Qlisting->bindInt(':language_id', $osC_Language->getID());
|
hpdl
|
219
|
112
|
$Qlisting->bindInt(':categories_id', $this->_category);
|
|
113
|
}
|
|
114
|
}
|
|
115
|
|
|
116
|
if ($this->hasManufacturer()) {
|
|
117
|
$Qlisting->appendQuery('and m.manufacturers_id = :manufacturers_id');
|
|
118
|
$Qlisting->bindInt(':manufacturers_id', $this->_manufacturer);
|
|
119
|
}
|
|
120
|
|
|
121
|
$Qlisting->appendQuery('order by');
|
|
122
|
|
|
123
|
if (isset($this->_sort_by)) {
|
|
124
|
$Qlisting->appendQuery(':order_by :order_by_direction, pd.products_name');
|
|
125
|
$Qlisting->bindRaw(':order_by', $this->_sort_by);
|
|
126
|
$Qlisting->bindRaw(':order_by_direction', (($this->_sort_by_direction == '-') ? 'desc' : ''));
|
|
127
|
} else {
|
|
128
|
$Qlisting->appendQuery('pd.products_name :order_by_direction');
|
|
129
|
$Qlisting->bindRaw(':order_by_direction', (($this->_sort_by_direction == '-') ? 'desc' : ''));
|
|
130
|
}
|
|
131
|
|
|
132
|
$Qlisting->setBatchLimit((isset($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 1), MAX_DISPLAY_SEARCH_RESULTS);
|
|
133
|
$Qlisting->execute();
|
|
134
|
|
|
135
|
return $Qlisting;
|
|
136
|
}
|
|
137
|
}
|
|
138
|
?>
|