Ka Extensions for OpenCart 3

This documentation applies to Ka Extensions for OpenCart 3.x only. It is not compatible with OpenCart 4.

Format
in component

Formatting values with language based

Table of Contents

Constants

DEFAULT_SIZE_UNITS  = ['bytes' => 'bytes', 'kb' => 'Kb', 'mb' => 'Mb', 'gb' => 'Gb']
Default labels of byte size units. They are used when the language file does not
define the text_unit_* keys and by the static formatBytes() method.
DEFAULT_TIME_UNITS  = ['days' => 'days', 'hours' => 'hours', 'minutes' => 'minutes', 'seconds' => 'seconds']
Default labels of time units. They are used when the language file does not
define the text_days, text_hours, text_minutes, text_seconds keys.
LANGUAGE_FILE  = 'extension/ka_extensions/ka_extensions/ka_format'
The language file of the class (admin and catalog areas)

Properties

Methods

__construct()  : mixed
$language_id - language identifier. When it is empty, the current language of the area is used
(config_language).
convertToByte()  : mixed
convertToMegabyte()  : mixed
formatBytes()  : mixed
Converts a number of bytes to a human readable string like '10.1 Mb'. It does not need a language
and can be called statically.
formatDate()  : mixed
formatLength()  : mixed
formatPassedTime()  : mixed
formatPrice()  : mixed
formatWeight()  : mixed
getLengthUnit()  : mixed
getSizeUnits()  : mixed
Returns labels of byte size units ('bytes', 'kb', 'mb', 'gb') from the language file
with the English defaults.
getWeightUnit()  : mixed
parseBytes()  : mixed
Converts a size value to bytes. It does not need a language and can be called statically.
parseLength()  : mixed
parsePrice()  : mixed
parseWeight()  : mixed
strip()  : mixed
findLanguage()  : mixed
Returns the language record (language_id, code, directory) or false if it is not found.
getText()  : mixed
Returns a language text or the default value when the language does not have the key.

Constants

DEFAULT_SIZE_UNITS

Default labels of byte size units. They are used when the language file does not define the text_unit_* keys and by the static formatBytes() method.

public mixed DEFAULT_SIZE_UNITS = ['bytes' => 'bytes', 'kb' => 'Kb', 'mb' => 'Mb', 'gb' => 'Gb']

DEFAULT_TIME_UNITS

Default labels of time units. They are used when the language file does not define the text_days, text_hours, text_minutes, text_seconds keys.

public mixed DEFAULT_TIME_UNITS = ['days' => 'days', 'hours' => 'hours', 'minutes' => 'minutes', 'seconds' => 'seconds']

LANGUAGE_FILE

The language file of the class (admin and catalog areas)

public mixed LANGUAGE_FILE = 'extension/ka_extensions/ka_extensions/ka_format'

Properties

$language

protected mixed $language

$language_id

protected mixed $language_id

$model_localisation_language

protected mixed $model_localisation_language

$registry

protected mixed $registry

Methods

__construct()

$language_id - language identifier. When it is empty, the current language of the area is used (config_language).

public __construct([mixed $language_id = null ]) : mixed

When the language is not found, the class works with the default (English) labels instead of stopping with a fatal error.

Parameters
$language_id : mixed = null

convertToByte()

public convertToByte(mixed $file_size) : mixed
Parameters
$file_size : mixed

convertToMegabyte()

public convertToMegabyte(mixed $val) : mixed
Parameters
$val : mixed

formatBytes()

Converts a number of bytes to a human readable string like '10.1 Mb'. It does not need a language and can be called statically.

public static formatBytes(mixed $bytes[, mixed $precision = 1 ][, mixed $units = [] ]) : mixed

Parameters: $bytes - number of bytes or a size string supported by parseBytes() like '10M' $precision - number of decimal digits $units - optional labels of units: ['bytes' => .., 'kb' => .., 'mb' => .., 'gb' => ..]. Missing labels are taken from DEFAULT_SIZE_UNITS.

Parameters
$bytes : mixed
$precision : mixed = 1
$units : mixed = []

formatDate()

public formatDate(mixed &$date) : mixed
Parameters
$date : mixed

formatLength()

public formatLength(mixed $val, mixed $class_id[, mixed $decimal_point = '.' ][, mixed $thousand_point = '' ]) : mixed
Parameters
$val : mixed
$class_id : mixed
$decimal_point : mixed = '.'
$thousand_point : mixed = ''

formatPassedTime()

public formatPassedTime(mixed $diff) : mixed
Parameters
$diff : mixed

formatPrice()

public formatPrice(mixed $price[, mixed $new = false ]) : mixed
Parameters
$price : mixed
$new : mixed = false

formatWeight()

public formatWeight(mixed $val, mixed $class_id[, mixed $decimal_point = '.' ][, mixed $thousand_point = '' ]) : mixed
Parameters
$val : mixed
$class_id : mixed
$decimal_point : mixed = '.'
$thousand_point : mixed = ''

getLengthUnit()

public getLengthUnit(mixed $class_id) : mixed
Parameters
$class_id : mixed

getSizeUnits()

Returns labels of byte size units ('bytes', 'kb', 'mb', 'gb') from the language file with the English defaults.

public getSizeUnits() : mixed

getWeightUnit()

public getWeightUnit(mixed $class_id) : mixed
Parameters
$class_id : mixed

parseBytes()

Converts a size value to bytes. It does not need a language and can be called statically.

public static parseBytes(mixed $value) : mixed

Supported values: 512, '512', '1.5G', '1,5G', '2M', '128K', '128k', '10 Mb', '10 KB', '100 bytes', '-1'. Suffixes K, M, G, T (case-insensitive) are multiples of 1024, an optional 'b' or 'bytes' after them is allowed. Values like PHP ini '-1' are returned as -1.

Unrecognized values are converted with (int) as is.

Returns: integer number of bytes

Parameters
$value : mixed

parseLength()

public parseLength(mixed $length) : mixed
Parameters
$length : mixed

parsePrice()

public parsePrice(mixed $price) : mixed
Parameters
$price : mixed

parseWeight()

public parseWeight(mixed $weight) : mixed
Parameters
$weight : mixed

strip()

public strip(mixed $str, mixed $chars) : mixed
Parameters
$str : mixed
$chars : mixed

findLanguage()

Returns the language record (language_id, code, directory) or false if it is not found.

protected findLanguage([mixed $language_id = null ]) : mixed

The list of languages is read once per request and area.

Parameters
$language_id : mixed = null

getText()

Returns a language text or the default value when the language does not have the key.

protected getText(mixed $key, mixed $default) : mixed
Parameters
$key : mixed
$default : mixed

        
On this page

Search results