Adds the session object to the context

@param \Aimeos\MShop\Context\Item\Iface $context Context object
@return \Aimeos\MShop\Context\Item\Iface Modified context object
427088
protected function addSession( \Aimeos\MShop\Context\Item\Iface $context )
	{
		$session = new \Aimeos\MW\Session\Laravel5( $this->session );

		return $context->setSession( $session );
	}
1134974
protected function addUserGroups( \Aimeos\MShop\Context\Item\Iface $context )
	{
		$username = '';
		$token = $this->container->get( 'security.token_storage' )->getToken();

		if( is_object( $token ) && is_object( $token->getUser() ) && method_exists( $token->getUser(), 'getId' ) )
		{
			$username =  $token->getUser()->getUsername();
			$userid = $token->getUser()->getId();
			$context->setUserId( $userid );
			$context->setGroupIds( function() use ( $context, $userid )
			{
				$manager = \Aimeos\MShop::create( $context, 'customer' );
				return $manager->getItem( $userid, array( 'customer/group' ) )->getGroups();
			} );
		}

		if( $username === '' && $this->container->has( 'request_stack' )
			&& ( $request = $this->container->get('request_stack')->getMasterRequest() ) !== null
		) {
			$username = $request->getClientIp();
		}

		return $context->setEditor( $username );
	}
452349
protected function addDatabaseManager( \Aimeos\MShop\Context\Item\Iface $context )
	{
		$dbm = new \Aimeos\MW\DB\Manager\DBAL( $context->getConfig() );

		return $context->setDatabaseManager( $dbm );
	}
408956
protected function addCache( \Aimeos\MShop\Context\Item\Iface $context )
	{
		$cache = new \Aimeos\MAdmin\Cache\Proxy\Standard( $context );

		return $context->setCache( $cache );
	}
977144
public function context(Context $context = null) : Context
    {
        if (!$this->context) {
            $this->context = $context ?: new SimpleContext;
        }

        return $this->context;
    }
670510
public function setObject( \Aimeos\Controller\Frontend\Iface $object )
	{
		parent::setObject( $object );

		$this->controller->setObject( $object );

		return $this;
	}
423787
protected static function addMessageQueueManager( \Aimeos\MShop\Context\Item\Iface $context )
	{
		if( isset( $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_mqueue'] )
			&& is_callable( ( $fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_mqueue'] ) )
		) {
			return $fcn( $context );
		}

		return $context->setMessageQueueManager( new \Aimeos\MW\MQueue\Manager\Standard( $context->getConfig() ) );
	}
508321
protected function _actionAdd(AnCommandContext $context)
    {
        $data = $context->data;

        return $this->getRepository()->create($data->toArray());
    }
477215
public function get( \Aimeos\MShop\Context\Item\Iface $context )
	{
		if( $this->locale === null )
		{
			$status = $this->container->getParameter( 'aimeos_shop.disable_sites' );
			$request = $this->requestStack->getMasterRequest();

			$site = $request->attributes->get( 'site', $request->query->get( 'site', 'default' ) );
			$currency = $request->attributes->get( 'currency', $request->query->get( 'currency', '' ) );
			$lang = $request->attributes->get( 'locale', $request->query->get( 'locale', '' ) );

			$localeManager = \Aimeos\MShop::create( $context, 'locale' );
			$this->locale = $localeManager->bootstrap( $site, $lang, $currency, $status );
		}

		return $this->locale;
	}
883066
protected function _afterEntityInsert(AnCommandContext $context)
    {
        $this->set->setValue('photo_count', $this->set->photos->reset()->getTotal());
    }
747486
public function setContext(Context $context)
    {
        $this->context = $context;

        if (empty($this->parameters['secret'])) {
            $this->parameters['secret'] = $context->getSecret();
        }

        return $this;
    }
912532
public function set( \Aimeos\MShop\Common\Item\Iface $item )
	{
		$code = $item->getCode();

		if( !isset( $this->attributes[$code] ) || !is_array( $this->attributes[$code] ) ) {
			$this->attributes[$code] = [];
		}

		$this->attributes[$code][$item->getType()] = $item;
	}
432155
public function setView( \Aimeos\MW\View\Iface $view )
	{
		$this->client->setView( $view );
		parent::setView( $view );

		return $this;
	}
1090458
protected function addItem( \Aimeos\MW\Container\Content\Iface $contentItem, \Aimeos\MShop\Product\Item\Iface $item, $langid )
	{
		$listTypes = [];
		foreach( $item->getListItems( 'text' ) as $listItem ) {
			$listTypes[$listItem->getRefId()] = $listItem->getType();
		}

		foreach( $this->getTextTypes( 'product' ) as $textTypeItem )
		{
			$textItems = $item->getRefItems( 'text', $textTypeItem->getCode() );

			if( !empty( $textItems ) )
			{
				foreach( $textItems as $textItem )
				{
					$listType = ( isset( $listTypes[$textItem->getId()] ) ? $listTypes[$textItem->getId()] : '' );
					$items = array( $langid, $item->getType(), $item->getCode(), $listType, $textTypeItem->getCode(), '', '' );

					// use language of the text item because it may be null
					if( ( $textItem->getLanguageId() == $langid || is_null( $textItem->getLanguageId() ) )
						&& $textItem->getTypeId() == $textTypeItem->getId() )
					{
						$items[0] = $textItem->getLanguageId();
						$items[5] = $textItem->getId();
						$items[6] = $textItem->getContent();
					}

					$contentItem->add( $items );
				}
			}
			else
			{
				$items = array( $langid, $item->getType(), $item->getCode(), 'default', $textTypeItem->getCode(), '', '' );
				$contentItem->add( $items );
			}
		}
	}
731748
protected static function addSession( \Aimeos\MW\View\Iface $view, \Aimeos\MW\Session\Iface $session )
	{
		$helper = new \Aimeos\MW\View\Helper\Session\Standard( $view, $session );
		$view->addHelper( 'session', $helper );

		return $view;
	}
570698
public function get( \Aimeos\MShop\Context\Item\Iface $context )
	{
		if( $this->locale === null )
		{
			$site = Input::get( 'site', 'default' );
			$currency = Input::get( 'currency', '' );
			$lang = Input::get( 'locale', '' );

			if( Route::current() )
			{
				$site =  Route::input( 'site', $site );
				$currency = Route::input( 'currency', $currency );
				$lang = Route::input( 'locale', $lang );
			}

			$localeManager = \Aimeos\MShop::create( $context, 'locale' );
			$disableSites = $this->config->get( 'shop.disableSites', true );

			try {
				$this->locale = $localeManager->bootstrap( $site, $lang, $currency, $disableSites );
			} catch( \Aimeos\MShop\Locale\Exception $e ) {
				$this->locale = $localeManager->bootstrap( 'default', $lang, $currency, $disableSites );
			}
		}

		return $this->locale;
	}
179037
protected static function cache_add(context $context) {
        if (isset(self::$cache_contextsbyid[$context->id])) {
            // already cached, no need to do anything - this is relatively cheap, we do all this because count() is slow
            return;
        }

        if (self::$cache_count >= CONTEXT_CACHE_MAX_SIZE) {
            $i = 0;
            foreach(self::$cache_contextsbyid as $ctx) {
                $i++;
                if ($i <= 100) {
                    // we want to keep the first contexts to be loaded on this page, hopefully they will be needed again later
                    continue;
                }
                if ($i > (CONTEXT_CACHE_MAX_SIZE / 3)) {
                    // we remove oldest third of the contexts to make room for more contexts
                    break;
                }
                unset(self::$cache_contextsbyid[$ctx->id]);
                unset(self::$cache_contexts[$ctx->contextlevel][$ctx->instanceid]);
                self::$cache_count--;
            }
        }

        self::$cache_contexts[$context->contextlevel][$context->instanceid] = $context;
        self::$cache_contextsbyid[$context->id] = $context;
        self::$cache_count++;
    }