You are here

class OrderItemOrderTotal in Commerce add to cart confirmation 1.x

Defines an order total area handler.

Shows the order total field with its components listed in the footer of a View.

Plugin annotation

@ViewsArea("commerce_add_to_cart_confirmation_order_item_order_total");

Hierarchy

  • class \Drupal\commerce_add_to_cart_confirmation\Plugin\views\area\OrderItemOrderTotal extends \Drupal\commerce_order\Plugin\views\area\OrderTotal

Expanded class hierarchy of OrderItemOrderTotal

File

src/Plugin/views/area/OrderItemOrderTotal.php, line 19

Namespace

Drupal\commerce_add_to_cart_confirmation\Plugin\views\area
View source
class OrderItemOrderTotal extends OrderTotal {

  /**
   * The order item storage.
   *
   * @var \Drupal\Core\Entity\Sql\SqlContentEntityStorage
   */
  protected $orderItemStorage;

  /**
   * Constructs a new OrderTotal instance.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
    parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager);
    $this->orderItemStorage = $entity_type_manager
      ->getStorage('commerce_order_item');
  }

  /**
   * {@inheritdoc}
   */
  public function render($empty = FALSE) {
    if (!$empty || !empty($this->options['empty'])) {
      foreach ($this->view->argument as $argument) {

        // First look for an order_id argument.
        if (!$argument instanceof NumericArgument) {
          continue;
        }
        if ($argument
          ->getField() !== 'commerce_order_item.order_item_id') {
          continue;
        }

        /** @var \Drupal\commerce_order\Entity\OrderItemInterface $order_item */
        $order_item = $this->orderItemStorage
          ->load($argument
          ->getValue());
        if (!$order_item) {
          continue;
        }
        if ($order = $order_item
          ->getOrder()) {
          return $order
            ->get('total_price')
            ->view([
            'label' => 'inline',
          ]);
        }
      }
    }
    return [];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
OrderItemOrderTotal::$orderItemStorage protected property The order item storage.
OrderItemOrderTotal::render public function
OrderItemOrderTotal::__construct public function Constructs a new OrderTotal instance.