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 $_aMustFillFields = null;
00026 
00031     protected $_blShowNoRegOpt = null;
00032 
00037     protected $_oUser = null;
00038 
00043     protected $_sSelectedAddress = null;
00044 
00049     protected $_iOption = null;
00050 
00055     protected $_oCountryList = null;
00056 
00061     protected $_sOrderRemark = null;
00062 
00067     protected $_sWishId = null;
00068 
00077     public function render()
00078     {
00079         parent::render();
00080 
00081         if ( ( $oUser = $this->getUser() ) ) {
00082 
00083             if ( oxConfig::getParameter( 'blshowshipaddress' ) ) {
00084                 // empty address to disable delivery address
00085                 $this->showShipAddress();
00086                 $this->getDelAddress();
00087                 $this->_addFakeAddress( $oUser->getUserAddresses() );
00088             }
00089         }
00090 
00091         $this->_aViewData['blshowshipaddress'] = $this->showShipAddress();
00092         $this->_aViewData['delivadr']          = $this->getDelAddress();
00093         $this->_aViewData['blnewssubscribed']  = $this->isNewsSubscribed();
00094 
00095         $this->_aViewData['order_remark'] = $this->getOrderRemark();
00096 
00097         $this->_aViewData['oxcountrylist'] = $this->getCountryList();
00098 
00099         $this->_aViewData['iOption'] = $this->getLoginOption();
00100 
00101         $this->_aViewData['blshownoregopt'] = $this->getShowNoRegOption();
00102 
00103         $this->_aViewData['aMustFillFields'] = $this->getMustFillFields();
00104 
00105         return $this->_sThisTemplate;
00106     }
00107 
00113     protected function _getWishListId()
00114     {
00115         $this->_sWishId = null;
00116         // added check because sometimes it throws php warning
00117         //if ( is_array($oBasket->getContents()))
00118         $this->_sWishId = false;
00119         // check if we have to set it here
00120         $oBasket = $this->getSession()->getBasket();
00121         foreach ( $oBasket->getContents() as $oBasketItem ) {
00122             if ( $this->_sWishId = $oBasketItem->getWishId() ) {
00123                 // stop on first found
00124                 break;
00125             }
00126         }
00127         return $this->_sWishId;
00128     }
00129 
00137     protected function _addFakeAddress( $oAddresses )
00138     {
00139         // generate selected no shipping address
00140         $oDefAddress = new oxStdClass();
00141         $oDefAddress->oxaddress__oxid = new oxStdClass();
00142         $oDefAddress->oxaddress__oxid->value    = -2;
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     protected function _getActiveUser()
00159     {
00160         if ( $this->_oUser === null ) {
00161             $this->_oUser = false;
00162             if ( $oUser = $this->getUser() ) {
00163                 $this->_oUser = $oUser;
00164             }
00165         }
00166         return $this->_oUser;
00167     }
00168 
00174     protected function _getSelectedAddress()
00175     {
00176         if ( $this->_sSelectedAddress === null ) {
00177             $this->_sSelectedAddress = false;
00178             if ( $oUser = $this->_getActiveUser() ) {
00179                 $this->_sSelectedAddress = $oUser->getSelectedAddress( $this->_getWishListId() );
00180             }
00181         }
00182         return $this->_sSelectedAddress;
00183     }
00184 
00190     public function getMustFillFields()
00191     {
00192         // passing must-be-filled-fields info
00193         if ( $this->_aMustFillFields === null ) {
00194             $this->_aMustFillFields = false;
00195             $aMustFillFields = $this->getConfig()->getConfigParam( 'aMustFillFields');
00196             if ( is_array( $aMustFillFields ) ) {
00197                 $this->_aMustFillFields = array_flip( $aMustFillFields );
00198             }
00199         }
00200         return $this->_aMustFillFields;
00201     }
00202 
00208     public function getShowNoRegOption()
00209     {
00210         if ( $this->_blShowNoRegOpt === null ) {
00211             $this->_blShowNoRegOpt = !$this->getConfig()->getConfigParam( 'blOrderDisWithoutReg' );
00212         }
00213         return $this->_blShowNoRegOpt;
00214     }
00215 
00221     public function getLoginOption()
00222     {
00223         if ( $this->_iOption === null ) {
00224             // passing user chosen option value to display correct content
00225             $iOption = oxConfig::getParameter( 'option' );
00226             // if user chosen "Option 2"" - we should show user details only if he is authorized
00227             if ( $iOption == 2 && !$this->_getActiveUser() ) {
00228                 $iOption = 0;
00229             }
00230             $this->_iOption = $iOption;
00231         }
00232         return $this->_iOption;
00233     }
00234 
00240     public function getCountryList()
00241     {
00242         if ( $this->_oCountryList === null ) {
00243             $this->_oCountryList = false;
00244             // passing country list
00245             $oCountryList = oxNew( 'oxcountrylist' );
00246             $oCountryList->loadActiveCountries();
00247             if ( $oCountryList->count() ) {
00248                 $this->_oCountryList = $oCountryList;
00249             }
00250         }
00251         return $this->_oCountryList;
00252     }
00253 
00259     public function getOrderRemark()
00260     {
00261         if ( $this->_sOrderRemark === null ) {
00262             $this->_sOrderRemark = false;
00263             if ( $sOrderRemark = oxSession::getVar( 'ordrem' ) ) {
00264                 $this->_sOrderRemark = $sOrderRemark;
00265             }
00266         }
00267         return $this->_sOrderRemark;
00268     }
00269 
00275     public function isNewsSubscribed()
00276     {
00277         if ( $this->_blNewsSubscribed === null ) {
00278             $blNews = false;
00279             if ( ( $blNews = oxConfig::getParameter( 'blnewssubscribed' ) ) === null ) {
00280                 $blNews = true;
00281             }
00282             if ( ( $oUser = $this->_getActiveUser() ) ) {
00283                 $blNews = $oUser->getNewsSubscription()->getOptInStatus();
00284             }
00285             $this->_blNewsSubscribed = $blNews;
00286         }
00287         return $this->_blNewsSubscribed;
00288     }
00289 
00295     public function showShipAddress()
00296     {
00297         if ( $this->_blShowShipAddress === null ) {
00298             $this->_blShowShipAddress = oxConfig::getParameter( 'blshowshipaddress' );
00299             if ( ( $oUser = $this->_getActiveUser() ) ) {
00300                 // wishlist user address id
00301                 if ( $sWishId = $this->_getWishListId() ) {
00302                     // if user didn't click on button to hide
00303                     if ( $sWishId && oxSession::getVar( 'blshowshipaddress' ) === null ) {
00304                         // opening address field for wishlist address information
00305                         oxSession::setVar( 'blshowshipaddress', 1 );
00306                         $this->_blShowShipAddress = 1;
00307                     }
00308                 }
00309                 // loading if only address must be shown
00310                 if ( oxConfig::getParameter( 'blshowshipaddress' ) ) {
00311                     $sAddressId = $this->_getSelectedAddress();
00312                     if ( '-2' == $sAddressId ) {
00313                         // user decided to use paymetn address as delivery
00314                         oxSession::setVar( 'blshowshipaddress', 0 );
00315                         $this->_blShowShipAddress = 0;
00316                         // unsetting delivery address
00317                         oxSession::deleteVar( 'deladdrid' );
00318                     }
00319                 }
00320             }
00321         }
00322         return $this->_blShowShipAddress;
00323     }
00324 
00330     public function getDelAddress()
00331     {
00332         if ( $this->_oDelAddress === null ) {
00333             $this->_oDelAddress = false;
00334             if ( $this->showShipAddress() ) {
00335                 $sAddressId = $this->_getSelectedAddress();
00336                 if ( $sAddressId && $sAddressId != '-1' ) {
00337                     $oAdress = oxNew( 'oxbase' );
00338                     $oAdress->init( 'oxaddress' );
00339                     if ( $oAdress->load( $sAddressId ) ) {
00340                         $this->_oDelAddress = $oAdress;
00341                     }
00342                 }
00343             }
00344         }
00345         return $this->_oDelAddress;
00346     }
00347 
00348 }

Generated on Thu Dec 4 12:04:57 2008 for OXID eShop CE by  doxygen 1.5.5