Ein Magento 1 Modul, das Multiselect-Attribute mit einem Custom Source Model korrekt in den EAV-Index schreibt, damit Layered Navigation und Filter für diese Attribute funktionieren.
Magento schreibt den EAV-Index für Multiselect-Attribute in
Mage_Catalog_Model_Resource_Product_Indexer_Eav_Source. Der Core-Code akzeptiert nur die Options-IDs,
die in der Tabelle eav_attribute_option stehen.
Manche Multiselect-Attribute nutzen ein Custom Source Model. Diese Attribute erzeugen ihre Optionen im
PHP-Code. Die Optionen stehen nicht in der Tabelle eav_attribute_option. Deshalb verwirft der
Core-Code alle Werte dieser Attribute, und der Index bleibt leer. Layered Navigation und Filter
funktionieren für diese Attribute nicht.
Das Modul ersetzt die Core-Indexer-Resource durch
Conlabz_CustomSourceIndex_Model_Rewrite_Catalog_Resource_Product_Indexer_Eav_Source.
Die neue Klasse macht drei Dinge:
- Sie ruft
getAllOptions()bei jedem Custom Source Model auf. Danach fügt sie diese Options-IDs der Liste der erlaubten Options-IDs hinzu. Siehe_getMultiSelectAttributeWithSourceModels(). - Sie ignoriert Werte, die nicht numerisch sind. Eine Options-ID muss eine Ganzzahl sein.
- Sie wählt die richtige Werte-Tabelle. Ab Magento 1.9.3.0 liest sie
catalog_product_entity_text. Bei früheren Versionen liest siecatalog_product_entity_varchar.
Das Modul besteht aus zwei PHP-Klassen:
| Datei | Funktion |
|---|---|
Helper/Data.php |
Ein leerer Helper. Er macht den Alias customsourceindex verfügbar. |
Model/Rewrite/.../Eav/Source.php |
Der Indexer-Rewrite. Er enthält die gesamte Logik. |
Das Modul legt keine Tabellen und keine Spalten an. Es hat keine Setup-Skripte, keine Admin-Einstellungen, keine Templates und keine Layout-Dateien.
Installation per Composer:
composer require conlabz/magex_customsourceindex
Alternativ per Modman:
modman clone git@github.com:conlabz/magex_customsourceindex.git
Danach diese Schritte durchführen:
- Magento-Cache leeren.
- Vollständigen Reindex des Product Attributes Index durchführen.
- Der Rewrite ist eine Kopie einer protected Core-Methode. Er ist somit an die Magento-Version gebunden. Modul nach jedem Magento-Update testen.
- Das Modul steht in Konflikt mit anderen Modulen, die
catalog_resource/product_indexer_eav_sourceüberschreiben.
- Modulversion: 1.0.0
- Code Pool: community
- Abhängigkeit:
Mage_Catalog
Magento writes the EAV index for multiselect attributes in
Mage_Catalog_Model_Resource_Product_Indexer_Eav_Source. The core code accepts only the option IDs
that are in the eav_attribute_option table.
Some multiselect attributes use a custom source model. These attributes make their options in PHP
code. The options are not in the eav_attribute_option table. Thus the core code refuses all values
of these attributes, and the index stays empty. Layered navigation and filters do not work for these
attributes.
The module replaces the core indexer resource with
Conlabz_CustomSourceIndex_Model_Rewrite_Catalog_Resource_Product_Indexer_Eav_Source.
The new class does these three things:
- It calls
getAllOptions()on each custom source model. Then it adds these option IDs to the list of permitted option IDs. Refer to_getMultiSelectAttributeWithSourceModels(). - It ignores values that are not numeric. An option ID must be an integer.
- It selects the correct value table. For Magento 1.9.3.0 and later versions, it reads
catalog_product_entity_text. For earlier versions, it readscatalog_product_entity_varchar.
The module has two PHP classes:
| File | Function |
|---|---|
Helper/Data.php |
An empty helper. It makes the customsourceindex alias available. |
Model/Rewrite/.../Eav/Source.php |
The indexer rewrite. It holds all of the logic. |
The module makes no tables and no columns. It has no setup scripts, no admin settings, no templates and no layout files.
Install the module with composer:
composer require conlabz/magex_customsourceindex
You can also install the module with modman:
modman clone git@github.com:conlabz/magex_customsourceindex.git
Then do these steps:
- Clear the Magento cache.
- Do a full reindex of the Product Attributes index.
- The rewrite is a copy of a protected core method. Thus it is related to the Magento version. Test the module after each Magento update.
- The module is in conflict with other modules that rewrite
catalog_resource/product_indexer_eav_source.
- Module version: 1.0.0
- Code pool: community
- Dependency:
Mage_Catalog
Diese Extension steht unter der MIT-Lizenz. Details siehe LICENSE.