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         if ($myConfig->getConfigParam( 'blPsBasketReservationEnabled' )) {
00071             $this->getSession()->getBasketReservations()->renewExpiration();
00072         }
00073 
00074         $oBasket = $this->getSession()->getBasket();
00075         if ( $myConfig->getConfigParam( 'blPsBasketReservationEnabled' ) && (!$oBasket || ( $oBasket && !$oBasket->getProductsCount() )) ) {
00076             oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL() .'cl=basket' );
00077         }
00078 
00079         parent::render();
00080 
00081         if ( $this->showShipAddress() && $oUser = $this->getUser()) {
00082                 $this->getDelAddress();
00083                 $this->_addFakeAddress( $oUser->getUserAddresses() );
00084         }
00085 
00086         $this->_aViewData['blshowshipaddress'] = $this->showShipAddress();
00087         $this->_aViewData['delivadr']          = $this->getDelAddress();
00088         $this->_aViewData['blnewssubscribed']  = $this->isNewsSubscribed();
00089 
00090         $this->_aViewData['order_remark'] = $this->getOrderRemark();
00091 
00092         $this->_aViewData['oxcountrylist'] = $this->getCountryList();
00093 
00094         $this->_aViewData['iOption'] = $this->getLoginOption();
00095 
00096         $this->_aViewData['blshownoregopt'] = $this->getShowNoRegOption();
00097 
00098         $this->_aViewData['aMustFillFields'] = $this->getMustFillFields();
00099 
00100         if ( $myConfig->getConfigParam( "bl_showFbConnect" ) && !$this->getUser() ) {
00101              $this->_fillFormWithFacebookData();
00102         }
00103 
00104         return $this->_sThisTemplate;
00105     }
00106 
00112     protected function _getWishListId()
00113     {
00114         $this->_sWishId = null;
00115         // check if we have to set it here
00116         $oBasket = $this->getSession()->getBasket();
00117         foreach ( $oBasket->getContents() as $oBasketItem ) {
00118             if ( $this->_sWishId = $oBasketItem->getWishId() ) {
00119                 // stop on first found
00120                 break;
00121             }
00122         }
00123         return $this->_sWishId;
00124     }
00125 
00133     protected function _addFakeAddress( $oAddresses )
00134     {
00135         // generate selected no shipping address
00136         $oDefAddress = new oxStdClass();
00137         $oDefAddress->oxaddress__oxid = new oxStdClass();
00138         $oDefAddress->oxaddress__oxid->value    = -2;
00139 
00140         //T2009-08-19
00141         //deprecated part
00142         //no more fields are used in templates anymore
00143         $oDefAddress->oxaddress__oxfname = new oxStdClass();
00144         $oDefAddress->oxaddress__oxfname->value = '-';
00145         $oDefAddress->oxaddress__oxlname = new oxStdClass();
00146         $oDefAddress->oxaddress__oxlname->value = '-';
00147         $oDefAddress->oxaddress__oxcity = new oxStdClass();
00148         $oDefAddress->oxaddress__oxcity->value  = '-';
00149 
00150         $oAddresses->offsetSet( $oAddresses->count(), $oDefAddress );
00151     }
00152 
00158     /*
00159     protected function _getActiveUser()
00160     {
00161         if ( $this->_oUser === null ) {
00162             $this->_oUser = false;
00163             if ( $oUser = $this->getUser() ) {
00164                 $this->_oUser = $oUser;
00165             }
00166         }
00167         return $this->_oUser;
00168     }*/
00169 
00175     protected function _getSelectedAddress()
00176     {
00177         if ( $this->_sSelectedAddress === null ) {
00178             $this->_sSelectedAddress = false;
00179             if ( $oUser = $this->getUser() ) {
00180                 $this->_sSelectedAddress = $oUser->getSelectedAddress( $this->_getWishListId() );
00181             }
00182         }
00183         return $this->_sSelectedAddress;
00184     }
00185 
00191     public function getShowNoRegOption()
00192     {
00193         if ( $this->_blShowNoRegOpt === null ) {
00194             $this->_blShowNoRegOpt = !$this->getConfig()->getConfigParam( 'blOrderDisWithoutReg' );
00195         }
00196         return $this->_blShowNoRegOpt;
00197     }
00198 
00204     public function getLoginOption()
00205     {
00206         if ( $this->_iOption === null ) {
00207             // passing user chosen option value to display correct content
00208             $iOption = oxConfig::getParameter( 'option' );
00209             // if user chosen "Option 2"" - we should show user details only if he is authorized
00210             if ( $iOption == 2 && !$this->getUser() ) {
00211                 $iOption = 0;
00212             }
00213             $this->_iOption = $iOption;
00214         }
00215         return $this->_iOption;
00216     }
00217 
00223     public function getCountryList()
00224     {
00225         if ( $this->_oCountryList === null ) {
00226             $this->_oCountryList = false;
00227             // passing country list
00228             $oCountryList = oxNew( 'oxcountrylist' );
00229             $oCountryList->loadActiveCountries();
00230             if ( $oCountryList->count() ) {
00231                 $this->_oCountryList = $oCountryList;
00232             }
00233         }
00234         return $this->_oCountryList;
00235     }
00236 
00242     public function getOrderRemark()
00243     {
00244         if ( $this->_sOrderRemark === null ) {
00245             $this->_sOrderRemark = false;
00246             if ( $sOrderRemark = oxSession::getVar( 'ordrem' ) ) {
00247                 $this->_sOrderRemark = oxConfig::checkSpecialChars( $sOrderRemark );
00248             } elseif ( $sOrderRemark = oxConfig::getParameter( 'order_remark' ) ) {
00249                 $this->_sOrderRemark = $sOrderRemark;
00250             }
00251         }
00252         return $this->_sOrderRemark;
00253     }
00254 
00260     public function isNewsSubscribed()
00261     {
00262         if ( $this->_blNewsSubscribed === null ) {
00263             $blNews = false;
00264             if ( ( $blNews = oxConfig::getParameter( 'blnewssubscribed' ) ) === null ) {
00265                 $blNews = false;
00266             }
00267             if ( ( $oUser = $this->getUser() ) ) {
00268                 $blNews = $oUser->getNewsSubscription()->getOptInStatus();
00269             }
00270             $this->_blNewsSubscribed = $blNews;
00271         }
00272 
00273         if (is_null($this->_blNewsSubscribed))
00274             $this->_blNewsSubscribed = false;
00275 
00276         return  $this->_blNewsSubscribed;
00277     }
00278 
00288     public function setShowShipAddress( $blShowShipAddress )
00289     {
00290         // does nothing, used for compat with old templates, remove it
00291         // after removing old templates support
00292     }
00293 
00299     public function showShipAddress()
00300     {
00301 
00302         if ( $this->_blShowShipAddress === null ) {
00303 
00304             $sAddressId = (int) oxConfig::getParameter( 'oxaddressid' );
00305             $this->_blShowShipAddress = ( $sAddressId == -2 ) ? 0 : oxConfig::getParameter( 'blshowshipaddress' );
00306 
00307             if ( ( $oUser = $this->getUser() ) ) {
00308                 // wishlist user address id
00309                 if ( $sWishId = $this->_getWishListId() ) {
00310                     // if user didn't click on button to hide
00311                     if ( $sWishId && oxSession::getVar( 'blshowshipaddress' ) === null ) {
00312                         // opening address field for wishlist address information
00313                         oxSession::setVar( 'blshowshipaddress', true );
00314                         $this->_blShowShipAddress = true;
00315                     }
00316                 }
00317             }
00318 
00319             if ( '-2' == $sAddressId ) {
00320                 // user decided to use paymetn address as delivery
00321                 oxSession::setVar( 'blshowshipaddress', 0 );
00322                 // unsetting delivery address
00323                 $this->_blShowShipAddress = false;
00324             }
00325         }
00326 
00327         //if still not set then take it from session
00328         if ( $this->_blShowShipAddress === null ) {
00329             $this->_blShowShipAddress = oxSession::getVar( 'blshowshipaddress');
00330         }
00331 
00332         if ( $this->_blShowShipAddress === null ) {
00333             $this->_blShowShipAddress = false;
00334         }
00335 
00336         return $this->_blShowShipAddress;
00337     }
00338 
00344     public function getDelAddress()
00345     {
00346         if ( $this->_oDelAddress === null ) {
00347             $this->_oDelAddress = false;
00348             if ( $this->showShipAddress() ) {
00349                 $sAddressId = $this->_getSelectedAddress();
00350                 if ( $sAddressId && $sAddressId != '-1' ) {
00351                     $oAdress = oxNew( 'oxaddress' );
00352                     if ( $oAdress->load( $sAddressId ) ) {
00353                         $this->_oDelAddress = $oAdress;
00354                         $this->_aViewData['deladr'] = null;
00355                     }
00356                 }
00357             }
00358         }
00359         return $this->_oDelAddress;
00360     }
00361 
00367     protected function _fillFormWithFacebookData()
00368     {
00369         // Create our Application instance.
00370         $oFacebook = oxFb::getInstance();
00371 
00372         if ( $oFacebook->isConnected() ) {
00373             $aMe  = $oFacebook->api('/me');
00374 
00375             $aInvAdr = $this->_aViewData['invadr'];
00376 
00377             if ( !$aInvAdr["oxuser__oxfname"] ) {
00378                 $aInvAdr["oxuser__oxfname"] = $aMe["first_name"];
00379             }
00380 
00381             if ( !$aInvAdr["oxuser__oxlname"] ) {
00382                 $aInvAdr["oxuser__oxlname"] = $aMe["last_name"];
00383             }
00384 
00385             $this->_aViewData['invadr'] = $aInvAdr;
00386         }
00387     }
00388 }