A server-side cart-handling is available. It uses the server side session to select the current cart for the user (one cart at a time per session)

Available functions

Get current cart


/**
 * @return array
 *      [cart_id] int
 *      [cart_data] array
 *          [order] array
 *              [invoice_country] string ISO-Code of the currently set Invoice-Country, e.g. "DE"
 *              ... other invoice address fields if already set ...
 *              [deliver_country] string ISO-Code of the currently set Delivery-Country, e.g. "DE"
 *              ... other delivery address fields if already set ...
 *              [fk_o_st_id] int ID of the currently set shipping-type
 *          [payment] array
 *          [currency] string, ISO-Code of the shop-currency, e.g. "EUR"
 *          [currency_dsp] string, Display Version of the shop-currency, e.g. "€"
 *          [cart_item_key] int next item-key
 *          [cart_items] array
 *              [<cart-item-key>][quantity] int|float
 *              [<cart-item-key>][pcode] string
 *              [<cart-item-key>][name] string
 *              [<cart-item-key>][vat_pct] int, e.g. "19"
 *              [<cart-item-key>][price_single_brutto] float, e.g. "123.45" price incl. vat for this item in the shop-currency
 *              [<cart-item-key>][type] string enum type value "product"|"shipping"|"payment"|"coupon"...
 *              [<cart-item-key>][xdata] array, optional additional details for this item
 *              [<cart-item-key>][block] int, additional grouping/sorting option
 *          summary data for easier display
 *          [cart_prds_quantity] int|float
 *          [cart_prds_netto]float
 *          [cart_prds_brutto] float
 *          [cart_total_quantity] int|float
 *          [cart_total_netto] float
 *          [cart_total_brutto] float
 *          [fk_cart_persid] null|int ID for the person-account if already assigned to a specific customer
 *          [summary] array
 *              [vats] array summary for each vat-percentage
 *                  [<vat_pct>][total_netto] float
 *                  [<vat_pct>][total_brutto] float
 *                  [<vat_pct>][total_vat] float
 *              [blocks] array summary for each block
 *                  [<block>][total_netto] float
 *                  [<block>][total_brutto] float
 *                  [<block>][total_vat] float
 *              [type] array summary for each item-type
 *                  [<type>][total_netto] float
 *                  [<type>][total_brutto] float
 *                  [<type>][total_vat] float
 *              [order_min_limit_OK] int|bool 1 if the configured minimum total per order for the shop is reached
 *          [checkout] array
 *              [purchase] int|bool 1 if the current cart settings could be purchased (final evaluate should still happen!)
 */

Example


    {% set cart = hublify.cart().getCart() %}
    {# do something with data in cart #}

Add products

You can easily add a product to your cart. In any case you have to provide product identifying: pcode value.

There are some restrictions that are checked when you add a product to the cart

  • Product with the pcode must exist in Hublify PIM
  • Product-Status must "online"
  • Product must be flagged "buyable"

/**
 * @param string $pcode (must)
 * @param int|float $quantity (optional, default: 1)
 * @param ?array $xdata additional settings if relevant
 *
 * @return array
 *      [status] bool true on success
 *      [data] array see "getCart" for details
 */

Examples


    {% set r = hublify.cart().addProduct("PC0001") %}

    {% set r = hublify.cart().addProduct("PC0002",2) %}

Update products


/**
 * @param array $items List of items with the values that should be changed
 *      [<cart-item-key>][quantity] int|float adjusts the quantity for this item
 * @param array|null $params optional addtional params
 *      [postAction] array
 *          [page] string page-label for direct redirect after successful update
 *
 * @return array (or directly triggered redirect if set)
 *      [status] bool true on success
 *      [data] array see "getCart" for details
 */

Examples


	{# update quantity #}
	{% set r = hublify.cart().updateProduct({"0": {"quantity": 2}}) %}
	{# update quantity and go to next checkout page on success #}
	{% set r = hublify.cart().updateProduct({"0": {"quantity": 3}},{"postAction": {"page": "checkout-address"}}) %}

Remove products


/**
 * @param string|int $itemId cart-item-key of the item that should be removed
 *
 * @return array
 *      [status] bool true on success
 *      [data] array see "getCart" for details
 */

Example


	{# remove the item with key "0" #}
	{% set r = hublify.cart().removeProduct("0") %}

Remove all products


/**
 * @return array
 *      [status] bool true on success
 *      [data] array see "getCart" for details
 */

Example


	{# remove all items from the cart #}
	{% set r = hublify.cart().removeAll() %}

Add a coupon / promo code


/**
 * Attention: this only works if the coupon-plugin is installed
 *
 * @param string $couponCode the coupon code that should be added
 *
 * @return array
 *      [status] bool true on success
 *      [data] array see "getCart" for details
 *      [msg] array msg-stack
 */

Example


	{# add coupon "MyCouponCode" to the cart #}
	{% set r = hublify.cart().addCoupon("MyCouponCode") %}


Set addresses & customer details


/**
 * @param array $data all relevant fields for invoice-address, delivery address or the customer,
 *      will be automatically separated into "order" and "person" sub-arrays
 *      [invoice_company] string, e.g. ""
 *      [invoice_gender] string, e.g. "male"
 *      [invoice_firstname] string, e.g.  "Max"
 *      [invoice_lastname] string, e.g.  "Muster"
 *      [invoice_addrextra] string, e.g.  ""
 *      [invoice_street] string, e.g. "Sample Street"
 *      [invoice_housenr] string, e.g.  "1b"
 *      [invoice_zip] string, e.g.  "22222"
 *      [invoice_town] string, e.g.  "Hamburg"
 *      [invoice_country] string, e.g.  "DE"
 *      [invoice_email] string, e.g.  "max.mmuster.de"
 *
 *      [deliver_company] string, e.g.  ""
 *      [deliver_gender] string, e.g.  "male"
 *      [deliver_firstname] string, e.g.  "Max"
 *      [deliver_lastname] string, e.g.  "Muster"
 *      [deliver_addrextra] string, e.g.  ""
 *      [deliver_street] string, e.g.  "Sample Street"
 *      [deliver_housenr] string, e.g.  "1b"
 *      [deliver_zip] string, e.g.  "22222"
 *      [deliver_town] string, e.g.  "Hamburg"
 *      [deliver_country] string, e.g.  "DE"
 *
 *      [telephone] string, e.g.  "+4940123456"                  // customer detail phone number
 *      [telephone_mobile] string, e.g.  "+491601234567"         // customer detail mobile number
 *      [email] string, e.g.  "max@muster.de"                    // customer details email
 * 
 * @param array|null $params optional addtional params
 *      [postAction] array
 *          [page] string page-label for direct redirect after success
 *
 * @return array (or directly triggered redirect if set)
 *      [status] bool true on success
 *      [data] array see "getCart" for details
 */

Example


        {% set r = hublify.cart().setAddresses({
  	    "invoice_company": "",
	    "invoice_gender": "male",
	    "invoice_firstname": "Max",
	    "invoice_lastname": "Muster",
	    "invoice_addrextra": "",
	    "invoice_street": "Sample Street",
	    "invoice_housenr": "1b",
	    "invoice_zip": "22222",
	    "invoice_town": "Hamburg",
	    "invoice_country": "DE",
	    "invoice_email": "max.mmuster.de",        
	    "deliver_company": "",
	    "deliver_gender": "male",
	    "deliver_firstname": "Max",
	    "deliver_lastname": "Muster",
	    "deliver_addrextra": "",
	    "deliver_street": "Sample Street",
	    "deliver_housenr": "1b",
	    "deliver_zip": "22222",
	    "deliver_town": "Hamburg",
	    "deliver_country": "DE",
	    "telephone": "+4940123456",
	    "telephone_mobile": "+491601234567",
	    "email": "max@muster.de"
           }, {"postAction": {"page": "checkout-payment"}}) %}

Get available order options

The returned options are already adjusted for the current cart-details like invoice-/delivery-country and total value


/**
 * @param string $type  "shipping"|"payment"
 *
 * @return array
 *      [status] bool
 *      [data] list of available options
 *         for shipping:
 *         --- for shipping ---
 *         [<idx>][st_id] int, e.g "1", Hublify internal ID for the shipping type
 *         [<idx>][st_grp_name] string, e.g. "Standardlieferung",
 *         [<idx>][st_label"] string, e.g. "Standard", Label for the shipping type
 *         [<idx>][st_desc] string
 *         [<idx>][st_deliver_category] string, "delivery"|"pickup"
 *         [<idx>][st_xcost_value_abs] float, absolute costs for this type
 *         [<idx>][st_xcost_value_rel] float, relative costs for this type in %
 *         [<idx>][st_xcost_value_min] float,  min costs for this type
 *         [<idx>][st_xcost_value_max] float,  max costs for this type
 *         [<idx>][oo_default] int, 1 for default option
 *         [<idx>][oo_settings] null|array,
 *         [<idx>][drvd_xcost_brutto] float,  absolute and relative costs combined based on your current cart total (incl.vat)
 *         [<idx>][drvd_xcost_netto] float,  absolute and relative costs combined based on your current cart total (without vat)
 *         [<idx>][drvd_xcost_total] float
 *         --- for payment ---
 *         [<idx>][pys_id] int, The Hublify internal ID for the payment method
 *         [<idx>][pys_method] string, Hublify internal label for the payment method
 *         [<idx>][pys_desc] string, payment-method name/description
 *         [<idx>][pys_xcost_value_abs] float, absolute costs for this type
 *         [<idx>][pys_xcost_value_rel] float, relative costs for this type in %
 *         [<idx>][pys_xcost_value_min] float,  min costs for this type
 *         [<idx>][pys_xcost_value_max] float,  max costs for this type
 *         [<idx>][pys_pos] int,  sorting
 *         [<idx>][pyp_id] int, The Hublify internal ID for the payment-provider
 *         [<idx>][pyp_label] string, The Hublify internal label for the payment-provider
 *         [<idx>][pyp_classname] string,  payment-provider name
 *         [<idx>][oo_default] int, 1 for default option
 *         [<idx>][drvd_xcost_brutto] float,  absolute and relative costs combined based on your current cart total (incl.vat)
 *         [<idx>][drvd_xcost_netto] float,  absolute and relative costs combined based on your current cart total (without vat)
 *         [<idx>][drvd_xcost_total] float
 */

Examples


	{# get the available shipping options #}
	{% set shippingOptions = hublify.cart().getOptions('shipping') %}
        {# show the available options #}
        {% for shp in shippingOptions.data %}    
            {{ shp.st_grp_name}}
        {% endfor %}

	{# get the available payment options #}
	{% set paymentOptions = hublify.cart().getOptions('payment') %}
        {# show the available options #}
        {% for pys in paymentOptions .data %}    
            {{ pys.pys_desc}}
        {% endfor %}

Get current shipping setting

Easy access to the currently selected shipping type


/**
 * @return array
 *      [st_id] int, Hublify internal ID for the shipping type
 *      [st_grp_name] string, e.g. "Standardlieferung",
 *      [st_label"] string, e.g. "Standard", Label for the shipping type
 *      [st_desc] string
 *      [st_deliver_category] string, "delivery"|"pickup"
 *      [st_xcost_value_abs] float, absolute costs for this type
 *      [st_xcost_value_rel] float, relative costs for this type in %
 *      [st_xcost_value_min] float,  min costs for this type
 *      [st_xcost_value_max] float,  max costs for this type
 */

Example


        {# get current selection #}
	{% set shp = hublify.cart().getShipping() %}
        {# show the selected shipping type in your template #}
        {{ shp.st_grp_name}}

Set Shipping details


/**
 * @param $shippingData
 *      [fk_o_st_id] int, the Hublify-Internal ID for the shippingtype
 *      [shipping] array (optional) additional shipping details if needed
 * @param array|null $params optional addtional params
 *      [postAction] array
 *          [page] string page-label for direct redirect after success
 *
 * @return array (or directly triggered redirect if set)
 *      [status] bool true on success
 *      [data] array see "getCart" for details
 */

Example


        {% set r = hublify.cart().setShipping({"fk_o_st_id": 1}) %}

Get current Payment-Settings


/**
 * @return array
 *     [pys_id] int, The Hublify internal ID for the payment method
 *     [pys_method] string, Hublify internal label for the payment method
 *     [pys_desc] string, payment-method name/description
 *     [pys_xcost_value_abs] float, absolute costs for this type
 *     [pys_xcost_value_rel] float, relative costs for this type in %
 *     [pys_xcost_value_min] float,  min costs for this type
 *     [pys_xcost_value_max] float,  max costs for this type
 *     [pys_pos] int,  sorting
 *     [pyp_id] int, The Hublify internal ID for the payment-provider
 *     [pyp_label] string, The Hublify internal label for the payment-provider
 *     [pyp_classname] string,  payment-provider name
 */

Example


        {# get current selection #}
	{% set pys= hublify.cart().getPayment() %}
        {# show the selected payment method in your template #}
        {{ pys.pys_desc}}

Set payment details


/**
 * @param $paymentData
 *      [pys_id] int the Hublify-Internal ID for the payment-method
 *      [payment] array (optional) additional payment details if needed
 * @param array|null $params optional addtional params
 *      [postAction] array
 *          [page] string page-label for direct redirect after success
 *
 * @return array (or directly triggered redirect if set)
 *      [status] bool true on success
 *      [data] array see "getCart" for details
 */

Example


        {% set r = hublify.cart().setPayment({"pys_id": 1},{"postAction": {"page": "checkout-overview"}}) %}

Finalize the purchase


/**
 * @param ?array $data optional any additional data
 * @param ?array $params
 *      [postAction] array
 *          [page] string page-label for direct redirect after success
 *      [postAction3rdParty] array
 *          [page] string page-label for direct redirect after success if a third party should be included (external payment)
 *
 * @return array (or directly triggered redirect if set)
 *      [status] bool true on success
 *      [data] array
 *          [oid] int, Hublify internal primary id for the order
 *          [orderid] string, Hublify internal order-id, usually the one to be displayed
 *          [persid] int, Hublify internal primary id for the customer
 *          [payment] array payment-details if a transaction was created
 *              [amount] float, Total amount of the created payment-transaction
 *              [currency] string, e.g. "EUR", Currency the transaction was created in
 *              [transid] int,  Hublify internal primary id for the created payment-transaction
 */

Example


        {% set r = hublify.cart().purchase(null,{"postAction": {"page": "checkout-done"}}) %}