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             } elseif ($sOrderRemark = oxConfig::getParameter( 'order_remark' )) {
00266                 $this->_sOrderRemark = $sOrderRemark;
00267             }
00268         }
00269         return $this->_sOrderRemark;
00270     }
00271 
00277     public function isNewsSubscribed()
00278     {
00279         if ( $this->_blNewsSubscribed === null ) {
00280             $blNews = false;
00281             if ( ( $blNews = oxConfig::getParameter( 'blnewssubscribed' ) ) === null ) {
00282                 $blNews = true;
00283             }
00284             if ( ( $oUser = $this->_getActiveUser() ) ) {
00285                 $blNews = $oUser->getNewsSubscription()->getOptInStatus();
00286             }
00287             $this->_blNewsSubscribed = $blNews;
00288         }
00289         return $this->_blNewsSubscribed;
00290     }
00291 
00299     public function setShowShipAddress( $blShowShipAddress )
00300     {
00301         // does nothing, used for compat with old templates, remove it
00302         // after removing old templates support
00303     }
00304 
00310     public function showShipAddress()
00311     {
00312         if ( $this->_blShowShipAddress === null ) {
00313             $sAddressId = (int) oxConfig::getParameter( 'oxaddressid' );
00314             $this->_blShowShipAddress = ( $sAddressId == -2 ) ? 0 : oxConfig::getParameter( 'blshowshipaddress' );
00315 
00316             if ( ( $oUser = $this->_getActiveUser() ) ) {
00317                 // wishlist user address id
00318                 if ( $sWishId = $this->_getWishListId() ) {
00319                     // if user didn't click on button to hide
00320                     if ( $sWishId && oxSession::getVar( 'blshowshipaddress' ) === null ) {
00321                         // opening address field for wishlist address information
00322                         oxSession::setVar( 'blshowshipaddress', 1 );
00323                         $this->_blShowShipAddress = 1;
00324                     }
00325                 }
00326                 // loading if only address must be shown
00327                 if ( oxConfig::getParameter( 'blshowshipaddress' ) ) {
00328                     $sAddressId = $this->_getSelectedAddress();
00329                     if ( '-2' == $sAddressId ) {
00330                         // user decided to use paymetn address as delivery
00331                         oxSession::setVar( 'blshowshipaddress', 0 );
00332                         $this->_blShowShipAddress = 0;
00333                         // unsetting delivery address
00334                         oxSession::deleteVar( 'deladdrid' );
00335                     }
00336                 }
00337             }
00338         }
00339         return $this->_blShowShipAddress;
00340     }
00341 
00349     public function setDelAddress( $oDelAddress )
00350     {
00351         // disabling default behaviour ..
00352     }
00353 
00359     public function getDelAddress()
00360     {
00361         if ( $this->_oDelAddress === null ) {
00362             $this->_oDelAddress = false;
00363             if ( $this->showShipAddress() ) {
00364                 $sAddressId = $this->_getSelectedAddress();
00365                 if ( $sAddressId && $sAddressId != '-1' ) {
00366                     $oAdress = oxNew( 'oxbase' );
00367                     $oAdress->init( 'oxaddress' );
00368                     if ( $oAdress->load( $sAddressId ) ) {
00369                         $this->_oDelAddress = $oAdress;
00370                     }
00371                 }
00372             }
00373         }
00374         return $this->_oDelAddress;
00375     }
00376 
00377 }

Generated on Tue Aug 18 09:21:09 2009 for OXID eShop CE by  doxygen 1.5.5