Add user profile data: common user data and billing address data.

@param array                      $aData
@param OxpsPaymorrowOxUser|oxUser $oUser

@return array
189564
protected function _addUserProfileData( array $aData, oxUser $oUser )
    {
        // Common user profile fields
        $aData['customer_id']           = self::toUtf( $oUser->getCustomerPaymorrowCustomerNumber() );
        $aData['customer_group']        = self::toUtf( $oUser->getUserGroupNames(), 255 );
        $aData['customer_title']        = self::toUtf( $oUser->getUserPaymorrowSalutation() );
        $aData['customer_gender']       = self::toUtf( $oUser->getUserPaymorrowGender() );
        $aData['customer_firstName']    = self::toUtf( $oUser->getUserPaymorrowFirstName() );
        $aData['customer_lastName']     = self::toUtf( $oUser->getUserPaymorrowLastName() );
        $aData['customer_phoneNumber']  = self::toUtf( $oUser->getUserPaymorrowPhone() );
        $aData['customer_mobileNumber'] = self::toUtf( $oUser->getUserPaymorrowMobilePhone() );
        $aData['customer_email']        = self::toUtf( $oUser->getUserPaymorrowEmail() );
        $aData['customer_dateOfBirth']  = self::toUtf( $oUser->getUserPaymorrowDateOfBirth() );

        // Billing address fields
        $aData['customer_billingAddress_street']     = self::toUtf( $oUser->getUserPaymorrowStreet() );
        $aData['customer_billingAddress_houseNo']    = self::toUtf( $oUser->getUserPaymorrowStreetNumber() );
        $aData['customer_billingAddress_postalCode'] = self::toUtf( $oUser->getUserPaymorrowZipCode() );
        $aData['customer_billingAddress_city']       = self::toUtf( $oUser->getUserPaymorrowCity() );
        $aData['customer_billingAddress_country']    = self::toUtf( $oUser->getUserPaymorrowCountry() );

        return $aData;
    }
499257
public function getBasketDiscounts($oBasket, $oUser = null)
    {
        $aList = [];
        $aDiscList = $this->_getList($oUser)->getArray();
        /** @var \OxidEsales\Eshop\Application\Model\Discount $oDiscount */
        foreach ($aDiscList as $oDiscount) {
            if ($oDiscount->isForBasket($oBasket)) {
                $aList[$oDiscount->getId()] = $oDiscount;
            }
        }

        return $aList;
    }
686535
public function setCacheUser($iUserId, $aData = [])
    {
        $this->unsetCacheUser($iUserId);
        $oUser = $this->getById($iUserId);

        if (empty($oUser)) {
            return false;
        }

        $this->setCache(
            $this->prepareCacheKey($this->tableIdColumn, $oUser->id, $aData),
            $oUser
        );

        return true;
    }
1323519
protected function _manageFullUserData($oUser, $oAmazonData)
    {
        $oContainer = $this->_getContainer();
        $oSession = $oContainer->getSession();
        $oConfig = $oContainer->getConfig();

        //Parse data from Amazon for OXID
        $aParsedData = $oContainer->getAddressUtil()->parseAmazonAddress(
            $oAmazonData->Destination->PhysicalDestination
        );

        $aDefaultMap = array(
            'oxcompany' => $aParsedData['CompanyName'],
            'oxfname' => $aParsedData['FirstName'],
            'oxlname' => $aParsedData['LastName'],
            'oxcity' => $aParsedData['City'],
            'oxstateid' => $aParsedData['StateOrRegion'],
            'oxcountryid' => $aParsedData['CountryId'],
            'oxzip' => $aParsedData['PostalCode'],
            'oxfon' => $aParsedData['Phone'],
            'oxstreet' => $aParsedData['Street'],
            'oxstreetnr' => $aParsedData['StreetNr'],
            'oxaddinfo' => $aParsedData['AddInfo']
        );

        //Getting Email
        $sEmail = $oAmazonData->Buyer->Email;

        // If we find user account in OXID with same email that we got from Amazon then add new shipping address
        $oDatabase = $oContainer->getDatabase();

        $sQuery = "SELECT OXID
            FROM oxuser
            WHERE OXUSERNAME = {$oDatabase->quote($sEmail)}
            AND OXSHOPID = {$oDatabase->quote($oConfig->getShopId())}";

        $sUserWithSuchEmailOxid = (string)$oDatabase->getOne($sQuery);

        if ($sUserWithSuchEmailOxid !== '') {
            //Load existing user from oxid
            $oUser->load($sUserWithSuchEmailOxid);

            /** @var oxAddress $oDelAddress */
            $oDelAddress = $oContainer->getObjectFactory()->createOxidObject('oxAddress');

            //Maybe we have already shipping address added for this user ? If yes then use it
            /**
             * @var oxAddress[] $aUserAddresses
             */
            $aUserAddresses = $oUser->getUserAddresses();

            foreach ($aUserAddresses as $oAddress) {
                if ((string)$oAddress->getFieldData('oxfname') === (string)$aParsedData['FirstName']
                    && (string)$oAddress->getFieldData('oxlname') === (string)$aParsedData['LastName']
                    && (string)$oAddress->getFieldData('oxstreet') === (string)$aParsedData['Street']
                    && (string)$oAddress->getFieldData('oxstreetnr') === (string)$aParsedData['StreetNr']
                ) {
                    $oDelAddress->load($oAddress->getId());
                    break;
                }
            }

            $oDelAddress->assign(array_merge($aDefaultMap, array('oxuserid' => $sUserWithSuchEmailOxid)));
            $sDeliveryAddressId = $oDelAddress->save();

            $oSession->setVariable('blshowshipaddress', 1);
            $oSession->setVariable('deladrid', $sDeliveryAddressId);
        } else {
            // If the user is new and not found in OXID update data from Amazon
            $oUser->assign(array_merge($aDefaultMap, array('oxusername' => $sEmail)));
            $oUser->save();

            $sDeliveryAddressId = (string) $oSession->getVariable('deladrid');

            // Set Amazon address as shipping
            if ($sDeliveryAddressId !== '') {
                /** @var oxAddress $oDelAddress */
                $oDelAddress = $oContainer->getObjectFactory()->createOxidObject('oxAddress');
                $oDelAddress->load($sDeliveryAddressId);
                $oDelAddress->assign($aDefaultMap);
                $oDelAddress->save();
            }
        }

        return $oUser;
    }
1143795
protected function askQuestionExecute($aData)
    {
        $oMailProfile = TdbDataMailProfile::GetProfile('product-info-request');
        $oMailProfile->AddDataArray($aData);
        // now add product info as well
        /** @var $oActiveProduct TdbShopArticle */
        $oActiveProduct = TdbShop::GetActiveItem();
        $aArticleData = $oActiveProduct->GetObjectPropertiesAsArray();
        $oMailProfile->AddDataArray($aArticleData);
        // add link to article

        $sLink = $oActiveProduct->getLink(true, null, array(TdbShopArticle::CMS_LINKABLE_OBJECT_PARAM_CATEGORY => null));
        $oMailProfile->AddData('sLink', $sLink);
        $oMailProfile->ChangeFromAddress($aData['email'], $aData['name']);
        $oMailProfile->SendUsingObjectView('emails', 'Customer');

        $oMsgManager = TCMSMessageManager::GetInstance();
        $oMsgManager->AddMessage($this->sModuleSpotName, 'QUESTION-SEND');

        $this->getRedirect()->redirect($this->getActivePageService()->getActivePage()->GetRealURLPlain());
    }
941915
protected function _markVouchers($oBasket, $oUser)
    {
        $this->_aVoucherList = $oBasket->getVouchers();

        if (is_array($this->_aVoucherList)) {
            foreach ($this->_aVoucherList as $sVoucherId => $oSimpleVoucher) {
                $oVoucher = oxNew(\OxidEsales\Eshop\Application\Model\Voucher::class);
                $oVoucher->load($sVoucherId);
                $oVoucher->markAsUsed($this->oxorder__oxid->value, $oUser->oxuser__oxid->value, $oSimpleVoucher->dVoucherdiscount);

                $this->_aVoucherList[$sVoucherId] = $oVoucher;
            }
        }
    }
1105217
protected function _isAvailableInOtherOrder($oUser)
    {
        $oSeries = $this->getSerie();
        if (!$oSeries->oxvoucherseries__oxallowuseanother->value) {
            $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
            $sSelect = 'select count(*) from ' . $this->getViewName() . ' where oxuserid = ' . $oDb->quote($oUser->oxuser__oxid->value) . ' and ';
            $sSelect .= 'oxvoucherserieid = ' . $oDb->quote($this->oxvouchers__oxvoucherserieid->value) . ' and ';
            $sSelect .= '((oxorderid is not NULL and oxorderid != "") or (oxdateused is not NULL and oxdateused != 0)) ';

            if ($oDb->getOne($sSelect)) {
                $oEx = oxNew(\OxidEsales\Eshop\Core\Exception\VoucherException::class);
                $oEx->setMessage('ERROR_MESSAGE_VOUCHER_NOTALLOWEDSAMESERIES');
                $oEx->setVoucherNr($this->oxvouchers__oxvouchernr->value);
                throw $oEx;
            }
        }

        return true;
    }
1058357
public function addDiscUser()
    {
        $oConfig = \OxidEsales\Eshop\Core\Registry::getConfig();
        $aChosenUsr = $this->_getActionIds('oxuser.oxid');
        $soxId = $oConfig->getRequestParameter('synchoxid');

        if ($oConfig->getRequestParameter('all')) {
            $sUserTable = $this->_getViewName('oxuser');
            $aChosenUsr = $this->_getAll($this->_addFilter("select $sUserTable.oxid " . $this->_getQuery()));
        }
        if ($soxId && $soxId != "-1" && is_array($aChosenUsr)) {
            foreach ($aChosenUsr as $sChosenUsr) {
                $oObject2Discount = oxNew(\OxidEsales\Eshop\Core\Model\BaseModel::class);
                $oObject2Discount->init('oxobject2discount');
                $oObject2Discount->oxobject2discount__oxdiscountid = new \OxidEsales\Eshop\Core\Field($soxId);
                $oObject2Discount->oxobject2discount__oxobjectid = new \OxidEsales\Eshop\Core\Field($sChosenUsr);
                $oObject2Discount->oxobject2discount__oxtype = new \OxidEsales\Eshop\Core\Field("oxuser");
                $oObject2Discount->save();
            }
        }
    }
145482
protected function setDataUsers(array &$aData, bool $bSetCreated = true): Base
    {
        if ($this->isAutoSetUsers()) {
            if (isLoggedIn()) {
                if ($bSetCreated && empty($aData[$this->tableCreatedByColumn])) {
                    $aData[$this->tableCreatedByColumn] = activeUser('id');
                }
                if (empty($aData[$this->tableModifiedByColumn])) {
                    $aData[$this->tableModifiedByColumn] = activeUser('id');
                }
            } else {
                if ($bSetCreated && empty($aData[$this->tableCreatedByColumn])) {
                    $aData[$this->tableCreatedByColumn] = null;
                }
                if (empty($aData[$this->tableModifiedByColumn])) {
                    $aData[$this->tableModifiedByColumn] = null;
                }
            }
        }

        return $this;
    }
414044
public function getBasketBundleDiscounts($oBasket, $oUser = null)
    {
        $aList = [];
        $aDiscList = $this->_getList($oUser)->getArray();
        /** @var \OxidEsales\Eshop\Application\Model\Discount $oDiscount */
        foreach ($aDiscList as $oDiscount) {
            if ($oDiscount->isForBundleBasket($oBasket)) {
                $aList[$oDiscount->getId()] = $oDiscount;
            }
        }

        return $aList;
    }
137950
protected function getCountCommon(array $aData = [])
    {
        if (empty($aData['select'])) {
            $aData['select'] = [
                $this->getTableAlias() . '.*',
                'ea.ref email_ref',
            ];
        }

        //  Common joins
        $oDb = Factory::service('Database');
        $oDb->join(NAILS_DB_PREFIX . 'email_archive ea', $this->getTableAlias() . '.email_id = ea.id', 'LEFT');

        parent::getCountCommon($aData);
    }
1038169
public Result<Void> addUserRole(AuthzTrans trans,UserRoleDAO.Data urData) {
		Result<Void> rv;
		if(Question.ADMIN.equals(urData.rname)) {
			rv = mayAddAdmin(trans, urData.ns, urData.user);
		} else if(Question.OWNER.equals(urData.rname)) {
			rv = mayAddOwner(trans, urData.ns, urData.user);
		} else {
			rv = checkValidID(trans, new Date(), urData.user);
		}
		if(rv.notOK()) {
			return rv; 
		}
		
		// Check if record exists
		if (q.userRoleDAO.read(trans, urData).isOKhasData()) {
			return Result.err(Status.ERR_ConflictAlreadyExists,
					"User Role exists");
		}
		if (q.roleDAO.read(trans, urData.ns, urData.rname).notOKorIsEmpty()) {
			return Result.err(Status.ERR_RoleNotFound,
					"Role [%s.%s] does not exist", urData.ns, urData.rname);
		}

		urData.expires = trans.org().expiration(null, Expiration.UserInRole, urData.user).getTime();
		
		
		Result<UserRoleDAO.Data> udr = q.userRoleDAO.create(trans, urData);
		switch (udr.status) {
		case OK:
			return Result.ok();
		default:
			return Result.err(udr);
		}
	}
488685
protected function GetTransferUserVariables(TdbShopOrder $oOrder)
    {
        $aUserVar = array();
        $sReturnURLBase = $this->getActivePageService()->getActivePage()->GetRealURLPlain(array(), true);
        if ('.html' === substr($sReturnURLBase, -5)) {
            $sReturnURLBase = substr($sReturnURLBase, 0, -5);
        }
        if ('/' !== substr($sReturnURLBase, -1)) {
            $sReturnURLBase .= '/';
        }
        $sReturnURLBase.self::URL_IDENTIFIER;

        $sSpot = '';
        $oGlobal = TGlobal::instance();
        if ($oGlobal) {
            $oModule = $oGlobal->GetExecutingModulePointer();
            if ($oModule) {
                $sSpot = $oModule->sModuleSpotName;
            }
        }

        $aUserVar['user_variable_0'] = $this->GetResponseURL('success');
        $aUserVar['user_variable_1'] = $this->GetResponseURL('failure');
        $aUserVar['user_variable_2'] = $this->GetResponseURL('notify').'/idnt_'.$this->sqlData['cmsident'];
        $aUserVar['user_variable_3'] = $oOrder->id;
        $aUserVar['user_variable_4'] = $sSpot;
        $aUserVar['user_variable_5'] = $this->sqlData['cmsident'];

        return $aUserVar;
    }
429618
protected function getCountCommonEvent($aData = [])
    {
        if (!empty($aData['keywords'])) {
            if (empty($aData['or_like'])) {
                $aData['or_like'] = [];
            }

            $sToSlug = strtolower(str_replace(' ', '_', $aData['keywords']));

            $aData['or_like'][] = [
                'column' => $this->sTableAlias . '.type',
                'value'  => $sToSlug,
            ];
            $aData['or_like'][] = [
                'column' => 'ue.email',
                'value'  => $aData['keywords'],
            ];
        }

        //  Common joins
        $oDb = Factory::service('Database');
        $oDb->join(NAILS_DB_PREFIX . 'user u', $this->sTableAlias . '.created_by = u.id', 'LEFT');
        $oDb->join(NAILS_DB_PREFIX . 'user_email ue', 'ue.user_id = u.id AND ue.is_primary = 1', 'LEFT');

        $this->getCountCommon($aData);
    }
252228
private function createEditForm(User $oUser)
        {
            $form = $this->createForm(new UserType(), $oUser, array(
                'action' => $this->generateUrl('backend_system_user_update', array('id' => $oUser->getId())),
                'method' => 'PUT',
            ));

            $form->add('submit', 'submit', array('label' => 'Update'));

            return $form;
        }
574611
protected function _setUser($oUser)
    {

        $this->oxorder__oxuserid = new \OxidEsales\Eshop\Core\Field($oUser->getId());

        // bill address
        $this->oxorder__oxbillcompany = clone $oUser->oxuser__oxcompany;
        $this->oxorder__oxbillemail = clone $oUser->oxuser__oxusername;
        $this->oxorder__oxbillfname = clone $oUser->oxuser__oxfname;
        $this->oxorder__oxbilllname = clone $oUser->oxuser__oxlname;
        $this->oxorder__oxbillstreet = clone $oUser->oxuser__oxstreet;
        $this->oxorder__oxbillstreetnr = clone $oUser->oxuser__oxstreetnr;
        $this->oxorder__oxbilladdinfo = clone $oUser->oxuser__oxaddinfo;
        $this->oxorder__oxbillustid = clone $oUser->oxuser__oxustid;
        $this->oxorder__oxbillcity = clone $oUser->oxuser__oxcity;
        $this->oxorder__oxbillcountryid = clone $oUser->oxuser__oxcountryid;
        $this->oxorder__oxbillstateid = clone $oUser->oxuser__oxstateid;
        $this->oxorder__oxbillzip = clone $oUser->oxuser__oxzip;
        $this->oxorder__oxbillfon = clone $oUser->oxuser__oxfon;
        $this->oxorder__oxbillfax = clone $oUser->oxuser__oxfax;
        $this->oxorder__oxbillsal = clone $oUser->oxuser__oxsal;


        // delivery address
        if (($oDelAdress = $this->getDelAddressInfo())) {
            // set delivery address
            $this->oxorder__oxdelcompany = clone $oDelAdress->oxaddress__oxcompany;
            $this->oxorder__oxdelfname = clone $oDelAdress->oxaddress__oxfname;
            $this->oxorder__oxdellname = clone $oDelAdress->oxaddress__oxlname;
            $this->oxorder__oxdelstreet = clone $oDelAdress->oxaddress__oxstreet;
            $this->oxorder__oxdelstreetnr = clone $oDelAdress->oxaddress__oxstreetnr;
            $this->oxorder__oxdeladdinfo = clone $oDelAdress->oxaddress__oxaddinfo;
            $this->oxorder__oxdelcity = clone $oDelAdress->oxaddress__oxcity;
            $this->oxorder__oxdelcountryid = clone $oDelAdress->oxaddress__oxcountryid;
            $this->oxorder__oxdelstateid = clone $oDelAdress->oxaddress__oxstateid;
            $this->oxorder__oxdelzip = clone $oDelAdress->oxaddress__oxzip;
            $this->oxorder__oxdelfon = clone $oDelAdress->oxaddress__oxfon;
            $this->oxorder__oxdelfax = clone $oDelAdress->oxaddress__oxfax;
            $this->oxorder__oxdelsal = clone $oDelAdress->oxaddress__oxsal;
        }
    }
600357
public function createPayPalUser($payPalData)
    {
        $userData = $this->prepareDataPayPalUser($payPalData);

        $userId = $this->getIdByUserName($payPalData->getEmail());
        if ($userId) {
            $this->load($userId);
        }

        $this->oxuser__oxactive = new \OxidEsales\Eshop\Core\Field(1);
        $this->oxuser__oxusername = new \OxidEsales\Eshop\Core\Field($payPalData->getEmail());
        $this->oxuser__oxfname = new \OxidEsales\Eshop\Core\Field($userData['oxfname']);
        $this->oxuser__oxlname = new \OxidEsales\Eshop\Core\Field($userData['oxlname']);
        $this->oxuser__oxfon = new \OxidEsales\Eshop\Core\Field($userData['oxfon']);
        $this->oxuser__oxsal = new \OxidEsales\Eshop\Core\Field($userData['oxsal']);
        $this->oxuser__oxcompany = new \OxidEsales\Eshop\Core\Field($userData['oxcompany']);
        $this->oxuser__oxstreet = new \OxidEsales\Eshop\Core\Field($userData['oxstreet']);
        $this->oxuser__oxstreetnr = new \OxidEsales\Eshop\Core\Field($userData['oxstreetnr']);
        $this->oxuser__oxcity = new \OxidEsales\Eshop\Core\Field($userData['oxcity']);
        $this->oxuser__oxzip = new \OxidEsales\Eshop\Core\Field($userData['oxzip']);
        $this->oxuser__oxcountryid = new \OxidEsales\Eshop\Core\Field($userData['oxcountryid']);
        $this->oxuser__oxstateid = new \OxidEsales\Eshop\Core\Field($userData['oxstateid']);
        $this->oxuser__oxaddinfo = new \OxidEsales\Eshop\Core\Field($userData['oxaddinfo']);
        $this->oxuser__oxpassword = new \OxidEsales\Eshop\Core\Field('');
        $this->oxuser__oxbirthdate = new \OxidEsales\Eshop\Core\Field('');

        if ($this->save()) {
            $this->_setAutoGroups($this->oxuser__oxcountryid->value);

            // and adding to group "oxidnotyetordered"
            $this->addToGroup("oxidnotyetordered");
        }
    }