Skip to main content
Reference

FormatHelper SFO

Properties

FieldTypeComment/Sample

Methods

MethodReturnsParametersParameter TypesComments/Sample
arrayFromCSV(csv)[Array](./array-sfo.md)csvstringparses a string by csv and returns back an array.
contains(text,search)booleantext searchstring stringreturns true if text contains search within it
copy(collection)[Array](./array-sfo.md)collection[Array](./array-sfo.md)creates a copy of an array and returns it
doesIPAddresMatch(address, matchAddresses)booleanaddress matchAddressesstring [Array](./array-sfo.md) of stringchecks 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)booleanstr1 str2string stringreturns true if the two strings match in a case-insensitive manner
escapeHtml(input)stringinputstringescapes a string of html
escapeJavascript(input)stringinputstringescapes a string of javascript
exerpt(input, maxLength)stringinput
maxLength
string
integer
takes a chuck of text and returns back the first maxLength characters of it.
exerptSentence(input, maxLength)stringinput
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)stringxhtml maxLengthstring integerreturns back an except from a block of xhtml
excerptXhtml(xhtml, maxLength, finishSentence)stringxhtml maxLength finishSentencestring integer booleanreturns 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](./array-sfo.md)collection attributeName attributeValue removeOnMatch[Array](./array-sfo.md) string string booleanfilters 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)voiditems[Array](./array-sfo.md) of [Item](./item-sfo.md)loops through a collection and removes any items that do not have an ebay auction id associated with it.
filterByElderOfItem(groups)voidgroups[Array](./array-sfo.md) of [ProductGroup](./productgroup-sfo.md)loops through a collection of product groups and removes any that does not have at least one item assigned to it
firstLine(str)stringstrstringexamines a string and returns the characters preceeding the first newline
formatDate(timestamp, format, timezone)stringtimestamp
format
timezone
[Timestamp](https://docs.oracle.com/javase/8/docs/api/java/sql/Timestamp.html)
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)objectobjects index[Array](./array-sfo.md) of objects integerreturns the object found at the index position of the objects array.
getItemsForPage(objects, pageNumber, itemsPerPage)[Array](./array-sfo.md) of [Item](./item-sfo.md)objects pageNumber itemsPerPage[Array](./array-sfo.md) of [Item](./item-sfo.md)\\integer integertakes an array of items and returns back a slice to help with pagination
getPageCount(objects, itemsPerPage)integerobjects itemsPerPage[Array](./array-sfo.md) of [Item](./item-sfo.md) integerreturns the count of items. objects.size() will do the same thing.
getWordCount(str)integerstrstringreturns the number of words in a string
htmlId(str)stringstrstringtakes a string and returns a valid string for an html id. Strips out invalid characters.
indexOf(text,search)integertext searchstring stringreturns the index of search if it is found in text, or -1 otherwise
injectAfter(str,search,occurrence,inject)stringstr
search
occurrence inject
string
string
integer string
injects the string variable 'inject' after the nth occurrence of the search variable.
isBetween(s, d1, d2)booleans
d1 d2
string
double double
true if the value converts to a number that is between d1 and d2.
isOutsideTraffic(referrer, hostName)booleanreferrer
hostName
string
string
notNull(str)booleanstrstringreturns true if the string is not null
parseBigDecimal(obj)[BigDecimal](./bigdecimal-sfo.md)objobjectparses an object and returns back a BigDecimal
parseInt(str)integerstrstringparses a string and returns an integer
random(collection)objectcollection[Array](./array-sfo.md) of objectsreturns a random object from an array
random(collection, count)[Array](./array-sfo.md) of objectscollection count[Array](./array-sfo.md) of objects integerreturns n count of random objects from an array
random(num)integernuninteger
removeHtml(str)stringstrstringstrips html from a string
removeItemsWithoutCost(items)[Array](./array-sfo.md) of [Item](./item-sfo.md)items[Array](./array-sfo.md) of [Item](./item-sfo.md)removes all items from an array which are free
removeNewLines(str)stringstrstringconverts all newlines to a single space each
removeOutOfStockItems(items)[Array](./array-sfo.md) of [Item](./item-sfo.md)items[Array](./array-sfo.md) of [Item](./item-sfo.md)removes all items from an array which are out of stock
removeOutOfStockItems(items,keepBackorderable,keepPreorder)[Array](./array-sfo.md) of [Item](./item-sfo.md)items[Array](./array-sfo.md) of [Item](./item-sfo.md)removes all items from an array which are out of stock and not preorder nor backorder
replaceNewLinesWithHtmlBreaks(str)stringstrstringconverts newlines to
tags. Useful for displaying long item descriptions or terms and conditions in a nicely formatted paragraph.
replaceStr(str, search, replace)stringstr
search replace
string
string string
does a search and replace on a string
reverse(collection)[Array](./array-sfo.md) of objectscollection[Array](./array-sfo.md)reverses a collection based on ordinal position
singleLine(str)stringstrstringremoves newlines from a string
sort(items, sortMap)[Array](./array-sfo.md) of [Item](./item-sfo.md)items sortMap[Array](./array-sfo.md) of [Item](./item-sfo.md) [Array](./array-sfo.md) of stringsorts a collection of items by a list of sort values (i.e. Small, Medium, Large, X-Large, etc)
sortAttributesByName(attributes)[Array](./array-sfo.md) of Attributesattributes[Array](./array-sfo.md) of Attributessorts 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](./array-sfo.md) of [Item](./item-sfo.md)items
attributeName ascending
[Array](./array-sfo.md) of [Item](./item-sfo.md) string booleansorts 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](./array-sfo.md) of [Item](./item-sfo.md)items
attributes ascendings
[Array](./array-sfo.md) of [Item](./item-sfo.md) [Array](./array-sfo.md) of string [Array](./array-sfo.md) of booleansorts 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](./array-sfo.md) of stringsstrings
ascending
[Array](./array-sfo.md) of strings booleansorts an array of strings
sortByItemId(items)[Array](./array-sfo.md) of [Item](./item-sfo.md)items[Array](./array-sfo.md) of [Item](./item-sfo.md)sorts a collection of items by item id.
sortByPrice(items, ascending)[Array](./array-sfo.md) of [Item](./item-sfo.md)items ascending[Array](./array-sfo.md) of [Item](./item-sfo.md) booleansorts a collection of items. ascending is a an optional parameter that can be used to sort high-low if desired.
sortByReviewOverall(items, ascending)[Array](./array-sfo.md) of [Item](./item-sfo.md)items ascending[Array](./array-sfo.md) of [Item](./item-sfo.md) booleansorts 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)integerav1
av2 ascending
string string booleancompares 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](./array-sfo.md) of [ItemReview](./itemreview-sfo.md)reviews
sortOn ascending
[Array](./array-sfo.md) of [ItemReview](./itemreview-sfo.md) string booleansorts an array of reviews based on the sortOn fields. Valid values for sortOn are "featured", "date", "rating", "helpfulness", "length", "reviewRank", "expert"
toLowerCase(s)stringstrstringconverts a string to lower case
toUpperCase(s)stringstrstringconverts a string to upper case
trimIfTooLong(str,len)stringstr lenstring integertrims a string if it exceeds 'len'
urlDecode(str)stringstrstrurl decodes a string
urlEncode(str)stringstrstringurl encodes a string

See Also

Was this page helpful?