ShopCategory
in package
Container for Products in the Shop.
Tags
Table of Contents
Constants
- TEXT_DESCRIPTION = 'category_description'
- TEXT_NAME = 'category_name'
- Text keys
- TEXT_SHORT_DESCRIPTION = 'category_short_description'
Properties
- $shortDescription : string
- $active : bool
- $description : string
- $flags : string
- $id : int
- $name : string
- $ord : int
- $parent_id : int
- $picture : string
Methods
- __construct() : ShopCategory
- Create a ShopCategory
- active() : bool
- Sets the active status, if present, and returns the current value
- addFlag() : bool
- Adds a flag
- delete() : bool
- Deletes this ShopCategory from the database.
- deleteChildNamed() : bool
- Looks for and deletes the sub-ShopCategory named $name contained by the ShopCategory specified by $parent_id.
- description() : string
- Sets the description, if present, and returns the current value
- errorHandler() : bool
- Handles any kind of database error
- flags() : string
- Sets the flags, if present, and returns the current value
- getById() : ShopCategory
- Returns a ShopCategory selected by its ID from the database.
- getCategoryTree() : array<string|int, mixed>
- Returns an array representing a tree of ShopCategories, not including the root chosen.
- getChildCategories() : mixed
- Returns an array of this ShopCategory's children from the database.
- getChildNamed() : mixed
- Returns the child ShopCategory of this with the given name, if found.
- getChildrenIdArray() : mixed
- Returns an array of all IDs of children ShopCateries.
- getNextShopCategoryId() : int
- Returns the ShopCategory ID following $shopCategoryId according to the sorting order.
- getParentCategoryId() : int
- Returns the parent category ID, or 0 (zero)
- getShopCategoryMenuHierarchic() : string
- Returns the HTML code for a dropdown menu listing all ShopCategories.
- getShopCategoryMenuHierarchicRecurse() : string
- Builds the ShopCategory menu recursively.
- id() : int
- Returns the ShopCategory ID
- insert() : bool
- Inserts this ShopCategory into the database.
- makeClone() : void
- Clones the ShopCategory
- name() : string
- Sets the name, if present, and returns the current value
- ord() : int
- Sets the ordinal, if present, and returns the current value
- parent_id() : int
- Sets the parent ID, if present, and returns the current value.
- picture() : string
- Sets the picture file name, if present, and returns the current value
- recordExists() : bool
- Tests whether a record with the ID of this object is already present in the database.
- removeFlag() : bool
- Removes a flag
- shortDescription() : string
- Sets the short description, if present, and returns the current value
- store() : bool
- Stores the ShopCategory object in the database.
- testFlag() : bool
- Tests for a match with the ShopCategory flags.
- testFlag2() : bool
- Tests for a match with the flags in the string.
- update() : bool
- Updates this ShopCategory in the database.
- virtual() : bool
- Sets the virtual flag if the argument evaluates to any boolean value, and returns the current state
Constants
TEXT_DESCRIPTION
public
mixed
TEXT_DESCRIPTION
= 'category_description'
TEXT_NAME
Text keys
public
mixed
TEXT_NAME
= 'category_name'
TEXT_SHORT_DESCRIPTION
public
mixed
TEXT_SHORT_DESCRIPTION
= 'category_short_description'
Properties
$shortDescription
protected
string
$shortDescription
= ''
ShopCategory short description
$active
private
bool
$active
= 1
Active status of the ShopCategory
Tags
$description
private
string
$description
= ''
ShopCategory description
Tags
$flags
private
string
$flags
= ''
ShopCategory flags
Tags
$id
private
int
$id
= null
ShopCategory ID
Tags
$name
private
string
$name
= ''
ShopCategory name
Tags
$ord
private
int
$ord
= 0
Ordinal value of the ShopCategory
Tags
$parent_id
private
int
$parent_id
= 0
Parent ShopCategory ID
Tags
$picture
private
string
$picture
= ''
ShopCategory picture name
Tags
Methods
__construct()
Create a ShopCategory
public
__construct(string $name[, string $shortDescription = null ][, string $description = null ][, int $parent_id = 0 ][, int $active = null ][, int $ord = 0 ][, int $id = 0 ]) : ShopCategory
If the optional argument $category_id is greater than zero, the corresponding category is updated. Otherwise, a new category is created.
Parameters
- $name : string
-
The category name
- $shortDescription : string = null
-
The optional category short description
- $description : string = null
-
The optional category description
- $parent_id : int = 0
-
The optional parent ID of the category
- $active : int = null
-
The optional active status category. Defaults to null (unset)
- $ord : int = 0
-
The optional ordinal value
- $id : int = 0
-
The optional category ID
Tags
Return values
ShopCategory —The ShopCategory
active()
Sets the active status, if present, and returns the current value
public
active([bool $active = null ]) : bool
Parameters
- $active : bool = null
-
The optional active status
Tags
Return values
bool —The active status
addFlag()
Adds a flag
public
addFlag(string $flag) : bool
Note that the match is case insensitive.
Parameters
- $flag : string
-
The flag to be added
Tags
Return values
bool —Boolean true if the flags were accepted or already present, false otherwise (always true for the time being).
delete()
Deletes this ShopCategory from the database.
public
delete([mixed $flagDeleteImages = false ]) : bool
Also removes associated subcategories and Products. Images will only be erased from the disc if the optional $flagDeleteImages parameter evaluates to true.
Parameters
- $flagDeleteImages : mixed = false
Tags
Return values
bool —True on success, false otherwise
deleteChildNamed()
Looks for and deletes the sub-ShopCategory named $name contained by the ShopCategory specified by $parent_id.
public
static deleteChildNamed(mixed $parent_id, string $name) : bool
The child's name must be unambiguous, or the method will fail.
Parameters
- $parent_id : mixed
- $name : string
-
The ShopCategory name to delete
Tags
Return values
bool —True on success, false otherwise
description()
Sets the description, if present, and returns the current value
public
description([string $description = null ]) : string
Parameters
- $description : string = null
-
The optional description
Tags
Return values
string —The current description
errorHandler()
Handles any kind of database error
public
static errorHandler() : bool
Tags
Return values
bool —False. Always.
flags()
Sets the flags, if present, and returns the current value
public
flags([string $flags = null ]) : string
Parameters
- $flags : string = null
-
The optional flags
Tags
Return values
string —The current flags
getById()
Returns a ShopCategory selected by its ID from the database.
public
static getById(int $category_id[, int $localeId = 0 ]) : ShopCategory
Returns null if the Category does not exist.
Parameters
- $category_id : int
-
The Shop Category ID
- $localeId : int = 0
-
Optional locale ID. If not set FRONTEND_LANG_ID will be used.
Tags
Return values
ShopCategory —The Shop Category object on success, false on failure, or null otherwise.
getCategoryTree()
Returns an array representing a tree of ShopCategories, not including the root chosen.
public
static getCategoryTree([int $parent_id = 0 ][, bool $active = false ][, int $level = 0 ]) : array<string|int, mixed>
The resulting array looks like: array( parent ID => array( child ID => array( 'ord' => val, 'active' => val, 'level' => val, ), ... more children ), ... more parents )
Parameters
- $parent_id : int = 0
-
The optional root ShopCategory ID. Defaults to 0 (zero).
- $active : bool = false
-
Only return ShopCategories with active==1 if true. Defaults to false.
- $level : int = 0
-
Optional nesting level, initially 0. Defaults to 0 (zero).
Tags
Return values
array<string|int, mixed> —The array of ShopCategories, or false on failure.
getChildCategories()
Returns an array of this ShopCategory's children from the database.
public
getChildCategories([bool $active = false ]) : mixed
Parameters
- $active : bool = false
-
Only return ShopCategories with active==1 if true. Defaults to false.
Tags
Return values
mixed —An array of ShopCategory objects on success, false otherwise
getChildNamed()
Returns the child ShopCategory of this with the given name, if found.
public
static getChildNamed(string $strName[, bool $active = true ]) : mixed
Returns false if the query fails, or if no child ShopCategory of that name can be found. //Note that if there are two or more children of the same name (and with //active status, if $active is true), a warning will be echo()ed. //This is by design.
Parameters
- $strName : string
-
The child ShopCategory name
- $active : bool = true
-
If true, only active ShopCategories are considered.
Tags
Return values
mixed —The ShopCategory on success, false otherwise.
getChildrenIdArray()
Returns an array of all IDs of children ShopCateries.
public
getChildrenIdArray() : mixed
Tags
Return values
mixed —Array of the resulting Shop Category IDs on success, false otherwise
getNextShopCategoryId()
Returns the ShopCategory ID following $shopCategoryId according to the sorting order.
public
static getNextShopCategoryId([int $shopCategoryId = 0 ]) : int
Parameters
- $shopCategoryId : int = 0
-
The ShopCategory ID
Tags
Return values
int —The next ShopCategory ID
getParentCategoryId()
Returns the parent category ID, or 0 (zero)
public
static getParentCategoryId(int $intCategoryId) : int
If the ID given corresponds to a top level category, 0 (zero) is returned, as there is no parent. If the ID cannot be found, 0 (zero) is returned as well.
Parameters
- $intCategoryId : int
-
The category ID
Tags
Return values
int —The parent category ID, or 0 (zero) on failure.
getShopCategoryMenuHierarchic()
Returns the HTML code for a dropdown menu listing all ShopCategories.
public
static getShopCategoryMenuHierarchic([mixed $selected = 0 ][, string $name = 'catId' ]) : string
If the optional menu name string is non-empty, the
Parameters
- $selected : mixed = 0
- $name : string = 'catId'
-
The optional menu name
Tags
Return values
string —The HTML dropdown menu code
getShopCategoryMenuHierarchicRecurse()
Builds the ShopCategory menu recursively.
public
static getShopCategoryMenuHierarchicRecurse(int $parent_id, int $level[, int $selected = 0 ]) : string
Parameters
- $parent_id : int
-
The parent ShopCategory ID.
- $level : int
-
The nesting level. Should start at 0 (zero).
- $selected : int = 0
-
The optional selected ShopCategory ID.
Tags
Return values
string —The HTML code with all
id()
Returns the ShopCategory ID
public
id() : int
Tags
Return values
int —The ShopCategory ID
insert()
Inserts this ShopCategory into the database.
public
insert() : bool
On success, updates this objects' Category ID. Uses the ID stored in this object, if greater than zero.
Tags
Return values
bool —True on success, false otherwise
makeClone()
Clones the ShopCategory
public
makeClone([bool $flagRecursive = false ][, bool $flagWithProducts = false ]) : void
Note that this does NOT create a copy in any way, but simply clears the ShopCategory ID. Upon storing this object, a new ID is created.
Parameters
- $flagRecursive : bool = false
-
Clone subcategories if true
- $flagWithProducts : bool = false
-
Clone contained Products if true
Tags
name()
Sets the name, if present, and returns the current value
public
name([string $name = null ]) : string
Parameters
- $name : string = null
-
The optional name
Tags
Return values
string —The current name
ord()
Sets the ordinal, if present, and returns the current value
public
ord([int $ord = null ]) : int
Parameters
- $ord : int = null
-
The optional ordinal value
Tags
Return values
int —The current ordinal value
parent_id()
Sets the parent ID, if present, and returns the current value.
public
parent_id([int $parent_id = null ]) : int
If the given parent ID equals the own ID, does not change the present value, and returns null.
Parameters
- $parent_id : int = null
-
The optional parent ID
Tags
Return values
int —The current parent ID, or null
picture()
Sets the picture file name, if present, and returns the current value
public
picture([string $picture = null ]) : string
The $picture parameter value is not tested in any way, so please watch your step.
Parameters
- $picture : string = null
-
The optional picture file name
Tags
Return values
string —The current picture file name
recordExists()
Tests whether a record with the ID of this object is already present in the database.
public
recordExists() : bool
Tags
Return values
bool —True if it exists, false otherwise
removeFlag()
Removes a flag
public
removeFlag(string $flag) : bool
Note that the match is case insensitive.
Parameters
- $flag : string
-
The flag to be removed
Tags
Return values
bool —Boolean true if the flags could be removed or wasn't present, false otherwise (always true for the time being).
shortDescription()
Sets the short description, if present, and returns the current value
public
shortDescription([mixed $shortDescription = null ]) : string
Parameters
- $shortDescription : mixed = null
Tags
Return values
string —The current short description
store()
Stores the ShopCategory object in the database.
public
store([int $localeId = 0 ]) : bool
Either updates (id > 0) or inserts (id == 0) the object.
Parameters
- $localeId : int = 0
-
Optional locale ID. If not set FRONTEND_LANG_ID will be used.
Tags
Return values
bool —True on success, false otherwise
testFlag()
Tests for a match with the ShopCategory flags.
public
testFlag(string $flag) : bool
Note that the match is case insensitive.
Parameters
- $flag : string
-
The ShopCategory flag to test
Tags
Return values
bool —Boolean true if the flag is set, false otherwise.
testFlag2()
Tests for a match with the flags in the string.
public
static testFlag2(string $flag, mixed $flags) : bool
Note that the match is case insensitive.
Parameters
- $flag : string
-
The ShopCategory flag to test
- $flags : mixed
Tags
Return values
bool —Boolean true if the flag is set, false otherwise.
update()
Updates this ShopCategory in the database.
public
update() : bool
Returns the result of the query.
Tags
Return values
bool —True on success, false otherwise
virtual()
Sets the virtual flag if the argument evaluates to any boolean value, and returns the current state
public
virtual([bool $virtual = null ]) : bool
Parameters
- $virtual : bool = null
-
The optional virtual flag
Tags
Return values
bool —True if the ShopCategory is virtual, false otherwise