| Total Complexity | 104 |
| Total Lines | 759 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like ModelCatalogProduct often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ModelCatalogProduct, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 23 | class ModelCatalogProduct extends \Divine\Engine\Core\Model |
||
|
|
|||
| 24 | { |
||
| 25 | public function updateViewed($product_id) |
||
| 26 | { |
||
| 27 | $this->db->query(" |
||
| 28 | UPDATE product |
||
| 29 | SET viewed = (viewed + 1) |
||
| 30 | WHERE product_id = '" . (int)$product_id . "' |
||
| 31 | "); |
||
| 32 | } |
||
| 33 | |||
| 34 | public function getProduct($product_id) |
||
| 35 | { |
||
| 36 | $query = $this->db->query(" |
||
| 37 | SELECT DISTINCT *, |
||
| 38 | pd.name AS name, |
||
| 39 | p.image, |
||
| 40 | p.noindex AS noindex, |
||
| 41 | m.name AS manufacturer, |
||
| 42 | |||
| 43 | (SELECT price |
||
| 44 | FROM product_discount pd2 |
||
| 45 | WHERE pd2.product_id = p.product_id |
||
| 46 | AND pd2.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' |
||
| 47 | AND pd2.quantity = '1' |
||
| 48 | AND ((pd2.date_start = '2000-01-01' |
||
| 49 | OR pd2.date_start < NOW()) |
||
| 50 | AND (pd2.date_end = '2000-01-01' |
||
| 51 | OR pd2.date_end > NOW())) |
||
| 52 | ORDER BY pd2.priority ASC, pd2.price ASC |
||
| 53 | LIMIT 1) AS discount, |
||
| 54 | |||
| 55 | (SELECT price |
||
| 56 | FROM product_special ps |
||
| 57 | WHERE ps.product_id = p.product_id |
||
| 58 | AND ps.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' |
||
| 59 | AND ((ps.date_start = '2000-01-01' |
||
| 60 | OR ps.date_start < NOW()) |
||
| 61 | AND (ps.date_end = '2000-01-01' |
||
| 62 | OR ps.date_end > NOW())) |
||
| 63 | ORDER BY ps.priority ASC, ps.price ASC |
||
| 64 | LIMIT 1) AS special, |
||
| 65 | |||
| 66 | (SELECT points |
||
| 67 | FROM product_reward pr |
||
| 68 | WHERE pr.product_id = p.product_id |
||
| 69 | AND pr.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "') AS reward, |
||
| 70 | |||
| 71 | (SELECT ss.name |
||
| 72 | FROM stock_status ss |
||
| 73 | WHERE ss.stock_status_id = p.stock_status_id |
||
| 74 | AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "') AS stock_status, |
||
| 75 | |||
| 76 | (SELECT COUNT(*) AS total |
||
| 77 | FROM review r2 |
||
| 78 | WHERE r2.product_id = p.product_id |
||
| 79 | AND r2.status = '1' |
||
| 80 | GROUP BY r2.product_id) AS reviews, |
||
| 81 | p.sort_order |
||
| 82 | FROM product p |
||
| 83 | LEFT JOIN product_description pd ON (p.product_id = pd.product_id) |
||
| 84 | LEFT JOIN manufacturer m ON (p.manufacturer_id = m.manufacturer_id) |
||
| 85 | WHERE p.product_id = '" . (int)$product_id . "' |
||
| 86 | AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' |
||
| 87 | AND p.status = '1' |
||
| 88 | "); |
||
| 89 | |||
| 90 | if ($query->num_rows) { |
||
| 91 | return array( |
||
| 92 | 'product_id' => $query->row['product_id'], |
||
| 93 | 'name' => $query->row['name'], |
||
| 94 | 'description' => $query->row['description'], |
||
| 95 | 'description_mini' => $query->row['description_mini'], |
||
| 96 | 'meta_title' => $query->row['meta_title'], |
||
| 97 | 'noindex' => $query->row['noindex'], |
||
| 98 | 'meta_h1' => $query->row['meta_h1'], |
||
| 99 | 'meta_description' => $query->row['meta_description'], |
||
| 100 | 'tag' => $query->row['tag'], |
||
| 101 | 'model' => $query->row['model'], |
||
| 102 | 'sku' => $query->row['sku'], |
||
| 103 | 'upc' => $query->row['upc'], |
||
| 104 | 'ean' => $query->row['ean'], |
||
| 105 | 'jan' => $query->row['jan'], |
||
| 106 | 'isbn' => $query->row['isbn'], |
||
| 107 | 'mpn' => $query->row['mpn'], |
||
| 108 | 'location' => $query->row['location'], |
||
| 109 | 'quantity' => $query->row['quantity'], |
||
| 110 | 'stock_status' => $query->row['stock_status'], |
||
| 111 | 'image' => $query->row['image'], |
||
| 112 | 'manufacturer_id' => $query->row['manufacturer_id'], |
||
| 113 | 'manufacturer' => $query->row['manufacturer'], |
||
| 114 | 'price' => ($query->row['discount'] ? $query->row['discount'] : $query->row['price']), |
||
| 115 | 'special' => $query->row['special'], |
||
| 116 | 'reward' => $query->row['reward'], |
||
| 117 | 'points' => $query->row['points'], |
||
| 118 | 'width' => $query->row['width'], |
||
| 119 | 'height' => $query->row['height'], |
||
| 120 | 'subtract' => $query->row['subtract'], |
||
| 121 | 'reviews' => $query->row['reviews'] ? $query->row['reviews'] : 0, |
||
| 122 | 'minimum' => $query->row['minimum'], |
||
| 123 | 'sort_order' => $query->row['sort_order'], |
||
| 124 | 'status' => $query->row['status'], |
||
| 125 | 'date_added' => $query->row['date_added'], |
||
| 126 | 'date_modified' => $query->row['date_modified'], |
||
| 127 | 'viewed' => $query->row['viewed'] |
||
| 128 | ); |
||
| 129 | } else { |
||
| 130 | return false; |
||
| 131 | } |
||
| 132 | } |
||
| 133 | |||
| 134 | public function getproducttab($product_id) |
||
| 135 | { |
||
| 136 | $query = $this->db->query(" |
||
| 137 | SELECT * |
||
| 138 | FROM product_tab pt |
||
| 139 | LEFT JOIN product_tab_desc ptd ON(pt.product_tab_id = ptd.product_tab_id) |
||
| 140 | WHERE pt.product_id = " . $this->db->escape($product_id) . " |
||
| 141 | AND ptd.language_id = '" . $this->config->get('config_language_id') . "' |
||
| 142 | AND pt.status = 1 |
||
| 143 | ORDER BY sort_order ASC |
||
| 144 | "); |
||
| 145 | return $query->rows; |
||
| 146 | } |
||
| 147 | |||
| 148 | public function getProducts($data = array()) |
||
| 149 | { |
||
| 150 | $sql = " |
||
| 151 | SELECT p.product_id, |
||
| 152 | |||
| 153 | (SELECT price |
||
| 154 | FROM product_discount pd2 |
||
| 155 | WHERE pd2.product_id = p.product_id |
||
| 156 | AND pd2.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' |
||
| 157 | AND pd2.quantity = '1' |
||
| 158 | AND ((pd2.date_start = '2000-01-01' |
||
| 159 | OR pd2.date_start < NOW()) |
||
| 160 | AND (pd2.date_end = '2000-01-01' |
||
| 161 | OR pd2.date_end > NOW())) |
||
| 162 | ORDER BY pd2.priority ASC, pd2.price ASC |
||
| 163 | LIMIT 1) AS discount, |
||
| 164 | |||
| 165 | (SELECT price |
||
| 166 | FROM product_special ps |
||
| 167 | WHERE ps.product_id = p.product_id |
||
| 168 | AND ps.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' |
||
| 169 | AND ((ps.date_start = '2000-01-01' |
||
| 170 | OR ps.date_start < NOW()) |
||
| 171 | AND (ps.date_end = '2000-01-01' |
||
| 172 | OR ps.date_end > NOW())) |
||
| 173 | ORDER BY ps.priority ASC, ps.price ASC |
||
| 174 | LIMIT 1) AS special |
||
| 175 | "; |
||
| 176 | |||
| 177 | if (!empty($data['filter_category_id'])) { |
||
| 178 | if (!empty($data['filter_sub_category'])) { |
||
| 179 | $sql .= " FROM category_path cp LEFT JOIN product_to_category p2c ON (cp.category_id = p2c.category_id)"; |
||
| 180 | } else { |
||
| 181 | $sql .= " FROM product_to_category p2c"; |
||
| 182 | } |
||
| 183 | |||
| 184 | if (!empty($data['filter_filter'])) { |
||
| 185 | $sql .= " LEFT JOIN product_filter pf ON (p2c.product_id = pf.product_id) LEFT JOIN product p ON (pf.product_id = p.product_id)"; |
||
| 186 | } else { |
||
| 187 | $sql .= " LEFT JOIN product p ON (p2c.product_id = p.product_id)"; |
||
| 188 | } |
||
| 189 | } else { |
||
| 190 | $sql .= " FROM product p"; |
||
| 191 | } |
||
| 192 | |||
| 193 | $sql .= " |
||
| 194 | LEFT JOIN product_description pd ON (p.product_id = pd.product_id) |
||
| 195 | WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' |
||
| 196 | AND p.status = '1' |
||
| 197 | "; |
||
| 198 | |||
| 199 | if (!empty($data['filter_category_id'])) { |
||
| 200 | if (!empty($data['filter_sub_category'])) { |
||
| 201 | $sql .= " AND cp.path_id = '" . (int)$data['filter_category_id'] . "'"; |
||
| 202 | } else { |
||
| 203 | $sql .= " AND p2c.category_id = '" . (int)$data['filter_category_id'] . "'"; |
||
| 204 | } |
||
| 205 | |||
| 206 | if (!empty($data['filter_filter'])) { |
||
| 207 | $implode = array(); |
||
| 208 | |||
| 209 | $filters = explode(',', $data['filter_filter']); |
||
| 210 | |||
| 211 | foreach ($filters as $filter_id) { |
||
| 212 | $implode[] = (int)$filter_id; |
||
| 213 | } |
||
| 214 | |||
| 215 | $sql .= " AND pf.filter_id IN (" . implode(',', $implode) . ")"; |
||
| 216 | } |
||
| 217 | } |
||
| 218 | |||
| 219 | if (!empty($data['filter_name']) || !empty($data['filter_tag'])) { |
||
| 220 | $sql .= " AND ("; |
||
| 221 | |||
| 222 | if (!empty($data['filter_name'])) { |
||
| 223 | $implode = array(); |
||
| 224 | |||
| 225 | $words = explode(' ', trim(preg_replace('/\s+/', ' ', $data['filter_name']))); |
||
| 226 | |||
| 227 | foreach ($words as $word) { |
||
| 228 | $implode[] = "pd.name LIKE '%" . $this->db->escape($word) . "%'"; |
||
| 229 | } |
||
| 230 | |||
| 231 | if ($implode) { |
||
| 232 | $sql .= " " . implode(" AND ", $implode) . ""; |
||
| 233 | } |
||
| 234 | |||
| 235 | if (!empty($data['filter_description'])) { |
||
| 236 | $sql .= " OR pd.description LIKE '%" . $this->db->escape($data['filter_name']) . "%'"; |
||
| 237 | } |
||
| 238 | } |
||
| 239 | |||
| 240 | if (!empty($data['filter_name']) && !empty($data['filter_tag'])) { |
||
| 241 | $sql .= " OR "; |
||
| 242 | } |
||
| 243 | |||
| 244 | if (!empty($data['filter_tag'])) { |
||
| 245 | $implode = array(); |
||
| 246 | |||
| 247 | $words = explode(' ', trim(preg_replace('/\s+/', ' ', $data['filter_tag']))); |
||
| 248 | |||
| 249 | foreach ($words as $word) { |
||
| 250 | $implode[] = "pd.tag LIKE '%" . $this->db->escape($word) . "%'"; |
||
| 251 | } |
||
| 252 | |||
| 253 | if ($implode) { |
||
| 254 | $sql .= " " . implode(" AND ", $implode) . ""; |
||
| 255 | } |
||
| 256 | } |
||
| 257 | |||
| 258 | if (!empty($data['filter_name'])) { |
||
| 259 | $sql .= " OR LCASE(p.model) = '" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_name'])) . "'"; |
||
| 260 | $sql .= " OR LCASE(p.sku) = '" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_name'])) . "'"; |
||
| 261 | $sql .= " OR LCASE(p.upc) = '" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_name'])) . "'"; |
||
| 262 | $sql .= " OR LCASE(p.ean) = '" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_name'])) . "'"; |
||
| 263 | $sql .= " OR LCASE(p.jan) = '" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_name'])) . "'"; |
||
| 264 | $sql .= " OR LCASE(p.isbn) = '" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_name'])) . "'"; |
||
| 265 | $sql .= " OR LCASE(p.mpn) = '" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_name'])) . "'"; |
||
| 266 | } |
||
| 267 | |||
| 268 | $sql .= ")"; |
||
| 269 | } |
||
| 270 | |||
| 271 | if (!empty($data['filter_manufacturer_id'])) { |
||
| 272 | $sql .= " AND p.manufacturer_id = '" . (int)$data['filter_manufacturer_id'] . "'"; |
||
| 273 | } |
||
| 274 | |||
| 275 | $sql .= " GROUP BY p.product_id"; |
||
| 276 | |||
| 277 | $sort_data = array( |
||
| 278 | 'pd.name', |
||
| 279 | 'p.model', |
||
| 280 | 'p.quantity', |
||
| 281 | 'p.price', |
||
| 282 | 'p.sort_order', |
||
| 283 | 'p.date_added' |
||
| 284 | ); |
||
| 285 | |||
| 286 | if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { |
||
| 287 | if ($data['sort'] == 'pd.name' || $data['sort'] == 'p.model') { |
||
| 288 | $sql .= " ORDER BY LCASE(" . $data['sort'] . ")"; |
||
| 289 | } elseif ($data['sort'] == 'p.price') { |
||
| 290 | $sql .= " ORDER BY (CASE WHEN special IS NOT NULL THEN special WHEN discount IS NOT NULL THEN discount ELSE p.price END)"; |
||
| 291 | } else { |
||
| 292 | $sql .= " ORDER BY " . $data['sort']; |
||
| 293 | } |
||
| 294 | } else { |
||
| 295 | $sql .= " ORDER BY p.sort_order"; |
||
| 296 | } |
||
| 297 | |||
| 298 | if (isset($data['order']) && ($data['order'] == 'DESC')) { |
||
| 299 | $sql .= " DESC, LCASE(pd.name) DESC"; |
||
| 300 | } else { |
||
| 301 | $sql .= " ASC, LCASE(pd.name) ASC"; |
||
| 302 | } |
||
| 303 | |||
| 304 | if (isset($data['start']) || isset($data['limit'])) { |
||
| 305 | if ($data['start'] < 0) { |
||
| 306 | $data['start'] = 0; |
||
| 307 | } |
||
| 308 | |||
| 309 | if ($data['limit'] > 100 && $data['limit'] > $this->config->get('config_product_limit')) { // fix Buslikdrev |
||
| 310 | $data['limit'] = 100; |
||
| 311 | } |
||
| 312 | |||
| 313 | if ($data['limit'] < 1) { |
||
| 314 | $data['limit'] = 20; |
||
| 315 | } |
||
| 316 | |||
| 317 | $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; |
||
| 318 | } |
||
| 319 | |||
| 320 | $product_data = array(); |
||
| 321 | |||
| 322 | $query = $this->db->query($sql); |
||
| 323 | |||
| 324 | foreach ($query->rows as $result) { |
||
| 325 | $product_data[$result['product_id']] = $this->getProduct($result['product_id']); |
||
| 326 | } |
||
| 327 | |||
| 328 | return $product_data; |
||
| 329 | } |
||
| 330 | |||
| 331 | public function getProductSticker($product_id) |
||
| 332 | { |
||
| 333 | $product_sticker_data = array(); |
||
| 334 | |||
| 335 | $query = $this->db->query(" |
||
| 336 | SELECT * |
||
| 337 | FROM product_to_sticker |
||
| 338 | WHERE product_id = '" . (int)$product_id . "' |
||
| 339 | "); |
||
| 340 | |||
| 341 | foreach ($query->rows as $result) { |
||
| 342 | $product_sticker_data[] = $result['sticker_id']; |
||
| 343 | } |
||
| 344 | |||
| 345 | return $product_sticker_data; |
||
| 346 | } |
||
| 347 | |||
| 348 | public function getProductBenefitsbyProductId($product_id) |
||
| 349 | { |
||
| 350 | $query = $this->db->query(" |
||
| 351 | SELECT * |
||
| 352 | FROM product_to_benefit p2b |
||
| 353 | LEFT JOIN benefit b ON (p2b.benefit_id = b.benefit_id) |
||
| 354 | LEFT JOIN benefit_description bd ON (p2b.benefit_id = bd.benefit_id) |
||
| 355 | WHERE product_id = '" . (int)$product_id . "' |
||
| 356 | AND bd.language_id = '" . (int)$this->config->get('config_language_id') . "' |
||
| 357 | "); |
||
| 358 | |||
| 359 | return $query->rows; |
||
| 360 | } |
||
| 361 | |||
| 362 | public function getProductStickerbyProductId($product_id) |
||
| 363 | { |
||
| 364 | $query = $this->db->query(" |
||
| 365 | SELECT * |
||
| 366 | FROM product_to_sticker p2s |
||
| 367 | LEFT JOIN sticker ps ON (p2s.sticker_id = ps.sticker_id) |
||
| 368 | WHERE product_id = '" . (int)$product_id . "' |
||
| 369 | "); |
||
| 370 | |||
| 371 | return $query->rows; |
||
| 372 | } |
||
| 373 | |||
| 374 | public function getProductSpecials($data = array()) |
||
| 375 | { |
||
| 376 | $sql = " |
||
| 377 | SELECT DISTINCT ps.product_id |
||
| 378 | FROM product_special ps |
||
| 379 | LEFT JOIN product p ON (ps.product_id = p.product_id) |
||
| 380 | LEFT JOIN product_description pd ON (p.product_id = pd.product_id) |
||
| 381 | WHERE p.status = '1' |
||
| 382 | AND ps.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' |
||
| 383 | AND ((ps.date_start = '2000-01-01' OR ps.date_start < NOW()) |
||
| 384 | AND (ps.date_end = '2000-01-01' OR ps.date_end > NOW())) |
||
| 385 | GROUP BY ps.product_id |
||
| 386 | "; |
||
| 387 | |||
| 388 | $sort_data = array( |
||
| 389 | 'pd.name', |
||
| 390 | 'p.model', |
||
| 391 | 'ps.price', |
||
| 392 | 'p.sort_order' |
||
| 393 | ); |
||
| 394 | |||
| 395 | if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { |
||
| 396 | if ($data['sort'] == 'pd.name' || $data['sort'] == 'p.model') { |
||
| 397 | $sql .= " ORDER BY LCASE(" . $data['sort'] . ")"; |
||
| 398 | } else { |
||
| 399 | $sql .= " ORDER BY " . $data['sort']; |
||
| 400 | } |
||
| 401 | } else { |
||
| 402 | $sql .= " ORDER BY p.sort_order"; |
||
| 403 | } |
||
| 404 | |||
| 405 | if (isset($data['order']) && ($data['order'] == 'DESC')) { |
||
| 406 | $sql .= " DESC, LCASE(pd.name) DESC"; |
||
| 407 | } else { |
||
| 408 | $sql .= " ASC, LCASE(pd.name) ASC"; |
||
| 409 | } |
||
| 410 | |||
| 411 | if (isset($data['start']) || isset($data['limit'])) { |
||
| 412 | if ($data['start'] < 0) { |
||
| 413 | $data['start'] = 0; |
||
| 414 | } |
||
| 415 | |||
| 416 | if ($data['limit'] > 100 && $data['limit'] > $this->config->get('config_product_limit')) { // fix Buslikdrev |
||
| 417 | $data['limit'] = 100; |
||
| 418 | } |
||
| 419 | |||
| 420 | if ($data['limit'] < 1) { |
||
| 421 | $data['limit'] = 20; |
||
| 422 | } |
||
| 423 | |||
| 424 | $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; |
||
| 425 | } |
||
| 426 | |||
| 427 | $product_data = array(); |
||
| 428 | |||
| 429 | $query = $this->db->query($sql); |
||
| 430 | |||
| 431 | foreach ($query->rows as $result) { |
||
| 432 | $product_data[$result['product_id']] = $this->getProduct($result['product_id']); |
||
| 433 | } |
||
| 434 | |||
| 435 | return $product_data; |
||
| 436 | } |
||
| 437 | |||
| 438 | public function getLatestProducts($limit) |
||
| 439 | { |
||
| 440 | $product_data = $this->cache->get('product.latest.' . (int)$this->config->get('config_language_id') . '.0.' . $this->config->get('config_customer_group_id') . '.' . (int)$limit); |
||
| 441 | |||
| 442 | if (!$product_data) { |
||
| 443 | $query = $this->db->query(" |
||
| 444 | SELECT p.product_id FROM product p |
||
| 445 | WHERE p.status = '1' |
||
| 446 | ORDER BY p.date_added DESC |
||
| 447 | LIMIT |
||
| 448 | " . (int)$limit); |
||
| 449 | |||
| 450 | foreach ($query->rows as $result) { |
||
| 451 | $product_data[$result['product_id']] = $this->getProduct($result['product_id']); |
||
| 452 | } |
||
| 453 | |||
| 454 | $this->cache->set( |
||
| 455 | 'product.latest.' . (int)$this->config->get('config_language_id') . '.0.' . $this->config->get('config_customer_group_id') . '.' . (int)$limit, |
||
| 456 | $product_data |
||
| 457 | ); |
||
| 458 | } |
||
| 459 | |||
| 460 | return $product_data; |
||
| 461 | } |
||
| 462 | |||
| 463 | public function getPopularProducts($limit) |
||
| 464 | { |
||
| 465 | $product_data = $this->cache->get('product.popular.' . (int)$this->config->get('config_language_id') . '.0.' . $this->config->get('config_customer_group_id') . '.' . (int)$limit); |
||
| 466 | |||
| 467 | if (!$product_data) { |
||
| 468 | $query = $this->db->query(" |
||
| 469 | SELECT p.product_id FROM product p |
||
| 470 | WHERE p.status = '1' |
||
| 471 | ORDER BY p.viewed DESC, p.date_added DESC |
||
| 472 | LIMIT |
||
| 473 | " . (int)$limit); |
||
| 474 | |||
| 475 | foreach ($query->rows as $result) { |
||
| 476 | $product_data[$result['product_id']] = $this->getProduct($result['product_id']); |
||
| 477 | } |
||
| 478 | |||
| 479 | $this->cache->set( |
||
| 480 | 'product.popular.' . (int)$this->config->get('config_language_id') . '.0.' . $this->config->get('config_customer_group_id') . '.' . (int)$limit, |
||
| 481 | $product_data |
||
| 482 | ); |
||
| 483 | } |
||
| 484 | |||
| 485 | return $product_data; |
||
| 486 | } |
||
| 487 | |||
| 488 | public function getBestSellerProducts($limit) |
||
| 489 | { |
||
| 490 | $product_data = $this->cache->get('product.bestseller.' . (int)$this->config->get('config_language_id') . '.0.' . $this->config->get('config_customer_group_id') . '.' . (int)$limit); |
||
| 491 | |||
| 492 | if (!$product_data) { |
||
| 493 | $product_data = array(); |
||
| 494 | |||
| 495 | $query = $this->db->query(" |
||
| 496 | SELECT op.product_id, SUM(op.quantity) AS total |
||
| 497 | FROM order_product op |
||
| 498 | LEFT JOIN `order` o ON (op.order_id = o.order_id) |
||
| 499 | LEFT JOIN `product` p ON (op.product_id = p.product_id) |
||
| 500 | WHERE o.order_status_id > '0' |
||
| 501 | AND p.status = '1' |
||
| 502 | GROUP BY op.product_id |
||
| 503 | ORDER BY total DESC |
||
| 504 | LIMIT |
||
| 505 | " . (int)$limit); |
||
| 506 | |||
| 507 | foreach ($query->rows as $result) { |
||
| 508 | $product_data[$result['product_id']] = $this->getProduct($result['product_id']); |
||
| 509 | } |
||
| 510 | |||
| 511 | $this->cache->set( |
||
| 512 | 'product.bestseller.' . (int)$this->config->get('config_language_id') . '.0.' . $this->config->get('config_customer_group_id') . '.' . (int)$limit, |
||
| 513 | $product_data |
||
| 514 | ); |
||
| 515 | } |
||
| 516 | |||
| 517 | return $product_data; |
||
| 518 | } |
||
| 519 | |||
| 520 | public function getProductAttributes($product_id) |
||
| 521 | { |
||
| 522 | $product_attribute_group_data = array(); |
||
| 523 | |||
| 524 | $product_attribute_group_query = $this->db->query("SELECT ag.attribute_group_id, agd.name FROM product_attribute pa LEFT JOIN attribute a ON (pa.attribute_id = a.attribute_id) LEFT JOIN attribute_group ag ON (a.attribute_group_id = ag.attribute_group_id) LEFT JOIN attribute_group_description agd ON (ag.attribute_group_id = agd.attribute_group_id) WHERE pa.product_id = '" . (int)$product_id . "' AND agd.language_id = '" . (int)$this->config->get('config_language_id') . "' GROUP BY ag.attribute_group_id ORDER BY ag.sort_order, agd.name"); |
||
| 525 | |||
| 526 | foreach ($product_attribute_group_query->rows as $product_attribute_group) { |
||
| 527 | $product_attribute_data = array(); |
||
| 528 | |||
| 529 | $product_attribute_query = $this->db->query("SELECT a.attribute_id, ad.name, pa.text FROM product_attribute pa LEFT JOIN attribute a ON (pa.attribute_id = a.attribute_id) LEFT JOIN attribute_description ad ON (a.attribute_id = ad.attribute_id) WHERE pa.product_id = '" . (int)$product_id . "' AND a.attribute_group_id = '" . (int)$product_attribute_group['attribute_group_id'] . "' AND ad.language_id = '" . (int)$this->config->get('config_language_id') . "' AND pa.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY a.sort_order, ad.name"); |
||
| 530 | |||
| 531 | foreach ($product_attribute_query->rows as $product_attribute) { |
||
| 532 | $product_attribute_data[] = array( |
||
| 533 | 'attribute_id' => $product_attribute['attribute_id'], |
||
| 534 | 'name' => $product_attribute['name'], |
||
| 535 | 'text' => $product_attribute['text'] |
||
| 536 | ); |
||
| 537 | } |
||
| 538 | |||
| 539 | $product_attribute_group_data[] = array( |
||
| 540 | 'attribute_group_id' => $product_attribute_group['attribute_group_id'], |
||
| 541 | 'name' => $product_attribute_group['name'], |
||
| 542 | 'attribute' => $product_attribute_data |
||
| 543 | ); |
||
| 544 | } |
||
| 545 | |||
| 546 | return $product_attribute_group_data; |
||
| 547 | } |
||
| 548 | |||
| 549 | public function getProductOptions($product_id) |
||
| 550 | { |
||
| 551 | $product_option_data = array(); |
||
| 552 | |||
| 553 | $product_option_query = $this->db->query("SELECT * FROM product_option po LEFT JOIN `option` o ON (po.option_id = o.option_id) LEFT JOIN option_description od ON (o.option_id = od.option_id) WHERE po.product_id = '" . (int)$product_id . "' AND od.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY o.sort_order"); |
||
| 554 | |||
| 555 | foreach ($product_option_query->rows as $product_option) { |
||
| 556 | $product_option_value_data = array(); |
||
| 557 | |||
| 558 | $product_option_value_query = $this->db->query("SELECT * FROM product_option_value pov LEFT JOIN option_value ov ON (pov.option_value_id = ov.option_value_id) LEFT JOIN option_value_description ovd ON (ov.option_value_id = ovd.option_value_id) WHERE pov.product_id = '" . (int)$product_id . "' AND pov.product_option_id = '" . (int)$product_option['product_option_id'] . "' AND ovd.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY ov.sort_order"); |
||
| 559 | |||
| 560 | foreach ($product_option_value_query->rows as $product_option_value) { |
||
| 561 | $product_option_value_data[] = array( |
||
| 562 | 'product_option_value_id' => $product_option_value['product_option_value_id'], |
||
| 563 | 'option_value_id' => $product_option_value['option_value_id'], |
||
| 564 | 'name' => $product_option_value['name'], |
||
| 565 | 'image' => $product_option_value['image'], |
||
| 566 | 'quantity' => $product_option_value['quantity'], |
||
| 567 | 'subtract' => $product_option_value['subtract'], |
||
| 568 | 'price' => $product_option_value['price'], |
||
| 569 | 'price_prefix' => $product_option_value['price_prefix'] |
||
| 570 | ); |
||
| 571 | } |
||
| 572 | |||
| 573 | $product_option_data[] = array( |
||
| 574 | 'product_option_id' => $product_option['product_option_id'], |
||
| 575 | 'product_option_value' => $product_option_value_data, |
||
| 576 | 'option_id' => $product_option['option_id'], |
||
| 577 | 'name' => $product_option['name'], |
||
| 578 | 'type' => $product_option['type'], |
||
| 579 | 'value' => $product_option['value'], |
||
| 580 | 'required' => $product_option['required'] |
||
| 581 | ); |
||
| 582 | } |
||
| 583 | |||
| 584 | return $product_option_data; |
||
| 585 | } |
||
| 586 | |||
| 587 | public function getProductDiscounts($product_id) |
||
| 588 | { |
||
| 589 | $query = $this->db->query(" |
||
| 590 | SELECT * FROM product_discount |
||
| 591 | WHERE product_id = '" . (int)$product_id . "' |
||
| 592 | AND customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' |
||
| 593 | AND quantity > 1 |
||
| 594 | AND ((date_start = '2000-01-01' OR date_start < NOW()) |
||
| 595 | AND (date_end = '2000-01-01' OR date_end > NOW())) |
||
| 596 | ORDER BY quantity ASC, priority ASC, price ASC |
||
| 597 | "); |
||
| 598 | |||
| 599 | return $query->rows; |
||
| 600 | } |
||
| 601 | |||
| 602 | public function getProductImages($product_id) |
||
| 603 | { |
||
| 604 | $query = $this->db->query(" |
||
| 605 | SELECT * |
||
| 606 | FROM product_image |
||
| 607 | WHERE product_id = '" . (int)$product_id . "' |
||
| 608 | ORDER BY sort_order ASC |
||
| 609 | "); |
||
| 610 | |||
| 611 | return $query->rows; |
||
| 612 | } |
||
| 613 | |||
| 614 | public function getProductRelated($product_id) |
||
| 615 | { |
||
| 616 | $product_data = array(); |
||
| 617 | |||
| 618 | $query = $this->db->query(" |
||
| 619 | SELECT * |
||
| 620 | FROM product_related pr |
||
| 621 | LEFT JOIN product p ON (pr.related_id = p.product_id) |
||
| 622 | WHERE pr.product_id = '" . (int)$product_id . "' |
||
| 623 | AND p.status = '1' |
||
| 624 | "); |
||
| 625 | |||
| 626 | foreach ($query->rows as $result) { |
||
| 627 | $product_data[$result['related_id']] = $this->getProduct($result['related_id']); |
||
| 628 | } |
||
| 629 | |||
| 630 | return $product_data; |
||
| 631 | } |
||
| 632 | |||
| 633 | public function getProductLayoutId($product_id) |
||
| 634 | { |
||
| 635 | $query = $this->db->query(" |
||
| 636 | SELECT * |
||
| 637 | FROM product_to_layout |
||
| 638 | WHERE product_id = '" . (int)$product_id . "' |
||
| 639 | "); |
||
| 640 | |||
| 641 | if ($query->num_rows) { |
||
| 642 | return $query->row['layout_id']; |
||
| 643 | } else { |
||
| 644 | return 0; |
||
| 645 | } |
||
| 646 | } |
||
| 647 | |||
| 648 | public function getCategories($product_id) |
||
| 649 | { |
||
| 650 | $query = $this->db->query(" |
||
| 651 | SELECT * |
||
| 652 | FROM product_to_category |
||
| 653 | WHERE product_id = '" . (int)$product_id . "' |
||
| 654 | "); |
||
| 655 | |||
| 656 | return $query->rows; |
||
| 657 | } |
||
| 658 | |||
| 659 | public function getTotalProducts($data = array()) |
||
| 764 | } |
||
| 765 | |||
| 766 | public function getTotalProductSpecials() |
||
| 767 | { |
||
| 768 | $query = $this->db->query(" |
||
| 769 | SELECT COUNT(DISTINCT ps.product_id) AS total |
||
| 770 | FROM product_special ps |
||
| 771 | LEFT JOIN product p ON (ps.product_id = p.product_id) |
||
| 772 | WHERE p.status = '1' |
||
| 773 | AND ps.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' |
||
| 774 | AND ((ps.date_start = '2000-01-01' OR ps.date_start < NOW()) |
||
| 775 | AND (ps.date_end = '2000-01-01' OR ps.date_end > NOW())) |
||
| 776 | "); |
||
| 777 | |||
| 778 | if (isset($query->row['total'])) { |
||
| 779 | return $query->row['total']; |
||
| 780 | } else { |
||
| 782 | } |
||
| 783 | } |
||
| 784 | } |
||
| 785 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.