Overview

Packages

  • blesta
    • app
      • controllers
      • models
    • components
      • auth
        • ldap
        • motp
        • oath
      • delivery
        • interfax
        • postal
          • methods
      • download
      • email
      • events
      • exchange
        • rates
          • currency
            • layer
          • fixer
          • open
            • exchange
              • rates
          • x
            • rates
      • gateway
        • payments
      • gateways
      • invoice
        • delivery
        • templates
          • perforated
            • invoice
          • quickbooks
            • invoice
          • templates
            • default
      • modules
      • net
        • amazon
          • s3
        • http
        • net
          • geo
            • ip
      • plugins
      • reports
        • aging
          • invoices
        • client
          • data
            • portability
        • custom
          • report
        • invoice
          • creation
        • package
          • revenue
        • tax
          • liability
        • transactions
          • applied
          • received
      • security
      • session
        • cart
      • settingscollection
      • upgrades
        • tasks
      • upload
      • vcard
    • core
      • Automation
        • Tasks
          • Common
          • Task
        • Type
          • Common
          • Cron
      • Pricing
        • ItemComparator
        • MetaItem
        • Modifier
          • Type
            • Description
              • Type
                • Discount
                • Option
                • Service
                • Tax
            • Discount
            • Price
            • Proration
        • Presenter
          • Build
            • Invoice
            • InvoiceData
            • Options
            • Service
            • ServiceChange
            • ServiceData
          • Collection
          • Format
            • Fields
            • Type
              • Discount
              • Item
              • Option
              • Options
              • Package
              • Pricing
              • Service
              • Tax
          • Items
            • Invoice
            • Service
          • Type
      • ServiceProviders
      • Util
        • Captcha
          • Captchas
          • Common
        • Common
          • Traits
        • Events
          • Common
          • Handlers
          • Observers
        • Filters
          • Common
        • GeoIp
        • Input
          • Fields
            • Common
        • Tax
        • Widgets
    • helpers
      • currency
        • format
      • data
        • structure
          • array
          • string
      • text
        • parser
      • widget
        • client
  • minPHP
    • helpers
      • color
      • data
        • structure
  • None
  • PHP

Classes

  • Accounts
  • Actions
  • ApiKeys
  • Backup
  • CalendarEvents
  • ClientGroups
  • Clients
  • Companies
  • Contacts
  • Countries
  • Coupons
  • CouponTerms
  • CronTasks
  • Currencies
  • EmailGroups
  • Emails
  • EmailVerifications
  • Encryption
  • GatewayManager
  • Invoices
  • InvoiceTemplateManager
  • Languages
  • Logs
  • Marketplace
  • MessageGroups
  • Messages
  • MessengerManager
  • ModuleClientMeta
  • ModuleManager
  • ModuleTypes
  • Navigation
  • PackageGroups
  • PackageOptionGroups
  • PackageOptions
  • Packages
  • Payments
  • Permissions
  • PluginManager
  • Pricings
  • ReportManager
  • ServiceChanges
  • ServiceInvoices
  • Services
  • Settings
  • Staff
  • StaffGroups
  • States
  • SystemEvents
  • Taxes
  • Themes
  • Transactions
  • Users
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated

Class Coupons

Coupon management

Model
Extended by AppModel uses Blesta\Core\Util\Common\Traits\Container
Extended by Coupons
Package: blesta\app\models
Copyright: Copyright (c) 2010, Phillips Data, Inc.
License: The Blesta License Agreement
Link: Blesta
Located at app/models/coupons.php
Methods summary
public
# __construct( )

Initialize Coupons

Initialize Coupons

Overrides

AppModel::__construct()
public mixed
# getList( integer $company_id, integer $page = 1, string $order_by = ['code' => 'ASC'] )

Fetches a list of all coupons for a given company

Fetches a list of all coupons for a given company

Parameters

$company_id
The ID of the company to fetch coupons for
$page
The page to return results for (optional, default 1)
$order_by
The sort and order conditions (e.g. array('sort_field'=>"ASC"), optional)

Returns

mixed
An array of stdClass objects representing coupons, false if no coupons found
public integer
# getListCount( integer $company_id )

Returns the total number of coupons returned from Coupons::getList(), useful in constructing pagination for the getList() method.

Returns the total number of coupons returned from Coupons::getList(), useful in constructing pagination for the getList() method.

Parameters

$company_id
The ID of the company to fetch coupons for

Returns

integer
The total number of coupons

See

Coupons::getList()
public array
# getCouponAmounts( integer $coupon_id )

Fetches a list of currencies and amounts associated with a given coupon

Fetches a list of currencies and amounts associated with a given coupon

Parameters

$coupon_id
The ID of the coupon whose amounts to fetch

Returns

array
An array of objects representing each coupon amount
public mixed
# get( integer $coupon_id )

Fetches a coupon using the given $coupon_id

Fetches a coupon using the given $coupon_id

Parameters

$coupon_id
The ID of the coupon to fetch

Returns

mixed
A stdClass object representing the coupon, false if no such coupon exists
public mixed
# getByCode( string $code )

Retrieves a coupon by its code

Retrieves a coupon by its code

Parameters

$code
The coupon code representing the coupon to fetch

Returns

mixed
A stdClass object representing the coupon, or false if no such coupon exists
public mixed
# getForPackages( string $code = null, string $coupon_id = null, array $packages = null )

Fetches a coupon using the given code or coupon ID. Only returns coupons that are active and capable of being used for the current company.

Fetches a coupon using the given code or coupon ID. Only returns coupons that are active and capable of being used for the current company.

Parameters

$code
The coupon code to fetch
$coupon_id
The coupon ID to fetch
$packages

array of package IDs to attempt to use with the coupon in one of the following formats:

  • A numerically indexed array of package IDs
  • An array of package IDs and pricing IDs [packageID => pricingID]

Returns

mixed

A stdClass object representing the coupon, false if no such coupon exists of the coupon is no longer valid

public mixed
# getRecurring( integer $coupon_id, string $currency, string $date )

Retrieves the given coupon and the recurring coupon amount iff it recurs and applies to the given currency at the given date

Retrieves the given coupon and the recurring coupon amount iff it recurs and applies to the given currency at the given date

Parameters

$coupon_id
The ID of the coupon to fetch
$currency
The ISO 4217 currency code
$date
The date at which to check that the coupon will apply

Returns

mixed
An stdClass object representing the coupon and the recurring amount, or false otherwise
public integer
# add( array $vars )

Creates a new coupon

Creates a new coupon

Parameters

$vars

An array of coupon information including:

  • code The coupon code
  • company_id The company ID this coupon belongs to
  • used_qty The number of times this coupon has been used (optional, default 0)
  • max_qty The maximum number of times this coupon can be used (optional, default 0 for unlimited)
  • start_date The date this coupon goes into effect (optional)
  • end_date The date this coupon is no longer effective (optional)
  • status The status of the coupon, 'active' or 'inactive' (optional, default 'active')
  • recurring Allows the coupon to be applied every time the service renews, restrictions on start_date/end_date/used_qty/max_qty do not apply. If the coupon was applied originally, it will continue to be applied so long as status is 'active' and the package is still tied to this coupon.
  • limit_recurring Allows the coupon to be used again every time a renewing service that uses it renews (1 to increase the used quantity each time a renewing service renews, 0 for renewing services to use this coupon only once. optional, default 0)
  • packages A numerically indexed array containing package IDs this coupon applies to:
  • amounts An array of discounts for this coupon containing (only one per currency):
    • currency The ISO 4217 currency code
    • amount The amount of the discount
    • type The type of discount 'amount' a currency amount, 'percent' a percentage (optional, default 'percent')

Returns

integer
The ID code for this coupon
public integer
# edit( integer $coupon_id, array $vars )

Updates an existing coupon

Updates an existing coupon

Parameters

$coupon_id
The ID of the coupon to update
$vars

An array of coupon information including:

  • code The coupon code
  • company_id The ID of the company this coupon belongs to
  • used_qty The number of times this coupon has been used (optional, default 0)
  • max_qty The maximum number of times this coupon can be used (optional, default 0 for unlimited)
  • start_date The date this coupon goes into effect (optional)
  • end_date The date this coupon is no longer effective (optional)
  • status The status of the coupon, 'active' or 'inactive' (optional, default 'active')
  • recurring Allows the coupon to be applied every time the service renews, restrictions on start_date/end_date/used_qty/max_qty do not apply. If the coupon was applied originally, it will continue to be applied so long as status is 'active' and the package is still tied to this coupon.
  • limit_recurring Allows the coupon to be used again every time a renewing service that uses it renews (1 to increase the used quantity each time a renewing service renews, 0 for renewing services to use this coupon only once. optional, default 0)
  • packages A numerically indexed array containing package IDs this coupon applies to:
  • amounts An array of discounts for this coupon containing (only one per currency):
    • currency The ISO 4217 currency code
    • amount The amount of the discount
    • type The type of discount 'amount' a currency amount, 'percent' a percentage (optional, default 'percent')

Returns

integer
The ID code for this coupon
public
# delete( integer $coupon_id )

Permanently removes the coupon from the system

Permanently removes the coupon from the system

Parameters

$coupon_id
The ID of the coupon to delete
public
# incrementUsage( integer $coupon_id )

Increments the used quantity on the given coupon

Increments the used quantity on the given coupon

Parameters

$coupon_id
The ID of the coupon whose used quantity to increment
public array
# getAmountTypes( )

Retrieves a list of coupon amount types

Retrieves a list of coupon amount types

Returns

array
Key=>value pairs of coupon amount types
public boolean
# validateStatus( string $status )

Validates a coupon's 'status' field

Validates a coupon's 'status' field

Parameters

$status
The status to check

Returns

boolean
True if validated, false otherwise
public boolean
# validateAmountType( string $type )

Validates a coupon amount's 'type' field

Validates a coupon amount's 'type' field

Parameters

$type
The type to check

Returns

boolean
True if validated, false otherwise
public boolean
# validateAmountDuplicates( array $vars )

Validates an array of coupon discounts to check for duplicate currencies.

Validates an array of coupon discounts to check for duplicate currencies.

Parameters

$vars

An indexed array of discount options including:

  • currency The currency code as defined in ISO 4217
  • type The type of discount ("amount" or "percent")
  • amount The numeric amount of this discount

Returns

boolean
True if each currency is unique, false otherwise
public boolean
# validateUniqueCode( string $coupon_code, mixed $coupon_id = null )

Validates whether the given coupon code is currently in use

Validates whether the given coupon code is currently in use

Parameters

$coupon_code
The coupon code to validate
$coupon_id
The ID of the coupon the given coupon code must represent, or null to not require any

Returns

boolean
True if the given coupon code is unique, or false otherwise
Methods inherited from AppModel
_(), boolToInt(), currencyToDecimal(), dateToUtc(), errors(), getPerPage(), ifSet(), loadCrypto(), setDefaultIfEmpty(), setPerPage(), setRulesIfSet(), strToBool(), systemDecrypt(), systemEncrypt(), systemHash(), truncateDecimal(), validateExists(), validateStateCountry()
Methods used from Blesta\Core\Util\Common\Traits\Container
getFromContainer()
Properties inherited from AppModel
$logger, $replacement_keys
Blesta API documentation generated by ApiGen