Change Log

  • 07-02-2021 | v5.6.0 | Added properties to Liquid output for; taxCode, taxCodeHtml, unitRecommended..., and onSale
  • Liquid output updated with various tax related properties

Contributors:

Adam Wilson - Logo Pogo

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']}}