Service provider problem

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!
dala
Posts: 6
Joined: 08 Feb 2025, 23:17

Service provider problem

Post by dala » 31 May 2025, 13:49

I am testing out Aimeos and trying to write my own payment-provider extension.
I am looking following the documentation here https://aimeos.org/docs/2024.x/providers/service/ when trying to register some paymentdata, and I am copying the following code:

$orderServiceItem = $order->getService( 'payment' );
$orderServiceItem->addAttributeItems( $this->attributes( $attributes ), 'myprovider' );


However, $order->getService() returns an array of payment-services, so when calling $orderServiceItem->addAttributeItems, like it shows in the documentation, I get an exception since $orderServiceItem is an array and not an object.
Instead, I have to call $orderServiceItem[0]->addAttributeItems.

First, is there some error in the documentation or is there something I am missing?
Second, since $order->getService( 'payment' ) returns an array, I guess its possible to register multiple payment-servies on each order. How do I know which is the correct one?

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

Re: Service provider problem

Post by aimeos » 01 Jun 2025, 07:21

This is an error in the docs and you should use current() or reset() to get the first order service item in the array if you are sure there's only one. We will fix that in the docs, thanks for the hint!
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply