paketonlinestore

product.php model file

Feb 2nd, 2014
490
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. class ModelCatalogProduct extends Model {
  3. public function addProduct($data) {
  4. $this->db->query("INSERT INTO " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "', sku = '" . $this->db->escape($data['sku']) . "', location = '" . $this->db->escape($data['location']) . "', quantity = '" . (int)$data['quantity'] . "', minimum = '" . (int)$data['minimum'] . "', subtract = '" . (int)$data['subtract'] . "', stock_status_id = '" . (int)$data['stock_status_id'] . "', date_available = '" . $this->db->escape($data['date_available']) . "', manufacturer_id = '" . (int)$data['manufacturer_id'] . "', shipping = '" . (int)$data['shipping'] . "', price = '" . (float)$data['price'] . "', cost = '" . (float)$data['cost'] . "', weight = '" . (float)$data['weight'] . "', weight_class_id = '" . (int)$data['weight_class_id'] . "', length = '" . (float)$data['length'] . "', width = '" . (float)$data['width'] . "', height = '" . (float)$data['height'] . "', length_class_id = '" . (int)$data['length_class_id'] . "', status = '" . (int)$data['status'] . "', tax_class_id = '" . (int)$data['tax_class_id'] . "', sort_order = '" . (int)$data['sort_order'] . "', date_added = NOW()");
  5.  
  6. $product_id = $this->db->getLastId();
  7.  
  8. if (isset($data['image'])) {
  9. $this->db->query("UPDATE " . DB_PREFIX . "product SET image = '" . $this->db->escape($data['image']) . "' WHERE product_id = '" . (int)$product_id . "'");
  10. }
  11.  
  12. foreach ($data['product_description'] as $language_id => $value) {
  13. $this->db->query("INSERT INTO " . DB_PREFIX . "product_description SET product_id = '" . (int)$product_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "', meta_keywords = '" . $this->db->escape($value['meta_keywords']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', description = '" . $this->db->escape($value['description']) . "'");
  14. }
  15.  
  16. if (isset($data['product_store'])) {
  17. foreach ($data['product_store'] as $store_id) {
  18. $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_store SET product_id = '" . (int)$product_id . "', store_id = '" . (int)$store_id . "'");
  19. }
  20. }
  21.  
  22. if (isset($data['product_option'])) {
  23. foreach ($data['product_option'] as $product_option) {
  24. $this->db->query("INSERT INTO " . DB_PREFIX . "product_option SET product_id = '" . (int)$product_id . "', sort_order = '" . (int)$product_option['sort_order'] . "'");
  25.  
  26. $product_option_id = $this->db->getLastId();
  27.  
  28. foreach ($product_option['language'] as $language_id => $language) {
  29. $this->db->query("INSERT INTO " . DB_PREFIX . "product_option_description SET product_option_id = '" . (int)$product_option_id . "', language_id = '" . (int)$language_id . "', product_id = '" . (int)$product_id . "', name = '" . $this->db->escape($language['name']) . "'");
  30. }
  31.  
  32. if (isset($product_option['product_option_value'])) {
  33. foreach ($product_option['product_option_value'] as $product_option_value) {
  34. $this->db->query("INSERT INTO " . DB_PREFIX . "product_option_value SET product_option_id = '" . (int)$product_option_id . "', product_id = '" . (int)$product_id . "', quantity = '" . (int)$product_option_value['quantity'] . "', subtract = '" . (int)$product_option_value['subtract'] . "', price = '" . (float)$product_option_value['price'] . "', prefix = '" . $this->db->escape($product_option_value['prefix']) . "', sort_order = '" . (int)$product_option_value['sort_order'] . "'");
  35.  
  36. $product_option_value_id = $this->db->getLastId();
  37.  
  38. foreach ($product_option_value['language'] as $language_id => $language) {
  39. $this->db->query("INSERT INTO " . DB_PREFIX . "product_option_value_description SET product_option_value_id = '" . (int)$product_option_value_id . "', language_id = '" . (int)$language_id . "', product_id = '" . (int)$product_id . "', name = '" . $this->db->escape($language['name']) . "'");
  40. }
  41. }
  42. }
  43. }
  44. }
  45.  
  46. if (isset($data['product_discount'])) {
  47. foreach ($data['product_discount'] as $value) {
  48. $this->db->query("INSERT INTO " . DB_PREFIX . "product_discount SET product_id = '" . (int)$product_id . "', customer_group_id = '" . (int)$value['customer_group_id'] . "', quantity = '" . (int)$value['quantity'] . "', priority = '" . (int)$value['priority'] . "', price = '" . (float)$value['price'] . "', date_start = '" . $this->db->escape($value['date_start']) . "', date_end = '" . $this->db->escape($value['date_end']) . "'");
  49. }
  50. }
  51.  
  52. if (isset($data['product_special'])) {
  53. foreach ($data['product_special'] as $value) {
  54. $this->db->query("INSERT INTO " . DB_PREFIX . "product_special SET product_id = '" . (int)$product_id . "', customer_group_id = '" . (int)$value['customer_group_id'] . "', priority = '" . (int)$value['priority'] . "', price = '" . (float)$value['price'] . "', date_start = '" . $this->db->escape($value['date_start']) . "', date_end = '" . $this->db->escape($value['date_end']) . "'");
  55. }
  56. }
  57.  
  58. if (isset($data['product_image'])) {
  59. foreach ($data['product_image'] as $image) {
  60. $this->db->query("INSERT INTO " . DB_PREFIX . "product_image SET product_id = '" . (int)$product_id . "', image = '" . $this->db->escape($image) . "'");
  61. }
  62. }
  63.  
  64. if (isset($data['product_download'])) {
  65. foreach ($data['product_download'] as $download_id) {
  66. $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_download SET product_id = '" . (int)$product_id . "', download_id = '" . (int)$download_id . "'");
  67. }
  68. }
  69.  
  70. if (isset($data['product_category'])) {
  71. foreach ($data['product_category'] as $category_id) {
  72. $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_category SET product_id = '" . (int)$product_id . "', category_id = '" . (int)$category_id . "'");
  73. }
  74. }
  75.  
  76. if (isset($data['product_related'])) {
  77. foreach ($data['product_related'] as $related_id) {
  78. $this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$product_id . "', related_id = '" . (int)$related_id . "'");
  79. $this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$related_id . "', related_id = '" . (int)$product_id . "'");
  80. }
  81. }
  82.  
  83. if ($data['keyword']) {
  84. $this->db->query("INSERT INTO " . DB_PREFIX . "url_alias SET query = 'product_id=" . (int)$product_id . "', keyword = '" . $this->db->escape($data['keyword']) . "'");
  85. }
  86.  
  87. foreach ($data['product_tags'] as $language_id => $value) {
  88. $tags = explode(',', $value);
  89. foreach ($tags as $tag) {
  90. $this->db->query("INSERT INTO " . DB_PREFIX . "product_tags SET product_id = '" . (int)$product_id . "', language_id = '" . (int)$language_id . "', tag = '" . $this->db->escape(trim($tag)) . "'");
  91. }
  92. }
  93.  
  94.  
  95. $this->cache->delete('product');
  96. }
  97.  
  98. public function editProduct($product_id, $data) {
  99. $this->db->query("UPDATE " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "', sku = '" . $this->db->escape($data['sku']) . "', location = '" . $this->db->escape($data['location']) . "', quantity = '" . (int)$data['quantity'] . "', minimum = '" . (int)$data['minimum'] . "', subtract = '" . (int)$data['subtract'] . "', stock_status_id = '" . (int)$data['stock_status_id'] . "', date_available = '" . $this->db->escape($data['date_available']) . "', manufacturer_id = '" . (int)$data['manufacturer_id'] . "', shipping = '" . (int)$data['shipping'] . "', price = '" . (float)$data['price'] . "', cost = '" . (float)$data['cost'] . "', weight = '" . (float)$data['weight'] . "', weight_class_id = '" . (int)$data['weight_class_id'] . "', length = '" . (float)$data['length'] . "', width = '" . (float)$data['width'] . "', height = '" . (float)$data['height'] . "', length_class_id = '" . (int)$data['length_class_id'] . "', status = '" . (int)$data['status'] . "', tax_class_id = '" . (int)$data['tax_class_id'] . "', sort_order = '" . (int)$data['sort_order'] . "', date_modified = NOW() WHERE product_id = '" . (int)$product_id . "'");
  100.  
  101. if (isset($data['image'])) {
  102. $this->db->query("UPDATE " . DB_PREFIX . "product SET image = '" . $this->db->escape($data['image']) . "' WHERE product_id = '" . (int)$product_id . "'");
  103. }
  104.  
  105. $this->db->query("DELETE FROM " . DB_PREFIX . "product_description WHERE product_id = '" . (int)$product_id . "'");
  106.  
  107. foreach ($data['product_description'] as $language_id => $value) {
  108. $this->db->query("INSERT INTO " . DB_PREFIX . "product_description SET product_id = '" . (int)$product_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "', meta_keywords = '" . $this->db->escape($value['meta_keywords']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', description = '" . $this->db->escape($value['description']) . "'");
  109. }
  110.  
  111. $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_store WHERE product_id = '" . (int)$product_id . "'");
  112.  
  113. if (isset($data['product_store'])) {
  114. foreach ($data['product_store'] as $store_id) {
  115. $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_store SET product_id = '" . (int)$product_id . "', store_id = '" . (int)$store_id . "'");
  116. }
  117. }
  118.  
  119. $this->db->query("DELETE FROM " . DB_PREFIX . "product_option WHERE product_id = '" . (int)$product_id . "'");
  120. $this->db->query("DELETE FROM " . DB_PREFIX . "product_option_description WHERE product_id = '" . (int)$product_id . "'");
  121. $this->db->query("DELETE FROM " . DB_PREFIX . "product_option_value WHERE product_id = '" . (int)$product_id . "'");
  122. $this->db->query("DELETE FROM " . DB_PREFIX . "product_option_value_description WHERE product_id = '" . (int)$product_id . "'");
  123.  
  124. if (isset($data['product_option'])) {
  125. foreach ($data['product_option'] as $product_option) {
  126. $this->db->query("INSERT INTO " . DB_PREFIX . "product_option SET product_id = '" . (int)$product_id . "', sort_order = '" . (int)$product_option['sort_order'] . "'");
  127.  
  128. $product_option_id = $this->db->getLastId();
  129.  
  130. foreach ($product_option['language'] as $language_id => $language) {
  131. $this->db->query("INSERT INTO " . DB_PREFIX . "product_option_description SET product_option_id = '" . (int)$product_option_id . "', language_id = '" . (int)$language_id . "', product_id = '" . (int)$product_id . "', name = '" . $this->db->escape($language['name']) . "'");
  132. }
  133.  
  134. if (isset($product_option['product_option_value'])) {
  135. foreach ($product_option['product_option_value'] as $product_option_value) {
  136. $this->db->query("INSERT INTO " . DB_PREFIX . "product_option_value SET product_option_id = '" . (int)$product_option_id . "', product_id = '" . (int)$product_id . "', quantity = '" . (int)$product_option_value['quantity'] . "', subtract = '" . (int)$product_option_value['subtract'] . "', price = '" . (float)$product_option_value['price'] . "', prefix = '" . $this->db->escape($product_option_value['prefix']) . "', sort_order = '" . (int)$product_option_value['sort_order'] . "'");
  137.  
  138. $product_option_value_id = $this->db->getLastId();
  139.  
  140. foreach ($product_option_value['language'] as $language_id => $language) {
  141. $this->db->query("INSERT INTO " . DB_PREFIX . "product_option_value_description SET product_option_value_id = '" . (int)$product_option_value_id . "', language_id = '" . (int)$language_id . "', product_id = '" . (int)$product_id . "', name = '" . $this->db->escape($language['name']) . "'");
  142. }
  143. }
  144. }
  145. }
  146. }
  147.  
  148. $this->db->query("DELETE FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "'");
  149.  
  150. if (isset($data['product_discount'])) {
  151. foreach ($data['product_discount'] as $value) {
  152. $this->db->query("INSERT INTO " . DB_PREFIX . "product_discount SET product_id = '" . (int)$product_id . "', customer_group_id = '" . (int)$value['customer_group_id'] . "', quantity = '" . (int)$value['quantity'] . "', priority = '" . (int)$value['priority'] . "', price = '" . (float)$value['price'] . "', date_start = '" . $this->db->escape($value['date_start']) . "', date_end = '" . $this->db->escape($value['date_end']) . "'");
  153. }
  154. }
  155.  
  156. $this->db->query("DELETE FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "'");
  157.  
  158. if (isset($data['product_special'])) {
  159. foreach ($data['product_special'] as $value) {
  160. $this->db->query("INSERT INTO " . DB_PREFIX . "product_special SET product_id = '" . (int)$product_id . "', customer_group_id = '" . (int)$value['customer_group_id'] . "', priority = '" . (int)$value['priority'] . "', price = '" . (float)$value['price'] . "', date_start = '" . $this->db->escape($value['date_start']) . "', date_end = '" . $this->db->escape($value['date_end']) . "'");
  161. }
  162. }
  163.  
  164. $this->db->query("DELETE FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "'");
  165.  
  166. if (isset($data['product_image'])) {
  167. foreach ($data['product_image'] as $image) {
  168. $this->db->query("INSERT INTO " . DB_PREFIX . "product_image SET product_id = '" . (int)$product_id . "', image = '" . $this->db->escape($image) . "'");
  169. }
  170. }
  171.  
  172. $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_download WHERE product_id = '" . (int)$product_id . "'");
  173.  
  174. if (isset($data['product_download'])) {
  175. foreach ($data['product_download'] as $download_id) {
  176. $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_download SET product_id = '" . (int)$product_id . "', download_id = '" . (int)$download_id . "'");
  177. }
  178. }
  179.  
  180. $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'");
  181.  
  182. if (isset($data['product_category'])) {
  183. foreach ($data['product_category'] as $category_id) {
  184. $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_category SET product_id = '" . (int)$product_id . "', category_id = '" . (int)$category_id . "'");
  185. }
  186. }
  187.  
  188. $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "'");
  189.  
  190. if (isset($data['product_related'])) {
  191. foreach ($data['product_related'] as $related_id) {
  192. $this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$product_id . "', related_id = '" . (int)$related_id . "'");
  193. $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$related_id . "' AND related_id = '" . (int)$product_id . "'");
  194. $this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$related_id . "', related_id = '" . (int)$product_id . "'");
  195. }
  196. }
  197.  
  198. $this->db->query("DELETE FROM " . DB_PREFIX . "url_alias WHERE query = 'product_id=" . (int)$product_id. "'");
  199.  
  200. if ($data['keyword']) {
  201. $this->db->query("INSERT INTO " . DB_PREFIX . "url_alias SET query = 'product_id=" . (int)$product_id . "', keyword = '" . $this->db->escape($data['keyword']) . "'");
  202. }
  203.  
  204. $this->db->query("DELETE FROM " . DB_PREFIX . "product_tags WHERE product_id = '" . (int)$product_id. "'");
  205.  
  206. foreach ($data['product_tags'] as $language_id => $value) {
  207. $tags = explode(',', $value);
  208. foreach ($tags as $tag) {
  209. $this->db->query("INSERT INTO " . DB_PREFIX . "product_tags SET product_id = '" . (int)$product_id . "', language_id = '" . (int)$language_id . "', tag = '" . $this->db->escape(trim($tag)) . "'");
  210. }
  211. }
  212.  
  213. $this->cache->delete('product');
  214. }
  215.  
  216. public function copyProduct($product_id) {
  217. $query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "'");
  218.  
  219. if ($query->num_rows) {
  220. $data = array();
  221.  
  222. $data = $query->row;
  223.  
  224. $data = array_merge($data, array('product_description' => $this->getProductDescriptions($product_id)));
  225. $data = array_merge($data, array('product_option' => $this->getProductOptions($product_id)));
  226.  
  227. $data['keyword'] = '';
  228.  
  229. $data['product_image'] = array();
  230.  
  231. $results = $this->getProductImages($product_id);
  232.  
  233. foreach ($results as $result) {
  234. $data['product_image'][] = $result['image'];
  235. }
  236.  
  237. $data = array_merge($data, array('product_discount' => $this->getProductDiscounts($product_id)));
  238. $data = array_merge($data, array('product_special' => $this->getProductSpecials($product_id)));
  239. $data = array_merge($data, array('product_download' => $this->getProductDownloads($product_id)));
  240. $data = array_merge($data, array('product_category' => $this->getProductCategories($product_id)));
  241. $data = array_merge($data, array('product_store' => $this->getProductStores($product_id)));
  242. $data = array_merge($data, array('product_related' => $this->getProductRelated($product_id)));
  243. $data = array_merge($data, array('product_tags' => $this->getProductTags($product_id)));
  244.  
  245. $this->addProduct($data);
  246. }
  247. }
  248.  
  249. public function deleteProduct($product_id) {
  250. $this->db->query("DELETE FROM " . DB_PREFIX . "product WHERE product_id = '" . (int)$product_id . "'");
  251. $this->db->query("DELETE FROM " . DB_PREFIX . "product_description WHERE product_id = '" . (int)$product_id . "'");
  252. $this->db->query("DELETE FROM " . DB_PREFIX . "product_option WHERE product_id = '" . (int)$product_id . "'");
  253. $this->db->query("DELETE FROM " . DB_PREFIX . "product_option_description WHERE product_id = '" . (int)$product_id . "'");
  254. $this->db->query("DELETE FROM " . DB_PREFIX . "product_option_value WHERE product_id = '" . (int)$product_id . "'");
  255. $this->db->query("DELETE FROM " . DB_PREFIX . "product_option_value_description WHERE product_id = '" . (int)$product_id . "'");
  256. $this->db->query("DELETE FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "'");
  257. $this->db->query("DELETE FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "'");
  258. $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "'");
  259. $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_download WHERE product_id = '" . (int)$product_id . "'");
  260. $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'");
  261. $this->db->query("DELETE FROM " . DB_PREFIX . "review WHERE product_id = '" . (int)$product_id . "'");
  262. $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_store WHERE product_id = '" . (int)$product_id . "'");
  263. $this->db->query("DELETE FROM " . DB_PREFIX . "url_alias WHERE query = 'product_id=" . (int)$product_id. "'");
  264. $this->db->query("DELETE FROM " . DB_PREFIX . "product_tags WHERE product_id='" . (int)$product_id. "'");
  265.  
  266. $this->cache->delete('product');
  267. }
  268.  
  269. public function getProduct($product_id) {
  270. $query = $this->db->query("SELECT DISTINCT *, (SELECT keyword FROM " . DB_PREFIX . "url_alias WHERE query = 'product_id=" . (int)$product_id . "') AS keyword FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "'");
  271.  
  272. return $query->row;
  273. }
  274.  
  275. public function getProducts($data = array()) {
  276. if ($data) {
  277. $sql = "SELECT * FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "'";
  278.  
  279. if (isset($data['filter_name']) && !is_null($data['filter_name'])) {
  280. $sql .= " AND LCASE(pd.name) LIKE '%" . $this->db->escape(strtolower($data['filter_name'])) . "%'";
  281. }
  282.  
  283. if (isset($data['filter_model']) && !is_null($data['filter_model'])) {
  284. $sql .= " AND LCASE(p.model) LIKE '%" . $this->db->escape(strtolower($data['filter_model'])) . "%'";
  285. }
  286.  
  287. if (isset($data['filter_quantity']) && !is_null($data['filter_quantity'])) {
  288. $sql .= " AND p.quantity = '" . $this->db->escape($data['filter_quantity']) . "'";
  289. }
  290.  
  291. if (isset($data['filter_status']) && !is_null($data['filter_status'])) {
  292. $sql .= " AND p.status = '" . (int)$data['filter_status'] . "'";
  293. }
  294.  
  295. $sort_data = array(
  296. 'pd.name',
  297. 'p.model',
  298. 'p.quantity',
  299. 'p.status',
  300. 'p.sort_order'
  301. );
  302.  
  303. if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
  304. $sql .= " ORDER BY " . $data['sort'];
  305. } else {
  306. $sql .= " ORDER BY pd.name";
  307. }
  308.  
  309. if (isset($data['order']) && ($data['order'] == 'DESC')) {
  310. $sql .= " DESC";
  311. } else {
  312. $sql .= " ASC";
  313. }
  314.  
  315. if (isset($data['start']) || isset($data['limit'])) {
  316. if ($data['start'] < 0) {
  317. $data['start'] = 0;
  318. }
  319.  
  320. if ($data['limit'] < 1) {
  321. $data['limit'] = 20;
  322. }
  323.  
  324. $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
  325. }
  326.  
  327. $query = $this->db->query($sql);
  328.  
  329. return $query->rows;
  330. } else {
  331. $product_data = $this->cache->get('product.' . $this->config->get('config_language_id'));
  332.  
  333. if (!$product_data) {
  334. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY pd.name ASC");
  335.  
  336. $product_data = $query->rows;
  337.  
  338. $this->cache->set('product.' . $this->config->get('config_language_id'), $product_data);
  339. }
  340.  
  341. return $product_data;
  342. }
  343. }
  344.  
  345. public function addFeatured($data) {
  346. $this->db->query("DELETE FROM " . DB_PREFIX . "product_featured");
  347.  
  348. if (isset($data['product_featured'])) {
  349. foreach ($data['product_featured'] as $product_id) {
  350. $this->db->query("INSERT INTO " . DB_PREFIX . "product_featured SET product_id = '" . (int)$product_id . "'");
  351. }
  352. }
  353. }
  354.  
  355. public function getFeaturedProducts() {
  356. $product_featured_data = array();
  357.  
  358. $query = $this->db->query("SELECT product_id FROM " . DB_PREFIX . "product_featured");
  359.  
  360. foreach ($query->rows as $result) {
  361. $product_featured_data[] = $result['product_id'];
  362. }
  363. return $product_featured_data;
  364. }
  365.  
  366. public function getProductsByKeyword($keyword) {
  367. if ($keyword) {
  368. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND (LCASE(pd.name) LIKE '%" . $this->db->escape(strtolower($keyword)) . "%' OR LCASE(p.model) LIKE '%" . $this->db->escape(strtolower($keyword)) . "%')");
  369.  
  370. return $query->rows;
  371. } else {
  372. return array();
  373. }
  374. }
  375.  
  376. public function getProductsByCategoryId($category_id) {
  377. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "' ORDER BY pd.name ASC");
  378.  
  379. return $query->rows;
  380. }
  381.  
  382. public function getProductDescriptions($product_id) {
  383. $product_description_data = array();
  384.  
  385. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_description WHERE product_id = '" . (int)$product_id . "'");
  386.  
  387. foreach ($query->rows as $result) {
  388. $product_description_data[$result['language_id']] = array(
  389. 'name' => $result['name'],
  390. 'meta_keywords' => $result['meta_keywords'],
  391. 'meta_description' => $result['meta_description'],
  392. 'description' => $result['description']
  393. );
  394. }
  395.  
  396. return $product_description_data;
  397. }
  398.  
  399. public function getProductOptions($product_id) {
  400. $product_option_data = array();
  401.  
  402. $product_option = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option WHERE product_id = '" . (int)$product_id . "' ORDER BY sort_order");
  403.  
  404. foreach ($product_option->rows as $product_option) {
  405. $product_option_value_data = array();
  406.  
  407. $product_option_value = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value WHERE product_option_id = '" . (int)$product_option['product_option_id'] . "' ORDER BY sort_order");
  408.  
  409. foreach ($product_option_value->rows as $product_option_value) {
  410. $product_option_value_description_data = array();
  411.  
  412. $product_option_value_description = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value_description WHERE product_option_value_id = '" . (int)$product_option_value['product_option_value_id'] . "'");
  413.  
  414. foreach ($product_option_value_description->rows as $result) {
  415. $product_option_value_description_data[$result['language_id']] = array('name' => $result['name']);
  416. }
  417.  
  418. $product_option_value_data[] = array(
  419. 'product_option_value_id' => $product_option_value['product_option_value_id'],
  420. 'language' => $product_option_value_description_data,
  421. 'quantity' => $product_option_value['quantity'],
  422. 'subtract' => $product_option_value['subtract'],
  423. 'price' => $product_option_value['price'],
  424. 'prefix' => $product_option_value['prefix'],
  425. 'sort_order' => $product_option_value['sort_order']
  426. );
  427. }
  428.  
  429. $product_option_description_data = array();
  430.  
  431. $product_option_description = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_description WHERE product_option_id = '" . (int)$product_option['product_option_id'] . "'");
  432.  
  433. foreach ($product_option_description->rows as $result) {
  434. $product_option_description_data[$result['language_id']] = array('name' => $result['name']);
  435. }
  436.  
  437. $product_option_data[] = array(
  438. 'product_option_id' => $product_option['product_option_id'],
  439. 'language' => $product_option_description_data,
  440. 'product_option_value' => $product_option_value_data,
  441. 'sort_order' => $product_option['sort_order']
  442. );
  443. }
  444.  
  445. return $product_option_data;
  446. }
  447.  
  448. public function getProductImages($product_id) {
  449. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "'");
  450.  
  451. return $query->rows;
  452. }
  453.  
  454. public function getProductDiscounts($product_id) {
  455. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' ORDER BY quantity, priority, price");
  456.  
  457. return $query->rows;
  458. }
  459.  
  460. public function getProductSpecials($product_id) {
  461. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "' ORDER BY priority, price");
  462.  
  463. return $query->rows;
  464. }
  465.  
  466. public function getProductDownloads($product_id) {
  467. $product_download_data = array();
  468.  
  469. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_download WHERE product_id = '" . (int)$product_id . "'");
  470.  
  471. foreach ($query->rows as $result) {
  472. $product_download_data[] = $result['download_id'];
  473. }
  474.  
  475. return $product_download_data;
  476. }
  477.  
  478. public function getProductStores($product_id) {
  479. $product_store_data = array();
  480.  
  481. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_store WHERE product_id = '" . (int)$product_id . "'");
  482.  
  483. foreach ($query->rows as $result) {
  484. $product_store_data[] = $result['store_id'];
  485. }
  486.  
  487. return $product_store_data;
  488. }
  489.  
  490. public function getProductCategories($product_id) {
  491. $product_category_data = array();
  492.  
  493. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'");
  494.  
  495. foreach ($query->rows as $result) {
  496. $product_category_data[] = $result['category_id'];
  497. }
  498.  
  499. return $product_category_data;
  500. }
  501.  
  502. public function getProductRelated($product_id) {
  503. $product_related_data = array();
  504.  
  505. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "'");
  506.  
  507. foreach ($query->rows as $result) {
  508. $product_related_data[] = $result['related_id'];
  509. }
  510.  
  511. return $product_related_data;
  512. }
  513.  
  514. public function getProductTags($product_id) {
  515. $product_tag_data = array();
  516.  
  517. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_tags WHERE product_id = '" . (int)$product_id . "'");
  518.  
  519. $tag_data = array();
  520.  
  521. foreach ($query->rows as $result) {
  522. $tag_data[$result['language_id']][] = $result['tag'];
  523. }
  524.  
  525. foreach ($tag_data as $language => $tags) {
  526. $product_tag_data[$language] = implode(',', $tags);
  527. }
  528.  
  529. return $product_tag_data;
  530. }
  531.  
  532. public function getTotalProducts($data = array()) {
  533. $sql = "SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "'";
  534.  
  535. if (isset($data['filter_name']) && !is_null($data['filter_name'])) {
  536. $sql .= " AND LCASE(pd.name) LIKE '%" . $this->db->escape(strtolower($data['filter_name'])) . "%'";
  537. }
  538.  
  539. if (isset($data['filter_model']) && !is_null($data['filter_model'])) {
  540. $sql .= " AND LCASE(p.model) LIKE '%" . $this->db->escape(strtolower($data['filter_model'])) . "%'";
  541. }
  542.  
  543. if (isset($data['filter_quantity']) && !is_null($data['filter_quantity'])) {
  544. $sql .= " AND p.quantity = '" . $this->db->escape($data['filter_quantity']) . "'";
  545. }
  546.  
  547. if (isset($data['filter_status']) && !is_null($data['filter_status'])) {
  548. $sql .= " AND p.status = '" . (int)$data['filter_status'] . "'";
  549. }
  550.  
  551. $query = $this->db->query($sql);
  552.  
  553. return $query->row['total'];
  554. }
  555.  
  556. public function getTotalProductsByStockStatusId($stock_status_id) {
  557. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE stock_status_id = '" . (int)$stock_status_id . "'");
  558.  
  559. return $query->row['total'];
  560. }
  561.  
  562. public function getTotalProductsByImageId($image_id) {
  563. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE image_id = '" . (int)$image_id . "'");
  564.  
  565. return $query->row['total'];
  566. }
  567.  
  568. public function getTotalProductsByTaxClassId($tax_class_id) {
  569. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE tax_class_id = '" . (int)$tax_class_id . "'");
  570.  
  571. return $query->row['total'];
  572. }
  573.  
  574. public function getTotalProductsByWeightClassId($weight_class_id) {
  575. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE weight_class_id = '" . (int)$weight_class_id . "'");
  576.  
  577. return $query->row['total'];
  578. }
  579.  
  580. public function getTotalProductsByLengthClassId($length_class_id) {
  581. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE length_class_id = '" . (int)$length_class_id . "'");
  582.  
  583. return $query->row['total'];
  584. }
  585.  
  586. public function getTotalProductsByOptionId($option_id) {
  587. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product_to_option WHERE option_id = '" . (int)$option_id . "'");
  588.  
  589. return $query->row['total'];
  590. }
  591.  
  592. public function getTotalProductsByDownloadId($download_id) {
  593. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product_to_download WHERE download_id = '" . (int)$download_id . "'");
  594.  
  595. return $query->row['total'];
  596. }
  597.  
  598. public function getTotalProductsByManufacturerId($manufacturer_id) {
  599. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE manufacturer_id = '" . (int)$manufacturer_id . "'");
  600.  
  601. return $query->row['total'];
  602. }
  603. }
  604. ?>
RAW Paste Data