Mage_Checkout_OnepageController Class Reference

Inheritance diagram for Mage_Checkout_OnepageController:

Mage_Checkout_Controller_Action Mage_Core_Controller_Front_Action Mage_Core_Controller_Varien_Action

List of all members.

Public Member Functions

 preDispatch ()
 getOnepage ()
 indexAction ()
 progressAction ()
 shippingMethodAction ()
 reviewAction ()
 successAction ()
 failureAction ()
 getAdditionalAction ()
 getAddressAction ()
 saveMethodAction ()
 saveBillingAction ()
 saveShippingAction ()
 saveShippingMethodAction ()
 savePaymentAction ()
 saveOrderAction ()

Protected Member Functions

 _ajaxRedirectResponse ()
 _expireAjax ()
 _getShippingMethodsHtml ()
 _getPaymentMethodsHtml ()
 _getAdditionalHtml ()


Detailed Description

Definition at line 28 of file OnepageController.php.


Member Function Documentation

_ajaxRedirectResponse (  )  [protected]

Definition at line 44 of file OnepageController.php.

00045     {
00046         $this->getResponse()
00047             ->setHeader('HTTP/1.1', '403 Session Expired')
00048             ->setHeader('Login-Required', 'true')
00049             ->sendResponse();
00050         return $this;
00051     }

_expireAjax (  )  [protected]

Definition at line 53 of file OnepageController.php.

00054     {
00055         if (!$this->getOnepage()->getQuote()->hasItems()
00056             || $this->getOnepage()->getQuote()->getHasError()
00057             || $this->getOnepage()->getQuote()->getIsMultiShipping()) {
00058             $this->_ajaxRedirectResponse();
00059             exit;
00060         }
00061         $action = $this->getRequest()->getActionName();
00062         if (Mage::getSingleton('checkout/session')->getCartWasUpdated(true)
00063             && !in_array($action, array('index', 'progress'))) {
00064             $this->_ajaxRedirectResponse();
00065             exit;
00066         }
00067         Mage::getSingleton('core/translate_inline')->setIsAjaxRequest(true);
00068     }

_getAdditionalHtml (  )  [protected]

Definition at line 92 of file OnepageController.php.

00093     {
00094         $layout = $this->getLayout();
00095         $update = $layout->getUpdate();
00096         $update->load('checkout_onepage_additional');
00097         $layout->generateXml();
00098         $layout->generateBlocks();
00099         $output = $layout->getOutput();
00100         return $output;
00101     }

_getPaymentMethodsHtml (  )  [protected]

Definition at line 81 of file OnepageController.php.

00082     {
00083         $layout = $this->getLayout();
00084         $update = $layout->getUpdate();
00085         $update->load('checkout_onepage_paymentmethod');
00086         $layout->generateXml();
00087         $layout->generateBlocks();
00088         $output = $layout->getOutput();
00089         return $output;
00090     }

_getShippingMethodsHtml (  )  [protected]

Definition at line 70 of file OnepageController.php.

00071     {
00072         $layout = $this->getLayout();
00073         $update = $layout->getUpdate();
00074         $update->load('checkout_onepage_shippingmethod');
00075         $layout->generateXml();
00076         $layout->generateBlocks();
00077         $output = $layout->getOutput();
00078         return $output;
00079     }

failureAction (  ) 

Definition at line 189 of file OnepageController.php.

00190     {
00191         $lastQuoteId = $this->getOnepage()->getCheckout()->getLastQuoteId();
00192         $lastOrderId = $this->getOnepage()->getCheckout()->getLastOrderId();
00193 
00194         if (!$lastQuoteId || !$lastOrderId) {
00195             $this->_redirect('checkout/cart');
00196             return;
00197         }
00198 
00199         $this->loadLayout();
00200         $this->renderLayout();
00201     }

getAdditionalAction (  ) 

Definition at line 204 of file OnepageController.php.

00205     {
00206         $this->getResponse()->setBody($this->_getAdditionalHtml());
00207     }

getAddressAction (  ) 

Address JSON

Definition at line 212 of file OnepageController.php.

00213     {
00214         $this->_expireAjax();
00215         $addressId = $this->getRequest()->getParam('address', false);
00216         if ($addressId) {
00217             $address = $this->getOnepage()->getAddress($addressId);
00218             $this->getResponse()->setHeader('Content-type', 'application/x-json');
00219             $this->getResponse()->setBody($address->toJson());
00220         }
00221     }

getOnepage (  ) 

Enter description here...

Returns:
Mage_Checkout_Model_Type_Onepage

Definition at line 108 of file OnepageController.php.

00109     {
00110         return Mage::getSingleton('checkout/type_onepage');
00111     }

indexAction (  ) 

Checkout page

Definition at line 116 of file OnepageController.php.

00117     {
00118         if (!Mage::helper('checkout')->canOnepageCheckout()) {
00119             Mage::getSingleton('checkout/session')->addError($this->__('Sorry, Onepage Checkout is disabled.'));
00120             $this->_redirect('checkout/cart');
00121             return;
00122         }
00123         $quote = $this->getOnepage()->getQuote();
00124         if (!$quote->hasItems() || $quote->getHasError()) {
00125             $this->_redirect('checkout/cart');
00126             return;
00127         }
00128         if (!$quote->validateMinimumAmount()) {
00129             $error = Mage::getStoreConfig('sales/minimum_order/error_message');
00130             Mage::getSingleton('checkout/session')->addError($error);
00131             $this->_redirect('checkout/cart');
00132             return;
00133         }
00134         Mage::getSingleton('checkout/session')->setCartWasUpdated(false);
00135         Mage::getSingleton('customer/session')->setBeforeAuthUrl($this->getRequest()->getRequestUri());
00136         $this->getOnepage()->initCheckout();
00137         $this->loadLayout();
00138         $this->_initLayoutMessages('customer/session');
00139         $this->getLayout()->getBlock('head')->setTitle($this->__('Checkout'));
00140         $this->renderLayout();
00141     }

preDispatch (  ) 

Returns:
Mage_Checkout_OnepageController

Reimplemented from Mage_Core_Controller_Front_Action.

Definition at line 33 of file OnepageController.php.

00034     {
00035         parent::preDispatch();
00036 
00037         if (!$this->_preDispatchValidateCustomer()) {
00038             return $this;
00039         }
00040 
00041         return $this;
00042     }

progressAction (  ) 

Checkout status block

Definition at line 146 of file OnepageController.php.

00147     {
00148         $this->_expireAjax();
00149         $this->loadLayout(false);
00150         $this->renderLayout();
00151     }

reviewAction (  ) 

Definition at line 160 of file OnepageController.php.

00161     {
00162         $this->_expireAjax();
00163         $this->loadLayout(false);
00164         $this->renderLayout();
00165     }

saveBillingAction (  ) 

save checkout billing address

Definition at line 236 of file OnepageController.php.

00237     {
00238         $this->_expireAjax();
00239         if ($this->getRequest()->isPost()) {
00240             $data = $this->getRequest()->getPost('billing', array());
00241             $customerAddressId = $this->getRequest()->getPost('billing_address_id', false);
00242             $result = $this->getOnepage()->saveBilling($data, $customerAddressId);
00243 
00244             if (!isset($result['error'])) {
00245                 /* check quote for virtual */
00246                 if ($this->getOnepage()->getQuote()->isVirtual()) {
00247                     $result['goto_section'] = 'payment';
00248                     $result['update_section'] = array(
00249                         'name' => 'payment-method',
00250                         'html' => $this->_getPaymentMethodsHtml()
00251                     );
00252                 }
00253                 elseif (isset($data['use_for_shipping']) && $data['use_for_shipping'] == 1) {
00254 
00255                    $result['goto_section'] = 'shipping_method';
00256 
00257                     $result['update_section'] = array(
00258                         'name' => 'shipping-method',
00259                         'html' => $this->_getShippingMethodsHtml()
00260                     );
00261 
00262                     $result['allow_sections'] = array('shipping');
00263                     $result['duplicateBillingInfo'] = 'true';
00264                 }
00265                 else {
00266                     $result['goto_section'] = 'shipping';
00267                 }
00268             }
00269 
00270             $this->getResponse()->setBody(Zend_Json::encode($result));
00271         }
00272     }

saveMethodAction (  ) 

Definition at line 223 of file OnepageController.php.

00224     {
00225         $this->_expireAjax();
00226         if ($this->getRequest()->isPost()) {
00227             $method = $this->getRequest()->getPost('method');
00228             $result = $this->getOnepage()->saveCheckoutMethod($method);
00229             $this->getResponse()->setBody(Zend_Json::encode($result));
00230         }
00231     }

saveOrderAction (  ) 

when there is redirect to third party, we don't want to save order yet. we will save the order in return action.

Definition at line 366 of file OnepageController.php.

00367     {
00368         $this->_expireAjax();
00369 
00370         $result = array();
00371         try {
00372             if ($requiredAgreements = Mage::helper('checkout')->getRequiredAgreementIds()) {
00373                 $postedAgreements = array_keys($this->getRequest()->getPost('agreement', array()));
00374                 if ($diff = array_diff($requiredAgreements, $postedAgreements)) {
00375                     $result['success'] = false;
00376                     $result['error'] = true;
00377                     $result['error_messages'] = $this->__('Please agree to all Terms and Conditions before placing the order.');
00378                     $this->getResponse()->setBody(Zend_Json::encode($result));
00379                     return;
00380                 }
00381             }
00382             if ($data = $this->getRequest()->getPost('payment', false)) {
00383                 $this->getOnepage()->getQuote()->getPayment()->importData($data);
00384             }
00385             $this->getOnepage()->saveOrder();
00386             $redirectUrl = $this->getOnepage()->getCheckout()->getRedirectUrl();
00387             $result['success'] = true;
00388             $result['error']   = false;
00389         }
00390         catch (Mage_Core_Exception $e) {
00391             Mage::logException($e);
00392             Mage::helper('checkout')->sendPaymentFailedEmail($this->getOnepage()->getQuote(), $e->getMessage());
00393             $result['success'] = false;
00394             $result['error'] = true;
00395             $result['error_messages'] = $e->getMessage();
00396             $this->getOnepage()->getQuote()->save();
00397         }
00398         catch (Exception $e) {
00399             Mage::logException($e);
00400             Mage::helper('checkout')->sendPaymentFailedEmail($this->getOnepage()->getQuote(), $e->getMessage());
00401             $result['success']  = false;
00402             $result['error']    = true;
00403             $result['error_messages'] = $this->__('There was an error processing your order. Please contact us or try again later.');
00404             $this->getOnepage()->getQuote()->save();
00405         }
00406 
00407         /**
00408          * when there is redirect to third party, we don't want to save order yet.
00409          * we will save the order in return action.
00410          */
00411         if (isset($redirectUrl)) {
00412             $result['redirect'] = $redirectUrl;
00413         }
00414 
00415         $this->getResponse()->setBody(Zend_Json::encode($result));
00416     }

savePaymentAction (  ) 

Definition at line 324 of file OnepageController.php.

00325     {
00326         $this->_expireAjax();
00327         if ($this->getRequest()->isPost()) {
00328             $data = $this->getRequest()->getPost('payment', array());
00329             /*
00330             * first to check payment information entered is correct or not
00331             */
00332 
00333             try {
00334                 $result = $this->getOnepage()->savePayment($data);
00335             }
00336             catch (Mage_Payment_Exception $e) {
00337                 if ($e->getFields()) {
00338                     $result['fields'] = $e->getFields();
00339                 }
00340                 $result['error'] = $e->getMessage();
00341             }
00342             catch (Exception $e) {
00343                 $result['error'] = $e->getMessage();
00344             }
00345             $redirectUrl = $this->getOnePage()->getQuote()->getPayment()->getCheckoutRedirectUrl();
00346             if (empty($result['error']) && !$redirectUrl) {
00347                 $this->loadLayout('checkout_onepage_review');
00348 
00349                 $result['goto_section'] = 'review';
00350                 $result['update_section'] = array(
00351                     'name' => 'review',
00352                     'html' => $this->getLayout()->getBlock('root')->toHtml()
00353                 );
00354 
00355 //                $result['review_html'] = $this->getLayout()->getBlock('root')->toHtml();
00356             }
00357 
00358             if ($redirectUrl) {
00359                 $result['redirect'] = $redirectUrl;
00360             }
00361 
00362             $this->getResponse()->setBody(Zend_Json::encode($result));
00363         }
00364     }

saveShippingAction (  ) 

Definition at line 274 of file OnepageController.php.

00275     {
00276         $this->_expireAjax();
00277         if ($this->getRequest()->isPost()) {
00278             $data = $this->getRequest()->getPost('shipping', array());
00279             $customerAddressId = $this->getRequest()->getPost('shipping_address_id', false);
00280             $result = $this->getOnepage()->saveShipping($data, $customerAddressId);
00281 
00282             if (!isset($result['error'])) {
00283                 $result['goto_section'] = 'shipping_method';
00284                 $result['update_section'] = array(
00285                     'name' => 'shipping-method',
00286                     'html' => $this->_getShippingMethodsHtml()
00287                 );
00288             }
00289 
00290 //            $this->loadLayout('checkout_onepage_shippingMethod');
00291 //            $result['shipping_methods_html'] = $this->getLayout()->getBlock('root')->toHtml();
00292 //            $result['shipping_methods_html'] = $this->_getShippingMethodsHtml();
00293 
00294             $this->getResponse()->setBody(Zend_Json::encode($result));
00295         }
00296     }

saveShippingMethodAction (  ) 

Definition at line 298 of file OnepageController.php.

00299     {
00300         $this->_expireAjax();
00301         if ($this->getRequest()->isPost()) {
00302             $data = $this->getRequest()->getPost('shipping_method', '');
00303             $result = $this->getOnepage()->saveShippingMethod($data);
00304             /*
00305             $result will have erro data if shipping method is empty
00306             */
00307             if(!$result) {
00308                 Mage::dispatchEvent('checkout_controller_onepage_save_shipping_method', array('request'=>$this->getRequest(), 'quote'=>$this->getOnepage()->getQuote()));
00309                 $this->getResponse()->setBody(Zend_Json::encode($result));
00310 
00311                 $result['goto_section'] = 'payment';
00312                 $result['update_section'] = array(
00313                     'name' => 'payment-method',
00314                     'html' => $this->_getPaymentMethodsHtml()
00315                 );
00316 
00317 //                $result['payment_methods_html'] = $this->_getPaymentMethodsHtml();
00318             }
00319             $this->getResponse()->setBody(Zend_Json::encode($result));
00320         }
00321 
00322     }

shippingMethodAction (  ) 

Definition at line 153 of file OnepageController.php.

00154     {
00155         $this->_expireAjax();
00156         $this->loadLayout(false);
00157         $this->renderLayout();
00158     }

successAction (  ) 

Definition at line 167 of file OnepageController.php.

00168     {
00169         if (!$this->getOnepage()->getCheckout()->getLastSuccessQuoteId()) {
00170             $this->_redirect('checkout/cart');
00171             return;
00172         }
00173 
00174         $lastQuoteId = $this->getOnepage()->getCheckout()->getLastQuoteId();
00175         $lastOrderId = $this->getOnepage()->getCheckout()->getLastOrderId();
00176 
00177         if (!$lastQuoteId || !$lastOrderId) {
00178             $this->_redirect('checkout/cart');
00179             return;
00180         }
00181 
00182         Mage::getSingleton('checkout/session')->clear();
00183         $this->loadLayout();
00184         $this->_initLayoutMessages('checkout/session');
00185         Mage::dispatchEvent('checkout_onepage_controller_success_action');
00186         $this->renderLayout();
00187     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:52 2009 for Magento by  doxygen 1.5.8