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