Quick Search:

View

Revision:

Diff

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