HaLe Blog twitter
HaLe Blog Rss

Drupal cache headers are driving me nuts!

Posted by Kim | Posted in Coding, Content Management Systems, Drupal, PHP | Posted on 10-10-2011

0

A client of ours had this problem on their website, where users who had logged out, could still see their profile page as if they were connected!

After googling (what else!) I found the answer to be in a slight change of the headers being sent by Drupal:

File: /includes/bootstrap.inc, line 728 / 765

From:

Cache-Control:store, no-cache, must-revalidate, post-check=0, pre-check=0

To:

Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0

More info on this issue can be found here: http://drupal.org/node/197786#comment-1565612, the patch is right here: http://drupal.org/files/issues/login_linger.patch

Drupal + Ubercart tax calculations go wrong..

Posted by Kim | Posted in Content Management Systems, Drupal | Posted on 22-07-2011

0

Hi guys,

We’ve encountered some strange behaviour while implementing Ubercart on a client’s website. it seems that when you’re having multiple tax-rates, they all get added, and there is no real way to “filter” out the last correct one.

Also there seems to be a buggy code issue, where a line item is not added when your tax-rate is set to “0%”.

The following code proves this:

<?php
function uc_taxes_apply_tax($order, $tax) {
$amount = 0;
$taxable_amount = 0;
if (is_array($order->products)) {
foreach ($order->products as $item) {
$taxable_amount += uc_taxes_apply_item_tax($item, $tax);
}
}
$taxed_line_items = $tax->taxed_line_items;
if (is_array($order->line_items) && is_array($taxed_line_items)) {
foreach ($order->line_items as $key => $line_item) {
if ($line_item['type'] == ‘tax’) {
// Don’t tax old taxes.
continue;
}
if (in_array($line_item['type'], $taxed_line_items)) {
$taxable_amount += $line_item['amount'];
}
}
}
if (isset($taxed_line_items['tax'])) {
// Tax taxes that were just calculated.
foreach ($order->taxes as $other_tax) {
$taxable_amount += $other_tax->amount;
}
}
$amount = $taxable_amount * $tax->rate;
if ( $amount ) {
$line_item = (object)array(
‘id’ => $tax->id,
‘name’ => $tax->name,
‘amount’ => $amount,
‘weight’ => $tax->weight,
‘summed’ => 1,
);
$line_item->data = array(
‘tax_id’ => $tax->id,
‘tax_rate’ => $tax->rate,
‘taxable_amount’ => $taxable_amount,
‘tax_jurisdiction’ => $tax->name,
);
return $line_item;
}
}
?>

In the above function, the line item is only added when the $amount variable equals something “true”. This does *not* include the *valid* value of “0″ €, in the case you have set a tax rate of 0 (because 3 € * 0 % = 0).

The following behaviour can be fixed by just commenting the if ( $amount ) as follows:
<?php
//if ( $amount ) {
$line_item = (object)array(
‘id’ => $tax->id,
‘name’ => $tax->name,
‘amount’ => $amount,
‘weight’ => $tax->weight,
‘summed’ => 1,
);
$line_item->data = array(
‘tax_id’ => $tax->id,
‘tax_rate’ => $tax->rate,
‘taxable_amount’ => $taxable_amount,
‘tax_jurisdiction’ => $tax->name,
);
return $line_item;
//}
?>

Say you have 2 tax rates:
A. 21% for everyone
B. 0% for specific case with conditions.

Then, both tax rates should be applied, but only *one* should remain and be added to the order?

For example:

Subtotal = 5 €
Taxrate A =  5 € * 21% == 1.05 €
Taxrate B = 5 € * 0% == 0.00 €
Total = 5€ + 1.05 € + 0.00 €…

I hope this can help some other people when looking into Tax rates.

Geshi Supported Languages

Posted by Kim | Posted in Coding | Posted on 23-04-2010

1

It took us *too* long to find a list of supported languages for our GeShi Code Highlighter so here it is, to never more forget it!

Supported Languages

The following languages are supported in the lang attribute:

abap, actionscript, actionscript3, ada, apache, applescript, apt_sources, asm, asp, autoit, avisynth, bash, bf, bibtex, blitzbasic, bnf, boo, c, c_mac, caddcl, cadlisp, cil, cfdg, cfm, cmake, cobol, cpp-qt, cpp, csharp, css, d, dcs, delphi, diff, div, dos, dot, eiffel, email, erlang, fo, fortran, freebasic, genero, gettext, glsl, gml, bnuplot, groovy, haskell, hq9plus, html4strict, idl, ini, inno, intercal, io, java, java5, javascript, kixtart, klonec, klonecpp, latex, lisp, locobasic, lolcode lotusformulas, lotusscript, lscript, lsl2, lua, m68k, make, matlab, mirc, modula3, mpasm, mxml, mysql, nsis, oberon2, objc, ocaml-brief, ocaml, oobas, oracle11, oracle8, pascal, per, pic16, pixelbender, perl, php-brief, php, plsql, povray, powershell, progress, prolog, properties, providex, python, qbasic, rails, rebol, reg, robots, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, sql, tcl, teraterm, text, thinbasic, tsql, typoscript, vb, vbnet, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xml, xorg_conf, xpp, z80