# Zugriff auf Shopware()-&gt;Session() bevor postDistpatch

**URL:** <https://forum.shopware.com/t/zugriff-auf-shopware-gt-session-bevor-postdistpatch/24921>\
**Category:** Shopware 3.5\
**Tags:** programming\
**Created:** [5. Februar 2015 um 11:03 UTC](https://forum.shopware.com/t/zugriff-auf-shopware-gt-session-bevor-postdistpatch/24921 "2015-02-05T11:03:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![moep](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@moep](https://forum.shopware.com/u/moep)\
**Post date:** [5. Februar 2015 um 11:03 UTC](https://forum.shopware.com/t/zugriff-auf-shopware-gt-session-bevor-postdistpatch/24921/1 "2015-02-05T11:03:15Z")

</div>

Wie wäre es mir möglich auf Shopware()-\>Session(), insbesondere auf Shopware()-\>Session()-\>sOutputNet bevor postDispatch, während Dispatch, zuzugreifen? Momentan erhalte ich beim Zugriff nur einen Fehler, daß die Dependency Injection “shop” nicht finden kann. Jemand evtl. ne Idee? code Fatal error: Uncaught exception ‘Exception’ with message ‘Resource “shop” not found failure’ in C:\dev\tools\xampp\htdocs\shopware\engine\Shopware\Components\DependencyInjection\Container.php on line 192 ( ! ) Exception: Resource “shop” not found failure in C:\dev\tools\xampp\htdocs\shopware\engine\Shopware\Components\DependencyInjection\Container.php on line 192 Call Stack # Time Memory Function Location 1 0.2000 150896 {main}( ) …\shopware.php:0 2 0.2200 1845904 Shopware\Components\HttpCache\AppCache-\>handle( ) …\shopware.php:109 3 0.2200 1851824 Symfony\Component\HttpKernel\HttpCache\HttpCache-\>handle( ) …\AppCache.php:113 4 0.2200 1867136 Shopware\Components\HttpCache\AppCache-\>lookup( ) …\HttpCache.php:193 5 0.2200 1867296 Symfony\Component\HttpKernel\HttpCache\HttpCache-\>lookup( ) …\AppCache.php:178 6 0.2200 1868240 Symfony\Component\HttpKernel\HttpCache\HttpCache-\>fetch( ) …\HttpCache.php:329 7 0.2200 1873552 Shopware\Components\HttpCache\AppCache-\>forward( ) …\HttpCache.php:429 8 0.2500 2703128 Symfony\Component\HttpKernel\HttpCache\HttpCache-\>forward( ) …\AppCache.php:256 9 0.2500 2703992 Shopware\Kernel-\>handle( ) …\HttpCache.php:472 10 0.3400 5212640 Enlight\_Controller\_Front-\>dispatch( ) …\Kernel.php:141[/code]

---

<div class="post-metadata">

**Author:** ![EikeBrandtWarneke](https://avatars.discourse-cdn.com/v4/letter/e/cdc98d/32.png) [@EikeBrandtWarneke](https://forum.shopware.com/u/EikeBrandtWarneke)\
**Post date:** [5. Februar 2015 um 11:05 UTC](https://forum.shopware.com/t/zugriff-auf-shopware-gt-session-bevor-postdistpatch/24921/2 "2015-02-05T11:05:05Z")

</div>

Der Fehler dürfte relativ wenig mit dem Zugriff auf die Session zu tun haben. Bitte poste mal deinen quellcode. Viele Grüße

---

<div class="post-metadata">

**Author:** ![moep](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@moep](https://forum.shopware.com/u/moep)\
**Post date:** [5. Februar 2015 um 11:23 UTC](https://forum.shopware.com/t/zugriff-auf-shopware-gt-session-bevor-postdistpatch/24921/3 "2015-02-05T11:23:18Z")

</div>

Ich versuche es in einer API Resource @Aquatuning Edit: Problem ist Zeile 49 [code]\<?php namespace Shopware\Components\Api\Resource;

use Shopware\Components\Api\Exception as ApiException;

class MobileShop extends Resource {  
public function getRepository()  
{  
#return $this-\>getManager()-\>getRepository(’\Shopware\CustomModels\MyPlugin\Shop’); return $this-\>getManager()-\>getRepository(’\Shopware\Models\Shop\Shop’); } public function getList($mainLang = null) { $this-\>checkPrivilege(‚read‘); $return = array(); $builder = $this-\>getRepository()-\>createQueryBuilder(‚ms‘); $builder-\>select(array( ‚ms.id‘, ‚ms.categoryId‘, ‚ms.name‘, ‚ms.title‘, ‚ms.position‘, ‚ms.host‘, ‚ms.baseUrl‘, ‚ms.default‘, ‚locale.locale‘, ‚locale.id as locale\_id‘, ‚currency.currency‘, )) -\>where(‚ms.active=1‘) -\>innerJoin(‚ms.locale‘, ‚locale‘) -\>innerJoin(‚ms.currency‘, ‚currency‘) ; $query = $builder-\>getQuery(); $query-\>setHydrationMode($this-\>resultMode); $shopPaginator = $this-\>getManager()-\>createPaginator($query); $shops = $shopPaginator-\>getIterator()-\>getArrayCopy(); $ci = Shopware()-\>Models() -\>getRepository(’\Shopware\CustomModels\MyPlugin\CorporateIdentity’) -\>createQueryBuilder(‚ci‘) -\>getQuery() -\>getSingleResult($this-\>resultMode); //$shop = Shopware()-\>Shop(); //var\_dump($shop); $session = Shopware()-\>Session(); //var\_dump($this-\>sSYSTEM); foreach ($shops as &$shop) { $builder = Shopware()-\>Models()-\>getRepository(’\Shopware\Models\Snippet\Snippet’)-\>createQueryBuilder(‚s‘); $builder-\>select(array( ‚s.id‘, ‚s.name‘, ‚s.value‘ ) ) //-\>where(‚s.shopId = :shopId‘) -\>andWhere(‚s.localeId = :localeId‘) -\>andWhere(„s.namespace like ‚frontend/index/%footer%‘“) //-\>setParameter(‚shopId‘, $shop[‚id‘]) -\>setParameter(‚localeId‘, $shop[‚locale\_id‘]) ; $shop[‚footer‘] = $builder-\>getQuery()-\>getResult($this-\>resultMode); } $builder = Shopware()-\>Models()-\>getRepository(’\Shopware\Models\Site\Site’)-\>createQueryBuilder(‚s‘); $builder-\>select(array( ‚s.id‘, ‚s.parentId‘, ‚s.description‘, ‚s.pageTitle‘, ‚s.metaKeywords‘, ‚s.metaDescription‘, ‚s.html‘, ‚s.grouping‘, ‚s.position‘, ‚s.link‘, )) -\>where(‚s.grouping != :disabledGrouping‘) -\>addOrderBy(‚s.parentId‘, ‚ASC‘) -\>addOrderBy(‚s.position‘, ‚ASC‘) -\>setParameter(‚disabledGrouping‘, „gDisabled“) ; $siteObjects = $builder-\>getQuery()-\>getResult($this-\>resultMode); $siteGroups = array(); #[http://stackoverflow.com/questions/4196157/create-array-tree-from-array-list](http://stackoverflow.com/questions/4196157/create-array-tree-from-array-list) $new = array(); foreach ( $siteObjects as $s ) { if ($s[‚parentId‘] === NULL) { $s[‚parentId‘] = 0; } $new[$s[‚parentId‘]] = $s; foreach (explode(’|’, $s[‚grouping‘]) as $grouping) { if (empty($siteGroups[$grouping])) { $siteGroups[$grouping] = array(); } $siteGroups[$grouping] = $s[‚id‘]; } } if(isset($siteGroups[‚gDisabled‘])) { unset($siteGroups[‚gDisabled‘]); } $sites = $this-\>createTree($new, $new[0]); $return[‚shops‘] = $shops; $return[‚ci‘] = $ci; $return[‚siteGroups‘] = $siteGroups; $return[‚sites‘] = $sites; return array(‚data‘ =\> $return); } private function createTree(&$list, $parent) { $tree = array(); foreach ($parent as $k=\>$l){ if(isset($list[$l[‚id‘]])){ $l[‚children‘] = $this-\>createTree($list, $list[$l[‚id‘]]); } $tree = $l; } return $tree; } } ?\>[/code]
