Advertisement
Guest User

Untitled

a guest
Oct 27th, 2013
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 47.24 KB | None | 0 0
  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']) . "', upc = '" . $this->db->escape($data['upc']) . "', 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'] . "', points = '" . (int)$data['points'] . "', 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 = '" . $this->db->escape($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(html_entity_decode($data['image'], ENT_QUOTES, 'UTF-8')) . "' WHERE product_id = '" . (int)$product_id . "'");
  10. }
  11.  
  12. $productName = "";
  13. foreach ($data['product_description'] as $language_id => $value) {
  14. if ($language_id == $this->config->get('config_language_id')){
  15. $productName = $value['name'];
  16. }
  17.  
  18. $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_keyword = '" . $this->db->escape($value['meta_keyword']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', description = '" . $this->db->escape($value['description']) . "', seo_title = '" . $this->db->escape($value['seo_title']) . "', seo_h1 = '" . $this->db->escape($value['seo_h1']) . "'");
  19. }
  20.  
  21. if (isset($data['product_store'])) {
  22. foreach ($data['product_store'] as $store_id) {
  23. $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_store SET product_id = '" . (int)$product_id . "', store_id = '" . (int)$store_id . "'");
  24. }
  25. }
  26.  
  27. if (isset($data['product_attribute'])) {
  28. foreach ($data['product_attribute'] as $product_attribute) {
  29. if ($product_attribute['attribute_id']) {
  30. $this->db->query("DELETE FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "' AND attribute_id = '" . (int)$product_attribute['attribute_id'] . "'");
  31.  
  32. foreach ($product_attribute['product_attribute_description'] as $language_id => $product_attribute_description) {
  33. $this->db->query("INSERT INTO " . DB_PREFIX . "product_attribute SET product_id = '" . (int)$product_id . "', attribute_id = '" . (int)$product_attribute['attribute_id'] . "', language_id = '" . (int)$language_id . "', text = '" . $this->db->escape($product_attribute_description['text']) . "'");
  34. }
  35. }
  36. }
  37. }
  38.  
  39. if (isset($data['product_option'])) {
  40. foreach ($data['product_option'] as $product_option) {
  41. if ($product_option['type'] == 'select' || $product_option['type'] == 'radio' || $product_option['type'] == 'checkbox' || $product_option['type'] == 'image') {
  42. $this->db->query("INSERT INTO " . DB_PREFIX . "product_option SET product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', required = '" . (int)$product_option['required'] . "'");
  43.  
  44. $product_option_id = $this->db->getLastId();
  45.  
  46. if (isset($product_option['product_option_value'])) {
  47. foreach ($product_option['product_option_value'] as $product_option_value) {
  48. $this->db->query("INSERT INTO " . DB_PREFIX . "product_option_value SET product_option_id = '" . (int)$product_option_id . "', product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', option_value_id = '" . (int)$product_option_value['option_value_id'] . "', quantity = '" . (int)$product_option_value['quantity'] . "', subtract = '" . (int)$product_option_value['subtract'] . "', price = '" . (float)$product_option_value['price'] . "', price_prefix = '" . $this->db->escape($product_option_value['price_prefix']) . "', points = '" . (int)$product_option_value['points'] . "', points_prefix = '" . $this->db->escape($product_option_value['points_prefix']) . "', weight = '" . (float)$product_option_value['weight'] . "', weight_prefix = '" . $this->db->escape($product_option_value['weight_prefix']) . "'");
  49. }
  50. }
  51. } else {
  52. $this->db->query("INSERT INTO " . DB_PREFIX . "product_option SET product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', option_value = '" . $this->db->escape($product_option['option_value']) . "', required = '" . (int)$product_option['required'] . "'");
  53. }
  54. }
  55. }
  56.  
  57. if (isset($data['product_discount'])) {
  58. foreach ($data['product_discount'] as $product_discount) {
  59. $this->db->query("INSERT INTO " . DB_PREFIX . "product_discount SET product_id = '" . (int)$product_id . "', customer_group_id = '" . (int)$product_discount['customer_group_id'] . "', quantity = '" . (int)$product_discount['quantity'] . "', priority = '" . (int)$product_discount['priority'] . "', price = '" . (float)$product_discount['price'] . "', date_start = '" . $this->db->escape($product_discount['date_start']) . "', date_end = '" . $this->db->escape($product_discount['date_end']) . "'");
  60. }
  61. }
  62.  
  63. if (isset($data['product_special'])) {
  64. foreach ($data['product_special'] as $product_special) {
  65. $this->db->query("INSERT INTO " . DB_PREFIX . "product_special SET product_id = '" . (int)$product_id . "', customer_group_id = '" . (int)$product_special['customer_group_id'] . "', priority = '" . (int)$product_special['priority'] . "', price = '" . (float)$product_special['price'] . "', date_start = '" . $this->db->escape($product_special['date_start']) . "', date_end = '" . $this->db->escape($product_special['date_end']) . "'");
  66. }
  67. }
  68.  
  69. if (isset($data['product_image'])) {
  70. foreach ($data['product_image'] as $product_image) {
  71. $this->db->query("INSERT INTO " . DB_PREFIX . "product_image SET product_id = '" . (int)$product_id . "', image = '" . $this->db->escape(html_entity_decode($product_image['image'], ENT_QUOTES, 'UTF-8')) . "', sort_order = '" . (int)$product_image['sort_order'] . "'");
  72. }
  73. }
  74.  
  75. if (isset($data['product_download'])) {
  76. foreach ($data['product_download'] as $download_id) {
  77. $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_download SET product_id = '" . (int)$product_id . "', download_id = '" . (int)$download_id . "'");
  78. }
  79. }
  80.  
  81. if (isset($data['product_category'])) {
  82. foreach ($data['product_category'] as $category_id) {
  83. $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_category SET product_id = '" . (int)$product_id . "', category_id = '" . (int)$category_id . "'");
  84. }
  85. }
  86.  
  87. if (isset($data['main_category_id']) && $data['main_category_id'] > 0) {
  88. $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "' AND category_id = '" . (int)$data['main_category_id'] . "'");
  89. $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_category SET product_id = '" . (int)$product_id . "', category_id = '" . (int)$data['main_category_id'] . "', main_category = 1");
  90. } elseif (isset($data['product_category'][0])) {
  91. $this->db->query("UPDATE " . DB_PREFIX . "product_to_category SET main_category = 1 WHERE product_id = '" . (int)$product_id . "' AND category_id = '" . (int)$data['product_category'][0] . "'");
  92. }
  93.  
  94. if (isset($data['product_related'])) {
  95. foreach ($data['product_related'] as $related_id) {
  96. $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "' AND related_id = '" . (int)$related_id . "'");
  97. $this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$product_id . "', related_id = '" . (int)$related_id . "'");
  98. $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$related_id . "' AND related_id = '" . (int)$product_id . "'");
  99. $this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$related_id . "', related_id = '" . (int)$product_id . "'");
  100. }
  101. }
  102.  
  103. if (isset($data['product_reward'])) {
  104. foreach ($data['product_reward'] as $customer_group_id => $product_reward) {
  105. $this->db->query("INSERT INTO " . DB_PREFIX . "product_reward SET product_id = '" . (int)$product_id . "', customer_group_id = '" . (int)$customer_group_id . "', points = '" . (int)$product_reward['points'] . "'");
  106. }
  107. }
  108.  
  109. if (isset($data['product_layout'])) {
  110. foreach ($data['product_layout'] as $store_id => $layout) {
  111. if ($layout['layout_id']) {
  112. $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_layout SET product_id = '" . (int)$product_id . "', store_id = '" . (int)$store_id . "', layout_id = '" . (int)$layout['layout_id'] . "'");
  113. }
  114. }
  115. }
  116.  
  117. foreach ($data['product_tag'] as $language_id => $value) {
  118. if ($value) {
  119. $tags = explode(',', $value);
  120.  
  121. foreach ($tags as $tag) {
  122. $this->db->query("INSERT INTO " . DB_PREFIX . "product_tag SET product_id = '" . (int)$product_id . "', language_id = '" . (int)$language_id . "', tag = '" . $this->db->escape(trim($tag)) . "'");
  123. }
  124. }
  125. }
  126.  
  127.  
  128. /* BEGIN Clear cache SEO */
  129. $this->cache->delete('seo_pro');
  130. $this->cache->delete('seo_url');
  131. /* END Clear cache SEO */
  132.  
  133. if ($data['keyword']) {
  134. $this->db->query("INSERT INTO " . DB_PREFIX . "url_alias SET query = 'product_id=" . (int)$product_id . "', keyword = '" . $this->db->escape($data['keyword']) . "'");
  135. } else {
  136. $this->load->model('catalog/manufacturer');
  137. $manufacturer = $this->model_catalog_manufacturer->getManufacturer((int)$data['manufacturer_id']);
  138. $manufacturerName = "";
  139. if ($manufacturer) {
  140. $manufacturerName = $manufacturer['name'];
  141. }
  142. $this->load->model('module/deadcow_seo');
  143. if ($productName) {
  144. $this->model_module_deadcow_seo->generateProduct($product_id, $productName, $data['model'], $manufacturerName, $this->config->get('deadcow_seo_products_template'), $this->config->get('config_language'));
  145. }
  146. }
  147.  
  148. $this->cache->delete('product');
  149. }
  150.  
  151. public function editProduct($product_id, $data) {
  152. $this->db->query("UPDATE " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "', sku = '" . $this->db->escape($data['sku']) . "', upc = '" . $this->db->escape($data['upc']) . "', 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'] . "', points = '" . (int)$data['points'] . "', 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 = '" . $this->db->escape($data['tax_class_id']) . "', sort_order = '" . (int)$data['sort_order'] . "', date_modified = NOW() WHERE product_id = '" . (int)$product_id . "'");
  153.  
  154. if (isset($data['image'])) {
  155. $this->db->query("UPDATE " . DB_PREFIX . "product SET image = '" . $this->db->escape(html_entity_decode($data['image'], ENT_QUOTES, 'UTF-8')) . "' WHERE product_id = '" . (int)$product_id . "'");
  156. }
  157.  
  158. $this->db->query("DELETE FROM " . DB_PREFIX . "product_description WHERE product_id = '" . (int)$product_id . "'");
  159.  
  160. $productName="";
  161. foreach ($data['product_description'] as $language_id => $value) {
  162. if ($language_id == $this->config->get('config_language_id')){
  163. $productName = $value['name'];
  164. }
  165.  
  166. $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_keyword = '" . $this->db->escape($value['meta_keyword']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', description = '" . $this->db->escape($value['description']) . "', seo_title = '" . $this->db->escape($value['seo_title']) . "', seo_h1 = '" . $this->db->escape($value['seo_h1']) . "'");
  167. }
  168.  
  169. $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_store WHERE product_id = '" . (int)$product_id . "'");
  170.  
  171. if (isset($data['product_store'])) {
  172. foreach ($data['product_store'] as $store_id) {
  173. $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_store SET product_id = '" . (int)$product_id . "', store_id = '" . (int)$store_id . "'");
  174. }
  175. }
  176.  
  177. $this->db->query("DELETE FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "'");
  178.  
  179. if (!empty($data['product_attribute'])) {
  180. foreach ($data['product_attribute'] as $product_attribute) {
  181. if ($product_attribute['attribute_id']) {
  182. $this->db->query("DELETE FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "' AND attribute_id = '" . (int)$product_attribute['attribute_id'] . "'");
  183.  
  184. foreach ($product_attribute['product_attribute_description'] as $language_id => $product_attribute_description) {
  185. $this->db->query("INSERT INTO " . DB_PREFIX . "product_attribute SET product_id = '" . (int)$product_id . "', attribute_id = '" . (int)$product_attribute['attribute_id'] . "', language_id = '" . (int)$language_id . "', text = '" . $this->db->escape($product_attribute_description['text']) . "'");
  186. }
  187. }
  188. }
  189. }
  190.  
  191. $this->db->query("DELETE FROM " . DB_PREFIX . "product_option WHERE product_id = '" . (int)$product_id . "'");
  192. $this->db->query("DELETE FROM " . DB_PREFIX . "product_option_value WHERE product_id = '" . (int)$product_id . "'");
  193.  
  194. if (isset($data['product_option'])) {
  195. foreach ($data['product_option'] as $product_option) {
  196. if ($product_option['type'] == 'select' || $product_option['type'] == 'radio' || $product_option['type'] == 'checkbox' || $product_option['type'] == 'image') {
  197. $this->db->query("INSERT INTO " . DB_PREFIX . "product_option SET product_option_id = '" . (int)$product_option['product_option_id'] . "', product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', required = '" . (int)$product_option['required'] . "'");
  198.  
  199. $product_option_id = $this->db->getLastId();
  200.  
  201. if (isset($product_option['product_option_value'])) {
  202. foreach ($product_option['product_option_value'] as $product_option_value) {
  203. $this->db->query("INSERT INTO " . DB_PREFIX . "product_option_value SET product_option_value_id = '" . (int)$product_option_value['product_option_value_id'] . "', product_option_id = '" . (int)$product_option_id . "', product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', option_value_id = '" . (int)$product_option_value['option_value_id'] . "', quantity = '" . (int)$product_option_value['quantity'] . "', subtract = '" . (int)$product_option_value['subtract'] . "', price = '" . (float)$product_option_value['price'] . "', price_prefix = '" . $this->db->escape($product_option_value['price_prefix']) . "', points = '" . (int)$product_option_value['points'] . "', points_prefix = '" . $this->db->escape($product_option_value['points_prefix']) . "', weight = '" . (float)$product_option_value['weight'] . "', weight_prefix = '" . $this->db->escape($product_option_value['weight_prefix']) . "'");
  204. }
  205. }
  206. } else {
  207. $this->db->query("INSERT INTO " . DB_PREFIX . "product_option SET product_option_id = '" . (int)$product_option['product_option_id'] . "', product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', option_value = '" . $this->db->escape($product_option['option_value']) . "', required = '" . (int)$product_option['required'] . "'");
  208. }
  209. }
  210. }
  211.  
  212. $this->db->query("DELETE FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "'");
  213.  
  214. if (isset($data['product_discount'])) {
  215. foreach ($data['product_discount'] as $product_discount) {
  216. $this->db->query("INSERT INTO " . DB_PREFIX . "product_discount SET product_id = '" . (int)$product_id . "', customer_group_id = '" . (int)$product_discount['customer_group_id'] . "', quantity = '" . (int)$product_discount['quantity'] . "', priority = '" . (int)$product_discount['priority'] . "', price = '" . (float)$product_discount['price'] . "', date_start = '" . $this->db->escape($product_discount['date_start']) . "', date_end = '" . $this->db->escape($product_discount['date_end']) . "'");
  217. }
  218. }
  219.  
  220. $this->db->query("DELETE FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "'");
  221.  
  222. if (isset($data['product_special'])) {
  223. foreach ($data['product_special'] as $product_special) {
  224. $this->db->query("INSERT INTO " . DB_PREFIX . "product_special SET product_id = '" . (int)$product_id . "', customer_group_id = '" . (int)$product_special['customer_group_id'] . "', priority = '" . (int)$product_special['priority'] . "', price = '" . (float)$product_special['price'] . "', date_start = '" . $this->db->escape($product_special['date_start']) . "', date_end = '" . $this->db->escape($product_special['date_end']) . "'");
  225. }
  226. }
  227.  
  228. $this->db->query("DELETE FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "'");
  229.  
  230. if (isset($data['product_image'])) {
  231. foreach ($data['product_image'] as $product_image) {
  232. $this->db->query("INSERT INTO " . DB_PREFIX . "product_image SET product_id = '" . (int)$product_id . "', image = '" . $this->db->escape(html_entity_decode($product_image['image'], ENT_QUOTES, 'UTF-8')) . "', sort_order = '" . (int)$product_image['sort_order'] . "'");
  233. }
  234. }
  235.  
  236. $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_download WHERE product_id = '" . (int)$product_id . "'");
  237.  
  238. if (isset($data['product_download'])) {
  239. foreach ($data['product_download'] as $download_id) {
  240. $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_download SET product_id = '" . (int)$product_id . "', download_id = '" . (int)$download_id . "'");
  241. }
  242. }
  243.  
  244. $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'");
  245.  
  246. if (isset($data['product_category'])) {
  247. foreach ($data['product_category'] as $category_id) {
  248. $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_category SET product_id = '" . (int)$product_id . "', category_id = '" . (int)$category_id . "'");
  249. }
  250. }
  251.  
  252. if (isset($data['main_category_id']) && $data['main_category_id'] > 0) {
  253. $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "' AND category_id = '" . (int)$data['main_category_id'] . "'");
  254. $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_category SET product_id = '" . (int)$product_id . "', category_id = '" . (int)$data['main_category_id'] . "', main_category = 1");
  255. } elseif (isset($data['product_category'])) {
  256. $this->db->query("UPDATE " . DB_PREFIX . "product_to_category SET main_category = 1 WHERE product_id = '" . (int)$product_id . "' AND category_id = '" . (int)$data['product_category'][0] . "'");
  257. }
  258.  
  259. $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "'");
  260. $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE related_id = '" . (int)$product_id . "'");
  261.  
  262. if (isset($data['product_related'])) {
  263. foreach ($data['product_related'] as $related_id) {
  264. $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "' AND related_id = '" . (int)$related_id . "'");
  265. $this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$product_id . "', related_id = '" . (int)$related_id . "'");
  266. $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$related_id . "' AND related_id = '" . (int)$product_id . "'");
  267. $this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$related_id . "', related_id = '" . (int)$product_id . "'");
  268. }
  269. }
  270.  
  271. $this->db->query("DELETE FROM " . DB_PREFIX . "product_reward WHERE product_id = '" . (int)$product_id . "'");
  272.  
  273. if (isset($data['product_reward'])) {
  274. foreach ($data['product_reward'] as $customer_group_id => $value) {
  275. $this->db->query("INSERT INTO " . DB_PREFIX . "product_reward SET product_id = '" . (int)$product_id . "', customer_group_id = '" . (int)$customer_group_id . "', points = '" . (int)$value['points'] . "'");
  276. }
  277. }
  278.  
  279. $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_layout WHERE product_id = '" . (int)$product_id . "'");
  280.  
  281. if (isset($data['product_layout'])) {
  282. foreach ($data['product_layout'] as $store_id => $layout) {
  283. if ($layout['layout_id']) {
  284. $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_layout SET product_id = '" . (int)$product_id . "', store_id = '" . (int)$store_id . "', layout_id = '" . (int)$layout['layout_id'] . "'");
  285. }
  286. }
  287. }
  288.  
  289. $this->db->query("DELETE FROM " . DB_PREFIX . "product_tag WHERE product_id = '" . (int)$product_id. "'");
  290.  
  291. foreach ($data['product_tag'] as $language_id => $value) {
  292. if ($value) {
  293. $tags = explode(',', $value);
  294.  
  295. foreach ($tags as $tag) {
  296. $this->db->query("INSERT INTO " . DB_PREFIX . "product_tag SET product_id = '" . (int)$product_id . "', language_id = '" . (int)$language_id . "', tag = '" . $this->db->escape(trim($tag)) . "'");
  297. }
  298. }
  299. }
  300.  
  301. $this->db->query("DELETE FROM " . DB_PREFIX . "url_alias WHERE query = 'product_id=" . (int)$product_id. "'");
  302.  
  303.  
  304. /* BEGIN Clear cache SEO */
  305. $this->cache->delete('seo_pro');
  306. $this->cache->delete('seo_url');
  307. /* END Clear cache SEO */
  308.  
  309. if ($data['keyword']) {
  310. $this->db->query("INSERT INTO " . DB_PREFIX . "url_alias SET query = 'product_id=" . (int)$product_id . "', keyword = '" . $this->db->escape($data['keyword']) . "'");
  311. } else {
  312. $this->load->model('catalog/manufacturer');
  313. $manufacturer = $this->model_catalog_manufacturer->getManufacturer((int)$data['manufacturer_id']);
  314. $manufacturerName = "";
  315. if ($manufacturer) {
  316. $manufacturerName = $manufacturer['name'];
  317. }
  318. $this->load->model('module/deadcow_seo');
  319. if ($productName) {
  320. $this->model_module_deadcow_seo->generateProduct($product_id, $productName, $data['model'], $manufacturerName, $this->config->get('deadcow_seo_products_template'), $this->config->get('config_language'));
  321. }
  322. }
  323.  
  324. $this->cache->delete('product');
  325. }
  326.  
  327. public function copyProduct($product_id) {
  328. $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') . "'");
  329.  
  330. if ($query->num_rows) {
  331. $data = array();
  332.  
  333. $data = $query->row;
  334.  
  335. $data['keyword'] = '';
  336.  
  337. $data['status'] = '0';
  338.  
  339. $data = array_merge($data, array('product_attribute' => $this->getProductAttributes($product_id)));
  340. $data = array_merge($data, array('product_description' => $this->getProductDescriptions($product_id)));
  341. $data = array_merge($data, array('product_discount' => $this->getProductDiscounts($product_id)));
  342. $data = array_merge($data, array('product_image' => $this->getProductImages($product_id)));
  343.  
  344. {#$data['product_image'] = array();
  345.  
  346. #$results = $this->getProductImages($product_id);
  347.  
  348. #foreach ($results as $result) {
  349. #$data['product_image'][] = $result['image'];
  350. }
  351.  
  352. $data = array_merge($data, array('product_option' => $this->getProductOptions($product_id)));
  353. $data = array_merge($data, array('product_related' => $this->getProductRelated($product_id)));
  354. $data = array_merge($data, array('product_reward' => $this->getProductRewards($product_id)));
  355. $data = array_merge($data, array('product_special' => $this->getProductSpecials($product_id)));
  356. $data = array_merge($data, array('product_tag' => $this->getProductTags($product_id)));
  357. $data = array_merge($data, array('product_category' => $this->getProductCategories($product_id)));
  358. $data = array_merge($data, array('product_download' => $this->getProductDownloads($product_id)));
  359. $data = array_merge($data, array('product_layout' => $this->getProductLayouts($product_id)));
  360. $data = array_merge($data, array('product_store' => $this->getProductStores($product_id)));
  361.  
  362. $this->addProduct($data);
  363. }
  364. }
  365.  
  366. public function deleteProduct($product_id) {
  367. $this->db->query("DELETE FROM " . DB_PREFIX . "product WHERE product_id = '" . (int)$product_id . "'");
  368. $this->db->query("DELETE FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "'");
  369. $this->db->query("DELETE FROM " . DB_PREFIX . "product_description WHERE product_id = '" . (int)$product_id . "'");
  370. $this->db->query("DELETE FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "'");
  371. $this->db->query("DELETE FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "'");
  372. $this->db->query("DELETE FROM " . DB_PREFIX . "product_option WHERE product_id = '" . (int)$product_id . "'");
  373. $this->db->query("DELETE FROM " . DB_PREFIX . "product_option_value WHERE product_id = '" . (int)$product_id . "'");
  374. $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "'");
  375. $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE related_id = '" . (int)$product_id . "'");
  376. $this->db->query("DELETE FROM " . DB_PREFIX . "product_reward WHERE product_id = '" . (int)$product_id . "'");
  377. $this->db->query("DELETE FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "'");
  378. $this->db->query("DELETE FROM " . DB_PREFIX . "product_tag WHERE product_id='" . (int)$product_id. "'");
  379. $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'");
  380. $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_download WHERE product_id = '" . (int)$product_id . "'");
  381. $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_layout WHERE product_id = '" . (int)$product_id . "'");
  382. $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_store WHERE product_id = '" . (int)$product_id . "'");
  383. $this->db->query("DELETE FROM " . DB_PREFIX . "review WHERE product_id = '" . (int)$product_id . "'");
  384.  
  385. $this->db->query("DELETE FROM " . DB_PREFIX . "url_alias WHERE query = 'product_id=" . (int)$product_id. "'");
  386.  
  387. $this->cache->delete('product');
  388. }
  389.  
  390. public function getProduct($product_id) {
  391. $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') . "'");
  392.  
  393. return $query->row;
  394. }
  395.  
  396. public function getProducts($data = array()) {
  397. if ($data) {
  398.  
  399. $sql = "SELECT p.*,pd.*, m.name as manufacturer, ua.keyword as seourl FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON ( p.manufacturer_id = m.manufacturer_id ) LEFT JOIN " . DB_PREFIX . "url_alias ua ON (CONCAT('product_id=', p.product_id) = ua.query)";
  400.  
  401.  
  402. if (!empty($data['filter_category_id'])) {
  403. $sql .= " LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id)";
  404. }
  405.  
  406. $sql .= " WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "'";
  407.  
  408. if (!empty($data['filter_name'])) {
  409. $sql .= " AND LCASE(pd.name) LIKE '%" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "%'";
  410. }
  411.  
  412. if (!empty($data['filter_model'])) {
  413. $sql .= " AND LCASE(p.model) LIKE '%" . $this->db->escape(utf8_strtolower($data['filter_model'])) . "%'";
  414. }
  415.  
  416.  
  417. if (!empty($data['filter_sku'])) {
  418. $sql .= " AND LCASE(p.sku) LIKE '%" . $this->db->escape(utf8_strtolower($data['filter_sku'])) . "%'";
  419. }
  420.  
  421. if (!empty($data['filter_price'])) {
  422. $sql .= " AND p.price LIKE '" . $this->db->escape($data['filter_price']) . "%'";
  423. }
  424.  
  425. if (isset($data['filter_quantity']) && !is_null($data['filter_quantity'])) {
  426. $sql .= " AND p.quantity = '" . $this->db->escape($data['filter_quantity']) . "'";
  427. }
  428.  
  429. if (isset($data['filter_status']) && !is_null($data['filter_status'])) {
  430. $sql .= " AND p.status = '" . (int)$data['filter_status'] . "'";
  431. }
  432.  
  433. if (!empty($data['filter_category_id'])) {
  434. if (!empty($data['filter_sub_category'])) {
  435. $implode_data = array();
  436.  
  437. $implode_data[] = "category_id = '" . (int)$data['filter_category_id'] . "'";
  438.  
  439. $this->load->model('catalog/category');
  440.  
  441. $categories = $this->model_catalog_category->getCategories($data['filter_category_id']);
  442.  
  443. foreach ($categories as $category) {
  444. $implode_data[] = "p2c.category_id = '" . (int)$category['category_id'] . "'";
  445. }
  446.  
  447. $sql .= " AND (" . implode(' OR ', $implode_data) . ")";
  448. } else {
  449. $sql .= " AND p2c.category_id = '" . (int)$data['filter_category_id'] . "'";
  450. }
  451. }
  452.  
  453.  
  454. if (isset($data['filter_manufacturer']) && !is_null($data['filter_manufacturer'])) {
  455. $sql .= " AND p.manufacturer_id = '" . (int)$data['filter_manufacturer'] . "'";
  456. }
  457.  
  458. $sql .= " GROUP BY p.product_id";
  459.  
  460. $sort_data = array(
  461.  
  462. 'p.sku',
  463.  
  464. 'pd.name',
  465. 'p.model',
  466. 'p.price',
  467. 'p.quantity',
  468. 'p.status',
  469. 'p.sort_order'
  470. );
  471.  
  472. if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
  473. $sql .= " ORDER BY " . $data['sort'];
  474. } else {
  475. $sql .= " ORDER BY pd.name";
  476. }
  477.  
  478. if (isset($data['order']) && ($data['order'] == 'DESC')) {
  479. $sql .= " DESC";
  480. } else {
  481. $sql .= " ASC";
  482. }
  483.  
  484. if (isset($data['start']) || isset($data['limit'])) {
  485. if ($data['start'] < 0) {
  486. $data['start'] = 0;
  487. }
  488.  
  489. if ($data['limit'] < 1) {
  490. $data['limit'] = 20;
  491. }
  492.  
  493. $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
  494. }
  495.  
  496. $query = $this->db->query($sql);
  497.  
  498. return $query->rows;
  499. } else {
  500. $product_data = $this->cache->get('product.' . (int)$this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id'));
  501.  
  502. if (!$product_data) {
  503. $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");
  504.  
  505. $product_data = $query->rows;
  506.  
  507. $this->cache->set('product.' . (int)$this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id'), $product_data);
  508. }
  509.  
  510. return $product_data;
  511. }
  512. }
  513.  
  514. public function getProductsByCategoryId($category_id) {
  515. $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");
  516.  
  517. return $query->rows;
  518. }
  519.  
  520. public function getProductDescriptions($product_id) {
  521. $product_description_data = array();
  522.  
  523. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_description WHERE product_id = '" . (int)$product_id . "'");
  524.  
  525. foreach ($query->rows as $result) {
  526. $product_description_data[$result['language_id']] = array(
  527. 'seo_title' => $result['seo_title'],
  528. 'seo_h1' => $result['seo_h1'],
  529. 'name' => $result['name'],
  530. 'description' => $result['description'],
  531. 'meta_keyword' => $result['meta_keyword'],
  532. 'meta_description' => $result['meta_description']
  533. );
  534. }
  535.  
  536. return $product_description_data;
  537. }
  538.  
  539. public function getProductAttributes($product_id) {
  540. $product_attribute_data = array();
  541.  
  542. $product_attribute_query = $this->db->query("SELECT pa.attribute_id, ad.name FROM " . DB_PREFIX . "product_attribute pa LEFT JOIN " . DB_PREFIX . "attribute a ON (pa.attribute_id = a.attribute_id) LEFT JOIN " . DB_PREFIX . "attribute_description ad ON (a.attribute_id = ad.attribute_id) WHERE pa.product_id = '" . (int)$product_id . "' AND ad.language_id = '" . (int)$this->config->get('config_language_id') . "' GROUP BY pa.attribute_id");
  543.  
  544. foreach ($product_attribute_query->rows as $product_attribute) {
  545. $product_attribute_description_data = array();
  546.  
  547. $product_attribute_description_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "' AND attribute_id = '" . (int)$product_attribute['attribute_id'] . "'");
  548.  
  549. foreach ($product_attribute_description_query->rows as $product_attribute_description) {
  550. $product_attribute_description_data[$product_attribute_description['language_id']] = array('text' => $product_attribute_description['text']);
  551. }
  552.  
  553. $product_attribute_data[] = array(
  554. 'attribute_id' => $product_attribute['attribute_id'],
  555. 'name' => $product_attribute['name'],
  556. 'product_attribute_description' => $product_attribute_description_data
  557. );
  558. }
  559.  
  560. return $product_attribute_data;
  561. }
  562.  
  563. public function getProductOptions($product_id) {
  564. $product_option_data = array();
  565.  
  566. $product_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option po LEFT JOIN `" . DB_PREFIX . "option` o ON (po.option_id = o.option_id) LEFT JOIN " . DB_PREFIX . "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");
  567.  
  568. foreach ($product_option_query->rows as $product_option) {
  569. if ($product_option['type'] == 'select' || $product_option['type'] == 'radio' || $product_option['type'] == 'checkbox' || $product_option['type'] == 'image') {
  570. $product_option_value_data = array();
  571.  
  572. $product_option_value_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value pov LEFT JOIN " . DB_PREFIX . "option_value ov ON (pov.option_value_id = ov.option_value_id) LEFT JOIN " . DB_PREFIX . "option_value_description ovd ON (ov.option_value_id = ovd.option_value_id) WHERE 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");
  573.  
  574. foreach ($product_option_value_query->rows as $product_option_value) {
  575. $product_option_value_data[] = array(
  576. 'product_option_value_id' => $product_option_value['product_option_value_id'],
  577. 'option_value_id' => $product_option_value['option_value_id'],
  578. 'name' => $product_option_value['name'],
  579. 'image' => $product_option_value['image'],
  580. 'quantity' => $product_option_value['quantity'],
  581. 'subtract' => $product_option_value['subtract'],
  582. 'price' => $product_option_value['price'],
  583. 'price_prefix' => $product_option_value['price_prefix'],
  584. 'points' => $product_option_value['points'],
  585. 'points_prefix' => $product_option_value['points_prefix'],
  586. 'weight' => $product_option_value['weight'],
  587. 'weight_prefix' => $product_option_value['weight_prefix']
  588. );
  589. }
  590.  
  591. $product_option_data[] = array(
  592. 'product_option_id' => $product_option['product_option_id'],
  593. 'option_id' => $product_option['option_id'],
  594. 'name' => $product_option['name'],
  595. 'type' => $product_option['type'],
  596. 'product_option_value' => $product_option_value_data,
  597. 'required' => $product_option['required']
  598. );
  599. } else {
  600. $product_option_data[] = array(
  601. 'product_option_id' => $product_option['product_option_id'],
  602. 'option_id' => $product_option['option_id'],
  603. 'name' => $product_option['name'],
  604. 'type' => $product_option['type'],
  605. 'option_value' => $product_option['option_value'],
  606. 'required' => $product_option['required']
  607. );
  608. }
  609. }
  610.  
  611. return $product_option_data;
  612. }
  613.  
  614. public function getProductImages($product_id) {
  615. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "'");
  616.  
  617. return $query->rows;
  618. }
  619.  
  620. public function getProductDiscounts($product_id) {
  621. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' ORDER BY quantity, priority, price");
  622.  
  623. return $query->rows;
  624. }
  625.  
  626. public function getProductSpecials($product_id) {
  627. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "' ORDER BY priority, price");
  628.  
  629. return $query->rows;
  630. }
  631.  
  632. public function getProductRewards($product_id) {
  633. $product_reward_data = array();
  634.  
  635. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_reward WHERE product_id = '" . (int)$product_id . "'");
  636.  
  637. foreach ($query->rows as $result) {
  638. $product_reward_data[$result['customer_group_id']] = array('points' => $result['points']);
  639. }
  640.  
  641. return $product_reward_data;
  642. }
  643.  
  644. public function getProductDownloads($product_id) {
  645. $product_download_data = array();
  646.  
  647. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_download WHERE product_id = '" . (int)$product_id . "'");
  648.  
  649. foreach ($query->rows as $result) {
  650. $product_download_data[] = $result['download_id'];
  651. }
  652.  
  653. return $product_download_data;
  654. }
  655.  
  656. public function getProductStores($product_id) {
  657. $product_store_data = array();
  658.  
  659. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_store WHERE product_id = '" . (int)$product_id . "'");
  660.  
  661. foreach ($query->rows as $result) {
  662. $product_store_data[] = $result['store_id'];
  663. }
  664.  
  665. return $product_store_data;
  666. }
  667.  
  668. public function getProductLayouts($product_id) {
  669. $product_layout_data = array();
  670.  
  671. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_layout WHERE product_id = '" . (int)$product_id . "'");
  672.  
  673. foreach ($query->rows as $result) {
  674. $product_layout_data[$result['store_id']] = $result['layout_id'];
  675. }
  676.  
  677. return $product_layout_data;
  678. }
  679.  
  680.  
  681. public function getProductCategoriesInfo($product_id) {
  682. $product_category_data = array();
  683.  
  684. $query = $this->db->query("SELECT c.*, cd.name FROM " . DB_PREFIX . "product_to_category c INNER JOIN " . DB_PREFIX . "category_description cd ON c.category_id = cd.category_id WHERE product_id = '" . (int)$product_id . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "' AND main_category = '0'");
  685.  
  686. foreach ($query->rows as $result) {
  687. $path = $this->model_catalog_category->getPath( $result['category_id'] );
  688. $product_category_data[] = array(
  689. 'id' => $result['category_id'],
  690. 'name' => $result['name'],
  691. 'path' => $path
  692. );
  693. }
  694. return $product_category_data;
  695. }
  696.  
  697. public function getProductMainCategoryInfo($product_id) {
  698. $product_category_data = array();
  699.  
  700. $query = $this->db->query("SELECT c.*, cd.name FROM " . DB_PREFIX . "product_to_category c INNER JOIN " . DB_PREFIX . "category_description cd ON c.category_id = cd.category_id WHERE product_id = '" . (int)$product_id . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "' AND main_category = '1'");
  701.  
  702. foreach ($query->rows as $result) {
  703. $path = $this->model_catalog_category->getPath( $result['category_id'] );
  704. $product_category_data[] = array(
  705. 'id' => $result['category_id'],
  706. 'name' => $result['name'],
  707. 'path' => $path
  708. );
  709. }
  710. return $product_category_data;
  711. }
  712.  
  713. public function getProductCategories($product_id) {
  714. $product_category_data = array();
  715.  
  716. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'");
  717.  
  718. foreach ($query->rows as $result) {
  719. $product_category_data[] = $result['category_id'];
  720. }
  721.  
  722. return $product_category_data;
  723. }
  724.  
  725. public function getProductMainCategoryId($product_id) {
  726. $query = $this->db->query("SELECT category_id FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "' AND main_category = '1' LIMIT 1");
  727.  
  728. return ($query->num_rows ? (int)$query->row['category_id'] : 0);
  729. }
  730.  
  731. public function getProductRelated($product_id) {
  732. $product_related_data = array();
  733.  
  734. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "'");
  735.  
  736. foreach ($query->rows as $result) {
  737. $product_related_data[] = $result['related_id'];
  738. }
  739.  
  740. return $product_related_data;
  741. }
  742.  
  743. public function getProductTags($product_id) {
  744. $product_tag_data = array();
  745.  
  746. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_tag WHERE product_id = '" . (int)$product_id . "'");
  747.  
  748. $tag_data = array();
  749.  
  750. foreach ($query->rows as $result) {
  751. $tag_data[$result['language_id']][] = $result['tag'];
  752. }
  753.  
  754. foreach ($tag_data as $language => $tags) {
  755. $product_tag_data[$language] = implode(',', $tags);
  756. }
  757.  
  758. return $product_tag_data;
  759. }
  760.  
  761. public function getTotalProducts($data = array()) {
  762. $sql = "SELECT COUNT(DISTINCT p.product_id) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id)";
  763.  
  764. if (!empty($data['filter_category_id'])) {
  765. $sql .= " LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id)";
  766. }
  767.  
  768. $sql .= " WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "'";
  769.  
  770. if (!empty($data['filter_name'])) {
  771. $sql .= " AND LCASE(pd.name) LIKE '%" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "%'";
  772. }
  773.  
  774. if (!empty($data['filter_model'])) {
  775. $sql .= " AND LCASE(p.model) LIKE '%" . $this->db->escape(utf8_strtolower($data['filter_model'])) . "%'";
  776. }
  777.  
  778.  
  779. if (!empty($data['filter_sku'])) {
  780. $sql .= " AND LCASE(p.sku) LIKE '%" . $this->db->escape(utf8_strtolower($data['filter_sku'])) . "%'";
  781. }
  782.  
  783. if (!empty($data['filter_price'])) {
  784. $sql .= " AND p.price LIKE '" . $this->db->escape($data['filter_price']) . "%'";
  785. }
  786.  
  787. if (isset($data['filter_quantity']) && !is_null($data['filter_quantity'])) {
  788. $sql .= " AND p.quantity = '" . $this->db->escape($data['filter_quantity']) . "'";
  789. }
  790.  
  791. if (isset($data['filter_status']) && !is_null($data['filter_status'])) {
  792. $sql .= " AND p.status = '" . (int)$data['filter_status'] . "'";
  793. }
  794.  
  795. if (!empty($data['filter_category_id'])) {
  796. if (!empty($data['filter_sub_category'])) {
  797. $implode_data = array();
  798.  
  799. $implode_data[] = "p2c.category_id = '" . (int)$data['filter_category_id'] . "'";
  800.  
  801. $this->load->model('catalog/category');
  802.  
  803. $categories = $this->model_catalog_category->getCategories($data['filter_category_id']);
  804.  
  805. foreach ($categories as $category) {
  806. $implode_data[] = "p2c.category_id = '" . (int)$category['category_id'] . "'";
  807. }
  808.  
  809. $sql .= " AND (" . implode(' OR ', $implode_data) . ")";
  810. } else {
  811. $sql .= " AND p2c.category_id = '" . (int)$data['filter_category_id'] . "'";
  812. }
  813. }
  814.  
  815. $query = $this->db->query($sql);
  816.  
  817. return $query->row['total'];
  818. }
  819.  
  820. public function getTotalProductsByTaxClassId($tax_class_id) {
  821. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE tax_class_id = '" . (int)$tax_class_id . "'");
  822.  
  823. return $query->row['total'];
  824. }
  825.  
  826. public function getTotalProductsByStockStatusId($stock_status_id) {
  827. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE stock_status_id = '" . (int)$stock_status_id . "'");
  828.  
  829. return $query->row['total'];
  830. }
  831.  
  832. public function getTotalProductsByWeightClassId($weight_class_id) {
  833. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE weight_class_id = '" . (int)$weight_class_id . "'");
  834.  
  835. return $query->row['total'];
  836. }
  837.  
  838. public function getTotalProductsByLengthClassId($length_class_id) {
  839. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE length_class_id = '" . (int)$length_class_id . "'");
  840.  
  841. return $query->row['total'];
  842. }
  843.  
  844. public function getTotalProductsByDownloadId($download_id) {
  845. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product_to_download WHERE download_id = '" . (int)$download_id . "'");
  846.  
  847. return $query->row['total'];
  848. }
  849.  
  850. public function getTotalProductsByManufacturerId($manufacturer_id) {
  851. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE manufacturer_id = '" . (int)$manufacturer_id . "'");
  852.  
  853. return $query->row['total'];
  854. }
  855.  
  856. public function getTotalProductsByAttributeId($attribute_id) {
  857. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product_attribute WHERE attribute_id = '" . (int)$attribute_id . "'");
  858.  
  859. return $query->row['total'];
  860. }
  861.  
  862. public function getTotalProductsByOptionId($option_id) {
  863. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product_option WHERE option_id = '" . (int)$option_id . "'");
  864.  
  865. return $query->row['total'];
  866. }
  867.  
  868. public function getTotalProductsByLayoutId($layout_id) {
  869. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product_to_layout WHERE layout_id = '" . (int)$layout_id . "'");
  870.  
  871. return $query->row['total'];
  872. }
  873. }
  874. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement