summaryrefslogtreecommitdiffstats
path: root/modules/search/includes/commerce_pos_search_status_filter.inc
blob: 8f7753e855cb497ce88922c093e85b65171874fc (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 disabled Commerce entities.
 */
class CommercePosSearchStatusFilter extends SearchApiAbstractAlterCallback {

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

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

}