0

I am trying to update order status and payment status depending upon the value we get in a variable called $payment_status. I am able to update order status but I am unable to update payment status inside that order. I am getting an error "The website encountered an unexpected error. Please try again later. Error: Class 'Drupal\commerce_order\Payment\Payment' not found" The code I used is as follows:-

//update order status based on payment status
  $order = \Drupal\commerce_order\Entity\Order::load($order_id);
  // dpm($order);
  if($payment_status === 'payment.captured' ){
    $order->set('state', 'completed' );
    $order->save();
    $payments = \Drupal\commerce_order\Payment\Payment::loadByProperties(['order_id' => $order_id]);
      foreach ($payments as $payment)
      {
        $payment->setState('completed')->save();
      }
  }
  else{
    $order->set('state', 'pending' );
    $order->save();
  }

How to solve this?

1
  • 1
    I guess you could do it \Drupal::entityTypeManager() ->getStorage('commerce_payment') ->loadByProperties([ 'order_id' => [$orderid], ]); Commented Aug 9, 2018 at 5:16

2 Answers 2

2

Please change the code from

 \Drupal\commerce_order\Payment\Payment::loadByProperties(['order_id' => $order_id]);    
        TO        
 \Drupal::entityTypeManager() ->getStorage('commerce_payment') ->loadByProperties([ 'order_id' => [$orderid], ]);
0
0

It should be like below:

$payments = \Drupal::entityTypeManager()->getStorage('commerce_payment')->loadByProperties(['order_id' => $order_idS]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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