Products
in package
Product helper object
Provides methods for accessing sets of Products, displaying menus and the like.
Tags
Table of Contents
Constants
- DEFAULT_VIEW_COUNT = 4
- DEFAULT_VIEW_DISCOUNTS = 2
- DEFAULT_VIEW_LASTFIVE = 3
- DEFAULT_VIEW_MARKED = 1
- DEFAULT_VIEW_NONE = 0
Properties
- $arrProductOrder : array<string|int, mixed>
- Sorting order strings according to the corresponding setting
Methods
- changeFlagsByProductCode() : mixed
- Apply the flags to all Products matching the given Product code
- cmpPrice() : int
- Returns -1, 0, or 1 if the first Product title is smaller, equal to, or greater than the second, respectively
- cmpTitle() : int
- Returns -1, 0, or 1 if the first Product title is smaller, equal to, or greater than the second, respectively
- deleteByCode() : bool
- Delete Products bearing the given Product code from the database.
- deleteByShopCategory() : bool
- Delete Products from the ShopCategory given by its ID.
- get_image_array_from_base64() : array<string|int, mixed>
- Returns an array of image names, widths and heights from the base64 encoded string taken from the database
- getByCustomId() : mixed
- Returns an array of Product objects sharing the same Product code.
- getByShopParams() : array<string|int, mixed>
- Returns an array of Products selected by parameters as available in the Shop.
- getDefaultViewMenuoptions() : string
- Returns HTML code for dropdown menu options to choose the default view on the Shop starting page.
- getIdArrayByShopCategory() : mixed
- Returns an array of Product IDs contained by the given ShopCategory ID.
- getJavascriptArray() : mixed
- getMenuoptions() : array<string|int, mixed>
- Returns a string with HTML options for any menu
- getNameArray() : array<string|int, mixed>
- Returns an array of Product names from the database
- getPictureByCategoryId() : string
- Returns the first matching picture name found in the Products within the Shop Category given by its ID.
- getProductSortingMenuoptions() : string
- Returns the HTML dropdown menu options for the product sorting order menu
- getQueryParts() : string
- Builds and returns a database query for Products
- getShopCategoryIdArrayByFlag() : mixed
- Returns an array of ShopCategory IDs containing Products with their flags containing the given string.
- makeThumbnailsById() : bool
- Create thumbnails and update the corresponding Product records
- set_active() : bool
- Set the active status of all Products for the given IDs
Constants
DEFAULT_VIEW_COUNT
public
mixed
DEFAULT_VIEW_COUNT
= 4
DEFAULT_VIEW_DISCOUNTS
public
mixed
DEFAULT_VIEW_DISCOUNTS
= 2
DEFAULT_VIEW_LASTFIVE
public
mixed
DEFAULT_VIEW_LASTFIVE
= 3
DEFAULT_VIEW_MARKED
public
mixed
DEFAULT_VIEW_MARKED
= 1
DEFAULT_VIEW_NONE
public
mixed
DEFAULT_VIEW_NONE
= 0
Properties
$arrProductOrder
Sorting order strings according to the corresponding setting
public
static array<string|int, mixed>
$arrProductOrder
= array(1 => '`product`.`ord` ASC, `id` DESC', 2 => '`name` ASC, `code` ASC', 3 => '`code` ASC, `name` ASC')
Order 1: By order field value ascending, ID descending Order 2: By name ascending, Product ID ascending Order 3: By Product ID ascending, name ascending
Tags
Methods
changeFlagsByProductCode()
Apply the flags to all Products matching the given Product code
public
static changeFlagsByProductCode(int $productCode, string $strNewFlags) : mixed
Any Product and ShopCategory carrying one or more of the names of any ShopCategory marked as "VIRTUAL" is cloned and added to that category. Those having any such flags removed are deleted from the respective category. Identical copies of the same Products are recognized by their "product_id" (the Product code).
Note that in this current version, only the flags of Products are tested and applied. Products are cloned and added together with their immediate parent ShopCategories (aka "Article").
Thus, all Products within the same "Article" ShopCategory carry the same flags, as does the containing ShopCategory itself.
Parameters
- $productCode : int
-
The Product code (NOT the ID). This must be non-empty!
- $strNewFlags : string
-
The new flags for the Product
Tags
cmpPrice()
Returns -1, 0, or 1 if the first Product title is smaller, equal to, or greater than the second, respectively
public
static cmpPrice(Product $objProduct1, Product $objProduct2) : int
Parameters
Return values
int —-1, 0, or 1
cmpTitle()
Returns -1, 0, or 1 if the first Product title is smaller, equal to, or greater than the second, respectively
public
static cmpTitle(Product $objProduct1, Product $objProduct2) : int
Parameters
Return values
int —-1, 0, or 1
deleteByCode()
Delete Products bearing the given Product code from the database.
public
static deleteByCode(int $productCode, bool $flagDeleteImages) : bool
Parameters
- $productCode : int
-
The Product code. This MUST be non-empty!
- $flagDeleteImages : bool
-
If true, Product images are deleted as well
Tags
Return values
bool —True on success, false otherwise
deleteByShopCategory()
Delete Products from the ShopCategory given by its ID.
public
static deleteByShopCategory(int $category_id[, bool $flagDeleteImages = false ][, bool $recursive = false ]) : bool
If deleting one of the Products fails, aborts and returns false immediately without trying to delete the remaining Products. Deleting the ShopCategory after this method failed will most likely result in Product bodies in the database!
Parameters
- $category_id : int
-
The ShopCategory ID
- $flagDeleteImages : bool = false
-
Delete images, if true
- $recursive : bool = false
-
Delete Products from subcategories, if true
Tags
Return values
bool —True on success, null on noop, false otherwise
get_image_array_from_base64()
Returns an array of image names, widths and heights from the base64 encoded string taken from the database
public
static get_image_array_from_base64(string $base64Str) : array<string|int, mixed>
The array returned looks like
array(
1 => array(
'img' =>
Parameters
- $base64Str : string
-
The base64 encoded image string
Tags
Return values
array<string|int, mixed> —The decoded image array
getByCustomId()
Returns an array of Product objects sharing the same Product code.
public
static getByCustomId(string $customId) : mixed
Parameters
- $customId : string
-
The Product code
Tags
Return values
mixed —The array of matching Product objects on success, false otherwise.
getByShopParams()
Returns an array of Products selected by parameters as available in the Shop.
public
static getByShopParams(int &$count[, int $offset = 0 ][, int|array<string|int, mixed> $product_id = null ][, int $category_id = null ][, int $manufacturer_id = null ][, string $pattern = null ][, bool $flagSpecialoffer = false ][, bool $flagLastFive = false ][, int $orderSetting = '' ][, bool $flagIsReseller = null ][, bool $flagShowInactive = false ]) : array<string|int, mixed>
The $count parameter is set to the number of records found. After it returns, it contains the actual number of matching Products.
Parameters
- $count : int
-
The desired number of Products, by reference. Set to the actual total matching number.
- $offset : int = 0
-
The Product offset
- $product_id : int|array<string|int, mixed> = null
-
The optional Product ID, or an array of such
- $category_id : int = null
-
The ShopCategory ID
- $manufacturer_id : int = null
-
The Manufacturer ID
- $pattern : string = null
-
A search pattern
- $flagSpecialoffer : bool = false
-
Limit results to special offers if true. Disabled if either the Product ID, Category ID, Manufacturer ID, or the search pattern is non-empty.
- $flagLastFive : bool = false
-
Limit results to the last five Products added to the Shop if true. Note: You may specify an integer count as well, this will set the limit accordingly.
- $orderSetting : int = ''
-
The sorting order setting, defaults to the order field value ascending, Product ID descending
- $flagIsReseller : bool = null
-
The reseller status of the current customer, ignored if it's the empty string
- $flagShowInactive : bool = false
-
Include inactive Products if true. Backend use only!
Tags
Return values
array<string|int, mixed> —Array of Product objects, or false if none were found
getDefaultViewMenuoptions()
Returns HTML code for dropdown menu options to choose the default view on the Shop starting page.
public
static getDefaultViewMenuoptions([int $selected = '' ]) : string
Possible choices are defined by global constants self::DEFAULT_VIEW_* and corresponding language variables.
Parameters
- $selected : int = ''
-
The optional preselected view index
Tags
Return values
string —The HTML menu options
getIdArrayByShopCategory()
Returns an array of Product IDs contained by the given ShopCategory ID.
public
static getIdArrayByShopCategory(int $category_id) : mixed
Orders the array by ascending ordinal field value
Parameters
- $category_id : int
-
The ShopCategory ID
Tags
Return values
mixed —The array of Product IDs on success, false otherwise.
getJavascriptArray()
public
static getJavascriptArray([mixed $groupCustomerId = 0 ][, mixed $isReseller = false ]) : mixed
Parameters
- $groupCustomerId : mixed = 0
- $isReseller : mixed = false
getMenuoptions()
Returns a string with HTML options for any menu
public
static getMenuoptions([int $selected = null ][, bool $active = null ][, string $format = '%2$s' ][, bool $showAllOptions = true ]) : array<string|int, mixed>
Includes Products with the given active status only if $active is not null. The options' values are the Product IDs. The sprintf() format for the options defaults to "%2$s", possible values are:
- %1$u: The Product ID
- %2$s: The Product name
Parameters
- $selected : int = null
-
The optional preselected Product ID
- $active : bool = null
-
Optional. Include active (true) or inactive (false) Products only. Ignored if null. Defaults to null
- $format : string = '%2$s'
-
The optional sprintf() format
- $showAllOptions : bool = true
-
Show all options and not only the selected
Tags
Return values
array<string|int, mixed> —The HTML options string on success, null otherwise
getNameArray()
Returns an array of Product names from the database
public
static getNameArray([bool $activeonly = false ][, string $format = '%2$s' ]) : array<string|int, mixed>
The array is indexed by the Product ID and ordered by the names and ID, ascending. The names array is kept in this method statically between calls.
Parameters
- $activeonly : bool = false
-
Optional. Include active (true) or inactive (false) Products only. Ignored if null. Defaults to null
- $format : string = '%2$s'
-
The optional sprintf() format
Tags
Return values
array<string|int, mixed> —The array of Product names on success, false otherwise
getPictureByCategoryId()
Returns the first matching picture name found in the Products within the Shop Category given by its ID.
public
static getPictureByCategoryId(type $category_id) : string
Parameters
- $category_id : type
Tags
Return values
string —The image name, or the empty string.
getProductSortingMenuoptions()
Returns the HTML dropdown menu options for the product sorting order menu
public
static getProductSortingMenuoptions() : string
Tags
Return values
string —The HTML code string
getQueryParts()
Builds and returns a database query for Products
public
static getQueryParts([int|array<string|int, mixed> $product_id = null ][, int|string $category_id = null ][, int $manufacturer_id = null ][, string $pattern = null ][, int $flagSpecialoffer = false ][, bool $flagLastFive = false ][, int|string $orderSetting = '' ][, bool $flagIsReseller = null ][, bool $flagShowInactive = false ]) : string
Parameters
- $product_id : int|array<string|int, mixed> = null
-
The optional Product ID, an array of such, or null
- $category_id : int|string = null
-
The optional Category ID, or comma separated list
- $manufacturer_id : int = null
-
The optional manufacturer ID
- $pattern : string = null
-
The optional search term
- $flagSpecialoffer : int = false
-
The optional special offer flag
- $flagLastFive : bool = false
-
The optional "last five" flag
- $orderSetting : int|string = ''
-
The optional order setting, or SQL string
- $flagIsReseller : bool = null
-
The optional reseller flag
- $flagShowInactive : bool = false
-
The optional inactive flag
Return values
string —The SQL query
getShopCategoryIdArrayByFlag()
Returns an array of ShopCategory IDs containing Products with their flags containing the given string.
public
static getShopCategoryIdArrayByFlag(string $strName) : mixed
Parameters
- $strName : string
-
The name of the flag to match
Tags
Return values
mixed —The array of ShopCategory IDs on success, false otherwise.
makeThumbnailsById()
Create thumbnails and update the corresponding Product records
public
static makeThumbnailsById(int $arrId) : bool
Scans the Products with the given IDs. If a non-empty picture string with a reasonable extension is encountered, determines whether the corresponding thumbnail is available and up to date or not. If not, tries to load the file and to create a thumbnail. If it succeeds, it also updates the picture field with the base64 encoded entry containing the image width and height. Note that only single file names are supported! Also note that this method returns a string with information about problems that were encountered. It skips records which contain no or invalid image names, thumbnails that cannot be created, and records which refuse to be updated! The reasoning behind this is that this method is currently only called from within some methods. The focus lies on importing Products; whether or not thumbnails can be created is secondary, as the process can be repeated if there is a problem.
Parameters
- $arrId : int
-
The array of Product IDs
Tags
Return values
bool —True on success, false on any error
set_active()
Set the active status of all Products for the given IDs
public
static set_active(array<string|int, mixed> $arrId, bool $active) : bool
Depending on $active, activates (true) or deactivates (false) the Products. If no valid ID is present in $arrId, returns null.
Parameters
- $arrId : array<string|int, mixed>
-
The array of Product IDs
- $active : bool
-
The desired active status
Return values
bool —True on success, null on no operation, false otherwise