Quick Search:

View

Revision:

Diff

Diff from 210 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) {
17       global $osC_Database;
18
19       $Qproduct = $osC_Database->query('select pd.products_name as name, pd.products_description as description, 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 from :table_products p, :table_products_description pd where p.products_id = :products_id and p.products_status = 1 and p.products_id = pd.products_id and pd.language_id = :language_id');
20       $Qproduct->bindTable(':table_products', TABLE_PRODUCTS);
21       $Qproduct->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
22       $Qproduct->bindInt(':products_id', tep_get_prid($id));
23       $Qproduct->bindInt(':language_id', $_SESSION['languages_id']);
24       $Qproduct->execute();
25
26       $this->_data = $Qproduct->toArray();
27       $this->_data['id'] = $id;
28
29       $Qcheck = $osC_Database->query('select products_attributes_id from :table_products_attributes patrib where products_id = :products_id limit 1');
30       $Qcheck->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
31       $Qcheck->bindInt(':products_id', tep_get_prid($id));
32       $Qcheck->execute();
33
34       if ($Qcheck->numberOfRows() === 1) {
35         $this->_data['attributes'] = array();
36
37         $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');
38         $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
39         $Qattributes->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS);
40         $Qattributes->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES);
41         $Qattributes->bindInt(':products_id', tep_get_prid($id));
42         $Qattributes->bindInt(':language_id', $_SESSION['languages_id']);
43         $Qattributes->bindInt(':language_id', $_SESSION['languages_id']);
44         $Qattributes->execute();
45
46         while ($Qattributes->next()) {
47           $this->_data['attributes'][] = array('options_id' => $Qattributes->valueInt('options_id'),
48                                                'options_name' => $Qattributes->value('products_options_name'),
49                                                'options_values_id' => $Qattributes->valueInt('options_values_id'),
50                                                'options_values_name' => $Qattributes->value('products_options_values_name'),
51                                                'options_values_price' => $Qattributes->value('options_values_price'),
52                                                'price_prefix' => $Qattributes->value('price_prefix'));
53         }
54       }
55     }
56
57     function getID() {
58       return $this->_data['id'];
59     }
60
61     function getTitle() {
62       return $this->_data['name'];
63     }
64
65     function getDescription() {
66       return $this->_data['description'];
67     }
68
69     function hasModel() {
70       return (isset($this->_data['model']) && !empty($this->_data['model']));
71     }
72
73     function getModel() {
74       return $this->_data['model'];
75     }
76
77     function getPrice() {
78     }
79
80     function getPriceFormated($with_special = false) {
81       global $osC_Services, $osC_Specials, $osC_Currencies;
82
83       if (($with_special === true) && $osC_Services->isStarted('specials') && ($new_price = $osC_Specials->getPrice($this->_data['id']))) {
84         $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>';
85       } else {
86         $price = $osC_Currencies->displayPrice($this->_data['price'], $this->_data['tax_class_id']);
87       }
88
89       return $price;
90     }
91
92     function hasImage() {
93       return (isset($this->_data['image']) && !empty($this->_data['image']));
94     }
95
96     function getImage() {
97       return $this->_data['image'];
98     }
99
100     function hasURL() {
101       return (isset($this->_data['url']) && !empty($this->_data['url']));
102     }
103
104     function getURL() {
105       return $this->_data['url'];
106     }
107
108     function getDateAvailable() {
109       return $this->_data['date_available'];
110     }
111
112     function getDateAdded() {
113       return $this->_data['date_added'];
114     }
115
116     function hasAttributes() {
117       return (isset($this->_data['attributes']) && !empty($this->_data['attributes']));
118     }
119
120     function &getAttributes() {
121       global $osC_Currencies;
122
123       $array = array();
124
125       foreach ($this->_data['attributes'] as $attribute) {
126         if (!isset($array[$attribute['options_id']])) {
127           $array[$attribute['options_id']] = array('options_name' => $attribute['options_name'],
128                                                    'values' => array(),
129                                                    'data' => array());
130         }
131
132         $array[$attribute['options_id']]['values'][] = array('options_values_id' => $attribute['options_values_id'],
133                                                              'options_values_name' => $attribute['options_values_name'],
134                                                              'options_values_price' => $attribute['options_values_price'],
135                                                              'price_prefix' => $attribute['price_prefix']);
136
137         $array[$attribute['options_id']]['data'][] = array('id' => $attribute['options_values_id'],
138                                                            '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']) . ')' : ''));
139       }
140
141       return $array;
142     }
143
144     function checkEntry($id) {
145       global $osC_Database;
146
147       $Qcheck = $osC_Database->query('select products_id from :table_products where products_id = :products_id and products_status = 1 limit 1');
148       $Qcheck->bindTable(':table_products', TABLE_PRODUCTS);
149       $Qcheck->bindInt(':products_id', tep_get_prid($id));
150       $Qcheck->execute();
151
152       if ($Qcheck->numberOfRows() === 1) {
153         return true;
154       }
155
156       return false;
157     }
158
159     function incrementCounter() {
160       global $osC_Database;
161
162       $Qupdate = $osC_Database->query('update :table_products_description set products_viewed = products_viewed+1 where products_id = :products_id and language_id = :language_id');
163       $Qupdate->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
164       $Qupdate->bindInt(':products_id', tep_get_prid($this->_data['id']));
165       $Qupdate->bindInt(':language_id', $_SESSION['languages_id']);
166       $Qupdate->execute();
167     }
168   }
169 ?>