我目前正在 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();
?>