将 php 函数应用于 Magento 价格
apply a php function into Magento price
我想将 Magento 价格视图更改为我的语言。我是说我想换号码。
我有这个 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 价格中应用这些
您可以使用以下代码段
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));
我想将 Magento 价格视图更改为我的语言。我是说我想换号码。
我有这个 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 价格中应用这些
您可以使用以下代码段
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));