You are here

function uc_order_product_revive in Ubercart 7.3

Same name and namespace in other branches
  1. 8.4 uc_order/uc_order.module \uc_order_product_revive()

Merge fields from their associated nodes into a set of order products.

Parameters

$products: An array of order_products.

$published: TRUE to load only published nodes, FALSE to load all nodes.

Return value

TRUE if the merge was successful for all products in the set. FALSE otherwise (i.e. if the associated product node no longer exists).

2 calls to uc_order_product_revive()
uc_cart_checkout in uc_cart/uc_cart.pages.inc
Displays the cart checkout page built of checkout panes from enabled modules.
uc_cart_checkout_review in uc_cart/uc_cart.pages.inc
Allows a customer to review their order before finally submitting it.

File

uc_order/uc_order.module, line 1207

Code

function uc_order_product_revive($products, $published = TRUE) {

  // Allow invocation for a single product.
  if (!is_array($products)) {
    $products = array(
      $products,
    );
  }

  // Load the nodes associated with each order product.
  $nids = array();
  foreach ($products as $product) {
    $nids[] = $product->nid;
  }
  $nodes = node_load_multiple($nids);

  // Merge in fields from any nodes that still exist (but don't override order
  // product fields that are already set).
  $return = TRUE;
  foreach ($products as &$product) {
    if (!empty($nodes[$product->nid]) && (!$published || $nodes[$product->nid]->status == NODE_PUBLISHED)) {
      foreach ($nodes[$product->nid] as $key => $value) {
        if (!isset($product->{$key})) {
          $product->{$key} = $value;
        }
      }

      // Order products are always variants.
      $product->variant = TRUE;
    }
    else {
      $return = FALSE;
    }
  }
  return $return;
}