Quick Search:

View

Revision:

Diff

Diff from 230 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/branches/hpdl/oscommerce/includes/classes/products.php

Annotated File View

hpdl
219
1 <?php
2 /*
3   $Id: $
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_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':
58           $this->_sort_by = 'p.products_model';
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() {
82       global $osC_Database;
83
hpdl
230
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 from :table_products p left join :table_manufacturers m using(manufacturers_id) left join :table_specials s on (p.products_id = s.products_id), :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);
87       $Qlisting->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
88       $Qlisting->bindTable(':table_specials', TABLE_SPECIALS);
89       $Qlisting->bindTable(':table_categories', TABLE_CATEGORIES);
90       $Qlisting->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES);
91       $Qlisting->bindInt(':language_id', $_SESSION['languages_id']);
92
93       if ($this->hasCategory()) {
94         if ($this->isRecursive()) {
95           $subcategories_array = array();
96           tep_get_subcategories($subcategories_array, $this->_category);
97
98           $Qlisting->appendQuery('and p2c.products_id = p.products_id and p2c.products_id = pd.products_id and (p2c.categories_id = :categories_id');
99           $Qlisting->bindInt(':categories_id', $this->_category);
100
101           foreach ($subcategories_array as $sc) {
102             $Qlisting->appendQuery('or p2c.categories_id = :categories_id');
103             $Qlisting->bindInt(':categories_id', $sc);
104           }
105
106           $Qlisting->appendQuery(')');
107         } else {
108           $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');
109           $Qlisting->bindInt(':language_id', $_SESSION['languages_id']);
110           $Qlisting->bindInt(':categories_id', $this->_category);
111         }
112       }
113
114       if ($this->hasManufacturer()) {
115         $Qlisting->appendQuery('and m.manufacturers_id = :manufacturers_id');
116         $Qlisting->bindInt(':manufacturers_id', $this->_manufacturer);
117       }
118
119       $Qlisting->appendQuery('order by');
120
121       if (isset($this->_sort_by)) {
122         $Qlisting->appendQuery(':order_by :order_by_direction, pd.products_name');
123         $Qlisting->bindRaw(':order_by', $this->_sort_by);
124         $Qlisting->bindRaw(':order_by_direction', (($this->_sort_by_direction == '-') ? 'desc' : ''));
125       } else {
126         $Qlisting->appendQuery('pd.products_name :order_by_direction');
127         $Qlisting->bindRaw(':order_by_direction', (($this->_sort_by_direction == '-') ? 'desc' : ''));
128       }
129
130       $Qlisting->setBatchLimit((isset($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 1), MAX_DISPLAY_SEARCH_RESULTS);
131       $Qlisting->execute();
132
133       return $Qlisting;
134     }
135   }
136 ?>