2015-02-07 64 views
0

我想將Magento價格視圖更改爲我的語言。我的意思是我想改變數字。在Magento中應用php函數價格

我有這個PHP函數:

function fanum($englishnumbers) 
{ 
$englishnumbers = str_replace(’0′ , ‘٠’ , $englishnumbers); 
$englishnumbers = str_replace(’1′ , ‘١’ , $englishnumbers); 
$englishnumbers = str_replace(’2′ , ‘٢’ , $englishnumbers); 
$englishnumbers = str_replace(’3′ , ‘٣’ , $englishnumbers); 
$englishnumbers = str_replace(’4′ , ‘۴’ , $englishnumbers); 
$englishnumbers = str_replace(’5′ , ‘۵’ , $englishnumbers); 
$englishnumbers = str_replace(’6′ , ‘۶’ , $englishnumbers); 
$englishnumbers = str_replace(’7′ , ‘٧’ , $englishnumbers); 
$englishnumbers = str_replace(’8′ , ‘٨’ , $englishnumbers); 
$englishnumbers = str_replace(’9′ , ‘٩’ , $englishnumbers); 

return $englishnumbers; 
} 

和:

$echo fanum($en_number); 

如何應用這些在Magento價格

回答

0

您可以使用以下代碼片段

public function convertNumber($num) 
{ 


    list($num, $dec) = explode(".", $num); 

    $output = ""; 

    if($num{0} == "-") 
    { 
     $output = "negative "; 
     $num = ltrim($num, "-"); 
    } 
    else if($num{0} == "+") 
    { 
     $output = "positive "; 
     $num = ltrim($num, "+"); 
    } 


    if($num{0} == "0") 
    { 
     $output .= "Zero"; 
    } 
    else 
    { 
     $num = str_pad($num, 36, "0", STR_PAD_LEFT); 
     $group = rtrim(chunk_split($num, 3, " "), " "); 
     $groups = explode(" ", $group); 

     $groups2 = array(); 
     foreach($groups as $g) { 
     $groups2[] = $this->convertThreeDigit($g{0}, $g{1}, $g{2}); 
     } 

     for($z = 0; $z < count($groups2); $z++) 
     { 
     if($groups2[$z] != "") 
     { 
      $output .= $groups2[$z].$this->convertGroup(11 - $z).($z < 11 && !array_search('', array_slice($groups2, $z + 1, -1)) 
      && $groups2[11] != '' && $groups[11]{0} == '0' ? " and " : ", "); 
     } 
     } 

     $output = rtrim($output, ", "); 
    } 

    if($dec > 0) 
    { 
     $output .= " point"; 
     for($i = 0; $i < strlen($dec); $i++) $output .= " ".$this->convertDigit($dec{$i}); 
    } 

    return $output; 
} 

public function convertGroup($index) 
{ 
    switch($index) 
    { 
     case 11: return " Decillion"; 
     case 10: return " Nonillion"; 
     case 9: return " Octillion"; 
     case 8: return " Septillion"; 
     case 7: return " Sextillion"; 
     case 6: return " Quintrillion"; 
     case 5: return " Quadrillion"; 
     case 4: return " Trillion"; 
     case 3: return " Billion"; 
     case 2: return " Million"; 
     case 1: return " Thousand"; 
     case 0: return ""; 
    } 
} 

public function convertThreeDigit($dig1, $dig2, $dig3) 
{ 

    $output = ""; 

    if($dig1 == "0" && $dig2 == "0" && $dig3 == "0") return ""; 

    if($dig1 != "0") 
    { 
     $output .= $this->convertDigit($dig1)." Hundred"; 
     if($dig2 != "0" || $dig3 != "0") $output .= " and "; 
    } 

    if($dig2 != "0") $output .= $this->convertTwoDigit($dig2, $dig3); 
    else if($dig3 != "0") $output .= $this->convertDigit($dig3); 

    return $output; 
} 

public function convertTwoDigit($dig1, $dig2) 
{ 
    if($dig2 == "0") 
    { 
     switch($dig1) 
     { 
     case "1": return "Ten"; 
     case "2": return "Twenty"; 
     case "3": return "Thirty"; 
     case "4": return "Forty"; 
     case "5": return "Fifty"; 
     case "6": return "Sixty"; 
     case "7": return "Seventy"; 
     case "8": return "Eighty"; 
     case "9": return "Ninety"; 
     } 
    } 
    else if($dig1 == "1") 
    { 


     switch($dig2) 
     { 
     case "1": return "Eleven"; 
     case "2": return "Twelve"; 
     case "3": return "Thirteen"; 
     case "4": return "Fourteen"; 
     case "5": return "Fifteen"; 
     case "6": return "Sixteen"; 
     case "7": return "Seventeen"; 
     case "8": return "Eighteen"; 
     case "9": return "Nineteen"; 
     } 
    } 
    else 
    { 
     $temp = $this->convertDigit($dig2); 
     switch($dig1) 
     { 
     case "2": return "Twenty-$temp"; 
     case "3": return "Thirty-$temp"; 
     case "4": return "Forty-$temp"; 
     case "5": return "Fifty-$temp"; 
     case "6": return "Sixty-$temp"; 
     case "7": return "Seventy-$temp"; 
     case "8": return "Eighty-$temp"; 
     case "9": return "Ninety-$temp"; 
     } 
    } 
} 

public function convertDigit($digit) 
{ 
    switch($digit) 
    { 
     case "0": return "Zero"; 
     case "1": return "One"; 
     case "2": return "Two"; 
     case "3": return "Three"; 
     case "4": return "Four"; 
     case "5": return "Five"; 
     case "6": return "Six"; 
     case "7": return "Seven"; 
     case "8": return "Eight"; 
     case "9": return "Nine"; 
    } 
} 

你可以這樣稱呼低

$this->convertNumber(round($_price)); 
+0

謝謝。但我不知道我應該把這些代碼放在哪裏?我應該創建哪些文件? 即時通訊新的magento我會很感激,如果你爲我解釋它 – Moh3n 2015-02-07 16:22:35

+0

你可以把這段代碼放在任何幫助文件中,然後你可以在任何你想要的地方打電話給那個幫手 – 2015-02-07 18:38:18