생성 된 날짜별로 필터링하고 “어제” 생성 된 항목을 필터링하려는 사용자 지정 컬렉션이 있습니다.
수집 품목
//dates are set in controller using
setCreatedTime(Mage::getModel('core/date')->gmtDate());
어제 작성 (작동하지 않음)
//3 products items Yesterday
//below filtering outputs incorrect entries
$collection = Mage::getModel('things/things')->getCollection();
시도했지만 잘못된 항목을 출력합니다.
//thought strtotime('yesterday') would work..
$collection->addFieldToFilter('created_time', array('gt' => Mage::getModel('core/date')->date('Y-m-d H:i:s', strtotime('yesterday'))));
$collection->addFieldToFilter('created_time', array('gt' => Mage::getModel('core/date')->date('Y-m-d H:i:s', strtotime('-1 day'))));
$collection->addFieldToFilter('created_time', array('from'=> strtotime('-1 day', time()),'to'=> time(),'datetime' => true));
$fromDate = date('Y-m-d H:i:s', strtotime($fromDate));
$toDate = date('Y-m-d H:i:s', strtotime($toDate));
$collection->addFieldToFilter('created_time', array('from'=>$fromDate, 'to'=>$toDate));
오늘 (현재) 작성 (작동)
//5 products items today with timestamp 2016-05-01 05:22:53
//below filtering outputs correct entries
$collection = Mage::getModel('things/things')->getCollection();
$collection->addFieldToFilter('created_time', array('gt' => Mage::getModel('core/date')->date('Y-m-d H:i:s', strtotime('today'))));
지난 주에 작성 (작업)
//23 products items with timestamps for this week
//below filtering outputs correct entries
$collection = Mage::getModel('things/things')->getCollection();
$collection->addFieldToFilter('created_time', array('gt' => Mage::getModel('core/date')->date('Y-m-d H:i:s', strtotime('-1 week'))));
답변
@Ashvin 답변에 추가하려면 ..
지난 1 시간 이내에 작성된 항목이 있습니다.
$things = Mage::getModel('things/things')->getCollection();
$things->addFieldToFilter('things_type', 'view');
$fromDate = date('Y-m-d H:i:s', strtotime('-1 hour'));
$toDate = date('Y-m-d H:i:s', strtotime(now()));
$things->addFieldToFilter('created_time', array(
'from' => $fromDate,
'to' => $toDate,
'date' => true,
));
return count($things);
어제 어떻게 항목을 만들 었는지;
$now = Mage::getModel('core/date')->timestamp(time());
$dateStart = date('Y-m-d' . ' 00:00:00', $now);
$dateEnd = date('Y-m-d' . ' 23:59:59', $now);
$things = Mage::getModel('things/things')->getCollection();
$things->addFieldToFilter('things_type', 'view');
$things->addFieldToFilter('created_time', array('from' => $dateStart, 'to' => $dateEnd));
return count($things);
답변
우리는 그것을 어떻게 해결합니까? 단순한. 달리 요청하지 않는 한 지난 24 시간 동안 주문 그리드에 표시되는 주문의 양을 제한합니다.
예 :
-app / code / core / Mage / Adminhtml / Block / Sales / Order / Grid.php 파일을 다음 위치에 복사하십시오.
app / code / local / Mage / Adminhtml / Block / Sales / Order / Grid.php
여기에서 복사-붙여 넣기 기능을 편집하십시오.
protected function _prepareCollection() {
$collection = Mage::getResourceModel($this->_getCollectionClass());
######################## FILTER BY LAST DAY ######################
$now = Mage::getModel('core/date')->timestamp(time());
$filter = $this->getParam($this->getVarNameFilter(), null); //important - check for other requested grid-filters before filtering today's orders
$dateStart = date('Y-m-d' . ' 00:00:00', $now);
$dateEnd = date('Y-m-d' . ' 23:59:59', $now);
$postData = Mage::app()->getRequest()->getPost();
if (empty($filter)) {
$collection->addFieldToFilter('`main_table`.created_at', array('from' => $dateStart, 'to' => $dateEnd));
}
##################################################################
$collection->getSelect()->group('entity_id');
$this->setCollection($collection);
return $this;
}
귀하의 질문에 대한 더 많은 코드를 사용하십시오 … (오늘, 어제, 주, 시간 등)