You are here

function uc_attribute_add_to_cart_data in Ubercart 5

Same name and namespace in other branches
  1. 6.2 uc_attribute/uc_attribute.module \uc_attribute_add_to_cart_data()

Stores the customer's choices in the cart.

File

uc_attribute/uc_attribute.module, line 315

Code

function uc_attribute_add_to_cart_data($form_values) {
  if (!isset($form_values['attributes'])) {
    return array(
      'attributes' => array(),
      'model' => null,
    );
  }
  $combination = array();
  foreach ($form_values['attributes'] as $aid => $value) {
    if (is_numeric($value)) {
      $attribute = uc_attribute_load($aid, $form_values['nid'], 'product');
      if ($attribute && ($attribute->display == 1 || $attribute->display == 2)) {
        $combination[$aid] = $value;
      }
    }
  }
  ksort($combination);
  $result = db_query("SELECT model FROM {uc_product_adjustments} WHERE nid = %d AND combination LIKE '%s'", $form_values['nid'], serialize($combination));
  $model = db_result($result);

  // Preserve the 'attributes' key to allow other modules to add to the data field.
  return array(
    'attributes' => $form_values['attributes'],
    'model' => $model,
  );
}