Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge custom site configuration on admin pages #466

Merged
merged 2 commits into from
Aug 26, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Aimeos/Shop/Controller/JqadmController.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,17 @@ protected function createAdmin() : \Aimeos\Admin\JQAdm\Iface
$context = app( 'aimeos.context' )->get( false, 'backend' );
$context->setI18n( app( 'aimeos.i18n' )->get( array( $lang, 'en' ) ) );
$context->setLocale( app( 'aimeos.locale' )->getBackend( $context, $site ) );

$siteManager = \Aimeos\MShop::create( $context, 'locale/site');

$filter = $siteManager->filter();
$filter->add([ 'locale.site.code' => $site ]);

$siteItem = $siteManager->search( $filter->slice( 0 ) );
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use $siteManager->find( $site ) instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, that is much better. I have switched to that method.

$siteConfig = $siteItem->getConfig()->toArray();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getConfig() already returns an array, so calling toArray() should fail

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did initially try to just use $siteItem->getConfig() but config()->apply($siteConfig) complained that $siteConfig was a Map rather than an array. I think this was because I wasn't popping the config array off of the list returned from the filter/search.

I have just changed this to remove ->toArray() and it works perfectly.

$siteConfig = array_pop( $siteConfig );
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be wrong because only one setting will be applied to the config instead of all settings

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The array returned from $site-Item->getConfig()->toArray() is like this:

[1] => [
'theme/default/--ai-bg' => '#000000',
'theme/default/--ai-bg-alt' => '#ffffff',
]

so array_pop returns the full settings array

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have just tested removing ->toArray() from line 267 and this makes array_pop unnecessary so I have removed that too.


$context->config()->apply( $siteConfig );

$view = app( 'aimeos.view' )->create( $context, $paths, $lang );

Expand Down