isotope / core

Core repository of Isotope eCommerce, an eCommerce extension for Contao Open Source CMS
https://isotopeecommerce.org
136 stars 107 forks source link

AttributeOption::findByAttribute() expects Argument 1 implementing interface IsotopeAttributeWithOptions #2191

Closed Xirdion closed 2 years ago

Xirdion commented 3 years ago

Using the new version of isotope (2.7) with Contao 4.9.11 leads to an error while building the cache. Argument 1 passed to Isotope\Model\AttributeOption::findByAttribute() must implement interface Isotope\Interfaces\IsotopeAttributeWithOptions, instance of Isotope\Model\Attribute\TextField given

The problem is, that the function findByAttribute expects an argument with interface IsotopeAttributeWithOptions. This interface is an extension of IsotopeAttribute. But the Attribute-class itself and e.g. the TextField-class just implementing IsotopeAttribute. So the type is not correct because the child-interface is needed.


example of an Attribute-instance

class TextField extends Attribute implements IsotopeAttributeWithRange

example of an child-interface of Isotope-Attribute

interface IsotopeAttributeWithRange extends IsotopeAttribute

The interface that is needed when using the function AttributeOption::findByAttribute().

interface IsotopeAttributeWithOptions extends IsotopeAttribute
Flo-JB commented 3 years ago

We got also the same error message and temporary fixed it by wrapping

case IsotopeAttributeWithOptions::SOURCE_PRODUCT:

in an if case:

if ($this instanceof IsotopeAttributeWithOptions) {

in /vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Model/Attribute.php

I am not 100% sure about possible side effects but the shop works right now for us. Just if someone else need a quick fix to get the shop up again.

Note: A downgrade to 2.6.15 didn't fix the problem for us - we tried that first.

richardhj commented 3 years ago

Kannst du überprüfen, ob der TypeHint auf das Interface IsotopeAttributeWithOptions notwendig ist, oder ob der TypeHint IsotopeAttribute ausreicht und einen PR erstellen?

Xirdion commented 3 years ago

Der TypeHint ist leider notwendig, da die Funktion getOptionsSource() aus dem Interface aufgerufen wird.

if (IsotopeAttributeWithOptions::SOURCE_TABLE !== $objAttribute->getOptionsSource()) {
    throw new \LogicException('Options source for attribute "' . $objAttribute->field_name . '" is not the database table');
}

Entfernt man den TypeHint, dann bekommt man folgende Fehlermeldung. Attempted to call an undefined method named "getOptionsSource" of class "Isotope\Model\Attribute\TextField".

k-webdesign commented 3 years ago

Note: A downgrade to 2.6.15 didn't fix the problem for us - we tried that first.

Well, my quick fix was to downgrade. I deleted /vendor and the .lock file, reinstalled everything and it was fine then

ameotoko commented 3 years ago

I can confirm the issue. Downgrading using ~2.6.15 works for now.

DonLars commented 3 years ago

How can I downgrade with contao manager, because I got:

In AttributeOption.php line 267: Argument 1 passed to Isotope\Model\AttributeOption::findByAttribute() must

if I want to dorngrade zu 2.6.15

Thanks a Lot!

fritzmg commented 3 years ago

How can I downgrade with contao manager

Just change the version requirement to either ~2.6.0 or 2.6.*.

DonLars commented 3 years ago

It Works ,thanks :)

operatorone commented 3 years ago

Hi, I updated from 2.6 to 2.7.1 and still get the following error message when I want to update the database:

[2021-04-04 03:32:10] request.CRITICAL: Uncaught PHP Exception TypeError: "Argument 1 passed to Isotope\Model\AttributeOption::findByAttribute() must implement interface Isotope\Interfaces\IsotopeAttributeWithOptions, instance of Isotope\Model\Attribute\TextField given, called in /home/www/contao4_upd/vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Model/Attribute.php on line 260" at /home/www/contao4_upd/vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Model/AttributeOption.php line 267 {"exception":"[object] (TypeError(code: 0): Argument 1 passed to Isotope\\Model\\AttributeOption::findByAttribute() must implement interface Isotope\\Interfaces\\IsotopeAttributeWithOptions, instance of Isotope\\Model\\Attribute\\TextField given, called in /home/www/contao4_upd/vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Model/Attribute.php on line 260 at /home/www/contao4_upd/vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Model/AttributeOption.php:267)"} []

[2021-04-04 01:32:10] console.CRITICAL: Error thrown while running command "cache:warmup --env=prod". Message: "Argument 1 passed to Isotope\Model\AttributeOption::findByAttribute() must implement interface Isotope\Interfaces\IsotopeAttributeWithOptions, instance of Isotope\Model\Attribute\TextField given, called in /home/www/contao4_upd/vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Model/Attribute.php on line 260" {"exception":"[object] (TypeError(code: 0): Argument 1 passed to Isotope\\Model\\AttributeOption::findByAttribute() must implement interface Isotope\\Interfaces\\IsotopeAttributeWithOptions, instance of Isotope\\Model\\Attribute\\TextField given, called in /home/www/contao4_upd/vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Model/Attribute.php on line 260 at /home/www/contao4_upd/vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Model/AttributeOption.php:267)","command":"cache:warmup --env=prod","message":"Argument 1 passed to Isotope\\Model\\AttributeOption::findByAttribute() must implement interface Isotope\\Interfaces\\IsotopeAttributeWithOptions, instance of Isotope\\Model\\Attribute\\TextField given, called in /home/www/contao4_upd/vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Model/Attribute.php on line 260"} []

I tried to downgrade to 2.6.15, deleted the vendor folder and then update to 2.7.1. Unfortunately, no luck with solving the error.

May be someone has an additional idea how to fix this. Thnx.

aschempp commented 3 years ago

see https://github.com/isotope/core/pull/2203

fritzmg commented 3 years ago

@aschempp is this really fixed by #2203?

operatorone commented 3 years ago

Any news on this issue?

smsmyelco commented 3 years ago

We also had this problem.

Our fix was pretty easy.

In the database 'tl_iso_attribute' we searched for the attributes of the type 'text'.

We saw that there were an attribute with the following value in the column 'optionsSource' = table.

We changed it to 'attribute' and everything was working as it should.

We have no idea where this did happen... :(

UPDATEtl_iso_attributeSET optionsSource='attribute' WHERE optionsSource='table' AND type='text';

aschempp commented 2 years ago

fixed in 852d492c9fe34426a293c5788680db1c7fc3a507