Skip to content

Commit

Permalink
Adapts code for locale selector
Browse files Browse the repository at this point in the history
  • Loading branch information
Norbert committed Jul 27, 2014
1 parent b55c4b7 commit 6b07aae
Showing 1 changed file with 48 additions and 9 deletions.
57 changes: 48 additions & 9 deletions zfapp/library/Application/Controller/Action/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,27 125,55 @@ public function init()
$dbm = new MW_DB_Manager_PDO( $conf );
$ctx->setDatabaseManager( $dbm );

$i18n = new MW_Translation_Zend( self::_getArcavias()->getI18nPaths(), 'gettext', 'en_GB', array('disableNotices'=>true) );
if( function_exists( 'apc_store' ) === true ) {
$i18n = new MW_Translation_Decorator_APC( $i18n );
$i18n_en = new MW_Translation_Zend( self::_getArcavias()->getI18nPaths(), 'gettext', 'en_GB', array('disableNotices'=>true) );
$i18n_de = new MW_Translation_Zend( self::_getArcavias()->getI18nPaths(), 'gettext', 'de', array('disableNotices'=>true) );

if( function_exists( 'apc_store' ) === true )
{
$i18n_en = new MW_Translation_Decorator_APC( $i18n_en );
$i18n_de = new MW_Translation_Decorator_APC( $i18n_de );
}
$ctx->setI18n( array( 'en' => $i18n ) );
$ctx->setI18n( array( 'en' => $i18n_en, 'de' => $i18n_de ) );

$session = new MW_Session_PHP();
$ctx->setSession( $session );

$logger = MAdmin_Log_Manager_Factory::createManager( $ctx );
$ctx->setLogger( $logger );

$localeManager = MShop_Locale_Manager_Factory::createManager($ctx);
$localeItem = $localeManager->bootstrap( $site, 'en', '', false );
$ctx->setLocale($localeItem);

$cache = new MAdmin_Cache_Proxy_Default( $ctx );
$ctx->setCache( $cache );

$ctx->setEditor( 'test' );


$current = $session->get( 'arcavias/locale/languageid', 'en' );
$language = $conf->get( 'mshop/locale/language', $current );

if( isset( $params['loc-language'] ) ) {
$language = $params['loc-language'];
}

if( $language !== $current ) {
$session->set( 'arcavias/locale/languageid', $language );
}

$current = $session->get( 'arcavias/locale/currencyid', 'EUR' );
$currency = $conf->get( 'mshop/locale/currency', $current );

if( isset( $params['loc-currency'] ) ) {
$currency = $params['loc-currency'];
}

if( $currency !== $current ) {
$session->set( 'arcavias/locale/currencyid', $currency );
}

$localeManager = MShop_Locale_Manager_Factory::createManager($ctx);
$localeItem = $localeManager->bootstrap( $site, $language, $currency, false );
$ctx->setLocale($localeItem);


$customerManager = MShop_Customer_Manager_Factory::createManager( $ctx );
$search = $customerManager->createSearch( true );
$search->setConditions( $search->compare( '==', 'customer.code', 'demo-test' ) );
Expand All @@ -155,6 183,7 @@ public function init()
$ctx->setUserId( $customerItem->getId() );
}


Zend_Registry::set('ctx', $ctx);


Expand All @@ -178,6 207,12 @@ public function init()
}

$this->view->params = $params;


$templatePaths = $arcavias->getCustomPaths( 'client/html' );
$this->view->localeSelect = Client_Html_Locale_Select_Factory::createClient( $ctx, $templatePaths );
$this->view->localeSelect->setView( $this->_createView() );
$this->view->localeSelect->process();
}


Expand All @@ -187,6 222,10 @@ protected function _createView()
$router = Zend_Controller_Front::getInstance()->getRouter();
$router->setGlobalParam( 'site', $this->_getParam( 'site' ) );

// Required to generate URLs to reload the current page
$params = $this->_getAllParams();
$params['target'] = 'routeDefault';

$view = new MW_View_Default();

$helper = new MW_View_Helper_Url_Zend( $view, $router, $this->_getServerUrl() );
Expand All @@ -195,7 234,7 @@ protected function _createView()
$helper = new MW_View_Helper_Translate_Default( $view, $context->getI18n() );
$view->addHelper( 'translate', $helper );

$helper = new MW_View_Helper_Parameter_Default( $view, $this->_getAllParams() );
$helper = new MW_View_Helper_Parameter_Default( $view, $params );
$view->addHelper( 'param', $helper );

$helper = new MW_View_Helper_Config_Default( $view, $context->getConfig() );
Expand Down

0 comments on commit 6b07aae

Please sign in to comment.