1

这就是我所拥有的,但它获得了第一个订单 ID

/**      
 * @param string, datetime UTC
 * @param string, datetime UTC
 * @return Mage_Customer_Model_Resource_Customer_Collection         
 */
public function filterOrderId($from, $to) 
{
    $this->addAttributeToSelect(array('first_name', 'last_name', 'gender', 'dob'));
    $this->joinTable(
        array('o' => 'sales/order_grid'), 
        'customer_id=entity_id', 
        array(
            'order_id'                => 'increment_id',
            'grand_total'             => 'grand_total'
        ),
        array(                
            'created_at'              => array('from'=>$from,'to'=>$to),
            'status'                  => array("nin"=>array('canceled', 'rejected', 'closed', 'complete'))
        ),                     
        'inner'  
    );

    $this->getSelect()->group('o.customer_id');
    //$this->addExpressionAttributeToSelect('max_id', 'MAX({{entity_id}})', 'entity_id'); //this does not work
    //$this->setOrder('max_id', 'desc');

    return $this;
}

我想我需要在联接中添加一个子查询,但我不知道该怎么做。

4

0 回答 0