You are here

function uc_order_product_revive in Ubercart 8.4

Same name and namespace in other branches
  1. 7.3 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.

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

Return value

bool 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()
CheckoutController::checkout in uc_cart/src/Controller/CheckoutController.php
Builds the cart checkout page from available checkout pane plugins.
CheckoutController::review in uc_cart/src/Controller/CheckoutController.php
Allows a customer to review their order before finally submitting it.

File

uc_order/uc_order.module, line 233
Handles all things concerning Ubercart orders.

Code

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

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

  // Load the nodes associated with each order product.
  $nids = [];
  foreach ($products as $product) {
    $nids[] = $product->nid->target_id;
  }
  $nodes = Node::loadMultiple($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->target_id]) && (!$published || $nodes[$product->nid->target_id]
      ->isPublished())) {
      foreach (get_object_vars($nodes[$product->nid->target_id]) as $key => $value) {
        if (!property_exists($product, $key)) {
          $product->{$key} = $value;
        }
      }

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