![]() |
| > Home > Documentation > Latest documentation > Interchange tags > accessories |
|
accessoriesA "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. Summary
ExamplesTag expansion example
Perl example
or similarly with positional parameters:
DescriptionThis 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:
Notes:
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:
You can use this in combination with the mv_order_item and mv_order_quantity session variables to allow a customer to enter an item attribute during an order. 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 loopYou 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. ParameterscodeThis 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". You should not specify a code parameter when looping on [PREFIX-accessories], as it internally sets the "code" to the key for the current item in the loop. See the outboard parameter. arg
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:
appendYou 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. attributeYou can set attributes for items in a table, usually the "products" table, with the UseModifier configuration directive. Typical attributes are "size" and "colour". This parameter selects the item attribute upon which this tag will operate. Also see the column parameter, below. colsThe tag will pass the number you choose through to the HTML "cols=X" parameter in HTML widgets that accept it. See also rows, above. columnThis 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. containsRequires 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. defaultSets 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:
delimiterThe 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). emptyRequires 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. extraThe value of this parameter will be appended to the list of attributes attached to the widget's HTML tag. The following example illustrates the append, extra and js parameters:
which will generate:
formRequires type to be "links". This sets the base value for the form in a "links widget. The default is "mv_action=return", which will simply set the variable value in the link. For example, to generate a series of links (one per item attribute value passed), that sets the variable "colour" to the corresponding passed value (blank, "blue", or "green"), do this:
This will generate something like the following:
If you want the empty "--select--" option to show up then pass an empty=1 parameter to this tag. hrefRequires type to be "links". This sets the base href for the link in a links type. The default is the current page. joinerRequires type to be "links". With "type=links", this tag returns a link for each option. This allows you to override the default string (<br>) that joins these links. You can use Perl's meta-character escapes, such as "\n" for newline or "\t" for tab. jsThis parameter allows you to place JavaScript within the start tag of the widget's HTML output. See the extra parameter for a usage example. The "js" parameter has no default, except when "type=move_combo", where the default is:
newRequires type to be "combo" or "reverse_combo". You can use this to set a value in place of the "New" or "Current" option in a combo box. For example, if item "os28044" has "size" attribute values of "Sm=10oz, Med=15oz, Lg=20oz":
will generate:
Or, with the default "new" value:
will generate:
The default is no value with option text set to "<-- New" if type is "combo", or "Current -->" if type is "reverse_combo". nameThis sets the name of the form variable to use, if appropriate for the widget being built. This defaults to "mv_order_attribute". I.e. if the attribute is named "size" then the form variable will be named "mv_order_size". If the variable is set in the user's session then the widget will retain its previous setting. In other words, [value name] will contain the previous setting and the widget will use it as its default setting. Also see the default parameter. outboardIf you need to select from a database table who's primary key is different from the product's SKU code, then you can use this parameter to pass the key value that should can be used to find the accessory data. This is especially useful when using [PREFIX-accessories], as that loop sub-tag cannot be passed a code parameter. passedYou can use this to pass your own values to the widget built by this tag. If you have set passed to a list of widget options, then this tag will simply build a widget, of the specified type, with your values - instead of fetching an attribute value list from the database. For example, to generate a select widget with a blank option (perhaps forcing a select), the value of "blue" with a label of "Blue" and the value of "green" with a label of "Sea Green", use the following:
Which will generate:
prependYou can set a string to prepend to the returned output of the tag. Note that this is not a list to prepend to the fetched attribute value list, which is treated within the tag. For example,
will generate:
priceWhen combined with the price_data parameter, this allows you to force prices for item attributes. You probably do not want to use this; Just let the tag pick up prices from your database, as appropriate. If you're passing attribute values, you can use this parameter to control the displayed price in the widget, as follows:
which will generate:
price_datarowsThis tag will pass the number you choose through to the HTML "rows=Y" parameter in HTML widgets that accept it. For some types, you can also define widget rows and columns within the string that sets the type. For example, type="textarea_6_33_wrap=virtual" specifies a <textarea> widget with "rows=6", "cols=33" and "wrap=virtual". You should resort to this only when you cannot use the named parameters, for example within the [PREFIX-accessories] tag. The result of setting conflicting values in the type string and the "rows=Y" attribute is undefined. See also cols, below. secureRequires type to be "links". Setting this parameter true will cause the generated link(s) to point to your secure (HTTPS/SSL) Interchange URI. See the SecureURL local configuration directive. tableThis is the database table containing the item's attribute values. It defaults to the first of the ProductFiles tables, found to contain a matching SKU. If you have configured your database so that the attributes are kept in a different table from other item data, then the primary key should be named "code" and contain product SKUs. If you're using "[PREFIX-accessories]" and cannot Specify "code=key" then use the outboard parameter instead. templateRequires type to be "links". Allows you to override the standard Interchange template for a hyperlink. You probably don't need to use this. Grep the Interchange core code to grok it if you do (find the "build_accessory_links" subroutine in the core). typeThis parameter may be used to select a display widget from the following list:
The default is "select", which builds a HTML <select> form entry widget for the attribute.
Some types build widgets that use rows=Y, cols=X, or certain other HTML attributes. For these, you can define widget rows and columns within the string that sets the type. For example, type="textarea_6_33_wrap=virtual" specifies a <textarea> widget with "rows=6", "cols=33" and "wrap=virtual". You should resort to this only when you cannot use the named parameters. For example within an [PREFIX-accessories] tag. Otherwise pass the rows=Y and cols=X parameters to this tag instead. The result of setting conflicting values in the type string and the rows and cols attributes is undefined. The following list shows syntax for type strings, where X is the number of columns and Y is the number of rows.
In any of the option building types, you can append the string ranges and a special option processing will be done -- any option matching the pattern [A-Za-z0-0]..[A-Za-z0-0] will be expanded into a comma separated range between the bounds. The same behaviour is accomplished by passing the accessories tag option ranges. For example:
and
will both output:
|