public
|
#
__construct( )
Initialize Coupons
Overrides
|
public
mixed
|
#
getList( integer $company_id, integer $page = 1, string $order_by = array('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
integer $company_id The ID of the company to fetch coupons for
- $page
integer $page The page to return results for (optional, default 1)
- $order_by
string $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
integer $company_id The ID of the company to fetch coupons for
Returns
integer The total number of coupons
See
|
private
Record
|
#
getCoupons( integer $company_id )
Partially constructs the query required by both Coupons::getList() and
Coupons::getListCount()
Partially constructs the query required by both Coupons::getList() and
Coupons::getListCount()
Parameters
- $company_id
integer $company_id The company ID to fetch coupons for
Returns
Record
The partially constructed query Record object
|
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
integer $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
integer $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
|
#
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
string $code The coupon code to fetch
- $coupon_id
string $coupon_id The coupon ID to fetch
- $packages
array An array of packages to attempt to use with the coupon. If the coupon is
inclusive all packages configured for the coupon must be present.
Returns
mixed A stdClass object representing the coupon, false if no such coupon exists of the
coupon is no longer valid
|
private
array
|
#
getPackages( integer $coupon_id )
Retrieves all packages associated with a given coupon
Retrieves all packages associated with a given coupon
Parameters
- $coupon_id
integer $coupon_id The coupon ID
Returns
array An array of stdClass object representing package IDs
|
private
array
|
#
getAmounts( integer $coupon_id )
Retrieves all packages associated with a given coupon
Retrieves all packages associated with a given coupon
Parameters
- $coupon_id
integer $coupon_id The coupon ID
Returns
array An array of stdClass object representing coupon pricing
|
public
integer
|
#
add( array $vars )
Creates a new coupon
Parameters
- $vars
array $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') -type The type of coupon, 'inclusive'
must order all packages in package for coupon to apply, 'exclusive' no
restriction on coupon application (optional, default 'exclusive') -recurring
Allows the coupon to be applied every time the service renews, restrictions on
start_date/end_date/used_qty/max_qty/type 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
integer $coupon_id The ID of the coupon to update
- $vars
array $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') -type The type of coupon,
'inclusive' must order all packages in package for coupon to apply, 'exclusive'
no restriction on coupon application (optional, default 'exclusive') -recurring
Allows the coupon to be applied every time the service renews, restrictions on
start_date/end_date/used_qty/max_qty/type 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
integer $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
integer $coupon_id The ID of the coupon whose used quantity to increment
|
public
array
|
#
getTypes( )
Retrieves a list of coupon types
Retrieves a list of coupon types
Returns
array Key=>value pairs of coupon types
|
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
string $status The status to check
Returns
boolean True if validated, false otherwise
|
public
boolean
|
#
validateType( string $type )
Validates a coupon's 'type' field
Validates a coupon's 'type' field
Parameters
- $type
string $type The type 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
string $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
array $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
|
#
validateInclusiveRecurring( array $amounts, string $recurring, string $type )
Validates that inclusive recurring coupons of discount type "Amount" do not
exist. This prohibits the possibility of amount discounts being applied to each
service with a recurring coupon.
Validates that inclusive recurring coupons of discount type "Amount" do not
exist. This prohibits the possibility of amount discounts being applied to each
service with a recurring coupon.
Parameters
- $amounts
array $amounts 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
- $recurring
string $recurring Whether this coupon is set to be recurring (1 or 0)
- $type
string $type The coupon type ("inclusive" or "exclusive")
Returns
boolean True if this coupon is not set as an inclusive recurring coupon that contains
any discounts of type "Amount", or false otherwise
|
private
array
|
#
getRules( array $vars, boolean $edit = false )
Returns the rule set for adding/editing coupons
Returns the rule set for adding/editing coupons
Parameters
- $vars
array $vars A list of input vars
- $edit
boolean $edit True to get the edit rules, false for the add rules
Returns
array Coupon rules
|