Quick Search:

View

Revision:

Diff

Diff from 1674 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
hpdl
1674
8   Copyright (c) 2007 osCommerce
hpdl
219
9
hpdl
1497
10   This program is free software; you can redistribute it and/or modify
11   it under the terms of the GNU General Public License v2 (1991)
12   as published by the Free Software Foundation.
hpdl
219
13 */
14
15   class osC_Products {
16     var $_category,
17         $_recursive = true,
18         $_manufacturer,
19         $_sql_query,
20         $_sort_by,
21         $_sort_by_direction;
22
23 /* Class constructor */
24
hpdl
1674
25     function __construct($id = null) {
hpdl
219
26       if (is_numeric($id)) {
27         $this->_category = $id;
28       }
29     }
30
31 /* Public methods */
32
33     function hasCategory() {
34       return isset($this->_category) && !empty($this->_category);
35     }
36
37     function isRecursive() {
38       return $this->_recursive;
39     }
40
41     function hasManufacturer() {
42       return isset($this->_manufacturer) && !empty($this->_manufacturer);
43     }
44
45     function setCategory($id, $recursive = true) {
46       $this->_category = $id;
47
48       if ($recursive === false) {
49         $this->_recursive = false;
50       }
51     }
52
53     function setManufacturer($id) {
54       $this->_manufacturer = $id;
55     }
56
57     function setSortBy($field, $direction = '+') {
58       switch ($field) {
59         case 'model':
hpdl
1674
60           $this->_sort_by = 'p.products_model';
hpdl
219
61           break;
62         case 'manufacturer':
63           $this->_sort_by = 'm.manufacturers_name';
64           break;
65         case 'quantity':
66           $this->_sort_by = 'p.products_quantity';
67           break;
68         case 'weight':
69           $this->_sort_by = 'p.products_weight';
70           break;
71         case 'price':
72           $this->_sort_by = 'final_price';
73           break;
74       }
75
76       $this->_sort_by_direction = ($direction == '-') ? '-' : '+';
77     }
78
79     function setSortByDirection($direction) {
80       $this->_sort_by_direction = ($direction == '-') ? '-' : '+';
81     }
82
83     function &execute() {
hpdl
733
84       global $osC_Database, $osC_Language, $osC_CategoryTree, $osC_Image;
hpdl
219
85
hpdl
599
86       $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
87       $Qlisting->bindTable(':table_products', TABLE_PRODUCTS);
88       $Qlisting->bindTable(':table_manufacturers', TABLE_MANUFACTURERS);
hpdl
555
89       $Qlisting->bindTable(':table_specials', TABLE_SPECIALS);
hpdl
556
90       $Qlisting->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
hpdl
219
91       $Qlisting->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
92       $Qlisting->bindTable(':table_categories', TABLE_CATEGORIES);
93       $Qlisting->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES);
hpdl
583
94       $Qlisting->bindInt(':default_flag', 1);
hpdl
377
95       $Qlisting->bindInt(':language_id', $osC_Language->getID());
hpdl
219
96
97       if ($this->hasCategory()) {
98         if ($this->isRecursive()) {
hpdl
733
99           $subcategories_array = array($this->_category);
hpdl
219
100
hpdl
733
101           $Qlisting->appendQuery('and p2c.products_id = p.products_id and p2c.products_id = pd.products_id and p2c.categories_id in (:categories_id)');
102           $Qlisting->bindRaw(':categories_id', implode(',', $osC_CategoryTree->getChildren($this->_category, $subcategories_array)));
hpdl
219
103         } else {
104           $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
377
105           $Qlisting->bindInt(':language_id', $osC_Language->getID());
hpdl
219
106           $Qlisting->bindInt(':categories_id', $this->_category);
107         }
108       }
109
110       if ($this->hasManufacturer()) {
111         $Qlisting->appendQuery('and m.manufacturers_id = :manufacturers_id');
112         $Qlisting->bindInt(':manufacturers_id', $this->_manufacturer);
113       }
114
115       $Qlisting->appendQuery('order by');
116
117       if (isset($this->_sort_by)) {
118         $Qlisting->appendQuery(':order_by :order_by_direction, pd.products_name');
119         $Qlisting->bindRaw(':order_by', $this->_sort_by);
120         $Qlisting->bindRaw(':order_by_direction', (($this->_sort_by_direction == '-') ? 'desc' : ''));
121       } else {
122         $Qlisting->appendQuery('pd.products_name :order_by_direction');
123         $Qlisting->bindRaw(':order_by_direction', (($this->_sort_by_direction == '-') ? 'desc' : ''));
124       }
125
126       $Qlisting->setBatchLimit((isset($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 1), MAX_DISPLAY_SEARCH_RESULTS);
127       $Qlisting->execute();
128
129       return $Qlisting;
130     }
131   }
132 ?>