Created
September 20, 2011 05:55
-
-
Save jzmwebdevelopment/1228467 to your computer and use it in GitHub Desktop.
OpenCart V5 Product MVC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ControllerProductProduct extends Controller { | |
private $error = array(); | |
public function index() { | |
$this->language->load('product/product'); | |
$this->data['breadcrumbs'] = array(); | |
$this->data['breadcrumbs'][] = array( | |
'text' => $this->language->get('text_home'), | |
'href' => $this->url->link('common/home'), | |
'separator' => false | |
); | |
$this->load->model('catalog/category'); | |
if (isset($this->request->get['path'])) { | |
$path = ''; | |
foreach (explode('_', $this->request->get['path']) as $path_id) { | |
if (!$path) { | |
$path = $path_id; | |
} else { | |
$path .= '_' . $path_id; | |
} | |
$category_info = $this->model_catalog_category->getCategory($path_id); | |
if ($category_info) { | |
$this->data['breadcrumbs'][] = array( | |
'text' => $category_info['name'], | |
'href' => $this->url->link('product/category', 'path=' . $path), | |
'separator' => $this->language->get('text_separator') | |
); | |
} | |
} | |
} | |
$this->load->model('catalog/manufacturer'); | |
if (isset($this->request->get['manufacturer_id'])) { | |
$this->data['breadcrumbs'][] = array( | |
'text' => $this->language->get('text_brand'), | |
'href' => $this->url->link('product/manufacturer'), | |
'separator' => $this->language->get('text_separator') | |
); | |
$manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($this->request->get['manufacturer_id']); | |
if ($manufacturer_info) { | |
$this->data['breadcrumbs'][] = array( | |
'text' => $manufacturer_info['name'], | |
'href' => $this->url->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id']), | |
'separator' => $this->language->get('text_separator') | |
); | |
} | |
} | |
if (isset($this->request->get['filter_name']) || isset($this->request->get['filter_tag'])) { | |
$url = ''; | |
if (isset($this->request->get['filter_name'])) { | |
$url .= '&filter_name=' . $this->request->get['filter_name']; | |
} | |
if (isset($this->request->get['filter_tag'])) { | |
$url .= '&filter_tag=' . $this->request->get['filter_tag']; | |
} | |
if (isset($this->request->get['filter_description'])) { | |
$url .= '&filter_description=' . $this->request->get['filter_description']; | |
} | |
if (isset($this->request->get['filter_category_id'])) { | |
$url .= '&filter_category_id=' . $this->request->get['filter_category_id']; | |
} | |
$this->data['breadcrumbs'][] = array( | |
'text' => $this->language->get('text_search'), | |
'href' => $this->url->link('product/search', $url), | |
'separator' => $this->language->get('text_separator') | |
); | |
} | |
if (isset($this->request->get['product_id'])) { | |
$product_id = $this->request->get['product_id']; | |
} else { | |
$product_id = 0; | |
} | |
$this->load->model('catalog/product'); | |
$product_info = $this->model_catalog_product->getProduct($product_id); | |
$this->data['product_info'] = $product_info; | |
if ($product_info) { | |
$url = ''; | |
if (isset($this->request->get['path'])) { | |
$url .= '&path=' . $this->request->get['path']; | |
} | |
if (isset($this->request->get['manufacturer_id'])) { | |
$url .= '&manufacturer_id=' . $this->request->get['manufacturer_id']; | |
} | |
if (isset($this->request->get['filter_name'])) { | |
$url .= '&filter_name=' . $this->request->get['filter_name']; | |
} | |
if (isset($this->request->get['filter_tag'])) { | |
$url .= '&filter_tag=' . $this->request->get['filter_tag']; | |
} | |
if (isset($this->request->get['filter_description'])) { | |
$url .= '&filter_description=' . $this->request->get['filter_description']; | |
} | |
if (isset($this->request->get['filter_category_id'])) { | |
$url .= '&filter_category_id=' . $this->request->get['filter_category_id']; | |
} | |
$this->data['breadcrumbs'][] = array( | |
'text' => $product_info['name'], | |
'href' => $this->url->link('product/product', $url . '&product_id=' . $this->request->get['product_id']), | |
'separator' => $this->language->get('text_separator') | |
); | |
$this->document->setTitle($product_info['name']); | |
$this->document->setDescription($product_info['meta_description']); | |
$this->document->setKeywords($product_info['meta_keyword']); | |
$this->document->addLink($this->url->link('product/product', 'product_id=' . $this->request->get['product_id']), 'canonical'); | |
$this->data['heading_title'] = $product_info['name']; | |
$this->data['text_select'] = $this->language->get('text_select'); | |
$this->data['text_manufacturer'] = $this->language->get('text_manufacturer'); | |
$this->data['text_model'] = $this->language->get('text_model'); | |
$this->data['text_reward'] = $this->language->get('text_reward'); | |
$this->data['text_points'] = $this->language->get('text_points'); | |
$this->data['text_discount'] = $this->language->get('text_discount'); | |
$this->data['text_stock'] = $this->language->get('text_stock'); | |
$this->data['text_price'] = $this->language->get('text_price'); | |
$this->data['text_tax'] = $this->language->get('text_tax'); | |
$this->data['text_discount'] = $this->language->get('text_discount'); | |
$this->data['text_option'] = $this->language->get('text_option'); | |
$this->data['text_qty'] = $this->language->get('text_qty'); | |
$this->data['text_minimum'] = sprintf($this->language->get('text_minimum'), $product_info['minimum']); | |
$this->data['text_or'] = $this->language->get('text_or'); | |
$this->data['text_write'] = $this->language->get('text_write'); | |
$this->data['text_note'] = $this->language->get('text_note'); | |
$this->data['text_share'] = $this->language->get('text_share'); | |
$this->data['text_wait'] = $this->language->get('text_wait'); | |
$this->data['text_tags'] = $this->language->get('text_tags'); | |
$this->data['entry_name'] = $this->language->get('entry_name'); | |
$this->data['entry_review'] = $this->language->get('entry_review'); | |
$this->data['entry_rating'] = $this->language->get('entry_rating'); | |
$this->data['entry_good'] = $this->language->get('entry_good'); | |
$this->data['entry_bad'] = $this->language->get('entry_bad'); | |
$this->data['entry_captcha'] = $this->language->get('entry_captcha'); | |
$this->data['button_cart'] = $this->language->get('button_cart'); | |
$this->data['button_wishlist'] = $this->language->get('button_wishlist'); | |
$this->data['button_compare'] = $this->language->get('button_compare'); | |
$this->data['button_upload'] = $this->language->get('button_upload'); | |
$this->data['button_continue'] = $this->language->get('button_continue'); | |
$this->load->model('catalog/review'); | |
$this->data['tab_description'] = $this->language->get('tab_description'); | |
$this->data['tab_attribute'] = $this->language->get('tab_attribute'); | |
$this->data['tab_review'] = sprintf($this->language->get('tab_review'), $this->model_catalog_review->getTotalReviewsByProductId($this->request->get['product_id'])); | |
$this->data['tab_related'] = $this->language->get('tab_related'); | |
$this->data['product_id'] = $this->request->get['product_id']; | |
$this->data['manufacturer'] = $product_info['manufacturer']; | |
$this->data['manufacturers'] = $this->url->link('product/manufacturer/product', 'manufacturer_id=' . $product_info['manufacturer_id']); | |
$this->data['model'] = $product_info['model']; | |
$this->data['reward'] = $product_info['reward']; | |
$this->data['points'] = $product_info['points']; | |
if ($product_info['quantity'] <= 0) { | |
$this->data['stock'] = $product_info['stock_status']; | |
} elseif ($this->config->get('config_stock_display')) { | |
$this->data['stock'] = $product_info['quantity']; | |
} else { | |
$this->data['stock'] = $this->language->get('text_instock'); | |
} | |
$this->load->model('tool/image'); | |
if ($product_info['image']) { | |
$this->data['popup'] = $this->model_tool_image->resize($product_info['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height')); | |
} else { | |
$this->data['popup'] = ''; | |
} | |
if ($product_info['image']) { | |
$this->data['thumb'] = $this->model_tool_image->resize($product_info['image'], $this->config->get('config_image_thumb_width'), $this->config->get('config_image_thumb_height')); | |
} else { | |
$this->data['thumb'] = ''; | |
} | |
$this->data['images'] = array(); | |
$results = $this->model_catalog_product->getProductImages($this->request->get['product_id']); | |
foreach ($results as $result) { | |
$this->data['images'][] = array( | |
'popup' => $this->model_tool_image->resize($result['image'] , $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height')), | |
'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_additional_width'), $this->config->get('config_image_additional_height')) | |
); | |
} | |
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) { | |
$this->data['price'] = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax'))); | |
} else { | |
$this->data['price'] = false; | |
} | |
if ((float)$product_info['special']) { | |
$this->data['special'] = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax'))); | |
} else { | |
$this->data['special'] = false; | |
} | |
if ($this->config->get('config_tax')) { | |
$this->data['tax'] = $this->currency->format((float)$product_info['special'] ? $product_info['special'] : $product_info['price']); | |
} else { | |
$this->data['tax'] = false; | |
} | |
$discounts = $this->model_catalog_product->getProductDiscounts($this->request->get['product_id']); | |
$this->data['discounts'] = array(); | |
foreach ($discounts as $discount) { | |
$this->data['discounts'][] = array( | |
'quantity' => $discount['quantity'], | |
'price' => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax'))) | |
); | |
} | |
$this->data['options'] = array(); | |
foreach ($this->model_catalog_product->getProductOptions($this->request->get['product_id']) as $option) { | |
if ($option['type'] == 'select' || $option['type'] == 'radio' || $option['type'] == 'checkbox') { | |
$option_value_data = array(); | |
foreach ($option['option_value'] as $option_value) { | |
if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) { | |
$option_value_data[] = array( | |
'product_option_value_id' => $option_value['product_option_value_id'], | |
'option_value_id' => $option_value['option_value_id'], | |
'name' => $option_value['name'], | |
'price' => (float)$option_value['price'] ? $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax'))) : false, | |
'price_prefix' => $option_value['price_prefix'] | |
); | |
} | |
} | |
$this->data['options'][] = array( | |
'product_option_id' => $option['product_option_id'], | |
'option_id' => $option['option_id'], | |
'name' => $option['name'], | |
'type' => $option['type'], | |
'option_value' => $option_value_data, | |
'required' => $option['required'] | |
); | |
} elseif ($option['type'] == 'text' || $option['type'] == 'textarea' || $option['type'] == 'file' || $option['type'] == 'date' || $option['type'] == 'datetime' || $option['type'] == 'time') { | |
$this->data['options'][] = array( | |
'product_option_id' => $option['product_option_id'], | |
'option_id' => $option['option_id'], | |
'name' => $option['name'], | |
'type' => $option['type'], | |
'option_value' => $option['option_value'], | |
'required' => $option['required'] | |
); | |
} | |
} | |
if ($product_info['minimum']) { | |
$this->data['minimum'] = $product_info['minimum']; | |
} else { | |
$this->data['minimum'] = 1; | |
} | |
$this->data['review_status'] = $this->config->get('config_review_status'); | |
$this->data['reviews'] = sprintf($this->language->get('text_reviews'), (int)$product_info['reviews']); | |
$this->data['rating'] = (int)$product_info['rating']; | |
$this->data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8'); | |
$this->data['attribute_groups'] = $this->model_catalog_product->getProductAttributes($this->request->get['product_id']); | |
$this->data['products'] = array(); | |
$results = $this->model_catalog_product->getProductRelated($this->request->get['product_id']); | |
foreach ($results as $result) { | |
if ($result['image']) { | |
$image = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_related_width'), $this->config->get('config_image_related_height')); | |
} else { | |
$image = false; | |
} | |
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) { | |
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'))); | |
} else { | |
$price = false; | |
} | |
if ((float)$result['special']) { | |
$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax'))); | |
} else { | |
$special = false; | |
} | |
if ($this->config->get('config_review_status')) { | |
$rating = (int)$result['rating']; | |
} else { | |
$rating = false; | |
} | |
$this->data['products'][] = array( | |
'product_id' => $result['product_id'], | |
'thumb' => $image, | |
'name' => $result['name'], | |
'price' => $price, | |
'special' => $special, | |
'rating' => $rating, | |
'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']), | |
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']), | |
); | |
} | |
$this->data['tags'] = array(); | |
$results = $this->model_catalog_product->getProductTags($this->request->get['product_id']); | |
foreach ($results as $result) { | |
$this->data['tags'][] = array( | |
'tag' => $result['tag'], | |
'href' => $this->url->link('product/search', 'filter_tag=' . $result['tag']) | |
); | |
} | |
$this->model_catalog_product->updateViewed($this->request->get['product_id']); | |
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product.tpl')) { | |
$this->template = $this->config->get('config_template') . '/template/product/product.tpl'; | |
} else { | |
$this->template = 'default/template/product/product.tpl'; | |
} | |
$this->children = array( | |
'common/column_left', | |
'common/column_right', | |
'common/content_top', | |
'common/content_bottom', | |
'common/footer', | |
'common/header' | |
); | |
$this->response->setOutput($this->render()); | |
} else { | |
$url = ''; | |
if (isset($this->request->get['path'])) { | |
$url .= '&path=' . $this->request->get['path']; | |
} | |
if (isset($this->request->get['manufacturer_id'])) { | |
$url .= '&manufacturer_id=' . $this->request->get['manufacturer_id']; | |
} | |
if (isset($this->request->get['filter_name'])) { | |
$url .= '&filter_name=' . $this->request->get['filter_name']; | |
} | |
if (isset($this->request->get['filter_tag'])) { | |
$url .= '&filter_tag=' . $this->request->get['filter_tag']; | |
} | |
if (isset($this->request->get['filter_description'])) { | |
$url .= '&filter_description=' . $this->request->get['filter_description']; | |
} | |
if (isset($this->request->get['filter_category_id'])) { | |
$url .= '&filter_category_id=' . $this->request->get['filter_category_id']; | |
} | |
$this->data['breadcrumbs'][] = array( | |
'text' => $this->language->get('text_error'), | |
'href' => $this->url->link('product/product', $url . '&product_id=' . $product_id), | |
'separator' => $this->language->get('text_separator') | |
); | |
$this->document->setTitle($this->language->get('text_error')); | |
$this->data['heading_title'] = $this->language->get('text_error'); | |
$this->data['text_error'] = $this->language->get('text_error'); | |
$this->data['button_continue'] = $this->language->get('button_continue'); | |
$this->data['continue'] = $this->url->link('common/home'); | |
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) { | |
$this->template = $this->config->get('config_template') . '/template/error/not_found.tpl'; | |
} else { | |
$this->template = 'default/template/error/not_found.tpl'; | |
} | |
$this->children = array( | |
'common/column_left', | |
'common/column_right', | |
'common/content_top', | |
'common/content_bottom', | |
'common/footer', | |
'common/header' | |
); | |
$this->response->setOutput($this->render()); | |
} | |
} | |
public function review() { | |
$this->language->load('product/product'); | |
$this->load->model('catalog/review'); | |
$this->data['text_no_reviews'] = $this->language->get('text_no_reviews'); | |
if (isset($this->request->get['page'])) { | |
$page = $this->request->get['page']; | |
} else { | |
$page = 1; | |
} | |
$this->data['reviews'] = array(); | |
$review_total = $this->model_catalog_review->getTotalReviewsByProductId($this->request->get['product_id']); | |
$results = $this->model_catalog_review->getReviewsByProductId($this->request->get['product_id'], ($page - 1) * 5, 5); | |
foreach ($results as $result) { | |
$this->data['reviews'][] = array( | |
'author' => $result['author'], | |
'text' => strip_tags($result['text']), | |
'rating' => (int)$result['rating'], | |
'reviews' => sprintf($this->language->get('text_reviews'), (int)$review_total), | |
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])) | |
); | |
} | |
$pagination = new Pagination(); | |
$pagination->total = $review_total; | |
$pagination->page = $page; | |
$pagination->limit = 5; | |
$pagination->text = $this->language->get('text_pagination'); | |
$pagination->url = $this->url->link('product/product/review', 'product_id=' . $this->request->get['product_id'] . '&page={page}'); | |
$this->data['pagination'] = $pagination->render(); | |
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/review.tpl')) { | |
$this->template = $this->config->get('config_template') . '/template/product/review.tpl'; | |
} else { | |
$this->template = 'default/template/product/review.tpl'; | |
} | |
$this->response->setOutput($this->render()); | |
} | |
public function write() { | |
$this->language->load('product/product'); | |
$this->load->model('catalog/review'); | |
$json = array(); | |
if ((strlen(utf8_decode($this->request->post['name'])) < 3) || (strlen(utf8_decode($this->request->post['name'])) > 25)) { | |
$json['error'] = $this->language->get('error_name'); | |
} | |
if ((strlen(utf8_decode($this->request->post['text'])) < 25) || (strlen(utf8_decode($this->request->post['text'])) > 1000)) { | |
$json['error'] = $this->language->get('error_text'); | |
} | |
if (!$this->request->post['rating']) { | |
$json['error'] = $this->language->get('error_rating'); | |
} | |
if (!isset($this->session->data['captcha']) || ($this->session->data['captcha'] != $this->request->post['captcha'])) { | |
$json['error'] = $this->language->get('error_captcha'); | |
} | |
if (($this->request->server['REQUEST_METHOD'] == 'POST') && !isset($json['error'])) { | |
$this->model_catalog_review->addReview($this->request->get['product_id'], $this->request->post); | |
$json['success'] = $this->language->get('text_success'); | |
} | |
$this->load->library('json'); | |
$this->response->setOutput(Json::encode($json)); | |
} | |
public function captcha() { | |
$this->load->library('captcha'); | |
$captcha = new Captcha(); | |
$this->session->data['captcha'] = $captcha->getCode(); | |
$captcha->showImage(); | |
} | |
public function upload() { | |
$this->language->load('product/product'); | |
$json = array(); | |
if (isset($this->request->files['file']['name']) && $this->request->files['file']['name']) { | |
if ((strlen(utf8_decode($this->request->files['file']['name'])) < 3) || (strlen(utf8_decode($this->request->files['file']['name'])) > 128)) { | |
$json['error'] = $this->language->get('error_filename'); | |
} | |
$allowed = array(); | |
$filetypes = explode(',', $this->config->get('config_upload_allowed')); | |
foreach ($filetypes as $filetype) { | |
$allowed[] = trim($filetype); | |
} | |
if (!in_array(substr(strrchr($this->request->files['file']['name'], '.'), 1), $allowed)) { | |
$json['error'] = $this->language->get('error_filetype'); | |
} | |
if ($this->request->files['file']['error'] != UPLOAD_ERR_OK) { | |
$json['error'] = $this->language->get('error_upload_' . $this->request->files['file']['error']); | |
} | |
} else { | |
$json['error'] = $this->language->get('error_upload'); | |
} | |
if (($this->request->server['REQUEST_METHOD'] == 'POST') && !isset($json['error'])) { | |
if (is_uploaded_file($this->request->files['file']['tmp_name']) && file_exists($this->request->files['file']['tmp_name'])) { | |
$file = basename($this->request->files['file']['name']) . '.' . md5(rand()); | |
// Hide the uploaded file name sop people can not link to it directly. | |
$this->load->library('encryption'); | |
$encryption = new Encryption($this->config->get('config_encryption')); | |
$json['file'] = $encryption->encrypt($file); | |
move_uploaded_file($this->request->files['file']['tmp_name'], DIR_DOWNLOAD . $file); | |
} | |
$json['success'] = $this->language->get('text_upload'); | |
} | |
$this->load->library('json'); | |
$this->response->setOutput(Json::encode($json)); | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ModelCatalogProduct extends Model { | |
public function updateViewed($product_id) { | |
$this->db->query("UPDATE " . DB_PREFIX . "product SET viewed = (viewed + 1) WHERE product_id = '" . (int)$product_id . "'"); | |
} | |
public function getProduct($product_id) { | |
if ($this->customer->isLogged()) { | |
$customer_group_id = $this->customer->getCustomerGroupId(); | |
} else { | |
$customer_group_id = $this->config->get('config_customer_group_id'); | |
} | |
$query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special, (SELECT points FROM " . DB_PREFIX . "product_reward pr WHERE pr.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "') AS reward, (SELECT ss.name FROM " . DB_PREFIX . "stock_status ss WHERE ss.stock_status_id = p.stock_status_id AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "') AS stock_status, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating, (SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review r2 WHERE r2.product_id = p.product_id AND r2.status = '1' GROUP BY r2.product_id) AS reviews 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_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'"); | |
if ($query->num_rows) { | |
return array( | |
'product_id' => $query->row['product_id'], | |
'name' => $query->row['name'], | |
'description' => $query->row['description'], | |
'meta_description' => $query->row['meta_description'], | |
'meta_keyword' => $query->row['meta_keyword'], | |
'model' => $query->row['model'], | |
'model' => $query->row['model'], | |
'sku' => $query->row['sku'], | |
'upc' => $query->row['upc'], | |
'location' => $query->row['location'], | |
'quantity' => $query->row['quantity'], | |
'stock_status' => $query->row['stock_status'], | |
'image' => $query->row['image'], | |
'manufacturer_id' => $query->row['manufacturer_id'], | |
'manufacturer' => $query->row['manufacturer'], | |
'price' => ($query->row['discount'] ? $query->row['discount'] : $query->row['price']), | |
'special' => $query->row['special'], | |
'reward' => $query->row['reward'], | |
'points' => $query->row['points'], | |
'tax_class_id' => $query->row['tax_class_id'], | |
'date_available' => $query->row['date_available'], | |
'weight' => $query->row['weight'], | |
'weight_class_id' => $query->row['weight_class_id'], | |
'length' => $query->row['length'], | |
'width' => $query->row['width'], | |
'height' => $query->row['height'], | |
'length_class_id' => $query->row['length_class_id'], | |
'subtract' => $query->row['subtract'], | |
'rating' => (int)$query->row['rating'], | |
'reviews' => $query->row['reviews'], | |
'minimum' => $query->row['minimum'], | |
'sort_order' => $query->row['sort_order'], | |
'status' => $query->row['status'], | |
'date_added' => $query->row['date_added'], | |
'date_modified' => $query->row['date_modified'], | |
'viewed' => $query->row['viewed'] | |
); | |
} else { | |
return false; | |
} | |
} | |
public function getProducts($data = array()) { | |
if ($this->customer->isLogged()) { | |
$customer_group_id = $this->customer->getCustomerGroupId(); | |
} else { | |
$customer_group_id = $this->config->get('config_customer_group_id'); | |
} | |
$cache = md5(http_build_query($data)); | |
$product_data = $this->cache->get('product.' . $cache . '.' . $customer_group_id); | |
if (!$product_data) { | |
$sql = "SELECT p.product_id, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating 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_store p2s ON (p.product_id = p2s.product_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'"; | |
if (isset($data['filter_name']) && $data['filter_name']) { | |
if (isset($data['filter_description']) && $data['filter_description']) { | |
$sql .= " AND (LCASE(pd.name) LIKE '%" . $this->db->escape(mb_strtolower($data['filter_name'], 'UTF-8')) . "%' OR p.product_id IN (SELECT pt.product_id FROM " . DB_PREFIX . "product_tag pt WHERE pt.language_id = '" . (int)$this->config->get('config_language_id') . "' AND LCASE(pt.tag) LIKE '%" . $this->db->escape(mb_strtolower($data['filter_name'], 'UTF-8')) . "%') OR LCASE(pd.description) LIKE '%" . $this->db->escape(mb_strtolower($data['filter_name'], 'UTF-8')) . "%')"; | |
} else { | |
$sql .= " AND (LCASE(pd.name) LIKE '%" . $this->db->escape(mb_strtolower($data['filter_name'], 'UTF-8')) . "%' OR p.product_id IN (SELECT pt.product_id FROM " . DB_PREFIX . "product_tag pt WHERE pt.language_id = '" . (int)$this->config->get('config_language_id') . "' AND LCASE(pt.tag) LIKE '%" . $this->db->escape(mb_strtolower($data['filter_name'], 'UTF-8')) . "%'))"; | |
} | |
} | |
if (isset($data['filter_tag']) && $data['filter_tag']) { | |
$sql .= " AND p.product_id IN (SELECT pt.product_id FROM " . DB_PREFIX . "product_tag pt WHERE pt.language_id = '" . (int)$this->config->get('config_language_id') . "' AND LCASE(pt.tag) LIKE '%" . $this->db->escape(mb_strtolower($data['filter_tag'], 'UTF-8')) . "%')"; | |
} | |
if (isset($data['filter_category_id']) && $data['filter_category_id']) { | |
if (isset($data['filter_sub_category']) && $data['filter_sub_category']) { | |
$implode_data = array(); | |
$this->load->model('catalog/category'); | |
$categories = $this->model_catalog_category->getCategoriesByParentId($data['filter_category_id']); | |
foreach ($categories as $category_id) { | |
$implode_data[] = "p2c.category_id = '" . (int)$category_id . "'"; | |
} | |
$sql .= " AND p.product_id IN (SELECT p2c.product_id FROM " . DB_PREFIX . "product_to_category p2c WHERE " . implode(' OR ', $implode_data) . ")"; | |
} else { | |
$sql .= " AND p.product_id IN (SELECT p2c.product_id FROM " . DB_PREFIX . "product_to_category p2c WHERE p2c.category_id = '" . (int)$data['filter_category_id'] . "')"; | |
} | |
} | |
if (isset($data['filter_manufacturer_id'])) { | |
$sql .= " AND p.manufacturer_id = '" . (int)$data['filter_manufacturer_id'] . "'"; | |
} | |
$sql .= " GROUP BY p.product_id"; | |
$sort_data = array( | |
'pd.name', | |
'p.model', | |
'p.quantity', | |
'p.price', | |
'rating', | |
'p.sort_order', | |
'p.date_added' | |
); | |
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { | |
if ($data['sort'] == 'pd.name' || $data['sort'] == 'p.model') { | |
$sql .= " ORDER BY LCASE(" . $data['sort'] . ")"; | |
} else { | |
$sql .= " ORDER BY " . $data['sort']; | |
} | |
} else { | |
$sql .= " ORDER BY p.sort_order"; | |
} | |
if (isset($data['order']) && ($data['order'] == 'DESC')) { | |
$sql .= " DESC"; | |
} else { | |
$sql .= " ASC"; | |
} | |
if (isset($data['start']) || isset($data['limit'])) { | |
if ($data['start'] < 0) { | |
$data['start'] = 0; | |
} | |
if ($data['limit'] < 1) { | |
$data['limit'] = 20; | |
} | |
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; | |
} | |
$product_data = array(); | |
$query = $this->db->query($sql); | |
foreach ($query->rows as $result) { | |
$product_data[$result['product_id']] = $this->getProduct($result['product_id']); | |
} | |
$this->cache->set('product.' . $cache . '.' . $customer_group_id, $product_data); | |
} | |
return $product_data; | |
} | |
public function getProductSpecials($data = array()) { | |
if ($this->customer->isLogged()) { | |
$customer_group_id = $this->customer->getCustomerGroupId(); | |
} else { | |
$customer_group_id = $this->config->get('config_customer_group_id'); | |
} | |
$sql = "SELECT DISTINCT ps.product_id, (SELECT AVG(rating) FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = ps.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating FROM " . DB_PREFIX . "product_special ps LEFT JOIN " . DB_PREFIX . "product p ON (ps.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) GROUP BY ps.product_id"; | |
$sort_data = array( | |
'pd.name', | |
'p.model', | |
'ps.price', | |
'rating', | |
'p.sort_order' | |
); | |
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { | |
if ($data['sort'] == 'pd.name' || $data['sort'] == 'p.model') { | |
$sql .= " ORDER BY LCASE(" . $data['sort'] . ")"; | |
} else { | |
$sql .= " ORDER BY " . $data['sort']; | |
} | |
} else { | |
$sql .= " ORDER BY p.sort_order"; | |
} | |
if (isset($data['order']) && ($data['order'] == 'DESC')) { | |
$sql .= " DESC"; | |
} else { | |
$sql .= " ASC"; | |
} | |
if (isset($data['start']) || isset($data['limit'])) { | |
if ($data['start'] < 0) { | |
$data['start'] = 0; | |
} | |
if ($data['limit'] < 1) { | |
$data['limit'] = 20; | |
} | |
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; | |
} | |
$product_data = array(); | |
$query = $this->db->query($sql); | |
foreach ($query->rows as $result) { | |
$product_data[$result['product_id']] = $this->getProduct($result['product_id']); | |
} | |
return $product_data; | |
} | |
public function getLatestProducts($limit) { | |
$product_data = $this->cache->get('product.latest.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit); | |
if (!$product_data) { | |
$query = $this->db->query("SELECT p.product_id FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' ORDER BY p.date_added DESC LIMIT " . (int)$limit); | |
foreach ($query->rows as $result) { | |
$product_data[$result['product_id']] = $this->getProduct($result['product_id']); | |
} | |
$this->cache->set('product.latest.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit, $product_data); | |
} | |
return $product_data; | |
} | |
public function getPopularProducts($limit) { | |
$product_data = array(); | |
$query = $this->db->query("SELECT p.product_id FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' ORDER BY p.viewed, p.date_added DESC LIMIT " . (int)$limit); | |
foreach ($query->rows as $result) { | |
$product_data[$result['product_id']] = $this->getProduct($result['product_id']); | |
} | |
return $product_data; | |
} | |
public function getBestSellerProducts($limit) { | |
$product_data = $this->cache->get('product.bestseller.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit); | |
if (!$product_data) { | |
$product_data = array(); | |
$query = $this->db->query("SELECT op.product_id, COUNT(*) AS total FROM " . DB_PREFIX . "order_product op LEFT JOIN `" . DB_PREFIX . "order` o ON (op.order_id = o.order_id) LEFT JOIN `" . DB_PREFIX . "product` p ON (op.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE o.order_status_id > '0' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' GROUP BY op.product_id ORDER BY total DESC LIMIT " . (int)$limit); | |
foreach ($query->rows as $result) { | |
$product_data[$result['product_id']] = $this->getProduct($result['product_id']); | |
} | |
$this->cache->set('product.bestseller.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit, $product_data); | |
} | |
return $product_data; | |
} | |
public function getProductAttributes($product_id) { | |
$product_attribute_group_data = array(); | |
$product_attribute_group_query = $this->db->query("SELECT ag.attribute_group_id, agd.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_group ag ON (a.attribute_group_id = ag.attribute_group_id) LEFT JOIN " . DB_PREFIX . "attribute_group_description agd ON (ag.attribute_group_id = agd.attribute_group_id) WHERE pa.product_id = '" . (int)$product_id . "' AND agd.language_id = '" . (int)$this->config->get('config_language_id') . "' GROUP BY ag.attribute_group_id ORDER BY ag.sort_order, agd.name"); | |
foreach ($product_attribute_group_query->rows as $product_attribute_group) { | |
$product_attribute_data = array(); | |
$product_attribute_query = $this->db->query("SELECT a.attribute_id, ad.name, pa.text 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 a.attribute_group_id = '" . (int)$product_attribute_group['attribute_group_id'] . "' AND ad.language_id = '" . (int)$this->config->get('config_language_id') . "' AND pa.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY a.sort_order, ad.name"); | |
foreach ($product_attribute_query->rows as $product_attribute) { | |
$product_attribute_data[] = array( | |
'attribute_id' => $product_attribute['attribute_id'], | |
'name' => $product_attribute['name'], | |
'text' => $product_attribute['text'] | |
); | |
} | |
$product_attribute_group_data[] = array( | |
'attribute_group_id' => $product_attribute_group['attribute_group_id'], | |
'name' => $product_attribute_group['name'], | |
'attribute' => $product_attribute_data | |
); | |
} | |
return $product_attribute_group_data; | |
} | |
public function getProductOptions($product_id) { | |
$product_option_data = array(); | |
$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"); | |
foreach ($product_option_query->rows as $product_option) { | |
if ($product_option['type'] == 'select' || $product_option['type'] == 'radio' || $product_option['type'] == 'checkbox') { | |
$product_option_value_data = array(); | |
$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_id = '" . (int)$product_id . "' AND pov.product_option_id = '" . (int)$product_option['product_option_id'] . "' AND ovd.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY ov.sort_order"); | |
foreach ($product_option_value_query->rows as $product_option_value) { | |
$product_option_value_data[] = array( | |
'product_option_value_id' => $product_option_value['product_option_value_id'], | |
'option_value_id' => $product_option_value['option_value_id'], | |
'name' => $product_option_value['name'], | |
'quantity' => $product_option_value['quantity'], | |
'subtract' => $product_option_value['subtract'], | |
'price' => $product_option_value['price'], | |
'price_prefix' => $product_option_value['price_prefix'], | |
'weight' => $product_option_value['weight'], | |
'weight_prefix' => $product_option_value['weight_prefix'] | |
); | |
} | |
$product_option_data[] = array( | |
'product_option_id' => $product_option['product_option_id'], | |
'option_id' => $product_option['option_id'], | |
'name' => $product_option['name'], | |
'type' => $product_option['type'], | |
'option_value' => $product_option_value_data, | |
'required' => $product_option['required'] | |
); | |
} else { | |
$product_option_data[] = array( | |
'product_option_id' => $product_option['product_option_id'], | |
'option_id' => $product_option['option_id'], | |
'name' => $product_option['name'], | |
'type' => $product_option['type'], | |
'option_value' => $product_option['option_value'], | |
'required' => $product_option['required'] | |
); | |
} | |
} | |
return $product_option_data; | |
} | |
public function getProductDiscounts($product_id) { | |
if ($this->customer->isLogged()) { | |
$customer_group_id = $this->customer->getCustomerGroupId(); | |
} else { | |
$customer_group_id = $this->config->get('config_customer_group_id'); | |
} | |
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND quantity > 1 AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY quantity ASC, priority ASC, price ASC"); | |
return $query->rows; | |
} | |
public function getProductImages($product_id) { | |
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "'"); | |
return $query->rows; | |
} | |
public function getProductRelated($product_id) { | |
$product_data = array(); | |
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_related pr LEFT JOIN " . DB_PREFIX . "product p ON (pr.related_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE pr.product_id = '" . (int)$product_id . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'"); | |
foreach ($query->rows as $result) { | |
$product_data[$result['related_id']] = $this->getProduct($result['related_id']); | |
} | |
return $product_data; | |
} | |
public function getProductTags($product_id) { | |
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_tag WHERE product_id = '" . (int)$product_id . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'"); | |
return $query->rows; | |
} | |
public function getProductLayoutId($product_id) { | |
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_layout WHERE product_id = '" . (int)$product_id . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "'"); | |
if ($query->num_rows) { | |
return $query->row['layout_id']; | |
} else { | |
return $this->config->get('config_layout_product'); | |
} | |
} | |
public function getCategories($product_id) { | |
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'"); | |
return $query->rows; | |
} | |
public function getTotalProducts($data = array()) { | |
$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) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'"; | |
if (isset($data['filter_name'])) { | |
if (isset($data['filter_description']) && $data['filter_description']) { | |
$sql .= " AND (LCASE(pd.name) LIKE '%" . $this->db->escape(mb_strtolower($data['filter_name'], 'UTF-8')) . "%' OR p.product_id IN (SELECT pt.product_id FROM " . DB_PREFIX . "product_tag pt WHERE pt.language_id = '" . (int)$this->config->get('config_language_id') . "' AND LCASE(pt.tag) LIKE '%" . $this->db->escape(mb_strtolower($data['filter_name'], 'UTF-8')) . "%') OR LCASE(pd.description) LIKE '%" . $this->db->escape(mb_strtolower($data['filter_name'], 'UTF-8')) . "%')"; | |
} else { | |
$sql .= " AND (LCASE(pd.name) LIKE '%" . $this->db->escape(mb_strtolower($data['filter_name'], 'UTF-8')) . "%' OR p.product_id IN (SELECT pt.product_id FROM " . DB_PREFIX . "product_tag pt WHERE pt.language_id = '" . (int)$this->config->get('config_language_id') . "' AND LCASE(pt.tag) LIKE '%" . $this->db->escape(mb_strtolower($data['filter_name'], 'UTF-8')) . "%'))"; | |
} | |
} | |
if (isset($data['filter_tag']) && $data['filter_tag']) { | |
$sql .= " AND p.product_id IN (SELECT pt.product_id FROM " . DB_PREFIX . "product_tag pt WHERE pt.language_id = '" . (int)$this->config->get('config_language_id') . "' AND LCASE(pt.tag) LIKE '%" . $this->db->escape(mb_strtolower($data['filter_tag'], 'UTF-8')) . "%')"; | |
} | |
if (isset($data['filter_category_id']) && $data['filter_category_id']) { | |
if (isset($data['filter_sub_category']) && $data['filter_sub_category']) { | |
$implode_data = array(); | |
$this->load->model('catalog/category'); | |
$categories = $this->model_catalog_category->getCategoriesByParentId($data['filter_category_id']); | |
foreach ($categories as $category_id) { | |
$implode_data[] = "p2c.category_id = '" . (int)$category_id . "'"; | |
} | |
$sql .= " AND p.product_id IN (SELECT p2c.product_id FROM " . DB_PREFIX . "product_to_category p2c WHERE " . implode(' OR ', $implode_data) . ")"; | |
} else { | |
$sql .= " AND p.product_id IN (SELECT p2c.product_id FROM " . DB_PREFIX . "product_to_category p2c WHERE p2c.category_id = '" . (int)$data['filter_category_id'] . "')"; | |
} | |
} | |
if (isset($data['filter_manufacturer_id'])) { | |
$sql .= " AND p.manufacturer_id = '" . (int)$data['filter_manufacturer_id'] . "'"; | |
} | |
$query = $this->db->query($sql); | |
return $query->row['total']; | |
} | |
public function getTotalProductSpecials() { | |
if ($this->customer->isLogged()) { | |
$customer_group_id = $this->customer->getCustomerGroupId(); | |
} else { | |
$customer_group_id = $this->config->get('config_customer_group_id'); | |
} | |
$query = $this->db->query("SELECT COUNT(DISTINCT ps.product_id) AS total FROM " . DB_PREFIX . "product_special ps LEFT JOIN " . DB_PREFIX . "product p ON (ps.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW()))"); | |
if (isset($query->row['total'])) { | |
return $query->row['total']; | |
} else { | |
return 0; | |
} | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php echo $header; ?><?php echo $column_left; ?><?php echo $column_right; ?> | |
<div id="content"><?php echo $content_top; ?> | |
<div class="breadcrumb"> | |
<?php foreach ($breadcrumbs as $breadcrumb) { ?> | |
<?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a> | |
<?php } ?> | |
</div> | |
<h1><?php echo $heading_title; ?></h1> | |
<?php if ($thumb || $description) { ?> | |
<div class="category-info"> | |
<?php if ($thumb) { ?> | |
<div class="image"><img src="<?php echo $thumb; ?>" alt="<?php echo $heading_title; ?>" /></div> | |
<?php } ?> | |
<?php if ($description) { ?> | |
<?php echo $description; ?> | |
<?php } ?> | |
</div> | |
<?php } ?> | |
<?php if ($categories) { ?> | |
<h2><?php echo $text_refine; ?></h2> | |
<div class="category-list"> | |
<?php if (count($categories) <= 5) { ?> | |
<ul> | |
<?php foreach ($categories as $category) { ?> | |
<li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></li> | |
<?php } ?> | |
</ul> | |
<?php } else { ?> | |
<?php for ($i = 0; $i < count($categories);) { ?> | |
<ul> | |
<?php $j = $i + ceil(count($categories) / 4); ?> | |
<?php for (; $i < $j; $i++) { ?> | |
<?php if (isset($categories[$i])) { ?> | |
<li><a href="<?php echo $categories[$i]['href']; ?>"><?php echo $categories[$i]['name']; ?></a></li> | |
<?php } ?> | |
<?php } ?> | |
</ul> | |
<?php } ?> | |
<?php } ?> | |
</div> | |
<?php } ?> | |
<?php if ($products) { ?> | |
<div class="product-filter"> | |
<div class="display"><b><?php echo $text_display; ?></b> <?php echo $text_list; ?> <b>/</b> <a onclick="display('grid');"><?php echo $text_grid; ?></a></div> | |
<div class="limit"><b><?php echo $text_limit; ?></b> | |
<select onchange="location = this.value;"> | |
<?php foreach ($limits as $limits) { ?> | |
<?php if ($limits['value'] == $limit) { ?> | |
<option value="<?php echo $limits['href']; ?>" selected="selected"><?php echo $limits['text']; ?></option> | |
<?php } else { ?> | |
<option value="<?php echo $limits['href']; ?>"><?php echo $limits['text']; ?></option> | |
<?php } ?> | |
<?php } ?> | |
</select> | |
</div> | |
<div class="sort"><b><?php echo $text_sort; ?></b> | |
<select onchange="location = this.value;"> | |
<?php foreach ($sorts as $sorts) { ?> | |
<?php if ($sorts['value'] == $sort . '-' . $order) { ?> | |
<option value="<?php echo $sorts['href']; ?>" selected="selected"><?php echo $sorts['text']; ?></option> | |
<?php } else { ?> | |
<option value="<?php echo $sorts['href']; ?>"><?php echo $sorts['text']; ?></option> | |
<?php } ?> | |
<?php } ?> | |
</select> | |
</div> | |
</div> | |
<div class="product-compare"><a href="<?php echo $compare; ?>" id="compare_total"><?php echo $text_compare; ?></a></div> | |
<div class="product-grid"> | |
<?php foreach ($products as $product) { ?> | |
<div> | |
<?php if ($product['thumb']) { ?> | |
<div class="image"><a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" title="<?php echo $product['name']; ?>" alt="<?php echo $product['name']; ?>" /></a></div> | |
<?php } ?> | |
<div class="name"><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a></div> | |
<div class="description"><?php echo $product['description']; ?></div> | |
<?php if ($product['price']) { ?> | |
<div class="price"> | |
<?php if (!$product['special']) { ?> | |
<?php echo $product['price']; ?> | |
<?php } else { ?> | |
<span class="price-old"><?php echo $product['price']; ?></span> <span class="price-new"><?php echo $product['special']; ?></span> | |
<?php } ?> | |
</div> | |
<?php } ?> | |
<?php if ($product['rating']) { ?> | |
<div class="rating"><img src="catalog/view/theme/default/image/stars-<?php echo $product['rating']; ?>.png" alt="<?php echo $product['reviews']; ?>" /></div> | |
<?php } ?> | |
<div class="cart"><a onclick="addToCart('<?php echo $product['product_id']; ?>');" class="button"><span><?php echo $button_cart; ?></span></a></div> | |
<div class="wishlist"><a onclick="addToWishList('<?php echo $product['product_id']; ?>');"><?php echo $button_wishlist; ?></a></div> | |
<div class="compare"><a onclick="addToCompare('<?php echo $product['product_id']; ?>');"><?php echo $button_compare; ?></a></div> | |
</div> | |
<?php } ?> | |
</div> | |
<div class="pagination"><?php echo $pagination; ?></div> | |
<?php } ?> | |
<?php if (!$categories && !$products) { ?> | |
<div class="content"><?php echo $text_empty; ?></div> | |
<div class="buttons"> | |
<div class="right"><a href="<?php echo $continue; ?>" class="button"><span><?php echo $button_continue; ?></span></a></div> | |
</div> | |
<?php } ?> | |
<?php echo $content_bottom; ?></div> | |
<script type="text/javascript"><!-- | |
function display(view) { | |
if (view == 'list') { | |
$('.product-grid').attr('class', 'product-list'); | |
$('.product-list > div').each(function(index, element) { | |
html = '<div class="right">'; | |
html += ' <div class="cart">' + $(element).find('.cart').html() + '</div>'; | |
html += ' <div class="wishlist">' + $(element).find('.wishlist').html() + '</div>'; | |
html += ' <div class="compare">' + $(element).find('.compare').html() + '</div>'; | |
html += '</div>'; | |
html += '<div class="left">'; | |
var image = $(element).find('.image').html(); | |
if (image != null) { | |
html += '<div class="image">' + image + '</div>'; | |
} | |
var price = $(element).find('.price').html(); | |
if (price != null) { | |
html += '<div class="price">' + price + '</div>'; | |
} | |
html += ' <div class="name">' + $(element).find('.name').html() + '</div>'; | |
html += ' <div class="description">' + $(element).find('.description').html() + '</div>'; | |
var rating = $(element).find('.rating').html(); | |
if (rating != null) { | |
html += '<div class="rating">' + rating + '</div>'; | |
} | |
html += '</div>'; | |
$(element).html(html); | |
}); | |
$('.display').html('<b><?php echo $text_display; ?></b> <?php echo $text_list; ?> <b>/</b> <a onclick="display(\'grid\');"><?php echo $text_grid; ?></a>'); | |
$.cookie('display', 'list', { path: '/' }); | |
} else { | |
$('.product-list').attr('class', 'product-grid'); | |
$('.product-grid > div').each(function(index, element) { | |
html = ''; | |
var image = $(element).find('.image').html(); | |
if (image != null) { | |
html += '<div class="image">' + image + '</div>'; | |
} | |
html += '<div class="name">' + $(element).find('.name').html() + '</div>'; | |
html += '<div class="description">' + $(element).find('.description').html() + '</div>'; | |
var price = $(element).find('.price').html(); | |
if (price != null) { | |
html += '<div class="price">' + price + '</div>'; | |
} | |
var rating = $(element).find('.rating').html(); | |
if (rating != null) { | |
html += '<div class="rating">' + rating + '</div>'; | |
} | |
html += '<div class="cart">' + $(element).find('.cart').html() + '</div>'; | |
html += '<div class="wishlist">' + $(element).find('.wishlist').html() + '</div>'; | |
html += '<div class="compare">' + $(element).find('.compare').html() + '</div>'; | |
$(element).html(html); | |
}); | |
$('.display').html('<b><?php echo $text_display; ?></b> <a onclick="display(\'list\');"><?php echo $text_list; ?></a> <b>/</b> <?php echo $text_grid; ?>'); | |
$.cookie('display', 'grid', { path: '/' }); | |
} | |
} | |
view = $.cookie('display'); | |
if (view) { | |
display(view); | |
} else { | |
display('grid'); | |
} | |
//--></script> | |
<?php echo $footer; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment