You are here

function uc_wishlist_order in UC Wish List 6

Implements Ubercart hook_order.

When the status of an order is changed to pending, then the order is scanned for items from wish lists (that contain wid and wpid data fields). If items are found, then their records in uc_wishlist_products are updated with the additional purchases.

File

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

Code

function uc_wishlist_order($op, &$arg1, $arg2) {
  if ($op == 'update') {
    if (uc_order_status_data($arg1->order_status, 'state') != 'in_checkout' || uc_order_status_data($arg2, 'state') == 'in_checkout' || uc_order_status_data($arg2, 'state') == 'canceled') {
      return;
    }
    $o = $arg1;
    foreach ($o->products as $key => $item) {
      if ($item->data['wid'] && $item->data['wpid'] && !isset($item->data['wset'])) {
        $wid = $item->data['wid'];
        $wpid = $item->data['wpid'];
        $w = uc_wishlist_load($wid);
        $witem = uc_wishlist_get_product($wpid);
        $purchase = array(
          'order_id' => $item->order_id,
          'order_product_id' => $item->order_product_id,
          'uid' => $o->uid,
          'date' => time(),
        );
        for ($i = 0; $i < $item->qty; $i++) {
          $witem->purchase[] = $purchase;
        }
        uc_wishlist_update_purchase($witem);
      }
    }
  }
}