Adding Google Model Viewer in Products

How to configure and adapt Aimeos based shops as developer
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
User avatar
ARJIEANGELOG.VICUNA
Posts: 3
Joined: 28 Oct 2022, 10:07

Adding Google Model Viewer in Products

Post by ARJIEANGELOG.VICUNA » 28 Oct 2022, 10:14

Good day, i am very new to your platform, i want to add the google model viewer as a replacement or new function in displaying a product, but i do not know how i can implement it, may i ask for your assistance for this problem.

Thank you in advance

User avatar
aimeos
Administrator
Posts: 7905
Joined: 01 Jan 1970, 00:00

Re: Adding Google Model Viewer in Products

Post by aimeos » 28 Oct 2022, 11:50

First allow uploading the mimetype of the models by adding it using this configuration:
https://github.com/aimeos/aimeos-core/b ... #L574-L605

Then, we need to add the required HTML for the models here:
https://github.com/aimeos/ai-client-htm ... andard.php

If you create a pull request with your changes, we will be happy to merge them :-)
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
ARJIEANGELOG.VICUNA
Posts: 3
Joined: 28 Oct 2022, 10:07

Re: Adding Google Model Viewer in Products

Post by ARJIEANGELOG.VICUNA » 31 Oct 2022, 06:16

Good day Aimeos, may i ask again what is the directory where i can add a unpkg cdn for my google model viewer

User avatar
aimeos
Administrator
Posts: 7905
Joined: 01 Jan 1970, 00:00

Re: Adding Google Model Viewer in Products

Post by aimeos » 31 Oct 2022, 12:57

You can store it to the themes folder and add it conditionally in the header here:
https://github.com/aimeos/ai-client-htm ... hp#L77-L78
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
ARJIEANGELOG.VICUNA
Posts: 3
Joined: 28 Oct 2022, 10:07

Re: Adding Google Model Viewer in Products

Post by ARJIEANGELOG.VICUNA » 01 Nov 2022, 02:07

Hello aimeos i did follow what you told me but i still may have a problem saving the file

I did try to insert the cdn with echo in the public header in the standard.php, because it is the only file in the catalog/detail:

Code: Select all

public function header( string $uid = '' ) : ?string
	{
		$view = $this->view();
		$config = $this->context()->config();
		$prefixes = ['d_prodid', 'd_name'];
		$confkey = 'client/html/catalog/detail';

		$code = $config->get( 'client/html/catalog/detail/prodcode-default' );
		$id = $config->get( 'client/html/catalog/detail/prodid-default', $code );
		echo '<script type="module" src="https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js"></script>';
		if( !$view->param( 'd_name', $view->param( 'd_prodid', $id ) ) ) {
			return '';
		}

		if( $html = $this->cached( 'header', $uid, $prefixes, $confkey ) ) {
			return $this->modify( $html, $uid );
		}
And then i included the mimetype in the default variable:

Code: Select all

$default = [
			'image/webp', 'image/jpeg', 'image/png', 'image/gif', 'image/svg+xml',
			'application/pdf', 'application/zip',
			'video/mp4', 'video/webm'.
			'model/gltf+json', 'model/gltf-binary'
		];
And then for the viewing of the model here i used elseif for the new media

Code: Select all

if( !strncmp( $media->getMimetype(), 'video/', 6 ) )
		{
			return '
				<video autoplay muted class="item" id="image-' . $media->getId() . '" loading="lazy"
					thumbnail="' . $enc->attr( $view->content( $media->getPreview(), $media->getFileSystem() ) ) . '"
					poster="' . $enc->attr( $view->content( $media->getPreview( 600 ), $media->getFileSystem() ) ) . '"
					src="' . $enc->attr( $view->content( $media->getUrl(), $media->getFileSystem() ) ) . '"
					alt="' . $enc->attr( $media->getProperties( 'title' )->first( $media->getName() ) ) . '"
					' . $variant . ' />
				</video>
			';
		}elseif(  !strncmp( $media->getMimetype(), 'model/', 6 )){
			return '
				<model-viewer class="item" id="image-' . $media->getId() . '" loading="lazy"
				thumbnail="' . $enc->attr( $view->content( $media->getPreview(), $media->getFileSystem() ) ) . '"
				poster="' . $enc->attr( $view->content( $media->getPreview( 600 ), $media->getFileSystem() ) ) . '"
				src="' . $enc->attr( $view->content( $media->getUrl(), $media->getFileSystem() ) ) . '"
				alt="' . $enc->attr( $media->getProperties( 'title' )->first( $media->getName() ) ) . '"
				' . $variant . ' ar auto-rotate camera-controls>
			</model-viewer>
		';
		}
But saving the gltf file in the database is empty

i am very sorry for disturbing and looking forward for a response thank you in advance
Attachments
db.png
db.png (7.35 KiB) Viewed 1187 times

User avatar
aimeos
Administrator
Posts: 7905
Joined: 01 Jan 1970, 00:00

Re: Adding Google Model Viewer in Products

Post by aimeos » 01 Nov 2022, 07:55

ARJIEANGELOG.VICUNA wrote: 01 Nov 2022, 02:07 I did try to insert the cdn with echo in the public header in the standard.php, because it is the only file in the catalog/detail:
You have to add the script file here:
https://github.com/aimeos/ai-client-htm ... hp#L77-L78
ARJIEANGELOG.VICUNA wrote: 01 Nov 2022, 02:07 But saving the gltf file in the database is empty
The gltf file is stored according to your screenshot but there's no preview image generated because this works only for images.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply