Commit 58bf3534 authored by Christian Czernetzki's avatar Christian Czernetzki
Browse files

Add Performance Tweak and fix Code review issues

parent a617ec9e
......@@ -39,14 +39,17 @@ class GlobalData implements SubscriberInterface
*/
private $em;
/**
* @var array|null
*/
private $netiUserData;
/**
* GlobalData constructor.
*
* @param ConfigInterface $configService
* @param ConfigInterface $configService
* @param \Enlight_Components_Session_Namespace $session
* @param ModelManager $em
*
* @throws \Exception
* @param ModelManager $em
*/
public function __construct(
ConfigInterface $configService,
......@@ -73,6 +76,7 @@ class GlobalData implements SubscriberInterface
* Assigns global smarty variables
*
* @param \Enlight_Controller_ActionEventArgs $args
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function addSmartyGlobals(\Enlight_Controller_ActionEventArgs $args)
{
......@@ -82,30 +86,32 @@ class GlobalData implements SubscriberInterface
$this->userLoggedIn = (bool)$this->session->get('sUserId');
}
$netiUserData = [];
// assign userData array to smarty
if ($this->pluginConfig->isGlobalUserData() && $this->userLoggedIn) {
$this->addUserData($netiUserData);
if (\is_array($this->netiUserData)) {
return;
}
$this->addUserData();
}
if ($this->pluginConfig->isGlobalUserAttributeData() && $this->userLoggedIn) {
$this->addUserAttributes($netiUserData);
$this->addUserAttributes();
}
$view->assign('sUserLoggedIn', $this->userLoggedIn);
$view->assign('netiUserData', $netiUserData);
$view->assign('netiUserData', $this->netiUserData);
}
/**
* @param $netiUserData
*
* @return void
* @throws \Doctrine\ORM\NonUniqueResultException
*/
private function addUserData(&$netiUserData)
private function addUserData()
{
$userData = Shopware()->Modules()->Admin()->sGetUserData();
$netiUserData = [
$this->netiUserData = [
'sUserID' => $userData['additional']['user']['id'],
'sUserCompany' => $userData['additional']['user']['company'],
'sUserEmail' => $userData['additional']['user']['email'],
......@@ -144,7 +150,7 @@ class GlobalData implements SubscriberInterface
*
* @return void
*/
private function addUserAttributes(&$netiUserData)
private function addUserAttributes()
{
$userId = $this->session->offsetGet('sUserId');
$qb = $this->em->createQueryBuilder();
......@@ -163,7 +169,7 @@ class GlobalData implements SubscriberInterface
$result = $qb->getQuery()->execute(['customerId' => $userId], AbstractQuery::HYDRATE_ARRAY);
$attributeData = array_shift($result);
$netiUserData += [
$this->netiUserData += [
'sUserAttribute' => $attributeData['attribute'],
'sUserShippingAttribute' => $attributeData['shipping']['attribute'],
'sUserBillingAttribute' => $attributeData['billing']['attribute'],
......@@ -174,12 +180,18 @@ class GlobalData implements SubscriberInterface
/**
* @param $groupKey
* @return string
* @throws \Doctrine\ORM\NonUniqueResultException
*/
private function addUserCustomerGroupName($groupKey)
{
/** @var Group $result */
$result = $this->em->getRepository(Group::class)->findOneBy(['key' => $groupKey]);
$qb = $this->em->getRepository(Group::class)->createQueryBuilder('g');
$qb->select('g.name')
->where('g.key = :key')
->setParameter('key', $groupKey);
$result = $qb->getQuery()->getSingleScalarResult();
return($result->getName());
return($result);
}
}
......@@ -207,6 +207,6 @@ The config option to disable the sUserLoggedIn smarty variable was removed for p
</changelog>
<requiredPlugins>
<requiredPlugin pluginName="NetiFoundation" minVersion="4.0.0"/>
<requiredPlugin pluginName="NetiFoundation" minVersion="4.0.8"/>
</requiredPlugins>
</plugin>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment