Quick Search:

View

Revision:

Diff

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