0

I have created product attributes "Available from" and "Available to" with the input types date.

I want to get products from the available dates while searching.

How can I achieve that result?

Could anyone please help me with this?

0

Something like this

https://github.com/DominicWatts/Special/blob/master/Model/Layer.php#L65-L99

            $collection = $this->productCollectionFactory->create();

            $date = new \Zend_Date();

            $collection->addAttributeToFilter(
                'special_from_date',
                [
                    'or' => [
                        0 => [
                            'date' => true,
                            'to' => $date->get('YYYY-MM-dd') . ' 23:59:59'
                        ],
                        1 => [
                            'is' => new \Zend_Db_Expr('null')
                        ],
                    ]
                ],
                'left'
            );

            $collection->addAttributeToFilter(
                'special_to_date',
                [
                    'or' => [
                        0 => [
                            'date' => true,
                            'from' => $date->get('YYYY-MM-dd') . ' 00:00:00'
                        ],
                        1 => [
                            'is' => new \Zend_Db_Expr('null')
                        ],
                    ]
                ],
                'left'
            );
| improve this answer | |
  • Thanks. I will try and update – Siva Jul 22 '19 at 11:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.