UseModifier — specify default attributes that can be attached to items
Specify item attributes (or modifiers) that can be be attached to items.
Some of the names are reserved for use by Interchange, and you must not use them
in modifier names. Namely, they include
item
,
group
,
quantity
,
free
,
free_message
,
code
and, of course,
all mv_
variables.
You can see a quick list of those "reserved" names by entering the Interchange
source tree and issuing grep -r 'item->{[^$]' * | less
.
Example: Simple and standalone UseModifier example
We first need to define UseModifier
in the catalog.cfg
file (and restart
Interchange afterwards):
UseModifier size,color
Then we need to add the appropriate columns — size and color — to the products database. Here's an example:
sku description price size color 50595 Standard T-Shirt 15 S=Small, M=Medium, L=Large*, XL=Extra Large red=Red, blue=Blue, white=White 50623 Winter Jacket 140 S=Small, M=Medium, L=Large, XL=Extra Large*, XXL=Extra Extra Large blue=Blue, white=White, black=Black 50198 Long-sleeved Cotton Shirt 45 M=Medium*, L=Large red=Red, blue=Blue, white=White, maroon=Maroon
(The entry signified with "*
" will be understood as the
default).
And now all we need to display item size options is call
[accessories
on an
Interchange page. Let's create a sample
attributes.html page:SKU
size]
<html> <body> <table cellpadding="5"> <tr> <th>Test #</th> <th>Description</th> <th>Price</th> <th>Modifiers</th> </tr> [loop search="ra=yes/fi=products"] <tr> <td>[loop-code]</td> <td> [page [loop-code]] [loop-field description] </a> </td> <td align="right">[loop-field price]</td> <td> [loop-accessories size] [loop-accessories color] </td> </tr> [/loop] </table> </body> </html>
I hope this completes a very simple but working example, and breaks the entry-barrier to the world of Interchange modifiers.
Interchange 5.9.0:
Source: lib/Vend/Config.pm
Line 3780 (context shows lines 3780-3800)
sub parse_array { my($item,$settings) = @_; return '' unless $settings; my(@setting) = grep /\S/, split /[\s,]+/, $settings; my $c; if(defined $C) { $c = $C->{$item} || []; } else { no strict 'refs'; $c = ${"Global::$item"} || []; } for (@setting) { check_legal($item, $_); push @{$c}, $_; } $c; }