magento|paypal快速结账和结账页开发疑难

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即可。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值