-
Notifications
You must be signed in to change notification settings - Fork 0
7455/price slider #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
avstudnitz
wants to merge
18
commits into
develop
Choose a base branch
from
7455/price-slider
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
e4f0ce4
7455 add jquery-ui slider component as a dummy
sandrowagner 9cd93c2
7455 Display price slider with correct values
avstudnitz 67d650f
7455 Update page with correct parameters after using price slider
avstudnitz 5fb0659
7455 Adjust upper value to display .99 instead of .00
avstudnitz 9e7484e
Merge branch 'develop' into 7455/price-slider
avstudnitz 8a95c97
7455 Allow filtering by decimal attributes other than "price"
avstudnitz 7083485
7455 optimize filter styles
sandrowagner c368d8d
Merge branch '7455/price-slider' of github.com:integer-net/solr-magen…
sandrowagner b9cac94
7455 Show additional decimal filters in filter list
avstudnitz 10c1cbf
7455 Retrieve correct min and max available values for decimal filters
avstudnitz 8f93b4c
Merge remote-tracking branch 'composer/7455/price-slider' into 7455/p…
avstudnitz db47501
7455 Fix display of decimal attributes in state block
avstudnitz 92ba7da
7455 Calculate step size for decimal slider
avstudnitz bef8d06
7455 Add configuration option to disable slider for price filter
avstudnitz 409a87b
Merge branch 'develop' into 7455/price-slider
avstudnitz c6f07c0
7455 Add missing parameter for unit test
avstudnitz af8c995
7455 Skip failing test
avstudnitz dc9c25a
7455 Fix syntax error
avstudnitz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
main/src/Model/Plugin/CatalogsearchFilterDecimalPlugin.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
<?php | ||
/** | ||
* integer_net Magento Module | ||
* | ||
* @category IntegerNet | ||
* @package IntegerNet | ||
* @copyright Copyright (c) 2016 integer_net GmbH (http://www.integer-net.de/) | ||
* @author Fabian Schmengler <[email protected]> | ||
*/ | ||
|
||
namespace IntegerNet\Solr\Model\Plugin; | ||
|
||
use Magento\Catalog\Model\Layer\Filter\ItemFactory as FilterItemFactory; | ||
use Magento\CatalogSearch\Model\Layer\Filter\Decimal as Subject; | ||
use Magento\Framework\App\RequestInterface; | ||
|
||
/** | ||
* Plugin to display multiple filters for same attribute in state block | ||
*/ | ||
class CatalogsearchFilterDecimalPlugin | ||
{ | ||
/** | ||
* @var FilterItemFactory | ||
*/ | ||
private $filterItemFactory; | ||
/** | ||
* @var \Magento\Framework\Pricing\PriceCurrencyInterface | ||
*/ | ||
private $priceCurrency; | ||
/** | ||
* @var \Magento\Catalog\Model\Layer\Filter\DataProvider\PriceFactory | ||
*/ | ||
private $dataProviderFactory; | ||
|
||
public function __construct( | ||
FilterItemFactory $filterItemFactory, | ||
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency, | ||
\Magento\Catalog\Model\Layer\Filter\DataProvider\PriceFactory $dataProviderFactory | ||
) { | ||
$this->filterItemFactory = $filterItemFactory; | ||
$this->priceCurrency = $priceCurrency; | ||
$this->dataProviderFactory = $dataProviderFactory; | ||
} | ||
|
||
public function aroundApply(Subject $subject, \Closure $proceed, RequestInterface $request) | ||
{ | ||
$attributeCode = $subject->getRequestVar(); | ||
$attributeValue = $request->getParam($attributeCode); | ||
|
||
if ((!$attributeValue) || !is_array($attributeValue)) { | ||
return $proceed($request); | ||
} | ||
|
||
$fromParts = []; | ||
$toParts = []; | ||
foreach ($attributeValue as $attributeValueArrayPart) { | ||
$filterParams = explode(',', $attributeValueArrayPart); | ||
$dataProvider = $this->getDataProvider($subject); | ||
$filter = $dataProvider->validateFilter($filterParams[0]); | ||
if (!$filter) { | ||
continue; | ||
} | ||
|
||
$dataProvider->setInterval($filter); | ||
$priorFilters = $dataProvider->getPriorFilters($filterParams); | ||
if ($priorFilters) { | ||
$dataProvider->setPriorIntervals($priorFilters); | ||
} | ||
|
||
list($from, $to) = $filter; | ||
|
||
$fromParts[] = $from; | ||
$toParts[] = $to; | ||
|
||
$subject->getLayer()->getState()->addFilter( | ||
$this->_createItem($subject, $this->_renderRangeLabel($subject, empty($from) ? 0 : $from, $to), $filter) | ||
); | ||
} | ||
|
||
/** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $productCollection */ | ||
$productCollection = $subject->getLayer() | ||
->getProductCollection(); | ||
$productCollection->addFieldToFilter( | ||
$attributeCode, | ||
['from' => $fromParts, 'to' => $toParts] | ||
); | ||
|
||
|
||
return $subject; | ||
} | ||
|
||
/** | ||
* Create filter item object | ||
* | ||
* @param Subject $subject | ||
* @param string $label | ||
* @param mixed $value | ||
* @param int $count | ||
* @return \Magento\Catalog\Model\Layer\Filter\Item | ||
*/ | ||
protected function _createItem(Subject $subject, $label, $value, $count = 0) | ||
{ | ||
return $this->filterItemFactory->create() | ||
->setFilter($subject) | ||
->setLabel($label) | ||
->setValue($value) | ||
->setCount($count); | ||
} | ||
|
||
/** | ||
* Prepare text of range label | ||
* | ||
* @param Subject $subject | ||
* @param float|string $fromValue | ||
* @param float|string $toValue | ||
* @return float|\Magento\Framework\Phrase | ||
*/ | ||
protected function _renderRangeLabel(Subject $subject, $fromValue, $toValue) | ||
{ | ||
if ($toValue === '') { | ||
return __('%1 and above', $fromValue); | ||
} elseif ($fromValue == $toValue && $this->getDataProvider($subject)->getOnePriceIntervalValue()) { | ||
return $fromValue; | ||
} else { | ||
return __('%1 - %2', $fromValue, $toValue); | ||
} | ||
} | ||
|
||
/** | ||
* @param Subject $subject | ||
* @return \Magento\Catalog\Model\Layer\Filter\DataProvider\Price | ||
*/ | ||
private function getDataProvider(Subject $subject) | ||
{ | ||
return $this->dataProviderFactory->create(['layer' => $subject->getLayer()]); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/** | ||
* integer_net Magento Module | ||
* | ||
* @category IntegerNet | ||
* @package IntegerNet_Solr | ||
* @copyright Copyright (c) 2017 integer_net GmbH (http://www.integer-net.de/) | ||
* @author Andreas von Studnitz <[email protected]> | ||
*/ | ||
|
||
namespace IntegerNet\Solr\Model\Search\Adapter; | ||
|
||
class DecimalFilter extends \Magento\CatalogSearch\Model\Layer\Filter\Decimal | ||
{ | ||
|
||
/** | ||
* Checks whether the option reduces the number of results | ||
* | ||
* @param int $optionCount Count of search results with this option | ||
* @param int $totalSize Current search results count | ||
* @return bool | ||
*/ | ||
protected function isOptionReducesResults($optionCount, $totalSize) | ||
{ | ||
return true; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with current Magento 2 standards it should be private and without underscore