forked from Smile-SA/elasticsuite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Smile-SA#3369 from Smile-SA/vahonc-3333-elasticsui…
…te-catalog-default-sort-direction-system-config-settings-2.10_feature Default sort direction system config settings 2.10 feature
- Loading branch information
Showing
7 changed files
with
237 additions
and
18 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/module-elasticsuite-catalog/Model/Config/Source/SortDirectionConfig.php
This file contains 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,39 @@ | ||
<?php | ||
/** | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade Smile ElasticSuite to newer | ||
* versions in the future. | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteCatalog | ||
* @author Vadym Honcharuk <vahonc@smile.fr> | ||
* @copyright 2024 Smile | ||
* @license Open Software License ("OSL") v. 3.0 | ||
*/ | ||
namespace Smile\ElasticsuiteCatalog\Model\Config\Source; | ||
|
||
use Magento\Framework\Data\OptionSourceInterface; | ||
|
||
/** | ||
* Custom sort direction source model. | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteCatalog | ||
* @author Vadym Honcharuk <vahonc@smile.fr> | ||
*/ | ||
class SortDirectionConfig implements OptionSourceInterface | ||
{ | ||
/** | ||
* Get options in "value-label" format. | ||
* | ||
* @return array | ||
*/ | ||
public function toOptionArray() | ||
{ | ||
return [ | ||
['value' => 'asc', 'label' => __('ASC')], | ||
['value' => 'desc', 'label' => __('DESC')], | ||
]; | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
src/module-elasticsuite-catalog/Plugin/Catalog/Controller/Adminhtml/Category/SavePlugin.php
This file contains 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,96 @@ | ||
<?php | ||
/** | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade Smile ElasticSuite to newer | ||
* versions in the future. | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteCatalog | ||
* @author Romain Ruaud <romain.ruaud@smile.fr> | ||
* @copyright 2024 Smile | ||
* @license Open Software License ("OSL") v. 3.0 | ||
*/ | ||
namespace Smile\ElasticsuiteCatalog\Plugin\Catalog\Controller\Adminhtml\Category; | ||
|
||
use Magento\Catalog\Controller\Adminhtml\Category\Save; | ||
|
||
/** | ||
* Plugin on Category Save controller that allows to handle additional "use_config" elements. | ||
* The legacy ones are hardcoded in the controller class... | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteCatalog | ||
* @author Romain Ruaud <romain.ruaud@smile.fr> | ||
*/ | ||
class SavePlugin | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $stringToBoolInputs = [ | ||
'use_config' => ['sort_direction'], | ||
]; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param array $stringToBoolInputs The input names to cast | ||
*/ | ||
public function __construct(array $stringToBoolInputs = []) | ||
{ | ||
$this->stringToBoolInputs = array_merge_recursive($this->stringToBoolInputs, $stringToBoolInputs); | ||
} | ||
|
||
/** | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
* | ||
* @param \Magento\Catalog\Controller\Adminhtml\Category\Save $subject Category controller | ||
* @param array $result Result | ||
* @param array $data Legacy Data | ||
* @param array $stringToBoolInputs Inputs to be converted | ||
* | ||
* @return array | ||
*/ | ||
public function afterStringToBoolConverting(Save $subject, array $result, array $data, array $stringToBoolInputs = null) | ||
{ | ||
return $this->stringToBoolConverting($result); | ||
} | ||
|
||
/** | ||
* Copy paste of the legacy method of the category save controller. | ||
* Copy pasted because the legacy method cannot be called again in a plugin since it's recursive. | ||
* | ||
* @SuppressWarnings(PHPMD.ElseExpression) | ||
* | ||
* @param array $data The data | ||
* @param array $stringToBoolInputs The inputs | ||
* | ||
* @return mixed | ||
*/ | ||
private function stringToBoolConverting($data, array $stringToBoolInputs = null) | ||
{ | ||
if (null === $stringToBoolInputs) { | ||
$stringToBoolInputs = $this->stringToBoolInputs; | ||
} | ||
|
||
foreach ($stringToBoolInputs as $key => $value) { | ||
if (is_array($value)) { | ||
if (isset($data[$key])) { | ||
$data[$key] = $this->stringToBoolConverting($data[$key], $value); | ||
} | ||
} else { | ||
if (isset($data[$value])) { | ||
if ($data[$value] === 'true') { | ||
$data[$value] = true; | ||
} | ||
if ($data[$value] === 'false') { | ||
$data[$value] = false; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return $data; | ||
} | ||
} |
This file contains 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 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 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 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 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