You are here

function uc_wishlist_uc_order in UC Wish List 7

Implements hook_uc_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 465
Allows users to create public shopping/wish lists.

Code

function uc_wishlist_uc_order($op, $order, $arg2) {
  if ($op == 'update') {
    if (uc_order_status_data($order->order_status, 'state') != 'in_checkout' || uc_order_status_data($arg2, 'state') == 'in_checkout' || uc_order_status_data($arg2, 'state') == 'canceled') {
      return;
    }
    $o = $order;
    foreach ($o->products as $key => $item) {
      if (isset($item->data['wid']) && isset($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' => REQUEST_TIME,
        );
        for ($i = 0; $i < $item->qty; $i++) {
          $witem->purchase[] = $purchase;
        }
        uc_wishlist_update_purchase($witem);
      }
    }
  }
}