magento集成的有PayPal支付,我们一般采用的是PayPal快速结账支付方法,不仅可以在产品详情页实现快速结账,同时可以在结账页使用此种方式。不过这里遇到几个问题,具体罗列和分析如下:
1、详情页快速结账后,因为未传递运费,所以在PayPal支付完成后会跳转回到订单确认页让选择运输方式,然后才能生成订单号下单成功。解决方案是在快速结账的按钮上传递自定义参数,然后在PayPal里面接受参数,根据参数传递默认的运输方式即可。
2、详情页快速结账和信用卡支付,分别跳转的页面不同,信用卡支付直接跳转到输入卡号页面即可。快速结账跳转到输入账号界面,具体效果如下图;
结账页选择快速结账和信用卡支付,分别跳转的页面不同,问题如上,具体效果如上图;
具体需要更改的代码如下:
一、app\design\frontend\base\default\template\paypal\express\shortcut.phtml,magento产品详情页最终生成的地址为:信用卡http://test.longzhixiang.com/paypal/express/start/button/1/instruction/1/free/1,快速结账:http://test.longzhixiang.com/paypal/express/start/button/1/instruction/0/free/0。
二、结账页添加instruction参数,来判断是信用卡还是快速结账:app\design\frontend\yisainuo\pc\template\tm\firecheckout\checkout\payment\methods.phtml,更改两种方式的value值均为paypal_express,代码如下:
<script type="text/javascript">
jQuery(document).ready(function(){if(jQuery('#p_method_paypal_express').attr('checked') == 'checked'){
jQuery('.gw-instruction').val(0);
}else if(jQuery('#p_method_paypal_express').attr('checked') == 'checked'){
jQuery('.gw-instruction').val(1);
}jQuery('.gw-instruction').removeAttr("disabled");
jQuery('#p_method_paypal_express_bml').click(function(){
jQuery('.gw-instruction').val(1);
});
jQuery('#p_method_paypal_express').click(function(){jQuery('.gw-instruction').val(0);
});
});
</script>
效果如图:
三、后台接受参数,结账页控制器接受,因为这里用的是TM_FIRECHECKOUT插件,所以,需要更改,app\code\local\TM\FireCheckout\controllers\IndexController.php中的saveOrderAction方法,增加保存参数到session,
$paypalInstruction = $this->getRequest()->getPost('instruction');
Mage::getSingleton('core/session')->setPaypalInstruction($paypalInstruction);
四、接收详情页快速结账的方法:app\code\core\Mage\Paypal\Controller\Express\Abstract.php的startAction方法接受参数
$paypalInstruction = $this->getRequest()->getParam('instruction');
$paypalIsFree = $this->getRequest()->getParam('free');
//Mage::log($paypalInstruction,NULL,'2.log');
if(isset($paypalInstruction)){
//Mage::log($paypalInstruction,NULL,'1.log');
Mage::getSingleton('core/session')->setPaypalInstruction($paypalInstruction);
}
五、NVP里面读取参数并传递对应的PayPal值,从而进入不同的页面:app\code\core\Mage\Paypal\Model\Api\Nvp.php的933行call()方法:
$checkPaymentMethod=Mage::getSingleton('core/session')->getPaypalInstruction();
//Mage::log($checkPaymentMethod,NULL,'2.log');
$request = $this->_addMethodToRequest($methodName, $request);
if($checkPaymentMethod==1){
$request['LANDINGPAGE']='Billing';
//Mage::log($request,NULL,'amy1.log');
}else{
$request['LANDINGPAGE']='Login';
//Mage::log($request,NULL,'amy2.log');
}
六、app\code\core\Mage\Paypal\Controller\Express\Abstract.php的startAction方法接受参数传递默认运输方式:
第96行增加:
//gw 默认运输方式
if(isset($paypalIsFree) && $paypalIsFree == 1 ){
//freeshipping_freeshipping
$this->_checkout->updateShippingMethod('freeshipping_freeshipping');
}
第197行returnAction更改
//$this->_redirect('*/*/review');
$this->_forward('placeOrder');
七、PayPal不进行地址校验app\code\core\Mage\Paypal\Model\Api\Nvp.php中第602行,$request['ADDROVERRIDE'] = 1;更改为0即可。