For more information... RTFM!
NAVIGATION
PAGES THAT LINK HERE
ACCOUNT LOGIN

You are not logged in

Powered by Interchange version 5.7.0

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.

Summary

  • [accessories code arg]
  • [accessories code attribute type other_named_attributes]
  • [accessories code arg other_named_attributes] *DEPRECATED*

Parameter Description Default
code Value of the SKU code in the ProductFiles (or specified other) table. None
key Alias for code. None
row Alias for code. None
arg Positionally interpreted comma-delimited list of values for the following attributes:  attribute, type, column, table, name, outboard, passed.  (Deprecated) None
append Specify a string to append to the returned output. None
attribute The item attribute the tag will work with. None
cols Specify a number to pass to the to the "cols" parameter in HTML widgets that accept it. Varies with type (often 40)
column Specifies the column in the table that contains an item's attribute values. attribute
col Alias for column. attribute
field Alias for column. attribute
contains Determine whether a substring match of the value will cause a radio box or check box to be selected.. None
default Sets the default attribute option in the widget returned by this tag. None
delimiter Specify the attribute parameter list delimiter. Comma (",")
empty Request that this tag should include a hyperlink for the empty "--select--" option, when type is "links". None
extra Specify extra HTML tag attributes, such as "id" or "class" etc. None
form Set the base value for the form, when type is "links". mv_action=return
href Sets the base href for the hyperlinks, when type is "links". Current page
joiner Override the default string (<br>) that joins the hyperlinks, when type is "links". None
js Specify JavaScript to be placed within the start tag of the widget's HTML output. None
new Sets a value in place of the "New" or "Current" option in a combo box, when type is "combo" or "reverse_combo" None
name Sets the name of the form variable to use. mv_order_attribute
outboard Used with the [PREFIX-accessories] tag to specify the table lookup value. None
passed Used to pass custom values to the widget built by this tag. None
prepend Specify a string to prepend to the returned output. None
price Force prices to be displayed along with item attributes. None
price_data None
rows Specify a number to pass to the to the "rows" parameter in HTML widgets that accept it. Varies with type (often 4)
secure Cause the generated link(s) to point to your secure (HTTPS/SSL) Interchange URI, when type is "links". No
table Specifies database table that contains the item's attribute values See ProductFiles
base Alias for table. See ProductFiles
database Alias for table. See ProductFiles
db Alias for table. See ProductFiles
template Allows you to override the standard Interchange template for the hyperlinks, when type is "links". None
type The display widget to use. select
width Quasi-alias for the cols parameter that only works with the "text" and "password" widgets. None

Examples

Tag expansion example

[accessories os28044 size]
<select name="mv_order_size">
    <option value="10oz">10oz</option>
    <option value="15oz">15oz</option>
    <option value="20oz">20oz</option>
</select>

Perl example

$Tag->accessories({
    code  => 'os28044',
    arg   => 'colour, radio'
    table => 'special_products',
});

or similarly with positional parameters: 

$Tag->accessories($code, $arg, $attribute_hash_reference);

Description

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:

UseModifier  size colour

will attach both a size and colour attribute to each item code that is ordered.

Warning

Warning

You may not use the following names for attributes:  "item", "group", "quantity", "code", "mv_ib", "mv_mi" or "mv_si"

You can also set modifier names with the "mv_UseModifier" scratchpad variable, as follows:

[set mv_UseModifier] size colour [/set]

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.

Note

Note

You must be sure that none of the fields in your forms have digits appended to their name if the variable is the same name as the attribute name you select.  This is because the [modifier-name size] variables will be placed in the user session with names like size0, size1 and size2 etc.

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:

[item-accessories attribute, type, column, table, name, outboard, passed]

[accessories code=sku
    attribute=modifier
    type=select
    column=db_table_column_name
    table=db_table
    name=varname
    outboard=key
    passed="value=label, value2*, value3=label 3"
]

[accessories
    js=| onChange="set_description(simple_options, variant)"; |
    type=select
    name="[item-param o_group]"
    passed="=--choose--,[item-param o_value]"
]

Notes: 

  • The attribute attribute is required.
  • See the type attribute for a list of types.
  • The trailing "*" in value2 will mark it as the default ("selected") value in the select widget (see below).

When called with an attribute, the database is consulted to find a comma-separated list of item attribute options, which take the following form:

name_a=Label Text1, default_name=Default Label Text*, name_b, etc.

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:

[item-accessories colour]

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:

<select name="mv_order_colours">
    <option value="beige">Almond</option>
    <option value="gold">Harvest Gold</option>
    <option value="white" selected="selected">White</option>
    <option value="green">Avocado</option>
</select>

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 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.

<select name="[loop-modifier-name size]">
[loop option="[loop-modifier-name size]" list="S, M, L, XL"]
    <option value="[loop-code]"> [loop-code] -- [price code="[item-code]" size="[loop-code]"]</option>
[/loop]
</select>

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:

$Tag->accessories(
    $code,
    undef,              # deprecated "arg" parameter
    $named_attribute_hashref,
    $item_hashref
);

Also see the Looping tags and sub-tags category for information about hash-context and array-context in looping tags.

Parameters

code

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".

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

Deprecation notice

Deprecation notice

The arg parameter was deprecated in Interchange 4.6.  Please do not make use of this parameter as it may be removed, without warning, at any time.

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:

arg="attribute, type, column, table, name, outboard, passed"

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:

    arg="attribute, type, , table"

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:

    arg="colour, radio, , products"
Note

Note

Although you must use such a comma-delimited list to pass attributes to the [PREFIX-accessories] tag, please use named attributes instead for the [accessories] tag.

append

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.

attribute

You 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.

cols

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.

column

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.

contains

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.

default

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.

[accessories
    type=select
    name=colour
    passed="blue=blue, green=Sea Green*"
    default="blue"
]

which will generate:

<select name="colour">
    <option value="blue" selected="selected">blue</option>
    <option value="green">Sea Green</option>
</select>
Obscure technical note

Obscure technical note

the tag will ignore the "default" parameter if it has an item hash reference.  See Hash Lists, above.

delimiter

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).

empty

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.

extra

The 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:

[accessories
    code=os28044
    type=select
    attribute=size
    append="Append this text<br>"
    extra='id="foo"'
    js='onchange="foo()"'
]

which will generate:

<select name="mv_order_size" onchange="foo()" id="foo">
    <option value="10oz"