Miva Merchant: A Store Morph Technology Mini-Primer

Author: Tiny Queen Designs
Tiny Queen Designs – Ecommerce and Web Site Design

When Miva Merchant released MM5, they revolutionized the way the software worked “out of the box” and opened a whole new world of customization to ecommerce store owners. Using Store Morph Technology (SMT), store owners could completely and…well, I was going to say easily customize their stores to suit their needs, but the truth is that at first glance, SMT isn’t in fact all that easy.

One of the common complaints from new developers of MM sites, is the lack of documentation about SMT and how it works. The new owners of Miva Merchant are working hard to remedy the documentation void, but in the meantime, here’s a mini primer on SMT and some examples of the things you can do with it.

You’ll see SMT in MM’s page templates in a variety of different forms.

Variables

There are two types of variables in SMT: local variables, specific to the page you’re on, and global variables, which are available sitewide. The best way to find out what variables are available on a given page is to download the free Store Helper Module from Latu.net.

Variables are displayed on MM pages in a variety of ways. Note that variables always begin with an ampersand (&) and end with a semicolon (;).

&mvt:product:code;
&mvte:product:code;
&mvta:product:code;

Variables that begin with &mvte are “entity encoded.” This means that any characters they contain will be displayed on the page in their exact form — they will not be interpreted by the browser.

Variables that begin with &mvta are “attribute encoded.” This means that any characters they contain will be converted to the correct format for use in a link.

Tags

SMT tags look similar to XHTML tags in that they are surrounded by < >, they include name / value pairs, with the values surrounded by double quotes, and all SMT tags must be closed, either by using a trailing slash, or with a separate closing tag.

Items

SMT tags may call in specific page items. These tags start with mvt:item, and use name=”xyz” to identify which page item is being called. They may also include parameters that more specifically identify the content to be called in. They are frequently self closing, but may have a separate closing tag depending on their form.

<mvt:item name="html_profile" />

<mvt:item name="fonts" param="body_font" />
Some content here
</mvt:item>

Loops and arrays

SMT tags may be used to loop through an array, and display specific data associated with that array. Common uses for these tags include such things as displaying the products in a category or search result, listing all of the products in the basket, or listing available shipping methods. All loops must be closed with a separate closing tag after you’ve worked with the content you’re pulling from the array.

<mvt:foreach iterator="product" array="products">
Some stuff about each of the items in this array
</mvt:foreach>

Conditionals

Finally, SMT tags may be used to create conditionals. This is far and away one of the most useful aspects of SMT, and is the building block of the store owner’s ability to customize his or her store (at least in my opinion!). Writing conditionals is probably worthy of a post all its own, but here are some basics.

All conditionals start with mvt:if and contain an expression to test for. A very basic conditional might look like this. This conditional checks to see if the product code is equal to the string 12345, and if it is, displays some text. Note that the string is enclosed in single quotes.

<mvt:if expr="l.settings:product:code EQ '12345'">
Display some text.
</mvt:if>

Conditionals can also be set up to do one thing if the condition is true, and another thing if it is false.

<mvt:if expr="l.settings:product:code EQ '12345'">
Display some text.
<mvt:else>
Display some other text.
</mvt:if>

Or even…

<mvt:if expr="l.settings:product:code EQ '12345'">
Display some text.
<mvt:elseif expr="l.settings:product:code EQ '45678'">
Display some other text.
<mvt:else>
Display yet some other text.
</mvt:if>

Expressions can be combined to create extremely specific situations to test against. For instance, if you want to display some text only if the product code is 12345 and the customer is logged in, you would write your conditional something like this:

<mvt:if expr="((l.settings:product:code EQ '12345') AND (g.Basket:Cust_id))">
Display some text
</mvt:if>

You can also easily test for a match in a single string or a series of strings, by using CIN or IN. CIN is case insensitive; IN is case sensitive. The strings to test against are enclosed in single quotes, and if there is more than one, they are separated by commas. The conditional below will return true if the product code is 12345 or 45678 or 67890.

<mvt:if expr="l.settings:product:code IN '12345,45678,67890'">
Display some text.
</mvt:if>

Note that the conditional above will also return true if the product code is 1234567, 012345, or 98712356789. It checks merely to see if the content of the first variable is included in the second. If you need to look for an exact match, you would be better to use a conditional like the following.

<mvt:if expr="((l.settings:product:code EQ '12345') OR (l.settings:product:code EQ '45678') OR (l.settings:product:code EQ '67890'))">
Display some text.
</mvt:if>

Once you get the hang of them, you’ll wonder how you ever did without the power of conditionals to control your shopper’s experience on your site. Below are some of the most common conditional operators, along with what they do.

Operator Function
NOT Returns true if the condition does not match the variable
ISNULL Returns true if the variable is empty
AND Returns true if both conditions are true
OR Returns true if any of the conditions is true
EQ Returns true if the variable matches the string
NE Returns true if the variable does not match the string
GT Returns true if the variable is greater than the string
LT Returns true if the variable is less than the string
GE Returns true if the variable is greater than or equal to the string
LE Returns true if the variable is less than or equal to the string
IN Returns the first position of string_a in string_b. Case sensitive
CIN Returns the first position of string_a in string_b. Case insensitive


Comments

Finally, one of the most useful, and underused in my opinion, features of SMT is the comment feature. By carefully commenting your work, you make it so much easier on yourself or another developer when it comes time to try to make updates or changes to existing customizations. SMT comments take the following form. They are not parsed by the server, and won’t appear in your html source code.

<mvt:comment>
Here is an explanation of what this section of code is going to do.
</mvt:comment>

If you enjoyed this post, please consider leaving a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

You really are a “Queen,” L., … a MIVA Queen! What a helpful article for all those folks moving over to Miva Merchant, not to mention developers who need a helping hand.

Awesome primer! I put a link to this from my MerchantTutorials.com helpful links page.

http://www.merchanttutorials.com/helpfullinks.html

I have a Miva 4 store and beginning a new (domain) 5 store. I’m struggling with much of the design.

I’m not clear why I would need:

Display some text.

Thanx

I have a Miva 4 store and beginning a new (domain) 5 store. I’m struggling with much of the design.

I’m not clear why I would need to display some text based upon user input of an item number.

Thanx

Hi Mitch,

When using conditionals, sometimes you use them based on user input, but more often you use them within the page templates to control the output of the page under specific conditions. For example, you might have one category of products (let’s call the category ‘widgets’) where the products are priced per pair. On the category page, you’d like to add the words “per pair” after the price, but only for the widgets category.

In the Category Product Display Layout tab of your page, you would find the variable that displays the price (&mvt:product:formatted_price;), and surround it with a conditional to test for the category code widgets, and add “per pair” after the price, like so:

&mvt:product:formatted_price; per pair

&mvt:product:formatted_price;

Now when the page is processed for display in the browser, a check will be run against the category code. If the category code is widgets, the browser will display $X.XX per pair for each product in the category. If the category code is anything other than widgets, the browser will simply display $X.XX.

Great post…from a true blue-blood!

Excellent explanation and really clear examples- many thanks!! From a committed Miva 5.5 user.

Good primer, especially the conditionals. I would really like to see a post dedicated to conditionals.

[...] Check it out here: Miva Merchant: A Store Morph Technology Mini-Primer [...]

Display some text.

can also be constructed as:

Display some text.

While slightly slower, its less prone to typographic errors and easier to maintain. By adding | and | around the variable being tested, you prevent the problem of miss matching 1234 with 123,456,789,etc.

[...] This is the actual code I once saw in someone’s template. If you don’t know why I am showing it here, then you should definitely be asking the forum for advice on your coding attempts<g>. You can also find a primer on using SMT in a blog by Tiny Queen. [...]

Leave a comment

(required)

(required)