You are here

interface CouponCodeGeneratorInterface in Commerce Core 8.2

Generates coupon codes (unique, machine readable identifiers for coupons).

Hierarchy

Expanded class hierarchy of CouponCodeGeneratorInterface

All classes that implement CouponCodeGeneratorInterface

1 file declares its use of CouponCodeGeneratorInterface
CouponGenerateForm.php in modules/promotion/src/Form/CouponGenerateForm.php

File

modules/promotion/src/CouponCodeGeneratorInterface.php, line 8

Namespace

Drupal\commerce_promotion
View source
interface CouponCodeGeneratorInterface {

  /**
   * Validates the given pattern for the specified quantity.
   *
   * @param \Drupal\commerce_promotion\CouponCodePattern $pattern
   *   The pattern.
   * @param int $quantity
   *   The quantity.
   *
   * @return bool
   *   TRUE if the pattern is valid, FALSE otherwise.
   */
  public function validatePattern(CouponCodePattern $pattern, $quantity = 1);

  /**
   * Generates coupon codes.
   *
   * Ensures uniqueness, which means that depending on the pattern, the
   * number of generated codes might be smaller than requested.
   * This can be mitigated by using a pattern with a prefix/suffix.
   *
   * @param \Drupal\commerce_promotion\CouponCodePattern $pattern
   *   The pattern.
   * @param int $quantity
   *   The quantity.
   *
   * @return string[]
   *   The generated coupon codes.
   */
  public function generateCodes(CouponCodePattern $pattern, $quantity = 1);

}

Members

Namesort descending Modifiers Type Description Overrides
CouponCodeGeneratorInterface::generateCodes public function Generates coupon codes. 1
CouponCodeGeneratorInterface::validatePattern public function Validates the given pattern for the specified quantity. 1