Get logged in customer in view
Posted: 14 Oct 2019, 12:58
Hi aimeos community, tell me, please, how to get current logged in aimeos customer object in view ? Should I extend something for this ?
Cloud native, ultra fast e-commerce framework
https://aimeos.org/help/
Code: Select all
$view->user = \Aimeos\Controller\Frontend::create( $context, 'customer' )->get();
Code: Select all
$view->user = \Aimeos\Controller\Frontend::create( $context, 'customer' )->get();
Code: Select all
<?php
namespace Aimeos\Client\Helper\Partial;
class Partial extends \Aimeos\MW\View\Helper\Partial\Standard
{
/**
* @param string $file
* @param array $params
* @return string
* @throws \Aimeos\MW\View\Exception
*/
public function transform( $file, array $params = [] )
{
$view = clone $this->getView();
$params['user'] = $view->user;
$view->assign( $params );
return $view->render( $file );
}
}
Code: Select all
<?php
namespace Aimeos\Client\Html\Common\Decorator;
class CustomDecorator extends Base
{
public function addData( \Aimeos\MW\View\Iface $view, array &$tags = array(), &$expire = null )
{
$view = parent::addData( $view, $tags, $expire );
$view->user = \Aimeos\Controller\Frontend::create( $this->getContext(), 'customer' )->get();
$helper = new \Aimeos\Client\Helper\Partial\Partial($view);
$view->addHelper('partial', $helper);
return $view;
}
}
aimeos wrote: ↑14 Oct 2019, 15:48 You have to create a HTML client decorator that add the customer object to the view:
https://aimeos.org/docs/Developers/Html ... components
You can get the customer item of the logged in user with:Code: Select all
$view->user = \Aimeos\Controller\Frontend::create( $context, 'customer' )->get();
Code: Select all
$view->user = \Aimeos\Controller\Frontend::create( $context, 'customer' )->get();
Code: Select all
$view->user = \Aimeos\Controller\Frontend::create( $context, 'customer' )->uses([])->get();