You are here

function uc_wishlist_view_form in UC Wish List 7

Same name and namespace in other branches
  1. 6 uc_wishlist.pages.inc \uc_wishlist_view_form()

Display a page allowing the customer to view his/her wish list.

2 string references to 'uc_wishlist_view_form'
uc_wishlist_display in ./uc_wishlist.pages.inc
Display a wish list for viewing or altering.
uc_wishlist_user_display in ./uc_wishlist.pages.inc
Display a wishlist in user account page.

File

./uc_wishlist.pages.inc, line 373
Page callback and functions for wish lists.

Code

function uc_wishlist_view_form($form, $form_state, $items, $wid, $own) {
  $form = array();
  $form['items'] = array(
    '#tree' => TRUE,
  );

  // Load each wish list product and add it to the form array.
  foreach ($items as $item) {
    $node = node_load($item->nid);
    $element = array();
    $element['nid'] = array(
      '#type' => 'value',
      '#value' => $node->nid,
    );
    $element['wpid'] = array(
      '#type' => 'value',
      '#value' => $item->wpid,
    );
    $element['module'] = array(
      '#type' => 'value',
      '#value' => 'uc_product',
    );
    if ($own) {
      $element['remove'] = array(
        '#type' => 'checkbox',
      );
    }
    $item->haveqty = 0;
    if (is_array($item->purchase)) {
      $item->haveqty = count($item->purchase);
    }
    $element['title'] = array(
      '#type' => 'item',
      '#markup' => l(filter_xss($node->title, array()), 'node/' . $node->nid),
    );
    $description = uc_product_get_description($item);
    if ($description) {
      $element['description'] = array(
        '#type' => 'item',
        '#markup' => $description,
      );
    }
    $element['#total'] = $item->price * $item->qty;
    $element['data'] = array(
      '#type' => 'hidden',
      '#value' => serialize($item->data),
    );
    $element['wantqty'] = array(
      '#type' => 'textfield',
      '#default_value' => $item->qty,
      '#size' => 5,
      '#maxlength' => 6,
      '#disabled' => $own ? FALSE : TRUE,
    );
    if (!$own) {

      // Disabled elements do not pass their default value.
      $element['wantqty']['#value'] = $item->qty;
    }
    $element['haveqty'] = array(
      '#type' => 'textfield',
      '#default_value' => $item->haveqty,
      '#size' => 5,
      '#maxlength' => 6,
      '#disabled' => TRUE,
    );
    $element['qty'] = array(
      '#type' => 'textfield',
      '#default_value' => $item->qty - $item->haveqty > 0 ? $item->qty - $item->haveqty : 1,
      '#size' => 5,
      '#maxlength' => 6,
    );

    // Checking if uc_stock module is install in the site and
    // prevent user to add product into cart if the stock value of the product
    // is equal to 0.
    // Checking if uc_stock module install in the site.
    if (module_exists('uc_stock')) {

      // If product kit module is installed in the site and wishlist node type
      // is product kit.
      if (module_exists('uc_product_kit') && $node->type == 'product_kit') {

        // Getting the number of products attached with the Product Kit.
        // As there is no stock configuration, so we will check the stock value
        // of the each product of Product Kit.
        // If all products of the Product Kit has stock active, then we allow
        // user to purchase product kit.
        // @var unknown_type .
        $products = $node->products;
        $stock = TRUE;

        // Looping through each product.
        foreach ($products as $product) {

          // Checking stock level of the product.
          if (!uc_stock_level($product->model)) {
            $stock = FALSE;
          }
        }
      }
      else {

        // Getting stock value of the particular product SKU.
        // It will return FALSE, if stock level is not active to product SKU.
        $stock = uc_stock_level($node->model);
      }
      if ($stock) {
        $element['addcart'] = array(
          '#type' => 'submit',
          '#name' => 'addcart-' . $item->wpid,
          '#value' => t('Add to cart'),
        );
      }
      else {
        $element['addcart'] = array(
          '#type' => 'item',
          '#name' => 'addcart-' . $item->wpid,
          '#markup' => t('Out Of Stock'),
        );
      }
    }
    else {
      $element['addcart'] = array(
        '#type' => 'submit',
        '#name' => 'addcart-' . $item->wpid,
        '#value' => t('Add to cart'),
      );
    }
    $form['items'][] = $element;
  }
  $form['wid'] = array(
    '#type' => 'hidden',
    '#value' => $wid,
  );
  if ($own) {
    $form['own'] = array(
      '#type' => 'value',
      '#value' => TRUE,
    );
    $form['update'] = array(
      '#type' => 'submit',
      '#value' => t('Update wish list'),
    );
  }
  return $form;
}