0

I have created a cron which adds all products which have active special price from one specific category to another, now I want another cron to remove products from that sale category which doesn't have active special price. I am using this collection to get products on sale.

$products = $products->addAttributeToFilter(array(
                            array('attribute'=>'special_from_date','lteq'=>$current_date),
                            array('attribute'=>'special_from_date','eq'=>''),
                            array('attribute'=>'special_from_date','null'=>true)
                        ),'','left')
            ->addAttributeToFilter(array(
                            array('attribute'=>'special_to_date','gteq'=>$current_date),
                            array('attribute'=>'special_to_date','eq'=>''),
                            array('attribute'=>'special_to_date','null'=>true)
                        ),'','left');

$products->getSelect()->group('e.entity_id');

Now I changed the condition to

$products = $products->addAttributeToFilter(array(
                            array('attribute'=>'special_from_date','gteq'=>$current_date),
                            array('attribute'=>'special_from_date','neq'=>''),
                            array('attribute'=>'special_from_date','null'=>false)
                        ),'','left')
            ->addAttributeToFilter(array(
                            array('attribute'=>'special_to_date','lteq'=>$current_date),
                            array('attribute'=>'special_to_date','neq'=>''),
                            array('attribute'=>'special_to_date','null'=>false)
                        ),'','left');

But id doens't work

0

Ok I got it to work, here is the modified code

 $products = $products->addAttributeToFilter(array(
                            array('attribute'=>'special_from_date','gteq'=>$current_date),
                            array('attribute'=>'special_to_date','lteq'=>$current_date)

                        ),'','left')
            ->addAttributeToFilter(array(
                            array('attribute'=>'special_from_date','neq'=>''),
                            array('attribute'=>'special_to_date','neq'=>'')

                        ),'','left')
            ->addAttributeToFilter(array(


                            array('attribute'=>'special_to_date','notnull'=>true),
                            array('attribute'=>'special_from_date','notnull'=>true)
                        ),'','left');

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.