function uc_order_condition_has_product_class in Ubercart 7.3
Same name and namespace in other branches
- 8.4 uc_order/uc_order.rules.inc \uc_order_condition_has_product_class()
Checks that the order has the selected combination of product classes.
Parameters
object $order: The order to check.
array $product_classes: An array of strings containing the product classes (node content types) to check against.
bool $required: TRUE to require all product classes be present in the order. FALSE to require at least one be present.
bool $forbidden: TRUE to require that only the listed product classes be present. FALSE to allow products with other classes.
Return value
bool Whether the order meets the specified conditions.
1 string reference to 'uc_order_condition_has_product_class'
- uc_order_rules_condition_info in uc_order/
uc_order.rules.inc - Implements hook_rules_condition_info().
File
- uc_order/
uc_order.rules.inc, line 479 - Hooks and functions for uc_order Rules integration.
Code
function uc_order_condition_has_product_class($order, $product_classes, $required, $forbidden) {
$order_product_classes = array();
foreach ($order->products as $product) {
if (!empty($product->type)) {
// If present, use the product type from {uc_order_products}.data.type.
$order_product_classes[] = $product->type;
}
else {
// Otherwise, use the node type. If the node can't be loaded, ignore
// this product.
$node = node_load($product->nid);
if (!empty($node)) {
$order_product_classes[] = $node->type;
}
}
}
$required_product_classes = array_intersect($product_classes, $order_product_classes);
if ($required) {
$required_check = $required_product_classes == $product_classes;
}
else {
$required_check = (bool) count($required_product_classes);
}
if ($forbidden) {
$forbidden_product_classes = array_diff($order_product_classes, $product_classes);
$forbidden_check = (bool) count($forbidden_product_classes);
}
else {
$forbidden_check = FALSE;
}
return $required_check && !$forbidden_check;
}