2

I try to do a list of the products which have a special price defined. So I created a widget like that :

enter image description here

But even the products which have their "Date To" that is passed are shown.

Is it possible to add a condition which always takes the current date to filter these products?

  • Go to the product and edit special price in advanced pricing option. And check if this help – Martins Apr 7 '17 at 7:39
  • I don't want to remove the special price manually. I want that if the end date is passed, the product is not shown in the list. Like that, I still have the previous special price if I want to set it again. – LawCha Apr 7 '17 at 8:35
1

I created an extension which lets you list on products on special via a widget

https://github.com/DominicWatts/Special

Plus has controller page

But the widget functionality should be what you need

https://github.com/DominicWatts/Special/blob/ed3ebef80df4f8c2364154d4c94f3a712b5c9c12/Block/Widget/Special.php#L84-L121

        $date = new \Zend_Date();

        $collection = $this->_addProductAttributesAndPrices($collection)
            ->addStoreFilter()
            ->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'
            )
            ->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'
            )
            ->addAttributeToFilter('special_price', ['gt' => '0.1'])
            ->addAttributeToFilter('price', ['gt' => '0.1'])
            ->addAttributeToFilter('special_price', ['lt' => new \Zend_Db_Expr('at_price.value')])
            ->addAttributeToSort('created_at', 'desc')
-1

I didn't find a fix so a created a PHP script to set to NULL the special prices when their end date is passed.

https://fr.scribd.com/document/346652446/Update-Actions

https://pastebin.com/m1YNTSrs (edit: scribd isn't free, so here's a pastebin)

I call this script with a cron every 15 minutes.

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.