Quick Search:

View

Revision:

Diff

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