/**
  * Returns user shipping address country id.
  *
  * @param oxUser $oUser
  *
  * @return string
  */
 protected function _getUserShippingCountryId($oUser)
 {
     if ($oUser->getSelectedAddressId() && $oUser->getSelectedAddress()) {
         $sCountryId = $oUser->getSelectedAddress()->oxaddress__oxcountryid->value;
     } else {
         $sCountryId = $oUser->oxuser__oxcountryid->value;
     }
     return $sCountryId;
 }
 /**
  * Add user shipping address data: can be same as billing or a separate shipping address.
  *
  * @param array                      $aData
  * @param OxpsPaymorrowOxUser|oxUser $oUser
  *
  * @return array
  */
 protected function _addUserShippingAddressData(array $aData, oxUser $oUser)
 {
     $blShowShippingAddress = (bool) oxRegistry::getSession()->getVariable('blshowshipaddress');
     if (!$blShowShippingAddress) {
         // Use billing address as shipping
         $aData['customer_shippingAddress_street'] = $aData['customer_billingAddress_street'];
         $aData['customer_shippingAddress_houseNo'] = $aData['customer_billingAddress_houseNo'];
         $aData['customer_shippingAddress_city'] = $aData['customer_billingAddress_city'];
         $aData['customer_shippingAddress_postalCode'] = $aData['customer_billingAddress_postalCode'];
         $aData['customer_shippingAddress_country'] = $aData['customer_billingAddress_country'];
         // Additional, optional fields
         $aData['customer_shippingAddress_company'] = self::toUtf($oUser->oxuser__oxcompany->value);
     } else {
         // Load active shipping address
         /** @var oxAddress $oAddress */
         $oAddress = $oUser->getSelectedAddress();
         $aData['customer_shippingAddress_street'] = self::toUtf($oAddress->oxaddress__oxstreet->value);
         $aData['customer_shippingAddress_houseNo'] = self::toUtf($oAddress->oxaddress__oxstreetnr->value);
         $aData['customer_shippingAddress_city'] = self::toUtf($oAddress->oxaddress__oxcity->value);
         $aData['customer_shippingAddress_postalCode'] = self::toUtf($oAddress->oxaddress__oxzip->value);
         $aData['customer_shippingAddress_country'] = self::toUtf($oUser->getUserPaymorrowCountry($oAddress->oxaddress__oxcountryid->value));
         // Additional, optional fields
         $aData['customer_shippingAddress_additionalInfo'] = self::toUtf($oAddress->oxaddress__oxaddinfo->value);
         $aData['customer_shippingAddress_firstName'] = self::toUtf($oAddress->oxaddress__oxfname->value);
         $aData['customer_shippingAddress_lastName'] = self::toUtf($oAddress->oxaddress__oxlname->value);
         $aData['customer_shippingAddress_company'] = self::toUtf($oAddress->oxaddress__oxcompany->value);
     }
     return $aData;
 }
 /**
  * Get user active shipping address if it is used in the session and update it.
  *
  * @param OxpsPaymorrowOxUser|oxUser $oUser
  * @param array                      $aPostData
  *
  * @return bool
  */
 protected function _updateUserActiveShippingAddress(oxUser $oUser, array $aPostData)
 {
     /** @var oxAddress $oShippingAddress */
     $oShippingAddress = $oUser->getSelectedAddress();
     $blShowShippingAddress = (bool) oxRegistry::getSession()->getVariable('blshowshipaddress');
     if (!$blShowShippingAddress or !$oShippingAddress instanceof oxAddress or !$oShippingAddress->getId()) {
         return false;
     }
     return $oUser->mapShippingDataAndUpdateAddress($aPostData, $oShippingAddress);
 }