【问题标题】:Magento: Redirect customer to third-party payment siteMagento:将客户重定向到第三方支付网站
【发布时间】:2012-04-21 17:37:59
【问题描述】:

我目前正在 Magento 中创建我的第一个自定义结帐页面。我有一个有效的代码 - 它会创建一个未付款的订单,因此下一步是根据所选的付款方式将客户重定向到第三方付款网站。

经过一些研究,似乎有一个名为 redirectUrl 的参数,我应该能够以某种方式获得它,但我真的不知道如何。

如果我错了,请指点我回到正轨!提前谢谢你。

<?php
    require_once 'app/Mage.php';

    Mage::app();

    $quote = Mage::getModel('sales/quote')->setStoreId(Mage::app()->getStore('default')->getId());

    // guest order
    $quote->setCustomerEmail('customer@example.com');

    // add sample product
    $product = Mage::getModel('catalog/product')->load(8);
    $buyInfo = array(
            'qty' => 1,
    );
    $quote->addProduct($product, new Varien_Object($buyInfo));

    $addressData = array(
            'firstname' => 'Test',
            'lastname' => 'Test',
            'street' => 'Sample Street 10',
            'city' => 'Somewhere',
            'postcode' => '123456',
            'telephone' => '123456',
            'country_id' => 'SE'
    );

    $billingAddress = $quote->getBillingAddress()->addData($addressData);
    $shippingAddress = $quote->getShippingAddress()->addData($addressData);

    $shippingAddress->setCollectShippingRates(true)->collectShippingRates()->setShippingMethod('flatrate_flatrate')->setPaymentMethod('checkmo');

    $quote->getPayment()->importData(array('method' => 'checkmo'));

    $quote->collectTotals()->save();

    $service = Mage::getModel('sales/service_quote', $quote);
    $service->submitAll();
    $order = $service->getOrder();

    echo 'Created order #' . $order->getIncrementId();
?>

【问题讨论】:

    标签: php magento checkout


    【解决方案1】:

    在示例代码中,您将 Magento 类用于独立的 PHP 文件。这样,Magento 重定向将不起作用,因为它是来自Mage_Core_Controller_Front_Action 的方法。您必须使用 Magento 控制器来尝试这种重定向方式。

    无论如何,你可以使用PHP的header函数:header("Location: http://somepayment.com/complexUrl"); die;

    【讨论】:

    • 但是如何获取付款方式的 URL?
    • 您是指从管理中的付款方式配置部分获取 URL 吗?
    • 不,来自所选支付方式的 URL(示例中的“checkmo”)。
    猜你喜欢
    • 2011-08-09
    • 2013-01-21
    • 2013-05-24
    • 2013-12-30
    • 2011-06-29
    • 1970-01-01
    • 2020-10-27
    • 1970-01-01
    相关资源
    最近更新 更多