Skip to content

Instantly share code, notes, and snippets.

@flocondetoile
Created March 21, 2017 09:07
Show Gist options
  • Save flocondetoile/8fe76d7e6777323f5b94f161b48f1ec0 to your computer and use it in GitHub Desktop.
Save flocondetoile/8fe76d7e6777323f5b94f161b48f1ec0 to your computer and use it in GitHub Desktop.
// inside an event subscriber of `OrderEvents::ORDER_UPDATE` (edited)
if ($order->getState()->value == 'completed' && $order_total = $order->getTotalPrice()) {
$original_order = $order->original;
if ($original_order && $order->getState()->value == 'draft') {
/** @var \Drupal\commerce_payment\PaymentStorageInterface $payment_storage */
$payment_storage = \Drupal::entityTypeManager()->getStorage('commerce_payment');
$payments = $payment_storage->loadMultipleForOrder($order);
if ($payments) {
$payments_total= new Price(0, $order_total->getCurrencyCode());
foreach ($payments as $payment) {
$payments_total = $payments_total->add($payment->getAmount());
}
if ($order_total->equals($payments_total)) {
// do stuff
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment