Use cases
Our module supports adding New, In stock, Out of Stock and On Sale filters to Magento 2 layered navigation multi select. By allowing users to sort items that way, you make the searching process more convinient and effective.
- Toggle content by filter
- Stock Filter
- On Sale Filter
- New Filter
- Rating Filter
- Integration with magento 2.1
- Porto Img Lazyload Fix
Toggle content by filter
If you want to show/hide some HTML when some specific filter was applied in layered navigation.
So before you show some HTML you need to add it to the category page. If you already have HTML content at the page. Just wrap it in container <div class="swissup-aln-toggle swissup-aln-toggle-color-5484 swissup-aln-hidden"><!--your toggle content here --></div>
.
- Create a static block for all categories. Go
Content -> Blocks -> Add New Block
and fill the form like above - Create widget (type static block). Go
Content -> Wifdgets -> Add Widget
and fill formStorefront Properties -> Type
selectCms Static Block
. InWidget Options -> Block
select block name you created at previous step. Layout updates fill like at picture.- Click
Add Layout Update
. Select Display on Anchor Categories - Categories select ‘All’
- Container ‘Main Content Top’ - will shows above product listing
- Repeat for
Non-Anchor Categories
- Click
- Flush Cache
- Open any category page. In my case, I see many X.
- Select attribute-value pair for example color purple. After reloading you can copy your attribute-value from the address bar (in my case ?color=5484)
- Open you custom static block created at first step and add some html markup
<div class="swissup-aln-toggle swissup-aln-toggle-color-5484 swissup-aln-hidden">any HTML tags, picture, another widgets, etc.</div>
When attribute color option purple (5484) was apply js code remove class “swissup-aln-hidden” and show widget content.
Stock Filter
Please follow the next steps:
-
Go
Stores -> Configuration -> Catalog -> Inventory -> Stock Options -> Display Out of Stock Products
and enable the display Out of Stock Products. -
Open
Store -> Attributes -> Product
. -
Find the attribute
quantity_and_stock_status
. -
Open Storefront Properties and find
Use in Layered Navigation
and setFilterable with results
. -
In console run -
php bin/magento indexer:reindex
. -
Check on the frontend. At least one product must be ‘out of stock’.
On Sale Filter
-
Open
Store -> Attributes -> Product
. -
Find attribute
special_price
. -
Open Storefront Properties and find
Use in Layered Navigation
and setFilterable with results
. -
In console run -
php bin/magento indexer:reindex
. -
Check on the frontend.
New Filter
-
Open
Store -> Attributes -> Product
. -
Find attribute
new
. It comes with Magento 2 Sample Data, so you can create it manually if you don’t have it. It should have Yes/No type andnew
as attribute code. -
Open Storefront Properties section and find
Use in Layered Navigation
config - set itFilterable (with results)
. -
Execute re-index in console:
php bin/magento indexer:reindex
. -
How to set product as New in Magento 2:
- Go
Catalog > Products
, choose the product you want to set as New and click “Edit”. - Find
Set Product as New From
config and fill the date fields. - Save the changes.
- Go
-
Check the frontend.
Rating Filter
With rating filter functionality it is no need to scroll through thousands of products. The opportunity to sort items by rating is good for clients who trust other customers reviews.
-
Open
Store -> Attributes -> Product
. -
Find attribute
rating_summary
. -
Open Storefront Properties and find
Use in Layered Navigation
. Check/setFilterable with results
(by default Yes). -
In console run
bin/magento index:reindex
Integration with magento 2.1
For compatibility with 2.1 need apply changes from 2 commits:
curl -L https://github.com/magento/magento2/commit/f8c75a8.patch > /tmp/f8c75a8.patch
git apply --check /tmp/f8c75a8.patch
git apply /tmp/f8c75a8.patch
curl -L https://github.com/magento/magento2/commit/87ec99d.patch > /tmp/87ec99d.patch
git apply --check /tmp/87ec99d.patch
git apply /tmp/87ec99d.patch
Porto Img Lazyload Fix
Add js patch
$(document).on('swissup:ajaxlayerednavigation:reload:after', function (event, navigation, response) {
$("img.porto-lazyload:not(.porto-lazyload-loaded)").lazyload({effect:"fadeIn"});
});