我正在研究运输方法的自动化,它似乎工作正常,但问题是:
每个第二个订单都有相同的错误“请指定送货方式”
会不会是会话错误?变量应该通过 get-post 发送还是以其他方式从 Magento 检索?
这是一个代码:
<?php
$customer = Mage::getSingleton('customer/session')->getCustomer();
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
echo $customAddress = Mage::getModel('customer/address')->load($customer->getDefaultBilling());
$quote = Mage::getSingleton('checkout/session')->getQuote()->setBillingAddress(Mage::getSingleton('sales/quote_address')->importCustomerAddress($customAddress));
$cart = Mage::getSingleton('checkout/cart');
$storeId = Mage::app()->getStore()->getId();
$checkout = Mage::getSingleton('checkout/type_onepage');
$checkout->initCheckout();
$checkout->saveCheckoutMethod('register');
$checkout->saveShippingMethod('matrixrate_matrixrate_35');
$checkout->savePayment(array('method'=>'pay'));
Mage::getSingleton('checkout/type_onepage')->getQuote()->getShippingAddress()->setShippingMethod('matrixrate_matrixrate_35');
try {
if ($checkout->saveOrder()) {echo "SUCCESSSSS!!!";}}
catch (Exception $ex) {
echo $ex->getMessage();
}
/* Clear the cart */
$cart->truncate();
$cart->save();
$cart->getItems()->clear()->save();
Mage::getSingleton('checkout/session')->clear();
它使用名为 Pay 的自定义支付网关,我使用 matrixrate 扩展进行运输,尽管 flatrate_flatrate 存在相同的错误,所以我不认为这是扩展问题。
谢谢!!!
亚当