Closed liviusirbulescu closed 2 years ago
Works pretty well in our test setup. How does the URL of the link looks like?
URL of the uploaded PDF is ok, it's the icon src for the mime type that's causing the issue, see below snippet.
What's the non-modified HTML source code (before the JS code updates src
and srcset
)?
/var/www/aimeos/vendor/aimeos/ai-client-html/templates/client/html/catalog/detail/body.php
<div class="tab-pane fade" id="nav-characteristics" role="tabpanel" aria-labelledby="nav-characteristics-tab">
<?php if( !( $mediaItems = $this->detailProductItem->getRefItems( 'media', 'download' ) )->isEmpty() ) : ?>
<ul class="block downloads">
<?php foreach( $mediaItems as $id => $mediaItem ) : ?>
<li class="item">
<a href="<?= $this->content( $mediaItem->getUrl(), $mediaItem->getFileSystem() ) ?>"
title="<?= $enc->attr( $mediaItem->getProperties( 'title' )->first( $mediaItem->getLabel() ) ) ?>">
<img class="media-image"
alt="<?= $enc->attr( $mediaItem->getProperties( 'title' )->first( $mediaItem->getLabel() ) ) ?>"
src="<?= $enc->attr( $this->content( $mediaItem->getPreview(), $mediaItem->getFileSystem() ) ) ?>"
srcset="<?= $enc->attr( $this->imageset( $mediaItem->getPreviews(), $mediaItem->getFileSystem() ) ) ?>"
>
<span class="media-name"><?= $enc->html( $mediaItem->getProperties( 'title' )->first( $mediaItem->getLabel() ) ) ?></span>
</a>
</li>
<?php endforeach ?>
</ul>
<?php endif ?>
</div>
We need the generated source code as sent to the browser, not the PHP template
Sorry for the confusion, please see content of $mediaItems
^ Aimeos\Map {#1747 ▼
#list: array:1 [▼
159 => Aimeos\MShop\Media\Item\Standard {#1906 ▼
-available: true
-modified: false
-prefix: "media."
#bdata: array:16 [▼
"cgroups" => 0
"media.id" => 159
"media.siteid" => "1."
"media.languageid" => null
"media.type" => "download"
"media.url" => "1.d/files/a/b/ab7c43c8_Order-12.pdf"
"media.label" => "Order-12.pdf"
"media.status" => 1
"media.mimetype" => "application/pdf"
"media.domain" => "product"
"media.previews" => array:1 [▼
1 => ""
]
"media.filesystem" => "fs-media"
"media.mtime" => "2022-05-31 17:31:14"
"media.ctime" => "2022-05-31 17:31:14"
"media.editor" => "liviu"
".languageid" => "en"
]
-langid: "en"
-listItems: []
-listRefItems: []
-listRmItems: []
-listPrepared: true
-listRmMap: []
-listMap: []
-listMax: 0
-propItems: []
-propRmItems: []
-propMax: 0
}
]
#sep: "/"
}
This works fine for images, however for pdf's, $mediaItem->getPreview() returns an empty string. I might be wrong but shouldn't this return a mimeicon ?
Yes and it's a mime icon in our test setups. How does you ./config/shop.php looks like?
Thanks for your reply, please see below
<?php
$routes = [];
$prefix = config('app.shop_multilocale') ? '{locale}/' : '';
// if (config('app.shop_multishop') || config('app.shop_registration')) {
// $routes = ['routes' => [
// 'admin' => ['prefix' => 'admin', 'middleware' => ['web', 'auth', 'verified']],
// 'jqadm' => ['prefix' => 'admin/{site}/jqadm', 'middleware' => ['web', 'auth', 'verified']],
// 'jsonadm' => ['prefix' => 'admin/{site}/jsonadm', 'middleware' => ['web', 'auth', 'verified']],
// 'jsonapi' => ['prefix' => 'jsonapi/{site}', 'middleware' => ['web', 'api']],
// 'account' => ['prefix' => $prefix . 'profile/{site}', 'middleware' => ['web', 'auth', 'verified']],
// 'default' => ['prefix' => $prefix . 'shop/{site}', 'middleware' => ['web', 'auth', 'verified']],
// 'supplier' => ['prefix' => $prefix . 's/{site}', 'middleware' => ['web', 'auth', 'verified']],
// 'home' => ['prefix' => '{site}', 'middleware' => ['web', 'auth', 'verified']],
// 'page' => ['prefix' => '{site}', 'middleware' => ['web', 'auth', 'verified']],
// 'update' => ['prefix' => '{site}'],
// ]];
// }
return $routes + [
'apc_enabled' => false, // enable for maximum performance if APCu is available
'apc_prefix' => 'aimeos:', // prefix for caching config and translation in APCu
'num_formatter' => 'Locale', // locale based number formatter (alternative: "Standard")
'pcntl_max' => 4, // maximum number of parallel command line processes when starting jobs
'extdir' => '/var/www/marquis/packages',
'version' => env('APP_VERSION', 1), // shop CSS/JS file version
'legal' => true,
'routes' => [
// Docs: https://aimeos.org/docs/latest/laravel/extend/#custom-routes
// Multi-sites: https://aimeos.org/docs/latest/laravel/customize/#multiple-shops
'admin' => ['prefix' => 'admin', 'middleware' => ['web', 'auth', 'verified']],
'jqadm' => ['prefix' => 'admin/{site}/jqadm', 'middleware' => ['web', 'auth', 'verified']],
'jsonadm' => ['prefix' => 'admin/{site}/jsonadm', 'middleware' => ['web', 'auth', 'verified']],
'jsonapi' => ['prefix' => 'jsonapi', 'middleware' => ['web', 'api', 'verified']],
'account' => ['prefix' => $prefix . 'profile', 'middleware' => ['web', 'auth', 'verified']],
'default' => ['prefix' => $prefix . 'shop', 'middleware' => ['web', 'auth', 'verified']],
'supplier' => ['prefix' => $prefix . 's', 'middleware' => ['web', 'auth', 'verified']],
'home' => ['prefix' => $prefix, 'middleware' => ['web', 'auth', 'verified']],
'page' => ['prefix' => $prefix, 'middleware' => ['web', 'auth', 'verified']],
'update' => [],
],
'page' => [
// Docs: https://aimeos.org/docs/latest/laravel/extend/#adapt-pages
'account-index' => ['locale/select', 'basket/mini', 'catalog/tree', 'catalog/search', 'account/profile', 'account/review', 'account/subscription', 'account/history', 'account/favorite', 'account/watch', 'catalog/session'],
'basket-index' => ['locale/select', 'catalog/tree', 'catalog/search', 'basket/standard', 'basket/bulk', 'basket/related'],
'catalog-count' => ['catalog/count'],
'catalog-detail' => ['locale/select', 'basket/mini', 'catalog/tree', 'catalog/search', 'catalog/stage', 'catalog/detail', 'catalog/session'],
'catalog-home' => ['locale/select', 'basket/mini', 'catalog/tree', 'catalog/search', 'catalog/home', 'cms/page'],
'catalog-list' => ['locale/select', 'basket/mini', 'catalog/filter', 'catalog/tree', 'catalog/search', 'catalog/price', 'catalog/supplier', 'catalog/attribute', 'catalog/session', 'catalog/stage', 'catalog/lists'],
'catalog-session' => ['locale/select', 'basket/mini', 'catalog/tree', 'catalog/search', 'catalog/session'],
'catalog-stock' => ['catalog/stock'],
'catalog-suggest' => ['catalog/suggest'],
'catalog-tree' => ['locale/select', 'basket/mini', 'catalog/filter', 'catalog/tree', 'catalog/search', 'catalog/price', 'catalog/supplier', 'catalog/attribute', 'catalog/session', 'catalog/stage', 'catalog/lists'],
'checkout-confirm' => ['catalog/tree', 'catalog/search', 'checkout/confirm'],
'checkout-index' => ['locale/select', 'catalog/tree', 'catalog/search', 'checkout/standard'],
'checkout-update' => ['checkout/update'],
'supplier-detail' => ['locale/select', 'basket/mini', 'catalog/tree', 'catalog/search', 'supplier/detail', 'catalog/lists'],
'cms' => ['basket/mini', 'catalog/tree', 'cms/page'],
],
'resource' => [
'db' => [
'adapter' => config('database.connections.' . config('database.default', 'mysql') . '.driver', 'mysql'),
'host' => config('database.connections.' . config('database.default', 'mysql') . '.host', '127.0.0.1'),
'port' => config('database.connections.' . config('database.default', 'mysql') . '.port', '3306'),
'socket' => config('database.connections.' . config('database.default', 'mysql') . '.unix_socket', ''),
'database' => config('database.connections.' . config('database.default', 'mysql') . '.database', 'forge'),
'username' => config('database.connections.' . config('database.default', 'mysql') . '.username', 'forge'),
'password' => config('database.connections.' . config('database.default', 'mysql') . '.password', ''),
'stmt' => config('database.default', 'mysql') === 'mysql' ? ["SET SESSION sort_buffer_size=2097144; SET NAMES 'utf8mb4'; SET SESSION sql_mode='ANSI'"] : [],
'limit' => 3, // maximum number of concurrent database connections
'defaultTableOptions' => [
'charset' => config('database.connections.' . config('database.default', 'mysql') . '.charset'),
'collate' => config('database.connections.' . config('database.default', 'mysql') . '.collation'),
],
'driverOptions' => config('database.connections.' . config('database.default', 'mysql') . '.options'),
],
'fs' => [
'adapter' => env('FILESYSTEM_DRIVER_FS'), // or FlyAwsS3
'credentials' => [
'key' => config('services.do.key'),
'secret' => config('services.do.secret'),
],
'endpoint' => config('services.do.endpoint'),
'region' => config('services.do.region'),
'version' => 'latest',
'bucket' => config('services.do.bucket'),
'prefix' => config('services.do.prefix'), // optional
'baseurl' => config('services.do.baseurl') . DIRECTORY_SEPARATOR . config('services.do.prefix'),
],
'fs-media' => [
'adapter' => env('FILESYSTEM_DRIVER_FS'), // or FlyAwsS3
'credentials' => [
'key' => config('services.do.key'),
'secret' => config('services.do.secret'),
],
'endpoint' => config('services.do.endpoint'),
'region' => config('services.do.region'),
'version' => 'latest',
'bucket' => config('services.do.bucket'),
'prefix' => config('services.do.prefix'), // optional
'baseurl' => config('services.do.baseurl') . DIRECTORY_SEPARATOR . config('services.do.prefix'),
],
'fs-admin' => [
'adapter' => env('FILESYSTEM_DRIVER_FS'), // or FlyAwsS3
'credentials' => [
'key' => config('services.do.key'),
'secret' => config('services.do.secret'),
],
'endpoint' => config('services.do.endpoint'),
'region' => config('services.do.region'),
'version' => 'latest',
'bucket' => config('services.do.bucket'),
'prefix' => config('services.do.prefix'), // optional
'baseurl' => config('services.do.baseurl') . DIRECTORY_SEPARATOR . config('services.do.prefix'),
],
'cache' => [
'redis' => [
'scheme' => 'tcp',
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'username' => env('REDIS_USERNAME'),
'password' => env('REDIS_PASSWORD'),
'port' => env('REDIS_PORT', '6379'),
'database' => env('REDIS_DB', '0'),
]
],
'email' => [
'from-email' => config('mail.from.address'),
'from-name' => config('mail.from.name'),
],
],
'admin' => [
'jqadm' => [
'resource' => [
'locale' => [
'currency' => [
'groups' => ['admin', 'super'],
],
'language' => [
'groups' => ['admin', 'super'],
],
'groups' => ['admin', 'super'],
],
],
'customer' => [
'fields' => ['customer.status', 'customer.code', 'customer.lastname', 'customer.postal', 'customer.city'],
'decorators' => [
'global' => ['CustomerDecorator']
],
],
'locale' => [
'currency' => [
'decorators' => [
'global' => ['CurrencyDecorator']
]
]
],
'order' => [
'decorators' => [
'global' => ['OrderDecorator']
],
],
'product' => [
'fields' => ['image', 'product.id', 'product.status', 'product.type', 'product.code', 'product.label', 'product.stock'],
]
],
],
'client' => [
'html' => [
'basket' => [
'cache' => [
// 'enable' => false, // Disable basket content caching for development
],
],
'common' => [
'cache' => [
// 'force' => true // enforce caching for logged in users
],
'content' => [
'baseurl' => env('APP_URL')
],
// 'template' => [
// 'baseurl' => public_path('packages/aimeos/shop/themes/elegance')
// ]
],
'catalog' => [
'lists' => [
'basket-add' => true, // shows add to basket in list views
// 'infinite-scroll' => true, // load more products in list view
// 'size' => 48, // number of products per page
],
'selection' => [
'type' => [ // how variant attributes are displayed
'color' => 'radio',
'length' => 'radio',
'width' => 'radio',
],
],
],
'email' => [
'from-email' => config('mail.from.address'),
'from-name' => config('mail.from.name'),
'bcc-email' => config('mail.bcc'),
],
'payment' => [
'bcc-email' => config('mail.bcc'),
'reply-email' => config('mail.from.address'),
],
'checkout' => [
'update' => [
'decorators' => [
'global' => []
]
],
'standard' => [
'decorators' => [
'global' => []
],
],
],
],
],
'controller' => [
// 'common' => [
// 'media' => [
// 'standard' => [
// 'mimeicon' => [
// 'directory' => public_path('/vendor/shop/mimeicons/application/') // string - Path or URL to the base directory
// ]
// ]
// ]
// ],
'frontend' => [
'order' => [
'decorators' => [
'global' => []
]
],
'catalog' => [
'levels-always' => 3 // number of category levels for mega menu
]
],
'jobs' => [
'admin' => [
'log' => [
'limit-days' => 1, // default 30
]
],
'to-email' => config('mail.from.address'),
'from-email' => config('mail.from.name'), // Recipient e-mail address used when sending job e-mails, errors
],
],
'i18n' => [],
'madmin' => [
'cache' => [
'manager' => [
'name' => 'None', // Disable caching for development
],
],
'log' => [
'manager' => [
// 'loglevel' => 7, // Enable debug logging into madmin_log table
],
],
],
'mshop' => [
// 'locale' => [
// 'site' => 'default', // used instead of "default"
// ]
'order' => [
'manager' => [
'decorators' => [
'global' => ['CheckoutDecorator'],
],
],
],
],
'command' => [],
'frontend' => [
'mshop' => [
'customer' => [
'manager' => [
'decorators' => [
'excludes' => [
'CustomerGroup'
],
],
],
],
'attribute' => [
'manager' => [
'decorators' => [
'global' => [
'CustomerGroup' => 'CustomerGroup'
],
],
],
],
'catalog' => [
'manager' => [
'decorators' => [
'local' => [
'CatalogCustomerGroup' => 'CatalogCustomerGroup',
],
],
],
],
'index' => [
'manager' => [
'decorators' => [
'local' => [
'IndexCustomerGroup' => 'IndexCustomerGroup'
],
],
],
],
'media' => [
'manager' => [
'decorators' => [
'global' => [
'CustomerGroup' => 'CustomerGroup'
],
],
],
],
'product' => [
'manager' => [
'decorators' => [
// for relational databases
'global' => [
'CustomerGroup' => 'CustomerGroup'
],
// for ElasticSearch
// 'local' => [
// 'CustomerGroupElastic' => 'CustomerGroupElastic'
// ],
],
],
],
'service' => [
'manager' => [
'decorators' => [
'global' => [
'CustomerGroup' => 'CustomerGroup'
],
],
],
],
'supplier' => [
'manager' => [
'decorators' => [
'global' => [
'CustomerGroup' => 'CustomerGroup'
],
],
],
],
'text' => [
'manager' => [
'decorators' => [
'global' => [
'CustomerGroup' => 'CustomerGroup'
],
],
],
],
'locale' => [
'manager' => [
'site' => [
'decorators' => [
'excludes' => [
'CustomerGroup' => 'CustomerGroup'
],
],
],
],
],
],
],
'backend' => [],
];
The configuration in ./config/shop.php overwrites the resource
key completely and you have to add the missing filesystems like they are in the default config file:
https://github.com/aimeos/aimeos-laravel/blob/master/src/default.php#L65-L100
For some reason I thought keys are replaced, I can confirm that after adding the missing the missing filesystems mime icons are working, thank you.
Just noticed that using url() in a config will throw an error. https://github.com/aimeos/aimeos-laravel/blob/master/src/default.php#L69
Illuminate\Routing\UrlGenerator::__construct(): Argument #2 ($request) must be of type Illuminate\Http\Request, null given, called in /var/www/aimeos/vendor/laravel/framework/src/Illuminate/Routing/RoutingServiceProvider.php on line 65
Do you have a stack trace or can you share the full details?
Sure, see below stack trace - To replicate, add url() in shop config and run composer dump-autoload - more on this here and here
[2022-06-01 10:17:15] production.ERROR: Illuminate\Routing\UrlGenerator::__construct(): Argument #2 ($request) must be of type Illuminate\Http\Request, null given, called in /var/www/aimeos/vendor/laravel/framework/src/Illuminate/Routing/RoutingServiceProvider.php on line 65 {"exception":"[object] (TypeError(code: 0): Illuminate\\Routing\\UrlGenerator::__construct(): Argument #2 ($request) must be of type Illuminate\\Http\\Request, null given, called in /var/www/aimeos/vendor/laravel/framework/src/Illuminate/Routing/RoutingServiceProvider.php on line 65 at /var/www/aimeos/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:120)
[stacktrace]
#0 /var/www/aimeos/vendor/laravel/framework/src/Illuminate/Routing/RoutingServiceProvider.php(65): Illuminate\\Routing\\UrlGenerator->__construct()
#1 /var/www/aimeos/vendor/laravel/framework/src/Illuminate/Container/Container.php(871): Illuminate\\Routing\\RoutingServiceProvider->Illuminate\\Routing\\{closure}()
#2 /var/www/aimeos/vendor/laravel/framework/src/Illuminate/Container/Container.php(756): Illuminate\\Container\\Container->build()
#3 /var/www/aimeos/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(855): Illuminate\\Container\\Container->resolve()
#4 /var/www/aimeos/vendor/laravel/framework/src/Illuminate/Container/Container.php(692): Illuminate\\Foundation\\Application->resolve()
#5 /var/www/aimeos/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(840): Illuminate\\Container\\Container->make()
#6 /var/www/aimeos/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(119): Illuminate\\Foundation\\Application->make()
#7 /var/www/aimeos/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(905): app()
#8 /var/www/aimeos/config/shop.php(124): url()
#9 /var/www/aimeos/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php(72): require('...')
#10 /var/www/aimeos/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php(39): Illuminate\\Foundation\\Bootstrap\\LoadConfiguration->loadConfigurationFiles()
#11 /var/www/aimeos/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(239): Illuminate\\Foundation\\Bootstrap\\LoadConfiguration->bootstrap()
#12 /var/www/aimeos/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(310): Illuminate\\Foundation\\Application->bootstrapWith()
#13 /var/www/aimeos/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(127): Illuminate\\Foundation\\Console\\Kernel->bootstrap()
#14 Command line code(1): Illuminate\\Foundation\\Console\\Kernel->handle()
#15 {main}
"}
Running composer dump-autoload
doesn't reveal the error in our test setups.
Does it work if you use this instead:
'baseurl' => rtrim( env( 'ASSET_URL', PHP_SAPI == 'cli' ? env( 'APP_URL' ) : '', '/' ) . '/vendor/shop/mimeicons',
I can confirm your suggestion works.
rtrim(env('ASSET_URL', PHP_SAPI == 'cli' ? env('APP_URL') : '', '/') . '/vendor/shop/mimeicons')
Thanks again for all help
Great! Thanks for your help :-)
Hi Guys,
Getting this in the logs when uploading a PDF
Environment Version: 2022.04 Operating system: Ubuntu 20.04.4, PHP: 8.1.6
Describe the bug Downloads section