Skip to content

Commit

Permalink
Merge pull request #148 from PrestaShop/dev
Browse files Browse the repository at this point in the history
Release 3.4.0
  • Loading branch information
PierreRambaud committed Oct 16, 2019
2 parents f4ada75 + 6e5c5ab commit 20ddf72
Show file tree
Hide file tree
Showing 24 changed files with 732 additions and 48 deletions.
12 changes: 6 additions & 6 deletions .travis.yml
Expand Up @@ -27,14 +27,14 @@ jobs:
- docker exec -ti temp-ps rm -rf /var/www/html/modules/ps_facetedsearch
- docker run --rm --volumes-from temp-ps -v $PWD:/var/www/html/modules/ps_facetedsearch -e _PS_ROOT_DIR_=/var/www/html quetzacoalt/phpstan analyse --configuration=/var/www/html/modules/ps_facetedsearch/tests/php/phpstan/phpstan.neon
- stage: "PHP"
name: "PHPStan on PS 1.7.5.2"
name: "PHPStan on PS 1.7.5.1"
language: php
php: 7.2
script:
- composer install
- docker run -tid --rm -v ps-volume:/var/www/html --name temp-ps prestashop/prestashop:1.7.5.1
- docker exec -ti temp-ps rm -rf /var/www/html/modules/ps_facetedsearch
- docker run --rm --volumes-from temp-ps -v $PWD:/var/www/html/modules/ps_facetedsearch -e _PS_ROOT_DIR_=/var/www/html quetzacoalt/phpstan analyse --configuration=/var/www/html/modules/ps_facetedsearch/tests/php/phpstan/phpstan.neon
- docker run --rm --volumes-from temp-ps -v $PWD:/var/www/html/modules/ps_facetedsearch -e _PS_ROOT_DIR_=/var/www/html quetzacoalt/phpstan analyse --configuration=/var/www/html/modules/ps_facetedsearch/tests/php/phpstan/phpstan-1.7.5.1.neon
- stage: "PHP"
name: "PHPStan on PS 1.7.4.4"
language: php
Expand All @@ -43,7 +43,7 @@ jobs:
- composer install
- docker run -tid --rm -v ps-volume:/var/www/html --name temp-ps prestashop/prestashop:1.7.4.4
- docker exec -ti temp-ps rm -rf /var/www/html/modules/ps_facetedsearch
- docker run --rm --volumes-from temp-ps -v $PWD:/var/www/html/modules/ps_facetedsearch -e _PS_ROOT_DIR_=/var/www/html quetzacoalt/phpstan analyse --configuration=/var/www/html/modules/ps_facetedsearch/tests/php/phpstan/phpstan.neon
- docker run --rm --volumes-from temp-ps -v $PWD:/var/www/html/modules/ps_facetedsearch -e _PS_ROOT_DIR_=/var/www/html quetzacoalt/phpstan analyse --configuration=/var/www/html/modules/ps_facetedsearch/tests/php/phpstan/phpstan-1.7.4.4.neon
- stage: "PHP"
name: "PHPStan on PS 1.7.3.4"
language: php
Expand All @@ -52,7 +52,7 @@ jobs:
- composer install
- docker run -tid --rm -v ps-volume:/var/www/html --name temp-ps prestashop/prestashop:1.7.3.4
- docker exec -ti temp-ps rm -rf /var/www/html/modules/ps_facetedsearch
- docker run --rm --volumes-from temp-ps -v $PWD:/var/www/html/modules/ps_facetedsearch -e _PS_ROOT_DIR_=/var/www/html quetzacoalt/phpstan analyse --configuration=/var/www/html/modules/ps_facetedsearch/tests/php/phpstan/phpstan.neon
- docker run --rm --volumes-from temp-ps -v $PWD:/var/www/html/modules/ps_facetedsearch -e _PS_ROOT_DIR_=/var/www/html quetzacoalt/phpstan analyse --configuration=/var/www/html/modules/ps_facetedsearch/tests/php/phpstan/phpstan-1.7.3.4.neon
- stage: "PHP"
name: "PHPStan on PS 1.7.2.5"
language: php
Expand All @@ -61,7 +61,7 @@ jobs:
- composer install
- docker run -tid --rm -v ps-volume:/var/www/html --name temp-ps prestashop/prestashop:1.7.2.5
- docker exec -ti temp-ps rm -rf /var/www/html/modules/ps_facetedsearch
- docker run --rm --volumes-from temp-ps -v $PWD:/var/www/html/modules/ps_facetedsearch -e _PS_ROOT_DIR_=/var/www/html quetzacoalt/phpstan analyse --configuration=/var/www/html/modules/ps_facetedsearch/tests/php/phpstan/phpstan.neon
- docker run --rm --volumes-from temp-ps -v $PWD:/var/www/html/modules/ps_facetedsearch -e _PS_ROOT_DIR_=/var/www/html quetzacoalt/phpstan analyse --configuration=/var/www/html/modules/ps_facetedsearch/tests/php/phpstan/phpstan-1.7.2.5.neon
- stage: "PHP"
name: "PHPStan on PS 1.7.1.2"
language: php
Expand All @@ -70,7 +70,7 @@ jobs:
- composer install
- docker run -tid --rm -v ps-volume:/var/www/html --name temp-ps prestashop/prestashop:1.7.1.2
- docker exec -ti temp-ps rm -rf /var/www/html/modules/ps_facetedsearch
- docker run --rm --volumes-from temp-ps -v $PWD:/var/www/html/modules/ps_facetedsearch -e _PS_ROOT_DIR_=/var/www/html quetzacoalt/phpstan analyse --configuration=/var/www/html/modules/ps_facetedsearch/tests/php/phpstan/phpstan.neon
- docker run --rm --volumes-from temp-ps -v $PWD:/var/www/html/modules/ps_facetedsearch -e _PS_ROOT_DIR_=/var/www/html quetzacoalt/phpstan analyse --configuration=/var/www/html/modules/ps_facetedsearch/tests/php/phpstan/phpstan-1.7.1.2.neon

script:
- npm run lint
Expand Down
4 changes: 2 additions & 2 deletions config.xml
Expand Up @@ -2,11 +2,11 @@
<module>
<name>ps_facetedsearch</name>
<displayName><![CDATA[Faceted search]]></displayName>
<version><![CDATA[3.3.0]]></version>
<version><![CDATA[3.4.0]]></version>
<description><![CDATA[Displays a block allowing multiple filters.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[front_office_features]]></tab>
<is_configurable>1</is_configurable>
<need_instance>0</need_instance>
<limited_countries></limited_countries>
<limited_countries></limited_countries>
</module>
34 changes: 34 additions & 0 deletions config/index.php
@@ -0,0 +1,34 @@
<?php
/**
* 2007-2019 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-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/AFL-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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-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;
10 changes: 10 additions & 0 deletions config/services.yml
@@ -0,0 +1,10 @@
services:
_defaults:
public: true

prestashop.module.ps_facetedsearch.constraint.url_segment_validator:
class: PrestaShop\Module\FacetedSearch\Constraint\UrlSegmentValidator
arguments:
- '@prestashop.adapter.tools'
tags:
- { name: validator.constraint_validator }
4 changes: 2 additions & 2 deletions ps_facetedsearch.php
Expand Up @@ -97,7 +97,7 @@ public function __construct()
{
$this->name = 'ps_facetedsearch';
$this->tab = 'front_office_features';
$this->version = '3.3.0';
$this->version = '3.4.0';
$this->author = 'PrestaShop';
$this->need_instance = 0;
$this->bootstrap = true;
Expand Down Expand Up @@ -1227,7 +1227,7 @@ public function __call($methodName, array $arguments)
*/
public function invalidateLayeredFilterBlockCache()
{
$this->getDatabase()->execute('TRUNCATE TABLE ' . _DB_PREFIX_ . 'layered_filter_block');
return $this->getDatabase()->execute('TRUNCATE TABLE ' . _DB_PREFIX_ . 'layered_filter_block');
}

/**
Expand Down
42 changes: 42 additions & 0 deletions src/Constraint/UrlSegment.php
@@ -0,0 +1,42 @@
<?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
*/

namespace PrestaShop\Module\FacetedSearch\Constraint;

use Symfony\Component\Validator\Constraint;

class UrlSegment extends Constraint
{
public $message = '%s is invalid.';

/**
* {@inheritdoc}
*/
public function validatedBy()
{
return UrlSegmentValidator::class;
}
}
73 changes: 73 additions & 0 deletions src/Constraint/UrlSegmentValidator.php
@@ -0,0 +1,73 @@
<?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
*/

namespace PrestaShop\Module\FacetedSearch\Constraint;

use PrestaShop\PrestaShop\Adapter\Tools;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;

/**
* Class UrlSegmentValidator responsible for validating an URL segment.
*/
class UrlSegmentValidator extends ConstraintValidator
{
/**
* @var Tools
*/
private $tools;

/**
* @param Tools $tools
*/
public function __construct(Tools $tools)
{
$this->tools = $tools;
}

/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof UrlSegment) {
throw new UnexpectedTypeException($constraint, UrlSegment::class);
}

if (null === $value || '' === $value) {
return;
}

if (strtolower($value) !== $this->tools->linkRewrite($value)) {
$this->context->buildViolation($constraint->message)
->setTranslationDomain('Admin.Notifications.Error')
->setParameter('%s', $this->formatValue($value))
->addViolation()
;
}
}
}
2 changes: 1 addition & 1 deletion src/Filters/Block.php
Expand Up @@ -678,7 +678,7 @@ private function getAttributesGroups($idLang)
if (!isset($this->attributesGroup[$idLang])) {
$this->attributesGroup[$idLang] = [];
$tempAttributesGroup = $this->database->executeS(
'SELECT ag.id_attribute_group, agl.name as attribute_group_name, is_color_group ' .
'SELECT ag.id_attribute_group, agl.public_name as attribute_group_name, is_color_group ' .
'FROM `' . _DB_PREFIX_ . 'attribute_group` ag ' .
Shop::addSqlAssociation('attribute_group', 'ag') . ' ' .
'LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group_lang` agl ' .
Expand Down
4 changes: 2 additions & 2 deletions src/Filters/Converter.php
Expand Up @@ -323,9 +323,9 @@ public function createFacetedSearchFiltersFromQuery(ProductSearchQuery $query)
$attributesGroup = AttributeGroup::getAttributesGroups($idLang);
foreach ($attributesGroup as $attributeGroup) {
if ($filter['id_value'] == $attributeGroup['id_attribute_group']
&& isset($facetAndFiltersLabels[$attributeGroup['name']])
&& isset($facetAndFiltersLabels[$attributeGroup['public_name']])
) {
$attributeLabels = $facetAndFiltersLabels[$attributeGroup['name']];
$attributeLabels = $facetAndFiltersLabels[$attributeGroup['public_name']];
$attributes = AttributeGroup::getAttributes($idLang, $attributeGroup['id_attribute_group']);
foreach ($attributes as $attribute) {
if (in_array($attribute['name'], $attributeLabels)) {
Expand Down
94 changes: 94 additions & 0 deletions src/Form/Feature/FormDataProvider.php
@@ -0,0 +1,94 @@
<?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
*/

namespace PrestaShop\Module\FacetedSearch\Form\Feature;

use Db;
use PrestaShopDatabaseException;

/**
* Provides form data
*/
class FormDataProvider
{
/**
* @var Db
*/
private $database;

public function __construct(Db $database)
{
$this->database = $database;
}

/**
* Fills form data
*
* @param array $params
*
* @return array
*
* @throws PrestaShopDatabaseException
*/
public function getData(array $params)
{
$defaultUrl = [];
$defaultMetaTitle = [];
$isIndexable = true;

// if params contains id, gets data for edit form
if (!empty($params['id'])) {
$featureId = (int) $params['id'];

// returns false if request failed.
$queryIndexable = $this->database->getValue(
'SELECT `indexable` ' .
'FROM ' . _DB_PREFIX_ . 'layered_indexable_feature ' .
'WHERE `id_feature` = ' . $featureId
);

$isIndexable = (bool) $queryIndexable;
$result = $this->database->executeS(
'SELECT `url_name`, `meta_title`, `id_lang` ' .
'FROM ' . _DB_PREFIX_ . 'layered_indexable_feature_lang_value ' .
'WHERE `id_feature` = ' . $featureId
);

if (!empty($result) && is_array($result)) {
foreach ($result as $data) {
$defaultUrl[$data['id_lang']] = $data['url_name'];
$defaultMetaTitle[$data['id_lang']] = $data['meta_title'];
}
}
}

return [
'url' => $defaultUrl,
'meta_title' => $defaultMetaTitle,
'is_indexable' => $isIndexable,
];
}
}

0 comments on commit 20ddf72

Please sign in to comment.