【发布时间】: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();
?>
【问题讨论】: