2010-08-10 3 views
2

전날을 만든 Magento의 고객 또는 전날 업데이트 한 고객을 반환하고 싶습니다. 나는 어떤 성공도없이 addFieldToFilter를 가지고 놀려고했다.복잡한 쿼리를 의미하는 날짜

나는 또한 Zend_Db_Select를 조작하려고했지만 성공하지 못했습니다.

그래서 지금은 붙어 있어요!

가 여기 내 시도의 일부입니다 :이 현재로 설정되어 있기 때문에

$customer = Mage::getModel('customer/customer'); 
$customers = $customer 
    ->getCollection() 
    ->getSelect() 
    ->where("updated_at >= ? AND updated_at <= ?",$this->getFrom(), $this->getTo()) 
    ->orWhere("e.created_at >= ? AND e.created_at <= ?", $this->getFrom(), $this->getTo()); 

또는

->addFieldToFilter(
    array(
     array('attribute'=>'updated_at', 'gteq'=>$this->getFrom()), 
     array('attribute'=>'created_at', 'gteq'=>$this->getFrom()) 
    ), 
    '', 
    'left' 
); 

감사

+0

생성 된 SQL 쿼리는 어떤 모양입니까? (var_dump (string) $ customer-> getSelect());) –

답변

2
반드시 필요한 그리고 당신은 정확히이 버전에서 무대 뒤에서 무슨 일을 알고하지 않으면 내가 직접 선택 조작에 대해 권하고 싶습니다

마젠 토.

다음 구문은 날짜가 원하는 범위에 당신이해야 할 필요한 모든 드롭 당신

$c = Mage::getModel('customer/customer') 
->getCollection() 
->addAttributeToFilter(array(    
    array('attribute'=>'updated_at','from'=>'2010-05-12','to'=>'2010-05-30'), 
    array('attribute'=>'created_at','from'=>'2010-05-12','to'=>'2010-05-13') 
)); 

var_dump((string) $c->getSelect()); 
var_dump(count($c)); 

의 까다로운 부분을 처리해야합니다.

->addAttributeToFilter(array(    
    array('attribute'=>'updated_at','from'=>$this->getFrom(),'to'=>$this->getTo()) 
)); 

두 답변이 유용했다 : 앨런과 Silvo에

+0

기술적으로 이것은 정확히 내가 물어 본 것입니다. 감사합니다! 하지만 silvo의 트릭도 유용합니다. 나는 created_at을 무시할 수 있습니다. 사용자가 생성 될 때 updated_at가 자동으로 설정됩니다. – frinux

2

필터 속성과 updated_at 을 사용하기 충분하다 사용자가 생성 된 날짜. 따라서이 필드로 필터링하면 신규 사용자와 신규 사용자는 아니지만 해당 기간에 업데이트 된 사용자를 모두 얻을 수 있습니다. 여기에 지난 24 시간 동안 업데이트 또는 만든 사용자를 찾기 위해 코드입니다 :

$customers = Mage::getModel('customer/customer')->getCollection(); 
$customers->addAttributeToFilter('updated_at', array('gt' => date("Y-m-d H:i:s", time()-60*60*24))); 

foreach($customers as $customer) { 
    //do sth 
} 
0

덕분에, 여기에 내가 쓴 것입니다. 고맙습니다!

관련 문제