1

The default behaviour for commerce is to mark the isCompleted flag on an order to true once the order has been paid for.

I have need to alter this behaviour and only want to mark an order as Complete via manual intervention of a site admin - or after a predefined date has passed.

Is it possible to set the isCompleted flag from within a custom module? Right now, I'm listening to the EVENT_AFTER_ORDER_PAID then attempting to set the isCompleted flag and save the order.

What I can't figure out is how to save the order!

Code so far, for what it's worth:

Event::on(
            Order::class, 
            Order::EVENT_AFTER_ORDER_PAID, 
            function(Event $e) {
                $order = $e->sender;

                $order->isCompleted = false; // no idea if this is correct

                $order->saveOrder(); // this doesn't work
            }
        );
1

This can be achieved with

Event::on(
            Order::class, 
            Order::EVENT_AFTER_COMPLETE_ORDER, 
            function(Event $e) {

                $order = $e->sender;

                $order->isCompleted = false;
                Craft::$app->getElements()->saveElement($order, false);

            }
        );

But I'm not sure it's actually a good idea anyway.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.