OXID eShop CE  4.9.9
 All Classes Files Functions Variables Pages
order_address.php
Go to the documentation of this file.
1 <?php
2 
9 {
10 
18  public function render()
19  {
21 
22  $soxId = $this->_aViewData["oxid"] = $this->getEditObjectId();
23  if ($soxId != "-1" && isset($soxId)) {
24  // load object
25  $oOrder = oxNew("oxorder");
26  $oOrder->load($soxId);
27 
28  $this->_aViewData["edit"] = $oOrder;
29  }
30 
31  $oCountryList = oxNew("oxCountryList");
32  $oCountryList->loadActiveCountries(oxRegistry::getLang()->getObjectTplLanguage());
33 
34  $this->_aViewData["countrylist"] = $oCountryList;
35 
36  return "order_address.tpl";
37  }
38 
49  protected function _processAddress($aData, $sTypeToProcess, $aIgnore)
50  {
51  // empty address fields?
52  $blEmpty = true;
53 
54  // here we will store names of fields which needs to be cleaned up
55  $aFields = array();
56 
57  foreach ($aData as $sName => $sValue) {
58 
59  // if field type matches..
60  if (strpos($sName, $sTypeToProcess) !== false) {
61 
62  // storing which fields must be unset..
63  $aFields[] = $sName;
64 
65  // ignoring whats need to be ignored and testing values
66  if (!in_array($sName, $aIgnore) && $sValue) {
67 
68  // something was found - means leaving as is..
69  $blEmpty = false;
70  break;
71  }
72  }
73  }
74 
75  // cleanup if empty
76  if ($blEmpty) {
77  foreach ($aFields as $sName) {
78  $aData[$sName] = "";
79  }
80  }
81 
82  return $aData;
83  }
84 
88  public function save()
89  {
90  parent::save();
91 
92  $soxId = $this->getEditObjectId();
93  $aParams = (array) oxRegistry::getConfig()->getRequestParameter("editval");
94 
95  //TODO check if shop id is realy necessary at this place.
96  $sShopID = oxRegistry::getSession()->getVariable("actshop");
97  $aParams['oxorder__oxshopid'] = $sShopID;
98 
99  $oOrder = oxNew("oxorder");
100  if ($soxId != "-1") {
101  $oOrder->load($soxId);
102  } else {
103  $aParams['oxorder__oxid'] = null;
104  }
105 
106  $aParams = $this->_processAddress($aParams, "oxorder__oxdel", array("oxorder__oxdelsal"));
107  $oOrder->assign($aParams);
108  $oOrder->save();
109 
110  // set oxid if inserted
111  $this->setEditObjectId($oOrder->getId());
112  }
113 }