vq2-admin_model_catalog_product.php (41179B)
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']) . "', ean = '" . $this->db->escape($data['ean']) . "', jan = '" . $this->db->escape($data['jan']) . "', isbn = '" . $this->db->escape($data['isbn']) . "', mpn = '" . $this->db->escape($data['mpn']) . "', location = '" . $this->db->escape($data['location']) . "', quantity = '" . 5 (float)$data['quantity'] 6 . "', 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 = '" . (int)$data['tax_class_id'] . "', sort_order = '" . (int)$data['sort_order'] . "', date_added = NOW(), date_modified = NOW()"); 7 8 $product_id = $this->db->getLastId(); 9 10 if (isset($data['image'])) { 11 $this->db->query("UPDATE " . DB_PREFIX . "product SET image = '" . $this->db->escape($data['image']) . "' WHERE product_id = '" . (int)$product_id . "'"); 12 } 13 14 foreach ($data['product_description'] as $language_id => $value) { 15 $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']) . "', description = '" . $this->db->escape($value['description']) . "', tag = '" . $this->db->escape($value['tag']) . "', meta_title = '" . $this->db->escape($value['meta_title']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "'"); 16 } 17 18 if (isset($data['product_store'])) { 19 foreach ($data['product_store'] as $store_id) { 20 $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_store SET product_id = '" . (int)$product_id . "', store_id = '" . (int)$store_id . "'"); 21 } 22 } 23 24 if (isset($data['product_attribute'])) { 25 foreach ($data['product_attribute'] as $product_attribute) { 26 if ($product_attribute['attribute_id']) { 27 // Removes duplicates 28 $this->db->query("DELETE FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "' AND attribute_id = '" . (int)$product_attribute['attribute_id'] . "'"); 29 30 foreach ($product_attribute['product_attribute_description'] as $language_id => $product_attribute_description) { 31 $this->db->query("DELETE FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "' AND attribute_id = '" . (int)$product_attribute['attribute_id'] . "' AND language_id = '" . (int)$language_id . "'"); 32 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 if (isset($product_option['product_option_value'])) { 43 $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'] . "'"); 44 45 $product_option_id = $this->db->getLastId(); 46 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'] . "', value = '" . $this->db->escape($product_option['value']) . "', required = '" . (int)$product_option['required'] . "'"); 53 } 54 } 55 } 56 57 if (isset($data['product_recurring'])) { 58 foreach ($data['product_recurring'] as $recurring) { 59 $this->db->query("INSERT INTO `" . DB_PREFIX . "product_recurring` SET `product_id` = " . (int)$product_id . ", customer_group_id = " . (int)$recurring['customer_group_id'] . ", `recurring_id` = " . (int)$recurring['recurring_id']); 60 } 61 } 62 63 if (isset($data['product_discount'])) { 64 foreach ($data['product_discount'] as $product_discount) { 65 $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']) . "'"); 66 } 67 } 68 69 if (isset($data['product_special'])) { 70 foreach ($data['product_special'] as $product_special) { 71 $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']) . "'"); 72 } 73 } 74 75 if (isset($data['product_image'])) { 76 foreach ($data['product_image'] as $product_image) { 77 $this->db->query("INSERT INTO " . DB_PREFIX . "product_image SET product_id = '" . (int)$product_id . "', image = '" . $this->db->escape($product_image['image']) . "', sort_order = '" . (int)$product_image['sort_order'] . "'"); 78 } 79 } 80 81 if (isset($data['product_download'])) { 82 foreach ($data['product_download'] as $download_id) { 83 $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_download SET product_id = '" . (int)$product_id . "', download_id = '" . (int)$download_id . "'"); 84 } 85 } 86 87 if (isset($data['product_category'])) { 88 foreach ($data['product_category'] as $category_id) { 89 $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_category SET product_id = '" . (int)$product_id . "', category_id = '" . (int)$category_id . "'"); 90 } 91 } 92 93 if (isset($data['product_filter'])) { 94 foreach ($data['product_filter'] as $filter_id) { 95 $this->db->query("INSERT INTO " . DB_PREFIX . "product_filter SET product_id = '" . (int)$product_id . "', filter_id = '" . (int)$filter_id . "'"); 96 } 97 } 98 99 if (isset($data['product_related'])) { 100 foreach ($data['product_related'] as $related_id) { 101 $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "' AND related_id = '" . (int)$related_id . "'"); 102 $this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$product_id . "', related_id = '" . (int)$related_id . "'"); 103 $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$related_id . "' AND related_id = '" . (int)$product_id . "'"); 104 $this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$related_id . "', related_id = '" . (int)$product_id . "'"); 105 } 106 } 107 108 if (isset($data['product_reward'])) { 109 foreach ($data['product_reward'] as $customer_group_id => $product_reward) { 110 if ((int)$product_reward['points'] > 0) { 111 $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'] . "'"); 112 } 113 } 114 } 115 116 // SEO URL 117 if (isset($data['product_seo_url'])) { 118 foreach ($data['product_seo_url'] as $store_id => $language) { 119 foreach ($language as $language_id => $keyword) { 120 if (!empty($keyword)) { 121 $this->db->query("INSERT INTO " . DB_PREFIX . "seo_url SET store_id = '" . (int)$store_id . "', language_id = '" . (int)$language_id . "', query = 'product_id=" . (int)$product_id . "', keyword = '" . $this->db->escape($keyword) . "'"); 122 } 123 } 124 } 125 } 126 127 if (isset($data['product_layout'])) { 128 foreach ($data['product_layout'] as $store_id => $layout_id) { 129 $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_id . "'"); 130 } 131 } 132 133 134 $this->cache->delete('product'); 135 136 return $product_id; 137 } 138 139 public function editProduct($product_id, $data) { 140 $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']) . "', ean = '" . $this->db->escape($data['ean']) . "', jan = '" . $this->db->escape($data['jan']) . "', isbn = '" . $this->db->escape($data['isbn']) . "', mpn = '" . $this->db->escape($data['mpn']) . "', location = '" . $this->db->escape($data['location']) . "', quantity = '" . 141 (float)$data['quantity'] 142 . "', 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 = '" . (int)$data['tax_class_id'] . "', sort_order = '" . (int)$data['sort_order'] . "', date_modified = NOW() WHERE product_id = '" . (int)$product_id . "'"); 143 144 if (isset($data['image'])) { 145 $this->db->query("UPDATE " . DB_PREFIX . "product SET image = '" . $this->db->escape($data['image']) . "' WHERE product_id = '" . (int)$product_id . "'"); 146 } 147 148 $this->db->query("DELETE FROM " . DB_PREFIX . "product_description WHERE product_id = '" . (int)$product_id . "'"); 149 150 foreach ($data['product_description'] as $language_id => $value) { 151 $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']) . "', description = '" . $this->db->escape($value['description']) . "', tag = '" . $this->db->escape($value['tag']) . "', meta_title = '" . $this->db->escape($value['meta_title']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "'"); 152 } 153 154 $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_store WHERE product_id = '" . (int)$product_id . "'"); 155 156 if (isset($data['product_store'])) { 157 foreach ($data['product_store'] as $store_id) { 158 $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_store SET product_id = '" . (int)$product_id . "', store_id = '" . (int)$store_id . "'"); 159 } 160 } 161 162 $this->db->query("DELETE FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "'"); 163 164 if (!empty($data['product_attribute'])) { 165 foreach ($data['product_attribute'] as $product_attribute) { 166 if ($product_attribute['attribute_id']) { 167 // Removes duplicates 168 $this->db->query("DELETE FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "' AND attribute_id = '" . (int)$product_attribute['attribute_id'] . "'"); 169 170 foreach ($product_attribute['product_attribute_description'] as $language_id => $product_attribute_description) { 171 $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']) . "'"); 172 } 173 } 174 } 175 } 176 177 $this->db->query("DELETE FROM " . DB_PREFIX . "product_option WHERE product_id = '" . (int)$product_id . "'"); 178 $this->db->query("DELETE FROM " . DB_PREFIX . "product_option_value WHERE product_id = '" . (int)$product_id . "'"); 179 180 if (isset($data['product_option'])) { 181 foreach ($data['product_option'] as $product_option) { 182 if ($product_option['type'] == 'select' || $product_option['type'] == 'radio' || $product_option['type'] == 'checkbox' || $product_option['type'] == 'image') { 183 if (isset($product_option['product_option_value'])) { 184 $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'] . "'"); 185 186 $product_option_id = $this->db->getLastId(); 187 188 foreach ($product_option['product_option_value'] as $product_option_value) { 189 $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']) . "'"); 190 } 191 } 192 } else { 193 $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'] . "', value = '" . $this->db->escape($product_option['value']) . "', required = '" . (int)$product_option['required'] . "'"); 194 } 195 } 196 } 197 198 $this->db->query("DELETE FROM `" . DB_PREFIX . "product_recurring` WHERE product_id = " . (int)$product_id); 199 200 if (isset($data['product_recurring'])) { 201 foreach ($data['product_recurring'] as $product_recurring) { 202 $this->db->query("INSERT INTO `" . DB_PREFIX . "product_recurring` SET `product_id` = " . (int)$product_id . ", customer_group_id = " . (int)$product_recurring['customer_group_id'] . ", `recurring_id` = " . (int)$product_recurring['recurring_id']); 203 } 204 } 205 206 $this->db->query("DELETE FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "'"); 207 208 if (isset($data['product_discount'])) { 209 foreach ($data['product_discount'] as $product_discount) { 210 $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']) . "'"); 211 } 212 } 213 214 $this->db->query("DELETE FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "'"); 215 216 if (isset($data['product_special'])) { 217 foreach ($data['product_special'] as $product_special) { 218 $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']) . "'"); 219 } 220 } 221 222 $this->db->query("DELETE FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "'"); 223 224 if (isset($data['product_image'])) { 225 foreach ($data['product_image'] as $product_image) { 226 $this->db->query("INSERT INTO " . DB_PREFIX . "product_image SET product_id = '" . (int)$product_id . "', image = '" . $this->db->escape($product_image['image']) . "', sort_order = '" . (int)$product_image['sort_order'] . "'"); 227 } 228 } 229 230 $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_download WHERE product_id = '" . (int)$product_id . "'"); 231 232 if (isset($data['product_download'])) { 233 foreach ($data['product_download'] as $download_id) { 234 $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_download SET product_id = '" . (int)$product_id . "', download_id = '" . (int)$download_id . "'"); 235 } 236 } 237 238 $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'"); 239 240 if (isset($data['product_category'])) { 241 foreach ($data['product_category'] as $category_id) { 242 $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_category SET product_id = '" . (int)$product_id . "', category_id = '" . (int)$category_id . "'"); 243 } 244 } 245 246 $this->db->query("DELETE FROM " . DB_PREFIX . "product_filter WHERE product_id = '" . (int)$product_id . "'"); 247 248 if (isset($data['product_filter'])) { 249 foreach ($data['product_filter'] as $filter_id) { 250 $this->db->query("INSERT INTO " . DB_PREFIX . "product_filter SET product_id = '" . (int)$product_id . "', filter_id = '" . (int)$filter_id . "'"); 251 } 252 } 253 254 $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "'"); 255 $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE related_id = '" . (int)$product_id . "'"); 256 257 if (isset($data['product_related'])) { 258 foreach ($data['product_related'] as $related_id) { 259 $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "' AND related_id = '" . (int)$related_id . "'"); 260 $this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$product_id . "', related_id = '" . (int)$related_id . "'"); 261 $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$related_id . "' AND related_id = '" . (int)$product_id . "'"); 262 $this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$related_id . "', related_id = '" . (int)$product_id . "'"); 263 } 264 } 265 266 $this->db->query("DELETE FROM " . DB_PREFIX . "product_reward WHERE product_id = '" . (int)$product_id . "'"); 267 268 if (isset($data['product_reward'])) { 269 foreach ($data['product_reward'] as $customer_group_id => $value) { 270 if ((int)$value['points'] > 0) { 271 $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'] . "'"); 272 } 273 } 274 } 275 276 // SEO URL 277 $this->db->query("DELETE FROM " . DB_PREFIX . "seo_url WHERE query = 'product_id=" . (int)$product_id . "'"); 278 279 if (isset($data['product_seo_url'])) { 280 foreach ($data['product_seo_url']as $store_id => $language) { 281 foreach ($language as $language_id => $keyword) { 282 if (!empty($keyword)) { 283 $this->db->query("INSERT INTO " . DB_PREFIX . "seo_url SET store_id = '" . (int)$store_id . "', language_id = '" . (int)$language_id . "', query = 'product_id=" . (int)$product_id . "', keyword = '" . $this->db->escape($keyword) . "'"); 284 } 285 } 286 } 287 } 288 289 $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_layout WHERE product_id = '" . (int)$product_id . "'"); 290 291 if (isset($data['product_layout'])) { 292 foreach ($data['product_layout'] as $store_id => $layout_id) { 293 $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_id . "'"); 294 } 295 } 296 297 $this->cache->delete('product'); 298 } 299 300 public function copyProduct($product_id) { 301 $query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "product p WHERE p.product_id = '" . (int)$product_id . "'"); 302 303 if ($query->num_rows) { 304 $data = $query->row; 305 306 $data['sku'] = ''; 307 $data['upc'] = ''; 308 $data['viewed'] = '0'; 309 $data['keyword'] = ''; 310 $data['status'] = '0'; 311 312 $data['product_attribute'] = $this->getProductAttributes($product_id); 313 $data['product_description'] = $this->getProductDescriptions($product_id); 314 $data['product_discount'] = $this->getProductDiscounts($product_id); 315 $data['product_filter'] = $this->getProductFilters($product_id); 316 $data['product_image'] = $this->getProductImages($product_id); 317 $data['product_option'] = $this->getProductOptions($product_id); 318 $data['product_related'] = $this->getProductRelated($product_id); 319 $data['product_reward'] = $this->getProductRewards($product_id); 320 $data['product_special'] = $this->getProductSpecials($product_id); 321 $data['product_category'] = $this->getProductCategories($product_id); 322 $data['product_download'] = $this->getProductDownloads($product_id); 323 $data['product_layout'] = $this->getProductLayouts($product_id); 324 $data['product_store'] = $this->getProductStores($product_id); 325 $data['product_recurrings'] = $this->getRecurrings($product_id); 326 327 $this->addProduct($data); 328 } 329 } 330 331 public function deleteProduct($product_id) { 332 $this->db->query("DELETE FROM " . DB_PREFIX . "product WHERE product_id = '" . (int)$product_id . "'"); 333 $this->db->query("DELETE FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "'"); 334 $this->db->query("DELETE FROM " . DB_PREFIX . "product_description WHERE product_id = '" . (int)$product_id . "'"); 335 $this->db->query("DELETE FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "'"); 336 $this->db->query("DELETE FROM " . DB_PREFIX . "product_filter WHERE product_id = '" . (int)$product_id . "'"); 337 $this->db->query("DELETE FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "'"); 338 $this->db->query("DELETE FROM " . DB_PREFIX . "product_option WHERE product_id = '" . (int)$product_id . "'"); 339 $this->db->query("DELETE FROM " . DB_PREFIX . "product_option_value WHERE product_id = '" . (int)$product_id . "'"); 340 $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "'"); 341 $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE related_id = '" . (int)$product_id . "'"); 342 $this->db->query("DELETE FROM " . DB_PREFIX . "product_reward WHERE product_id = '" . (int)$product_id . "'"); 343 $this->db->query("DELETE FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "'"); 344 $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'"); 345 $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_download WHERE product_id = '" . (int)$product_id . "'"); 346 $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_layout WHERE product_id = '" . (int)$product_id . "'"); 347 $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_store WHERE product_id = '" . (int)$product_id . "'"); 348 $this->db->query("DELETE FROM " . DB_PREFIX . "product_recurring WHERE product_id = " . (int)$product_id); 349 $this->db->query("DELETE FROM " . DB_PREFIX . "review WHERE product_id = '" . (int)$product_id . "'"); 350 $this->db->query("DELETE FROM " . DB_PREFIX . "seo_url WHERE query = 'product_id=" . (int)$product_id . "'"); 351 $this->db->query("DELETE FROM " . DB_PREFIX . "coupon_product WHERE product_id = '" . (int)$product_id . "'"); 352 353 $this->cache->delete('product'); 354 } 355 356 public function getProduct($product_id) { 357 $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') . "'"); 358 359 return $query->row; 360 } 361 362 public function getProducts($data = array()) { 363 $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') . "'"; 364 365 if (!empty($data['filter_name'])) { 366 $sql .= " AND pd.name LIKE '" . $this->db->escape($data['filter_name']) . "%'"; 367 } 368 369 if (!empty($data['filter_model'])) { 370 $sql .= " AND p.model LIKE '" . $this->db->escape($data['filter_model']) . "%'"; 371 } 372 373 if (!empty($data['filter_price'])) { 374 $sql .= " AND p.price LIKE '" . $this->db->escape($data['filter_price']) . "%'"; 375 } 376 377 if (isset($data['filter_quantity']) && $data['filter_quantity'] !== '') { 378 $sql .= " AND p.quantity = '" . (int)$data['filter_quantity'] . "'"; 379 } 380 381 if (isset($data['filter_status']) && $data['filter_status'] !== '') { 382 $sql .= " AND p.status = '" . (int)$data['filter_status'] . "'"; 383 } 384 385 $sql .= " GROUP BY p.product_id"; 386 387 $sort_data = array( 388 'pd.name', 389 'p.model', 390 'p.price', 391 'p.quantity', 392 'p.status', 393 'p.sort_order' 394 ); 395 396 if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { 397 $sql .= " ORDER BY " . $data['sort']; 398 } else { 399 $sql .= " ORDER BY pd.name"; 400 } 401 402 if (isset($data['order']) && ($data['order'] == 'DESC')) { 403 $sql .= " DESC"; 404 } else { 405 $sql .= " ASC"; 406 } 407 408 if (isset($data['start']) || isset($data['limit'])) { 409 if ($data['start'] < 0) { 410 $data['start'] = 0; 411 } 412 413 if ($data['limit'] < 1) { 414 $data['limit'] = 20; 415 } 416 417 $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; 418 } 419 420 $query = $this->db->query($sql); 421 422 return $query->rows; 423 } 424 425 public function getProductsByCategoryId($category_id) { 426 $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"); 427 428 return $query->rows; 429 } 430 431 public function getProductDescriptions($product_id) { 432 $product_description_data = array(); 433 434 $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_description WHERE product_id = '" . (int)$product_id . "'"); 435 436 foreach ($query->rows as $result) { 437 $product_description_data[$result['language_id']] = array( 438 'name' => $result['name'], 439 'description' => $result['description'], 440 'meta_title' => $result['meta_title'], 441 'meta_description' => $result['meta_description'], 442 'meta_keyword' => $result['meta_keyword'], 443 'tag' => $result['tag'] 444 ); 445 } 446 447 return $product_description_data; 448 } 449 450 public function getProductCategories($product_id) { 451 $product_category_data = array(); 452 453 $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'"); 454 455 foreach ($query->rows as $result) { 456 $product_category_data[] = $result['category_id']; 457 } 458 459 return $product_category_data; 460 } 461 462 public function getProductFilters($product_id) { 463 $product_filter_data = array(); 464 465 $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_filter WHERE product_id = '" . (int)$product_id . "'"); 466 467 foreach ($query->rows as $result) { 468 $product_filter_data[] = $result['filter_id']; 469 } 470 471 return $product_filter_data; 472 } 473 474 public function getProductAttributes($product_id) { 475 $product_attribute_data = array(); 476 477 $product_attribute_query = $this->db->query("SELECT attribute_id FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "' GROUP BY attribute_id"); 478 479 foreach ($product_attribute_query->rows as $product_attribute) { 480 $product_attribute_description_data = array(); 481 482 $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'] . "'"); 483 484 foreach ($product_attribute_description_query->rows as $product_attribute_description) { 485 $product_attribute_description_data[$product_attribute_description['language_id']] = array('text' => $product_attribute_description['text']); 486 } 487 488 $product_attribute_data[] = array( 489 'attribute_id' => $product_attribute['attribute_id'], 490 'product_attribute_description' => $product_attribute_description_data 491 ); 492 } 493 494 return $product_attribute_data; 495 } 496 497 public function getProductOptions($product_id) { 498 $product_option_data = array(); 499 500 $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') . "'"); 501 502 foreach ($product_option_query->rows as $product_option) { 503 $product_option_value_data = array(); 504 505 $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) WHERE pov.product_option_id = '" . (int)$product_option['product_option_id'] . "' ORDER BY ov.sort_order ASC"); 506 507 foreach ($product_option_value_query->rows as $product_option_value) { 508 $product_option_value_data[] = array( 509 'product_option_value_id' => $product_option_value['product_option_value_id'], 510 'option_value_id' => $product_option_value['option_value_id'], 511 'quantity' => $product_option_value['quantity'], 512 'subtract' => $product_option_value['subtract'], 513 'price' => $product_option_value['price'], 514 'price_prefix' => $product_option_value['price_prefix'], 515 'points' => $product_option_value['points'], 516 'points_prefix' => $product_option_value['points_prefix'], 517 'weight' => $product_option_value['weight'], 518 'weight_prefix' => $product_option_value['weight_prefix'] 519 ); 520 } 521 522 $product_option_data[] = array( 523 'product_option_id' => $product_option['product_option_id'], 524 'product_option_value' => $product_option_value_data, 525 'option_id' => $product_option['option_id'], 526 'name' => $product_option['name'], 527 'type' => $product_option['type'], 528 'value' => $product_option['value'], 529 'required' => $product_option['required'] 530 ); 531 } 532 533 return $product_option_data; 534 } 535 536 public function getProductOptionValue($product_id, $product_option_value_id) { 537 $query = $this->db->query("SELECT pov.option_value_id, ovd.name, pov.quantity, pov.subtract, pov.price, pov.price_prefix, pov.points, pov.points_prefix, pov.weight, pov.weight_prefix 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_id = '" . (int)$product_id . "' AND pov.product_option_value_id = '" . (int)$product_option_value_id . "' AND ovd.language_id = '" . (int)$this->config->get('config_language_id') . "'"); 538 539 return $query->row; 540 } 541 542 public function getProductImages($product_id) { 543 $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "' ORDER BY sort_order ASC"); 544 545 return $query->rows; 546 } 547 548 public function getProductDiscounts($product_id) { 549 $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' ORDER BY quantity, priority, price"); 550 551 return $query->rows; 552 } 553 554 public function getProductSpecials($product_id) { 555 $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "' ORDER BY priority, price"); 556 557 return $query->rows; 558 } 559 560 public function getProductRewards($product_id) { 561 $product_reward_data = array(); 562 563 $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_reward WHERE product_id = '" . (int)$product_id . "'"); 564 565 foreach ($query->rows as $result) { 566 $product_reward_data[$result['customer_group_id']] = array('points' => $result['points']); 567 } 568 569 return $product_reward_data; 570 } 571 572 public function getProductDownloads($product_id) { 573 $product_download_data = array(); 574 575 $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_download WHERE product_id = '" . (int)$product_id . "'"); 576 577 foreach ($query->rows as $result) { 578 $product_download_data[] = $result['download_id']; 579 } 580 581 return $product_download_data; 582 } 583 584 public function getProductStores($product_id) { 585 $product_store_data = array(); 586 587 $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_store WHERE product_id = '" . (int)$product_id . "'"); 588 589 foreach ($query->rows as $result) { 590 $product_store_data[] = $result['store_id']; 591 } 592 593 return $product_store_data; 594 } 595 596 public function getProductSeoUrls($product_id) { 597 $product_seo_url_data = array(); 598 599 $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE query = 'product_id=" . (int)$product_id . "'"); 600 601 foreach ($query->rows as $result) { 602 $product_seo_url_data[$result['store_id']][$result['language_id']] = $result['keyword']; 603 } 604 605 return $product_seo_url_data; 606 } 607 608 public function getProductLayouts($product_id) { 609 $product_layout_data = array(); 610 611 $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_layout WHERE product_id = '" . (int)$product_id . "'"); 612 613 foreach ($query->rows as $result) { 614 $product_layout_data[$result['store_id']] = $result['layout_id']; 615 } 616 617 return $product_layout_data; 618 } 619 620 public function getProductRelated($product_id) { 621 $product_related_data = array(); 622 623 $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "'"); 624 625 foreach ($query->rows as $result) { 626 $product_related_data[] = $result['related_id']; 627 } 628 629 return $product_related_data; 630 } 631 632 public function getRecurrings($product_id) { 633 $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "product_recurring` WHERE product_id = '" . (int)$product_id . "'"); 634 635 return $query->rows; 636 } 637 638 public function getTotalProducts($data = array()) { 639 $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)"; 640 641 $sql .= " WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "'"; 642 643 if (!empty($data['filter_name'])) { 644 $sql .= " AND pd.name LIKE '" . $this->db->escape($data['filter_name']) . "%'"; 645 } 646 647 if (!empty($data['filter_model'])) { 648 $sql .= " AND p.model LIKE '" . $this->db->escape($data['filter_model']) . "%'"; 649 } 650 651 if (isset($data['filter_price']) && !is_null($data['filter_price'])) { 652 $sql .= " AND p.price LIKE '" . $this->db->escape($data['filter_price']) . "%'"; 653 } 654 655 if (isset($data['filter_quantity']) && $data['filter_quantity'] !== '') { 656 $sql .= " AND p.quantity = '" . (int)$data['filter_quantity'] . "'"; 657 } 658 659 if (isset($data['filter_status']) && $data['filter_status'] !== '') { 660 $sql .= " AND p.status = '" . (int)$data['filter_status'] . "'"; 661 } 662 663 $query = $this->db->query($sql); 664 665 return $query->row['total']; 666 } 667 668 public function getTotalProductsByTaxClassId($tax_class_id) { 669 $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE tax_class_id = '" . (int)$tax_class_id . "'"); 670 671 return $query->row['total']; 672 } 673 674 public function getTotalProductsByStockStatusId($stock_status_id) { 675 $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE stock_status_id = '" . (int)$stock_status_id . "'"); 676 677 return $query->row['total']; 678 } 679 680 public function getTotalProductsByWeightClassId($weight_class_id) { 681 $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE weight_class_id = '" . (int)$weight_class_id . "'"); 682 683 return $query->row['total']; 684 } 685 686 public function getTotalProductsByLengthClassId($length_class_id) { 687 $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE length_class_id = '" . (int)$length_class_id . "'"); 688 689 return $query->row['total']; 690 } 691 692 public function getTotalProductsByDownloadId($download_id) { 693 $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product_to_download WHERE download_id = '" . (int)$download_id . "'"); 694 695 return $query->row['total']; 696 } 697 698 public function getTotalProductsByManufacturerId($manufacturer_id) { 699 $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE manufacturer_id = '" . (int)$manufacturer_id . "'"); 700 701 return $query->row['total']; 702 } 703 704 public function getTotalProductsByAttributeId($attribute_id) { 705 $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product_attribute WHERE attribute_id = '" . (int)$attribute_id . "'"); 706 707 return $query->row['total']; 708 } 709 710 public function getTotalProductsByOptionId($option_id) { 711 $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product_option WHERE option_id = '" . (int)$option_id . "'"); 712 713 return $query->row['total']; 714 } 715 716 public function getTotalProductsByProfileId($recurring_id) { 717 $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product_recurring WHERE recurring_id = '" . (int)$recurring_id . "'"); 718 719 return $query->row['total']; 720 } 721 722 public function getTotalProductsByLayoutId($layout_id) { 723 $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product_to_layout WHERE layout_id = '" . (int)$layout_id . "'"); 724 725 return $query->row['total']; 726 } 727 }