0

I need to change order status to custom status if payment fails.

I tried to get order via $payment->getOrder(), and tried to set state and status. I called save() also. However It looks like not working. It is always saving order with 'processing' status. However, It saves comments when I run following functions using same method; addStatusToHistory, addStatusHistoryComment. Any idea how can I implement this?

class Payment extends \Magento\Payment\Model\Method\Cc {
...
fn(){
$payment->getOrder()->setState( 'holded' )->setStatus( 'custom_new_status' )->save();

Thank you.

0

Try below code

        $state = 'holded';
        $status = 'custom_new_status';
        $comment = '';
        $order->setState($state);
        $order->setStatus($status);
        $order->addStatusToHistory($order->getStatus(), $comment);
        $order->save();

Reference

| improve this answer | |
  • Hi, thanks for quick answer. I already tried, but It didn't work. – Mohamed Jul 10 '17 at 15:37
  • You can Use Event and Observer concept.Once payment has been completed observer can be called where you can set the order custom status @MmtBkn – Learing_Coder Jul 11 '17 at 4:19
  • Thanks @PranayK, I'm aware of it but thought should be easier way to do it. – Mohamed Jul 11 '17 at 16:40
  • @MmtBkn you should check your order object first. – Qaisar Satti Jul 11 '17 at 16:43
  • @QaisarSatti there is order object. I can add comment to history, however something is overriding and changing status to processing – Mohamed Jul 11 '17 at 16:45

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.