summaryrefslogtreecommitdiffstats
path: root/modules/search/modules/order/includes/commerce_pos_order_search_pos_filter.inc
blob: aa1999759964d1158713ce3353e8bdd26cb789a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php

/**
 * Data alteration callback that filters out non-POS Commerce orders.
 */
class CommercePosOrderSearchPosFilter extends SearchApiAbstractAlterCallback {

  /**
   * @param SearchApiIndex $index
   * @return bool
   */
  public function supportsIndex(SearchApiIndex $index) {
    return in_array($index->item_type, array('commerce_order'));
  }

  /**
   * Exclude items that doesn't have a product reference field attached to
   * the bundle.
   */
  public function alterItems(array &$items) {
    $statuses = commerce_pos_order_statuses();
    foreach ($items as $id => $item) {
      if (empty($statuses[$item->status])) {
        unset($items[$id]);
      }
    }
  }
}