Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Total price in pdf invoice contains <strong> tags


Herra Hakala

Recommended Posts

Hello, I installed the PDF Invoice (http://www.oscommerce.com/community/contributions,3027)module, and now when I open a pdf created by it contains <strong> tags, show in the picture:

 

post-309677-0-33268600-1332329892_thumb.png

 

I tried to search the files, I opened all files on catalog folder in notepad++, searched for Strong.

 

It found 1.3k results, from those I tried to find something relevant but couldn't.

 

The code on the pdf script that creates those texts is this:

 


$pdf->MultiCell(94,6,$order->totals[$i]['title'] . ' ' . $order->totals[$i]['text'],0,'R');

 

Anyone know what I need to change to remove those tags?

 

Thanks.

Link to comment
Share on other sites

The <strong> tags are stored in the database along with the formatted price. You could use a regex to remove them, or pull the unformatted price from the table and add the formatting.

 

This old contribution doesn't handle Unicode fonts, so you're likely to have more problems than this trying to use this with osCommerce 2.3.1.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

The <strong> tags are stored in the database along with the formatted price. You could use a regex to remove them, or pull the unformatted price from the table and add the formatting.

 

This old contribution doesn't handle Unicode fonts, so you're likely to have more problems than this trying to use this with osCommerce 2.3.1.

 

Regards

Jim

 

Thanks, a friend gave me this code:

preg_replace('/<[//]{0,1}(B|B)[^><]*>/g', '',$order->totals[$i]['text'];

 

 

But it doesn't seem to work, is there no way to stop OSCommerce from adding the strong tags to database?

Link to comment
Share on other sites

Thanks, a friend gave me this code:

preg_replace('/<[//]{0,1}(B|B)[^><]*>/g', '',$order->totals[$i]['text'];

That code doesn't make sense. What you want to do, once you have a string containing <strong> and </strong>, is to remove those tags from the string:

preg_replace('/<[\/]?strong>/gi', '', $order->totals[$i]['text'];

 

You can make similar statements for <b> and </b>, etc. (any HTML tags that are showing up in the PDF). Actually, I'd be surprised if there isn't a way to make the PDF functions accept HTML input and change them to the permitted PDF tags.

Link to comment
Share on other sites

I just noticed that the preg_replace call is missing its closing ), and you need to use the output of the call (it doesn't change the parameter):

$str = preg_replace('/<[\/]?strong>/gi', '', $order->totals[$i]['text']);
/* use $str rather than $order->totals[$i]['text'] */

Link to comment
Share on other sites

Thaks for the help, but now it doesn't print anything out anymore

 

Code:


$str = preg_replace('/<[\/]?strong>/gi', '', $order->totals[$i]['text']);
/* use $str rather than $order->totals[$i]['text'] */
$pdf->MultiCell(94,6,$order->totals[$i]['title'] . ' ' . $str,0,'R');

 

Error:


Warning: preg_replace(): Unknown modifier 'g' in /home/kauppate/www/pdfinvoice.php on line 683 
Warning: preg_replace(): Unknown modifier 'g' in /home/kauppate/www/pdfinvoice.php on line 683 
Warning: preg_replace(): Unknown modifier 'g' in /home/kauppate/www/pdfinvoice.php on line 683 
Warning: preg_replace(): Unknown modifier 'g' in /home/kauppate/www/pdfinvoice.php on line 683 

Link to comment
Share on other sites

Odd, I thought 'g' was a legitimate modifier (global = multiple occurences per string). I guess not. It's astonishing that it's lacking in the PCRE implementation! The problem becomes one of how to match and replace multiple times. If you're sure that there will be at most one pair of <strong> </strong> in a string, you could:

$str = preg_replace('/<strong>/i', '', $order->totals[$i]['text']);
$str = preg_replace('/<\/strong>/i', '', $str);
$pdf->MultiCell(94,6,$order->totals[$i]['title'] . ' ' . $str,0,'R');

 

If you notice that there are two or more sets of strong tags within a single string, you'll need to loop:

$oldstr = '';
$str = $order->totals[$i]['text'];
while ($str != $oldstr) {
 $oldstr = $str;
 $str = preg_replace('/<strong>/i', '', $str);
 $str = preg_replace('/<\/strong>/i', '', $str);
}
$pdf->MultiCell(94,6,$order->totals[$i]['title'] . ' ' . $str,0,'R');

 

P.S. Looking at the code some more, it might be safer to escape the backslash ([\\/] rather than [\/]). I don't think it matters for a string within single quotes ', as \/ should not be evaluated, but definitely if you ever changed it to double quotes " the \/ would probably be evaluated too early (at the PHP string handling pass) and end the search pattern too early. Even easier, change / to some other character for the delimiters:

$str = preg_replace('#</strong>#i', '', $str);

Link to comment
Share on other sites

  • 4 months later...

I have uploaded community contribution files and details on a "fix" for this html tag ,<strong></strong> issue for PDF Invoice for anyone still having trouble.

After initial setting up you've then got to tweak the configuration settings to settings get a pleasant/professional looking invoice- (I don't know why they made the initial default invoice with every conceivable mismatched color- I guess to show it's possible to have an invoice for your circus or clown business.

You can also tweak settings in the pdf_invoice.php to move around or adjust the logo and the text elements but be careful not to frolic in the field of code too long if you don't know how to restore the original file or can't figure the php settings in there.

Also I ran into another issue- pdf generated the html tags <strong>$795.95</strong> on the last line- the Total Line on the pdf. I spent considerable time troubleshooting and researching this out- I found that a php file called ot_total.php found-

catalog/admin/includes/modules/order_total/ot_total.php on around line 29-39

 

29 $this->output[] = array('title' => $this->title . ':',

30 'text' => '<strong>' . $currencies->format($order->info['total'], true, $order->info['currency'], $order->info['currency_value']) . '</strong>',

 

I solved the problem by just removing the tags like this-

 

29 $this->output[] = array('title' => $this->title . ':',

30 'text' => '' . $currencies->format($order->info['total'], true, $order->info['currency'], $order->info['currency_value']) . '',

 

However, it does change the html generated invoice also so that the total price is no longer bold. But I can live with that, can you?

Peace Out. CreatorG

Link to comment
Share on other sites

  • 11 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...