diff --git a/uc_attribute/uc_attribute.rules.inc b/uc_attribute/uc_attribute.rules.inc index f121ecd..6c04886 100644 --- a/uc_attribute/uc_attribute.rules.inc +++ b/uc_attribute/uc_attribute.rules.inc @@ -26,48 +26,43 @@ function uc_attribute_rules_condition_info() { } /** - * Returns TRUE if a product in the given order has the selected option. + * Returns TRUE if the product from a given order has the selected option. * * @see uc_attribute_condition_ordered_product_option_form() */ -function uc_attribute_condition_ordered_product_option($order) { - $result = FALSE; - - $match = unserialize($settings['attribute_option']); +function uc_attribute_condition_ordered_product_option($product, $option) { + if (empty($product->data['attributes'])) { + return FALSE; + } - foreach ($order->products as $product) { - if (!isset($product->data['attributes'])) { - continue; - } + $attributes = $product->data['attributes']; - $attributes = $product->data['attributes']; + // Once the order is made, the attribute data is changed to just the names. + // If we can't find it by ID, check the names. + if (is_int(array_shift(array_keys($attributes)))) { + foreach ($attributes as $options) { + // Only checkboxes are stored in an array, so fix up other option types. + if (!is_array($options)) { + $options = array($options); + } - // Once the order is made, the attribute data is changed to just the names. - // If we can't find it by ID, check the names. - if (is_int(key($attributes))) { - if (in_array($settings['attribute_option'], $attributes)) { - $result = TRUE; - break; + if (in_array($option, $options)) { + return TRUE; } } - else { - // Load the attribute data once, only if we need it. - if (!isset($option)) { - if ($option = uc_attribute_option_load($settings['attribute_option'])) { - $attribute = uc_attribute_load($option->aid); - } - } + } + else { + // Load the attribute data once, only if we need it. + if ($option = uc_attribute_option_load($option)) { + $attribute = uc_attribute_load($option->aid); + } - if ($attribute) { - if (isset($attributes[$attribute->name]) && $attributes[$attribute->name] == $option->name) { - $result = TRUE; - break; - } - } + if (isset($attribute) && isset($attributes[$attribute->name]) && $attributes[$attribute->name] == $option->name) { + return TRUE; } } - return $result; + return FALSE; } /**