first commit
This commit is contained in:
93
controllers/front/listing/BestSalesController.php
Normal file
93
controllers/front/listing/BestSalesController.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
use PrestaShop\PrestaShop\Adapter\BestSales\BestSalesProductSearchProvider;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
|
||||
|
||||
class BestSalesControllerCore extends ProductListingFrontController
|
||||
{
|
||||
public $php_self = 'best-sales';
|
||||
|
||||
/**
|
||||
* Initializes controller.
|
||||
*
|
||||
* @see FrontController::init()
|
||||
*
|
||||
* @throws PrestaShopException
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
if (Configuration::get('PS_DISPLAY_BEST_SELLERS')) {
|
||||
parent::init();
|
||||
} else {
|
||||
Tools::redirect('pagenotfound');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
parent::initContent();
|
||||
|
||||
$this->doProductSearch('catalog/listing/best-sales', ['entity' => 'best-sales']);
|
||||
}
|
||||
|
||||
protected function getProductSearchQuery()
|
||||
{
|
||||
$query = new ProductSearchQuery();
|
||||
$query
|
||||
->setQueryType('best-sales')
|
||||
->setSortOrder(new SortOrder('product', 'name', 'asc'));
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function getDefaultProductSearchProvider()
|
||||
{
|
||||
return new BestSalesProductSearchProvider(
|
||||
$this->getTranslator()
|
||||
);
|
||||
}
|
||||
|
||||
public function getListingLabel()
|
||||
{
|
||||
return $this->getTranslator()->trans('Best sellers', [], 'Shop.Theme.Catalog');
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->trans('Best sellers', [], 'Shop.Theme.Catalog'),
|
||||
'url' => $this->context->link->getPageLink('best-sales', true),
|
||||
];
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
}
|
||||
298
controllers/front/listing/CategoryController.php
Normal file
298
controllers/front/listing/CategoryController.php
Normal file
@@ -0,0 +1,298 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
use PrestaShop\PrestaShop\Adapter\Category\CategoryProductSearchProvider;
|
||||
use PrestaShop\PrestaShop\Adapter\Image\ImageRetriever;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
|
||||
|
||||
class CategoryControllerCore extends ProductListingFrontController
|
||||
{
|
||||
/** string Internal controller name */
|
||||
public $php_self = 'category';
|
||||
|
||||
/** @var bool If set to false, customer cannot view the current category. */
|
||||
public $customer_access = true;
|
||||
|
||||
/** @var bool */
|
||||
protected $notFound = false;
|
||||
|
||||
/**
|
||||
* @var Category
|
||||
*/
|
||||
protected $category;
|
||||
|
||||
public function canonicalRedirection($canonicalURL = '')
|
||||
{
|
||||
if (Validate::isLoadedObject($this->category)) {
|
||||
parent::canonicalRedirection($this->context->link->getCategoryLink($this->category));
|
||||
}
|
||||
}
|
||||
|
||||
public function getCanonicalURL()
|
||||
{
|
||||
if (!Validate::isLoadedObject($this->category)) {
|
||||
return '';
|
||||
}
|
||||
$canonicalUrl = $this->context->link->getCategoryLink($this->category);
|
||||
$parsedUrl = parse_url($canonicalUrl);
|
||||
if (isset($parsedUrl['query'])) {
|
||||
parse_str($parsedUrl['query'], $params);
|
||||
} else {
|
||||
$params = [];
|
||||
}
|
||||
$page = (int) Tools::getValue('page');
|
||||
if ($page > 1) {
|
||||
$params['page'] = $page;
|
||||
} else {
|
||||
unset($params['page']);
|
||||
}
|
||||
$canonicalUrl = http_build_url($parsedUrl, ['query' => http_build_query($params)]);
|
||||
|
||||
return $canonicalUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes controller.
|
||||
*
|
||||
* @see FrontController::init()
|
||||
*
|
||||
* @throws PrestaShopException
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$id_category = (int) Tools::getValue('id_category');
|
||||
$this->category = new Category(
|
||||
$id_category,
|
||||
$this->context->language->id
|
||||
);
|
||||
|
||||
parent::init();
|
||||
|
||||
if (!Validate::isLoadedObject($this->category) || !$this->category->active) {
|
||||
header('HTTP/1.1 404 Not Found');
|
||||
header('Status: 404 Not Found');
|
||||
$this->setTemplate('errors/404');
|
||||
$this->notFound = true;
|
||||
|
||||
return;
|
||||
} elseif (!$this->category->checkAccess($this->context->customer->id)) {
|
||||
header('HTTP/1.1 403 Forbidden');
|
||||
header('Status: 403 Forbidden');
|
||||
$this->errors[] = $this->trans('You do not have access to this category.', [], 'Shop.Notifications.Error');
|
||||
$this->setTemplate('errors/forbidden');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$categoryVar = $this->getTemplateVarCategory();
|
||||
|
||||
$filteredCategory = Hook::exec(
|
||||
'filterCategoryContent',
|
||||
['object' => $categoryVar],
|
||||
$id_module = null,
|
||||
$array_return = false,
|
||||
$check_exceptions = true,
|
||||
$use_push = false,
|
||||
$id_shop = null,
|
||||
$chain = true
|
||||
);
|
||||
if (!empty($filteredCategory['object'])) {
|
||||
$categoryVar = $filteredCategory['object'];
|
||||
}
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'category' => $categoryVar,
|
||||
'subcategories' => $this->getTemplateVarSubCategories(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
parent::initContent();
|
||||
|
||||
if (
|
||||
Validate::isLoadedObject($this->category)
|
||||
&& $this->category->active
|
||||
&& $this->category->checkAccess($this->context->customer->id)
|
||||
) {
|
||||
$this->doProductSearch(
|
||||
'catalog/listing/category',
|
||||
[
|
||||
'entity' => 'category',
|
||||
'id' => $this->category->id,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* overrides layout if category is not visible.
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public function getLayout()
|
||||
{
|
||||
if (!$this->category->checkAccess($this->context->customer->id) || $this->notFound) {
|
||||
return 'layouts/layout-full-width.tpl';
|
||||
}
|
||||
|
||||
return parent::getLayout();
|
||||
}
|
||||
|
||||
protected function getAjaxProductSearchVariables()
|
||||
{
|
||||
$data = parent::getAjaxProductSearchVariables();
|
||||
$rendered_products_header = $this->render('catalog/_partials/category-header', ['listing' => $data]);
|
||||
$data['rendered_products_header'] = $rendered_products_header;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getProductSearchQuery()
|
||||
{
|
||||
$query = new ProductSearchQuery();
|
||||
$query
|
||||
->setIdCategory($this->category->id)
|
||||
->setSortOrder(new SortOrder('product', Tools::getProductsOrder('by'), Tools::getProductsOrder('way')));
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function getDefaultProductSearchProvider()
|
||||
{
|
||||
return new CategoryProductSearchProvider(
|
||||
$this->getTranslator(),
|
||||
$this->category
|
||||
);
|
||||
}
|
||||
|
||||
protected function getTemplateVarCategory()
|
||||
{
|
||||
$category = $this->objectPresenter->present($this->category);
|
||||
$category['image'] = $this->getImage(
|
||||
$this->category,
|
||||
$this->category->id_image
|
||||
);
|
||||
|
||||
return $category;
|
||||
}
|
||||
|
||||
protected function getTemplateVarSubCategories()
|
||||
{
|
||||
return array_map(function (array $category) {
|
||||
$object = new Category(
|
||||
$category['id_category'],
|
||||
$this->context->language->id
|
||||
);
|
||||
|
||||
$category['image'] = $this->getImage(
|
||||
$object,
|
||||
$object->id_image
|
||||
);
|
||||
|
||||
$category['url'] = $this->context->link->getCategoryLink(
|
||||
$category['id_category'],
|
||||
$category['link_rewrite']
|
||||
);
|
||||
|
||||
return $category;
|
||||
}, $this->category->getSubCategories($this->context->language->id));
|
||||
}
|
||||
|
||||
protected function getImage($object, $id_image)
|
||||
{
|
||||
$retriever = new ImageRetriever(
|
||||
$this->context->link
|
||||
);
|
||||
|
||||
return $retriever->getImage($object, $id_image);
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
|
||||
foreach ($this->category->getAllParents() as $category) {
|
||||
if ($category->id_parent != 0 && !$category->is_root_category && $category->active) {
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $category->name,
|
||||
'url' => $this->context->link->getCategoryLink($category),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->category->id_parent != 0 && !$this->category->is_root_category && $category->active) {
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->category->name,
|
||||
'url' => $this->context->link->getCategoryLink($this->category),
|
||||
];
|
||||
}
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
||||
public function getCategory()
|
||||
{
|
||||
return $this->category;
|
||||
}
|
||||
|
||||
public function getTemplateVarPage()
|
||||
{
|
||||
$page = parent::getTemplateVarPage();
|
||||
|
||||
if ($this->notFound) {
|
||||
$page['page_name'] = 'pagenotfound';
|
||||
$page['body_classes']['pagenotfound'] = true;
|
||||
$page['title'] = $this->trans('The page you are looking for was not found.', [], 'Shop.Theme.Global');
|
||||
} else {
|
||||
$page['body_classes']['category-id-' . $this->category->id] = true;
|
||||
$page['body_classes']['category-' . $this->category->name] = true;
|
||||
$page['body_classes']['category-id-parent-' . $this->category->id_parent] = true;
|
||||
$page['body_classes']['category-depth-level-' . $this->category->level_depth] = true;
|
||||
}
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
public function getListingLabel()
|
||||
{
|
||||
if (!Validate::isLoadedObject($this->category)) {
|
||||
$this->category = new Category(
|
||||
(int) Tools::getValue('id_category'),
|
||||
$this->context->language->id
|
||||
);
|
||||
}
|
||||
|
||||
return $this->trans(
|
||||
'Category: %category_name%',
|
||||
['%category_name%' => $this->category->name],
|
||||
'Shop.Theme.Catalog'
|
||||
);
|
||||
}
|
||||
}
|
||||
217
controllers/front/listing/ManufacturerController.php
Normal file
217
controllers/front/listing/ManufacturerController.php
Normal file
@@ -0,0 +1,217 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
use PrestaShop\PrestaShop\Adapter\Manufacturer\ManufacturerProductSearchProvider;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
|
||||
|
||||
class ManufacturerControllerCore extends ProductListingFrontController
|
||||
{
|
||||
public $php_self = 'manufacturer';
|
||||
|
||||
protected $manufacturer;
|
||||
protected $label;
|
||||
|
||||
public function canonicalRedirection($canonicalURL = '')
|
||||
{
|
||||
if (Validate::isLoadedObject($this->manufacturer)) {
|
||||
parent::canonicalRedirection($this->context->link->getManufacturerLink($this->manufacturer));
|
||||
} elseif ($canonicalURL) {
|
||||
parent::canonicalRedirection($canonicalURL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize manufaturer controller.
|
||||
*
|
||||
* @see FrontController::init()
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
if ($id_manufacturer = Tools::getValue('id_manufacturer')) {
|
||||
$this->manufacturer = new Manufacturer((int) $id_manufacturer, $this->context->language->id);
|
||||
|
||||
if (!Validate::isLoadedObject($this->manufacturer) || !$this->manufacturer->active || !$this->manufacturer->isAssociatedToShop()) {
|
||||
$this->redirect_after = '404';
|
||||
$this->redirect();
|
||||
} else {
|
||||
$this->canonicalRedirection();
|
||||
}
|
||||
}
|
||||
|
||||
parent::init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign template vars related to page content.
|
||||
*
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
if (Configuration::get('PS_DISPLAY_MANUFACTURERS')) {
|
||||
parent::initContent();
|
||||
|
||||
if (Validate::isLoadedObject($this->manufacturer) && $this->manufacturer->active && $this->manufacturer->isAssociatedToShop()) {
|
||||
$this->assignManufacturer();
|
||||
$this->label = $this->trans(
|
||||
'List of products by brand %brand_name%',
|
||||
[
|
||||
'%brand_name%' => $this->manufacturer->name,
|
||||
],
|
||||
'Shop.Theme.Catalog'
|
||||
);
|
||||
$this->doProductSearch(
|
||||
'catalog/listing/manufacturer',
|
||||
['entity' => 'manufacturer', 'id' => $this->manufacturer->id]
|
||||
);
|
||||
} else {
|
||||
$this->assignAll();
|
||||
$this->label = $this->trans(
|
||||
'List of all brands',
|
||||
[],
|
||||
'Shop.Theme.Catalog'
|
||||
);
|
||||
$this->setTemplate('catalog/manufacturers', ['entity' => 'manufacturers']);
|
||||
}
|
||||
} else {
|
||||
$this->redirect_after = '404';
|
||||
$this->redirect();
|
||||
}
|
||||
}
|
||||
|
||||
protected function getProductSearchQuery()
|
||||
{
|
||||
$query = new ProductSearchQuery();
|
||||
$query
|
||||
->setIdManufacturer($this->manufacturer->id)
|
||||
->setSortOrder(new SortOrder('product', Tools::getProductsOrder('by'), Tools::getProductsOrder('way')));
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function getDefaultProductSearchProvider()
|
||||
{
|
||||
return new ManufacturerProductSearchProvider(
|
||||
$this->getTranslator(),
|
||||
$this->manufacturer
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign template vars if displaying one manufacturer.
|
||||
*/
|
||||
protected function assignManufacturer()
|
||||
{
|
||||
$manufacturerVar = $this->objectPresenter->present($this->manufacturer);
|
||||
|
||||
$filteredManufacturer = Hook::exec(
|
||||
'filterManufacturerContent',
|
||||
['filtered_content' => $manufacturerVar['description']],
|
||||
$id_module = null,
|
||||
$array_return = false,
|
||||
$check_exceptions = true,
|
||||
$use_push = false,
|
||||
$id_shop = null,
|
||||
$chain = true
|
||||
);
|
||||
if (!empty($filteredManufacturer)) {
|
||||
$manufacturerVar['description'] = $filteredManufacturer;
|
||||
}
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'manufacturer' => $manufacturerVar,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign template vars if displaying the manufacturer list.
|
||||
*/
|
||||
protected function assignAll()
|
||||
{
|
||||
$manufacturersVar = $this->getTemplateVarManufacturers();
|
||||
|
||||
if (!empty($manufacturersVar)) {
|
||||
foreach ($manufacturersVar as $k => $manufacturer) {
|
||||
$filteredManufacturer = Hook::exec(
|
||||
'filterManufacturerContent',
|
||||
['filtered_content' => $manufacturer['text']],
|
||||
$id_module = null,
|
||||
$array_return = false,
|
||||
$check_exceptions = true,
|
||||
$use_push = false,
|
||||
$id_shop = null,
|
||||
$chain = true
|
||||
);
|
||||
if (!empty($filteredManufacturer)) {
|
||||
$manufacturersVar[$k]['text'] = $filteredManufacturer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'brands' => $manufacturersVar,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getTemplateVarManufacturers()
|
||||
{
|
||||
$manufacturers = Manufacturer::getManufacturers(true, $this->context->language->id, true, $this->p, $this->n, false);
|
||||
$manufacturers_for_display = [];
|
||||
|
||||
foreach ($manufacturers as $manufacturer) {
|
||||
$manufacturers_for_display[$manufacturer['id_manufacturer']] = $manufacturer;
|
||||
$manufacturers_for_display[$manufacturer['id_manufacturer']]['text'] = $manufacturer['short_description'];
|
||||
$manufacturers_for_display[$manufacturer['id_manufacturer']]['image'] = $this->context->link->getManufacturerImageLink($manufacturer['id_manufacturer'], 'small_default');
|
||||
$manufacturers_for_display[$manufacturer['id_manufacturer']]['url'] = $this->context->link->getmanufacturerLink($manufacturer['id_manufacturer']);
|
||||
$manufacturers_for_display[$manufacturer['id_manufacturer']]['nb_products'] = $manufacturer['nb_products'] > 1 ? ($this->trans('%number% products', ['%number%' => $manufacturer['nb_products']], 'Shop.Theme.Catalog')) : $this->trans('%number% product', ['%number%' => $manufacturer['nb_products']], 'Shop.Theme.Catalog');
|
||||
}
|
||||
|
||||
return $manufacturers_for_display;
|
||||
}
|
||||
|
||||
public function getListingLabel()
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->getTranslator()->trans('Brands', [], 'Shop.Theme.Global'),
|
||||
'url' => $this->context->link->getPageLink('manufacturer', true),
|
||||
];
|
||||
|
||||
if (Validate::isLoadedObject($this->manufacturer) && $this->manufacturer->active && $this->manufacturer->isAssociatedToShop()) {
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->manufacturer->name,
|
||||
'url' => $this->context->link->getManufacturerLink($this->manufacturer),
|
||||
];
|
||||
}
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
}
|
||||
81
controllers/front/listing/NewProductsController.php
Normal file
81
controllers/front/listing/NewProductsController.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
use PrestaShop\PrestaShop\Adapter\NewProducts\NewProductsProductSearchProvider;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
|
||||
|
||||
class NewProductsControllerCore extends ProductListingFrontController
|
||||
{
|
||||
public $php_self = 'new-products';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
parent::initContent();
|
||||
|
||||
$this->doProductSearch('catalog/listing/new-products', ['entity' => 'new-products']);
|
||||
}
|
||||
|
||||
protected function getProductSearchQuery()
|
||||
{
|
||||
$query = new ProductSearchQuery();
|
||||
$query
|
||||
->setQueryType('new-products')
|
||||
->setSortOrder(new SortOrder('product', 'date_add', 'desc'));
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function getDefaultProductSearchProvider()
|
||||
{
|
||||
return new NewProductsProductSearchProvider(
|
||||
$this->getTranslator()
|
||||
);
|
||||
}
|
||||
|
||||
public function getListingLabel()
|
||||
{
|
||||
return $this->trans(
|
||||
'New products',
|
||||
[],
|
||||
'Shop.Theme.Catalog'
|
||||
);
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->trans('New products', [], 'Shop.Theme.Catalog'),
|
||||
'url' => $this->context->link->getPageLink('new-products', true),
|
||||
];
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
}
|
||||
81
controllers/front/listing/PricesDropController.php
Normal file
81
controllers/front/listing/PricesDropController.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
use PrestaShop\PrestaShop\Adapter\PricesDrop\PricesDropProductSearchProvider;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
|
||||
|
||||
class PricesDropControllerCore extends ProductListingFrontController
|
||||
{
|
||||
public $php_self = 'prices-drop';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
parent::initContent();
|
||||
|
||||
$this->doProductSearch('catalog/listing/prices-drop', ['entity' => 'prices-drop']);
|
||||
}
|
||||
|
||||
protected function getProductSearchQuery()
|
||||
{
|
||||
$query = new ProductSearchQuery();
|
||||
$query
|
||||
->setQueryType('prices-drop')
|
||||
->setSortOrder(new SortOrder('product', 'name', 'asc'));
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function getDefaultProductSearchProvider()
|
||||
{
|
||||
return new PricesDropProductSearchProvider(
|
||||
$this->getTranslator()
|
||||
);
|
||||
}
|
||||
|
||||
public function getListingLabel()
|
||||
{
|
||||
return $this->trans(
|
||||
'Prices drop',
|
||||
[],
|
||||
'Shop.Theme.Catalog'
|
||||
);
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->trans('Prices drop', [], 'Shop.Theme.Catalog'),
|
||||
'url' => $this->context->link->getPageLink('prices-drop', true),
|
||||
];
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
}
|
||||
119
controllers/front/listing/SearchController.php
Normal file
119
controllers/front/listing/SearchController.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
use PrestaShop\PrestaShop\Adapter\Search\SearchProductSearchProvider;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
|
||||
|
||||
class SearchControllerCore extends ProductListingFrontController
|
||||
{
|
||||
public $php_self = 'search';
|
||||
public $instant_search;
|
||||
public $ajax_search;
|
||||
|
||||
protected $search_string;
|
||||
protected $search_tag;
|
||||
|
||||
/**
|
||||
* Assign template vars related to page content.
|
||||
*
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
$this->search_string = Tools::getValue('s');
|
||||
if (!$this->search_string) {
|
||||
$this->search_string = Tools::getValue('search_query');
|
||||
}
|
||||
|
||||
$this->search_tag = Tools::getValue('tag');
|
||||
|
||||
$this->context->smarty->assign(
|
||||
[
|
||||
'search_string' => $this->search_string,
|
||||
'search_tag' => $this->search_tag,
|
||||
'subcategories' => [],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that no search results page is indexed by search engines.
|
||||
*/
|
||||
public function getTemplateVarPage()
|
||||
{
|
||||
$page = parent::getTemplateVarPage();
|
||||
|
||||
$page['meta']['robots'] = 'noindex';
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the search.
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
parent::initContent();
|
||||
|
||||
$this->doProductSearch('catalog/listing/search', ['entity' => 'search']);
|
||||
}
|
||||
|
||||
protected function getProductSearchQuery()
|
||||
{
|
||||
$query = new ProductSearchQuery();
|
||||
$query
|
||||
->setSortOrder(new SortOrder('product', 'position', 'desc'))
|
||||
->setSearchString($this->search_string)
|
||||
->setSearchTag($this->search_tag);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function getDefaultProductSearchProvider()
|
||||
{
|
||||
return new SearchProductSearchProvider(
|
||||
$this->getTranslator()
|
||||
);
|
||||
}
|
||||
|
||||
public function getListingLabel()
|
||||
{
|
||||
return $this->getTranslator()->trans('Search results', [], 'Shop.Theme.Catalog');
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->getTranslator()->trans('Search results', [], 'Shop.Theme.Catalog'),
|
||||
'url' => $this->getCurrentUrl(),
|
||||
];
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
}
|
||||
221
controllers/front/listing/SupplierController.php
Normal file
221
controllers/front/listing/SupplierController.php
Normal file
@@ -0,0 +1,221 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
use PrestaShop\PrestaShop\Adapter\Supplier\SupplierProductSearchProvider;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
|
||||
|
||||
class SupplierControllerCore extends ProductListingFrontController
|
||||
{
|
||||
public $php_self = 'supplier';
|
||||
|
||||
/** @var Supplier */
|
||||
protected $supplier;
|
||||
protected $label;
|
||||
|
||||
public function canonicalRedirection($canonicalURL = '')
|
||||
{
|
||||
if (Validate::isLoadedObject($this->supplier)) {
|
||||
parent::canonicalRedirection($this->context->link->getSupplierLink($this->supplier));
|
||||
} elseif ($canonicalURL) {
|
||||
parent::canonicalRedirection($canonicalURL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize supplier controller.
|
||||
*
|
||||
* @see FrontController::init()
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
if ($id_supplier = (int) Tools::getValue('id_supplier')) {
|
||||
$this->supplier = new Supplier($id_supplier, $this->context->language->id);
|
||||
|
||||
if (!Validate::isLoadedObject($this->supplier) || !$this->supplier->active) {
|
||||
$this->redirect_after = '404';
|
||||
$this->redirect();
|
||||
} else {
|
||||
$this->canonicalRedirection();
|
||||
}
|
||||
}
|
||||
|
||||
parent::init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign template vars related to page content.
|
||||
*
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
if (Configuration::get('PS_DISPLAY_SUPPLIERS')) {
|
||||
parent::initContent();
|
||||
|
||||
if (Validate::isLoadedObject($this->supplier) && $this->supplier->active && $this->supplier->isAssociatedToShop()) {
|
||||
$this->assignSupplier();
|
||||
$this->label = $this->trans(
|
||||
'List of products by supplier %supplier_name%',
|
||||
[
|
||||
'%supplier_name%' => $this->supplier->name,
|
||||
],
|
||||
'Shop.Theme.Catalog'
|
||||
);
|
||||
$this->doProductSearch(
|
||||
'catalog/listing/supplier',
|
||||
['entity' => 'supplier', 'id' => $this->supplier->id]
|
||||
);
|
||||
} else {
|
||||
$this->assignAll();
|
||||
$this->label = $this->trans(
|
||||
'List of all suppliers',
|
||||
[],
|
||||
'Shop.Theme.Catalog'
|
||||
);
|
||||
$this->setTemplate('catalog/suppliers', ['entity' => 'suppliers']);
|
||||
}
|
||||
} else {
|
||||
$this->redirect_after = '404';
|
||||
$this->redirect();
|
||||
}
|
||||
}
|
||||
|
||||
protected function getProductSearchQuery()
|
||||
{
|
||||
$query = new ProductSearchQuery();
|
||||
$query
|
||||
->setIdSupplier($this->supplier->id)
|
||||
->setSortOrder(new SortOrder('product', 'position', 'asc'));
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function getDefaultProductSearchProvider()
|
||||
{
|
||||
return new SupplierProductSearchProvider(
|
||||
$this->getTranslator(),
|
||||
$this->supplier
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign template vars if displaying one supplier.
|
||||
*/
|
||||
protected function assignSupplier()
|
||||
{
|
||||
$supplierVar = $this->objectPresenter->present($this->supplier);
|
||||
|
||||
$filteredSupplier = Hook::exec(
|
||||
'filterSupplierContent',
|
||||
['object' => $supplierVar],
|
||||
$id_module = null,
|
||||
$array_return = false,
|
||||
$check_exceptions = true,
|
||||
$use_push = false,
|
||||
$id_shop = null,
|
||||
$chain = true
|
||||
);
|
||||
if (!empty($filteredSupplier['object'])) {
|
||||
$supplierVar = $filteredSupplier['object'];
|
||||
}
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'supplier' => $supplierVar,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign template vars if displaying the supplier list.
|
||||
*/
|
||||
protected function assignAll()
|
||||
{
|
||||
$suppliersVar = $this->getTemplateVarSuppliers();
|
||||
|
||||
if (!empty($suppliersVar)) {
|
||||
foreach ($suppliersVar as $k => $supplier) {
|
||||
$filteredSupplier = Hook::exec(
|
||||
'filterSupplierContent',
|
||||
['object' => $supplier],
|
||||
$id_module = null,
|
||||
$array_return = false,
|
||||
$check_exceptions = true,
|
||||
$use_push = false,
|
||||
$id_shop = null,
|
||||
$chain = true
|
||||
);
|
||||
if (!empty($filteredSupplier['object'])) {
|
||||
$suppliersVar[$k] = $filteredSupplier['object'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'brands' => $suppliersVar,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getTemplateVarSuppliers()
|
||||
{
|
||||
$suppliers = Supplier::getSuppliers(true, $this->context->language->id, true);
|
||||
$suppliers_for_display = [];
|
||||
|
||||
foreach ($suppliers as $supplier) {
|
||||
$suppliers_for_display[$supplier['id_supplier']] = $supplier;
|
||||
$suppliers_for_display[$supplier['id_supplier']]['text'] = $supplier['description'];
|
||||
$suppliers_for_display[$supplier['id_supplier']]['image'] = $this->context->link->getSupplierImageLink($supplier['id_supplier'], 'small_default');
|
||||
$suppliers_for_display[$supplier['id_supplier']]['url'] = $this->context->link->getsupplierLink($supplier['id_supplier']);
|
||||
$suppliers_for_display[$supplier['id_supplier']]['nb_products'] = $supplier['nb_products'] > 1
|
||||
? $this->trans('%number% products', ['%number%' => $supplier['nb_products']], 'Shop.Theme.Catalog')
|
||||
: $this->trans('%number% product', ['%number%' => $supplier['nb_products']], 'Shop.Theme.Catalog');
|
||||
}
|
||||
|
||||
return $suppliers_for_display;
|
||||
}
|
||||
|
||||
public function getListingLabel()
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->trans('All suppliers', [], 'Shop.Theme.Catalog'),
|
||||
'url' => $this->context->link->getPageLink('supplier', true),
|
||||
];
|
||||
|
||||
if (Validate::isLoadedObject($this->supplier) && $this->supplier->active && $this->supplier->isAssociatedToShop()) {
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->supplier->name,
|
||||
'url' => $this->context->link->getSupplierLink($this->supplier),
|
||||
];
|
||||
}
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
}
|
||||
34
controllers/front/listing/index.php
Normal file
34
controllers/front/listing/index.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
Reference in New Issue
Block a user