How to override Aimeos\Controller\Common\Media add() function.

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
AnujMagar
Posts: 1
Joined: 19 Jun 2023, 16:19

How to override Aimeos\Controller\Common\Media add() function.

Post by AnujMagar » 19 Jun 2023, 18:05

Hi,

I'm on using Laravel 9, Aimeos 2022.x and PHP 8.1 on linux

I need to customize the behavior of the add() function in the Aimeos\Controller\Common\Media class using extension. However, I'm unsure about the correct approach to override this function.

Specifically, I want to extend the functionality of the add() method in order to perform blurhash of $file when adding a new media item.

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

Re: How to override Aimeos\Controller\Common\Media add() function.

Post by aimeos » 21 Jun 2023, 14:27

You can create your own common media controller class with a new name (e.g. "Mymedia") and extend from the "Standard" class:

Code: Select all

<?php
namespace Aimeos\Controller\Common\Media;

class Mymedia extends Standard
{
	public function add( \Aimeos\MShop\Media\Item\Iface $item, \Psr\Http\Message\UploadedFileInterface $file ) : \Aimeos\MShop\Media\Item\Iface
	{
		// own implementation
	}
}
Then, configure the new class to be used:

Code: Select all

controller/common/media/name = Mymedia
How to add configuration depends on the use framework. For Laravel it's in ./config/shop.php:

Code: Select all

'controller' => [
	'common' => [
		'media' => [
			'name' => 'Mymedia'
		]
	]
]
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply