Commit 6729bb3f authored by Bojan Živanović's avatar Bojan Živanović
Browse files

Issue #2788795 by bojanz: Add a getter for the order total

parent 375266d1
Loading
Loading
Loading
Loading
+7
Changes for modules/order/src/Entity/Order.php: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -305,6 +305,13 @@ class Order extends ContentEntityBase implements OrderInterface {
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getTotalPrice() {
    return $this->get('total_price')->first()->toPrice();
  }

  /**
   * {@inheritdoc}
   */
+8
Changes for modules/order/src/Entity/OrderInterface.php: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -161,6 +161,14 @@ interface OrderInterface extends AdjustableInterface, ContentEntityInterface, En
   */
  public function hasLineItem(LineItemInterface $line_item);

  /**
   * Gets the total price.
   *
   * @return \Drupal\commerce_price\Price
   *   The total price.
   */
  public function getTotalPrice();

  /**
   * Gets the order state.
   *
+2 −4
Changes for modules/payment/src/PluginForm/PaymentAddForm.php: 2 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -17,14 +17,12 @@ class PaymentAddForm extends PaymentGatewayFormBase {
    if (!$order) {
      throw new \InvalidArgumentException('Payment entity with no order reference given to PaymentAddForm.');
    }
    // @todo The order needs a getter for total_price.
    // @todo Implement a balance method (unpaid portion of the total).
    $order_total = $order->get('total_price')->first()->toPrice();

    // @todo Implement a balance method (unpaid portion of the total).
    $form['amount'] = [
      '#type' => 'commerce_price',
      '#title' => t('Amount'),
      '#default_value' => $order_total,
      '#default_value' => $order->getTotalPrice(),
      '#required' => TRUE,
    ];
    $form['transaction_type'] = [