Commit 187c5a32 authored by Sascha Brüggenolte's avatar Sascha Brüggenolte
Browse files

Merge branch '33064' into '4.1'

33064-Extended Global Smarty Variable

See merge request !31
parents 176f1ae7 253416b2
......@@ -15,6 +15,7 @@ use NetiFoundation\Service\PluginManager\ConfigInterface;
use NetiToolKit\Struct\PluginConfig;
use Shopware\Components\Model\ModelManager;
use Shopware\Models\Customer\Customer;
use Shopware\Models\Customer\Group;
class GlobalData implements SubscriberInterface
{
......@@ -38,14 +39,17 @@ class GlobalData implements SubscriberInterface
*/
private $em;
/**
* @var array
*/
private $netiUserData = [];
/**
* GlobalData constructor.
*
* @param ConfigInterface $configService
* @param \Enlight_Components_Session_Namespace $session
* @param ModelManager $em
*
* @throws \Exception
*/
public function __construct(
ConfigInterface $configService,
......@@ -72,6 +76,8 @@ class GlobalData implements SubscriberInterface
* Assigns global smarty variables
*
* @param \Enlight_Controller_ActionEventArgs $args
*
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function addSmartyGlobals(\Enlight_Controller_ActionEventArgs $args)
{
......@@ -81,91 +87,108 @@ 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 ($this->pluginConfig->isGlobalUserAttributeData() && $this->userLoggedIn) {
$this->addUserAttributes($netiUserData);
if ($this->userLoggedIn && [] === $this->netiUserData) {
if ($this->pluginConfig->isGlobalUserData()) {
$this->addUserData();
}
if ($this->pluginConfig->isGlobalUserAttributeData()) {
$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 = [
'sUserID' => $userData['additional']['user']['id'],
'sUserCompany' => $userData['additional']['user']['company'],
'sUserEmail' => $userData['additional']['user']['email'],
'sUserAccountmode' => $userData['additional']['user']['accountmode'],
'sUserPaymentID' => $userData['additional']['user']['paymentID'],
'sUserFirstlogin' => $userData['additional']['user']['firstlogin'],
'sUserLastlogin' => $userData['additional']['user']['lastlogin'],
'sUserNewsletter' => (bool)$userData['additional']['user']['newsletter'],
'sUserAffiliate' => (bool)$userData['additional']['user']['affiliate'],
'sUserCustomergroup' => $userData['additional']['user']['customergroup'],
'sUserPaymentpreset' => $userData['additional']['user']['paymentpreset'],
'sUserLanguage' => $userData['additional']['user']['language'],
'sUserSubshopID' => $userData['additional']['user']['subshopID'],
'sUserPricegroupID' => $userData['additional']['user']['pricegroupID'],
'sUserInternalcomment' => $userData['additional']['user']['internalcomment'],
'sUserCustomernumber' => $userData['additional']['user']['customernumber'],
'sUserBillingaddressCompany' => $userData['billingaddress']['company'],
'sUserBillingaddressDepartment' => $userData['billingaddress']['department'],
'sUserBillingaddressSalutation' => $userData['billingaddress']['salutation'],
'sUserBillingaddressFirstname' => $userData['billingaddress']['firstname'],
'sUserBillingaddressLastname' => $userData['billingaddress']['lastname'],
'sUserBillingaddressStreet' => $userData['billingaddress']['street'],
'sUserBillingaddressZipcode' => $userData['billingaddress']['zipcode'],
'sUserBillingaddressCity' => $userData['billingaddress']['city'],
'sUserBillingaddressPhone' => $userData['billingaddress']['phone'],
'sUserBillingaddressFax' => $userData['billingaddress']['fax'],
'sUserBillingaddressCountryID' => $userData['billingaddress']['countryID'],
'sUserBillingaddressStateID' => $userData['billingaddress']['stateID'],
'sUserBillingaddressBirthday' => $userData['billingaddress']['birthday'],
$userData = Shopware()->Modules()->Admin()->sGetUserData();
$this->netiUserData = [
'sUserID' => $userData['additional']['user']['id'],
'sUserCompany' => $userData['additional']['user']['company'],
'sUserEmail' => $userData['additional']['user']['email'],
'sUserAccountmode' => $userData['additional']['user']['accountmode'],
'sUserPaymentID' => $userData['additional']['user']['paymentID'],
'sUserFirstlogin' => $userData['additional']['user']['firstlogin'],
'sUserLastlogin' => $userData['additional']['user']['lastlogin'],
'sUserNewsletter' => (bool)$userData['additional']['user']['newsletter'],
'sUserAffiliate' => (bool)$userData['additional']['user']['affiliate'],
'sUserCustomergroup' => $userData['additional']['user']['customergroup'],
'sUserCustomergroupName' => $this->addUserCustomerGroupName(
$userData['additional']['user']['customergroup']
),
'sUserPaymentpreset' => $userData['additional']['user']['paymentpreset'],
'sUserLanguage' => $userData['additional']['user']['language'],
'sUserSubshopID' => $userData['additional']['user']['subshopID'],
'sUserPricegroupID' => $userData['additional']['user']['pricegroupID'],
'sUserInternalcomment' => $userData['additional']['user']['internalcomment'],
'sUserCustomernumber' => $userData['additional']['user']['customernumber'],
'sUserBillingaddressCompany' => $userData['billingaddress']['company'],
'sUserBillingaddressDepartment' => $userData['billingaddress']['department'],
'sUserBillingaddressSalutation' => $userData['billingaddress']['salutation'],
'sUserBillingaddressFirstname' => $userData['billingaddress']['firstname'],
'sUserBillingaddressLastname' => $userData['billingaddress']['lastname'],
'sUserBillingaddressStreet' => $userData['billingaddress']['street'],
'sUserBillingaddressZipcode' => $userData['billingaddress']['zipcode'],
'sUserBillingaddressCity' => $userData['billingaddress']['city'],
'sUserBillingaddressPhone' => $userData['billingaddress']['phone'],
'sUserBillingaddressFax' => $userData['billingaddress']['fax'],
'sUserBillingaddressCountryID' => $userData['billingaddress']['countryID'],
'sUserBillingaddressStateID' => $userData['billingaddress']['stateID'],
'sUserBillingaddressBirthday' => $userData['billingaddress']['birthday'],
];
}
/**
* @param $netiUserData
*
* @return void
*/
private function addUserAttributes(&$netiUserData)
private function addUserAttributes()
{
$userId = $this->session->offsetGet('sUserId');
$qb = $this->em->createQueryBuilder();
$qb->from(Customer::class, 'c')
->select(['c', 'ca', 'cdb', 'cdba', 'cb', 'cba', 'cs', 'csa'])
->leftJoin('c.attribute', 'ca')
->leftJoin('c.defaultBillingAddress', 'cdb')
->leftJoin('cdb.attribute', 'cdba')
->leftJoin('c.defaultBillingAddress', 'cb')
->leftJoin('cb.attribute', 'cba')
->leftJoin('c.defaultShippingAddress', 'cs')
->leftJoin('cs.attribute', 'csa')
->where($qb->expr()->eq('c.id', ':customerId'))
->setMaxResults(1);
$result = $qb->getQuery()->execute(['customerId' => $userId], AbstractQuery::HYDRATE_ARRAY);
->select([ 'c', 'ca', 'cdb', 'cdba', 'cb', 'cba', 'cs', 'csa' ])
->leftJoin('c.attribute', 'ca')
->leftJoin('c.defaultBillingAddress', 'cdb')
->leftJoin('cdb.attribute', 'cdba')
->leftJoin('c.defaultBillingAddress', 'cb')
->leftJoin('cb.attribute', 'cba')
->leftJoin('c.defaultShippingAddress', 'cs')
->leftJoin('cs.attribute', 'csa')
->where($qb->expr()->eq('c.id', ':customerId'))
->setMaxResults(1);
$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'],
'sUserAddressAttribute' => $attributeData['defaultBillingAddress']['attribute'],
];
}
/**
* @param $groupKey
*
* @return string
* @throws \Doctrine\ORM\NonUniqueResultException
*/
private function addUserCustomerGroupName($groupKey)
{
$qb = $this->em->getRepository(Group::class)->createQueryBuilder('g');
$qb->select('g.name')
->where('g.key = :key')
->setParameter('key', $groupKey);
return $qb->getQuery()->getSingleScalarResult();
}
}
......@@ -5,11 +5,24 @@
<label lang="de">ToolKit</label>
<label lang="en">ToolKit</label>
<version>4.0.0</version>
<version>4.1.0</version>
<link>http://www.shopinventors.de</link>
<author>Net Inventors GmbH</author>
<compatibility minVersion="5.6.0"/>
<changelog version="4.1.0">
<changes lang="de">
<![CDATA[
[#33064] Globale Smarty-Variable um sUserCustomergroupName erweitert
]]>
</changes>
<changes lang="en">
<![CDATA[
[#33064] Extended Global Smarty-Variable with sUserCustomergroupName
]]>
</changes>
</changelog>
<changelog version="4.0.0">
<changes lang="de">
<![CDATA[
......@@ -37,22 +50,22 @@
</changelog>
<changelog version="3.1.0">
<changes lang="de">
<![CDATA[
<changes lang="de">
<![CDATA[
[#30371] sUserCustomernumber und sUserBillingadressCompany zugefügt
[#30354] Fix für die Kundenanmeldung
[#30443] $netiUserData auf der Startseite füllen
]]>
</changes>
<changes lang="en">
<![CDATA[
<![CDATA[
[#30371] added sUserCustomernumber and sUserBillingadressCompany
[#30354] Fix for the customer login
[#30443] Fill $netiUserData on the homepage
]]>
</changes>
</changelog>
<changelog version="3.0.0">
<changes lang="de">
<![CDATA[
......@@ -194,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