  |
16 | 16 | | function osC_Product($id) { |
| |
17 | 17 | | global $osC_Database, $osC_Services; |
| |
18 | 18 | | |
  |
19 | | - | $Qproduct = $osC_Database->query('select p.products_id as id, 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, pd.products_name as name, pd.products_description as description from :table_products p, :table_products_description pd where'); |
| |
20 | | - | $Qproduct->bindTable(':table_products', TABLE_PRODUCTS); |
| |
21 | | - | $Qproduct->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION); |
| |
| 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); |
|
22 | 23 | | |
  |
23 | | - | if (is_numeric($id) || ereg('[0-9]+[{[0-9]+}[0-9]+]*$', $id)) { |
| |
24 | | - | $Qproduct->appendQuery('p.products_id = :products_id'); |
| |
25 | | - | $Qproduct->bindInt(':products_id', tep_get_prid($id)); |
| |
26 | | - | } else { |
| |
27 | | - | $Qproduct->appendQuery('p.products_model = :products_model'); |
| |
28 | | - | $Qproduct->bindValue(':products_model', $id); |
| |
29 | | - | } |
| |
| 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 | + | } |
|
30 | 31 | | |
  |
31 | | - | $Qproduct->appendQuery('and p.products_status = 1 and p.products_id = pd.products_id and pd.language_id = :language_id'); |
| |
32 | | - | $Qproduct->bindInt(':language_id', $_SESSION['languages_id']); |
| |
33 | | - | $Qproduct->execute(); |
| |
| 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(); |
|
34 | 35 | | |
  |
35 | | - | $this->_data = $Qproduct->toArray(); |
| |
| 36 | + | $this->_data = $Qproduct->toArray(); |
|
36 | 37 | | |
  |
37 | | - | $Qcheck = $osC_Database->query('select products_attributes_id from :table_products_attributes patrib where products_id = :products_id limit 1'); |
| |
38 | | - | $Qcheck->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES); |
| |
39 | | - | $Qcheck->bindInt(':products_id', tep_get_prid($id)); |
| |
40 | | - | $Qcheck->execute(); |
| |
| 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(); |
|
41 | 42 | | |
  |
42 | | - | if ($Qcheck->numberOfRows() === 1) { |
| |
43 | | - | $this->_data['attributes'] = array(); |
| |
| 43 | + | if ($Qcheck->numberOfRows() === 1) { |
| |
| 44 | + | $this->_data['attributes'] = array(); |
|
44 | 45 | | |
  |
45 | | - | $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'); |
| |
46 | | - | $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES); |
| |
47 | | - | $Qattributes->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS); |
| |
48 | | - | $Qattributes->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES); |
| |
49 | | - | $Qattributes->bindInt(':products_id', tep_get_prid($id)); |
| |
50 | | - | $Qattributes->bindInt(':language_id', $_SESSION['languages_id']); |
| |
51 | | - | $Qattributes->bindInt(':language_id', $_SESSION['languages_id']); |
| |
52 | | - | $Qattributes->execute(); |
| |
| 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(); |
|
53 | 54 | | |
  |
54 | | - | while ($Qattributes->next()) { |
| |
55 | | - | $this->_data['attributes'][] = array('options_id' => $Qattributes->valueInt('options_id'), |
| |
56 | | - | 'options_name' => $Qattributes->value('products_options_name'), |
| |
57 | | - | 'options_values_id' => $Qattributes->valueInt('options_values_id'), |
| |
58 | | - | 'options_values_name' => $Qattributes->value('products_options_values_name'), |
| |
59 | | - | 'options_values_price' => $Qattributes->value('options_values_price'), |
| |
60 | | - | 'price_prefix' => $Qattributes->value('price_prefix')); |
| |
| 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 | + | } |
|
61 | 63 | | } |
  |
62 | | - | } |
|
63 | 64 | | |
  |
64 | | - | if ($osC_Services->isStarted('reviews')) { |
| |
65 | | - | $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'); |
| |
66 | | - | $Qavg->bindTable(':table_reviews', TABLE_REVIEWS); |
| |
67 | | - | $Qavg->bindInt(':products_id', $id); |
| |
68 | | - | $Qavg->bindInt(':languages_id', $_SESSION['languages_id']); |
| |
69 | | - | $Qavg->execute(); |
| |
| 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(); |
|
70 | 71 | | |
  |
71 | | - | $this->_data['reviews_average_rating'] = round($Qavg->value('rating')); |
| |
| 72 | + | $this->_data['reviews_average_rating'] = round($Qavg->value('rating')); |
| |
| 73 | + | } |
|
72 | 74 | | } |
| |
73 | 75 | | } |
| |
74 | 76 | | |
  |
| 77 | + | function isValid() { |
| |
| 78 | + | if (empty($this->_data)) { |
| |
| 79 | + | return false; |
| |
| 80 | + | } |
| |
| 81 | + | |
| |
| 82 | + | return true; |
| |
| 83 | + | } |
| |
| 84 | + | |
|
75 | 85 | | function getData($key) { |
| |
76 | 86 | | if (isset($this->_data[$key])) { |
| |
77 | 87 | | return $this->_data[$key]; |
| |
|
|
 |
… |
|
100 | 110 | | return $this->_data['model']; |
| |
101 | 111 | | } |
| |
102 | 112 | | |
  |
| 113 | + | function getKeyword() { |
| |
| 114 | + | return $this->_data['keyword']; |
| |
| 115 | + | } |
| |
| 116 | + | |
|
103 | 117 | | function getPrice() { |
| |
104 | 118 | | } |
| |
105 | 119 | | |
| |
|
|
 |
… |
|
170 | 184 | | function checkEntry($id) { |
| |
171 | 185 | | global $osC_Database; |
| |
172 | 186 | | |
  |
173 | | - | $Qcheck = $osC_Database->query('select products_id from :table_products where'); |
| |
| 187 | + | $Qcheck = $osC_Database->query('select p.products_id from :table_products p'); |
|
174 | 188 | | $Qcheck->bindTable(':table_products', TABLE_PRODUCTS); |
| |
175 | 189 | | |
| |
176 | 190 | | if (is_numeric($id) || ereg('[0-9]+[{[0-9]+}[0-9]+]*$', $id)) { |
  |
177 | | - | $Qcheck->appendQuery('products_id = :products_id'); |
| |
| 191 | + | $Qcheck->appendQuery('where p.products_id = :products_id'); |
|
178 | 192 | | $Qcheck->bindInt(':products_id', tep_get_prid($id)); |
| |
179 | 193 | | } else { |
  |
180 | | - | $Qcheck->appendQuery('products_model = :products_model'); |
| |
181 | | - | $Qcheck->bindValue(':products_model', $id); |
| |
| 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); |
|
182 | 197 | | } |
| |
183 | 198 | | |
  |
184 | | - | $Qcheck->appendQuery('and products_status = 1 limit 1'); |
| |
| 199 | + | $Qcheck->appendQuery('and p.products_status = 1 limit 1'); |
  |
185 | 200 | | $Qcheck->execute(); |
| |
186 | 201 | | |
| |
187 | 202 | | if ($Qcheck->numberOfRows() === 1) { |