Quick Search:

View

Revision:

Diff

Diff from 613 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
608
17       global $osC_Database, $osC_Services, $osC_Language, $osC_Image;
hpdl
210
18
hpdl
246
19       if (!empty($id)) {
hpdl
613
20         $Qproduct = $osC_Database->query('select p.products_id as id, p.products_quantity as quantity, 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');
hpdl
246
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');
hpdl
383
33         $Qproduct->bindInt(':language_id', $osC_Language->getID());
hpdl
246
34         $Qproduct->execute();
hpdl
210
35
hpdl
248
36         if ($Qproduct->numberOfRows() === 1) {
37           $this->_data = $Qproduct->toArray();
hpdl
210
38
hpdl
613
39           $this->_data['images'] = array();
40
41           $Qimages = $osC_Database->query('select id, image, default_flag from :table_products_images where products_id = :products_id order by sort_order');
42           $Qimages->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
43           $Qimages->bindInt(':products_id', $this->_data['id']);
44           $Qimages->execute();
45
46           while ($Qimages->next()) {
47             $this->_data['images'][] = $Qimages->toArray();
48           }
49
hpdl
300
50           $Qcategory = $osC_Database->query('select categories_id from :table_products_to_categories where products_id = :products_id limit 1');
51           $Qcategory->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES);
52           $Qcategory->bindInt(':products_id', $this->_data['id']);
53           $Qcategory->execute();
54
55           $this->_data['category_id'] = $Qcategory->valueInt('categories_id');
56
hpdl
248
57           $Qcheck = $osC_Database->query('select products_attributes_id from :table_products_attributes patrib where products_id = :products_id limit 1');
58           $Qcheck->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
59           $Qcheck->bindInt(':products_id', $this->_data['id']);
60           $Qcheck->execute();
hpdl
210
61
hpdl
248
62           if ($Qcheck->numberOfRows() === 1) {
63             $this->_data['attributes'] = array();
hpdl
210
64
hpdl
248
65             $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');
66             $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
67             $Qattributes->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS);
68             $Qattributes->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES);
69             $Qattributes->bindInt(':products_id', $this->_data['id']);
hpdl
383
70             $Qattributes->bindInt(':language_id', $osC_Language->getID());
71             $Qattributes->bindInt(':language_id', $osC_Language->getID());
hpdl
248
72             $Qattributes->execute();
hpdl
210
73
hpdl
248
74             while ($Qattributes->next()) {
75               $this->_data['attributes'][] = array('options_id' => $Qattributes->valueInt('options_id'),
76                                                    'options_name' => $Qattributes->value('products_options_name'),
77                                                    'options_values_id' => $Qattributes->valueInt('options_values_id'),
78                                                    'options_values_name' => $Qattributes->value('products_options_values_name'),
79                                                    'options_values_price' => $Qattributes->value('options_values_price'),
80                                                    'price_prefix' => $Qattributes->value('price_prefix'));
81             }
hpdl
246
82           }
hpdl
213
83
hpdl
248
84           if ($osC_Services->isStarted('reviews')) {
85             $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');
86             $Qavg->bindTable(':table_reviews', TABLE_REVIEWS);
87             $Qavg->bindInt(':products_id', $this->_data['id']);
hpdl
383
88             $Qavg->bindInt(':languages_id', $osC_Language->getID());
hpdl
248
89             $Qavg->execute();
hpdl
213
90
hpdl
248
91             $this->_data['reviews_average_rating'] = round($Qavg->value('rating'));
92           }
hpdl
246
93         }
hpdl
213
94       }
hpdl
210
95     }
96
hpdl
246
97     function isValid() {
98       if (empty($this->_data)) {
99         return false;
100       }
101
102       return true;
103     }
104
hpdl
213
105     function getData($key) {
106       if (isset($this->_data[$key])) {
107         return $this->_data[$key];
108       }
109
110       return false;
111     }
112
hpdl
210
113     function getID() {
114       return $this->_data['id'];
115     }
116
117     function getTitle() {
118       return $this->_data['name'];
119     }
120
121     function getDescription() {
122       return $this->_data['description'];
123     }
124
125     function hasModel() {
126       return (isset($this->_data['model']) && !empty($this->_data['model']));
127     }
128
129     function getModel() {
130       return $this->_data['model'];
131     }
132
hpdl
248
133     function hasKeyword() {
134       return (isset($this->_data['keyword']) && !empty($this->_data['keyword']));
135     }
136
hpdl
246
137     function getKeyword() {
138       return $this->_data['keyword'];
139     }
140
hpdl
248
141     function hasTags() {
142       return (isset($this->_data['tags']) && !empty($this->_data['tags']));
143     }
144
145     function getTags() {
146       return $this->_data['tags'];
147     }
148
hpdl
210
149     function getPrice() {
150     }
151
152     function getPriceFormated($with_special = false) {
153       global $osC_Services, $osC_Specials, $osC_Currencies;
154
155       if (($with_special === true) && $osC_Services->isStarted('specials') && ($new_price = $osC_Specials->getPrice($this->_data['id']))) {
156         $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>';
157       } else {
158         $price = $osC_Currencies->displayPrice($this->_data['price'], $this->_data['tax_class_id']);
159       }
160
161       return $price;
162     }
163
hpdl
300
164     function getCategoryID() {
165       return $this->_data['category_id'];
166     }
167
hpdl
613
168     function getImages() {
169       return $this->_data['images'];
170     }
171
hpdl
210
172     function hasImage() {
hpdl
613
173       foreach ($this->_data['images'] as $image) {
174         if ($image['default_flag'] == '1') {
175           return true;
176         }
177       }
hpdl
210
178     }
179
180     function getImage() {
hpdl
613
181       foreach ($this->_data['images'] as $image) {
182         if ($image['default_flag'] == '1') {
183           return $image['image'];
184         }
185       }
hpdl
210
186     }
187
188     function hasURL() {
189       return (isset($this->_data['url']) && !empty($this->_data['url']));
190     }
191
192     function getURL() {
193       return $this->_data['url'];
194     }
195
196     function getDateAvailable() {
197       return $this->_data['date_available'];
198     }
199
200     function getDateAdded() {
201       return $this->_data['date_added'];
202     }
203
204     function hasAttributes() {
205       return (isset($this->_data['attributes']) && !empty($this->_data['attributes']));
206     }
207
208     function &getAttributes() {
209       global $osC_Currencies;
210
211       $array = array();
212
213       foreach ($this->_data['attributes'] as $attribute) {
214         if (!isset($array[$attribute['options_id']])) {
215           $array[$attribute['options_id']] = array('options_name' => $attribute['options_name'],
216                                                    'values' => array(),
217                                                    'data' => array());
218         }
219
220         $array[$attribute['options_id']]['values'][] = array('options_values_id' => $attribute['options_values_id'],
221                                                              'options_values_name' => $attribute['options_values_name'],
222                                                              'options_values_price' => $attribute['options_values_price'],
223                                                              'price_prefix' => $attribute['price_prefix']);
224
225         $array[$attribute['options_id']]['data'][] = array('id' => $attribute['options_values_id'],
226                                                            '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']) . ')' : ''));
227       }
228
229       return $array;
230     }
231
232     function checkEntry($id) {
233       global $osC_Database;
234
hpdl
246
235       $Qcheck = $osC_Database->query('select p.products_id from :table_products p');
hpdl
210
236       $Qcheck->bindTable(':table_products', TABLE_PRODUCTS);
hpdl
245
237
238       if (is_numeric($id) || ereg('[0-9]+[{[0-9]+}[0-9]+]*$', $id)) {
hpdl
246
239         $Qcheck->appendQuery('where p.products_id = :products_id');
hpdl
245
240         $Qcheck->bindInt(':products_id', tep_get_prid($id));
241       } else {
hpdl
246
242         $Qcheck->appendQuery(', :table_products_description pd where pd.products_keyword = :products_keyword and pd.products_id = p.products_id');
243         $Qcheck->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
244         $Qcheck->bindValue(':products_keyword', $id);
hpdl
245
245       }
246
hpdl
246
247       $Qcheck->appendQuery('and p.products_status = 1 limit 1');
hpdl
210
248       $Qcheck->execute();
249
250       if ($Qcheck->numberOfRows() === 1) {
251         return true;
252       }
253
254       return false;
255     }
256
257     function incrementCounter() {
hpdl
383
258       global $osC_Database, $osC_Language;
hpdl
210
259
260       $Qupdate = $osC_Database->query('update :table_products_description set products_viewed = products_viewed+1 where products_id = :products_id and language_id = :language_id');
261       $Qupdate->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
262       $Qupdate->bindInt(':products_id', tep_get_prid($this->_data['id']));
hpdl
383
263       $Qupdate->bindInt(':language_id', $osC_Language->getID());
hpdl
210
264       $Qupdate->execute();
265     }
hpdl
211
266
hpdl
613
267     function numberOfImages() {
268       return sizeof($this->_data['images']);
269     }
270
hpdl
211
271     function &getListingNew() {
hpdl
608
272       global $osC_Database, $osC_Language, $osC_Image;
hpdl
211
273
hpdl
608
274       $Qproducts = $osC_Database->query('select p.products_id, p.products_price, p.products_tax_class_id, p.products_date_added, pd.products_name, pd.products_keyword, m.manufacturers_name, i.image from :table_products p left join :table_manufacturers m on (p.manufacturers_id = m.manufacturers_id) left join :table_products_images i on (p.products_id = i.products_id and i.default_flag = :default_flag), :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');
hpdl
211
275       $Qproducts->bindTable(':table_products', TABLE_PRODUCTS);
276       $Qproducts->bindTable(':table_manufacturers', TABLE_MANUFACTURERS);
hpdl
608
277       $Qproducts->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
hpdl
211
278       $Qproducts->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
hpdl
608
279       $Qproducts->bindInt(':default_flag', 1);
hpdl
383
280       $Qproducts->bindInt(':language_id', $osC_Language->getID());
hpdl
211
281       $Qproducts->setBatchLimit($_GET['page'], MAX_DISPLAY_PRODUCTS_NEW);
282       $Qproducts->execute();
283
284       return $Qproducts;
285     }
hpdl
210
286   }
287 ?>