0

I'm currently writing a Shopware Plugin. Shopware uses Doctrine for Database operations.

I would like to write a doctrine statement like this:

Where(condition1 and [condition2 or condition3])

See my comment in the code.

$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());
basti500
  • 600
  • 4
  • 20

1 Answers1

2

Use:

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

Aside from single conditions, where takes any form of conditions

Alex Tartan
  • 6,736
  • 10
  • 34
  • 45