Tweaking Your Products

The tweak.rules rules file, unlike other rules files, has no direct effect on your checkout line-items. Instead, it is used to modify products read from your products source (usually your products file), allowing you to "tweak" their values according to user input, store conditions, or just about anything you can do in HZML.

Since you're all big boys and can deal with just jumping into an example, let's do that right now. The following tweak.rules file would cut in half the price of any item with a true SLASH field.

## tweak.rules
##   Rules for tweaking product info right after Hazel reads their data
## from the standard source.
## --
## quinn@netsville.com

<Hazel-Loop Type="Products" Src="%HZH_TWEAKABLE" >
<Hazel-True Token="%HZI_SLASH">
<Hazel-False Token="%HZI_SLASHED">
<Hazel-Math Value="%HZI_PRICE" OP1="/2" Type="Float" />
SKUID: %HZI_SKUID
PRICE: %HZV_RESULT
NOTE: Price of %HZI_NAME is SLASHED in half for a limited time!
SLASHED: 1
</Hazel-False>
</Hazel-True>
</Hazel-Loop>

## End.

The one thing common to all tweak files is the %HZH_TWEAKABLE value. It will contain a semicolon delimited list of all SKUID Hazel feels should be "tweaked" at the time the file is processed. Above, we use a standard Hazel-Loop to loop over each of those.

Within this set of "tweakable" products, we only care about those with a true SLASH field value. Of those, we want to avoid processing the ones we've already set as SLASHED.

So, if a tweakable product is slashable and hasn't already been slashed, we do some Hazel-Math to determine the half-price (note we specify a floating point return value), then we output lines just as we would in a Hazel products file, starting with an indication of the SKUID we're setting, then subsequent lines of field values.

And it's just that easy!


Getting Started HZML Rules Extras Advanced Reference
Walkthrough
Configuration
Products File
Order Reporting
Platforms
Upgrading
Known Problems
Actions
HZML Tokens
HZML Tags
HZML Loops
HZML & HAM
Overview
Shipping
Sales Tax
Discounts
Surcharges
Tweaking
Customization
Input Fields
Softgoods
Search Engine
Optioned Products
Plugins
Design Tips
Themes
Currency
Payment Methods
Coupons
Regular Expressions
Perl API
hazel.config
Templates
HTML Basics
CGI and You
ChangeLog

Hazel Home - Help Contents - Searchable Knowledge Base - Live Technical Support