first commit
This commit is contained in:
440
catalog/controller/product/category.php
Normal file
440
catalog/controller/product/category.php
Normal file
@ -0,0 +1,440 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Product;
|
||||
/**
|
||||
* Class Category
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Product
|
||||
*/
|
||||
class Category extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): object|null {
|
||||
$this->load->language('product/category');
|
||||
|
||||
if (isset($this->request->get['path'])) {
|
||||
$path = (string)$this->request->get['path'];
|
||||
} else {
|
||||
$path = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter'])) {
|
||||
$filter = $this->request->get['filter'];
|
||||
} else {
|
||||
$filter = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = $this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'p.sort_order';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = $this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['limit']) && (int)$this->request->get['limit']) {
|
||||
$limit = (int)$this->request->get['limit'];
|
||||
} else {
|
||||
$limit = $this->config->get('config_pagination');
|
||||
}
|
||||
|
||||
$parts = explode('_', $path);
|
||||
|
||||
$category_id = (int)array_pop($parts);
|
||||
|
||||
$this->load->model('catalog/category');
|
||||
|
||||
$category_info = $this->model_catalog_category->getCategory($category_id);
|
||||
|
||||
if ($category_info) {
|
||||
$this->document->setTitle($category_info['meta_title']);
|
||||
$this->document->setDescription($category_info['meta_description']);
|
||||
$this->document->setKeywords($category_info['meta_keyword']);
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['limit'])) {
|
||||
$url .= '&limit=' . $this->request->get['limit'];
|
||||
}
|
||||
|
||||
$path = '';
|
||||
|
||||
foreach ($parts as $path_id) {
|
||||
if (!$path) {
|
||||
$path = (int)$path_id;
|
||||
} else {
|
||||
$path .= '_' . (int)$path_id;
|
||||
}
|
||||
|
||||
$category_info = $this->model_catalog_category->getCategory($path_id);
|
||||
|
||||
if ($category_info) {
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $category_info['name'],
|
||||
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $path . $url)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['path'])) {
|
||||
$url .= '&path=' . $this->request->get['path'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter'])) {
|
||||
$url .= '&filter=' . $this->request->get['filter'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['limit'])) {
|
||||
$url .= '&limit=' . $this->request->get['limit'];
|
||||
}
|
||||
|
||||
// Set the last category breadcrumb
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $category_info['name'],
|
||||
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . $url)
|
||||
];
|
||||
|
||||
$data['heading_title'] = $category_info['name'];
|
||||
|
||||
$data['text_compare'] = sprintf($this->language->get('text_compare'), (isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0));
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
if (is_file(DIR_IMAGE . html_entity_decode($category_info['image'], ENT_QUOTES, 'UTF-8'))) {
|
||||
$data['thumb'] = $this->model_tool_image->resize(html_entity_decode($category_info['image'], ENT_QUOTES, 'UTF-8'), $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));
|
||||
} else {
|
||||
$data['thumb'] = '';
|
||||
}
|
||||
|
||||
$data['description'] = html_entity_decode($category_info['description'], ENT_QUOTES, 'UTF-8');
|
||||
$data['compare'] = $this->url->link('product/compare', 'language=' . $this->config->get('config_language'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter'])) {
|
||||
$url .= '&filter=' . $this->request->get['filter'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['limit'])) {
|
||||
$url .= '&limit=' . $this->request->get['limit'];
|
||||
}
|
||||
|
||||
$data['categories'] = [];
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
$results = $this->model_catalog_category->getCategories($category_id);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$filter_data = [
|
||||
'filter_category_id' => $result['category_id'],
|
||||
'filter_sub_category' => false
|
||||
];
|
||||
|
||||
$data['categories'][] = [
|
||||
'name' => $result['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
|
||||
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['path'])) {
|
||||
$url .= '&path=' . $this->request->get['path'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter'])) {
|
||||
$url .= '&filter=' . $this->request->get['filter'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['limit'])) {
|
||||
$url .= '&limit=' . $this->request->get['limit'];
|
||||
}
|
||||
|
||||
$data['products'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'filter_category_id' => $category_id,
|
||||
'filter_sub_category' => false,
|
||||
'filter_filter' => $filter,
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $limit,
|
||||
'limit' => $limit
|
||||
];
|
||||
|
||||
$product_total = $this->model_catalog_product->getTotalProducts($filter_data);
|
||||
|
||||
$results = $this->model_catalog_product->getProducts($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
if (is_file(DIR_IMAGE . html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'))) {
|
||||
$image = $this->model_tool_image->resize(html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'), $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
|
||||
} else {
|
||||
$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
|
||||
}
|
||||
|
||||
if ($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')), $this->session->data['currency']);
|
||||
} 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')), $this->session->data['currency']);
|
||||
} else {
|
||||
$special = false;
|
||||
}
|
||||
|
||||
if ($this->config->get('config_tax')) {
|
||||
$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
|
||||
} else {
|
||||
$tax = false;
|
||||
}
|
||||
|
||||
$product_data = [
|
||||
'product_id' => $result['product_id'],
|
||||
'thumb' => $image,
|
||||
'name' => $result['name'],
|
||||
'description' => oc_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('config_product_description_length')) . '..',
|
||||
'price' => $price,
|
||||
'special' => $special,
|
||||
'tax' => $tax,
|
||||
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
|
||||
'rating' => $result['rating'],
|
||||
'href' => $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $result['product_id'] . $url)
|
||||
];
|
||||
|
||||
$data['products'][] = $this->load->controller('product/thumb', $product_data);
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['path'])) {
|
||||
$url .= '&path=' . $this->request->get['path'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter'])) {
|
||||
$url .= '&filter=' . $this->request->get['filter'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['limit'])) {
|
||||
$url .= '&limit=' . $this->request->get['limit'];
|
||||
}
|
||||
|
||||
$data['sorts'] = [];
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_default'),
|
||||
'value' => 'p.sort_order-ASC',
|
||||
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&sort=p.sort_order&order=ASC' . $url)
|
||||
];
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_name_asc'),
|
||||
'value' => 'pd.name-ASC',
|
||||
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&sort=pd.name&order=ASC' . $url)
|
||||
];
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_name_desc'),
|
||||
'value' => 'pd.name-DESC',
|
||||
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&sort=pd.name&order=DESC' . $url)
|
||||
];
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_price_asc'),
|
||||
'value' => 'p.price-ASC',
|
||||
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&sort=p.price&order=ASC' . $url)
|
||||
];
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_price_desc'),
|
||||
'value' => 'p.price-DESC',
|
||||
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&sort=p.price&order=DESC' . $url)
|
||||
];
|
||||
|
||||
if ($this->config->get('config_review_status')) {
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_rating_desc'),
|
||||
'value' => 'rating-DESC',
|
||||
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&sort=rating&order=DESC' . $url)
|
||||
];
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_rating_asc'),
|
||||
'value' => 'rating-ASC',
|
||||
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&sort=rating&order=ASC' . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_model_asc'),
|
||||
'value' => 'p.model-ASC',
|
||||
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&sort=p.model&order=ASC' . $url)
|
||||
];
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_model_desc'),
|
||||
'value' => 'p.model-DESC',
|
||||
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&sort=p.model&order=DESC' . $url)
|
||||
];
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['path'])) {
|
||||
$url .= '&path=' . $this->request->get['path'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter'])) {
|
||||
$url .= '&filter=' . $this->request->get['filter'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['limits'] = [];
|
||||
|
||||
$limits = array_unique([$this->config->get('config_pagination'), 25, 50, 75, 100]);
|
||||
|
||||
sort($limits);
|
||||
|
||||
foreach ($limits as $value) {
|
||||
$data['limits'][] = [
|
||||
'text' => $value,
|
||||
'value' => $value,
|
||||
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . $url . '&limit=' . $value)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['path'])) {
|
||||
$url .= '&path=' . $this->request->get['path'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter'])) {
|
||||
$url .= '&filter=' . $this->request->get['filter'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['limit'])) {
|
||||
$url .= '&limit=' . $this->request->get['limit'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $product_total,
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
'url' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $this->request->get['path'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($product_total - $limit)) ? $product_total : ((($page - 1) * $limit) + $limit), $product_total, ceil($product_total / $limit));
|
||||
|
||||
// http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html
|
||||
if ($page == 1) {
|
||||
$this->document->addLink($this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $this->request->get['path']), 'canonical');
|
||||
} else {
|
||||
$this->document->addLink($this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $this->request->get['path'] . '&page='. $page), 'canonical');
|
||||
}
|
||||
|
||||
if ($page > 1) {
|
||||
$this->document->addLink($this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $this->request->get['path'] . (($page - 2) ? '&page='. ($page - 1) : '')), 'prev');
|
||||
}
|
||||
|
||||
if ($limit && ceil($product_total / $limit) > $page) {
|
||||
$this->document->addLink($this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $this->request->get['path'] . '&page='. ($page + 1)), 'next');
|
||||
}
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
$data['limit'] = $limit;
|
||||
|
||||
$data['continue'] = $this->url->link('common/home', 'language=' . $this->config->get('config_language'));
|
||||
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['column_right'] = $this->load->controller('common/column_right');
|
||||
$data['content_top'] = $this->load->controller('common/content_top');
|
||||
$data['content_bottom'] = $this->load->controller('common/content_bottom');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
|
||||
$this->response->setOutput($this->load->view('product/category', $data));
|
||||
} else {
|
||||
return new \Opencart\System\Engine\Action('error/not_found');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
214
catalog/controller/product/compare.php
Normal file
214
catalog/controller/product/compare.php
Normal file
@ -0,0 +1,214 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Product;
|
||||
/**
|
||||
* Class Compare
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Product
|
||||
*/
|
||||
class Compare extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('product/compare');
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
$this->load->model('catalog/manufacturer');
|
||||
$this->load->model('localisation/stock_status');
|
||||
$this->load->model('tool/image');
|
||||
|
||||
if (!isset($this->session->data['compare'])) {
|
||||
$this->session->data['compare'] = [];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['remove'])) {
|
||||
$key = array_search($this->request->get['remove'], $this->session->data['compare']);
|
||||
|
||||
if ($key !== false) {
|
||||
unset($this->session->data['compare'][$key]);
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_remove');
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('product/compare', 'language=' . $this->config->get('config_language')));
|
||||
}
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('product/compare', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
$data['add_to_cart'] = $this->url->link('checkout/cart.add', 'language=' . $this->config->get('config_language'));
|
||||
$data['cart'] = $this->url->link('common/cart.info', 'language=' . $this->config->get('config_language'));
|
||||
|
||||
if (isset($this->session->data['success'])) {
|
||||
$data['success'] = $this->session->data['success'];
|
||||
|
||||
unset($this->session->data['success']);
|
||||
} else {
|
||||
$data['success'] = '';
|
||||
}
|
||||
|
||||
$data['products'] = [];
|
||||
|
||||
$data['attribute_groups'] = [];
|
||||
|
||||
foreach ($this->session->data['compare'] as $key => $product_id) {
|
||||
$product_info = $this->model_catalog_product->getProduct($product_id);
|
||||
|
||||
if ($product_info) {
|
||||
if (is_file(DIR_IMAGE . html_entity_decode($product_info['image'], ENT_QUOTES, 'UTF-8'))) {
|
||||
$image = $this->model_tool_image->resize(html_entity_decode($product_info['image'], ENT_QUOTES, 'UTF-8'), $this->config->get('config_image_compare_width'), $this->config->get('config_image_compare_height'));
|
||||
} else {
|
||||
$image = false;
|
||||
}
|
||||
|
||||
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
|
||||
$price = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
|
||||
} else {
|
||||
$price = false;
|
||||
}
|
||||
|
||||
if ((float)$product_info['special']) {
|
||||
$special = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
|
||||
} else {
|
||||
$special = false;
|
||||
}
|
||||
|
||||
$manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($product_info['manufacturer_id']);
|
||||
|
||||
if ($manufacturer_info) {
|
||||
$manufacturer = $manufacturer_info['name'];
|
||||
} else {
|
||||
$manufacturer = '';
|
||||
}
|
||||
|
||||
if ($product_info['quantity'] <= 0) {
|
||||
$stock_status_info = $this->model_localisation_stock_status->getStockStatus($product_info['stock_status_id']);
|
||||
|
||||
if ($stock_status_info) {
|
||||
$availability = $stock_status_info['name'];
|
||||
} else {
|
||||
$availability = '';
|
||||
}
|
||||
} elseif ($this->config->get('config_stock_display')) {
|
||||
$availability = $product_info['quantity'];
|
||||
} else {
|
||||
$availability = $this->language->get('text_instock');
|
||||
}
|
||||
|
||||
$attribute_data = [];
|
||||
|
||||
$attribute_groups = $this->model_catalog_product->getAttributes($product_id);
|
||||
|
||||
foreach ($attribute_groups as $attribute_group) {
|
||||
foreach ($attribute_group['attribute'] as $attribute) {
|
||||
$attribute_data[$attribute['attribute_id']] = $attribute['text'];
|
||||
}
|
||||
}
|
||||
|
||||
$data['products'][$product_id] = [
|
||||
'product_id' => $product_info['product_id'],
|
||||
'name' => $product_info['name'],
|
||||
'thumb' => $image,
|
||||
'price' => $price,
|
||||
'special' => $special,
|
||||
'description' => oc_substr(strip_tags(html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8')), 0, 200) . '..',
|
||||
'model' => $product_info['model'],
|
||||
'manufacturer' => $manufacturer,
|
||||
'availability' => $availability,
|
||||
'minimum' => $product_info['minimum'] > 0 ? $product_info['minimum'] : 1,
|
||||
'rating' => (int)$product_info['rating'],
|
||||
'reviews' => sprintf($this->language->get('text_reviews'), (int)$product_info['reviews']),
|
||||
'weight' => $this->weight->format($product_info['weight'], $product_info['weight_class_id'], $this->language->get('decimal_point'), $this->language->get('thousand_point')),
|
||||
'length' => $this->length->format($product_info['length'], $product_info['length_class_id'], $this->language->get('decimal_point'), $this->language->get('thousand_point')),
|
||||
'width' => $this->length->format($product_info['width'], $product_info['length_class_id'], $this->language->get('decimal_point'), $this->language->get('thousand_point')),
|
||||
'height' => $this->length->format($product_info['height'], $product_info['length_class_id'], $this->language->get('decimal_point'), $this->language->get('thousand_point')),
|
||||
'attribute' => $attribute_data,
|
||||
'href' => $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $product_id),
|
||||
'remove' => $this->url->link('product/compare', 'language=' . $this->config->get('config_language') . '&remove=' . $product_id)
|
||||
];
|
||||
|
||||
foreach ($attribute_groups as $attribute_group) {
|
||||
$data['attribute_groups'][$attribute_group['attribute_group_id']]['name'] = $attribute_group['name'];
|
||||
|
||||
foreach ($attribute_group['attribute'] as $attribute) {
|
||||
$data['attribute_groups'][$attribute_group['attribute_group_id']]['attribute'][$attribute['attribute_id']]['name'] = $attribute['name'];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
unset($this->session->data['compare'][$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$data['continue'] = $this->url->link('common/home', 'language=' . $this->config->get('config_language'));
|
||||
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['column_right'] = $this->load->controller('common/column_right');
|
||||
$data['content_top'] = $this->load->controller('common/content_top');
|
||||
$data['content_bottom'] = $this->load->controller('common/content_bottom');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
|
||||
$this->response->setOutput($this->load->view('product/compare', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function add(): void {
|
||||
$this->load->language('product/compare');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!isset($this->session->data['compare'])) {
|
||||
$this->session->data['compare'] = [];
|
||||
}
|
||||
|
||||
if (isset($this->request->post['product_id'])) {
|
||||
$product_id = (int)$this->request->post['product_id'];
|
||||
} else {
|
||||
$product_id = 0;
|
||||
}
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
$product_info = $this->model_catalog_product->getProduct($product_id);
|
||||
|
||||
if (!$product_info) {
|
||||
$json['error'] = $this->language->get('error_product');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
// If already in array remove the product_id so it will be added to the back of the array
|
||||
$key = array_search($this->request->post['product_id'], $this->session->data['compare']);
|
||||
|
||||
if ($key !== false) {
|
||||
unset($this->session->data['compare'][$key]);
|
||||
}
|
||||
|
||||
// If we count a numeric value that is greater than 4 products, we remove the first one
|
||||
if (count($this->session->data['compare']) >= 4) {
|
||||
array_shift($this->session->data['compare']);
|
||||
}
|
||||
|
||||
$this->session->data['compare'][] = $this->request->post['product_id'];
|
||||
|
||||
$json['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $this->request->post['product_id']), $product_info['name'], $this->url->link('product/compare', 'language=' . $this->config->get('config_language')));
|
||||
|
||||
$json['total'] = sprintf($this->language->get('text_compare'), (isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0));
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
353
catalog/controller/product/manufacturer.php
Normal file
353
catalog/controller/product/manufacturer.php
Normal file
@ -0,0 +1,353 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Product;
|
||||
/**
|
||||
* Class Manufacturer
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Product
|
||||
*/
|
||||
class Manufacturer extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('product/manufacturer');
|
||||
|
||||
$this->load->model('catalog/manufacturer');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_brand'),
|
||||
'href' => $this->url->link('product/manufacturer', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
$data['categories'] = [];
|
||||
|
||||
$results = $this->model_catalog_manufacturer->getManufacturers();
|
||||
|
||||
foreach ($results as $result) {
|
||||
if (is_numeric(oc_substr($result['name'], 0, 1))) {
|
||||
$key = '0 - 9';
|
||||
} else {
|
||||
$key = oc_substr(oc_strtoupper($result['name']), 0, 1);
|
||||
}
|
||||
|
||||
if (!isset($data['categories'][$key])) {
|
||||
$data['categories'][$key]['name'] = $key;
|
||||
$data['categories'][$key]['href'] = $this->url->link('product/manufacturer', 'language=' . $this->config->get('config_language'));
|
||||
}
|
||||
|
||||
$data['categories'][$key]['manufacturer'][] = [
|
||||
'name' => $result['name'],
|
||||
'href' => $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $result['manufacturer_id'])
|
||||
];
|
||||
}
|
||||
|
||||
$data['continue'] = $this->url->link('common/home', 'language=' . $this->config->get('config_language'));
|
||||
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['column_right'] = $this->load->controller('common/column_right');
|
||||
$data['content_top'] = $this->load->controller('common/content_top');
|
||||
$data['content_bottom'] = $this->load->controller('common/content_bottom');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
|
||||
$this->response->setOutput($this->load->view('product/manufacturer_list', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function info(): \Opencart\System\Engine\Action|null {
|
||||
$this->load->language('product/manufacturer');
|
||||
|
||||
if (isset($this->request->get['manufacturer_id'])) {
|
||||
$manufacturer_id = (int)$this->request->get['manufacturer_id'];
|
||||
} else {
|
||||
$manufacturer_id = 0;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = $this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'p.sort_order';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = $this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['limit']) && (int)$this->request->get['limit']) {
|
||||
$limit = (int)$this->request->get['limit'];
|
||||
} else {
|
||||
$limit = (int)$this->config->get('config_pagination');
|
||||
}
|
||||
|
||||
$this->load->model('catalog/manufacturer');
|
||||
|
||||
$manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($manufacturer_id);
|
||||
|
||||
if ($manufacturer_info) {
|
||||
$this->document->setTitle($manufacturer_info['name']);
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_brand'),
|
||||
'href' => $this->url->link('product/manufacturer', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['limit'])) {
|
||||
$url .= '&limit=' . $this->request->get['limit'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $manufacturer_info['name'],
|
||||
'href' => $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . $url)
|
||||
];
|
||||
|
||||
$data['heading_title'] = $manufacturer_info['name'];
|
||||
|
||||
$data['text_compare'] = sprintf($this->language->get('text_compare'), (isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0));
|
||||
|
||||
$data['compare'] = $this->url->link('product/compare', 'language=' . $this->config->get('config_language'));
|
||||
|
||||
$data['products'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'filter_manufacturer_id' => $manufacturer_id,
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $limit,
|
||||
'limit' => $limit
|
||||
];
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$product_total = $this->model_catalog_product->getTotalProducts($filter_data);
|
||||
|
||||
$results = $this->model_catalog_product->getProducts($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
if (is_file(DIR_IMAGE . html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'))) {
|
||||
$image = $this->model_tool_image->resize(html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'), $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
|
||||
} else {
|
||||
$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
|
||||
}
|
||||
|
||||
if ($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')), $this->session->data['currency']);
|
||||
} 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')), $this->session->data['currency']);
|
||||
} else {
|
||||
$special = false;
|
||||
}
|
||||
|
||||
if ($this->config->get('config_tax')) {
|
||||
$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
|
||||
} else {
|
||||
$tax = false;
|
||||
}
|
||||
|
||||
$product_data = [
|
||||
'product_id' => $result['product_id'],
|
||||
'thumb' => $image,
|
||||
'name' => $result['name'],
|
||||
'description' => oc_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('config_product_description_length')) . '..',
|
||||
'price' => $price,
|
||||
'special' => $special,
|
||||
'tax' => $tax,
|
||||
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
|
||||
'rating' => $result['rating'],
|
||||
'href' => $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $result['manufacturer_id'] . '&product_id=' . $result['product_id'] . $url)
|
||||
];
|
||||
|
||||
$data['products'][] = $this->load->controller('product/thumb', $product_data);
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['limit'])) {
|
||||
$url .= '&limit=' . $this->request->get['limit'];
|
||||
}
|
||||
|
||||
$data['sorts'] = [];
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_default'),
|
||||
'value' => 'p.sort_order-ASC',
|
||||
'href' => $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.sort_order&order=ASC' . $url)
|
||||
];
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_name_asc'),
|
||||
'value' => 'pd.name-ASC',
|
||||
'href' => $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=pd.name&order=ASC' . $url)
|
||||
];
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_name_desc'),
|
||||
'value' => 'pd.name-DESC',
|
||||
'href' => $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=pd.name&order=DESC' . $url)
|
||||
];
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_price_asc'),
|
||||
'value' => 'p.price-ASC',
|
||||
'href' => $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.price&order=ASC' . $url)
|
||||
];
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_price_desc'),
|
||||
'value' => 'p.price-DESC',
|
||||
'href' => $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.price&order=DESC' . $url)
|
||||
];
|
||||
|
||||
if ($this->config->get('config_review_status')) {
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_rating_desc'),
|
||||
'value' => 'rating-DESC',
|
||||
'href' => $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=rating&order=DESC' . $url)
|
||||
];
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_rating_asc'),
|
||||
'value' => 'rating-ASC',
|
||||
'href' => $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=rating&order=ASC' . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_model_asc'),
|
||||
'value' => 'p.model-ASC',
|
||||
'href' => $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.model&order=ASC' . $url)
|
||||
];
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_model_desc'),
|
||||
'value' => 'p.model-DESC',
|
||||
'href' => $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.model&order=DESC' . $url)
|
||||
];
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['limits'] = [];
|
||||
|
||||
$limits = array_unique([$this->config->get('config_pagination'), 25, 50, 75, 100]);
|
||||
|
||||
sort($limits);
|
||||
|
||||
foreach ($limits as $value) {
|
||||
$data['limits'][] = [
|
||||
'text' => $value,
|
||||
'value' => $value,
|
||||
'href' => $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&limit=' . $value)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['limit'])) {
|
||||
$url .= '&limit=' . $this->request->get['limit'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $product_total,
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
'url' => $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($product_total - $limit)) ? $product_total : ((($page - 1) * $limit) + $limit), $product_total, ceil($product_total / $limit));
|
||||
|
||||
// http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html
|
||||
if ($page == 1) {
|
||||
$this->document->addLink($this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id']), 'canonical');
|
||||
} else {
|
||||
$this->document->addLink($this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . '&page=' . $page), 'canonical');
|
||||
}
|
||||
|
||||
if ($page > 1) {
|
||||
$this->document->addLink($this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . (($page - 2) ? '&page=' . ($page - 1) : '')), 'prev');
|
||||
}
|
||||
|
||||
if ($limit && ceil($product_total / $limit) > $page) {
|
||||
$this->document->addLink($this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . '&page=' . ($page + 1)), 'next');
|
||||
}
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
$data['limit'] = $limit;
|
||||
|
||||
$data['continue'] = $this->url->link('common/home', 'language=' . $this->config->get('config_language'));
|
||||
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['column_right'] = $this->load->controller('common/column_right');
|
||||
$data['content_top'] = $this->load->controller('common/content_top');
|
||||
$data['content_bottom'] = $this->load->controller('common/content_bottom');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
|
||||
$this->response->setOutput($this->load->view('product/manufacturer_info', $data));
|
||||
} else {
|
||||
return new \Opencart\System\Engine\Action('error/not_found');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
524
catalog/controller/product/product.php
Normal file
524
catalog/controller/product/product.php
Normal file
@ -0,0 +1,524 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Product;
|
||||
/**
|
||||
* Class Product
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Product
|
||||
*/
|
||||
class Product extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): \Opencart\System\Engine\Action|null {
|
||||
$this->load->language('product/product');
|
||||
|
||||
if (isset($this->request->get['product_id'])) {
|
||||
$product_id = (int)$this->request->get['product_id'];
|
||||
} else {
|
||||
$product_id = 0;
|
||||
}
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
$product_info = $this->model_catalog_product->getProduct($product_id);
|
||||
|
||||
if ($product_info) {
|
||||
$this->document->setTitle($product_info['meta_title']);
|
||||
$this->document->setDescription($product_info['meta_description']);
|
||||
$this->document->setKeywords($product_info['meta_keyword']);
|
||||
$this->document->addLink($this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $product_id), 'canonical');
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
$this->load->model('catalog/category');
|
||||
|
||||
if (isset($this->request->get['path'])) {
|
||||
$path = '';
|
||||
|
||||
$parts = explode('_', (string)$this->request->get['path']);
|
||||
|
||||
$category_id = (int)array_pop($parts);
|
||||
|
||||
foreach ($parts as $path_id) {
|
||||
if (!$path) {
|
||||
$path = $path_id;
|
||||
} else {
|
||||
$path .= '_' . $path_id;
|
||||
}
|
||||
|
||||
$category_info = $this->model_catalog_category->getCategory($path_id);
|
||||
|
||||
if ($category_info) {
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $category_info['name'],
|
||||
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $path)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Set the last category breadcrumb
|
||||
$category_info = $this->model_catalog_category->getCategory($category_id);
|
||||
|
||||
if ($category_info) {
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['limit'])) {
|
||||
$url .= '&limit=' . $this->request->get['limit'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $category_info['name'],
|
||||
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $this->request->get['path'] . $url)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$this->load->model('catalog/manufacturer');
|
||||
|
||||
if (isset($this->request->get['manufacturer_id'])) {
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_brand'),
|
||||
'href' => $this->url->link('product/manufacturer', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['limit'])) {
|
||||
$url .= '&limit=' . $this->request->get['limit'];
|
||||
}
|
||||
|
||||
$manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($this->request->get['manufacturer_id']);
|
||||
|
||||
if ($manufacturer_info) {
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $manufacturer_info['name'],
|
||||
'href' => $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . $url)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->request->get['search']) || isset($this->request->get['tag'])) {
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['search'])) {
|
||||
$url .= '&search=' . $this->request->get['search'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['tag'])) {
|
||||
$url .= '&tag=' . $this->request->get['tag'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['description'])) {
|
||||
$url .= '&description=' . $this->request->get['description'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['category_id'])) {
|
||||
$url .= '&category_id=' . $this->request->get['category_id'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sub_category'])) {
|
||||
$url .= '&sub_category=' . $this->request->get['sub_category'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['limit'])) {
|
||||
$url .= '&limit=' . $this->request->get['limit'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_search'),
|
||||
'href' => $this->url->link('product/search', 'language=' . $this->config->get('config_language') . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['path'])) {
|
||||
$url .= '&path=' . $this->request->get['path'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter'])) {
|
||||
$url .= '&filter=' . $this->request->get['filter'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['manufacturer_id'])) {
|
||||
$url .= '&manufacturer_id=' . $this->request->get['manufacturer_id'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['search'])) {
|
||||
$url .= '&search=' . $this->request->get['search'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['tag'])) {
|
||||
$url .= '&tag=' . $this->request->get['tag'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['description'])) {
|
||||
$url .= '&description=' . $this->request->get['description'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['category_id'])) {
|
||||
$url .= '&category_id=' . $this->request->get['category_id'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sub_category'])) {
|
||||
$url .= '&sub_category=' . $this->request->get['sub_category'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['limit'])) {
|
||||
$url .= '&limit=' . $this->request->get['limit'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $product_info['name'],
|
||||
'href' => $this->url->link('product/product', 'language=' . $this->config->get('config_language') . $url . '&product_id=' . $product_id)
|
||||
];
|
||||
|
||||
$this->document->setTitle($product_info['meta_title']);
|
||||
$this->document->setDescription($product_info['meta_description']);
|
||||
$this->document->setKeywords($product_info['meta_keyword']);
|
||||
$this->document->addLink($this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $product_id), 'canonical');
|
||||
|
||||
$this->document->addScript('catalog/view/javascript/jquery/magnific/jquery.magnific-popup.min.js');
|
||||
$this->document->addStyle('catalog/view/javascript/jquery/magnific/magnific-popup.css');
|
||||
|
||||
$data['heading_title'] = $product_info['name'];
|
||||
|
||||
$data['text_minimum'] = sprintf($this->language->get('text_minimum'), $product_info['minimum']);
|
||||
$data['text_login'] = sprintf($this->language->get('text_login'), $this->url->link('account/login', 'language=' . $this->config->get('config_language')), $this->url->link('account/register', 'language=' . $this->config->get('config_language')));
|
||||
$data['text_reviews'] = sprintf($this->language->get('text_reviews'), (int)$product_info['reviews']);
|
||||
|
||||
$data['tab_review'] = sprintf($this->language->get('tab_review'), $product_info['reviews']);
|
||||
|
||||
$data['error_upload_size'] = sprintf($this->language->get('error_upload_size'), $this->config->get('config_file_max_size'));
|
||||
|
||||
$data['config_file_max_size'] = ((int)$this->config->get('config_file_max_size') * 1024 * 1024);
|
||||
|
||||
$data['upload'] = $this->url->link('tool/upload', 'language=' . $this->config->get('config_language'));
|
||||
|
||||
$data['product_id'] = $product_id;
|
||||
|
||||
$manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($product_info['manufacturer_id']);
|
||||
|
||||
if ($manufacturer_info) {
|
||||
$data['manufacturer'] = $manufacturer_info['name'];
|
||||
} else {
|
||||
$data['manufacturer'] = '';
|
||||
}
|
||||
|
||||
$data['manufacturers'] = $this->url->link('product/manufacturer.info', 'language=' . $this->config->get('config_language') . '&manufacturer_id=' . $product_info['manufacturer_id']);
|
||||
$data['model'] = $product_info['model'];
|
||||
$data['reward'] = $product_info['reward'];
|
||||
$data['points'] = $product_info['points'];
|
||||
$data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');
|
||||
|
||||
if ($product_info['quantity'] <= 0) {
|
||||
$this->load->model('localisation/stock_status');
|
||||
|
||||
$stock_status_info = $this->model_localisation_stock_status->getStockStatus($product_info['stock_status_id']);
|
||||
|
||||
if ($stock_status_info) {
|
||||
$data['stock'] = $stock_status_info['name'];
|
||||
} else {
|
||||
$data['stock'] = '';
|
||||
}
|
||||
} elseif ($this->config->get('config_stock_display')) {
|
||||
$data['stock'] = $product_info['quantity'];
|
||||
} else {
|
||||
$data['stock'] = $this->language->get('text_instock');
|
||||
}
|
||||
|
||||
$data['rating'] = (int)$product_info['rating'];
|
||||
$data['review_status'] = (int)$this->config->get('config_review_status');
|
||||
|
||||
$data['review'] = $this->load->controller('product/review');
|
||||
|
||||
$data['add_to_wishlist'] = $this->url->link('account/wishlist.add', 'language=' . $this->config->get('config_language'));
|
||||
$data['add_to_compare'] = $this->url->link('product/compare.add', 'language=' . $this->config->get('config_language'));
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
if (is_file(DIR_IMAGE . html_entity_decode($product_info['image'], ENT_QUOTES, 'UTF-8'))) {
|
||||
$data['popup'] = $this->model_tool_image->resize(html_entity_decode($product_info['image'], ENT_QUOTES, 'UTF-8'), $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height'));
|
||||
} else {
|
||||
$data['popup'] = '';
|
||||
}
|
||||
|
||||
if (is_file(DIR_IMAGE . html_entity_decode($product_info['image'], ENT_QUOTES, 'UTF-8'))) {
|
||||
$data['thumb'] = $this->model_tool_image->resize(html_entity_decode($product_info['image'], ENT_QUOTES, 'UTF-8'), $this->config->get('config_image_thumb_width'), $this->config->get('config_image_thumb_height'));
|
||||
} else {
|
||||
$data['thumb'] = '';
|
||||
}
|
||||
|
||||
$data['images'] = [];
|
||||
|
||||
$results = $this->model_catalog_product->getImages($product_id);
|
||||
|
||||
foreach ($results as $result) {
|
||||
if (is_file(DIR_IMAGE . html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'))) {
|
||||
$data['images'][] = [
|
||||
'popup' => $this->model_tool_image->resize(html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'), $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height')),
|
||||
'thumb' => $this->model_tool_image->resize(html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'), $this->config->get('config_image_additional_width'), $this->config->get('config_image_additional_height'))
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
|
||||
$data['price'] = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
|
||||
} else {
|
||||
$data['price'] = false;
|
||||
}
|
||||
|
||||
if ((float)$product_info['special']) {
|
||||
$data['special'] = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
|
||||
} else {
|
||||
$data['special'] = false;
|
||||
}
|
||||
|
||||
if ($this->config->get('config_tax')) {
|
||||
$data['tax'] = $this->currency->format((float)$product_info['special'] ? $product_info['special'] : $product_info['price'], $this->session->data['currency']);
|
||||
} else {
|
||||
$data['tax'] = false;
|
||||
}
|
||||
|
||||
$discounts = $this->model_catalog_product->getDiscounts($product_id);
|
||||
|
||||
$data['discounts'] = [];
|
||||
|
||||
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
|
||||
foreach ($discounts as $discount) {
|
||||
$data['discounts'][] = [
|
||||
'quantity' => $discount['quantity'],
|
||||
'price' => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency'])
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$data['options'] = [];
|
||||
|
||||
// Check if product is variant
|
||||
if ($product_info['master_id']) {
|
||||
$product_id = (int)$product_info['master_id'];
|
||||
} else {
|
||||
$product_id = (int)$this->request->get['product_id'];
|
||||
}
|
||||
|
||||
$product_options = $this->model_catalog_product->getOptions($product_id);
|
||||
|
||||
foreach ($product_options as $option) {
|
||||
if ((int)$this->request->get['product_id'] && !isset($product_info['override']['variant'][$option['product_option_id']])) {
|
||||
$product_option_value_data = [];
|
||||
|
||||
foreach ($option['product_option_value'] as $option_value) {
|
||||
if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
|
||||
if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option_value['price']) {
|
||||
$price = $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax') ? 'P' : false), $this->session->data['currency']);
|
||||
} else {
|
||||
$price = false;
|
||||
}
|
||||
|
||||
if (is_file(DIR_IMAGE . html_entity_decode($option_value['image'], ENT_QUOTES, 'UTF-8'))) {
|
||||
$image = $this->model_tool_image->resize(html_entity_decode($option_value['image'], ENT_QUOTES, 'UTF-8'), 50, 50);
|
||||
} else {
|
||||
$image = '';
|
||||
}
|
||||
|
||||
$product_option_value_data[] = [
|
||||
'product_option_value_id' => $option_value['product_option_value_id'],
|
||||
'option_value_id' => $option_value['option_value_id'],
|
||||
'name' => $option_value['name'],
|
||||
'image' => $image,
|
||||
'price' => $price,
|
||||
'price_prefix' => $option_value['price_prefix']
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$data['options'][] = [
|
||||
'product_option_id' => $option['product_option_id'],
|
||||
'product_option_value' => $product_option_value_data,
|
||||
'option_id' => $option['option_id'],
|
||||
'name' => $option['name'],
|
||||
'type' => $option['type'],
|
||||
'value' => $option['value'],
|
||||
'required' => $option['required']
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Subscriptions
|
||||
$data['subscription_plans'] = [];
|
||||
|
||||
$results = $this->model_catalog_product->getSubscriptions($product_id);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$description = '';
|
||||
|
||||
if ($result['trial_status']) {
|
||||
$trial_price = $this->currency->format($this->tax->calculate($result['trial_price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
|
||||
$trial_cycle = $result['trial_cycle'];
|
||||
$trial_frequency = $this->language->get('text_' . $result['trial_frequency']);
|
||||
$trial_duration = $result['trial_duration'];
|
||||
|
||||
$description .= sprintf($this->language->get('text_subscription_trial'), $trial_price, $trial_cycle, $trial_frequency, $trial_duration);
|
||||
}
|
||||
|
||||
$price = $this->currency->format($this->tax->calculate($result['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
|
||||
$cycle = $result['cycle'];
|
||||
$frequency = $this->language->get('text_' . $result['frequency']);
|
||||
$duration = $result['duration'];
|
||||
|
||||
if ($duration) {
|
||||
$description .= sprintf($this->language->get('text_subscription_duration'), $price, $cycle, $frequency, $duration);
|
||||
} else {
|
||||
$description .= sprintf($this->language->get('text_subscription_cancel'), $price, $cycle, $frequency);
|
||||
}
|
||||
|
||||
$data['subscription_plans'][] = [
|
||||
'subscription_plan_id' => $result['subscription_plan_id'],
|
||||
'name' => $result['name'],
|
||||
'description' => $description
|
||||
];
|
||||
}
|
||||
|
||||
if ($product_info['minimum']) {
|
||||
$data['minimum'] = $product_info['minimum'];
|
||||
} else {
|
||||
$data['minimum'] = 1;
|
||||
}
|
||||
|
||||
$data['share'] = $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . (int)$this->request->get['product_id']);
|
||||
|
||||
$data['attribute_groups'] = $this->model_catalog_product->getAttributes($product_id);
|
||||
|
||||
$data['products'] = [];
|
||||
|
||||
$results = $this->model_catalog_product->getRelated($product_id);
|
||||
|
||||
foreach ($results as $result) {
|
||||
if (is_file(DIR_IMAGE . html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'))) {
|
||||
$image = $this->model_tool_image->resize(html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'), $this->config->get('config_image_related_width'), $this->config->get('config_image_related_height'));
|
||||
} else {
|
||||
$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('config_image_related_width'), $this->config->get('config_image_related_height'));
|
||||
}
|
||||
|
||||
if ($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')), $this->session->data['currency']);
|
||||
} 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')), $this->session->data['currency']);
|
||||
} else {
|
||||
$special = false;
|
||||
}
|
||||
|
||||
if ($this->config->get('config_tax')) {
|
||||
$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
|
||||
} else {
|
||||
$tax = false;
|
||||
}
|
||||
|
||||
$product_data = [
|
||||
'product_id' => $result['product_id'],
|
||||
'thumb' => $image,
|
||||
'name' => $result['name'],
|
||||
'description' => oc_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('config_product_description_length')) . '..',
|
||||
'price' => $price,
|
||||
'special' => $special,
|
||||
'tax' => $tax,
|
||||
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
|
||||
'rating' => $result['rating'],
|
||||
'href' => $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $result['product_id'])
|
||||
];
|
||||
|
||||
$data['products'][] = $this->load->controller('product/thumb', $product_data);
|
||||
}
|
||||
|
||||
$data['tags'] = [];
|
||||
|
||||
if ($product_info['tag']) {
|
||||
$tags = explode(',', $product_info['tag']);
|
||||
|
||||
foreach ($tags as $tag) {
|
||||
$data['tags'][] = [
|
||||
'tag' => trim($tag),
|
||||
'href' => $this->url->link('product/search', 'language=' . $this->config->get('config_language') . '&tag=' . trim($tag))
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->config->get('config_product_report_status')) {
|
||||
$this->model_catalog_product->addReport($this->request->get['product_id'], $this->request->server['REMOTE_ADDR']);
|
||||
}
|
||||
|
||||
$data['language'] = $this->config->get('config_language');
|
||||
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['column_right'] = $this->load->controller('common/column_right');
|
||||
$data['content_top'] = $this->load->controller('common/content_top');
|
||||
$data['content_bottom'] = $this->load->controller('common/content_bottom');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
|
||||
$this->response->setOutput($this->load->view('product/product', $data));
|
||||
} else {
|
||||
return new \Opencart\System\Engine\Action('error/not_found');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
198
catalog/controller/product/review.php
Normal file
198
catalog/controller/product/review.php
Normal file
@ -0,0 +1,198 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Product;
|
||||
/**
|
||||
* Class Review
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Product
|
||||
*/
|
||||
class Review extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
$this->load->language('product/review');
|
||||
|
||||
$data['text_login'] = sprintf($this->language->get('text_login'), $this->url->link('account/login', 'language=' . $this->config->get('config_language')), $this->url->link('account/register', 'language=' . $this->config->get('config_language')));
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
if (isset($this->request->get['product_id'])) {
|
||||
$data['product_id'] = (int)$this->request->get['product_id'];
|
||||
} else {
|
||||
$data['product_id'] = 0;
|
||||
}
|
||||
|
||||
if ($this->customer->isLogged() || $this->config->get('config_review_guest')) {
|
||||
$data['review_guest'] = true;
|
||||
} else {
|
||||
$data['review_guest'] = false;
|
||||
}
|
||||
|
||||
if ($this->customer->isLogged()) {
|
||||
$data['customer_name'] = $this->customer->getFirstName() . ' ' . $this->customer->getLastName();
|
||||
} else {
|
||||
$data['customer_name'] = '';
|
||||
}
|
||||
|
||||
// Create a login token to prevent brute force attacks
|
||||
$this->session->data['review_token'] = oc_token(32);
|
||||
|
||||
$data['review_token'] = $this->session->data['review_token'];
|
||||
|
||||
// Captcha
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$extension_info = $this->model_setting_extension->getExtensionByCode('captcha', $this->config->get('config_captcha'));
|
||||
|
||||
if ($extension_info && $this->config->get('captcha_' . $this->config->get('config_captcha') . '_status') && in_array('review', (array)$this->config->get('config_captcha_page'))) {
|
||||
$data['captcha'] = $this->load->controller('extension/' . $extension_info['extension'] . '/captcha/' . $extension_info['code']);
|
||||
} else {
|
||||
$data['captcha'] = '';
|
||||
}
|
||||
|
||||
$data['language'] = $this->config->get('config_language');
|
||||
|
||||
return $this->load->view('product/review', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function write(): void {
|
||||
$this->load->language('product/review');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['product_id'])) {
|
||||
$product_id = (int)$this->request->get['product_id'];
|
||||
} else {
|
||||
$product_id = 0;
|
||||
}
|
||||
|
||||
if (!isset($this->request->get['review_token']) || !isset($this->session->data['review_token']) || $this->request->get['review_token'] != $this->session->data['review_token']) {
|
||||
$json['error']['warning'] = $this->language->get('error_token');
|
||||
}
|
||||
|
||||
$keys = [
|
||||
'name',
|
||||
'text',
|
||||
'rating'
|
||||
];
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if (!isset($this->request->post[$key])) {
|
||||
$this->request->post[$key] = '';
|
||||
}
|
||||
}
|
||||
|
||||
$this->load->model('product/product');
|
||||
|
||||
$product_info = $this->model_product_product->getProduct($product_id);
|
||||
|
||||
if (!$product_info) {
|
||||
$json['error']['warning'] = $this->language->get('error_product');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['name']) < 3) || (oc_strlen($this->request->post['name']) > 25)) {
|
||||
$json['error']['name'] = $this->language->get('error_name');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['text']) < 25) || (oc_strlen($this->request->post['text']) > 1000)) {
|
||||
$json['error']['text'] = $this->language->get('error_text');
|
||||
}
|
||||
|
||||
if ($this->request->post['rating'] < 1 || $this->request->post['rating'] > 5) {
|
||||
$json['error']['rating'] = $this->language->get('error_rating');
|
||||
}
|
||||
|
||||
if (!$this->customer->isLogged() && !$this->config->get('config_review_guest')) {
|
||||
$json['error']['warning'] = $this->language->get('error_guest');
|
||||
}
|
||||
|
||||
if ($this->customer->isLogged() && $this->config->get('config_review_purchased')) {
|
||||
$this->load->model('account/order');
|
||||
|
||||
if (!$this->model_account_order->getTotalOrdersByProductId($product_id)) {
|
||||
$json['error']['purchased'] = $this->language->get('error_purchased');
|
||||
}
|
||||
}
|
||||
|
||||
// Captcha
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$extension_info = $this->model_setting_extension->getExtensionByCode('captcha', $this->config->get('config_captcha'));
|
||||
|
||||
if ($extension_info && $this->config->get('captcha_' . $this->config->get('config_captcha') . '_status') && in_array('review', (array)$this->config->get('config_captcha_page'))) {
|
||||
$captcha = $this->load->controller('extension/' . $extension_info['extension'] . '/captcha/' . $extension_info['code'] . '.validate');
|
||||
|
||||
if ($captcha) {
|
||||
$json['error']['captcha'] = $captcha;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('catalog/review');
|
||||
|
||||
$this->model_catalog_review->addReview($product_id, $this->request->post);
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('product/review');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getList(): string {
|
||||
if (isset($this->request->get['product_id'])) {
|
||||
$product_id = (int)$this->request->get['product_id'];
|
||||
} else {
|
||||
$product_id = 0;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$data['reviews'] = [];
|
||||
|
||||
$this->load->model('catalog/review');
|
||||
|
||||
$review_total = $this->model_catalog_review->getTotalReviewsByProductId($product_id);
|
||||
|
||||
$results = $this->model_catalog_review->getReviewsByProductId($product_id, ($page - 1) * 5, 5);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['reviews'][] = [
|
||||
'author' => $result['author'],
|
||||
'text' => nl2br($result['text']),
|
||||
'rating' => (int)$result['rating'],
|
||||
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
|
||||
];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $review_total,
|
||||
'page' => $page,
|
||||
'limit' => 5,
|
||||
'url' => $this->url->link('product/review.list', 'language=' . $this->config->get('config_language') . '&product_id=' . $product_id . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($review_total) ? (($page - 1) * 5) + 1 : 0, ((($page - 1) * 5) > ($review_total - 5)) ? $review_total : ((($page - 1) * 5) + 5), $review_total, ceil($review_total / 5));
|
||||
|
||||
return $this->load->view('product/review_list', $data);
|
||||
}
|
||||
}
|
461
catalog/controller/product/search.php
Normal file
461
catalog/controller/product/search.php
Normal file
@ -0,0 +1,461 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Product;
|
||||
/**
|
||||
* Class Search
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Product
|
||||
*/
|
||||
class Search extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('product/search');
|
||||
|
||||
$this->load->model('catalog/category');
|
||||
$this->load->model('catalog/product');
|
||||
$this->load->model('tool/image');
|
||||
|
||||
if (isset($this->request->get['search'])) {
|
||||
$search = $this->request->get['search'];
|
||||
} else {
|
||||
$search = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['tag'])) {
|
||||
$tag = $this->request->get['tag'];
|
||||
} elseif (isset($this->request->get['search'])) {
|
||||
$tag = $this->request->get['search'];
|
||||
} else {
|
||||
$tag = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['description'])) {
|
||||
$description = $this->request->get['description'];
|
||||
} else {
|
||||
$description = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['category_id'])) {
|
||||
$category_id = (int)$this->request->get['category_id'];
|
||||
} else {
|
||||
$category_id = 0;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sub_category'])) {
|
||||
$sub_category = $this->request->get['sub_category'];
|
||||
} else {
|
||||
$sub_category = 0;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = $this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'p.sort_order';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = $this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['limit']) && (int)$this->request->get['limit']) {
|
||||
$limit = (int)$this->request->get['limit'];
|
||||
} else {
|
||||
$limit = $this->config->get('config_pagination');
|
||||
}
|
||||
|
||||
if (isset($this->request->get['search'])) {
|
||||
$this->document->setTitle($this->language->get('heading_title') . ' - ' . $this->request->get['search']);
|
||||
} elseif (isset($this->request->get['tag'])) {
|
||||
$this->document->setTitle($this->language->get('heading_title') . ' - ' . $this->language->get('heading_tag') . $this->request->get['tag']);
|
||||
} else {
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['search'])) {
|
||||
$url .= '&search=' . urlencode(html_entity_decode($this->request->get['search'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['tag'])) {
|
||||
$url .= '&tag=' . urlencode(html_entity_decode($this->request->get['tag'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['description'])) {
|
||||
$url .= '&description=' . $this->request->get['description'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['category_id'])) {
|
||||
$url .= '&category_id=' . $this->request->get['category_id'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sub_category'])) {
|
||||
$url .= '&sub_category=' . $this->request->get['sub_category'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['limit'])) {
|
||||
$url .= '&limit=' . $this->request->get['limit'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('product/search', 'language=' . $this->config->get('config_language') . $url)
|
||||
];
|
||||
|
||||
if (isset($this->request->get['search'])) {
|
||||
$data['heading_title'] = $this->language->get('heading_title') . ' - ' . $this->request->get['search'];
|
||||
} else {
|
||||
$data['heading_title'] = $this->language->get('heading_title');
|
||||
}
|
||||
|
||||
$data['text_compare'] = sprintf($this->language->get('text_compare'), (isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0));
|
||||
|
||||
$data['compare'] = $this->url->link('product/compare', 'language=' . $this->config->get('config_language'));
|
||||
|
||||
$this->load->model('catalog/category');
|
||||
|
||||
// 3 Level Category Search
|
||||
$data['categories'] = [];
|
||||
|
||||
$categories_1 = $this->model_catalog_category->getCategories(0);
|
||||
|
||||
foreach ($categories_1 as $category_1) {
|
||||
$level_2_data = [];
|
||||
|
||||
$categories_2 = $this->model_catalog_category->getCategories($category_1['category_id']);
|
||||
|
||||
foreach ($categories_2 as $category_2) {
|
||||
$level_3_data = [];
|
||||
|
||||
$categories_3 = $this->model_catalog_category->getCategories($category_2['category_id']);
|
||||
|
||||
foreach ($categories_3 as $category_3) {
|
||||
$level_3_data[] = [
|
||||
'category_id' => $category_3['category_id'],
|
||||
'name' => $category_3['name'],
|
||||
];
|
||||
}
|
||||
|
||||
$level_2_data[] = [
|
||||
'category_id' => $category_2['category_id'],
|
||||
'name' => $category_2['name'],
|
||||
'children' => $level_3_data
|
||||
];
|
||||
}
|
||||
|
||||
$data['categories'][] = [
|
||||
'category_id' => $category_1['category_id'],
|
||||
'name' => $category_1['name'],
|
||||
'children' => $level_2_data
|
||||
];
|
||||
}
|
||||
|
||||
$data['products'] = [];
|
||||
|
||||
if ($search || $tag) {
|
||||
$filter_data = [
|
||||
'filter_search' => $search,
|
||||
'filter_tag' => $tag,
|
||||
'filter_description' => $description,
|
||||
'filter_category_id' => $category_id,
|
||||
'filter_sub_category' => $sub_category,
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $limit,
|
||||
'limit' => $limit
|
||||
];
|
||||
|
||||
$product_total = $this->model_catalog_product->getTotalProducts($filter_data);
|
||||
|
||||
$results = $this->model_catalog_product->getProducts($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
if (is_file(DIR_IMAGE . html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'))) {
|
||||
$image = $this->model_tool_image->resize(html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'), $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
|
||||
} else {
|
||||
$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
|
||||
}
|
||||
|
||||
if ($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')), $this->session->data['currency']);
|
||||
} 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')), $this->session->data['currency']);
|
||||
} else {
|
||||
$special = false;
|
||||
}
|
||||
|
||||
if ($this->config->get('config_tax')) {
|
||||
$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
|
||||
} else {
|
||||
$tax = false;
|
||||
}
|
||||
|
||||
$product_data = [
|
||||
'product_id' => $result['product_id'],
|
||||
'thumb' => $image,
|
||||
'name' => $result['name'],
|
||||
'description' => oc_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('config_product_description_length')) . '..',
|
||||
'price' => $price,
|
||||
'special' => $special,
|
||||
'tax' => $tax,
|
||||
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
|
||||
'rating' => $result['rating'],
|
||||
'href' => $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $result['product_id'] . $url)
|
||||
];
|
||||
|
||||
$data['products'][] = $this->load->controller('product/thumb', $product_data);
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['search'])) {
|
||||
$url .= '&search=' . urlencode(html_entity_decode($this->request->get['search'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['tag'])) {
|
||||
$url .= '&tag=' . urlencode(html_entity_decode($this->request->get['tag'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['description'])) {
|
||||
$url .= '&description=' . $this->request->get['description'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['category_id'])) {
|
||||
$url .= '&category_id=' . $this->request->get['category_id'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sub_category'])) {
|
||||
$url .= '&sub_category=' . $this->request->get['sub_category'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['limit'])) {
|
||||
$url .= '&limit=' . $this->request->get['limit'];
|
||||
}
|
||||
|
||||
$data['sorts'] = [];
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_default'),
|
||||
'value' => 'p.sort_order-ASC',
|
||||
'href' => $this->url->link('product/search', 'language=' . $this->config->get('config_language') . '&sort=p.sort_order&order=ASC' . $url)
|
||||
];
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_name_asc'),
|
||||
'value' => 'pd.name-ASC',
|
||||
'href' => $this->url->link('product/search', 'language=' . $this->config->get('config_language') . '&sort=pd.name&order=ASC' . $url)
|
||||
];
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_name_desc'),
|
||||
'value' => 'pd.name-DESC',
|
||||
'href' => $this->url->link('product/search', 'language=' . $this->config->get('config_language') . '&sort=pd.name&order=DESC' . $url)
|
||||
];
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_price_asc'),
|
||||
'value' => 'p.price-ASC',
|
||||
'href' => $this->url->link('product/search', 'language=' . $this->config->get('config_language') . '&sort=p.price&order=ASC' . $url)
|
||||
];
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_price_desc'),
|
||||
'value' => 'p.price-DESC',
|
||||
'href' => $this->url->link('product/search', 'language=' . $this->config->get('config_language') . '&sort=p.price&order=DESC' . $url)
|
||||
];
|
||||
|
||||
if ($this->config->get('config_review_status')) {
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_rating_desc'),
|
||||
'value' => 'rating-DESC',
|
||||
'href' => $this->url->link('product/search', 'language=' . $this->config->get('config_language') . '&sort=rating&order=DESC' . $url)
|
||||
];
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_rating_asc'),
|
||||
'value' => 'rating-ASC',
|
||||
'href' => $this->url->link('product/search', 'language=' . $this->config->get('config_language') . '&sort=rating&order=ASC' . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_model_asc'),
|
||||
'value' => 'p.model-ASC',
|
||||
'href' => $this->url->link('product/search', 'language=' . $this->config->get('config_language') . '&sort=p.model&order=ASC' . $url)
|
||||
];
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_model_desc'),
|
||||
'value' => 'p.model-DESC',
|
||||
'href' => $this->url->link('product/search', 'language=' . $this->config->get('config_language') . '&sort=p.model&order=DESC' . $url)
|
||||
];
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['search'])) {
|
||||
$url .= '&search=' . urlencode(html_entity_decode($this->request->get['search'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['tag'])) {
|
||||
$url .= '&tag=' . urlencode(html_entity_decode($this->request->get['tag'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['description'])) {
|
||||
$url .= '&description=' . $this->request->get['description'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['category_id'])) {
|
||||
$url .= '&category_id=' . $this->request->get['category_id'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sub_category'])) {
|
||||
$url .= '&sub_category=' . $this->request->get['sub_category'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['limits'] = [];
|
||||
|
||||
$limits = array_unique([$this->config->get('config_pagination'), 25, 50, 75, 100]);
|
||||
|
||||
sort($limits);
|
||||
|
||||
foreach ($limits as $value) {
|
||||
$data['limits'][] = [
|
||||
'text' => $value,
|
||||
'value' => $value,
|
||||
'href' => $this->url->link('product/search', 'language=' . $this->config->get('config_language') . $url . '&limit=' . $value)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['search'])) {
|
||||
$url .= '&search=' . urlencode(html_entity_decode($this->request->get['search'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['tag'])) {
|
||||
$url .= '&tag=' . urlencode(html_entity_decode($this->request->get['tag'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['description'])) {
|
||||
$url .= '&description=' . $this->request->get['description'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['category_id'])) {
|
||||
$url .= '&category_id=' . $this->request->get['category_id'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sub_category'])) {
|
||||
$url .= '&sub_category=' . $this->request->get['sub_category'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['limit'])) {
|
||||
$url .= '&limit=' . $this->request->get['limit'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $product_total,
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
'url' => $this->url->link('product/search', 'language=' . $this->config->get('config_language') . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($product_total - $limit)) ? $product_total : ((($page - 1) * $limit) + $limit), $product_total, ceil($product_total / $limit));
|
||||
|
||||
if (isset($this->request->get['search']) && $this->config->get('config_customer_search')) {
|
||||
$this->load->model('account/search');
|
||||
|
||||
if ($this->customer->isLogged()) {
|
||||
$customer_id = $this->customer->getId();
|
||||
} else {
|
||||
$customer_id = 0;
|
||||
}
|
||||
|
||||
if (isset($this->request->server['REMOTE_ADDR'])) {
|
||||
$ip = $this->request->server['REMOTE_ADDR'];
|
||||
} else {
|
||||
$ip = '';
|
||||
}
|
||||
|
||||
$search_data = [
|
||||
'keyword' => $search,
|
||||
'category_id' => $category_id,
|
||||
'sub_category' => $sub_category,
|
||||
'description' => $description,
|
||||
'products' => $product_total,
|
||||
'customer_id' => $customer_id,
|
||||
'ip' => $ip
|
||||
];
|
||||
|
||||
$this->model_account_search->addSearch($search_data);
|
||||
}
|
||||
}
|
||||
|
||||
$data['search'] = $search;
|
||||
$data['description'] = $description;
|
||||
$data['category_id'] = $category_id;
|
||||
$data['sub_category'] = $sub_category;
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
$data['limit'] = $limit;
|
||||
|
||||
$data['language'] = $this->config->get('config_language');
|
||||
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['column_right'] = $this->load->controller('common/column_right');
|
||||
$data['content_top'] = $this->load->controller('common/content_top');
|
||||
$data['content_bottom'] = $this->load->controller('common/content_bottom');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
|
||||
$this->response->setOutput($this->load->view('product/search', $data));
|
||||
}
|
||||
}
|
274
catalog/controller/product/special.php
Normal file
274
catalog/controller/product/special.php
Normal file
@ -0,0 +1,274 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Product;
|
||||
/**
|
||||
* Class Special
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Product
|
||||
*/
|
||||
class Special extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('product/special');
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = $this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'p.sort_order';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = $this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['limit']) && (int)$this->request->get['limit']) {
|
||||
$limit = (int)$this->request->get['limit'];
|
||||
} else {
|
||||
$limit = $this->config->get('config_pagination');
|
||||
}
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
|
||||
];
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['limit'])) {
|
||||
$url .= '&limit=' . $this->request->get['limit'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . $url)
|
||||
];
|
||||
|
||||
$data['text_compare'] = sprintf($this->language->get('text_compare'), (isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0));
|
||||
|
||||
$data['compare'] = $this->url->link('product/compare', 'language=' . $this->config->get('config_language'));
|
||||
|
||||
$data['products'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $limit,
|
||||
'limit' => $limit
|
||||
];
|
||||
|
||||
$product_total = $this->model_catalog_product->getTotalSpecials();
|
||||
|
||||
$results = $this->model_catalog_product->getSpecials($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
if (is_file(DIR_IMAGE . html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'))) {
|
||||
$image = $this->model_tool_image->resize(html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'), $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
|
||||
} else {
|
||||
$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
|
||||
}
|
||||
|
||||
if ($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')), $this->session->data['currency']);
|
||||
} 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')), $this->session->data['currency']);
|
||||
} else {
|
||||
$special = false;
|
||||
}
|
||||
|
||||
if ($this->config->get('config_tax')) {
|
||||
$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
|
||||
} else {
|
||||
$tax = false;
|
||||
}
|
||||
|
||||
$product_data = [
|
||||
'product_id' => $result['product_id'],
|
||||
'thumb' => $image,
|
||||
'name' => $result['name'],
|
||||
'description' => oc_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('config_product_description_length')) . '..',
|
||||
'price' => $price,
|
||||
'special' => $special,
|
||||
'tax' => $tax,
|
||||
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
|
||||
'rating' => $result['rating'],
|
||||
'href' => $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $result['product_id'] . $url)
|
||||
];
|
||||
|
||||
$data['products'][] = $this->load->controller('product/thumb', $product_data);
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['limit'])) {
|
||||
$url .= '&limit=' . $this->request->get['limit'];
|
||||
}
|
||||
|
||||
$data['sorts'] = [];
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_default'),
|
||||
'value' => 'p.sort_order-ASC',
|
||||
'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&sort=p.sort_order&order=ASC' . $url)
|
||||
];
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_name_asc'),
|
||||
'value' => 'pd.name-ASC',
|
||||
'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&sort=pd.name&order=ASC' . $url)
|
||||
];
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_name_desc'),
|
||||
'value' => 'pd.name-DESC',
|
||||
'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&sort=pd.name&order=DESC' . $url)
|
||||
];
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_price_asc'),
|
||||
'value' => 'ps.price-ASC',
|
||||
'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&sort=ps.price&order=ASC' . $url)
|
||||
];
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_price_desc'),
|
||||
'value' => 'ps.price-DESC',
|
||||
'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&sort=ps.price&order=DESC' . $url)
|
||||
];
|
||||
|
||||
if ($this->config->get('config_review_status')) {
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_rating_desc'),
|
||||
'value' => 'rating-DESC',
|
||||
'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&sort=rating&order=DESC' . $url)
|
||||
];
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_rating_asc'),
|
||||
'value' => 'rating-ASC',
|
||||
'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&sort=rating&order=ASC' . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_model_asc'),
|
||||
'value' => 'p.model-ASC',
|
||||
'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&sort=p.model&order=ASC' . $url)
|
||||
];
|
||||
|
||||
$data['sorts'][] = [
|
||||
'text' => $this->language->get('text_model_desc'),
|
||||
'value' => 'p.model-DESC',
|
||||
'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&sort=p.model&order=DESC' . $url)
|
||||
];
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['limits'] = [];
|
||||
|
||||
$limits = array_unique([$this->config->get('config_pagination'), 25, 50, 75, 100]);
|
||||
|
||||
sort($limits);
|
||||
|
||||
foreach ($limits as $value) {
|
||||
$data['limits'][] = [
|
||||
'text' => $value,
|
||||
'value' => $value,
|
||||
'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . $url . '&limit=' . $value)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['limit'])) {
|
||||
$url .= '&limit=' . $this->request->get['limit'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $product_total,
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
'url' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($product_total - $limit)) ? $product_total : ((($page - 1) * $limit) + $limit), $product_total, ceil($product_total / $limit));
|
||||
|
||||
// http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html
|
||||
if ($page == 1) {
|
||||
$this->document->addLink($this->url->link('product/special', 'language=' . $this->config->get('config_language')), 'canonical');
|
||||
} else {
|
||||
$this->document->addLink($this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&page='. $page), 'canonical');
|
||||
}
|
||||
|
||||
if ($page > 1) {
|
||||
$this->document->addLink($this->url->link('product/special', 'language=' . $this->config->get('config_language') . (($page - 2) ? '&page='. ($page - 1) : '')), 'prev');
|
||||
}
|
||||
|
||||
if ($limit && ceil($product_total / $limit) > $page) {
|
||||
$this->document->addLink($this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&page='. ($page + 1)), 'next');
|
||||
}
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
$data['limit'] = $limit;
|
||||
|
||||
$data['continue'] = $this->url->link('common/home', 'language=' . $this->config->get('config_language'));
|
||||
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['column_right'] = $this->load->controller('common/column_right');
|
||||
$data['content_top'] = $this->load->controller('common/content_top');
|
||||
$data['content_bottom'] = $this->load->controller('common/content_bottom');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
|
||||
$this->response->setOutput($this->load->view('product/special', $data));
|
||||
}
|
||||
}
|
27
catalog/controller/product/thumb.php
Normal file
27
catalog/controller/product/thumb.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Product;
|
||||
/**
|
||||
* Class Thumb
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Product
|
||||
*/
|
||||
class Thumb extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function index(array $data): string {
|
||||
$this->load->language('product/thumb');
|
||||
|
||||
$data['cart'] = $this->url->link('common/cart.info', 'language=' . $this->config->get('config_language'));
|
||||
|
||||
$data['add_to_cart'] = $this->url->link('checkout/cart.add', 'language=' . $this->config->get('config_language'));
|
||||
$data['add_to_wishlist'] = $this->url->link('account/wishlist.add', 'language=' . $this->config->get('config_language'));
|
||||
$data['add_to_compare'] = $this->url->link('product/compare.add', 'language=' . $this->config->get('config_language'));
|
||||
|
||||
$data['review_status'] = (int)$this->config->get('config_review_status');
|
||||
|
||||
return $this->load->view('product/thumb', $data);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user