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!
Re: Hook into order completing process
OK, if you store the attribute with list type "hidden", it will be automatically added to the order as order product attribute.
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
Ok, good to know. Now the attribute is hidden, I can fetch it. Thanks!
Now I'm on the last step, storing the serial. I'm using this code to add it to the payment service:
Is this correct? I'm a bit confused, as you said "store the order base object again", which doesn't seem necessary with the above code. I tried adding the new serial attribute to the payment service and then storing the order base object, but it didn't store the new attribute.
Also, can I only add the attribute to the payment or delivery service, or can I create a custom new service?
Now I'm on the last step, storing the serial. I'm using this code to add it to the payment service:
Code: Select all
$basket = $this->getOrderBase($orderItem->getBaseId(), OrderItemBaseBase::PARTS_ALL);
$paymentServiceObject = $basket->getService(OrderItemService::TYPE_PAYMENT);
$serviceId = $paymentServiceObject[0]->getBaseId();
$newItem = \Aimeos\MShop::create($this->getContext(), 'order/base/service/attribute')->createItem();
$newItem->setParentId($serviceId)
->setType('payment/serial/brand')
->setCode('Brand Serial')
->setName('Brand Serial Name')
->setValue('Brand Serial Value')
->setQuantity(1);
\Aimeos\MShop::create($this->getContext(), 'order/base/service/attribute')->saveItem($newItem);
Also, can I only add the attribute to the payment or delivery service, or can I create a custom new service?
Re: Hook into order completing process
You should use reset() to get the first service item and check if there's really one with "reset() !== false". Also, you don't need to set the quantity explicitely and I suggest to use the delivery service instead of the payment service because it seems to be more related to delivery resp. ERP than payment.flomo wrote: ↑25 Jan 2020, 18:54Code: Select all
$basket = $this->getOrderBase($orderItem->getBaseId(), OrderItemBaseBase::PARTS_ALL); $paymentServiceObject = $basket->getService(OrderItemService::TYPE_PAYMENT); $serviceId = $paymentServiceObject[0]->getBaseId(); $newItem = \Aimeos\MShop::create($this->getContext(), 'order/base/service/attribute')->createItem(); $newItem->setParentId($serviceId) ->setType('payment/serial/brand') ->setCode('Brand Serial') ->setName('Brand Serial Name') ->setValue('Brand Serial Value') ->setQuantity(1); \Aimeos\MShop::create($this->getContext(), 'order/base/service/attribute')->saveItem($newItem);
You can use to simplify the code:
Code: Select all
$basket = $this->getOrderBase($orderItem->getBaseId());
$services = $basket->getService('delivery');
if(($serviceItem = reset($services)) !== false)
{
$this->setAttributes($serviceItem, ['Brand Serial' => 'Brand Serial Value'], 'payment/serial/brand');
$this->saveOrderBase($basket);
}
You can use existing services or create a new service type other than "delivery" or "payment".
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
Thanks a lot! It becomes so easy, once you get to know the processes and the classes. But it's a steep learning curve.