Documentation

Attributes
in package

Product Attributes

This class provides frontend and backend helper and display functionality related to the Product Attribute class. See for details.

Tags
version
3.0.0
subpackage

module_shop

copyright

CLOUDREXX CMS - CLOUDREXX AG

author

Reto Kohli reto.kohli@comvation.com

todo

Test!

Table of Contents

Properties

$arrAttributes  : array<string|int, mixed>
The array of Attribute names
$arrOptions  : array<string|int, mixed>
The array of options
$arrRelation  : array<string|int, mixed>
The array of Attribute relations

Methods

addOptionToProduct()  : bool
Creates a relation between the given option and Product IDs.
deleteAll()  : bool
Delete all Attributes from the database
errorHandler()  : mixed
getArray()  : array<string|int, mixed>
Returns an array of Attribute objects
getArrayById()  : array<string|int, mixed>
Returns an array of Attribute data for the given name ID
getAsStrings()  : array<string|int, mixed>
Returns an array of two HTML representations of the Attributes and their respective options specified by the array given
getAttributeJSVars()  : string
Returns a string containing an Javascript array variable definition with the first option ID for each Attribute
getDisplayTypeMenu()  : string
Returns HTML code for the Attribute type selection dropdown menu
getIdArray()  : array<string|int, mixed>
Returns an array of Attribute IDs
getInputs()  : string
Returns a string containing HTML code for a list of input boxes with the option values (names) or prices of an Attribute
getNameArray()  : array<string|int, mixed>
Returns an array of all Attribute names
getOptionArray()  : array<string|int, mixed>
Returns the full array of Options arrays available
getOptionArrayByAttributeId()  : array<string|int, mixed>
Returns the array of Options for the given Attribute ID
getOptionMenu()  : string
Returns HTML code for the option menu for an Attribute
getOptionNameById()  : mixed
Return the name of the option selected by its ID from the database.
getOptionPriceById()  : float
Return the price of the option selected by its ID from the database.
getOptionPriceSum()  : mixed
getRelationArray()  : array<string|int, mixed>
Returns an array of Product-Option relations for the given Product ID
initAttributeArray()  : bool
Initialises the array of Attribute name data
initOptionArray()  : bool
Initialises the Options array for the given Attribute ID, or any Attributes if it is missing
initRelationArray()  : bool
Initialises the Product-Option relation array
removeFromProduct()  : bool
Remove all Product-option relations for the given Product ID.
reset()  : mixed
Clear all static data

Properties

$arrAttributes

The array of Attribute names

private static array<string|int, mixed> $arrAttributes = array()

Includes the fields id, name, and type

$arrOptions

The array of options

private static array<string|int, mixed> $arrOptions = array()

See initOptionArray() for details

$arrRelation

The array of Attribute relations

private static array<string|int, mixed> $arrRelation

See {@see initRelationArray() for details.

Methods

addOptionToProduct()

Creates a relation between the given option and Product IDs.

public static addOptionToProduct(int $option_id, int $product_id[, int $order = 0 ]) : bool

The optional $order argument determines the ordinal value.

Parameters
$option_id : int

The option ID

$product_id : int

The Product ID

$order : int = 0

The optional ordinal value, defaults to 0 (zero)

Tags
static
global

ADONewConnection $objDatabase Database connection object

author

Reto Kohli reto.kohli@comvation.com

Return values
bool

True on success, false otherwise

deleteAll()

Delete all Attributes from the database

public static deleteAll() : bool

Clears all Attributes, options, and relations. Use with due care!

Tags
static
global

ADONewConnection $objDatabase Database connection object

Return values
bool

True on success, false otherwise.

getArray()

Returns an array of Attribute objects

public static getArray(int &$count[, int $offset = 0 ][, int $limit = null ][, string $order = '`attribute`.`id` ASC' ][, string $filter = null ]) : array<string|int, mixed>
Parameters
$count : int

The number of matching records, by reference

$offset : int = 0

The optional offset, defaults to 0 (zero)

$limit : int = null

The optional limit for the number of IDs returned, defaults to null (all)

$order : string = '`attribute`.`id` ASC'

The optional order field and direction, defaults to ID, ascending

$filter : string = null

The optional filter to be applied to the name, defaults to null (any)

Tags
global

mixed $objDatabase The Database connection

Return values
array<string|int, mixed>

The array of Attributes on success, false otherwise

getArrayById()

Returns an array of Attribute data for the given name ID

public static getArrayById(int $attribute_id[, int $localeId = 0 ]) : array<string|int, mixed>

This array contains no options, just the Attribute name and type. It is a single entry of the result of initAttributeArray(().

Parameters
$attribute_id : int

The name ID

$localeId : int = 0

Optional locale ID

Return values
array<string|int, mixed>

The Attribute array

getAsStrings()

Returns an array of two HTML representations of the Attributes and their respective options specified by the array given

public static getAsStrings(array<string|int, mixed> $arrAttributesOptions[, float &$options_price = NULL ]) : array<string|int, mixed>

One of these representation may be used anywhere the matching Product is viewed. The first (at index 0) is the long form best used in the cart view, the second (at index 1) is suitable for the JSCart in the sidebar. Attributes with an empty list of option IDs will not be included in the string produced. Invalid IDs are silently skipped. Note that the format of the string can be easily customized by editing the following language entries: TXT_SHOP_OPTION_LONG_FORMAT TXT_SHOP_OPTION_LONG_FORMAT_JOINER TXT_SHOP_ATTRIBUTE_LONG_FORMAT TXT_SHOP_ATTRIBUTE_LONG_FORMAT_JOINER TXT_SHOP_OPTION_CART_FORMAT TXT_SHOP_OPTION_CART_FORMAT_JOINER TXT_SHOP_ATTRIBUTE_CART_FORMAT TXT_SHOP_ATTRIBUTE_CART_FORMAT_JOINER The array parameter must have the form array( Attribute ID => array( option ID, [...] ), [...], )

Parameters
$arrAttributesOptions : array<string|int, mixed>

The array of Attribute and option IDs

$options_price : float = NULL

The sum of all option prices, by reference

Tags
global

array $_ARRAYLANG

Return values
array<string|int, mixed>

The array of two HTML representations of the Attributes and options present in the parameter array

getAttributeJSVars()

Returns a string containing an Javascript array variable definition with the first option ID for each Attribute

public static getAttributeJSVars() : string

The array has the form optionId[Attribute ID] = first option ID; Additionally, the variable "index" is set to the highest option ID encountered. This is incremented for each new option added on the page.

Tags
static
access

private

Return values
string

$jsVars Javascript variables list

getDisplayTypeMenu()

Returns HTML code for the Attribute type selection dropdown menu

public static getDisplayTypeMenu(int $attribute_id[, int $type = '' ][, string $onchange = '' ]) : string
Parameters
$attribute_id : int

The Attribute ID

$type : int = ''

The optional preselected type

$onchange : string = ''

The optional onchange attribute value

Tags
global

array $_ARRAYLANG

Return values
string

The dropdown menu HTML code

getIdArray()

Returns an array of Attribute IDs

public static getIdArray(int &$count[, int $offset = 0 ][, int $limit = null ][, string $order = '`attribute`.`id` ASC' ][, string $filter = null ][, int $localeId = 0 ]) : array<string|int, mixed>
Parameters
$count : int

The number of matching records, by reference

$offset : int = 0

The optional offset, defaults to 0 (zero)

$limit : int = null

The optional limit for the number of IDs returned, defaults to null (all)

$order : string = '`attribute`.`id` ASC'

The optional order field and direction, defaults to ID, ascending

$filter : string = null

The optional filter to be applied to the name, defaults to null (any)

$localeId : int = 0

Optional locale ID. If not set FRONTEND_LANG_ID will be used.

Tags
global

mixed $objDatabase The Database connection

Return values
array<string|int, mixed>

The array of IDs on success, false otherwise

getInputs()

Returns a string containing HTML code for a list of input boxes with the option values (names) or prices of an Attribute

public static getInputs(int $attribute_id, string $name, string $content[, int $maxlength = '' ][, string $style = '' ]) : string

Only the first of the input elements has its display style set to 'inline', the others are invisible ('none'). See _showAttributeOptions() for an example on how it's used.

Parameters
$attribute_id : int

The Attribute ID

$name : string

The name and ID attribute for the input element

$content : string

The field content ('value' or 'price')

$maxlength : int = ''

The maximum length of the input box

$style : string = ''

The optional CSS style for the input element

Tags
access

private

Return values
string

The string with HTML code

getNameArray()

Returns an array of all Attribute names

public static getNameArray(int &$count[, int $offset = 0 ][, int $limit = 1000 ][, string $order = null ][, string $filter = null ]) : array<string|int, mixed>

Backend use only. The resulting array is limited to the first 1000 Attributes found, if the $limit parameter value is missing.

Parameters
$count : int

The number of matching records, by reference

$offset : int = 0

The optional offset, defaults to 0 (zero)

$limit : int = 1000

The optional limit for the number of IDs returned, defaults to null (all)

$order : string = null

The optional order field and direction, defaults to ID, ascending

$filter : string = null

The optional filter to be applied to the name, defaults to null (any)

Return values
array<string|int, mixed>

The array of Attribute names on success, false otherwise

getOptionArray()

Returns the full array of Options arrays available

public static getOptionArray() : array<string|int, mixed>

See initOptionArray() for details on the array returned.

Return values
array<string|int, mixed>

The Options array

getOptionArrayByAttributeId()

Returns the array of Options for the given Attribute ID

public static getOptionArrayByAttributeId(mixed $attribute_id[, int $localeId = 0 ]) : array<string|int, mixed>

See initOptionArray() for details on the array returned.

Parameters
$attribute_id : mixed
$localeId : int = 0

Optional locale ID

Return values
array<string|int, mixed>

The Options array

getOptionMenu()

Returns HTML code for the option menu for an Attribute

public static getOptionMenu(int $attribute_id, string $name[, int $selected_id = 0 ][, string $onchange = '' ][, string $style = '' ]) : string

Used in the Backend for selecting and editing.

Parameters
$attribute_id : int

The Attribute ID

$name : string

The name and ID attribute for the menu

$selected_id : int = 0

The ID of the selected option

$onchange : string = ''

The optional Javascript onchange event

$style : string = ''

The optional CSS style for the menu

Tags
global

array $_ARRAYLANG Language array

static
Return values
string

$menu The Option menu HTML code

getOptionNameById()

Return the name of the option selected by its ID from the database.

public static getOptionNameById(int $option_id) : mixed

Returns false on error, or the empty string if the value cannot be found.

Parameters
$option_id : int

The option ID

Tags
static
global

mixed $objDatabase Database object

Return values
mixed

The option name on success, or false otherwise.

getOptionPriceById()

Return the price of the option selected by its ID from the database.

public static getOptionPriceById(int $option_id) : float

Returns false on error or if the value cannot be found.

Parameters
$option_id : int

The option ID

Tags
static
global

mixed $objDatabase Database object

Return values
float

The option price on success, or false on failure.

getOptionPriceSum()

public static getOptionPriceSum(mixed $attribute_id, mixed $arrOptionId) : mixed
Parameters
$attribute_id : mixed
$arrOptionId : mixed

getRelationArray()

Returns an array of Product-Option relations for the given Product ID

public static getRelationArray(int $product_id) : array<string|int, mixed>

See initRelationArray() for details on the array.

Parameters
$product_id : int

The Product ID

Return values
array<string|int, mixed>

The relation array on success, null otherwise

initAttributeArray()

Initialises the array of Attribute name data

public static initAttributeArray([int $attribute_id = 0 ][, int $localeId = 0 ]) : bool

This array contains no options, just the Attribute name and type. The array has the form array( Attribute ID => array( 'id' => Attribute ID, 'name' => Attribute name (according to $localeId), 'type' => Attribute type, ), ... more ... ) If you specify a valid $attribute_id parameter value, only that Attribute is initialized. But note that the static array is not automatically cleared, so you can use it as a cache.

Parameters
$attribute_id : int = 0

The optional Attribute ID

$localeId : int = 0

Optional locale ID. If not set FRONTEND_LANG_ID will be used.

Return values
bool

True on success, false otherwise

initOptionArray()

Initialises the Options array for the given Attribute ID, or any Attributes if it is missing

public static initOptionArray([int $attribute_id = 0 ][, int $localeId = 0 ]) : bool

The array has the form array( Attribute ID => array( Option ID => array( 'id' => The option ID, 'attribute_id' => The Attribute ID, 'value' => The option name (according to $localeId), 'price' => The option price (including the sign), ), ... more ... ), ... more ... )

Parameters
$attribute_id : int = 0

The optional Attribute ID

$localeId : int = 0

Optional locale ID. If not set FRONTEND_LANG_ID will be used.

Return values
bool

True on success, false otherwise

initRelationArray()

Initialises the Product-Option relation array

public static initRelationArray([int $product_id = 0 ]) : bool

If the optional Product ID is missing, all Products are included. The resulting array has the form array( Product ID => array( Option ID => The ordinal value (for sorting), ... more ... ), ... more ... ) The option IDs for any Product are sorted by their ascending ordinal value.

Parameters
$product_id : int = 0

The optional Product ID

Return values
bool

True on success, false otherwise

removeFromProduct()

Remove all Product-option relations for the given Product ID.

public static removeFromProduct(int $product_id) : bool
Parameters
$product_id : int

The Product ID

Tags
static
global

ADONewConnection $objDatabase Database connection object

Return values
bool

True on success, false otherwise.

reset()

Clear all static data

public static reset() : mixed

You SHOULD call this after updating database records.

Tags
static

        
On this page

Search results