Skip to content
← All PrestaShop 9 errors

PrestaShop 9 errors

Call to undefined method Attribute::getAttributes() in PrestaShop 8 and 9

PrestaShop 8 renamed the Attribute class to ProductAttribute, because PHP 8 has its own Attribute class. Old code that calls Attribute:: now reaches PHP's class and fails.

The error
Call to undefined method Attribute::getAttributes()
Removed in
PrestaShop 8.0
Usually found in
Modules that handle combinations, overrides

What happened

In PrestaShop 1.7, product attribute values (size M, colour Red) were handled by a class called Attribute. PHP 8 added a built-in class with the same name, used for PHP attributes such as #[Route]. The two cannot live together, so PrestaShop 8.0 renamed its class to ProductAttribute.

Old code does not fail with "class not found". Attribute still exists, it is just PHP's class now. So the error appears on the first method call:

  • Attribute::getAttributes($idLang) gives Call to undefined method Attribute::getAttributes()
  • new Attribute($id) creates PHP's attribute object, and the code fails a little later, when it reads ->name or calls ->save()

That makes it confusing: the class name looks right, but nothing on it works.

The fix

Use the new class name. Its methods and properties are the same:

// Before (PrestaShop 1.7)
$values = Attribute::getAttributes($idLang);
$value = new Attribute($idAttribute, $idLang);

// After (PrestaShop 8 and 9)
$values = ProductAttribute::getAttributes($idLang);
$value = new ProductAttribute($idAttribute, $idLang);

An override in override/classes/Attribute.php has to become override/classes/ProductAttribute.php with class ProductAttribute extends ProductAttributeCore. Delete var/cache/prod/class_index.php afterwards so PrestaShop finds it.

AttributeGroup kept its name.

Where else it hides

Modules for combinations, product options, layered navigation, feeds and imports. Search for the class used in code, not just the word:

grep -rn "Attribute::\|new Attribute(\|extends AttributeCore" modules/ override/

Find every place like this before you upgrade

Where one removed call is, there are usually more. Our free PrestaShop 9 Readiness Check reads the code of every module, the theme and the overrides and lists each problem with its file and line. It only reads, nothing is changed.

Get the free check

Prefer not to fix it yourself? We upgrade stores to PrestaShop 9 for a fixed price. See the upgrade