user.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class User extends oxUBase
00008 {
00013     protected $_sThisTemplate = 'user.tpl';
00014 
00019     protected $_blIsOrderStep = true;
00020 
00025     protected $_blShowNoRegOpt = null;
00026 
00031     protected $_sSelectedAddress = null;
00032 
00037     protected $_iOption = null;
00038 
00043     protected $_oCountryList = null;
00044 
00049     protected $_sOrderRemark = null;
00050 
00055     protected $_sWishId = null;
00056 
00067     public function render()
00068     {
00069         $myConfig = $this->getConfig();
00070 
00071         if ( $this->getIsOrderStep() ) {
00072             if ($myConfig->getConfigParam( 'blPsBasketReservationEnabled' )) {
00073                 $this->getSession()->getBasketReservations()->renewExpiration();
00074             }
00075 
00076             $oBasket = $this->getSession()->getBasket();
00077             if ( $this->_blIsOrderStep && $myConfig->getConfigParam( 'blPsBasketReservationEnabled' ) && (!$oBasket || ( $oBasket && !$oBasket->getProductsCount() )) ) {
00078                 oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL() .'cl=basket' );
00079             }
00080         }
00081 
00082         parent::render();
00083 
00084         if ( $this->showShipAddress() && $oUser = $this->getUser()) {
00085                 $this->getDelAddress();
00086                 $this->_addFakeAddress( $oUser->getUserAddresses() );
00087         }
00088 
00089         $this->_aViewData['blshowshipaddress'] = $this->showShipAddress();
00090         $this->_aViewData['delivadr']          = $this->getDelAddress();
00091         $this->_aViewData['blnewssubscribed']  = $this->isNewsSubscribed();
00092 
00093         $this->_aViewData['order_remark'] = $this->getOrderRemark();
00094 
00095         $this->_aViewData['oxcountrylist'] = $this->getCountryList();
00096 
00097         $this->_aViewData['iOption'] = $this->getLoginOption();
00098 
00099         $this->_aViewData['blshownoregopt'] = $this->getShowNoRegOption();
00100 
00101         $this->_aViewData['aMustFillFields'] = $this->getMustFillFields();
00102 
00103         if ( $myConfig->getConfigParam( "bl_showFbConnect" ) && !$this->getUser() ) {
00104              $this->_fillFormWithFacebookData();
00105         }
00106 
00107         return $this->_sThisTemplate;
00108     }
00109 
00115     protected function _getWishListId()
00116     {
00117         $this->_sWishId = null;
00118         // check if we have to set it here
00119         $oBasket = $this->getSession()->getBasket();
00120         foreach ( $oBasket->getContents() as $oBasketItem ) {
00121             if ( $this->_sWishId = $oBasketItem->getWishId() ) {
00122                 // stop on first found
00123                 break;
00124             }
00125         }
00126         return $this->_sWishId;
00127     }
00128 
00136     protected function _addFakeAddress( $oAddresses )
00137     {
00138         // generate selected no shipping address
00139         $oDefAddress = new oxStdClass();
00140         $oDefAddress->oxaddress__oxid = new oxStdClass();
00141         $oDefAddress->oxaddress__oxid->value    = -2;
00142 
00143         //T2009-08-19
00144         //deprecated part
00145         //no more fields are used in templates anymore
00146         $oDefAddress->oxaddress__oxfname = new oxStdClass();
00147         $oDefAddress->oxaddress__oxfname->value = '-';
00148         $oDefAddress->oxaddress__oxlname = new oxStdClass();
00149         $oDefAddress->oxaddress__oxlname->value = '-';
00150         $oDefAddress->oxaddress__oxcity = new oxStdClass();
00151         $oDefAddress->oxaddress__oxcity->value  = '-';
00152 
00153         $oAddresses->offsetSet( $oAddresses->count(), $oDefAddress );
00154     }
00155 
00161     /*
00162     protected function _getActiveUser()
00163     {
00164         if ( $this->_oUser === null ) {
00165             $this->_oUser = false;
00166             if ( $oUser = $this->getUser() ) {
00167                 $this->_oUser = $oUser;
00168             }
00169         }
00170         return $this->_oUser;
00171     }*/
00172 
00178     protected function _getSelectedAddress()
00179     {
00180         if ( $this->_sSelectedAddress === null ) {
00181             $this->_sSelectedAddress = false;
00182             if ( $oUser = $this->getUser() ) {
00183                 $this->_sSelectedAddress = $oUser->getSelectedAddress( $this->_getWishListId() );
00184             }
00185         }
00186         return $this->_sSelectedAddress;
00187     }
00188 
00194     public function getShowNoRegOption()
00195     {
00196         if ( $this->_blShowNoRegOpt === null ) {
00197             $this->_blShowNoRegOpt = !$this->getConfig()->getConfigParam( 'blOrderDisWithoutReg' );
00198         }
00199         return $this->_blShowNoRegOpt;
00200     }
00201 
00207     public function getLoginOption()
00208     {
00209         if ( $this->_iOption === null ) {
00210             // passing user chosen option value to display correct content
00211             $iOption = oxConfig::getParameter( 'option' );
00212             // if user chosen "Option 2"" - we should show user details only if he is authorized
00213             if ( $iOption == 2 && !$this->getUser() ) {
00214                 $iOption = 0;
00215             }
00216             $this->_iOption = $iOption;
00217         }
00218         return $this->_iOption;
00219     }
00220 
00226     public function getCountryList()
00227     {
00228         if ( $this->_oCountryList === null ) {
00229             $this->_oCountryList = false;
00230             // passing country list
00231             $oCountryList = oxNew( 'oxcountrylist' );
00232             $oCountryList->loadActiveCountries();
00233             if ( $oCountryList->count() ) {
00234                 $this->_oCountryList = $oCountryList;
00235             }
00236         }
00237         return $this->_oCountryList;
00238     }
00239 
00245     public function getOrderRemark()
00246     {
00247         if ( $this->_sOrderRemark === null ) {
00248             $this->_sOrderRemark = false;
00249             if ( $sOrderRemark = oxSession::getVar( 'ordrem' ) ) {
00250                 $this->_sOrderRemark = oxConfig::checkSpecialChars( $sOrderRemark );
00251             } elseif ( $sOrderRemark = oxConfig::getParameter( 'order_remark' ) ) {
00252                 $this->_sOrderRemark = $sOrderRemark;
00253             }
00254         }
00255         return $this->_sOrderRemark;
00256     }
00257 
00263     public function isNewsSubscribed()
00264     {
00265         if ( $this->_blNewsSubscribed === null ) {
00266             $blNews = false;
00267             if ( ( $blNews = oxConfig::getParameter( 'blnewssubscribed' ) ) === null ) {
00268                 $blNews = false;
00269             }
00270             if ( ( $oUser = $this->getUser() ) ) {
00271                 $blNews = $oUser->getNewsSubscription()->getOptInStatus();
00272             }
00273             $this->_blNewsSubscribed = $blNews;
00274         }
00275 
00276         if (is_null($this->_blNewsSubscribed))
00277             $this->_blNewsSubscribed = false;
00278 
00279         return  $this->_blNewsSubscribed;
00280     }
00281 
00291     public function setShowShipAddress( $blShowShipAddress )
00292     {
00293         // does nothing, used for compat with old templates, remove it
00294         // after removing old templates support
00295     }
00296 
00302     public function showShipAddress()
00303     {
00304 
00305         if ( $this->_blShowShipAddress === null ) {
00306 
00307             $sAddressId = (int) oxConfig::getParameter( 'oxaddressid' );
00308             $this->_blShowShipAddress = ( $sAddressId == -2 ) ? 0 : oxConfig::getParameter( 'blshowshipaddress' );
00309 
00310             if ( ( $oUser = $this->getUser() ) ) {
00311                 // wishlist user address id
00312                 if ( $sWishId = $this->_getWishListId() ) {
00313                     // if user didn't click on button to hide
00314                     if ( $sWishId && oxSession::getVar( 'blshowshipaddress' ) === null ) {
00315                         // opening address field for wishlist address information
00316                         oxSession::setVar( 'blshowshipaddress', true );
00317                         $this->_blShowShipAddress = true;
00318                     }
00319                 }
00320             }
00321 
00322             if ( '-2' == $sAddressId ) {
00323                 // user decided to use paymetn address as delivery
00324                 oxSession::setVar( 'blshowshipaddress', 0 );
00325                 // unsetting delivery address
00326                 $this->_blShowShipAddress = false;
00327             }
00328         }
00329 
00330         //if still not set then take it from session
00331         if ( $this->_blShowShipAddress === null ) {
00332             $this->_blShowShipAddress = oxSession::getVar( 'blshowshipaddress');
00333         }
00334 
00335         if ( $this->_blShowShipAddress === null ) {
00336             $this->_blShowShipAddress = false;
00337         }
00338 
00339         return $this->_blShowShipAddress;
00340     }
00341 
00347     public function getDelAddress()
00348     {
00349         if ( $this->_oDelAddress === null ) {
00350             $this->_oDelAddress = false;
00351             if ( $this->showShipAddress() ) {
00352                 $sAddressId = $this->_getSelectedAddress();
00353                 if ( $sAddressId && $sAddressId != '-1' ) {
00354                     $oAdress = oxNew( 'oxaddress' );
00355                     if ( $oAdress->load( $sAddressId ) ) {
00356                         $this->_oDelAddress = $oAdress;
00357                         $this->_aViewData['deladr'] = null;
00358                     }
00359                 }
00360             }
00361         }
00362         return $this->_oDelAddress;
00363     }
00364 
00370     protected function _fillFormWithFacebookData()
00371     {
00372         // Create our Application instance.
00373         $oFacebook = oxFb::getInstance();
00374 
00375         if ( $oFacebook->isConnected() ) {
00376             $aMe  = $oFacebook->api('/me');
00377 
00378             $aInvAdr = $this->_aViewData['invadr'];
00379             $sCharset = oxLang::getInstance()->translateString( "charset" );
00380 
00381             // do not stop converting on error - just try to translit unknown symbols
00382             $sCharset .= '//TRANSLIT';
00383 
00384             if ( !$aInvAdr["oxuser__oxfname"] ) {
00385                 $aInvAdr["oxuser__oxfname"] = iconv( 'UTF-8', $sCharset, $aMe["first_name"] );
00386             }
00387 
00388             if ( !$aInvAdr["oxuser__oxlname"] ) {
00389                 $aInvAdr["oxuser__oxlname"] = iconv( 'UTF-8', $sCharset, $aMe["last_name"] );
00390             }
00391 
00392             $this->_aViewData['invadr'] = $aInvAdr;
00393         }
00394     }
00395 }