How do I get the service attributes in the addService.before event in the basket plugin?

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!
kdim95
Advanced
Posts: 205
Joined: 26 Aug 2022, 12:17

How do I get the service attributes in the addService.before event in the basket plugin?

Post by kdim95 » 21 Sep 2023, 10:54

Laravel framework version: 10.16.1
Aimeos Laravel version: 2023.04.*
PHP Version: 8.2.8
Environment: Linux

I'm trying to get the service attributes when updating a service through jsonapi, but the attributes are not available in the service item here.

Code: Select all

    /**
     * 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, $value = null )
    {
		$context = $this->context();
		$basketIface = \Aimeos\MShop\Order\Item\Iface::class;
		$serviceIface = \Aimeos\MShop\Order\Item\Service\Iface::class;

		// Check if basket is of required type
		if( ! $basket instanceof $basketIface ) {
			$msg = sprintf( 'Object is not of required type "%1$s"', $basketIface );
			throw new \Aimeos\MShop\Plugin\Provider\Exception( $msg );
		}
		
		// Check if value is of required type
		if( ! $value instanceof $serviceIface ) {
			$msg = sprintf( 'Object is not of required type "%1$s"', $serviceIface );
			throw new \Aimeos\MShop\Plugin\Provider\Exception( $msg );
		}

		// dump service item, attributes items are missing
		dd( $value );

		return $value;
    }

kdim95
Advanced
Posts: 205
Joined: 26 Aug 2022, 12:17

Re: How do I get the service attributes in the addService.before event in the basket plugin?

Post by kdim95 » 25 Sep 2023, 12:18

Hello, I got the service attributes.
They were missing, because they weren't being passed in the parameters when updating the service.

Post Reply