Created
February 25, 2018 13:28
-
-
Save extcode/4add957d9f43c223b8f80df3b6671535 to your computer and use it in GitHub Desktop.
prefill Order\Address with TYPO3 FrontendUser data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
// 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'; | |
} | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is a version for TYPO 10.4:
https://gist.github.com/martinlipp/83a145b1b3faa0ed6f6f5d74462cbc37