Created
March 21, 2017 09:07
-
-
Save flocondetoile/8fe76d7e6777323f5b94f161b48f1ec0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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