You are here

function uc_coupon_session_add in Ubercart Discount Coupons 7.2

Same name and namespace in other branches
  1. 7.3 uc_coupon.module \uc_coupon_session_add()

Adds or updates a coupon code for the current session.

Parameters

$code: The code to add or update.

$op: Specifies the way the code should be handled the next time session codes are validated.

  • 'submit' - If the code fails validation it is removed from the session; otherwise it is retained. A success or failure message is displayed. This is the default operation performed when a customer enters a coupon code manually.
  • 'retain' - The code remains in the session whether or not it passes validation. A success message is displayed the first time the coupon passes. This is useful for codes which are added automatically in response to events occurring before any products have been added to the cart (e.g. via the querystring).
  • 'auto' - The code is removed from the session whether or not it passes validation. However, if it does validate, the corresponding coupon will be considered valid for the current request only. This is useful for modules implementing hook_uc_coupon_revalidate(), which can decide whether or not to add their codes each time the valid coupon cache is rebuilt (e.g. automatic discounts based on additional conditions).
5 calls to uc_coupon_session_add()
hook_uc_coupon_revalidate in ./uc_coupon.api.php
hook_uc_coupon_revalidate().
uc_coupon_form_submit in ./uc_coupon.module
Submit handler for the uc_coupon form.
uc_coupon_init in ./uc_coupon.module
Implements hook_init().
uc_coupon_session_validate in ./uc_coupon.module
Validates all coupons in the current session. The validated coupons are statically cached for each request. The cache is rebuilt the first time this function is called, or every time the cart contents are rebuilt.
uc_coupon_workflow_apply in uc_coupon_workflow/uc_coupon_workflow.rules.inc
Action callback to apply a coupon. This simply adds the coupon to the session; it is validated later.

File

./uc_coupon.module, line 445

Code

function uc_coupon_session_add($code, $op = 'submit') {
  if (!variable_get('uc_coupon_allow_multiple', FALSE)) {
    $_SESSION['uc_coupons'] = array(
      $code => $op,
    );
  }
  else {
    $_SESSION['uc_coupons'][$code] = $op;
  }
}