Skip to content

Instantly share code, notes, and snippets.

@extcode
Created February 25, 2018 13:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save extcode/4add957d9f43c223b8f80df3b6671535 to your computer and use it in GitHub Desktop.
Save extcode/4add957d9f43c223b8f80df3b6671535 to your computer and use it in GitHub Desktop.
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;
}
}
@martinlipp
Copy link

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