Hook into order completing process

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!
User avatar
aimeos
Administrator
Posts: 7893
Joined: 01 Jan 1970, 00:00

Re: Hook into order completing process

Post by aimeos » 25 Jan 2020, 17:59

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, Image give us a star

flomo
Posts: 52
Joined: 26 Sep 2019, 15:11

Re: Hook into order completing process

Post by flomo » 25 Jan 2020, 18:54

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:

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);
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?

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

Re: Hook into order completing process

Post by aimeos » 26 Jan 2020, 09:49

flomo wrote: 25 Jan 2020, 18:54

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);
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:54 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.
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);
}
flomo wrote: 25 Jan 2020, 18:54 Also, can I only add the attribute to the payment or delivery service, or can I create a custom new service?
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, Image give us a star

flomo
Posts: 52
Joined: 26 Sep 2019, 15:11

Re: Hook into order completing process

Post by flomo » 27 Jan 2020, 10:57

Thanks a lot! It becomes so easy, once you get to know the processes and the classes. But it's a steep learning curve.

Post Reply