Skip to content
Malouf Developer Docs

Common

Common

Filters

Adds globally available filters to format data that is frequently used.

currency

Cart and order values are returned from HQ as Minor Integers, which formats numbers without the decimal point (e.g., HQ returning 2345 represents 23.45). To account for this, the Dinero plugin accepts the minor int and converts it to a user-friendly value. ::: details Example: Cart Subtotals

<div class="mc-totals-wrap">
    <h2>Totals</h2>
    <div class="mc-totals">
        <p><span class="mc-total-property">Subtotal:</span> <span class="mc-total-value">{{ cart.totals.subtotal | currency}}</span></p>
        <p><span class="mc-total-property">Discount:</span> <span class="mc-total-value">{{ cart.totals.discount | currency}}</span></p>
        <p><span class="mc-total-property">Tax:</span> <span class="mc-total-value">{{ cart.totals.tax | currency }}</span></p>
        <p><span class="mc-total-property">Shipping:</span> <span class="mc-total-value">{{ cart.totals.shipping | currency}}</span></p>
        <p><span class="mc-total-property">Total:</span> <span class="mc-total-value">{{ cart.totals.total | currency}}</span></p>
    </div>
</div>

:::

formatting

Formatting provides an interface that can be added to with additional functions that format text (to keep consistent). The ucfirst() function is designed to accept a single string literal (word) and return the value of that string with the first letter capitalized (e.g., category => Category).

phoneNumber

Phone numbers are most often stored as a string of numbers without any additional characters, but this is difficult to read when displaying a number to the users. This filter will accept a string containing the number, clean and match it to verify the length and format, and finally return the newly formatted phone number (e.g., 8013219876 => (801) 321-9876)

Utils

Utility functions that are used within sites or within the SDK

isClient

Frequently used to verify the location of a method call. Bots can scrub a website and activate buttons that could trigger functions such as tracking or email marketing, so to prevent this we verify that the window exists before allowing these method calls. ::: details Example: Check isClient Before Tracking

if (process.isClient && window._dcq) {
    _dcq.push(["identify", {
        email: this.address.email,
        first_name: this.address.first_name,
        last_name: this.address.last_name,
        address1: this.address.street_1,
        address2: this.address.street_2,
        city: this.address.locality,
        state: this.address.region,
        zip: this.address.postcode,
        country: this.address.country,
        phone: this.address.phone
    }])
}

:::

minorCurrency

Used by the Currency filter, this utility accepts a value and attempts to parse it into an integer or float value, returning that parsed number to be used by the Dinero formatting tool. If the value passed in contains any unsupported characters, it will throw an error.