accessories

### Index Up >>

## accessories

CALL INFORMATION
  Parameters: code arg

  Positional parameters in same order.

  The attribute hash reference is passed to the subroutine after the parameters as the last argument. This may mean that there are parameters not shown here.

  Must pass named parameter interpolate=1 to cause interpolation.

  Invalidates cache: no

  Called Routine:

  ASP/perl tag calls:

          $Tag->accessories(
              {
               code => VALUE,
               arg => VALUE,
              }
          )

       OR

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

  Attribute aliases

                  base ==> table
                  col ==> column
                  database ==> table
                  db ==> table
                  field ==> column
                  key ==> code
                  row ==> code

DESCRIPTION
  The `[accessories ...]` tag allows you to access MiniVend's option attribute facility in any of several ways.

  If passed any of the optional arguments, initiates special processing of item attributes based on entries in the product database.

  MiniVend allows item attributes to be set for each ordered item. This allows a size, color, or other modifier to be attached to a line item in the shopping cart. Previous attribute values can be resubmitted by means of a hidden field on a form.

  The `catalog.cfg` file directive UseModifier is used to set the name of the modifier or modifiers. For example

          UseModifier        size color

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

  IMPORTANT NOTE: You may not use the following names for attributes:

          item  group  quantity  code  mv_ib  mv_mi  mv_si

  You can also set it in scratch with the mv_UseModifier scratch variable -- `[set mv_UseModifier]size color[/set]` has the same effect as 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 global directive SeparateItems places each ordered item on a separate line, simplifying attribute handling. The scratch 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 that quantity is handled.

  NOTE: You must be sure that no fields in your forms have digits appended to their names if the variable is the same name as the attribute name you select, as the `[modifier-name size]` variables will be placed in the user session as the form variables size0, size1, size2, etc.

  MiniVend will automatically generate the select boxes when the `[accessories <code` size]> or `[item-accessories size]` tags are called. They have the syntax:

         [item_accessories attribute, type*, column*, table*, name*, outboard*]

         [accessories code=sku
                      attribute=modifier
                      type="select|radio|display|show|checkbox|text|textarea"*
                      column=column_name*
                      table=db_table*
                      name=varname
                      outboard=key
                      passed="value=label, value2, value3=label 3" ]

code
  Not needed for item-accessories, this is the product code of the item to reference. =item attribute

  The item attribute as specified in the UseModifier configuration directive. Typical are `size` or `color`.

type
  The action to be taken. One of:

        select          Builds a dropdown <SELECT> menu for the attribute.
                        NOTE: This is the default.

        multiple        Builds a multiple dropdown <SELECT> menu for the
                        attribute.  The size is equal to the number of
                        option choices.

        display         Shows the label text for *only the selected option*.

        show            Shows the option choices (no labels) for the option.

        radio           Builds a radio box group for the item, with spaces
                        separating the elements.

        radio nbsp      Builds a radio box group for the item, with &nbsp;
                        separating the elements.

        radio left n    Builds a radio box group for the item, inside a
                        table, with the checkbox on the left side. If "n"
                        is present and is a digit from 2 to 9, it will align
                        the options in that many columns.

        radio right n   Builds a radio box group for the item, inside a
                        table, with the checkbox on the right side. If "n"
                        is present and is a digit from 2 to 9, it will align
                        the options in that many columns.

        check           Builds a checkbox group for the item, with spaces
                        separating the elements.

        check nbsp      Builds a checkbox group for the item, with &nbsp;
                        separating the elements.

        check left n    Builds a checkbox group for the item, inside a
                        table, with the checkbox on the left side. If "n"
                        is present and is a digit from 2 to 9, it will align
                        the options in that many columns.

        check right n   Builds a checkbox group for the item, inside a
                        table, with the checkbox on the right side. If "n"
                        is present and is a digit from 2 to 9, it will align
                        the options in that many columns.

        textarea_XX_YY  A textarea with XX columns and YY rows

        text_XX         A text box with XX size in characters

  The default is 'select', which builds an HTML select form entry for the attribute. Also recognized is 'multiple', which generates a multiple-selection drop down list, 'show', which shows the list of possible attributes, and 'display', which shows the label text for the selected option only.

column
  The database column name to be used to build the entry (usually a field in the products database). Defaults to a field named the same as the attribute.

table
  The database table to find column in, defaults to the first products file where the item code is found.

name
  Name of the form variable to use if a form is being built. Defaults to mv_order_attribute -- i.e. if the attribute is size, the form variable will be named mv_order_size. If the variable is set in the user session, the widget will ``remember'' its previous setting.

outboard
  If calling the item-accessories tag, and you wish to select from an outboard database table with a different key from the item code, you can pass the key to use to find the accessory data.

When called with an attribute, the database is consulted and looks for a comma-separated list of attribute options. They take the form:

        name=Label Text, name=Label Text*

The label text is optional -- if none is given, the name will be used.

If an asterisk is the last character of the label text, the item is the default selection. If no default is specified, the first will be the default. An example:

        [item_accessories color]

This will search the product database for a field named ``color''. If an entry ``beige=Almond, gold=Harvest Gold, White*, green=Avocado'' is found, a select box like this will be built:

        <SELECT NAME="mv_order_color">
        <OPTION VALUE="beige">Almond
        <OPTION VALUE="gold">Harvest Gold
        <OPTION SELECTED>White
        <OPTION VALUE="green">Avocado
        </SELECT>

In combination with the `mv_order_item` and `mv_order_quantity` variables this can be used to allow entry of an attribute at time of order.

If used in an item list, and the user has changed the value, the generated select box will automatically retain the current value the user has selected.

The value can then be displayed with `[item-modifier size]` on the order report, order receipt, or any other page containing an `[item-list]`.

When called with an attribute, the database is consulted and looks for a comma-separated list of attribute options. They take the form:

        name=Label Text, name=Label Text*

The label text is optional -- if none is given, the name will be used.

If an asterisk is the last character of the label text, the item is the default selection. If no default is specified, the first will be the default. An example:

        [accessories TK112 color]

This will search the product database for a field named ``color''. If an entry ``beige=Almond, gold=Harvest Gold, White*, green=Avocado'' is found, a select box like this will be built:

        <SELECT NAME="mv_order_color">
        <OPTION VALUE="beige">Almond
        <OPTION VALUE="gold">Harvest Gold
        <OPTION SELECTED>White
        <OPTION VALUE="green">Avocado
        </SELECT>

In combination with the mv_order_item and mv_order_quantity variables this can be used to allow entry of an attribute at time of order.

EMULATING WITH LOOP
  Below 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 would normally be contained within the `[item_list]` `[/item-list]` pair.

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

  The above is essentially the same as would be output with the [item-accessories size] tag if the product database field `size` contained the value `S, M, L, XL`, but contains the adjusted price.

### Index Up >>