how to use "&&" and "||" together in a search condition?

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Ahmad
Posts: 72
Joined: 05 Jul 2017, 15:19

how to use "&&" and "||" together in a search condition?

Post by Ahmad » 14 Feb 2021, 16:10

i want to use "&&" and "||" together in a search condition to get orders, for example:

Code: Select all

$first_expr = array(
	$search->compare('<', 'order.mtime', $limit),
	$search->compare('==', 'order.statuspayment', \Aimeos\MShop\Order\Item\Base::PAY_PENDING),
);
$second_expr = array(
	$search->compare('<', 'order.mtime', $limit),
	$search->compare('==', 'order.statuspayment', \Aimeos\MShop\Order\Item\Base::PAY_CANCELLED),
);
in this example i want to get orders those mtime is lower than a timeLimit "&&" with orders those payment status is PAY_PENDING "or" payment status is PAY_CANCELLED.

how can i do this with a just once search items?

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: how to use "&&" and "||" together in a search condition?

Post by aimeos » 15 Feb 2021, 10:57

The easiest way is using a list of values if they are of the same type:

Code: Select all

$status = [\Aimeos\MShop\Order\Item\Base::PAY_PENDING, \Aimeos\MShop\Order\Item\Base::PAY_CANCELLED];
$search = $manager->filter();
$search->add( $filter->and( [
	$search->compare('<', 'order.mtime', $limit),
	$search->compare('==', 'order.statuspayment', $status),
] );
If you have OR conditions of different types:

Code: Select all

$search->add( $filter->and( [
	$search->compare('<', 'order.mtime', $limit),
	$search->or( [
		$search->compare('==', 'order.statuspayment', \Aimeos\MShop\Order\Item\Base::PAY_PENDING),
		$search->compare('==', 'order.statusdelivery', \Aimeos\MShop\Order\Item\Base::STAT_PENDING),
	] )
] );
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply