hryvinskyi / magento2-catalog-sorting-newest
Catalog sort option New: the most recently created products first, ordered by a creation time written into the search documents.
Package info
github.com/hryvinskyi/magento2-catalog-sorting-newest
Type:magento2-module
pkg:composer/hryvinskyi/magento2-catalog-sorting-newest
Requires
- php: ~8.1.0||~8.2.0||~8.3.0||~8.4.0||~8.5.0
- hryvinskyi/magento2-catalog-sorting: ^1.0
- hryvinskyi/magento2-catalog-sorting-options: ^1.0
- magento/framework: *
- magento/module-backend: *
- magento/module-catalog: *
- magento/module-config: *
- magento/module-store: *
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Adds New to the storefront Sort By list: the most recently created products first, per store view.
What it does for a store
- A New sort order (
product_list_order=new), offered in the store views where it is enabled. A listing sorted by it opens newest-first when the shopper chose no direction. - The product's creation time (
created_atof the product, in Unix seconds) is written into each product search document at index time, with one query per batch of products. - No table, no refresh, nothing per request. The value is written whenever a product's search document is built, and the engine sorts on the numeric document field
sort_newest; there is no join and no computation per query. - Switching the option on needs no reindex. The field is written in every store whatever the store's setting.
Requirements
- PHP 8.1 to 8.5.
hryvinskyi/magento2-catalog-sortingandhryvinskyi/magento2-catalog-sorting-options, ^1.0 each.- The platform's Catalog, Store, Config and Backend modules (what
composer.jsonandetc/module.xmldeclare).
Installation
composer require hryvinskyi/magento2-catalog-sorting-newest bin/magento setup:upgrade bin/magento setup:di:compile bin/magento cache:flush bin/magento indexer:reindex catalogsearch_fulltext
The module adds the field sort_newest to the product search documents. One full catalogsearch_fulltext reindex puts it into the index mapping and writes the values; listings keep working before it, and a product without the value sorts as 0, the oldest.
Configuration
Stores › Configuration › Catalog › Catalog Sorting › New
| Path | Label | Default | Scope |
|---|---|---|---|
catalog_sorting/new/enabled |
Enabled | No | default, website, store view |
The label, the place and the visibility of the option in Sort By are set in Catalog Sorting › Sort Options.
Registrations
| Pool | Item |
|---|---|
providers of Hryvinskyi\CatalogSorting\Model\Index\DocumentFields |
newest, field sort_newest (long) |
sortFields of Hryvinskyi\CatalogSorting\Model\Search\ShopperSortFields |
code new on sort_newest |
options of Hryvinskyi\CatalogSortingOptions\Model\ListingSortOptions |
option new, "New", descending, sortOrder 150 |