【发布时间】:2015-03-18 14:21:06
【问题描述】:
简介: 如果您的基础货币不是此处列出的 @987654321 @
我安装了 3 种货币的 Magento。
我使用 PayPal 标准付款作为付款选项,但问题是向用户收取相同金额但以美元计费。例如,如果我有 100 RON 并选择通过贝宝付款,我将被收取 100 美元的费用。
我检查了使重定向可用的贝宝模块
app/code/core/Mage/Paypal/Block/Standard/Redirect.php
并且正确设置与货币和金额相关的变量并发送到贝宝。
我不知道如何解决这个问题,这非常令人沮丧,因为我猜 Magento 中的标准 PayPal 模块是由 PayPal 设计的(需要确认),并且已针对这种情况进行了验证。
信息 #1: PayPal 不接受某些货币(例如罗马尼亚雷伊,恰好是这家商店的基础货币)进行交易(允许的货币在这里列出 https://www.paypal.com/us/webapps/helpcenter/helphub/article/?solutionId=FAQ2390)所以当您单击提交时,他们只会转换货币符号(转换为 $)而不是金额。您必须自己更改的金额,但是 Magento (v 1.5) 中的默认 PayPal 模块没有这样做,这就是我打开这个问题的原因。
编辑#1
我尝试了下面提出的解决方案,但它不起作用,因为它实际上替换了一些变量,但不是以所需的方式。
我在这里看到两个选项:
选项#1:“查找和替换”选项是我在最终形式中找到所有浮点值并将它们替换为转换为美元的值的位置。但是,这不是一个可行的选择,因为没有正确转换值并且可能会发生错误。
选项 #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;
}
这两行:
$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);
问题是值没有被转换。
【问题讨论】:
-
您的问题解决了吗?你能帮我@@magento.stackexchange.com/q/186198/51361
标签: php api magento paypal currency