OXID eShop CE  4.8.10
 All Classes Files Functions Variables Pages
user_address.php
Go to the documentation of this file.
1 <?php
2 
9 {
15  protected $_blDelete = false;
16 
24  public function render()
25  {
27 
28  $soxId = $this->getEditObjectId();
29  if ( $soxId != "-1" && isset( $soxId)) {
30  // load object
31  $oUser = oxNew( "oxuser" );
32  $oUser->load( $soxId);
33 
34  // load adress
35  $soxAddressId = isset($this->sSavedOxid)?$this->sSavedOxid:oxConfig::getParameter( "oxaddressid");
36  if ( $soxAddressId != "-1" && isset( $soxAddressId ) ) {
37  $oAdress = oxNew( "oxaddress" );
38  $oAdress->load( $soxAddressId );
39  $this->_aViewData["edit"] = $oAdress;
40  }
41 
42  $this->_aViewData["oxaddressid"] = $soxAddressId;
43 
44  // generate selected
45  $oAddressList = $oUser->getUserAddresses();
46  foreach ( $oAddressList as $oAddress ) {
47  if ( $oAddress->oxaddress__oxid->value == $soxAddressId ) {
48  $oAddress->selected = 1;
49  break;
50  }
51  }
52 
53  $this->_aViewData["edituser"] = $oUser;
54  }
55 
56  $oCountryList = oxNew( "oxCountryList" );
57  $oCountryList->loadActiveCountries( oxRegistry::getLang()->getObjectTplLanguage() );
58 
59  $this->_aViewData["countrylist"] = $oCountryList;
60 
61  if (!$this->_allowAdminEdit($soxId))
62  $this->_aViewData['readonly'] = true;
63 
64  return "user_address.tpl";
65  }
66 
72  public function save()
73  {
74  parent::save();
75 
76  if ( $this->_allowAdminEdit( $this->getEditObjectId() ) ) {
77  $aParams = oxConfig::getParameter( "editval" );
78  $oAdress = oxNew( "oxaddress" );
79  if ( isset( $aParams['oxaddress__oxid'] ) && $aParams['oxaddress__oxid'] == "-1" ) {
80  $aParams['oxaddress__oxid'] = null;
81  } else {
82  $oAdress->load( $aParams['oxaddress__oxid'] );
83  }
84 
85  $oAdress->assign( $aParams );
86  $oAdress->save();
87 
88  $this->sSavedOxid = $oAdress->getId();
89  }
90  }
91 
97  public function delAddress()
98  {
99  $this->_blDelete = false;
100  if ( $this->_allowAdminEdit( $this->getEditObjectId() ) ) {
101  $aParams = oxConfig::getParameter( "editval" );
102  if ( isset( $aParams['oxaddress__oxid'] ) && $aParams['oxaddress__oxid'] != "-1" ) {
103  $oAdress = oxNew( "oxaddress" );
104  $this->_blDelete = $oAdress->delete( $aParams['oxaddress__oxid'] );
105  }
106  }
107  }
108 }