Smile-SA / magento2-module-retailer-offer

Retailer Offer Module for Retailer Suite
6 stars 24 forks source link

Function visibility problem on getFilterField #72

Open mwawrzyniak-57 opened 8 months ago

mwawrzyniak-57 commented 8 months ago

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();