ePages 7.37.0 - DE_EPAGES/Shop/API/Resource/Formatter.pm

Package DE_EPAGES::Shop::API::Resource::Formatter

formatter class for shop-dependend REST resources.

Functions

bool
locale
new
percentage
price
quantity
shop
unit

bool

Returns a formatted boolean in json format

Syntax
$Bool = $Formatter->bool($Value);
Example
$hStruct = { isAvaliabe => $Formatter->bool($IsAvailable) };
$Bool = $Formatter->bool( $x < $y );
Input
$Value (boolean)
unformatted boolean value
Return
$Bool (JSON::XS::true or JSON::XS::false)
formated boolean value

locale

Returns the locale.

Syntax
$Locale = $Formatter->locale;
Return
$Locale (DE_EPAGES::Object::API::Object::SiteLocale)
locale of the formatter

new

Create a new Formatter object for a given shop to provide some format methods.

Syntax
$Formatter = DE_EPAGES::Shop::API::Resource::Formatter->new($Shop, $LocaleID);
Example
$Formatter = DE_EPAGES::Shop::API::Resource::Formatter->new($Object->getSite,'de_DE');
Input
$Shop (DE_EPAGET::Shop::API::Object::Shop)
shop object
$LocaleID (string)
locale string i.e. 'de_DE'
Return
$Formatter (DE_EPAGES::Shop::API::Resource::Formatter)
formatter

percentage

Returns a formatted percentage representation

Syntax
$hPercentage = $Formatter->percentage($Percentage);
Example
$hStruct = { percentage => $Formatter->percentage($Percentage) }
Input
$Percentage (integer)
percentage value
Return
$hPercentage (ref.hash)
formated percentage for use in a JSON structure, hash keys are:
  • percentage - percentage value - float
  • formatted - value with percentage symbol - string

price

Returns a formatted price of amount and currency symbol as defined for the formatter locale

Syntax
$hPrice = $Formatter->price($Amount, $CurrencyID, $TaxModel);
Example
$hPrice = $Formatter->price(27.25, 'EUR', undef);
$hPrice = $Formatter->price(1, 'GBP', TAX_MODEL_GROSS);
Input
$Amount (float)
amount value
$CurrencyID (string)
currency string i.e. 'EUR'
$TaxModel (integer)
locale string i.e. 'de_DE'
Return
$hPrice (ref.hash)
formated price for use in a JSON structure, hash keys are:
  • amount - price value - float
  • currency - currency id, e.g. 'USD' - string
  • locale - locale id, e.g. 'en_US'
  • taxType - tax included? GROSS/NET/NONE

quantity

Returns a formatted qunatity in json format

Syntax
$hQuantity = $Formatter->quantity($Amount);
$hQuantity = $Formatter->quantity($Amount, $Unit);
Example
$hStruct = { quantity => $Formatter->quantity(1) }
$hStruct = { quantity => $Formatter->quantity(1,$Unit) }
Input
$Amount (float)
amount value
$Unit (DE_EPAGES::Object::API::Object::UnitOfMeasurement)
(optional) unit of measurement
Return
$hQuantity (JSON::true or JSON::false)
formated quantity value

shop

Returns the shop.

Syntax
$Shop = $Formatter->shop;
Return
$Shop (DE_EPAGES::Shop::API::Object::Shop)
shop of the current request

unit

Returns a formatted unit representation

Syntax
$UnitName = $Formatter->unit($Unit);
Example
$hStruct = { unit => $Formatter->unit($Unit) }
Input
$Unit (DE_EPAGES::Object::API::Object::UnitOfMeasurement)
unit of measurement
Return
$UnitName (string)
representation of unit (symbol or name)