function uc_order_condition_has_products in Ubercart 8.4
Same name and namespace in other branches
- 5 uc_order/uc_order_workflow.inc \uc_order_condition_has_products()
- 6.2 uc_order/uc_order.ca.inc \uc_order_condition_has_products()
- 7.3 uc_order/uc_order.rules.inc \uc_order_condition_has_products()
Checks that the order has the selected combination of products.
File
- uc_order/
uc_order.rules.inc, line 255 - Rules integration for order-related entity events, conditions, and actions.
Code
function uc_order_condition_has_products($order, $products, $required, $forbidden) {
$order_products = [];
foreach ($order->products as $product) {
$order_products[] = $product->model;
}
$required_products = array_intersect($products, $order_products);
if ($required) {
$required_check = $required_products == $products;
}
else {
$required_check = (bool) count($required_products);
}
if ($forbidden) {
$forbidden_products = array_diff($order_products, $products);
$forbidden_check = (bool) count($forbidden_products);
}
else {
$forbidden_check = FALSE;
}
return $required_check && !$forbidden_check;
}