Hook into order completing process
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!
Hook into order completing process
As soon as an order has been paid, I need to make an API call to fetch a serial number, store the serial with the order and send it to the customer with the payment email.
I'm a bit lost:
1. Where can I hook into the order complete process to start my API calls (the order must be fully paid at this moment)?
2. Where would I store the serial to, so the user can view it in his account?
Ideally this should happen before the confirmation is sent to the customer, to include the serial in the email.
I'm a bit lost:
1. Where can I hook into the order complete process to start my API calls (the order must be fully paid at this moment)?
2. Where would I store the serial to, so the user can view it in his account?
Ideally this should happen before the confirmation is sent to the customer, to include the serial in the email.
Re: Hook into order completing process
The best way is to create a decorator for the payment service provider:
- https://aimeos.org/docs/Developers/Libr ... _decorator
- https://aimeos.org/docs/Developers/Library/Service
Then, in your decorator:
- add the updateSync() (called after redirecting the customer to the confirmation page) method
- add updatePush() (called by the payment server in an asynchon way if the payment status changes) methods
- check if the payment status is what you need (authorized or received)
- fetch the order base object (basket) with the services (payment and delivery)
- check if the serial number is already set as order service attribute
- make your API calls
- store the serial number as order service attribute
- store the order base object again
There are helper/support methods for almost everything documented. The rest (serial number is shown to the customers in their accounts and in their e-mails) is done automatically as long as you don't use a order service attribute type "hidden".
- https://aimeos.org/docs/Developers/Libr ... _decorator
- https://aimeos.org/docs/Developers/Library/Service
Then, in your decorator:
- add the updateSync() (called after redirecting the customer to the confirmation page) method
- add updatePush() (called by the payment server in an asynchon way if the payment status changes) methods
- check if the payment status is what you need (authorized or received)
- fetch the order base object (basket) with the services (payment and delivery)
- check if the serial number is already set as order service attribute
- make your API calls
- store the serial number as order service attribute
- store the order base object again
There are helper/support methods for almost everything documented. The rest (serial number is shown to the customers in their accounts and in their e-mails) is done automatically as long as you don't use a order service attribute type "hidden".
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: Hook into order completing process
Thank you very much! Will dive into this this week.
Re: Hook into order completing process
How would I get the basket/products? I was able to fetch the basket, but the products are always empty:
Code: Select all
public function updateSync(\Psr\Http\Message\ServerRequestInterface $request, \Aimeos\MShop\Order\Item\Iface $orderItem)
{
$update = $this->getProvider()->updateSync($request, $orderItem);
// Returns []
dump($this->getProvider()->getOrderBase($orderItem->getBaseId())->getProducts());
// Returns []
dump($this->getOrderBase($orderItem->getBaseId())->getProducts());
return $update;
}
Re: Hook into order completing process
Nevermind. I just found out, that accepts a second parameter that defines, which part of the order to load: https://aimeos.org/api/latest/class-Aim ... .Base.html
Using or (defined here https://aimeos.org/api/latest/class-Aim ... .Base.html) solves the problem.
Code: Select all
\Aimeos\MShop\Service\Provider\Base::getOrderBase()
Using
Code: Select all
\Aimeos\MShop\Order\Item\Base\Base::PARTS_ALL
Code: Select all
\Aimeos\MShop\Order\Item\Base\Base::PARTS_PRODUCT
Re: Hook into order completing process
Still having problems. I now have the Aimeos\MShop\Order\Item\Base\Product\Standard objects from the order, but the supplier ( getSupplierCode() ) and attributes ( getAttribute(), the function getAttributes() is even not available) are empty. How can I access this data?
Re: Hook into order completing process
The supplier code is only added if it's passed when adding it to the basket. This isn't done by default because there can be several suppliers for one product.
These are the methods available for retrieving attributes of an order product item:
https://github.com/aimeos/aimeos-core/b ... #L289-L313
These are the methods available for retrieving attributes of an order product item:
https://github.com/aimeos/aimeos-core/b ... #L289-L313
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: Hook into order completing process
I tried those methods, but getAttributeItem() returns null, and getAttributeItems() an empty array [] with this code:
I had to use this code, to get the attribute value:
Is that ok this way?
Code: Select all
$basket = $this->getOrderBase($orderItem->getBaseId(), OrderItemBaseBase::PARTS_ALL);
$products = $basket->getProducts();
foreach($products as $product) {
$product->getAttributeItems());
// []
}
Code: Select all
$basket = $this->getOrderBase($orderItem->getBaseId(), OrderItemBaseBase::PARTS_ALL);
$products = $basket->getProducts();
$baseManager = \Aimeos\MShop::create($this->getContext(), 'product');
foreach ($products as $product) {
$item = $baseManager->getItem($product->getProductId(), ['attribute']);
$serialApi = $item->getRefItems('attribute', 'serialapi');
if (!empty($serialApi)) {
$serialApiValue = reset($serialApi)->getCode();
}
}
Re: Hook into order completing process
No, you didn't store the serial ID as order product attribute but as regular product referencing a regular attribute instead! That way, your serial ID is shared for all orders and if there will be two orders at the same time, they will both retrieve the same serial ID.
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: Hook into order completing process
The code in my previous post ist not about the serial yet. I store an API reference called "serialapi" (each product might get its serial from another API, depending on the brand) with each product. After payment I have to retrieve this reference to know, which API I have to contact.
So I think the idea is correct, I'm just not sure if my complicated code is correct (because $product->getAttributeItems() returns an empty array).
So I think the idea is correct, I'm just not sure if my complicated code is correct (because $product->getAttributeItems() returns an empty array).