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

Range filter is not working #2374

Open
xApep opened this issue Sep 21, 2022 · 10 comments
Open

Range filter is not working #2374

xApep opened this issue Sep 21, 2022 · 10 comments

Comments

@xApep
Copy link

xApep commented Sep 21, 2022

The more I do the more things are not working, or I just don't know how to set it up correctly =)

This is my module settings
image

This is initial dump before submitting the range filter form (item value of specs_dimension_depth: 70)
Untitled-2

If not adjusting the range filter, meaning min: 1 max: 110

  • no items are shown

No matter which value I set for max (above 99), eg. 100, 101

  • no items are shown

But if I set value for max under 100, for example 99

  • items are shown

This probably is not working as it should since no matter which max I would set that is above 70 (this is product specs_dimension_depth value), items should be shown.

image

Contao: 4.13.8
Isotope: 2.8.7

@xApep
Copy link
Author

xApep commented Sep 21, 2022

I have notice that if you use range filter for Price it works as it should.

The setting in Range filter module is for Depth which is "custom" Text field attribute.
image


I have locally one more isotope 2.7.x-dev where this is working.

@aschempp
Copy link
Member

it would be great if you could further debug this issue because I don't have that complex setup. Please create a pull request or patch if you have a solution to discuss 😊

@xApep
Copy link
Author

xApep commented Sep 27, 2022

Unfortunately my understanding of Isotope is not that comprehensive to debug that thing to the causing problem.

But what I have seen every range attribute (which we define as attribute number) works random (when it shows results), but the price field always works as it should.

What would be the fastest thing to do (on mine side) so that you can debug it? :)

@aschempp
Copy link
Member

What would be the fastest thing to do (on mine side) so that you can debug it? :)

we do offer paid support through the Isotope Circle (https://circle.isotopeecommerce.org) 🙃

@xApep
Copy link
Author

xApep commented Sep 28, 2022

You sir, needs to do better packaging to sell it :)

All thou I'm familiar how Isotope is developed, but still, we are talking about bugfix :)

...but I can make a few feature suggestion to push Isotope CRO to next level, of course for free :P

@criwas
Copy link

criwas commented Sep 26, 2024

Taking this up again with a solution. Had the same problem.

Contao 4.13.49
Isotope: 2.9.1

I found out, that even the digit-values are saved as varchar. I extended the TextField-Attribute to handle digits as numbers in the database. I have added a field to control the decimal places individually. Range filter works now. Not the cleanest, but it had to be done quickly :)

It makes some problems if you have an existing installation with non decimals values. I made some changes directly in the database, because I had no time to build a runonce-file.

config/config.php

\Isotope\Model\Attribute::registerModelType('text', 'App\Model\Attribute\TextField');

dca/tl_isotope_attribute.php

use Contao\CoreBundle\DataContainer\PaletteManipulator;
PaletteManipulator::create()
    ->addField('decimalPlaces', 'rgxp', PaletteManipulator::POSITION_BEFORE)
    ->applyToPalette('textdigit', 'tl_iso_attribute');

$GLOBALS['TL_DCA']['tl_iso_attribute']['fields']['decimalPlaces'] = [
    'exclude'                 => true,
    'inputType'               => 'text',
    'eval'                    => ['rgxp'=>'digit', 'tl_class'=>'w50'],
    'sql'                     => "int(5) unsigned NOT NULL default '0'"
];

languages/de/tl_isotope_attribute.php

$GLOBALS['TL_LANG']['tl_iso_attribute']['decimalPlaces'] = ['Nachkommastellen', 'Bitte geben Sie die Anzahl Nachkommastellen ein.'];

App/Model/Attribute/TextField.php

namespace App\Model\Attribute;

use Isotope\Model\Attribute\TextField as IsotopeTextField;

class TextField extends IsotopeTextField {
    /**
     * @inheritdoc
     */
    public function saveToDCA(array &$arrData) {
        parent::saveToDCA($arrData);
        
        $maxlength = (int) $this->maxlength ?: 255;

        if ('digit' === $this->rgxp) {
            if (0 < ($decimalPlaces = $this->decimalPlaces)) {
                $maxlength = $maxlength > 10 ? 10 : $maxlength;
                $default = str_pad('0.', ($decimalPlaces+2), '0', STR_PAD_RIGHT);
                $arrData['fields'][$this->field_name]['sql'] = "decimal($maxlength,$decimalPlaces) unsigned NOT NULL default '$default'";
            } else {
                $maxlength = $maxlength > 65 ? 65 : $maxlength;
                $arrData['fields'][$this->field_name]['sql'] = "int($maxlength) unsigned NOT NULL default '0'";
            }
        } else {
            $arrData['fields'][$this->field_name]['sql'] = "varchar($maxlength) NOT NULL default ''";
        }
    }
}

@aschempp
Copy link
Member

aschempp commented Dec 3, 2024

I'm not sure I can follow here. Setting "Input validation" to "Numeric" means you cannot enter decimal places. If you need decimal places, change the Input validation. A text field can store both, but the validation should prevent it. Maybe that already solves the problem?

@criwas
Copy link

criwas commented Dec 3, 2024

I had the problem that the data got imported and the customer had wrong data (e. g. strings). While the filter is generated in the frontend, the original input is no longer validated. As a result, the filter no longer works. And due to the non-strict DB field, you still have a way to enter anything, even strings that are not numbers. The strict DB field means that incorrect data can no longer be entered. Not even via an import.

@fritzmg
Copy link
Contributor

fritzmg commented Dec 3, 2024

but still, we are talking about bugfix :)

@xApep any work is work. This is OSS you can use free of charge.

@aschempp
Copy link
Member

aschempp commented Dec 4, 2024

I had the problem that the data got imported and the customer had wrong data (e. g. strings). While the filter is generated in the frontend, the original input is no longer validated. As a result, the filter no longer works. And due to the non-strict DB field, you still have a way to enter anything, even strings that are not numbers. The strict DB field means that incorrect data can no longer be entered. Not even via an import.

I get that, but it is basically an issue with your import in the first place, right? Also, be aware that you can always create DCA fields like everywhere in Contao, by adding them to tl_iso_product. If you need special formatting, validation, save_callback or anything else, use the DCA not the attributes manager. I don't see anything we can fix in Isotope here for the general public 🤔

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

4 participants