ext/bestitamazonpay4oxid_oxorder.php
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;
    }
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;
    }
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 ; }
Manages received user data from Amazon

@param oxUser $oUser       Customers user object
@param object $oAmazonData User data received from Amazon WS

@return oxUser
@throws oxConnectionException
@throws oxSystemComponentException
Manages received user data from Amazon