[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date
][Minivend by thread
]
Re: [mv] 4.03 How to add user defined format check routines?
****** message to minivend-users from Mike Heins <mikeh@minivend.com> ******
Quoting Ton Verhagen (ton@verhagen.net):
> ****** message to minivend-users from "Ton Verhagen" <ton@verhagen.net> ******
>
> Hi all,
>
> I am wondering how I could add additional format check routines
> to the ones already defined in Order.pm.
>
> I'd like to implement some extra routines (eg. isbn) in the same
> way as the phone, state, province, and email check routines are
> implemented, so I would be able to use them in an order profile
> like:
>
> __NAME__ my_order_profile
> my_field=isbn
> my_email=email
> &fatal=yes
> __END__
>
> Of course I could simply add my routines to the source code of
> Order.pm but that's not what I am looking for, as this is not a
> desirable solution (for me that is).
>
> I've tried to define my routines in the order_profile definitions
> but that won't do the trick.
> Like:
> [perl]
> sub _isbn {
> <code>
> }
> [/perl]
>
> Also tried to define a Sub in minivend.cfg without success.
> No matter what I tried I always got the same result: 'No format
> check routine defined for 'isbn'. This simply means MV couldn't
> find the _isbn
> tine.:-(
>
>
> There should be a pragma &format according to the code of Order.pm, but I couldn't figure that one. Do I need &format to define additional format check routines?
>
> I am pretty sure that the great MV has an elegant way of adding user defined format checking routines, the only thing left is to know how to do it.
>
> Has anyone done this before, or does anyone know how to go about?
>
> Many thanks in advance for your kind cooperation.
I put this in back in 3.xx, and it still applies:
* Added order profile checks for "state", "province",
"province_or_state", "postcode", "ca_postcode", and "zip". Sorry,
only US/Canada supported, but you can add a check yourself
in a GlobalSub:
GlobalSub <<EOF
sub set_up_extra_check {
BEGIN {
package Vend::Order;
sub _pt_postcode {
# $ref is to Vend::Session->{'values'} hash
# $var is the passed name of the variable
# $val is current value of checked variable
my($ref, $var, $val) = @_;
if ($ref->{country} =~ /^(PT|portugal)$/i) {
return $val =~ /^\d\d\d\d$/ ? 1 : 0;
}
else {
return 1;
}
}
}
}
EOF
Now you can specify in an order profile:
postcode=pt_postcode
There must be an underscore preceding the routine name in this
case. Very elaborate checks are possible, of course. If some user
takes on the polyglot it would be appreciated if they contribute
the routines.
To you MiniVend hackers out there, this is a general technicque you can
use to override MV subroutines. For the most part, I try to keep the
same call interface, and this should make updates *much* easier.
--
Internet Robotics, 131 Willow Lane, Floor 2, Oxford, OH 45056
phone +1.513.523.7621 fax 7501 <mikeh@minivend.com>
Fast, reliable, cheap. Pick two and we'll talk. -- unknown
-
To unsubscribe from the list, DO NOT REPLY to this message. Instead, send
email with 'UNSUBSCRIBE minivend-users' in the body to Majordomo@minivend.com.
Archive of past messages: http://www.minivend.com/minivend/minivend-list