2016-11-17 2 views
0

Ich habe einen PHP-Code, der Zahlen in Wörter umwandelt. Wie kann ich das in Prestashop 1.6.0.14 Rechnung implementieren?Wie wird der Gesamtpreis in Worten in Prestashop Rechnung hinzugefügt?

Ich habe versucht, den Code zu schreiben:

<?php 
$num = '123'; 
list($p1, $p2) = explode('.', str_replace(',','.',$num)); 
?> 

<table style="width: 100%;"> 
    <tr> 
     <td>Amout in words: <?php echo ucfirst(words($p1)) . ' eur ' . ' and '.$p2 . ' ct' ; ?></td> 
    </tr> 
</table> 

Antwort

0

Siehe den Code unten

<?php 

$number = 1052; 
$no = round($number); 
$point = round($number - $no, 2) * 100; 
$hundred = null; 
$digits_1 = strlen($no); 
$i = 0; 
$str = array(); 
$words = array('0' => '', '1' => 'One', '2' => 'Two', 
       '3' => 'Three', '4' => 'Four', '5' => 'Five', '6' => 'Six', 
       '7' => 'Seven', '8' => 'Eight', '9' => 'Nine', 
       '10' => 'Ten', '11' => 'Eleven', '12' => 'Twelve', 
       '13' => 'Thirteen', '14' => 'Fourteen', 
       '15' => 'Fifteen', '16' => 'Sixteen', '17' => 'Seventeen', 
       '18' => 'Eighteen', '19' =>'Nineteen', '20' => 'Twenty', 
       '30' => 'Thirty', '40' => 'Forty', '50' => 'Fifty', 
       '60' => 'Sixty', '70' => 'Seventy', 
       '80' => 'Eighty', '90' => 'Ninety'); 
$digits = array('', 'Hundred', 'Thousand', 'Lakh', 'Crore'); 
while ($i < $digits_1) { 
    $divider = ($i == 2) ? 10 : 100; 
    $number = floor($no % $divider); 
    $no = floor($no/$divider); 
    $i += ($divider == 10) ? 1 : 2; 
    if ($number) { 
     $plural = (($counter = count($str)) && $number > 9) ? 's' : null; 
     $hundred = ($counter == 1 && $str[0]) ? ' and ' : null; 
     $str [] = ($number < 21) ? $words[$number] . 
      " " . $digits[$counter] . $plural . " " . $hundred 
      : 
     $words[floor($number/10) * 10] . " " . $words[$number % 10] . " " . $digits[$counter] . $plural . " " . $hundred; 
    } else $str[] = null; 
} 
$str = array_reverse($str); 
$rupees = implode('', $str); 
$points = ($point) ? "" . $words[$point/10] . " " . $words[$point = $point % 10] : ''; 
if($points!="") 
    echo $rupees . "rupees and " . $points . " paise ."; 
else 
    echo $rupees . "rupees ."; 
?> 
+1

Und wie dieser Code hinzuzufügen Rechnung (TPL) prestatashop Datei? – Andrius

+0

http://Stackoverflow.com/a/9601682/4833984 – Mubin

+0

Überprüfen Sie den obigen Link, um den Code in 'tpl' Datei hinzuzufügen – Mubin

Verwandte Themen