Change log

shopping_cart

This component fetches data relating to the shopping cart, such as any products added, order totals, tax, shipping, etc.

It's primarily used to render a shopping cart summary throughout the site and the shopping cart layout.

{% component type:"shopping_cart" %}

Parameters and Options

Parameter
Values
Required
Description
type
shopping_cart

This is the name of the entity that needs to be used for the component retrieving function.

layout
<path/to/layout>

Path to file that will contain the Liquid layout content to be parsed.

If an empty string, nothing will be rendered.
If paramater is not included, the default virtual layout will be rendered (see below).

collectionVariable
<yourLiquidVariableName>

Assigns the data to a Liquid collection enabling further access to the data on the Page or Template using Liquid.

Your collectionVariable value must only contain English letters, numbers or underscores. Spaces or special characters are not supported.

Liquid Output

The below example shows the Liquid data output from this component (for example, when using a collectionVariable to create the collection):

{
    "totalItemsCount": 2,
    "hasGiftVoucherProducts": false,
    "taxCodeId": "",
    "unitsCountHtml": "<span data-cms_cart_units_count=\"1907185188476027629\">2</span>",
    "checkoutButtonHtml": "<button class=\"system_button\" data-cms_cart_checkout=\"\">checkout</button>",
    "clearCartHtml": "<button class=\"system_button\" data-cms_cart_clear_cart=\"\">Clear cart</button>",
    "giftVoucherHtml": "<input type=\"text\" data-cms_cart_gift_voucher=\"\" value=\"\">",
    "discountCodeHtml": "<input type=\"text\" data-cms_cart_discount_code=\"\" value=\"\">",
    "deliveryPostalCode": "",
    "deliveryCity": "",
    "id": "1907185188476027629",
    "paymentIntentId": "",
    "paymentIntentClientSecret": "",
    "formatSetting": {
        "name": "Default",
        "culture": "en-US",
        "decimalsQuantity": 2,
        "currency": {
            "code": "USD",
            "symbol": "$",
            "digitalCode": "840",
            "name": "US Dollar"
        }
    },
    "domainCountry": {
        "name": "UNITED STATES",
        "code": "US"
    },
    "destinationCountry": {
        "name": "UNITED STATES",
        "code": "US"
    },
    "shippingOption": {
        "id": null,
        "shippingOptionId": null,
        "name": null,
        "price": 0.0,
        "taxPercent": 0.0,
        "taxRate": 0.0,
        "taxPrice": 0.0,
        "totalPrice": 0.0,
        "subTotalPrice": 0.0
    },
    "discount": {
        "id": null,
        "code": null,
        "type": null,
        "amount": 0.0
    },
    "giftVoucher": {
        "id": null,
        "code": null,
        "amount": 0.0,
        "balance": 0.0
    },
    "subTotalPrice": "41.9500",
    "taxPercent": "0",
    "taxRate": "0",
    "taxPrice": "1.6800",
    "discountPrice": "0.0000",
    "totalPrice": "43.6300",
    "shippingPrice": "0",
    "shippingTaxRate": "0",
    "shippingTaxPrice": "0",
    "shippingSubTotalPrice": "0",
    "shippingTotalPrice": "0",
    "giftVoucherPrice": "0.0000",
    "subTotalTaxPrice": "1.6800",
    "discountedSubTotalTaxPrice": "1.6800",
    "grandTotalPrice": "43.6300",
    "totalPriceExcludingTax": "41.9500",
    "totalPriceExcludingTaxAndGiftVoucherAmount": "41.9500",
    "taxCode": "",
    "totalPriceExcludingTaxHtml": "<span data-cms_cart_total_price_excluding_tax=\"1907185188476027629\">$41.95</span>",
    "totalPriceExcludingTaxAndGiftVoucherAmountHtml": "<span data-cms_cart_total_price_excluding_tax_and_gift_voucher_amount=\"1907185188476027629\">$41.95</span>",
    "grandTotalPriceHtml": "<span data-cms_cart_grand_total_price=\"1907185188476027629\">$43.63</span>",
    "discountPriceHtml": "<span data-cms_cart_discount_price=\"1907185188476027629\">$0.00</span>",
    "discountedSubTotalTaxPriceHtml": "<span data-cms_cart_discounted_sub_total_tax_price=\"1907185188476027629\">$1.68</span>",
    "subTotalTaxPriceHtml": "<span data-cms_cart_subtotal_tax_price=\"1907185188476027629\">$1.68</span>",
    "taxPriceHtml": "<span data-cms_cart_tax_price=\"1907185188476027629\">$1.68</span>",
    "shippingTotalPriceHtml": "<span data-cms_cart_shipping_total_price=\"1907185188476027629\">$0.00</span>",
    "shippingPriceHtml": "<span data-cms_cart_shipping_price=\"1907185188476027629\">$0.00</span>",
    "shippingTaxPriceHtml": "<span data-cms_cart_shipping_tax_price=\"1907185188476027629\">$0.00</span>",
    "shippingTaxPercentHtml": "<span data-cms_cart_shipping_tax_percent=\"1907185188476027629\">0%</span>",
    "taxPercentHtml": "<span data-cms_cart_tax_percent=\"1907185188476027629\">0%</span>",
    "giftVoucherPriceHtml": "<span data-cms_cart_gift_voucher_price=\"1907185188476027629\">$0.00</span>",
    "totalPriceHtml": "<span data-cms_cart_total=\"1907185188476027629\">$43.63</span>",
    "items": [
        {
            "id": "15049017874163171335",
            "ecommerceItemId": 2535,
            "smallImage": "/images/template-detail-dinewine-mobile@2x.png",
            "name": "DEMO Product 1",
            "type": "ModuleItem",
            "moduleId": 0,
            "SKUCode": "DEMO1",
            "quantity": 1,
            "productFileLink": null,
            "Url": "/catalogs/demo-product-1",
            "taxCode": null,
            "onSalse": true,
            "price": 39.9500,
            "taxPercent": 4.0000,
            "unitPrice": 41.9500,
            "taxPrice": 1.6800,
            "unitTotalPrice": 43.63,
            "totalPrice": 43.63,
            "unitTaxPrice": 1.67800000,
            "taxRate": 0.0400,
            "totalPriceExcludingTax": 41.9500,
            "unitRecommendedPrice": 0.0000,
            "unitRecommendedTaxPrice": 0.0,
            "unitRecommendedTotalPrice": 0.0,
            "taxPercentHtml": "<span data-cms_cart_item_tax_percent=\"15049017874163171335\">4.0000%</span>",
            "totalPriceExcludingTaxHtml": "<span data-cms_cart_item_total_without_tax=\"15049017874163171335\">$41.95</span>",
            "unitTaxPriceHtml": "<span data-cms_cart_item_unit_tax=\"15049017874163171335\">$1.68</span>",
            "unitTotalPriceHtml": "<span data-cms_cart_item_total_unit_price=\"15049017874163171335\">$43.63</span>",
            "unitPriceHtmlTotal": "<span data-cms_cart_item_total_unit_price=\"15049017874163171335\">$43.63</span>",
            "priceHtml": "<span data-cms_cart_item_price=\"15049017874163171335\">$39.95</span>",
            "unitPriceHtml": "<span data-cms_cart_item_subtotal_price=\"15049017874163171335\">$41.95</span>",
            "taxPriceHtml": "<span data-cms_cart_item_tax=\"15049017874163171335\">$1.68</span>",
            "totalPriceHtml": "<span data-cms_cart_item_total_price=\"15049017874163171335\">$43.63</span>",
            "quantityHtml": "<input type=\"number\" value=\"1\" data-cms_cart_item_quantity=\"15049017874163171335\">",
            "removeHtml": "<a href=\"javascript:\" data-cms_cart_remove_order_line=\"15049017874163171335\"><svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path d=\"M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z\" /><path d=\"M0 0h24v24H0z\" fill=\"none\" /></svg></a>",
            "taxCodeHtml": "<span data-cms_cart_tax_code_html=\"15049017874163171335\"></span>",
            "unitRecommendedPriceHtml": "<span data-cms_cart_unit_recommended_price_html=\"15049017874163171335\">$0.00</span>",
            "unitRecommendedTaxPriceHtml": "<span data-cms_cart_unit_recommended_tax_price_html=\"15049017874163171335\">$0.00</span>",
            "unitRecommendedTotalPriceHtml": "<span data-cms_cart_unit_recommended_total_price_html=\"15049017874163171335\">$0.00</span>",
            "attributes": [
                {
                    "id": "12550665647534637063",
                    "name": "Size",
                    "attributeType": "0",
                    "valueType": "FixedPrice",
                    "options": [
                        {
                            "id": "749807479205920777",
                            "name": "Medium",
                            "price": 2.0000,
                            "taxPercent": 4.0000,
                            "taxPrice": 8.00000000,
                            "image": "/images/template-crafter@2x.jpg",
                            "totalPrice": 10.00000000
                        }
                    ],
                    "subTotalPrice": 2.0000,
                    "taxPercent": 4.0000,
                    "taxPrice": 8.00000000,
                    "price": 2.0000,
                    "totalPrice": 10.00000000
                }
            ]
        },
        {
        "id": "15049017874163171336",
        "ecommerceItemId": 2536,
        "smallImage": "/images/template-detail-crafter-mobile@2x.png",
        "name": "DEMO product 2",
        "type": "ModuleItem",
        "moduleId": 0,
        "SKUCode": "DEMO2",
        "quantity": 1,
        "productFileLink": null,
        "Url": "/catalogs/demo-product-2",
        "taxCode": null,
        "onSalse": true,
        "price": 0.0000,
        "taxPercent": 0.0000,
        "unitPrice": 0.0000,
        "taxPrice": 0.0000,
        "unitTotalPrice": 0.00,
        "totalPrice": 0.00,
        "unitTaxPrice": 0.00000000,
        "taxRate": 0.0000,
        "totalPriceExcludingTax": 0.0000,
        "unitRecommendedPrice": 0.0000,
        "unitRecommendedTaxPrice": 0.0,
        "unitRecommendedTotalPrice": 0.0,
        "taxPercentHtml": "<span data-cms_cart_item_tax_percent=\"15049017874163171336\">0.0000%</span>",
        "totalPriceExcludingTaxHtml": "<span data-cms_cart_item_total_without_tax=\"15049017874163171336\">$0.00</span>",
        "unitTaxPriceHtml": "<span data-cms_cart_item_unit_tax=\"15049017874163171336\">$0.00</span>",
        "unitTotalPriceHtml": "<span data-cms_cart_item_total_unit_price=\"15049017874163171336\">$0.00</span>",
        "unitPriceHtmlTotal": "<span data-cms_cart_item_total_unit_price=\"15049017874163171336\">$0.00</span>",
        "priceHtml": "<span data-cms_cart_item_price=\"15049017874163171336\">$0.00</span>",
        "unitPriceHtml": "<span data-cms_cart_item_subtotal_price=\"15049017874163171336\">$0.00</span>",
        "taxPriceHtml": "<span data-cms_cart_item_tax=\"15049017874163171336\">$0.00</span>",
        "totalPriceHtml": "<span data-cms_cart_item_total_price=\"15049017874163171336\">$0.00</span>",
        "quantityHtml": "<input type=\"number\" value=\"1\" data-cms_cart_item_quantity=\"15049017874163171336\">",
        "removeHtml": "<a href=\"javascript:\" data-cms_cart_remove_order_line=\"15049017874163171336\"><svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path d=\"M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z\" /><path d=\"M0 0h24v24H0z\" fill=\"none\" /></svg></a>",
        "taxCodeHtml": "<span data-cms_cart_tax_code_html=\"15049017874163171336\"></span>",
        "unitRecommendedPriceHtml": "<span data-cms_cart_unit_recommended_price_html=\"15049017874163171336\">$0.00</span>",
        "unitRecommendedTaxPriceHtml": "<span data-cms_cart_unit_recommended_tax_price_html=\"15049017874163171336\">$0.00</span>",
        "unitRecommendedTotalPriceHtml": "<span data-cms_cart_unit_recommended_total_price_html=\"15049017874163171336\">$0.00</span>",
        "attributes": []
        }
    ],
    "subTotalPriceHtml": "<span data-cms_cart_subtotal=\"1907185188476027629\">$41.95</span>",
    "taxCodeHtml": "<span data-cms_cart_tax_code_html=\"1907185188476027629\"></span>",
    "Params": {
        "type": "shopping_cart",
        "collectionVariable": "shoppingCartData",
        "layout": ""
    }
}

Virtual Layout

Based on the above example, if not using any custom layout or collection, the default virtual layout will output as follows:

<div class="shoppingCartWidget" data-ecommerce_shopping_cart_widget>
    <div class="cms_cart_widget fl_left not_empty" style="display:{% if this.totalItemsCount > 0 %}block{% else %}none{% endif %};">
        <h5>Your Order</h5>
        <p><span data-ecommerce_shopping_cart_widget_items_count>{{this.totalItemsCount}}</span> item(s), Total: <span data-ecommerce_shopping_cart_widget_total_price>{{this.totalPrice | domain_money_format }}</span> </p>
        <a href="/shopping_cart" class="system_button shoppingCartLink">View Cart</a>
    </div>
    <div class="cms_cart_widget fl_left empty"  style="display:{% if this.totalItemsCount > 0 %}none{% else %}block{% endif %};">
        <h5>Shopping cart is empty.</h5>
    </div>
</div>

Accessing the Data

JSON Output

You can output the full JSON for your component data by referencing the root Liquid object {{this}} in your module’s layouts, or directly on your page, if using the collectionVariable parameter in your component tag.

For example:

{% component type: ... collectionVariable: "myData" %}

You can then render the JSON like so:

{{myData}}

For more details on using this approach, see Part 2 of the free ‘Learning Liquid Course’.

Rendering Property Values

This data is accessible in two main ways:

1. Using Liquid in a custom defined Layout via the this object (for the cart properties) and a forloop on the this.items object (for the cart products).

{% component type: "shopping_cart", layout: "/snippets/sample-cart-layout.inc" %}

Example of the custom layout file sample-cart-layout.inc

<h4>Your Cart Summary</h4>
<p>You have {{this.totalItemsCount}} item(s), with a total price of {{this.totalPrice | domain_money_format }}</p>
{% if totalItemsCount > 0 %}
<p><b>Products include:</b></p>
<ul>
    {% for p in this.items %}
    <li>{{p.name}}</li>
    {% endfor %}
</ul>
<a class="shoppingCartLink" href="/shopping_cart">Review items in cart</a>
{% endif %}

2. Directly on the Page or Template via a Liquid Collection if collectionVariable was added to the Component.

An example using collectionVariable with value "cartCollection":

{% component type: "shopping_cart", collectionVariable: "cartCollection" %}

Using the following forloop directly on the page:

<ul>
    {% for p in this.items %}
    <li>{{p.name}}</li>
    {% endfor %}
</ul>

Renders all the item names in a list:

  • Product Name 1
  • Product Name 2

Accessing a specific item within the collection. In this case the first item (zero based index), which in our example would render the value Product Name 1

{{cartCollection.items[0]['name']}}


Related Articles

  • Site Settings & Management
    Domains

    The Treepl CMS Domain settings allow you to control default domain, landing pages, domain authentication for system emails along with country and cultural settings like number and currency formatting.
  • Site Settings & Management
    Payment Settings

    Integrate various payment gateways, for multiple countries and currencies, into Treepl CMS for form payments, subscriptions and eCommerce workflows.
  • CRM
    Orders

    Orders store accounts of any payments made via the website and provide management for additional payments, invoices, order statuses, tracking info, the products purchased within the order and the details of the form submission used to take the order.
  • CRM
    Advanced CRM Groups

    Advanced CRM Groups allow you to extend the data fields within multiple areas of the CRM, either globally or on a per-record basis.
  • Liquid Objects & Usage
    {{ order }} object

    This liquid object will output the order details of a submitted payment. ...
  • Liquid Components
    module (Catalogs)

    This module component fetches data relating to eCommerce Catalogs and can be used to render Catalog structures and Products within them.
  • Liquid Components
    module (Products)

    This module component fetches data relating to eCommerce Products and can be used to render Product information.
  • Liquid Components
    ecommerce_add_to_cart

    This component renders an anchor element allowing the javascript function to add the item to the shopping cart.
  • Liquid Components
    ecommerce_buy_now

    This component renders an anchor element allowing the javascript function to add the item to the shopping cart and then proceeding directly to the shopping cart page.
  • Liquid Components
    ecommerce_item_quantity

    This component renders a form input element allowing a quantity to be set for when the source item is added to the shopping cart.
  • Liquid Components
    item_attributes

    This component fetches all attributes/options for a specified product. By default, each attribute group is rendered, with its options and any prices, according to their specified form inputs.
  • Liquid Components
    related_items

    This component fetches related items of a specific source item, such as a Product that has had Related Products assign to it.
  • Liquid Components
    grouped_items

    This component fetches grouped items of a specific source item, such as a Product that has been Grouped with other Products and allows the ability to navigate between grouped items.
  • Liquid Components
    currencies

    This component renders a form select element of all currency names, codes and symbols by default, and can also be used to output currency data to a Liquid collection.
  • Liquid Components
    shipping_options

    This component renders a form select element of all shipping options configured on the site, and can also be used to output shipping option data to a Liquid collection.
  • Liquid Components
    shippingProviderFields

    This component provides a placeholder for populating additional Shipping Provider options to the user.
  • Liquid Components
    tax_codes

    This component renders a form select element of all tax codes configured on the site, and can also be used to output tax code data to a Liquid collection.
  • Liquid Components
    payment_form_fields

    This component is used to render payment fields, and payment related validation errors, within a form using the capabilities provided by your configured payment gateway.
  • Liquid Components
    orders

    This component fetches Orders from the CRM, either owned by the logged-in user or for all customer Orders.
  • eCommerce
    Getting Started

    To get started with the eCommerce module there are some overall settings to configure that provide eCommerce with further context in order to function appropriately for your situation.
  • eCommerce
    Products

    Products are one of the most powerful and flexible modules in Treepl CMS. Create customised product schemas with multiple price points, catalogs, inventory tracked attributes/variables, SEO optimisation and more.
  • eCommerce
    Catalogs

    When organising any eCommerce store, Catalogs are crucial to your Products structure and browserbility. Easily create and customise unlimited product catalogs for your online store.
  • eCommerce
    Discount codes

    Provide discount code functionality for your Treepl CMS shopping cart. Ideal for promotions, customer loyalty and conversions or to help move more stock.
  • eCommerce
    Gift vouchers

    Gift vouchers can be issued to your customers or purchased by them online via the shopping cart.
  • eCommerce
    Taxes

    Create any number of required tax codes specific to the shipping country selected in your Treepl CMS shopping cart.
  • Liquid Components
    countries

    This component renders a form select element of all country names and country codes by default, and can also be used to output country codes/names to a Liquid collection.
  • Liquid Components
    domain_settings

    This module component retrieves settings associated with the current domain, or optionally from another specified domain configured in the site instance.
  • eCommerce
    Shipping Options

    Treepl CMS provides the ability to configure both custom shipping options and integrated shipping providers based on a variety of conditions during the shopping cart stage.
  • eCommerce
    Settings

    These various eCommerce settings allow you to further control and customise the way your website functions, both in the admin and on the front-end, in terms of eCommerce functionality.
  • eCommerce
    eCommerce Javascript

    This is the provided javascript options for further controlling/customising the ecommerce javascript provided by the CMS.
  • Extensions
    Abandoned Cart Recovery

    With Abandoned Cart Recovery functionality, you can automatically send email reminders to customers who add products to their cart (while logged in) and leave without completing the order.
  • Public API
    CRM Orders

    Return or update Order item/s via the public API endpoint.
  • Extras
    Migrating to Advanced Payment Flow

    This article describes differences and possible required actions for migrating to the Advanced Payment Gateway flow.

External Resources


Please let us know if you have any other contributions or know of any helpful resources you'd like to see added here.


Questions?

We are always happy to help with any questions you may have.
Visit the Treepl Forum for community support and to search previously asked questions or send us a message at support@treepl.co and we will consult you as soon as possible.