Skip to content
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

Function visibility problem on getFilterField #72

Open
mwawrzyniak-57 opened this issue Feb 21, 2024 · 0 comments
Open

Function visibility problem on getFilterField #72

mwawrzyniak-57 opened this issue Feb 21, 2024 · 0 comments

Comments

@mwawrzyniak-57
Copy link

Description

The visibility of the private method : getFilterField causes a problem for us when displaying the price slider filter of elasticsuite.
When we called this method in the DecimalFilterTrait.php of elasticsuite catalog in _getItemsData() method to get items :

    /**
     * @SuppressWarnings(PHPMD.CamelCaseMethodName)
     * Get data array for building attribute filter items
     *
     * @return array
     * @throws \Magento\Framework\Exception\LocalizedException
     */
protected function _getItemsData()
    {
        $attribute = $this->getAttributeModel();
        $this->_requestVar = $attribute->getAttributeCode();

        /** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $productCollection */
        $productCollection = $this->getLayer()->getProductCollection();
        $facets = $productCollection->getFacetedData($this->getFilterField());

The function calls a magic method and not the correct method because it is private :

$facets = $productCollection->getFacetedData($this->getFilterField());
// $this->getFilterField()) calls magic method

And so, the method returns null and this causes the price slider not to display because there are 0 items.

Solution

To fix this problem, we recommende to modify the visibility method as protected to be able to use it without problem.

For all same methods in module-elasticsuite-catalog :

private function getFilterField()

to

protected function getFilterField()

The patch, we made to fix this issue is the following :

diff --git a/src/module-elasticsuite-catalog-graph-ql/Search/Request/Product/Aggregation/Provider/FilterableAttributes/Modifier/ViewMore.php b/src/module-elasticsuite-catalog-graph-ql/Search/Request/Product/Aggregation/Provider/FilterableAttributes/Modifier/ViewMore.php
index 9c47b6f..8a76068 100644
--- a/src/module-elasticsuite-catalog-graph-ql/Search/Request/Product/Aggregation/Provider/FilterableAttributes/Modifier/ViewMore.php
+++ b/src/module-elasticsuite-catalog-graph-ql/Search/Request/Product/Aggregation/Provider/FilterableAttributes/Modifier/ViewMore.php
@@ -113,7 +113,7 @@ class ViewMore implements ModifierInterface
      *
      * @return bool|string
      */
-    private function getFilterField()
+    protected function getFilterField()
     {
         try {
             $attribute = $this->getAttribute();
diff --git a/src/module-elasticsuite-catalog/Model/Layer/Filter/Decimal.php b/src/module-elasticsuite-catalog/Model/Layer/Filter/Decimal.php
index 17fabe9..d9686a2 100644
--- a/src/module-elasticsuite-catalog/Model/Layer/Filter/Decimal.php
+++ b/src/module-elasticsuite-catalog/Model/Layer/Filter/Decimal.php
@@ -114,7 +114,7 @@ class Decimal extends \Magento\CatalogSearch\Model\Layer\Filter\Decimal
      *
      * @return string
      */
-    private function getFilterField()
+    protected function getFilterField()
     {
         return $this->requestFieldMapper->getMappedFieldName(
             $this->getAttributeModel()->getAttributeCode()
diff --git a/src/module-elasticsuite-catalog/Model/Layer/Filter/Price.php b/src/module-elasticsuite-catalog/Model/Layer/Filter/Price.php
index b4c9f56..0a92bc9 100644
--- a/src/module-elasticsuite-catalog/Model/Layer/Filter/Price.php
+++ b/src/module-elasticsuite-catalog/Model/Layer/Filter/Price.php
@@ -136,7 +136,7 @@ class Price extends \Magento\CatalogSearch\Model\Layer\Filter\Price
      *
      * @return string
      */
-    private function getFilterField()
+    protected function getFilterField()
     {
         return $this->requestFieldMapper->getMappedFieldName('price');
     }
diff --git a/src/module-elasticsuite-catalog/Search/Request/Product/Aggregation/Provider/FilterableAttributes/Modifier/AjaxFilter.php b/src/module-elasticsuite-catalog/Search/Request/Product/Aggregation/Provider/FilterableAttributes/Modifier/AjaxFilter.php
index a1063ef..874c96e 100644
--- a/src/module-elasticsuite-catalog/Search/Request/Product/Aggregation/Provider/FilterableAttributes/Modifier/AjaxFilter.php
+++ b/src/module-elasticsuite-catalog/Search/Request/Product/Aggregation/Provider/FilterableAttributes/Modifier/AjaxFilter.php
@@ -118,7 +118,7 @@ class AjaxFilter implements ModifierInterface
      *
      * @return bool|string
      */
-    private function getFilterField()
+    protected function getFilterField()
     {
         try {
             $attribute = $this->getAttribute();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant