using a php twig converter, i converted to twig format. as usual it did not work. looking for the MVC structure, i think to use this function one of the order files, than write output to order_invoice.twig. Twig documentation page says i guess that have to install twig extensions to use some more php functions . i am confused.
i have to install twig extensions to use some more php functions?
or can i use this function in order_invoices.twig?
or in which file i have to use this function to have an output and be able to write output in order_invoice.twig?
php function numtowords($num){
$decones = array(
'01' => "one",
'02' => "two",
'03' => "three",
'04' => "four",
'05' => "five",
'06' => "six",
'07' => "seven",
'08' => "eight",
'09' => "nine",
10 => "ten",
11 => "eleven",
12 => "twelve",
13 => "thirteen",
14 => "foruteen",
15 => "fifeteen",
16 => "sixteen",
17 => "seventeen",
18 => "eighteen",
19 => "nineteen"
);
$ones = array(
0 => "",
1 => "",
2 => "two",
3 => "three",
4 => "four",
5 => "fve",
6 => "six",
7 => "seven",
8 => "eight",
9 => "nine",
10 => "ten",
11 => "eleven",
12 => "twelve",
13 => "thirteen",
14 => "foruteen",
15 => "fifeteen",
16 => "sixteen",
17 => "seventeen",
18 => "eighteen",
19 => "nineteen"
);
$tens = array(
0 => "",
2 => "twenty",
3 => "thirty",
4 => "fourty",
5 => "fifty",
6 => "sixty",
7 => "seventy",
8 => "eighty",
9 => "ninety"
);
$hundreds = array(
"hundered",
"thousand",
"Milioon",
"Billion",
"Trillion",
"Quadrillion"
); //limit t quadrillion
$num = number_format($num,2,".",",");
$num_arr = explode(".",$num);
$wholenum = $num_arr[0];
$decnum = $num_arr[1];
$whole_arr = array_reverse(explode(",",$wholenum));
krsort($whole_arr);
$rettxt = "";
foreach($whole_arr as $key => $i){
if($i < 20){
$rettxt .= $ones[$i];
}
elseif($i < 100){
$rettxt .= $tens[substr($i,0,1)];
$rettxt .= "".$ones[substr($i,1,1)];
}
else{
$rettxt .= $ones[substr($i,0,1)]."".$hundreds[0];
$rettxt .= "".$tens[substr($i,1,1)];
$rettxt .= "".$ones[substr($i,2,1)];
}
if($key > 0){
$rettxt .= "".$hundreds[$key]."";
}
}
$rettxt = $rettxt."dolar";
if($decnum > 0){
$rettxt .= "";
if($decnum < 20){
$rettxt .= $decones[$decnum];
}
elseif($decnum < 100){
$rettxt .= $tens[substr($decnum,0,1)];
$rettxt .= "".$ones[substr($decnum,1,1)];
}
$rettxt = $rettxt."cent.";
}
return $rettxt;}
$total['ntext'] =filter_var($total['text'], FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
echo numtowords($total['ntext']);
Code: Select all
$data['total'] = numtowords($total['ntext']);
{{ total }}
and it will display there.
twigs generally are not suited for program logic, mostly display logic.
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
Code: Select all
$data['total'] = $this->numtowords($total['ntext']);
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
Notice: Undefined variable: total in /home/***/public_html/admin/controller/sale/order.php on line 1948 Warning: number_format() expects parameter 1 to be float, string given in /home/***/public_html/admin/controller/sale/order.php on line 1909
order.php 1948, 1949, 1950 (last lines)
$total['ntext'] =filter_var($total['text'], FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
echo numtowords($total['ntext']);
$data['total'] = numtowords($total['ntext']);
order.php 1909
$num = number_format($num,2,".",",");
So check where you define variable $num.
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.

Code: Select all
$data['order_status_id'] = $order_info['order_status_id'];
$data['comment'] = $order_info['comment'];
at the very end, the view is called and that array is passed to it.
Code: Select all
$this->response->setOutput($this->load->view('sale/order_form', $data));
so you add the total string from your function to that array as well:
Code: Select all
$data['total'] = $whatever_comes_out_of_your_function;
then that is also passed to the view and picked up there and displayed when you add {{ total }} in that twig file.
(make sure $data['total'] is not already used for some other info)
that is how controller and view interact in V3.
not much different from .tpl in V2.
Why are you adding this to admin?
the error message for line 1909 has nothing to do with this, that is just because you cannot try to format_number a string.
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
Yet $total['ntext'] is a string, not a float. Hence the error message which comes from your function.
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
thanks for your very well explanation, help me to learn better. regards
Code: Select all
$data['total'] = $this->numtowords($float_variable);
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
Users browsing this forum: No registered users and 15 guests