/** * Returns an array of all discountable membership ids. */ function _cividiscount_get_discounted_membership_ids() { return _cividiscount_get_items_from_discounts(_cividiscount_get_discounts(), 'memberships'); }
/** * Returns an array of all discountable payment processor type ids. */ function _cividiscount_get_discounted_paymentProcessor_type_ids() { return _cividiscount_get_items_from_discounts(_cividiscount_get_discounts(), 'pp_types'); }
/** * @param string $discountCode * @param array $price_set_amount * @param $cost */ protected function apply_discount($discountCode, &$price_set_amount, &$cost, $event_id) { //need better way to determine if cividiscount installed $autoDiscount = array(); $sql = "select is_active from civicrm_extension where name like 'CiviDiscount%'"; $dao = CRM_Core_DAO::executeQuery($sql, ''); while ($dao->fetch()) { if ($dao->is_active != '1') { return; } } $discounted_priceset_ids = _cividiscount_get_discounted_priceset_ids(); $discounts = _cividiscount_get_discounts(); $stat = FALSE; foreach ($discounts as $key => $discountValue) { if ($key == $discountCode) { $events = CRM_Utils_Array::value('events', $discountValue); $evt_ids = implode(",", $events); if ($evt_ids == "0" || strpos($evt_ids, $event_id)) { $event_match = TRUE; } //check priceset is_active if ($discountValue['active_on'] != NULL) { $today = date('Y-m-d'); $diff1 = date_diff(date_create($today), date_create($discountValue['active_on'])); if ($diff1->days > 0) { $active1 = TRUE; } } else { $active1 = TRUE; } if ($discountValue['expire_on'] != NULL) { $diff2 = date_diff(date_create($today), date_create($discountValue['expire_on'])); if ($diff2->days > 0) { $active2 = TRUE; } } else { $active2 = TRUE; } } if ($discountValue['is_active'] == TRUE && ($discountValue['count_max'] == 0 || $discountValue['count_max'] > $discountValue['count_use']) && $active1 == TRUE && $active2 == TRUE && $event_match == TRUE) { foreach ($price_set_amount as $key => $price) { if (array_search($price['price_field_value_id'], $discounted_priceset_ids) != NULL) { $discounted = _cividiscount_calc_discount($price['line_total'], $price['label'], $discountValue, $autoDiscount, "USD"); $price_set_amount[$key]['line_total'] = $discounted[0]; $cost += $discounted[0]; $price_set_amount[$key]['label'] = $discounted[1]; } else { $cost += $price['line_total']; } } $stat = TRUE; } } return $stat; }