Quick Search:

View

Revision:

Diff

Diff from 245 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/trunk/oscommerce/includes/classes/product.php

Annotated File View

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
213
17       global $osC_Database, $osC_Services;
hpdl
210
18
hpdl
245
19       $Qproduct = $osC_Database->query('select p.products_id as id, p.products_model as model, p.products_quantity as quantity, p.products_image as image, pd.products_url as url, 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 from :table_products p, :table_products_description pd where');
hpdl
210
20       $Qproduct->bindTable(':table_products', TABLE_PRODUCTS);
21       $Qproduct->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
hpdl
245
22
23       if (is_numeric($id) || ereg('[0-9]+[{[0-9]+}[0-9]+]*$', $id)) {
24         $Qproduct->appendQuery('p.products_id = :products_id');
25         $Qproduct->bindInt(':products_id', tep_get_prid($id));
26       } else {
27         $Qproduct->appendQuery('p.products_model = :products_model');
28         $Qproduct->bindValue(':products_model', $id);
29       }
30
31       $Qproduct->appendQuery('and p.products_status = 1 and p.products_id = pd.products_id and pd.language_id = :language_id');
hpdl
210
32       $Qproduct->bindInt(':language_id', $_SESSION['languages_id']);
33       $Qproduct->execute();
34
35       $this->_data = $Qproduct->toArray();
36
37       $Qcheck = $osC_Database->query('select products_attributes_id from :table_products_attributes patrib where products_id = :products_id limit 1');
38       $Qcheck->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
39       $Qcheck->bindInt(':products_id', tep_get_prid($id));
40       $Qcheck->execute();
41
42       if ($Qcheck->numberOfRows() === 1) {
43         $this->_data['attributes'] = array();
44
45         $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');
46         $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
47         $Qattributes->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS);
48         $Qattributes->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES);
49         $Qattributes->bindInt(':products_id', tep_get_prid($id));
50         $Qattributes->bindInt(':language_id', $_SESSION['languages_id']);
51         $Qattributes->bindInt(':language_id', $_SESSION['languages_id']);
52         $Qattributes->execute();
53
54         while ($Qattributes->next()) {
55           $this->_data['attributes'][] = array('options_id' => $Qattributes->valueInt('options_id'),
56                                                'options_name' => $Qattributes->value('products_options_name'),
57                                                'options_values_id' => $Qattributes->valueInt('options_values_id'),
58                                                'options_values_name' => $Qattributes->value('products_options_values_name'),
59                                                'options_values_price' => $Qattributes->value('options_values_price'),
60                                                'price_prefix' => $Qattributes->value('price_prefix'));
61         }
62       }
hpdl
213
63
64       if ($osC_Services->isStarted('reviews')) {
65         $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');
66         $Qavg->bindTable(':table_reviews', TABLE_REVIEWS);
67         $Qavg->bindInt(':products_id', $id);
68         $Qavg->bindInt(':languages_id', $_SESSION['languages_id']);
69         $Qavg->execute();
70
71         $this->_data['reviews_average_rating'] = round($Qavg->value('rating'));
72       }
hpdl
210
73     }
74
hpdl
213
75     function getData($key) {
76       if (isset($this->_data[$key])) {
77         return $this->_data[$key];
78       }
79
80       return false;
81     }
82
hpdl
210
83     function getID() {
84       return $this->_data['id'];
85     }
86
87     function getTitle() {
88       return $this->_data['name'];
89     }
90
91     function getDescription() {
92       return $this->_data['description'];
93     }
94
95     function hasModel() {
96       return (isset($this->_data['model']) && !empty($this->_data['model']));
97     }
98
99     function getModel() {
100       return $this->_data['model'];
101     }
102
103     function getPrice() {
104     }
105
106     function getPriceFormated($with_special = false) {
107       global $osC_Services, $osC_Specials, $osC_Currencies;
108
109       if (($with_special === true) && $osC_Services->isStarted('specials') && ($new_price = $osC_Specials->getPrice($this->_data['id']))) {
110         $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>';
111       } else {
112         $price = $osC_Currencies->displayPrice($this->_data['price'], $this->_data['tax_class_id']);
113       }
114
115       return $price;
116     }
117
118     function hasImage() {
119       return (isset($this->_data['image']) && !empty($this->_data['image']));
120     }
121
122     function getImage() {
123       return $this->_data['image'];
124     }
125
126     function hasURL() {
127       return (isset($this->_data['url']) && !empty($this->_data['url']));
128     }
129
130     function getURL() {
131       return $this->_data['url'];
132     }
133
134     function getDateAvailable() {
135       return $this->_data['date_available'];
136     }
137
138     function getDateAdded() {
139       return $this->_data['date_added'];
140     }
141
142     function hasAttributes() {
143       return (isset($this->_data['attributes']) && !empty($this->_data['attributes']));
144     }
145
146     function &getAttributes() {
147       global $osC_Currencies;
148
149       $array = array();
150
151       foreach ($this->_data['attributes'] as $attribute) {
152         if (!isset($array[$attribute['options_id']])) {
153           $array[$attribute['options_id']] = array('options_name' => $attribute['options_name'],
154                                                    'values' => array(),
155                                                    'data' => array());
156         }
157
158         $array[$attribute['options_id']]['values'][] = array('options_values_id' => $attribute['options_values_id'],
159                                                              'options_values_name' => $attribute['options_values_name'],
160                                                              'options_values_price' => $attribute['options_values_price'],
161                                                              'price_prefix' => $attribute['price_prefix']);
162
163         $array[$attribute['options_id']]['data'][] = array('id' => $attribute['options_values_id'],
164                                                            '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']) . ')' : ''));
165       }
166
167       return $array;
168     }
169
170     function checkEntry($id) {
171       global $osC_Database;
172
hpdl
245
173       $Qcheck = $osC_Database->query('select products_id from :table_products where');
hpdl
210
174       $Qcheck->bindTable(':table_products', TABLE_PRODUCTS);
hpdl
245
175
176       if (is_numeric($id) || ereg('[0-9]+[{[0-9]+}[0-9]+]*$', $id)) {
177         $Qcheck->appendQuery('products_id = :products_id');
178         $Qcheck->bindInt(':products_id', tep_get_prid($id));
179       } else {
180         $Qcheck->appendQuery('products_model = :products_model');
181         $Qcheck->bindValue(':products_model', $id);
182       }
183
184       $Qcheck->appendQuery('and products_status = 1 limit 1');
hpdl
210
185       $Qcheck->execute();
186
187       if ($Qcheck->numberOfRows() === 1) {
188         return true;
189       }
190
191       return false;
192     }
193
194     function incrementCounter() {
195       global $osC_Database;
196
197       $Qupdate = $osC_Database->query('update :table_products_description set products_viewed = products_viewed+1 where products_id = :products_id and language_id = :language_id');
198       $Qupdate->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
199       $Qupdate->bindInt(':products_id', tep_get_prid($this->_data['id']));
200       $Qupdate->bindInt(':language_id', $_SESSION['languages_id']);
201       $Qupdate->execute();
202     }
hpdl
211
203
204     function &getListingNew() {
205       global $osC_Database;
206
207       $Qproducts = $osC_Database->query('select p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, p.products_date_added, m.manufacturers_name from :table_products p left join :table_manufacturers m on (p.manufacturers_id = m.manufacturers_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');
208       $Qproducts->bindTable(':table_products', TABLE_PRODUCTS);
209       $Qproducts->bindTable(':table_manufacturers', TABLE_MANUFACTURERS);
210       $Qproducts->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
211       $Qproducts->bindInt(':language_id', $_SESSION['languages_id']);
212       $Qproducts->setBatchLimit($_GET['page'], MAX_DISPLAY_PRODUCTS_NEW);
213       $Qproducts->execute();
214
215       return $Qproducts;
216     }
hpdl
210
217   }
218 ?>