Documentation

Attribute
in package

Product Attribute

These may be associated with zero or more Products. Each attribute consists of a name part (module_shop_attribute) and zero or more value parts (module_shop_option). Each of the values can be associated with an arbitrary number of Products by inserting the respective record into the relations table module_shop_products_attributes. The type determines the kind of relation between a Product and the attribute values, that is, whether it is optional or mandatory, and whether single or multiple attributes may be chosen at a time. 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

Constants

TEXT_ATTRIBUTE_NAME  = 'attribute_name'
Text keys
TEXT_OPTION_NAME  = 'option_name'
TYPE_CHECKBOX  = 2
TYPE_COUNT  = 20
TYPE_DATE_MANDATORY  = 15
TYPE_DATE_OPTIONAL  = 14
TYPE_EMAIL_MANDATORY  = 11
TYPE_EMAIL_OPTIONAL  = 10
TYPE_MENU_MANDATORY  = 3
TYPE_MENU_OPTIONAL  = 0
Attribute type constants
TYPE_NUMBER_FLOAT_MANDATORY  = 19
TYPE_NUMBER_FLOAT_OPTIONAL  = 18
TYPE_NUMBER_INT_MANDATORY  = 17
TYPE_NUMBER_INT_OPTIONAL  = 16
TYPE_RADIOBUTTON  = 1
TYPE_TEXT_MANDATORY  = 5
TYPE_TEXT_OPTIONAL  = 4
TYPE_TEXTAREA_MANDATORY  = 9
TYPE_TEXTAREA_OPTIONAL  = 8
TYPE_UPLOAD_MANDATORY  = 7
TYPE_UPLOAD_OPTIONAL  = 6
TYPE_URL_MANDATORY  = 13
TYPE_URL_OPTIONAL  = 12

Properties

$arrType  : array<string|int, mixed>
The available Attribute types
$arrRelation  : array<string|int, mixed>
The array of Product Attribute relations
$arrValues  : array<string|int, mixed>
The array of Options
$id  : int
The Attribute ID
$name  : string
The Attribute name
$order  : int
Sorting order
$product_id  : mixed
The associated Product ID, if any, or false
$type  : int
The Attribute type

Methods

__construct()  : mixed
Constructor
addOption()  : bool
Add an option
changeValue()  : bool
Update an option in this object
delete()  : bool
Deletes the Attribute from the database.
deleteValueById()  : bool
Remove the option with the given ID from this Attribute
errorHandler()  : bool
Handles database errors
getById()  : Attribute
Returns a new Attribute queried by its Attribute ID from the database.
getByOptionId()  : mixed
Returns a new Attribute queried by one of its option IDs from the database.
getId()  : int
Get the Attribute ID
getIdByOptionId()  : int
Returns the Attribute ID associated with the given option ID in the value table.
getName()  : string
Get the name
getNameById()  : mixed
Return the name of the Attribute selected by its ID from the database.
getOptionArray()  : array<string|int, mixed>
Returns an array of values for this Attribute.
getOrder()  : int
Get the Attribute sorting order
getType()  : int
Get the Attribute type
getValueIdByName()  : int
Return the option ID corresponding to the given value name, if found, false otherwise.
getVerificationRegex()  : string
Returns a regular expression for the verification of options
insert()  : bool
Inserts the Attribute object into the database.
insertValue()  : bool
Insert a new option into the database.
recordExists()  : bool
Returns true if the record for this objects' ID exists, false otherwise
recordExistsValue()  : bool
Returns boolean true if the option record with the given ID exists in the database table, false otherwise
setName()  : mixed
Set the Attribute name
setOrder()  : mixed
Set the Attribute sorting order.
setType()  : mixed
Set the Attribute type
store()  : bool
Stores the Attribute object in the database.
storeValues()  : bool
Store the Attibute value records in the database
toString()  : string
Returns a string representation of the Attribute
update()  : bool
Updates the Attribute object in the database.
updateValue()  : bool
Update the Attibute value record in the database

Constants

TEXT_ATTRIBUTE_NAME

Text keys

public mixed TEXT_ATTRIBUTE_NAME = 'attribute_name'

TYPE_MENU_OPTIONAL

Attribute type constants

public mixed TYPE_MENU_OPTIONAL = 0

Note that you need to update methods like Attributes::getDisplayTypeMenu() when you add another type here.

TYPE_NUMBER_FLOAT_MANDATORY

public mixed TYPE_NUMBER_FLOAT_MANDATORY = 19

TYPE_NUMBER_FLOAT_OPTIONAL

public mixed TYPE_NUMBER_FLOAT_OPTIONAL = 18

TYPE_NUMBER_INT_MANDATORY

public mixed TYPE_NUMBER_INT_MANDATORY = 17

Properties

$arrType

The available Attribute types

public static array<string|int, mixed> $arrType = array( self::TYPE_MENU_OPTIONAL => 'TYPE_MENU_OPTIONAL', self::TYPE_RADIOBUTTON => 'TYPE_RADIOBUTTON', self::TYPE_CHECKBOX => 'TYPE_CHECKBOX', self::TYPE_MENU_MANDATORY => 'TYPE_MENU_MANDATORY', self::TYPE_TEXT_OPTIONAL => 'TYPE_TEXT_OPTIONAL', self::TYPE_TEXT_MANDATORY => 'TYPE_TEXT_MANDATORY', // TODO: Disabled FTTB. Feature for 3.1.0 // TODO: Include upload path with corresponding backend setting // TODO: Set form type for multipart self::TYPE_UPLOAD_OPTIONAL => 'TYPE_UPLOAD_OPTIONAL', self::TYPE_UPLOAD_MANDATORY => 'TYPE_UPLOAD_MANDATORY', self::TYPE_TEXTAREA_OPTIONAL => 'TYPE_TEXTAREA_OPTIONAL', self::TYPE_TEXTAREA_MANDATORY => 'TYPE_TEXTAREA_MANDATORY', self::TYPE_EMAIL_OPTIONAL => 'TYPE_EMAIL_OPTIONAL', self::TYPE_EMAIL_MANDATORY => 'TYPE_EMAIL_MANDATORY', self::TYPE_URL_OPTIONAL => 'TYPE_URL_OPTIONAL', self::TYPE_URL_MANDATORY => 'TYPE_URL_MANDATORY', self::TYPE_DATE_OPTIONAL => 'TYPE_DATE_OPTIONAL', self::TYPE_DATE_MANDATORY => 'TYPE_DATE_MANDATORY', self::TYPE_NUMBER_INT_OPTIONAL => 'TYPE_NUMBER_INT_OPTIONAL', self::TYPE_NUMBER_INT_MANDATORY => 'TYPE_NUMBER_INT_MANDATORY', self::TYPE_NUMBER_FLOAT_OPTIONAL => 'TYPE_NUMBER_FLOAT_OPTIONAL', self::TYPE_NUMBER_FLOAT_MANDATORY => 'TYPE_NUMBER_FLOAT_MANDATORY', )

Listed in the dropdown menu in this order. Note that only types listed in this array are available for selecting in the shop backend! Format is array( Type => Language entry postfix, ... more ... )

$arrRelation

The array of Product Attribute relations

private array<string|int, mixed> $arrRelation = false

$arrValues

The array of Options

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

$order

Sorting order

private int $order

Only used by our friend, the Product class

$product_id

The associated Product ID, if any, or false

private mixed $product_id = false

Methods

__construct()

Constructor

public __construct(mixed $name, int $type[, int $id = 0 ][, int $product_id = false ][, int $localeId = 0 ]) : mixed
Parameters
$name : mixed
$type : int

The type of the Attribute

$id : int = 0

The optional Attribute ID

$product_id : int = false

The optional Product ID

$localeId : int = 0

Optional locale ID

addOption()

Add an option

public addOption(string $value, float $price[, int $order = 0 ]) : bool

The values' ID is set when the record is stored.

Parameters
$value : string

The value description

$price : float

The value price

$order : int = 0

The value order, only applicable when associated with a Product

Return values
bool

True on success, false otherwise

changeValue()

Update an option in this object

public changeValue(int $option_id, string $value, float $price[, int $order = 0 ]) : bool

The option is only stored together with the object in

Parameters
$option_id : int

The option ID

$value : string

The descriptive name

$price : float

The price

$order : int = 0

The order of the value, only applicable when associated with a Product

Return values
bool

True on success, false otherwise

delete()

Deletes the Attribute from the database.

public delete() : bool

Includes both the name and all of the value entries related to it. As a consequence, all relations to Products referring to the deleted entries are deleted, too. See . Keep in mind that any Products currently held in memory may cause inconsistencies!

Tags
global

ADONewConnection $objDatabase Database connection object

Return values
bool

True on success, false otherwise.

deleteValueById()

Remove the option with the given ID from this Attribute

public deleteValueById(int $option_id) : bool
Parameters
$option_id : int

The option ID

Tags
author

Reto Kohli reto.kohli@comvation.com

Return values
bool

True on success, false otherwise

errorHandler()

Handles database errors

public static errorHandler() : bool

Also migrates old ProductAttribute to new Attribute structures, including Text records.

Tags
throws
Update_DatabaseException
Return values
bool

false Always!

getById()

Returns a new Attribute queried by its Attribute ID from the database.

public static getById(int $id[, int $localeId = 0 ]) : Attribute
Parameters
$id : int

The Attribute ID

$localeId : int = 0

Optional locale ID

Tags
global

ADONewConnection

static
Return values
Attribute

The Attribute object

getByOptionId()

Returns a new Attribute queried by one of its option IDs from the database.

public static getByOptionId(int $option_id) : mixed
Parameters
$option_id : int

The option ID

Tags
static

getId()

Get the Attribute ID

public getId() : int
Return values
int

The Attribute ID

getIdByOptionId()

Returns the Attribute ID associated with the given option ID in the value table.

public static getIdByOptionId(int $option_id) : int
Parameters
$option_id : int

The option ID

Tags
static
global

ADONewConnection

Return values
int

The associated Attribute ID

getNameById()

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

public static getNameById(int $nameId) : mixed
Parameters
$nameId : int

The Attribute ID

Tags
global

ADONewConnection $objDatabase Database connection object

static
Return values
mixed

The Attribute name on success, false otherwise

getOptionArray()

Returns an array of values for this Attribute.

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

If the array has not been initialized, the method tries to do so from the database. The array has the form array( option ID => array( 'id' => option ID, 'attribute_id' => Attribute ID, 'value' => value name, 'price' => price, ), ... more ... ); For relations to the associated Product, if any, see .

Parameters
$localeId : int = 0

Optional locale ID

Tags
global

ADONewConnection

Return values
array<string|int, mixed>

Array of Options upon success, false otherwise.

getOrder()

Get the Attribute sorting order

public getOrder() : int

Note that this is SHOULD only be set by our friend, the Product object. So if you have a Attribute not actually associated to a Product, you SHOULD always get a return value of boolean false.

Return values
int

The Attribute sorting order, or false if not applicable.

getType()

Get the Attribute type

public getType() : int
Return values
int

The Attribute type

getValueIdByName()

Return the option ID corresponding to the given value name, if found, false otherwise.

public static getValueIdByName(string $value) : int

If there is more than one value of the same name, only the first ID found is returned, with no guarantee that it will always return the same. This method is awkwardly named because of the equally awkward names given to the database fields.

Parameters
$value : string

The option name

Tags
global

ADONewConnection $objDatabase Database connection object

static
Return values
int

The first matching option ID found, or false.

getVerificationRegex()

Returns a regular expression for the verification of options

public static getVerificationRegex(int $type) : string

The regex returned depends on the value of the $type parameter. Mind that the regex is also applicable to some optional types! For types that need not be verified, the empty string is returned.

Parameters
$type : int

The Attribute type

Return values
string

The regex

insert()

Inserts the Attribute object into the database.

public insert() : bool

Note that this neither updates the associated Text nor the values records. Call for that.

Tags
global

ADONewConnection

Return values
bool

True on success, false otherwise

insertValue()

Insert a new option into the database.

public insertValue(array<string|int, mixed> &$arrValue) : bool

Updates the values' ID upon success. Note that associated Text records are not changed here, call storeValues() with the value array for this.

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

The value array, by reference

Tags
access

private

global

ADONewConnection $objDatabase Database connection object

Return values
bool

True on success, false otherwise

recordExists()

Returns true if the record for this objects' ID exists, false otherwise

public recordExists() : bool
Tags
global

ADONewConnection $objDatabase

Return values
bool

True if the record exists, false otherwise

recordExistsValue()

Returns boolean true if the option record with the given ID exists in the database table, false otherwise

public static recordExistsValue(int $option_id) : bool
Parameters
$option_id : int

The option ID

Tags
static
Return values
bool

True if the record exists, false otherwise

setName()

Set the Attribute name

public setName(string $name) : mixed

Empty name arguments are ignored.

Parameters
$name : string

The Attribute name

Tags
author

Reto Kohli reto.kohli@comvation.com

setOrder()

Set the Attribute sorting order.

public setOrder(mixed $order) : mixed

Note that you can only set this to a valid integer value, not reset to false or even unset state. This SHOULD only be set if the Attribute is indeed associated with a Product, as this value will only be stored in the relations table module_shop_products_attributes.

Parameters
$order : mixed

setType()

Set the Attribute type

public setType(mixed $type) : mixed
Parameters
$type : mixed

store()

Stores the Attribute object in the database.

public store([int $localeId = 0 ]) : bool

Either updates or inserts the record. Also stores the associated Text records.

Parameters
$localeId : int = 0

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

Return values
bool

True on success, false otherwise

storeValues()

Store the Attibute value records in the database

public storeValues([int $localeId = 0 ]) : bool
Parameters
$localeId : int = 0

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

Tags
global

ADONewConnection

Return values
bool

True on success, false otherwise

toString()

Returns a string representation of the Attribute

public toString() : string
Return values
string

update()

Updates the Attribute object in the database.

public update() : bool

Note that this neither updates the associated Text nor the values records. Call for that.

Tags
global

ADONewConnection $objDatabase

Return values
bool

True on success, false otherwise

updateValue()

Update the Attibute value record in the database

public updateValue(array<string|int, mixed> $arrValue) : bool

Note that associated Text records are not changed here, call storeValues() with the value array for this.

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

The value array

Tags
global

ADONewConnection $objDatabase Database connection object

Return values
bool

True on success, false otherwise


        
On this page

Search results