Error when addService.before is attached
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!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Error when addService.before is attached
Laravel framework version: 10.16.1
Aimeos Laravel version: 2023.04.*
PHP Version: 8.2.8
Environment: Linux
Hello,
I get the following exception when adding a service using the jsonapi:
exception: Error
file: /var/www/vhosts/<domain>/httpdocs/vendor/aimeos/aimeos-core/src/MShop/Order/Item/Base.php
line: 655
message: Call to a member function getPrice() on bool
I'm not even doing anything when the addService.before event occurs.
This is the structure of my plugin:
This is the request:
Request URL - https://<domain>/jsonapi/basket?id=default&related=service&relatedid=delivery&_token=<token>
Payload:
Aimeos Laravel version: 2023.04.*
PHP Version: 8.2.8
Environment: Linux
Hello,
I get the following exception when adding a service using the jsonapi:
exception: Error
file: /var/www/vhosts/<domain>/httpdocs/vendor/aimeos/aimeos-core/src/MShop/Order/Item/Base.php
line: 655
message: Call to a member function getPrice() on bool
I'm not even doing anything when the addService.before event occurs.
This is the structure of my plugin:
Code: Select all
<?php
namespace Aimeos\MShop\Plugin\Provider\Order;
use Illuminate\Support\Facades\Http;
class MyPlugin
extends \Aimeos\MShop\Plugin\Provider\Factory\Base
implements \Aimeos\MShop\Plugin\Provider\Iface, \Aimeos\MShop\Plugin\Provider\Factory\Iface
{
private $singleton;
/**
* Register plugin at publisher object
*/
public function register( \Aimeos\MW\Observer\Publisher\Iface $publisher ) : \Aimeos\MW\Observer\Listener\Iface
{
$plugin = $this->object();
$publisher->attach( $plugin, 'addService.before' );
return $this;
}
public function update( \Aimeos\MW\Observer\Publisher\Iface $basket, $event, $service = null )
{
return true;
}
}
Request URL - https://<domain>/jsonapi/basket?id=default&related=service&relatedid=delivery&_token=<token>
Payload:
Code: Select all
id: default
related: service
relatedid: delivery
_token: <token>
form data: {"data":[{"id":"service","attributes":{"service.id":"2"}}]}:
Re: Error when addService.before is attached
Seems like you service has no price and the plugin is not responsible for the exception:
https://github.com/aimeos/aimeos-core/b ... 23-L655C30
https://github.com/aimeos/aimeos-core/b ... 23-L655C30
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
Re: Error when addService.before is attached
I've checked all of the services in the admin, they all have a price set.
I solved it, but I think that the documentation needs improvement, it doesn't specify this.
This is the line that causes the error.
$service = $this->notify( 'addService.before', $service );
The update() method of the plugin must return the service item, instead of "true", that's what causes the error "getPrice() on bool", because update() returned "true" instead of returning the service item.
I solved it, but I think that the documentation needs improvement, it doesn't specify this.
This is the line that causes the error.
$service = $this->notify( 'addService.before', $service );
The update() method of the plugin must return the service item, instead of "true", that's what causes the error "getPrice() on bool", because update() returned "true" instead of returning the service item.
Re: Error when addService.before is attached
This documentation needs more updating:
https://aimeos.org/docs/2023.x/provider ... ate-plugin
Please look at the notification names here:
Aimeos\MShop\Order\Item\Base
Some notifications specified in the documentation do not exist, or are wrong.
For example "setService.before" and "setService.after", I think they should be "addService.before" and "addService.after".
https://aimeos.org/docs/2023.x/provider ... ate-plugin
Please look at the notification names here:
Aimeos\MShop\Order\Item\Base
Some notifications specified in the documentation do not exist, or are wrong.
For example "setService.before" and "setService.after", I think they should be "addService.before" and "addService.after".
Re: Error when addService.before is attached
You are right and the articles has been updated now
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star