2017-02-15 72 views
0

我已經寫了一個代碼來從表order_address中檢索客戶的城市,電子郵件,街道和其他細節這裏的問題是每個訂單有兩行,其中一個排address_typeshipping,另一個是billing。當我查詢系統是從第二行自動檢索數據是計費。我需要地址類型爲shipping的行的數據。如何實現這一目標?任何人都可以讓我知道如何使用where子句在這裏過濾只有address_type =「shipping」行的行。如何添加一個where子句與左連接

$select = $collection->getSelect(); 
      $select->joinLeft(array('payment' => $collection->getTable('sales/order_payment')), 'payment.parent_id=main_table.entity_id', array('payment_method' => 'method')); 
      $select->joinLeft(array('email' => $collection->getTable('sales/order_address')), 'email.parent_id=main_table.entity_id', array('customer_email' => 'email','customer_phone' => 'telephone','shipping_street' => 'street','shipping_city' => 'city','shipping_postcode' => 'postcode','shipping_region' => 'region','shipping_country' => 'country_id')); 
      $select->join('sales_flat_order_item', '`sales_flat_order_item`.order_id=`main_table`.entity_id', array('skus' => new Zend_Db_Expr('group_concat(`sales_flat_order_item`.sku SEPARATOR ", ")'))); 
      $select->group('main_table.entity_id'); 
     } 

回答

1

試試下面的代碼希望這有助於。我剛剛在第3行添加了email.address_type = shipping到您的代碼。

$select = $collection->getSelect(); 
      $select->joinLeft(array('payment' => $collection->getTable('sales/order_payment')), 'payment.parent_id=main_table.entity_id', array('payment_method' => 'method')); 
      $select->joinLeft(array('email' => $collection->getTable('sales/order_address')), 'email.parent_id=main_table.entity_id AND email.address_type="shipping"', array('customer_email' => 'email','customer_phone' => 'telephone','shipping_street' => 'street','shipping_city' => 'city','shipping_postcode' => 'postcode','shipping_region' => 'region','shipping_country' => 'country_id')); 
      $select->join('sales_flat_order_item', '`sales_flat_order_item`.order_id=`main_table`.entity_id', array('skus' => new Zend_Db_Expr('group_concat(`sales_flat_order_item`.sku SEPARATOR ", ")'))); 
      $select->group('main_table.entity_id'); 
     } 
+0

這使我找到了我正在尋找的數據。謝謝:) –

+0

最受歡迎@AkshayVasu – user247217