Download the PHP package hans2103/magento2-optionfilter without Composer

On this page you can find all versions of the php package hans2103/magento2-optionfilter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package magento2-optionfilter

Hans2103_OptionFilter

Overview

This module filters configurable products from catalog views based on the stock status of their variants:

Behavior

No Filters Active

When no attribute filters are applied, configurable products are shown only if at least one variant is in stock. Products with all variants out of stock are hidden from the catalog.

Example:

Single Attribute Filter

When filtering by a single attribute (e.g., Size: M), a configurable product is shown only if at least one variant matching that filter is in stock.

Example:

Multiple Attribute Filters

When filtering by multiple attributes (e.g., Size: M AND Color: Red), a configurable product is shown only if the exact combination is in stock.

Example:

Non-Configurable Products

Simple, grouped, and bundle products are not affected by this filter and always show based on their own stock status.

Technical Implementation

Architecture

The module uses a beforeLoad plugin on Magento\Catalog\Model\ResourceModel\Product\Collection to modify the SQL query after all filters have been applied but before the collection executes.

Key Components

  1. Plugin: Hans2103\OptionFilter\Plugin\Product\Collection\FilterConfigurableByStock

    • Intercepts product collection before load
    • Detects layered navigation context
    • Builds and applies SQL WHERE clause
  2. Helper: Hans2103\OptionFilter\Helper\AttributeFilter
    • Parses active attribute filters from Layer state
    • Validates configurable attributes
    • Provides store context

SQL Strategy

The plugin adds a WHERE clause that:

Query pattern:

Note: The module uses catalog_product_entity_int (raw EAV table) instead of catalog_product_index_eav because Magento does not index configurable product child variants in the EAV index table.

Performance Considerations

Compatibility

Installation

  1. Place module in src/app/code/Hans2103/OptionFilter/
  2. Enable module: bin/magento module:enable Hans2103_OptionFilter
  3. Run deployment: make deploy
  4. Clear cache: bin/magento cache:flush

Uninstallation

  1. Disable module: bin/magento module:disable Hans2103_OptionFilter
  2. Run deployment: make deploy
  3. Remove module directory

Testing

Manual Test Scenarios

  1. No filters - all variants out of stock

    • Create configurable with Size M (out of stock), Size L (out of stock), Size XL (out of stock)
    • Navigate to category without filters
    • Expected: Product disappears
  2. No filters - at least one variant in stock

    • Create configurable with Size M (in stock), Size L (out of stock)
    • Navigate to category without filters
    • Expected: Product shows
  3. Single filter with out-of-stock variant

    • Product has Size M (in stock), Size L (out of stock)
    • Apply filter: Size = L
    • Expected: Product disappears
  4. Single filter with in-stock variant

    • Apply filter: Size = M
    • Expected: Product shows
  5. Multiple filters with exact combination out of stock

    • Create configurable: Size M Red (in stock), Size M Blue (out of stock)
    • Apply filters: Size = M AND Color = Blue
    • Expected: Product disappears
  6. Multiple filters with exact combination in stock

    • Apply filters: Size = M AND Color = Red
    • Expected: Product shows
  7. Non-configurable products
    • Apply any attribute filter or no filter
    • Expected: Simple products show based on own stock status

Troubleshooting

"Catalog Layer has been already created" Exception

Symptom: Exception thrown when viewing category pages with filters applied.

Cause: Multiple calls to Magento\Catalog\Model\Layer\Resolver::get() causing duplicate layer initialization.

Solution: This was fixed in the current version by consolidating layer retrieval to a single getLayer() method. If you encounter this error:

  1. Ensure you're using the latest version of the module
  2. Clear generated code: rm -rf generated/code
  3. Flush cache: bin/magento cache:flush

Prevention: Never call layerResolver->get() multiple times in the same request flow. Always cache the result if needed in multiple places.

Products not filtering as expected

  1. Check if filters are attribute-based (not category or price)
  2. Verify attributes are used in configurable products
  3. Check stock status in cataloginventory_stock_item table
  4. Review logs: var/log/system.log

All products disappear when filtering

If all products disappear when applying a filter, verify that configurable product child variants have attribute values in the catalog_product_entity_int table:

If this query returns no results, the EAV data may be corrupted or missing. Re-save the configurable product in the admin panel.

Performance issues

  1. Check MySQL slow query log
  2. Verify indexes exist on:
    • catalog_product_entity_int (entity_id, attribute_id, value, store_id)
    • catalog_product_super_link (parent_id, product_id)
    • cataloginventory_stock_item (product_id, is_in_stock)
  3. Monitor query execution time

Debug mode

Enable debug logging by checking var/log/system.log for entries containing "Error applying OptionFilter".

Implementation Notes

Why catalog_product_entity_int instead of catalog_product_index_eav?

Issue: Magento's EAV indexer (_prepareSelectIndex) filters out products with visibility = 1 (Not Visible Individually). Configurable product children always have visibility=1, so they are never indexed in catalog_product_index_eav. The _prepareRelationIndex step that propagates child values to the parent also only works from data already in the index — so configurable parents never get their super attribute values (e.g. size) in catalog_product_index_eav either.

This affects both FilterConfigurableByStock and AdjustAttributeCount. OpenSearch indexes configurables with their children's attribute values correctly, but the SQL-based catalog_product_index_eav does not.

Verification: You can verify this by running:

This will return 0, confirming that child products are not in the EAV index.

Solution: The module uses catalog_product_entity_int (the raw EAV attribute table) instead, which contains all attribute values including those for configurable product child variants. This approach:

Filter Type Compatibility

The module supports both:

This ensures compatibility with both standard category pages and search results pages, as well as Hyvä theme implementations.

License

Copyright © Hans2103. All rights reserved.


All versions of magento2-optionfilter with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1|^8.2|^8.3
magento/framework Version ^102.0|^103.0
magento/module-catalog Version ^104.0
magento/module-catalog-inventory Version ^100.4
magento/module-configurable-product Version ^100.4
magento/module-layered-navigation Version ^100.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package hans2103/magento2-optionfilter contains the following files

Loading the files please wait ...