Skip to content
Last updated

WHMCS\Product\Product

Class · extends AbstractModel · implements SlugInterface, PricedEntityInterface

A product

A product represents a sellable item in WHMCS. The property object models a product's properties and configuration. It stores billing, contact, inventory, resource overage tracking, and 24 custom fields available to third party modules.

Ordering a product creates a WHMCS\Service\Service object, which is available for use by the client.

Traits

  • BillingTrait
  • MarketConnectTrait
  • OnDemandRenewalTrait
  • SlugTrait

Constants

NameDescription
TYPE_SHARED
TYPE_RESELLER
TYPE_SERVERS
TYPE_OTHER
PAYMENT_FREE
PAYMENT_ONETIME
PAYMENT_RECURRING
AUTO_SETUP_ORDER
AUTO_SETUP_PAYMENT
AUTO_SETUP_ACCEPT
AUTO_SETUP_DISABLED
DEFAULT_EMAIL_TEMPLATES

Methods

boot

public static function boot()

productGroup

public function productGroup()

A product belongs to a product group.

Returns \Illuminate\Database\Eloquent\Relations\BelongsTo

welcomeEmailTemplate

public function welcomeEmailTemplate()

A product has one welcome email template.

Returns HasOne

autoTerminationEmailTemplate

public function autoTerminationEmailTemplate()

A product has one auto termination email template.

Returns HasOne

upgradeEmailTemplate

public function upgradeEmailTemplate()

A product has one upgrade email template.

Returns HasOne

productDownloads

public function productDownloads()

A product has many downloads.

Returns \Illuminate\Database\Eloquent\Relations\BelongsToMany

upgradeProducts

public function upgradeProducts()

A product has many upgrade packages.

Returns \Illuminate\Database\Eloquent\Relations\BelongsToMany

services

public function services()

A product can have many service instances of that product.

Services are what associate products with clients.

Returns HasMany

customFields

public function customFields()

Returns HasMany

scopeVisible

public function scopeVisible(Builder $query)

Filter for only non-hidden products.

Returns Builder

scopeSorted

public function scopeSorted($query)

Sort by display order.

Returns Builder

getDownloadIds

public function getDownloadIds()

Retrieve a list of the ids of the downloads associated with a product.

Returns int[]

getUpgradeProductIds

public function getUpgradeProductIds()

Retrieve a list of the ids of the upgrade products associated with a product.

Returns int[]

getAvailableBillingCycles

public function getAvailableBillingCycles(): array

Get available billing cycles for product.

Returns string[]

pricing

public function pricing($currency = null): Pricing

Get available cycles and pricing for product.

Parameters

TypeNameDescription
array|null$currencyOnly required on first call.

Returns Pricing

getNameAttribute

public function getNameAttribute($name)

Get the product name - this will override the output from the db value if set in Lang.

Parameters

TypeNameDescription
string$nameThe value from the database

Returns string

getDescriptionAttribute

public function getDescriptionAttribute($description)

Get the product description - this will override the output from the db value if set in Lang.

Parameters

TypeNameDescription
string$descriptionThe value from the database

Returns string

getTaglineAttribute

public function getTaglineAttribute($tagline)

Parameters

TypeNameDescription
string$tagline

Returns string

getShortDescriptionAttribute

public function getShortDescriptionAttribute($shortDescription)

Parameters

TypeNameDescription
string$shortDescription

Returns string

setShortDescriptionAttribute

public function setShortDescriptionAttribute(string $shortDescription)

Set the products short description

Parameters

TypeNameDescription
string$shortDescription

translatedNames

public function translatedNames()

Return the translated names for the specific product

Returns HasMany\|\WHMCS\Language\DynamicTranslation[]

translatedDescriptions

public function translatedDescriptions()

Return the translated names for the specific product

Returns HasMany\|\WHMCS\Language\DynamicTranslation[]

getProductName

public static function getProductName($productId, $fallback = '', $language = null)

Obtain the product name for the current language, passed language or fallback to the currently defined value for the product.

Parameters

TypeNameDescription
int$productId
string$fallback- override the language fallback value
string$language

Returns string

getProductDescription

public static function getProductDescription($productId, $fallback = '', $language = null)

Obtain the product description for the current language, passed language or fallback to the currently defined value for the product.

Parameters

TypeNameDescription
int$productId
string$fallback
string$language

Returns string

assignMatchingMarketConnectAddons

public function assignMatchingMarketConnectAddons(array $addons)

Parameters

TypeNameDescription
Addon[]$addons

isFree

public function isFree(): bool

Is product a free product.

Returns bool

isOneTime

public function isOneTime(): bool

Is product a one time product.

Returns bool

scopeIsNotRetired

public function scopeIsNotRetired(Builder $query)

Parameters

TypeNameDescription
Builder$query

Returns Builder

scopeIsRetired

public function scopeIsRetired(Builder $query)

Parameters

TypeNameDescription
Builder$query

Returns Builder

scopeOfModule

public function scopeOfModule(Builder $query, string $module): Builder

getProductKeyAttribute

public function getProductKeyAttribute()

Get product key attribute for the current product entity.

Parameters

TypeNameDescription
string$value

Returns string

isMarketConnectProduct

public function isMarketConnectProduct()

Is this a MarketConnect product?

Returns bool

getServiceKeyAttribute

public function getServiceKeyAttribute($value)

Get service key attribute for the current product entity.

Parameters

TypeNameDescription
string$value

Returns string

isValidForUpgrade

public function isValidForUpgrade(Product $product)

Validate a given product is a valid upgrade candidate.

For MarketConnect, validates upgrade product service key matches current product key.

Parameters

TypeNameDescription
Product$product

Returns bool

getFormattedProductFeaturesAttribute

public function getFormattedProductFeaturesAttribute()

Returns array

getBilledMetricsAttribute

public function getBilledMetricsAttribute()

metrics

public function metrics()

Returns HasMany

enabledMetrics

public function enabledMetrics(): HasMany

Usage metrics that are enabled

Returns HasMany

recommendations

public function recommendations(): BelongsToMany

Returns BelongsToMany

recommendationExists

public function recommendationExists(int $productId): bool

emailMarketerRules

public function emailMarketerRules()

getClientStockLevel

public function getClientStockLevel(): int

Returns int

moduleConfiguration

public function moduleConfiguration()

Returns HasMany

getModuleConfigurationSetting

public function getModuleConfigurationSetting(string $settingName): ModuleConfiguration

eventActions

public function eventActions(): HasMany

Returns HasMany

duplicate

public function duplicate(string $newProductName): Product

Duplicate a Product along with all corresponding attributes

Parameters

TypeNameDescription
string$newProductName

Returns Product — New Duplicated Product

slugs

public function slugs(): Relation

Returns HasMany

inactiveSlugs

public function inactiveSlugs(): Relation

Returns HasMany

activeSlug

public function activeSlug(): Relation

Returns HasOne

validateSlugIsUnique

public function validateSlugIsUnique(string $slug): bool

Parameters

TypeNameDescription
string$slug

Returns bool

getExistingSlugCheck

public function getExistingSlugCheck(string $slug): Builder

createSlug

public function createSlug()

getRoutePath

public function getRoutePath(): string

getRecommendationRoutePath

public function getRecommendationRoutePath(?int $productId = null): string

getRouteParts

public function getRouteParts(): array

getOrderLineItemProductGroupName

public function getOrderLineItemProductGroupName(): string

overrideOnDemandRenewal

public function overrideOnDemandRenewal(): HasOne

On-demand renewal override settings if not null

Returns HasOne

overridingOnDemandRenewal

public function overridingOnDemandRenewal(bool $enable, int $monthly, int $quarterly, int $semiannually, int $annually, int $biennially, int $triennially): self

Override on-demand renewal settings

Parameters

TypeNameDescription
bool$enable
int$monthly
int$quarterly
int$semiannually
int$annually
int$biennially
int$triennially

Returns Product