I'm trying to filter the data collection from 4 hours to now and I have the below code but its not working.
public function getWishlistProduct($wishlistid){
$to = date("Y-m-d h:i:s");
$from = strtotime('-4 hours', strtotime($to));
$from = date('Y-m-d h:i:s', $from);
$wishlist= $this->getCollection()->addFieldToFilter('wishlist_id', ['eq'=>$wishlistid])
->addFieldToFilter('added_at', array('from'=>$from, 'to'=>$to));
return $wishlist;
}
Could anyone please help?
-
Its showing HTTP ERROR 500MagentoDev– MagentoDev2020年06月18日 16:42:01 +00:00Commented Jun 18, 2020 at 16:42
1 Answer 1
I have solved this issue by using the time() function and the updated code as below. Hope it may helpful to someone:
public function getWishlistProduct($wishlistid){
$time = time();
$to = date('Y-m-d H:i:s', $time);
$lastTime = $time - 14400; //60*60*4
$from = date('Y-m-d H:i:s', $lastTime);
$wishlist= $this->getCollection()->addFieldToFilter('wishlist_id', ['eq'=>$wishlistid])
->addFieldToFilter('added_at', array('from'=>$from, 'to'=>$to));
return $wishlist;
}
answered Jun 18, 2020 at 17:09
MagentoDev
5348 silver badges43 bronze badges
-
1sound good , Or above my code why showing 500 error because i am missed some column(,) and i am not sure
$from = date('Y-m-d H:i:s', strtotime('-4 hour')); $toDate = date('Y-m-d H:i:s',$from); $wishlist= $this->getCollection()->addFieldToFilter('wishlist_id', ['eq'=>$wishlistid]) ->addFieldToFilter('added_at', array('from'=>$from, 'to'=>$toDate,'date'=>true)); return $wishlist;Mohit Patel– Mohit Patel2020年06月18日 17:18:59 +00:00Commented Jun 18, 2020 at 17:18 -
@MohitPatel, Can you please check this magento.stackexchange.com/questions/315373/… and help me out.MagentoDev– MagentoDev2020年06月19日 02:24:42 +00:00Commented Jun 19, 2020 at 2:24
Explore related questions
See similar questions with these tags.
default