00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 class Mage_GoogleCheckout_RedirectController extends Mage_Core_Controller_Front_Action
00033 {
00034
00035
00036
00037
00038
00039
00040 protected function _getApi ()
00041 {
00042 $session = Mage::getSingleton('checkout/session');
00043
00044 $api = Mage::getModel('googlecheckout/api');
00045
00046 if (!$session->getQuote()->hasItems()) {
00047 $this->getResponse()->setRedirect(Mage::getUrl('checkout/cart'));
00048 $api->setError(true);
00049 }
00050
00051 $storeQuote = Mage::getModel('sales/quote')->setStoreId(Mage::app()->getStore()->getId());
00052 $storeQuote->merge($session->getQuote());
00053 $storeQuote
00054 ->setItemsCount($session->getQuote()->getItemsCount())
00055 ->setItemsQty($session->getQuote()->getItemsQty())
00056 ->setChangedFlag(false);
00057 $storeQuote->save();
00058
00059 $baseCurrency = $session->getQuote()->getBaseCurrencyCode();
00060 $currency = Mage::app()->getStore($session->getQuote()->getStoreId())->getBaseCurrency();
00061 $session->getQuote()
00062 ->setForcedCurrency($currency)
00063 ->collectTotals()
00064 ->save();
00065
00066 if (!$api->getError()) {
00067 $api = $api->setAnalyticsData($this->getRequest()->getPost('analyticsdata'))
00068 ->checkout($session->getQuote());
00069
00070 $response = $api->getResponse();
00071 if ($api->getError()) {
00072 Mage::getSingleton('checkout/session')->addError($api->getError());
00073 } else {
00074 $session->replaceQuote($storeQuote);
00075 Mage::getModel('checkout/cart')->init()->save();
00076 if (Mage::getStoreConfigFlag('google/checkout/hide_cart_contents')) {
00077 $session->setGoogleCheckoutQuoteId($session->getQuoteId());
00078 $session->setQuoteId(null);
00079 }
00080 }
00081 }
00082 return $api;
00083 }
00084
00085 public function checkoutAction()
00086 {
00087 $api = $this->_getApi();
00088
00089 if ($api->getError()) {
00090 $url = Mage::getUrl('checkout/cart');
00091 } else {
00092 $url = $api->getRedirectUrl();
00093 }
00094 $this->getResponse()->setRedirect($url);
00095 }
00096
00097
00098
00099
00100
00101 public function redirectAction()
00102 {
00103 $api = $this->_getApi();
00104
00105 if ($api->getError()) {
00106 $this->getResponse()->setRedirect(Mage::getUrl('checkout/cart'));
00107 return;
00108 } else {
00109 $url = $api->getRedirectUrl();
00110 $this->loadLayout();
00111 $this->getLayout()->getBlock('googlecheckout_redirect')->setRedirectUrl($url);
00112 $this->renderLayout();
00113 }
00114 }
00115
00116 public function cartAction()
00117 {
00118 if (Mage::getStoreConfigFlag('google/checkout/hide_cart_contents')) {
00119 $session = Mage::getSingleton('checkout/session');
00120 if ($session->getQuoteId()) {
00121 $session->getQuote()->delete();
00122 }
00123 $session->setQuoteId($session->getGoogleCheckoutQuoteId());
00124 $session->setGoogleCheckoutQuoteId(null);
00125 }
00126
00127 $this->_redirect('checkout/cart');
00128 }
00129
00130 public function continueAction()
00131 {
00132 $session = Mage::getSingleton('checkout/session');
00133
00134 if ($quoteId = $session->getGoogleCheckoutQuoteId()) {
00135 $quote = Mage::getModel('sales/quote')->load($quoteId)
00136 ->setIsActive(false)->save();
00137 $session->unsQuoteId();
00138 }
00139
00140
00141
00142
00143
00144 $url = Mage::getStoreConfig('google/checkout/continue_shopping_url');
00145 if (empty($url)) {
00146 $this->_redirect('');
00147 } elseif (substr($url, 0, 4)==='http') {
00148 $this->getResponse()->setRedirect($url);
00149 } else {
00150 $this->_redirect($url);
00151 }
00152 }
00153
00154 }