我尝试使用此链接以编程方式创建订单:http://pastebin.com/8cft4d8v#。问题是:保存我的报价后,如何重定向到checkout / onepage / saveorder?我尝试重定向,但它显示“访问该网页被拒绝”;
这是我的代码:
$productid = Mage::app()->getRequest()->getParam('value');
$payment = Mage::app()->getRequest()->getParam('payment');
$session = Mage::getSingleton('customer/session');
if(!$session->isLoggedIn())
{
//login
$username = Mage::app()->getRequest()->getParam('username');
$password = Mage::app()->getRequest()->getParam('password');
try
{
$result = $session->login($username,$password);
}
catch(Mage_Core_Exception $e)
{
$response['status'] = 0;
$response['message'] = $e->getMessage();
echo Zend_Json::encode($response);
return false;
}
$session->setCustomerAsLoggedIn($session->getCustomer());
}
$cust_id = $session->getId();
$customer = Mage::getModel('customer/customer')->load($cust_id);
$quote = Mage::getModel('sales/quote')
->setStoreId(Mage::app()->getStore('default')->getId());
$quote->assignCustomer($customer);
// add product(s)
$product = Mage::getModel('catalog/product')->load($productid);
$buyInfo = array(
'qty' => 1,
);
$quote->addProduct($product, new Varien_Object($buyInfo));
$billing = $customer->getDefaultBillingAddress();
$addressData = array(
'firstname' => $billing->getFirstname(),
'lastname' => $billing->getLastname(),
'street' => $billing->getStreet(),
'city' => $billing->getCity(),
'postcode' => $billing->getPostcode(),
'telephone' => $billing->getTelephone(),
'country_id' => $billing->getCountryId(),
'region_id' => $billing->getRegionId());
$billingAddress = $quote->getBillingAddress()->addData($addressData);
$quote->getPayment()->importData(array('method' => $payment));
$quote->collectTotals()->save();
$response['status'] = 1;
echo Zend_Json::encode($response);
答案 0 :(得分:0)
以编程方式创建订单后,您可以重定向到订单成功页面。为什么要去订购保存页面。保存报价后即可保存订单。使用$ this-> _redirect进行重定向