Initial commit

This commit is contained in:
2020-10-07 10:37:15 +02:00
commit ce5f440392
28157 changed files with 4429172 additions and 0 deletions

View File

@@ -0,0 +1,81 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* 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.txt.
* 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://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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('index.php?controller=404');
}
}
/**
* {@inheritdoc}
*/
public function initContent()
{
parent::initContent();
$this->doProductSearch('catalog/listing/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', array(), 'Shop.Theme.Catalog');
}
}

View File

@@ -0,0 +1,273 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* 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.txt.
* 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://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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 Category
*/
protected $category;
public function canonicalRedirection($canonicalURL = '')
{
if (Validate::isLoadedObject($this->category)) {
parent::canonicalRedirection($this->context->link->getCategoryLink($this->category));
} elseif ($canonicalURL) {
parent::canonicalRedirection($canonicalURL);
}
}
public function getCanonicalURL()
{
$canonicalUrl = $this->context->link->getCategoryLink($this->category);
$parsedUrl = parse_url($canonicalUrl);
if (isset($parsedUrl['query'])) {
parse_str($parsedUrl['query'], $params);
} else {
$params = array();
}
$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
);
if (!Validate::isLoadedObject($this->category) || !$this->category->active) {
Tools::redirect('index.php?controller=404');
}
parent::init();
if (!$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.', array(), 'Shop.Notifications.Error');
$this->setTemplate('errors/forbidden');
return;
}
$categoryVar = $this->getTemplateVarCategory();
$filteredCategory = Hook::exec(
'filterCategoryContent',
array('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(array(
'category' => $categoryVar,
'subcategories' => $this->getTemplateVarSubCategories(),
));
}
/**
* {@inheritdoc}
*/
public function initContent()
{
parent::initContent();
if ($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)) {
return 'layouts/layout-full-width.tpl';
}
return parent::getLayout();
}
protected function getAjaxProductSearchVariables()
{
$data = parent::getAjaxProductSearchVariables();
$rendered_products_header = $this->render('catalog/_partials/category-header', array('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) {
$breadcrumb['links'][] = $this->getCategoryPath($category);
}
}
$breadcrumb['links'][] = $this->getCategoryPath($this->category);
return $breadcrumb;
}
public function getCategory()
{
return $this->category;
}
public function getTemplateVarPage()
{
$page = parent::getTemplateVarPage();
$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%',
array('%category_name%' => $this->category->name),
'Shop.Theme.Catalog'
);
}
}

View File

@@ -0,0 +1,217 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* 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.txt.
* 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://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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_SUPPLIERS')) {
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%',
array(
'%brand_name%' => $this->manufacturer->name,
),
'Shop.Theme.Catalog'
);
$this->doProductSearch(
'catalog/listing/manufacturer',
array('entity' => 'manufacturer', 'id' => $this->manufacturer->id)
);
} else {
$this->assignAll();
$this->label = $this->trans(
'List of all brands',
array(),
'Shop.Theme.Catalog'
);
$this->setTemplate('catalog/manufacturers', array('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',
array('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(array(
'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',
array('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(array(
'brands' => $manufacturersVar,
));
}
public function getTemplateVarManufacturers()
{
$manufacturers = Manufacturer::getManufacturers(true, $this->context->language->id, true, $this->p, $this->n, false);
$manufacturers_for_display = array();
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', array('%number%' => $manufacturer['nb_products']), 'Shop.Theme.Catalog')) : $this->trans('%number% product', array('%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;
}
}

View File

@@ -0,0 +1,69 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* 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.txt.
* 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://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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');
}
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',
array(),
'Shop.Theme.Catalog'
);
}
}

View File

@@ -0,0 +1,69 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* 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.txt.
* 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://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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');
}
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(
'On sale',
array(),
'Shop.Theme.Catalog'
);
}
}

View File

@@ -0,0 +1,118 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* 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.txt.
* 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://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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(
array(
'search_string' => $this->search_string,
'search_tag' => $this->search_tag,
)
);
}
/**
* 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', array('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', array(), 'Shop.Theme.Catalog');
}
public function getBreadcrumbLinks()
{
$breadcrumb = parent::getBreadcrumbLinks();
$breadcrumb['links'][] = array(
'title' => $this->getTranslator()->trans('Search results', array(), 'Shop.Theme.Catalog'),
'url' => $this->getCurrentUrl(),
);
return $breadcrumb;
}
}

View File

@@ -0,0 +1,202 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* 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.txt.
* 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://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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%',
array(
'%supplier_name%' => $this->supplier->name,
),
'Shop.Theme.Catalog'
);
$this->doProductSearch(
'catalog/listing/supplier',
array('entity' => 'supplier', 'id' => $this->supplier->id)
);
} else {
$this->assignAll();
$this->label = $this->trans(
'List of all suppliers',
array(),
'Shop.Theme.Catalog'
);
$this->setTemplate('catalog/suppliers', array('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',
array('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(array(
'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',
array('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(array(
'brands' => $suppliersVar,
));
}
public function getTemplateVarSuppliers()
{
$suppliers = Supplier::getSuppliers(true, $this->context->language->id, true);
$suppliers_for_display = array();
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', array('%number%' => $supplier['nb_products']), 'Shop.Theme.Catalog')
: $this->trans('%number% product', array('%number%' => $supplier['nb_products']), 'Shop.Theme.Catalog');
}
return $suppliers_for_display;
}
public function getListingLabel()
{
return $this->label;
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* 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.txt.
* 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://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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;