FormatHelper SFO

Properties

Field

Type

Comment/Sample

Methods

Method

Returns

Parameters

Parameter Types

Comments/Sample

arrayFromCSV(csv)

Array

csv

string

parses a string by csv and returns back an array.

contains(text,search)

boolean

text
search

string
string

returns true if text contains search within it

copy(collection)

Array

collection

Array

creates a copy of an array and returns it

doesIPAddresMatch(address, matchAddresses)

boolean

address
matchAddresses

string
Array of string

checks to see if address matches any of the ip addresses in the matchAddresses array and returns true if a match is made

equalsIgnoreCase(str1,str2)

boolean

str1
str2

string
string

returns true if the two strings match in a case-insensitive manner

escapeHtml(input)

string

input

string

escapes a string of html

escapeJavascript(input)

string

input

string

escapes a string of javascript

exerpt(input, maxLength)string

input

maxLength

string

integer

takes a chuck of text and returns back the first maxLength characters of it.
exerptSentence(input, maxLength)string

input

maxLength

string

integer

takes a chuck of text and returns back the first maxLength characters of it. If the chunk contains a period, The routine finds the last period within the excerpt and returns everything up to and including that period. This allows for excerpts that are whole sentences.

excerptXhtml(xhtml, maxLength)

string

xhtml
maxLength

string
integer

returns back an except from a block of xhtml

excerptXhtml(xhtml, maxLength, finishSentence)stringxhtml
maxLength
finishSentence 

string
integer
boolean 

returns back an except from a block of xhtml, but it will finish out the sentence so that there is not an odd break.

filterByAttribute(collection, attributeName, attributeValue, removeOnMatch)

Array

collection
attributeName
attributeValue
removeOnMatch

Array
string
string
boolean

filters a collection and removes any members that do not have a matching attribute name/value pair. The last parameter flips this behavior by removing any matches

filterByEbay(items)

void

items

Array of Item

loops through a collection and removes any items that do not have an ebay auction id associated with it.

filterByElderOfItem(groups)

void

groups

Array of ProductGroup

loops through a collection of product groups and removes any that does not have at least one item assigned to it

firstLine(str)

string

str

string

examines a string and returns the characters preceeding the first newline

formatDate(timestamp, format, timezone)string

timestamp

format

timezone

Timestamp

string

string (optional)

This method is useful for formatting raw timestamp objects into strings. As a reminder, the UltraCart platform is java based, and this method uses the SimpleDateFormat object underneath. So the format and timezone strings should be based on that object's requirements. See the official SimpleDateFormat docs for example formats and timezones.

Sample usage: $formatHelper.formatDate($form.expirationDateRaw, "dd.MM.yyyy", "GMT")






getFromCollection(objects, index)

object

objects
index

Array of objects
integer

returns the object found at the index position of the objects array.

getItemsForPage(objects, pageNumber, itemsPerPage)

Array of Item

objects
pageNumber
itemsPerPage

Array of Item\\integer
integer

takes an array of items and returns back a slice to help with pagination

getPageCount(objects, itemsPerPage)

integer

objects
itemsPerPage

Array of Item
integer

returns the count of items. objects.size() will do the same thing.

getWordCount(str)

integer

str

string

returns the number of words in a string

htmlId(str)

string

str

string

takes a string and returns a valid string for an html id. Strips out invalid characters.

indexOf(text,search)

integer

text
search

string
string

returns the index of search if it is found in text, or -1 otherwise

injectAfter(str,search,occurrence,inject)

string

str

search

occurrence
inject

string

string

integer
string

injects the string variable 'inject' after the nth occurrence of the search variable.

isBetween(s, d1, d2)

boolean

s

d1
d2

string

double
double

true if the value converts to a number that is between d1 and d2.

isOutsideTraffic(referrer, hostName)

boolean

referrer

hostName

string

string

notNull(str)

boolean

str

string

returns true if the string is not null

parseBigDecimal(obj)

BigDecimal

obj

object

parses an object and returns back a BigDecimal

parseInt(str)

integer

str

string

parses a string and returns an integer

random(collection)

object

collection

Array of objects

returns a random object from an array

random(collection, count)

Array of objects

collection
count

Array of objects
integer

returns n count of random objects from an array

random(num)

integer

nun

integer

removeHtml(str)

string

str

string

strips html from a string

removeItemsWithoutCost(items)

Array of Item

items

Array of Item

removes all items from an array which are free

removeNewLines(str)

string

str

string

converts all newlines to a single space each

removeOutOfStockItems(items)

Array of Item

items

Array of Item

removes all items from an array which are out of stock

removeOutOfStockItems(items,keepBackorderable,keepPreorder)

Array of Item

items

Array of Item

removes all items from an array which are out of stock and not preorder nor backorder

replaceNewLinesWithHtmlBreaks(str)

string

str

string

converts newlines to <br> tags. Useful for displaying long item descriptions or terms and conditions in a nicely formatted paragraph.

replaceStr(str, search, replace)

string

str

search
replace

string

string
string

does a search and replace on a string

reverse(collection)

Array of objects

collection

Array

reverses a collection based on ordinal position

singleLine(str)

string

str

string

removes newlines from a string

sort(items, sortMap)

Array of Item

items
sortMap

Array of Item
Array of string

sorts a collection of items by a list of sort values (i.e. Small, Medium, Large, X-Large, etc)

sortAttributesByName(attributes)

Array of Attributes

attributes

Array of Attributes

sorts a collection of attributes by name. There are many different types of attributes: product group attributes, item attributes, and affiliate attributes. This method handles them all.

sortByAttribute(items, attributeName, ascending)

Array of Item

items

attributeName
ascending

Array of Item
string
boolean

sorts a collection of items by looking at the item attributes and sorting by attribute specified by the 2nd parameter. ascending is an optional value used to switch the sorting direction.

sortByAttributes(items, attributes, ascendings)

Array of Item

items

attributes
ascendings

Array of Item
Array of string
Array of boolean

sorts a collection of items by looking at the item attributes and sorting by the attribute list specified by the 2nd parameter. ascending is an optional value used to switch the sorting direction for each attribute.

sortByFirstNumber(strings, ascending)

Array of strings

strings

ascending

Array of strings
boolean

sorts an array of strings

sortByItemId(items)

Array of Item

items

Array of Item

sorts a collection of items by item id.

sortByPrice(items, ascending)

Array of Item

items
ascending

Array of Item
boolean

sorts a collection of items. ascending is a an optional parameter that can be used to sort high-low if desired.

sortByReviewOverall(items, ascending)

Array of Item

items
ascending

Array of Item
boolean

sorts a collection of items by review stars. ascending is a an optional parameter that can be used to sort high-low if desired.

sortCompare(av1, av2, ascending)

integer

av1

av2
ascending

string
string
boolean

compares the two values. Returns back -1 if av1 is less than. Returns back 1 if av2 is less than, and returns zero if they're equal. av1 and av2 may also be integers

sortReviews(reviews, sortOn, ascending)

Array of ItemReview

reviews

sortOn
ascending

Array of ItemReview
string
boolean

sorts an array of reviews based on the sortOn fields. Valid values for sortOn are "featured", "date", "rating", "helpfulness", "length", "reviewRank", "expert"

toLowerCase(s)

string

str

string

converts a string to lower case

toUpperCase(s)

string

str

string

converts a string to upper case

trimIfTooLong(str,len)

string

str
len

string
integer

trims a string if it exceeds 'len'

urlDecode(str)

string

str

str

url decodes a string

urlEncode(str)

string

str

string

url encodes a string

See Also