Skip to content

Commit

Permalink
Merge pull request #1031 from PrestaShop/dev
Browse files Browse the repository at this point in the history
Release 3.16.0
  • Loading branch information
Hlavtox authored May 31, 2024
2 parents 5e06b7e + df0af59 commit c2652b3
Show file tree
Hide file tree
Showing 9 changed files with 904 additions and 955 deletions.
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>ps_facetedsearch</name>
<displayName><![CDATA[Faceted search]]></displayName>
<version><![CDATA[3.15.1]]></version>
<version><![CDATA[3.16.0]]></version>
<description><![CDATA[Displays a block allowing multiple filters.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[front_office_features]]></tab>
Expand Down
1,715 changes: 846 additions & 869 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,24 @@
},
"homepage": "https://github.com/PrestaShop/ps_facetedsearch#readme",
"devDependencies": {
"@babel/eslint-parser": "^7.23.10",
"@babel/cli": "^7.23.9",
"@babel/eslint-parser": "^7.24.5",
"@babel/cli": "^7.24.5",
"@babel/core": "^7.23.9",
"@babel/node": "^7.23.9",
"@babel/preset-env": "^7.23.9",
"@babel/preset-env": "^7.24.5",
"@babel/register": "^7.23.7",
"babel-loader": "^9.1.3",
"chai": "^4.3.10",
"clean-webpack-plugin": "^4.0.0",
"css-loader": "^6.10.0",
"css-loader": "^7.1.2",
"eslint": "^8.57.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prestashop": "^0.2.1",
"eslint-plugin-import": "^2.29.1",
"mini-css-extract-plugin": "^1.0.0",
"mocha": "^10.2.0",
"mocha": "^10.4.0",
"node-sass": "^9.0.0",
"sass-loader": "^14.1.1",
"sass-loader": "^14.2.1",
"style-loader": "^2.0.0",
"webpack": "^5.90.3",
"webpack-cli": "^4.10.0"
Expand Down
2 changes: 1 addition & 1 deletion ps_facetedsearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function __construct()
{
$this->name = 'ps_facetedsearch';
$this->tab = 'front_office_features';
$this->version = '3.15.1';
$this->version = '3.16.0';
$this->author = 'PrestaShop';
$this->need_instance = 0;
$this->bootstrap = true;
Expand Down
15 changes: 0 additions & 15 deletions src/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ abstract class AbstractAdapter implements InterfaceAdapter

protected $orderDirection = 'DESC';

protected $limit = 20;

protected $offset = 0;

/** @var InterfaceAdapter */
protected $initialPopulation = null;

Expand Down Expand Up @@ -314,15 +310,4 @@ public function setOrderDirection($direction)

return $this;
}

/**
* {@inheritdoc}
*/
public function setLimit($limit, $offset = 0)
{
$this->limit = $limit ? (int) $limit : null;
$this->offset = (int) $offset;

return $this;
}
}
10 changes: 0 additions & 10 deletions src/Adapter/InterfaceAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@ public function setOrderField($fieldName);
*/
public function setOrderDirection($direction);

/**
* Set the limit and offset associated with the current search
*
* @param int|null $limit
* @param int $offset
*
* @return self
*/
public function setLimit($limit, $offset = 0);

/**
* Execute the search
*
Expand Down
11 changes: 1 addition & 10 deletions src/Adapter/MySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public function getMinMaxPriceValue()
$mysqlAdapter = $this->getFilteredSearchAdapter();
$mysqlAdapter->copyFilters($this);
$mysqlAdapter->setSelectFields(['price_min', 'MIN(price_min) as min, MAX(price_max) as max']);
$mysqlAdapter->setLimit(null);
$mysqlAdapter->setOrderField('');

$result = $mysqlAdapter->execute();
Expand Down Expand Up @@ -136,10 +135,6 @@ public function getQuery()
}
}

if ($this->limit !== null) {
$query .= ' LIMIT ' . $this->offset . ', ' . $this->limit;
}

return $query;
}

Expand Down Expand Up @@ -588,7 +583,6 @@ protected function computeWhereConditions(array $filterToTableMapping)
$idTmpFilteredProducts = [];
$mysqlAdapter = $this->getFilteredSearchAdapter();
$mysqlAdapter->addSelectField('id_product');
$mysqlAdapter->setLimit(null);
$mysqlAdapter->setOrderField('');
$mysqlAdapter->addFilter($filterName, $filterValues, $operator);
$idProducts = $mysqlAdapter->execute();
Expand Down Expand Up @@ -745,7 +739,6 @@ public function getMinMaxValue($fieldName)
$mysqlAdapter = $this->getFilteredSearchAdapter();
$mysqlAdapter->copyFilters($this);
$mysqlAdapter->setSelectFields(['MIN(' . $fieldName . ') as min, MAX(' . $fieldName . ') as max']);
$mysqlAdapter->setLimit(null);
$mysqlAdapter->setOrderField('');

$result = $mysqlAdapter->execute();
Expand Down Expand Up @@ -778,7 +771,6 @@ public function valueCount($fieldName = null)
}

$this->addSelectField('COUNT(DISTINCT p.id_product) c');
$this->setLimit(null);
$this->setOrderField('');

$this->copyOperationsFilters();
Expand All @@ -791,8 +783,7 @@ public function valueCount($fieldName = null)
*/
public function useFiltersAsInitialPopulation()
{
// Initial population has NO LIMIT and no ORDER BY
$this->setLimit(null);
// Initial population has no ORDER BY
$this->setOrderField('');

// We add basic select fields we will need to matter what
Expand Down
32 changes: 19 additions & 13 deletions src/Filters/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,13 @@ public function getProductByFilters(
ProductSearchQuery $query,
array $selectedFilters = []
) {
// Get pagination
$productsPerPage = (int) $query->getResultsPerPage();
$page = (int) $query->getPage();

// Load sorting type and direction, validate it and apply fallback if needed
$orderBy = $query->getSortOrder()->toLegacyOrderBy(false);
$orderWay = $query->getSortOrder()->toLegacyOrderWay();
$orderWay = Validate::isOrderWay($orderWay) ? $orderWay : 'ASC';
$orderBy = Validate::isOrderBy($orderBy) ? $orderBy : 'position';

$this->searchAdapter->setLimit($productsPerPage, ($page - 1) * $productsPerPage);
// Apply it to the filter
$this->searchAdapter->setOrderField($orderBy);
$this->searchAdapter->setOrderDirection($orderWay);

Expand All @@ -87,19 +83,29 @@ public function getProductByFilters(
$this->searchAdapter->addSelectField('price_max');
}

$matchingProductList = $this->searchAdapter->execute();
// Get full list of matching products
$fullProductList = $this->searchAdapter->execute();

$this->pricePostFiltering($matchingProductList, $selectedFilters);
// Count them
$totalProductCount = count($fullProductList);

$nbrProducts = $this->searchAdapter->count();
// Get pagination
$productsPerPage = (int) $query->getResultsPerPage();
$page = (int) $query->getPage();

if (empty($nbrProducts)) {
$matchingProductList = [];
}
// Cut them down by pagination
$finalProductList = array_slice(
$fullProductList,
($page - 1) * $productsPerPage,
$productsPerPage
);

// And run post filter
$this->pricePostFiltering($finalProductList, $selectedFilters);

return [
'products' => $matchingProductList,
'count' => $nbrProducts,
'products' => $finalProductList,
'count' => $totalProductCount,
];
}

Expand Down
Loading

0 comments on commit c2652b3

Please sign in to comment.