protected function NumberOfProductsCondition::doEvaluate in Ubercart 8.4
Checks that the order has the selected number of products.
Parameters
\Drupal\uc_order\OrderInterface $order: The order.
\Drupal\node\NodeInterface[] $products: The order products.
int $count: The count.
string $operation: The order.
Return value
bool TRUE if the order has the selected number of products.
File
- uc_order/
src/ Plugin/ Condition/ NumberOfProductsCondition.php, line 71
Class
- NumberOfProductsCondition
- Provides 'Count of order products' condition.
Namespace
Drupal\uc_order\Plugin\ConditionCode
protected function doEvaluate(OrderInterface $order, array $products, $count, $operation) {
$totals = [
'all' => 0,
];
$total = 0;
foreach ($order->products as $product) {
$totals['all'] += $product->qty;
if (isset($totals[$product->nid])) {
$totals[$product->nid] += $product->qty;
}
else {
$totals[$product->nid] = $product->qty;
}
}
if (in_array('all', $products)) {
$total = $totals['all'];
}
else {
foreach ($products as $product) {
if (isset($totals[$product])) {
$total += $totals[$product];
}
}
}
return $this
->compareComparisonOptions($total, $operation, $count);
}