overwrite base class

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
User avatar
VirtualSpy
Advanced
Posts: 122
Joined: 05 Jul 2022, 07:55

overwrite base class

Post by VirtualSpy » 13 Dec 2022, 09:41

laravel version 9.36.4 , Aimeos version 2022.10.3 and PHP version 8.1.3 (Win)

can i overwrite

Code: Select all

vendor\aimeos\aimeos-core\src\MShop\Common\Manager\Base.php
this file from extension without this

Code: Select all

Warning: Ambiguous class resolution, "Aimeos\MShop\Common\Manager\Base" was found 2x: in "D:/laragon/www/myshop/vendor/aimeos-extensions/extcliqnshop/src/MShop/Common/Manager/Base.php" and "D:\laragon\www\myshop\vendor/aimeos/aimeos-core/src\MShop\Common\Manager\Base.php", the first will be used.
because i want to remove 404 and variables from sprintf and pass my message in it from this

Code: Select all

 */
	protected function getItemBase( string $key, string $id, array $ref, ?bool $default ) : \Aimeos\MShop\Common\Item\Iface
	{
		$criteria = $this->object()->filter( $default )->add( [$key => $id] )->slice( 0, 1 );

		if( ( $item = $this->object()->search( $criteria, $ref )->first() ) ) {
			return $item;
		}

		$msg = $this->context()->translate( 'mshop', 'Item with ID "%2$s" in "%1$s" not found' );
		throw new \Aimeos\MShop\Exception( sprintf( $msg, $key, $id ), 404 );
	}
Last edited by VirtualSpy on 13 Dec 2022, 10:09, edited 1 time in total.

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

Re: overwrite base calss

Post by aimeos » 13 Dec 2022, 09:48

In PHP it's not possible to overwrite base classes but you can overwrite the translation and use another message string:
https://aimeos.org/docs/latest/laravel/ ... anslations
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
VirtualSpy
Advanced
Posts: 122
Joined: 05 Jul 2022, 07:55

Re: overwrite base calss

Post by VirtualSpy » 13 Dec 2022, 10:06

aimeos wrote: 13 Dec 2022, 09:48 In PHP it's not possible to overwrite base classes but you can overwrite the translation and use another message string:
https://aimeos.org/docs/latest/laravel/ ... anslations
but i want to change or remove 404 code from Exception.....please tell me how can i change

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

Re: overwrite base class

Post by aimeos » 14 Dec 2022, 07:17

You can replace the Exception decorator for the HTML client with your own implementation and handle 404 error code differently:
https://github.com/aimeos/ai-client-htm ... ptions.php
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply