2012-11-19 73 views
3

我想自動自動填充送貨方式,而不是在onepage結帳時顯示它。我能夠改變這個上應用程序/代碼/隱藏在我Onepagechekout送貨方式本地/法師/結帳/控制器/ OnepageController.php如何自動填充送貨方式Magento for onepagechekout

/** 
* save checkout billing address 
*/ 
public function saveBillingAction() 
{ 
    if ($this->_expireAjax()) { 
     return; 
    } 
    if ($this->getRequest()->isPost()) { 
//   $postData = $this->getRequest()->getPost('billing', array()); 
//   $data = $this->_filterPostData($postData); 
     $data = $this->getRequest()->getPost('billing', array()); 
     $customerAddressId = $this->getRequest()->getPost('billing_address_id', false); 

     if (isset($data['email'])) { 
      $data['email'] = trim($data['email']); 
     } 
     $result = $this->getOnepage()->saveBilling($data, $customerAddressId); 

     if (!isset($result['error'])) { 
      /* check quote for virtual */ 
      if ($this->getOnepage()->getQuote()->isVirtual()) 
      { 
       $result['goto_section'] = 'payment'; 
       $result['update_section'] = array(
        'name' => 'payment-method', 
        'html' => $this->_getPaymentMethodsHtml() 
       ); 
      } elseif (isset($data['use_for_shipping']) && $data['use_for_shipping'] == 1) 
       { 
       $result['goto_section'] = 'payment'; 
       $result['update_section'] = array(
        'name' => 'payment-method', 
        'html' => $this->_getPaymentMethodsHtml() 
       ); 

       $result['allow_sections'] = array('shipping'); 
       $result['duplicateBillingInfo'] = 'true'; 
      } else { 
       $result['goto_section'] = 'shipping'; 
      } 
     } 
     $this->saveShippingMethodAction(); 
     $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); 
    } 
} 

正如你看到的,我改變了鏈接,我將結算操作後的下一步重定向到付款步驟。

爲了自動保存送貨方式,我加

$this->saveShippingMethodAction(); 

在函數的結束,這種方法看起來像在這裏:

public function saveShippingMethodAction() 
{ 
    $this->_expireAjax(); 
    if ($this->getRequest()->isPost()) { 
     /* $this->savePaymentAction(); */ 
     $data = $this->getRequest()->getPost('shipping_method', 'flatrate_flatrate'); 
     $result = $this->getOnepage()->saveShippingMethod($data); 
      $this->getResponse()->setBody(Zend_Json::encode($result)); 
    } 

} 

所以我也就是嘗試自動包含flatrate_flatrate方法作爲默認方法。

但是,當我嘗試完成銷售時,它說我沒有指定運輸方式。任何想法爲什麼它不工作?

回答

4

現在你需要強制SHIPPING_METHOD在報價和會話:

$forcedMethod = "your_method_code"; 

$this->getOnePage()->getQuote() 
    ->getShippingAddress() 
    ->setShippingMethod($forcedMethod) 
    ->save(); 

Mage::getSingleton('checkout/session')->setShippingMethod($forcedMethod); 

你打電話之前:

$this->saveShippingMethodAction(); 

添加:

$this->getRequest()->setPost('shipping_method', $forcedMethod); 

它應該工作;)

相關問題