0
我嘗試實現一鍵結帳Magento 1.x,但如果我使用我的結帳,他們有買後的問題,沒有選擇運輸方式。Magento一次點擊結帳
這是我的Checkout控制器的代碼。
<?php
class MCP_Debitapi_CheckoutController extends Mage_Core_Controller_Front_Action
{
public function oneClickAction()
{
/**
* @var Mage_Catalog_Model_Product $product
*/
$options = [];
$product = Mage::getModel('catalog/product')->load((int)$_POST['product']);
/**
* create a cart to work with
* @var Mage_Checkout_Model_Cart $cart
*/
$cart = Mage::getModel('checkout/cart');
$cart->addProduct($product,$options);
$cart->save();
/**
* @var Mage_Checkout_Model_Type_Onepage $checkout
*/
$checkout = Mage::getSingleton('checkout/type_onepage');
$checkout->getQuote()->clearInstance();
$checkout->initCheckout();
/**
* @var Mage_Customer_Helper_Data $customerHelper
*/
$customerHelper = Mage::helper('customer');
$billingAddress = $customerHelper->getCustomer()->getDefaultBillingAddress();
$shippingAddress = $customerHelper->getCustomer()->getDefaultShippingAddress();
if(!$billingAddress) {
Mage::throwException('cannot create one-click order without default billing address');
return false;
}
$checkout->getQuote()->getBillingAddress()->importCustomerAddress($billingAddress)->setSaveInAddressBook(false);
$checkout->getQuote()->getShippingAddress()->importCustomerAddress($shippingAddress)->setSaveInAddressBook(false);
$checkout->getQuote()->getShippingAddress()->setShippingDescription('Fixed')->save();
$checkout->getQuote()->getShippingAddress()->setCollectShippingRates(true);
$checkout->saveShippingMethod('flatrate_flatrate');
$checkout->savePayment(array('method'=>'mcpdebitapi'));
$checkout->getQuote()->collectTotals();
$checkout->saveOrder();
$cart->truncate();
$cart->save();
$cart->getItems()->clear()->save();
$checkout->getQuote()->setIsActive(false)->save();
$this->_redirect('checkout/onepage/success',array('_secure'=>true));
}
}
如何找出並設置正確的運輸方式?
嗨,我tryed它,但得到了同樣的結果。爲了更好的理解,我添加了Exception: –