Synopsis: 如果您的基础货币不是此处列出的货币,Magento的PayPal支付模块将不会将货币转换为美元或任何PayPal接受的货币https://www.paypal.com/us/webapps/helpcenter/helphub/article/?solutionId=FAQ2390
我安装了3种货币的Magento安装 .
我使用PayPal标准付款作为付款选项,但问题是用户收取的金额相同,但是以美元计算 . 例如,如果我有100 RON并选择通过paypal付款,我将收取100美元的费用 .
我查看了使用重定向的paypal模块
app / code / core / Mage / Paypal / Block / Standard / Redirect.php
并且与货币和金额相关的变量被正确设置并发送到paypal .
我不确切知道如何解决这个问题而且非常令人沮丧,因为我猜Magento中的标准PayPal模块是由PayPal设计的(需要确认)并且在这种情况下得到验证 .
Info #1: PayPal不接受某些货币(例如罗马尼亚雷,例如恰好是这家商店的基础货币)进行交易(允许的货币列于此处https://www.paypal.com/us/webapps/helpcenter/helphub/article/?solutionId=FAQ2390)所以当您点击提交时,他们只会转换货币符号(至$)而不是金额 . 您必须自行更改的金额,但是Magento(v 1.5)中的默认PayPal模块没有这样做,这就是我打开这个问题的原因 .
EDIT #1
我尝试了下面提出的解决方案,但它没有工作,因为事实上它取代了一些变量,但没有以所需的方式 .
我在这里看到两个选项:
Option #1: 'find and replace'选项是我在最终表单中找到所有浮点值并将其替换为转换为USD的值 . 但是,这不是一个可行的选项,因为没有正确转换值并且可能发生错误 .
Option #2:
我找到了弹出表单中的值的函数,它位于spp / code / core / Mage / Paypal / Model / Api / Abstract.php
protected function _exportLineItems(array &$request, $i = 0)
{
if (!$this->_cart) {
return;
}
// always add cart totals, even if line items are not requested
if ($this->_lineItemTotalExportMap) {
foreach ($this->_cart->getTotals() as $key => $total) {
if (isset($this->_lineItemTotalExportMap[$key])) { // !empty($total)
$privateKey = $this->_lineItemTotalExportMap[$key];
$request[$privateKey] = $this->_filterAmount($total);
}
}
}
// add cart line items
$items = $this->_cart->getItems();
if (empty($items) || !$this->getIsLineItemsEnabled()) {
return;
}
$result = null;
foreach ($items as $item) {
foreach ($this->_lineItemExportItemsFormat as $publicKey => $privateFormat) {
$result = true;
$value = $item->getDataUsingMethod($publicKey);
if (isset($this->_lineItemExportItemsFilters[$publicKey])) {
$callback = $this->_lineItemExportItemsFilters[$publicKey];
$value = call_user_func(array($this, $callback), $value);
}
if (is_float($value)) {
$value = $this->_filterAmount($value);
}
$request[sprintf($privateFormat, $i)] = $value;
}
$i++;
}
return $result;
}
这2行:
$request[$privateKey] = $this->_filterAmount($total);
$value = $this->_filterAmount($value);
打印出变量列表中的金额,而不是函数_filterAmount我编写了以下函数,该函数应根据后端定义的汇率将金额从任何基础货币转换为美元:
protected function _convertAmounttoUSD($value)
{
$baseCode = Mage::app()->getBaseCurrencyCode();
$fromCur = Mage::app()->getStore()->getCurrentCurrencyCode();
$toCur = 'USD';
$allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();
$rates = Mage::getModel('directory/currency')->getCurrencyRates($baseCode, array_values($allowedCurrencies));
$output = ( $value * $rates[$toCur] ) / $rates[$fromCur];
return sprintf('%.2F', $output);
}
我用以下内容替换了上面的行:
$request[$privateKey] = $this->_convertAmounttoUSD($total);
$value = $this->_convertAmounttoUSD($value);
问题是值不会被转换 .
1 回答
在magento当用户被重定向到paypal它magento发送商店货币收费但paypal使用与paypal帐户相关联的货币所以我们需要将其转换为paypal帐户货币 .
它将收取100RON,但将其转换为美元货币 .
你需要使用以下函数更改下面的文件:app \ code \ core \ Mage \ Paypal \ Model \ Standard.php用以下函数替换getStandardCheckoutFormFields函数: