I am trying to add custom listing filter - ‚Is New‘ on basis of release date of product.
‚Mark products as ‚new‘, for ? days‘ config from Settings => Products
If config days + release date is greater than the current date then it is considered as new product.
For that, I need to add custom listing filter on product page
I have added a subscriber for that and also html code in filter-panel.html.twig
class AddNewListingFilter implements EventSubscriberInterface
{public static function getSubscribedEvents() { return [ ProductListingCollectFilterEvent::class => 'addFilter' ]; } public function addFilter(ProductListingCollectFilterEvent $event): void { // fetch existing filters $filters = $event->getFilters(); $request = $event->getRequest(); $filtered = (bool) $request->get('isNew'); $ids = []; $filter = new Filter( // name 'isNew', $filtered === true, [ new FilterAggregation( 'isNew', new MaxAggregation('isNew', 'product.isNew'), [new RangeFilter( 'product.releaseDate', [RangeFilter::GTE => 'DATE_SUB(CURRENT_DATE(), INTERVAL 90 DAY)'] )] ), ], new RangeFilter( 'product.releaseDate', [RangeFilter::GTE => 'DATE_SUB(CURRENT_DATE(), INTERVAL 90 DAY)'] ), $filtered ); // Add your custom filter $filters->add($filter); }
This code does not work. Please help me with this. Thank you in advance.