OXID eShop CE  4.9.6
 All Classes Files Functions Variables Pages
oxaddress.php
Go to the documentation of this file.
1 <?php
2 
6 class oxAddress extends oxBase
7 {
8 
14  protected $_sClassName = 'oxaddress';
15 
21  protected $_blSelected = false;
22 
26  protected $_oStateObject = null;
27 
33  protected function _getStateObject()
34  {
35  if (is_null($this->_oStateObject)) {
36  $this->_oStateObject = oxNew('oxState');
37  }
38 
39  return $this->_oStateObject;
40  }
41 
47  public function __construct()
48  {
50  $this->init('oxaddress');
51  }
52 
58  public function __toString()
59  {
60  return $this->toString();
61  }
62 
68  public function toString()
69  {
70  $sFirstName = $this->oxaddress__oxfname->value;
71  $sLastName = $this->oxaddress__oxlname->value;
72  $sStreet = $this->oxaddress__oxstreet->value;
73  $sStreetNr = $this->oxaddress__oxstreetnr->value;
74  $sCity = $this->oxaddress__oxcity->value;
75 
76  //format it
77  $sAddress = "";
78  if ($sFirstName || $sLastName) {
79  $sAddress = $sFirstName . ($sFirstName ? " " : "") . "$sLastName, ";
80  }
81  $sAddress .= "$sStreet $sStreetNr $sCity";
82 
83  $sAddress = trim($sAddress);
84 
85  return $sAddress;
86  }
87 
93  public function getEncodedDeliveryAddress()
94  {
95  return md5($this->_getMergedAddressFields());
96  }
97 
105  public function getState()
106  {
107  return $this->getStateId();
108  }
109 
115  public function getStateId()
116  {
117  return $this->oxaddress__oxstateid->value;
118  }
119 
120 
128  public function getStateTitle($sId = null)
129  {
130  $oState = $this->_getStateObject();
131 
132  if (is_null($sId)) {
133  $sId = $this->getStateId();
134  }
135 
136  return $oState->getTitleById($sId);
137  }
138 
144  public function isSelected()
145  {
146  return $this->_blSelected;
147  }
148 
152  public function setSelected()
153  {
154  $this->_blSelected = true;
155  }
156 
162  protected function _getMergedAddressFields()
163  {
164  $sDelAddress = '';
165  $sDelAddress .= $this->oxaddress__oxcompany;
166  $sDelAddress .= $this->oxaddress__oxfname;
167  $sDelAddress .= $this->oxaddress__oxlname;
168  $sDelAddress .= $this->oxaddress__oxstreet;
169  $sDelAddress .= $this->oxaddress__oxstreetnr;
170  $sDelAddress .= $this->oxaddress__oxaddinfo;
171  $sDelAddress .= $this->oxaddress__oxcity;
172  $sDelAddress .= $this->oxaddress__oxcountryid;
173  $sDelAddress .= $this->oxaddress__oxstateid;
174  $sDelAddress .= $this->oxaddress__oxzip;
175  $sDelAddress .= $this->oxaddress__oxfon;
176  $sDelAddress .= $this->oxaddress__oxfax;
177  $sDelAddress .= $this->oxaddress__oxsal;
178 
179  return $sDelAddress;
180  }
181 }