Permalink
Browse files

- slight adjustments to existing stuff

- 3 new howtos
  • Loading branch information...
1 parent d78b56e commit a013646d12d88df4ef10c9a62ed044606b9f826e @docelic docelic committed Aug 15, 2006
Showing with 133 additions and 10 deletions.
  1. +3 −0 TODO
  2. +57 −0 howtos/category-based-vat
  3. +21 −0 howtos/check-for-errors-in-form-submission
  4. +49 −0 howtos/make-data-structure-modifiable
  5. +2 −2 refs/HouseKeeping
  6. +0 −7 refs/MaxServers
  7. +1 −1 refs/PreFork
View
3 TODO
@@ -8,6 +8,9 @@
- that howto entries get automatic title if start with < in first line
- unit testing
- remove NEW from <meta>
+- In tags, make XSLT code print position number besides "Yes" word in
+ positional parameters for tags
+- add search box to guides/index.xml
Outstanding:
=======
View
@@ -0,0 +1,57 @@
+Use Category-dependent Tax Rates
+</para></question>
+
+<answer><para>
+Many european countries use product category-dependent tax rates.
+The question is, how to implement this in &IC;.
+</para><para>
+A quick and dirty way is to write a &glos-usertag; for calculation
+and include it in <database>salestax</database> database.
+<programlisting><![CDATA[
+UserTag vat-calc Order table field
+UserTag vat-calc addAttr
+UserTag vat-calc Routine <<EOR
+sub {
+ my ($table, $field, $opt) = @_;
+
+ my $error = sub {
+ my $msg = shift;
+ Log($msg);
+ return undef;
+ };
+
+ my $tax = 0;
+ foreach my $item (@$Vend::Items) {
+ my $taxrate = tag_data($table, $field, $item->{code});
+ $tax += ($taxrate * $item->{quantity});
+ }
+ return $tax;
+}
+EOR
+]]></programlisting>
+(If you add the above in &ccf; instead of &gcf;, you will have to
+make sure you reference the <database>products</database> database
+before this code runs). <!-- exactly how to do this? -->
+</para><para>
+Create <filename>salestax.asc</filename>:
+<programlisting>
+default [vat-calc products tax]
+UK [vat-calc products tax]
+FR [vat-calc products tax]
+US 0
+</programlisting>
+Modify &ccf;:
+<programlisting>
+SalesTax country
+</programlisting>
+At this point, tax rates would be taken from the
+<database class='field'>tax</database> field in the
+<database>products</database> database.
+</para><para>
+Finally, to retrieve category-dependent tax rate, you can specify:
+<programlisting>
+AutoModifier products:category
+</programlisting>
+in &ccf; and use <code>$item->{category}</code> (in &conf-CommonAdjust;
+for example) as the key to lookup tax value rate.
+<!-- Full working example todo -->
@@ -0,0 +1,21 @@
+Check for Errors in Form Submission
+</para></question>
+
+<answer><para>
+<!--
+
+(Below is as of 4.03, the equivalent in 4.02 is
+\[if type=explicit compare="[error all=1 keep=1]"] ... [/if].)
+
+To check errors without clearing them, you can use the idiom:
+
+> [if errors]
+> <FONT SIZE="+1" COLOR=RED>
+> There were errors in your form submission.
+> </FONT>
+> <BLOCKQUOTE>
+> [error all=1 show_error=1 joiner="<BR>"]
+> </BLOCKQUOTE>
+> [/if]
+
+-->
@@ -0,0 +1,49 @@
+Make Perl Hash Seemingly Modifiable
+</para></question>
+
+<answer><para>
+Sometimes you want to make a data structure modifiable, without having the
+changes permanently override original values. To do so, we can use &PERL;'s
+<classname>Tie::ShadowHash</classname> module.
+</para><para>
+This is an old trick, generally not needed any more since &glos-configuration;
+directives already are modifiable per-page (usually through an
+&conf-Autoload; routine). However, you might find it useful. Here's the
+usertag:
+<programlisting><![CDATA[
+UserTag modifiable Order thing
+UserTag modifiable Routine <<EOR
+require Tie::ShadowHash;
+sub {
+ my $thing = shift || 'Variable';
+ my $ref = $Vend::Cfg->{$thing};
+ return undef if ref($ref) ne 'HASH';
+
+ my %hash;
+ tie %hash, 'Tie::ShadowHash', $ref;
+
+ my $new = \%hash;
+ $Vend::Cfg->{$thing} = $new;
+
+ if($thing eq 'Variable') {
+ $::Variable = $Vend::Interpolate::Variable = $new;
+ }
+
+ return "$thing set to modifiable";
+}
+EOR
+]]></programlisting>
+Establish initial value in &ccf:
+<programlisting>
+Variable FOO bar
+</programlisting>
+And test with the following code:
+<programlisting>
+FOO=__FOO__<br>
+FOO=[var FOO]<br>
+[modifiable]<br>
+Set...[calc] $Variable->{FOO} = 'hosed'; [/calc]<br>
+FOO=[var FOO]
+</programlisting>
+The output should be the same on every page reload.
+
View
@@ -11,9 +11,9 @@ __END__
__NAME__ description
-Specify time &glos-interval;s at which should the Interchange server
+Specify periodic time &glos-interval; at which the Interchange server should
<emphasis>wake up</emphasis> and
-look for user reconfiguration requests and hung search processes. On some
+look for user reconfiguration requests and hung processes. On some
systems, this wakeup is the only time the server will terminate in response
to a stop command.
__END__
View
@@ -25,13 +25,6 @@ server's "usage count" drops.
__END__
__NAME__ notes
-The directive is only used when &IC; is in <literal>PreFork</literal>
-&glos-ic-run-mode;.
-__END__
-
-
-__NAME__ missing
-Is this only in PreFork? if not, fix Notes section.
__END__
View
@@ -18,7 +18,7 @@ __END__
__NAME__ description
For each new client connection, &IC; must spawn a new process that will
handle communication with the client.
-By using &conf-PreFork; it is possible to <emphasis>pre-fork</emphasis>
+By using &conf-PreFork;, it is possible to <emphasis>pre-fork</emphasis>
(or in other words, "start ahead of time") some number of &IC; servers
that will be ready to serve client requests immediately as they come in.
</para><para>

0 comments on commit a013646

Please sign in to comment.