magento默认的付款机制是不管前台切换什么货币付款,跳转到paypal付款界面时,都会是以基货币来付款的 需要修改几个文件 app\code\core\Mage\Paypal\Model\Standard.php
public function getStandardCheckoutFormFields()
{
$orderIncrementId = $this->getCheckout()->getLastRealOrderId();
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
$api = Mage::getModel('paypal/api_standard')->setConfigObject($this->getConfig());
$api->setOrderId($orderIncrementId)
->setCurrencyCode($order->getOrderCurrencyCode())//---修改 当前订单的货币
//->setPaymentAction()
->setOrder($order)
->setNotifyUrl(Mage::getUrl('paypal/ipn/'))//---ipn验证
...
}
app\code\core\Mage\Paypal\Model\Cart.php
protected function _render()
{
...
if ($this->_salesEntity instanceof Mage_Sales_Model_Order) {
$shippingDescription = $this->_salesEntity->getShippingDescription();
$this->_totals = array(
self::TOTAL_SUBTOTAL => $this->_salesEntity->getSubtotal(),//---修改
self::TOTAL_TAX => $this->_salesEntity->getTaxAmount(),//---修改
self::TOTAL_SHIPPING => $this->_salesEntity->getShippingAmount(),//---修改
self::TOTAL_DISCOUNT => abs($this->_salesEntity->getDiscountAmount()),//---修改
);
...
}
protected function _addRegularItem(Varien_Object $salesItem)
{
if ($this->_salesEntity instanceof Mage_Sales_Model_Order) {
$qty = (int) $salesItem->getQtyOrdered();
$amount = (float) $salesItem->getPrice();// 修改
// TODO: nominal item for order
} else {
$qty = (int) $salesItem->getTotalQty();
$amount = $salesItem->isNominal() ? 0 : (float) $salesItem->getBaseCalculationPrice();
}
// workaround in case if item subtotal precision is not compatible with PayPal (.2)
$subAggregatedLabel = '';
if ($amount - round($amount, 2)) {
$amount = $amount * $qty;
$subAggregatedLabel = ' x' . $qty;
$qty = 1;
}
// aggregate item price if item qty * price does not match row total
if (($amount * $qty) != $salesItem->getRowTotal()) {// 修改
$amount = (float) $salesItem->getRowTotal();// 修改
$subAggregatedLabel = ' x' . $qty;
$qty = 1;
}
return $this->addItem($salesItem->getName() . $subAggregatedLabel, $qty, $amount, $salesItem->getSku());
}
这样改过后,跳转到paypal付款界面已经实现了是当前的货币,也可以正常付款,但是付款成功后,上面那个ipn验证不能通过,到后台去看订单状态,发现是Suspected Fraud,是不能进行后续的操作的,如果解决这个问题,看下面 app\core\Mage\Sales\Model\Order\Payment.php
protected function _isCaptureFinal($amountToCapture)
{
$amountToCapture = $this->_formatAmount($amountToCapture, true);
$orderGrandTotal = $this->_formatAmount($this->getOrder()->getGrandTotal(), true);//---修改
if ($orderGrandTotal == $this->_formatAmount($this->getAmountPaid(), true) + $amountToCapture) {//---修改
if (false !== $this->getShouldCloseParentTransaction()) {
$this->setShouldCloseParentTransaction(true);
}
return true;
}
return false;
}
protected function _isSameCurrency()
{
return !$this->getCurrencyCode() || $this->getCurrencyCode() == $this->getOrder()->getOrderCurrencyCode();// 修改
}
现在就可以正常付款了