FormatHelper SFO
Properties
| Field | Type | Comment/Sample |
|---|
Methods
| Method | Returns | Parameters | Parameter Types | Comments/Sample |
|---|---|---|---|---|
arrayFromCSV(csv) | [Array](./array-sfo.md) | 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](./array-sfo.md) | collection | [Array](./array-sfo.md) | creates a copy of an array and returns it |
doesIPAddresMatch(address, matchAddresses) | boolean | address matchAddresses | string [Array](./array-sfo.md) 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 | inputmaxLength | stringinteger | takes a chuck of text and returns back the first maxLength characters of it. |
exerptSentence(input, maxLength) | string | inputmaxLength | stringinteger | 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) | string | xhtml 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](./array-sfo.md) | collection attributeName attributeValue removeOnMatch | [Array](./array-sfo.md) 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](./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) | void | groups | [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) | string | str | string | examines a string and returns the characters preceeding the first newline |
formatDate(timestamp, format, timezone) | string | timestampformattimezone | [Timestamp](https://docs.oracle.com/javase/8/docs/api/java/sql/Timestamp.html)stringstring (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](./array-sfo.md) of objects integer | returns 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 integer | takes an array of items and returns back a slice to help with pagination |
getPageCount(objects, itemsPerPage) | integer | objects itemsPerPage | [Array](./array-sfo.md) of [Item](./item-sfo.md) 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 | strsearchoccurrence inject | stringstringinteger string | injects the string variable 'inject' after the nth occurrence of the search variable. |
isBetween(s, d1, d2) | boolean | sd1 d2 | stringdouble double | true if the value converts to a number that is between d1 and d2. |
isOutsideTraffic(referrer, hostName) | boolean | referrerhostName | stringstring | |
notNull(str) | boolean | str | string | returns true if the string is not null |
parseBigDecimal(obj) | [BigDecimal](./bigdecimal-sfo.md) | 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](./array-sfo.md) of objects | returns a random object from an array |
random(collection, count) | [Array](./array-sfo.md) of objects | collection count | [Array](./array-sfo.md) 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](./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) | string | str | string | converts 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) | string | str | string | converts newlines to tags. Useful for displaying long item descriptions or terms and conditions in a nicely formatted paragraph. |
replaceStr(str, search, replace) | string | strsearch replace | stringstring string | does a search and replace on a string |
reverse(collection) | [Array](./array-sfo.md) of objects | collection | [Array](./array-sfo.md) | reverses a collection based on ordinal position |
singleLine(str) | string | str | string | removes 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 string | sorts 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 Attributes | attributes | [Array](./array-sfo.md) 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](./array-sfo.md) of [Item](./item-sfo.md) | itemsattributeName ascending | [Array](./array-sfo.md) of [Item](./item-sfo.md) 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](./array-sfo.md) of [Item](./item-sfo.md) | itemsattributes ascendings | [Array](./array-sfo.md) of [Item](./item-sfo.md) [Array](./array-sfo.md) of string [Array](./array-sfo.md) 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](./array-sfo.md) of strings | stringsascending | [Array](./array-sfo.md) of strings boolean | sorts 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) 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](./array-sfo.md) of [Item](./item-sfo.md) | items ascending | [Array](./array-sfo.md) of [Item](./item-sfo.md) 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 | av1av2 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](./array-sfo.md) of [ItemReview](./itemreview-sfo.md) | reviewssortOn ascending | [Array](./array-sfo.md) of [ItemReview](./itemreview-sfo.md) 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
Was this page helpful?