order_address.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class Order_Address extends oxAdminDetails
00009 {
00010 
00018     public function render()
00019     {
00020         parent::render();
00021 
00022         $soxId = $this->_aViewData["oxid"] = $this->getEditObjectId();
00023         if ($soxId != "-1" && isset($soxId)) {
00024             // load object
00025             $oOrder = oxNew("oxorder");
00026             $oOrder->load($soxId);
00027 
00028             $this->_aViewData["edit"] = $oOrder;
00029         }
00030 
00031         $oCountryList = oxNew("oxCountryList");
00032         $oCountryList->loadActiveCountries(oxRegistry::getLang()->getObjectTplLanguage());
00033 
00034         $this->_aViewData["countrylist"] = $oCountryList;
00035 
00036         return "order_address.tpl";
00037     }
00038 
00049     protected function _processAddress($aData, $sTypeToProcess, $aIgnore)
00050     {
00051         // empty address fields?
00052         $blEmpty = true;
00053 
00054         // here we will store names of fields which needs to be cleaned up
00055         $aFields = array();
00056 
00057         foreach ($aData as $sName => $sValue) {
00058 
00059             // if field type matches..
00060             if (strpos($sName, $sTypeToProcess) !== false) {
00061 
00062                 // storing which fields must be unset..
00063                 $aFields[] = $sName;
00064 
00065                 // ignoring whats need to be ignored and testing values
00066                 if (!in_array($sName, $aIgnore) && $sValue) {
00067 
00068                     // something was found - means leaving as is..
00069                     $blEmpty = false;
00070                     break;
00071                 }
00072             }
00073         }
00074 
00075         // cleanup if empty
00076         if ($blEmpty) {
00077             foreach ($aFields as $sName) {
00078                 $aData[$sName] = "";
00079             }
00080         }
00081 
00082         return $aData;
00083     }
00084 
00088     public function save()
00089     {
00090         parent::save();
00091 
00092         $soxId = $this->getEditObjectId();
00093         $aParams = (array) oxRegistry::getConfig()->getRequestParameter("editval");
00094 
00095         //TODO check if shop id is realy necessary at this place.
00096         $sShopID = oxRegistry::getSession()->getVariable("actshop");
00097         $aParams['oxorder__oxshopid'] = $sShopID;
00098 
00099         $oOrder = oxNew("oxorder");
00100         if ($soxId != "-1") {
00101             $oOrder->load($soxId);
00102         } else {
00103             $aParams['oxorder__oxid'] = null;
00104         }
00105 
00106         $aParams = $this->_processAddress($aParams, "oxorder__oxdel", array("oxorder__oxdelsal"));
00107         $oOrder->assign($aParams);
00108         $oOrder->save();
00109 
00110         // set oxid if inserted
00111         $this->setEditObjectId($oOrder->getId());
00112     }
00113 }