尽管Magento1.5已经出来了。。但现在大部分站还是继续1.4.0.1的。
Magento官方也公布了这个版本的多个BUG,其中一个是Magento1.4.0.1使用Paypal支付接口 的时候,如果客户先注册再放入购物车结算, 一切正常。 如果游客身份先放入购物车,然后再注册,去结算,就会在支付的时候 少算运费,后台的一切数值都正常,都是带运费的。但是就是Paypal收到的是不带运费的。
对着BUG修复文档处理了一下,问题可以解决。记录一下。。
app/code/core/Mage/Paypal/Helper/Data.php
$shippingDescription = '';
- if ($salesEntity instanceof Mage_Sales_Model_Order) {
- $discountAmount = abs(1 * $salesEntity->getBaseDiscountAmount());
- $shippingDescription = $salesEntity->getShippingDescription();
- $totals = array(
- 'subtotal' => $salesEntity->getBaseSubtotal() - $discountAmount,
- 'tax' => $salesEntity->getBaseTaxAmount(),
- 'shipping' => $salesEntity->getBaseShippingAmount(),
+ $discountAmount = abs(1 * $salesEntity->getBaseDiscountAmount());
+ $shippingDescription = $salesEntity->getShippingDescription();
+ $totals = array(
+ 'subtotal' => $salesEntity->getBaseSubtotal() - $discountAmount,
+ 'tax' => $salesEntity->getBaseTaxAmount(),
+ 'shipping' => $salesEntity->getBaseShippingAmount(),
+ 'discount' => $discountAmount,
// 'shipping_discount' => -1 * abs($salesEntity->getBaseShippingDiscountAmount()),
- );
- } else {
- $address = $salesEntity->getIsVirtual() ? $salesEntity->getBillingAddress() : $salesEntity->getShippingAddress();
- $discountAmount = abs(1 * $address->getBaseDiscountAmount());
- $shippingDescription = $address->getShippingDescription();
- $totals = array (
- 'subtotal' => $salesEntity->getBaseSubtotal() - $discountAmount,
- 'tax' => $address->getBaseTaxAmount(),
- 'shipping' => $address->getBaseShippingAmount(),
- 'discount' => $discountAmount,
-// 'shipping_discount' => -1 * abs($address->getBaseShippingDiscountAmount()),
- );
- }
+ );
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());
- $quote = $this->getQuote();
- $api->setOrderId($this->getCheckout()->getLastRealOrderId()) // TODO reserved order id
- ->setCurrencyCode($quote->getBaseCurrencyCode())
+ $api->setOrderId($orderIncrementId)
+ ->setCurrencyCode($order->getBaseCurrencyCode())
//->setPaymentAction()
->setNotifyUrl(Mage::getUrl('paypal/ipn/standard'))
->setReturnUrl(Mage::getUrl('paypal/standard/success'))
- ->setCancelUrl(Mage::getUrl('paypal/standard/cancel'))
- ;
+ ->setCancelUrl(Mage::getUrl('paypal/standard/cancel'));
// export address
- $isQuoteVirtual = $quote->getIsVirtual();
- $address = $isQuoteVirtual ? $quote->getBillingAddress() : $quote->getShippingAddress();
- if ($isQuoteVirtual) {
+ $isOrderVirtual = $order->getIsVirtual();
+ $address = $isOrderVirtual ? $order->getBillingAddress() : $order->getShippingAddress();
+ if ($isOrderVirtual) {
$api->setNoShipping(true);
- } elseif ($address->getEmail()) {
+ }
+ elseif ($address->getEmail()) {
$api->setAddress($address);
}
- list($items, $totals, $discountAmount, $shippingAmount) = Mage::helper('paypal')->prepareLineItems($quote, false, true);
+ list($items, $totals, $discountAmount, $shippingAmount) = Mage::helper('paypal')->prepareLineItems($order, false, true);
// prepare line items if required in config
if ($this->_config->lineItemsEnabled) {
$api->setLineItems($items)->setLineItemTotals($totals)->setDiscountAmount($discountAmount);
}
// or values specific for aggregated order
else {
- $grandTotal = $quote->getBaseGrandTotal();
- if (!$isQuoteVirtual) {
+ $grandTotal = $order->getBaseGrandTotal();
+ if (!$isOrderVirtual) {
$api->setShippingAmount($shippingAmount);
$grandTotal -= $shippingAmount;
}
app/code/core/Mage/Paypal/Model/Api/Standard.php
protected $_exportToRequestFilters = array(
'amount' => '_filterAmount',
- 'shipping' => '_filterAmount',
+ 'shipping' => '_filterAmount'
);
'amount' => 'amount_%d',
);
+ protected $_lineItemExportItemsFilters = array(
+ 'qty' => '_filterQty'
+ );
+
app/code/core/Mage/Paypal/Model/Api/Abstract.php
protected $_lineItemExportTotals = array();
protected $_lineItemExportItemsFormat = array();
+ protected $_lineItemExportItemsFilters = array();
foreach ($items as $item) {
foreach ($this->_lineItemExportItemsFormat as $publicKey => $privateFormat) {
$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);
}
{
return http_build_query($request);
}
+
+ /**
+ * Filter qty in API calls
+ * Paypal note: The value for quantity must be a positive integer. Null, zero, or negative numbers are not allowed.
+ *
+ * @param float|string|int $value
+ * @return string
+ */
+ protected function _filterQty($value)
+ {
+ return intval($value);
+ }
乳此,Magento Paypal支付接口
作者: Sjolzy
--EOF--