[ic] Tag->query in a usertag
Kevin Walsh
interchange-users@interchange.redhat.com
Thu Apr 18 23:16:01 2002
> UserTag get-valid-qty-break-fields Routine <<EOR
> sub {
> my $code = 'test-001';
> my $available_breaks =
> "q2,q3,q4,q5,q6,q7,q8,q9,q10,q12,q15,q25,q50,q100";
>
> my $break;
> my $sql = "SELECT " . $available_breaks . " FROM pricing WHERE
> sku ='" . $code . "';";
>
> my $sql_results = $Tag->query( {sql => $sql, hashref =>
> 'price_results' } );
>
> my $out = ref($sql_results);
>
> return $out;
> }
> EOR
>
> The inline perl returns 'ARRAY' as it should and the usertag returns ''.
> There are no errors in the error log, however it appears that the call
> to $Tag->query is not working in the usertag.
>
> I'm not too sure where to go from here, all of my tests show the code
> working inline, but fail as a usertag without violating safe
> constraints. Any ideas?
>
Remove this line:
my $sql_results = $Tag->query( {sql => $sql, hashref => 'price_results' } );
and replace with the following:
my $db = ::database_exists_ref('pricing') or die 'Bad pricing table';
my $sql_results = $db->query({ sql => $sql, hashref => 'price_results' });
By the way, there's no need for the ';' at the end of the SELECT statement.
Also, if you are going to go this way, you may as well create your own
price break table. A table with three columns should do the trick:
sku qty price
--------------- ------- -------
test-001 2 100.00
test-001 3 95.00
test-001 10 50.00
test-001 50 20.00
test-999 5 200.00
test-999 10 150.00
You'll find that a table like that will give you a lot more flexibility.
You won't have to use the same price breaks for every product and you
won't have to edit the UserTag every time you add a new price break.
Just something for you to think about.
--
_/ _/ _/_/_/_/ _/ _/ _/_/_/ _/ _/
_/_/_/ _/_/ _/ _/ _/ _/_/ _/ K e v i n W a l s h
_/ _/ _/ _/ _/ _/ _/ _/_/ kevin@cursor.biz
_/ _/ _/_/_/_/ _/ _/_/_/ _/ _/