123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- <?php
- function hook_uc_coupon_usage_alter(&$usage, $cid, $uid) {
-
- $rows = db_query('SELECT code, uses FROM {extra_coupon_usage} WHERE cid = :cid', array(':cid' => $cid));
- foreach ($rows as $row) {
- if (isset($usage[$row->code])) {
- $usage[$row->code] += $row->uses;
- }
- else {
- $usage[$row->code] = $row->uses;
- }
- }
- }
- function hook_uc_coupon_actions($coupon) {
- $actions = array();
-
- if (user_access('mark coupon as used')) {
- $actions[] = array(
- 'url' => 'admin/store/coupons/mark-as-used/' . $coupon->cid,
- 'icon' => drupal_get_path('module', 'mymodule') . 'mark_as_used.gif',
- 'title' => t('Mark coupon: @name as used', array('@name' => $coupon->name)),
- );
- };
- return $actions;
- }
- function hook_uc_coupon_revalidate($order) {
-
- $gotwidget = FALSE;
- $gotdoohickey = FALSE;
- foreach ($order->products as $product) {
- $node = node_load($product->nid);
- if ($node) {
- if ($node->type == 'widget') {
- $gotwidget = TRUE;
- }
- elseif ($node->type == 'doohickey') {
- $gotdoohickey = TRUE;
- }
- if ($gotwidget && $gotdoohickey) {
- uc_coupon_session_add('JACKPOT', 'auto');
- return;
- }
- }
- }
- }
- function hook_uc_coupon_apply($coupon) {
-
-
-
- global $user;
- if ($coupon->cid == 99 && $user->uid != 0) {
- $roles = $user->roles + array(99 => 'My Special Role');
- user_save($user, array('roles' => $roles));
- }
- }
- function hook_uc_coupon_remove($coupon) {
-
- global $user;
- if ($coupon->cid == 99 && $user->uid != 0) {
- $roles = $user->roles;
- $key = array_search('My Special Role', $roles);
- if ($key !== FALSE) {
- unset($roles[$key]);
- user_save($user, array('roles' => $roles));
- }
- }
- }
- function hook_uc_coupon_validate(&$coupon, $order, $account) {
-
- if (!empty($order->data['coupons'])) {
- foreach (array_keys($order->data['coupons']) as $code) {
- $other = uc_coupon_find($code);
- $other_listed = !empty($coupon->data['combinations']) && in_array($other->cid, $coupon->data['combinations']);
- $this_ok = (isset($coupon->data['negate_combinations']) xor $other_listed);
- $this_listed = !empty($other->data['combinations']) && in_array($coupon->cid, $other->data['combinations']);
- $other_ok = (isset($other->data['negate_combinations']) xor $this_listed);
- if (!$this_ok || !$other_ok) {
- return t('This coupon combination is not allowed.');
- }
- }
- }
-
- if ($coupon->max_uses > 0 && !empty($coupon->usage['codes'][$coupon->code]) && $coupon->usage['codes'][$coupon->code] >= $coupon->max_uses) {
- return t('This coupon has reached the maximum redemption limit.');
- }
-
- if ($account && isset($coupon->data['max_uses_per_user']) && $coupon->usage['user'] >= $coupon->data['max_uses_per_user']) {
- return t('This coupon has reached the maximum redemption limit.');
- }
-
- if ($account && isset($coupon->data['users'])) {
- if (in_array("$account->uid", $coupon->data['users'], TRUE) xor !isset($coupon->data['negate_users'])) {
- return t('Your user ID is not allowed to use this coupon.');
- }
- }
-
- if ($account && isset($coupon->data['roles'])) {
- $role_found = FALSE;
- foreach ($coupon->data['roles'] as $role) {
- if (in_array($role, $account->roles)) {
- $role_found = TRUE;
- break;
- }
- }
- if ($role_found xor !isset($coupon->data['negate_roles'])) {
- return t('You do not have the correct permission to use this coupon.');
- }
- }
- }
|