Skip to content

Rule: Source models extending \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource must use $_options to cache values #63

@schmengler

Description

@schmengler

Rule

The AbstractSource model contains a protected attribute $_options that is meant to cache the options. Unfortunately this is not enforced, instead each implementation of getAllOptions() is responsible to use that cache properly.

Reason

EAV source models often load possible values for attributes from external resources. Every access to those values, e.g. with $product->getAttributeText() calls getAllOptions() on the source model. The result of this method should only be calculated once.

Implementation

Any class that extends the abstract source model should return $this->_options in getAllOptions()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions