2017-07-12 17 views
0

私は現在Shopware Pluginを作成しています。 ShopwareはDoctrine for Database操作を使用します。Doctrine where Query-論理的順序 - Where(条件1と[条件2または条件3])

私はこのような教義文を書きたいと思います:

Where(condition1 and [condition2 or condition3]) 

は、コード内の私のコメントを参照してください。

$builder = Shopware()->Models()->createQueryBuilder(); 
$builder->select([ 
     'orders', 
     'details', 
     'customer', 
     'shipping', 
     'billing' 
]); 
$builder->from('Shopware\Models\Order\Order', 'orders'); 
$builder->leftJoin('orders.details', 'details') 
     ->leftJoin('orders.customer', 'customer') 
     ->leftJoin('orders.shipping', 'shipping') 
     ->leftJoin('orders.billing', 'billing'); 


//--> Here I would like to write an or statement. 
// So that i get all the orders by 
// where(customers.email = email) and [(shipping.zipCode = zip) or (billing.zipcode = zip)] 
$builder->where('customer.email = :email'); 
$builder->andWhere('(shipping.zipCode = :zipCode) orWhere (billing.zipCode = :zipCode)'); 

$builder->setParameter('email', $email); 
$builder->setParameter('zipCode', $zip); 
$builder->orderBy('orders.id', 'DESC'); 

$order = $builder->getQuery()->getResult($this->getResultMode()); 

答えて

2

使用:

$builder->where('customer.email = :email'); 
$builder->andWhere('(shipping.zipCode = :zipCode OR billing.zipCode = :zipCode)') 

別に単一の条件から、where条件

+0

はいの任意形態をとります。ありがとう。それは働いている。 私はその答えに非常に満足しています:) – basti500