You are here

function uc_wishlist_get_contents in UC Wish List 8

Same name and namespace in other branches
  1. 6 uc_wishlist.module \uc_wishlist_get_contents()
  2. 7 uc_wishlist.module \uc_wishlist_get_contents()

Get the items in a specified wish list.

2 calls to uc_wishlist_get_contents()
UCWishlistController::myWishlist in src/Controller/UCWishlistController.php
UCWishlistController::viewWishlist in src/Controller/UCWishlistController.php

File

./uc_wishlist.module, line 500
Allows users to create public shopping/wish lists.

Code

function uc_wishlist_get_contents($wid = NULL) {
  $wid = $wid ? $wid : uc_wishlist_get_wid();
  if (!$wid || !is_numeric($wid)) {
    return FALSE;
  }
  $items = [];
  $wishlist_manager = \Drupal::service('uc_wishlist.manager');
  $res = $wishlist_manager
    ->selectWishlistProducts($wid);

  // dpm($res);
  // Iterating through the array.
  foreach ($res as $item) {
    $product = Node::load($item->nid);
    $item->model = $product
      ->get('model')
      ->getValue();
    $item->price = $product
      ->get('price')
      ->getValue();

    // $item->price = $product->get('sell_price');.
    $item->weight = $product
      ->get('weight')
      ->getValue();

    // $item->weight_units = $product->get('weight_units');.
    $item->shippable = $product
      ->get('shippable')
      ->getValue();
    $item->data = unserialize($item->data);
    $item->module = $item->data['module'];
    $item->purchase = unserialize($item->purchase);
    $item->options = [];
    $item->qty = $item->qty;
    $item->haveqty = 1;

    // Add wishlist id data.
    $item->data['wid'] = $item->wid;
    $item->data['wpid'] = $item->wpid;
    $items[] = $item;
  }
  return $items;
}