Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
prefill Order\Address with TYPO3 FrontendUser data
...
// Cart Hook
if (TYPO3_MODE === 'FE') {
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['cart']['showCartActionAfterCartWasLoaded'][1519326733] =
'EXT:cart_ext/Classes/Hooks/FrontendUserHook.php:Extcode\CartExt\Hooks\FrontendUserHook->showCartActionAfterCartWasLoaded';
}
...
<?php
namespace Excode\CartExt\Hooks;
class FrontendUserHook
{
/**
* @param array &$parameters
*/
public function showCartActionAfterCartWasLoaded(&$parameters, $refObj)
{
$billingAddress = $parameters['billingAddress'];
$request = $parameters['request'];
if ($billingAddress instanceof \Extcode\Cart\Domain\Model\Order\Address) {
return;
}
if ($request && $request->getOriginalRequest() && $request->getOriginalRequest()->getArguments()) {
return;
}
$feUserUid = (int)$GLOBALS['TSFE']->fe_user->user['uid'];
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
\TYPO3\CMS\Extbase\Object\ObjectManager::class
);
$frontendUserRepository = $objectManager->get(
\TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository::class
);
$frontenUser = $frontendUserRepository->findByUid($feUserUid);
if ($frontenUser instanceof \TYPO3\CMS\Extbase\Domain\Model\FrontendUser) {
$billingAddress = $objectManager->get(
\Extcode\Cart\Domain\Model\Order\Address::class
);
$billingAddress->setEmail($frontenUser->getEmail());
$billingAddress->setTitle($frontenUser->getTitle());
$billingAddress->setFirstName($frontenUser->getFirstName());
$billingAddress->setLastName($frontenUser->getLastName());
$billingAddress->setCompany($frontenUser->getCompany());
$billingAddress->setStreet($frontenUser->getAddress());
$billingAddress->setZip($frontenUser->getZip());
$billingAddress->setCity($frontenUser->getCity());
}
$parameters['billingAddress'] = $billingAddress;
}
}
@mfMeds
Copy link

mfMeds commented Jan 20, 2020

Für Typo3 Version 9+ hat sich ein wenig verändert.

Meine Version:
https://gist.github.com/mfMeds/af09797e0863248c30271b5a0f3e1f0f

@hweckhardt
Copy link

hweckhardt commented Dec 24, 2020

Funktioniert das auch in Typo3 10?

@martinlipp
Copy link

martinlipp commented Jan 14, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment