PageRenderTime 71ms CodeModel.GetById 14ms app.highlight 48ms RepoModel.GetById 1ms app.codeStats 1ms

/admin/model/catalog/product.php

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