|> Home > Documentation > Latest documentation > Interchange tags > accessories|
A "Swiss Army Knife" widget builder, this provides access to Interchange's product option attributes (e.g. to choose or access product options such as a shirt's size or colour).
Can build selection objects (radio buttons, check boxes, select boxes, etc.), forms and hyperlinks, or can simply return a value.
Tag expansion example
or similarly with positional parameters:
This is the "Swiss Army Knife" widget builder for providing access to Interchange's product option attributes (e.g., to choose or access product options such as a shirt's size or colour).
Interchange allows you to choose item attribute values for each ordered item; You can attach a size, colour or any other modifier to a line item in the shopping cart. You can also resubmit previous attribute values via hidden form fields.
The UseModifier local configuration directive is used to set the name of the modifier(s). For example:
will attach both a size and colour attribute to each item code that is ordered.
You can also set modifier names with the "mv_UseModifier" scratchpad variable, as follows:
which has the same effect as the above.
This allows multiple options to be set for products. Whichever one is in effect at order time will be used. Be careful: You cannot set it more than once on the same page. Setting the mv_separate_items or the SeparateItems directive places each ordered item on a separate line, simplifying attribute handling. The scratchpad setting for mv_separate_items has the same effect.
The modifier value is accessed in the [item-list] loop, with the [item-param attribute] tag, and form input fields are placed with the [modifier-name attribute] tag. This is similar to the way quantities are handled.
Interchange will automatically generate the select widgets when the [accessories code="os28044" attribute="size"] or [PREFIX-accessories size] tags are called. They have the following syntax:
When called with an attribute, the database is consulted to find a comma-separated list of item attribute options, which take the following form:
The label text is optional. If no label is provided then the name will be used (as in the "name_b" in the above example).
If an asterisk (*) is the last character of the label text, then the item will be the default selection. If no default is specified then the first item in the list will be the default. For example:
This will search the ProductFiles table(s) for a column named "colours". If an entry such as "beige=Almond, gold=Harvest Gold, White*, green=Avocado" is found then a select widget like the following will be built:
If used in an [item-list], and the user has changed the value, the generated select widget will automatically retain its current value</i>, as selected by the user. The value can then be displayed with [item-modifier colour] on the order report, order receipt or any other page containing an [item-list] tag.
Emulating with a loop
You can also build widgets directly, without using the [accessories] tag. You may have to do so if you need more control of the content than the tag offers. The following is a fragment from a shopping basket display form, which shows a selectable size with sticky setting, and a price that changes based upon the modifier setting. Note that this example would normally be contained within the [item-list][/item-list] pair.
The output of the above would be similar to the output of [item-accessories size select] if the ProductFiles table's size column contained the value "S, M, L, XL". The difference is that the options in the loop emulation show the adjusted price in addition to the size within each option value.
Hash Lists (technical note)
As a technical note, some of the features of this tag work differently depending upon whether it was called with a $Vend::Interpolate::item hash reference. For example, when called as [item-accessories] within an [item-list] container.
In this context, the tag will have access to ancillary data from the item (including, perhaps, a user's chosen item attribute value). For example, if building a textarea widget within an [item-list], the widget will show the chosen item attribute value. On the other hand, within an array list such as a [search-list] block in a [search-region], the widget would be empty.
If you really know what you're doing, you can pass an item hash reference, within a [perl] tag, like this:
Also see the Looping tags and sub-tags category for information about hash-context and array-context in looping tags.
This is the primary key in the specified table (commonly named "sku" in a products table). If no table is specified then this tag defaults to the table(s) defined with the ProductFiles local configuration directive which, in turn, defaults to "products".
This parameter allows you to pass values for some of the more commonly used attributes, in the manner of the [PREFIX-accessories] tag, as a comma-delimited positional list. For instance:
Whitespace within the list is optional.
If you leave out one or more of the above attributes, and are setting anything after it in the list, then be sure to keep the comma(s). For instance:
The above example shows the attribute names for clarity. You would probably want actually use the values, so the previous example might actually be something like the following:
You can set a string to append to the returned output of the tag. Note that this is not a list to append to the fetched attribute value list, which is treated within the tag.
This parameter selects the item attribute upon which this tag will operate. Also see the column parameter, below.
The tag will pass the number you choose through to the HTML "cols=X" parameter in HTML widgets that accept it.
See also rows, above.
This specifies the column in the table that contains an item's attribute values. This tag will look for item attribute names and values in a comma-delimited list of "name=value" pairs, stored in this column of an item's row in the table.
The column, in the table, corresponding to the attribute will traditionally have the same name as the attribute. That does not need to be the case, but you may find it to be confusing if you use different names. If unspecified, the column name will default to the name specified with the attribute parameter.
For example, if an item in the "products" table has a "size" attribute, and each item's comma-delimited list of available sizes is stored in the "how_big" column, then you would need to specify "column=how_big" because the tag's default column choice (size) would be missing, or used for some other purpose.
Requires type to be "radio" or "check".
This is used to determine whether a substring match of the value will cause a radio box or check box to be selected. If true then the match will happen whether the value is on a word boundary or not. If false then the value must be on a word boundary. When we speak of a word boundary, it is in the Perl sense. I.e. a word character ([A-Za-z0-9_]) followed by or preceded by a non-word character, or the beginning or the end of the string.
Sets the default attribute option in the widget returned by this tag. This will override a default indicated with a trailing asterisk (*) in the database or a "passed" string. This will also override the default of a user's previous selection when it would have otherwise been preserved.
For example the following selects "blue" by default, rather than "green" as it would otherwise have done.
which will generate:
The list of attribute values will be a delimited string. This parameter allows you to specify an alternative delimiter if the list is not comma-delimited (the default).
Requires type to be "links".
Setting this parameter true requests that this tag should include a hyperlink for the empty "--select--" option. In the form example, above, if "empty=1" had been specified then three links would have been generated.
which will generate: