It is possible to invoke Interface tags also by using programming languages, such as PHP or JavaScript (however, it is not possible to use server-side programming languages in MyCashflow).
By using tags with programming languages, you can, for example, retrieve content from the dictionary tool by using AJAX calls, or print a product list from your online store on another web page.
If you plan on integrating your online store with any external software, use the MyCashflow REST API to process and retrieve the contents of the online store.
Syntax
Each Interface tag has its own access point in the online store with an address in the following format:
https://online-store-name.mycashflow.fi/interface/TagName?attribute=valueIf the invoked tag has attributes, they can be given values by adding them to the tag access point address as GET parameters, as shown above.
Scope in tags access points
Using certain tags requires that a content type, such as a product, is set in their scope in their usage environment. These include, for example, tags that print product data, such as {ProductName}, which only works in an environment that has a selected or otherwise defined scope of a product.
When tags are invoked in programming languages, the scope must be set by using the set parameters:
| Parameter | Corresponds to address |
|---|---|
| setProduct=id | /product/id/... |
| setCategory =id | /category/id/... |
| setBrand=id | /brand/id/... |
| setPage=id | /page/id/... |
| setNewsItem=id | /news/id/... |
Currently, product bundles have no dedicated access point in the Interface system.
set parameters are set in the same way as the GET parameter as other attributes given to the tag:
http://online-store-name.mycashflow.fi/interface/ProductName?setProduct=24In the example, the tag call would print the same content as the {ProductName} used on the product page with ID no. 24.
Attributes
Many attributes of Interface tags can be used when tags are invoked with programming languages.
The following sections present the syntax of different types of attributes at Interface tags access points.
For example, string values are used to retrieve entries from the dictionary:
https://online-store-name.mycashflow.fi/interface/Text?code=AboutUsNumeric values are given, for example, when determining the ID of the content to be retrieved:
https://online-store-name.mycashflow.fi/interface/Category?id=4&helper=helpers/helper-fileSome attributes are assigned a boolean value (true / false):
https://online-store-name.mycashflow.fi/interface/ProductName?setProduct=4&escape=trueIn case of tags that have list-type attributes, their syntax is the same when using tags in templates and through their access points.
https://online-store-name.mycashflow.fi/interface/Products?id=1|4|45Some tags have attributes that are given a file reference as their value. An example of such a tag is the {Helper} tag that was used below:
https://online-store-name.mycashflow.fi/interface/Helper?file=helpers/helper-fileThe file reference is assigned in relation to the root directory of the theme in use.
If the file to be retrieved uses e.g. product tags, you must set the desired product with the setProduct parameter. Read more about the set parameters.
JavaScript/jQuery (AJAX requests)
With JavaScript it is possible to perform asynchronous calls to Interface tags. In this way, you can, for example, retrieve contents from the dictionary without reloading the page.
$.get('http://demo.mycashflow.fi/interface/Text?code=TargetContent',
function(data) {
$('.result').html(data);
}
);Note that tags' attributes are indicated as GET parameters in the address of the called tag. In the example, the {Text} tag is used to retrieve content from the dictionary. The code of the entry to be retrieved is added to the tag as the value of the code attribute.
The request is sent by using the jQuery get() method. The HTML content retrieved by the request can then be written to the desired HTML element.
PHP
The server-side programming language PHP also can be used to retrieve content from MyCashflow store.
To call tags, you can use, for example, the PHP file_get_contents() function:
$new_products = file_get_contents("http://demo.mycashflow.fi/interface/NewProducts?limit=6");
echo $new_products;In the example, the store's 6 newest products are retrieved by using the {NewProducts} tag.
As the tags return HTML-formatted content, the content of the $new_products variable can be printed on the page as it is.
Creating a JSON object from a product list
By using the between and escape attributes, you can create a JSON object from a product list:
{ProductSet(
categories: 1|2,
before: '{',
between: ',',
helper: '{{
"{ProductID}": {
"name": "{ProductName(escape: 'json')}",
"description": "{ProductFullDesc(escape: 'json')}",
"url": "{ProductURL}"
}
}}',
after: '}'
)}- The
categoriesattribute selects the products to be printed from two product categories. - The
beforeandafterattributes open and close the top-level object. - The
betweenattribute adds a comma between each product list element. - The
helperattribute defines the format for each product as a JSON object that contains the product's name, description, and URL. - The
escapeattribute sets escape characters for content tags, which allow the content to be used as a value in a JSON object.
Limitations and known issues
Tags that can be retrieved from the /interface address have the following limitations and known issues:
- Order tags are not available
- The functioning of some tags is based on a visitor-specific session. If the tags are called with a server-side programming language (for example PHP), the visitor-specific session must be transmitted separately or tags won't work correctly. This restriction does not apply to the store's internal AJAX invitations.
Examples of session-based tags are customer data and shopping cart tags.
- If the content printed by the tag will be displayed under another domain, add a domain name to the beginning of the links' and images' path, e.g.
href="http://www.mcf-kauppa.fi/product/3"
