abinjohnedamanaabinjohnedamana MemberComments: 36 Received thanks: 9 Member since: February 2019

How to add customfields in product listing, search criteria?

Answers

  • abinjohnedamanaabinjohnedamana MemberComments: 36 Received thanks: 9 edited February 28 Member since: February 2019

    I have done this by using the following lines of code.

    public static function getSubscribedEvents(): array
        {
            return [
                ProductEvents::PRODUCT_LISTING_CRITERIA => 'productListingCriteria',
            ];
        }


        public function productListingCriteria(ProductListingCriteriaEvent $event)
        {

            $event->getCriteria()->addAssociation('customFields');

            $event->getCriteria()->addFilter(
                new RangeFilter('customFields.product_scheduled_from', [RangeFilter::LTE => date(DATE_ATOM)]),
                new RangeFilter('customFields.product_scheduled_to', [RangeFilter::GTE => date(DATE_ATOM)])
            );
            
            return true;
        }

Sign In or Register to comment.