Index  Up  <<  >>  


Price Maintenance with CommonAdjust

As of MiniVend 3.11, a flexible chained pricing scheme is available when the CommonAdjust directive is set.

NOTE: For compatibility with older carts, if both PriceAdjustment and CommonAdjust are set, and CommonAdjust contains a valid database identifier, the CommonAdjust value is used to set pricing adjustments based on item attributes. This is not discussed further in this section; all items below assume PriceAdjustment is not in use.

We talk below about a CommonAdjust string; it will be defined in due time.

A few rules about CommonAdjust, all assuming the PriceField directive is set to price:

  1. If CommonAdjust is set to any value, a valid CommonAdjust string or not, extended price adjustments are enabled. It may also hold the default pricing scheme.

  2. The price field may also hold a CommonAdjust string. It takes precedence over the default.

  3. If the value of the CommonAdjust directive is set to a CommonAdjust string, and the price field is empty or specifically 0, then it will be used to set the price of the items.

  4. If PriceBreaks is in use, it's price will take precedence over the value of CommonAdjust, though it may also contain a CommonAdjust string.

  5. If no CommonAdjust strings are found, then the price will be 0, subject to any later application of discounts.

  6. If another CommonAdjust string is found as the result of an operation, it will be re-parsed and the result applied. Chaining is retained; a fallback may be passed and will take effect.

Prices may be adjusted in several ways, and the individual actions are referred to below as atoms. Price atoms they may be final, chained, or fallback. A final price atom is always applied if it does not evaluate to zero. A chained price atom is subject to further adjustment. A fallback price atom is skipped if a previous chained price was not zero.

Atoms are separated by whitespace, and may be quoted (although there should not normally be whitespace in a setting). A chained item ends with a comma. A fallback item has a leading semi-colon. Final atoms have no comma appended or semi-colon prepended.

A settor is the means by which the price is set. There are There are eight different types of price settors. All settors can then yield another CommonAdjust string.

It is quite possible to create endless loops, so the maximum number of initial CommonAdjust strings is set to 16, and there may be only 20 iterations before the price will return zero on an error.

NOTE: Common needs are easily shown but not so easily explained; skip to the examples if the reference below if your vision starts to blur when reading the next section. 8-)

USAGE: Optional items below have asterisks appended. The asterisk should not be used in the actual string. Optional base or table always defaults to the active products database table. The optional key defaults to the item code except in a special case for the attribute-based lookup. The field name is not optional except in the case of an attribute lookup.

N.NN or -N.NN
where N is a digit. A number which is applied directly; for instance 10 will yield a price of 10. May be a positive or negative number.

N.NN%
where N is a digit. A number which is applied as a percentage of the current price value. May be a positive or negative number. For example, if the price is 10 and -8% is applied, the next price value will be 9.20.

table*:column:key*
Causes a straight lookup in a database table. The optional table defaults to the main products database table for the item (subject of course to multiple product files). The column must always be present. The optional key defaults to the item code except in a special case for the attribute-based lookup. The return value is then re-parsed as another price settor.

table*:col1..col5,col10:key*
Causes a quantity lookup in database table table (which defaults to the products database), with a set of comma-separated fields, looked up by the optional key. (Key defaults to the item code, of course). If ranges are specified with .., each column in the sequence will be used; Therefore

    pricing:p1,p2,p3,p4,p5,p10:

is the same as

    pricing:p1..p5,p10:

Leading non-digits are stripped, and the item quantity is compared with the numerical portion of the column name. The price is set to the value of the database column (numeric portion) that is at least equal to it but doesn't yet reach the next break.

WARNING: If the field at the appropriate quantity level is blank, a zero cost will be returned from the atom. It is important to have all columns populated.

==attribute:table*:column*:key*
Does an attribute-based adjustment. The attribute is looked up in the database table, with the optional column defaulting to the same name as the value of the attribute. If the column is not left blank, the key is set to the value of the attribute if blank.

&amp; CODE
The leading & sign is stripped and the code is passed to the equivalent of a [calc] tag. No MiniVend tags can be used, but the &tag_data routine is available, the current value of the price and quantity are available as $s, and the current item (code, quantity, price, and any attributes) are available as $item, all forced to the package Vend::Interpolate. That means that in a UserTag:

  $Vend::Interpolate::item          is the current item
  $Vend::Interpolate::item->{code}  gives key for current item
  $Vend::Interpolate::item->{size}  gives size for current item (if there)
  $Vend::Interpolate::item->{mv_ib} gives database ordered from

[valid minivend tags]
If the settor begins with a square bracket ([) or underscore, it is parsed for MiniVend tags with variable substitution (but no Locale substitution). You may define a price in a Variable in this fashion. The string is re-submitted as an atom, so it may yield yet another settor.

$
Tells MiniVend to look in the mv_price attribute of the shopping cart, and apply that price as the final price, if it exists. The attribute must be a numerical value.

>>word
Tells the routine to return word directly as the result. This is not useful in pricing, as it will evaluate to zero. But when CommonAdjust is used for shipping, it is a way of re-directing shipping modes.

word
The value of word, which must not match any of the other settors, is available as a key for the next lookup (only). If the next settor is a database lookup, and it contains a dollar sign ($) the word will be substituted; i.e. table:column:$ becomes table:column:word.

( settor )
The value returned by settor will be used as a key for the next lookup, as above.


Index  Up  <<  >>