You are here

class OrderViewsData in Ubercart 8.4

Provides the views data for the uc_order entity type.

Hierarchy

Expanded class hierarchy of OrderViewsData

File

uc_order/src/OrderViewsData.php, line 10

Namespace

Drupal\uc_order
View source
class OrderViewsData extends EntityViewsData {

  /**
   * {@inheritdoc}
   */
  public function getViewsData() {
    $data = parent::getViewsData();
    $data['uc_orders']['order_status']['filter']['id'] = 'uc_order_status';
    $data['uc_orders']['uid']['help'] = $this
      ->t('The user ID that the order belongs to.');
    $data['uc_orders']['uid']['filter']['id'] = 'user_name';
    $data['uc_orders']['uid']['relationship']['title'] = $this
      ->t('Customer');
    $data['uc_orders']['uid']['relationship']['help'] = $this
      ->t('Relate an order to the user who placed it.');
    $data['uc_orders']['uid']['relationship']['label'] = $this
      ->t('customer');
    $data['uc_orders']['order_total']['field']['id'] = 'uc_price';
    $data['uc_orders']['actions'] = [
      'title' => $this
        ->t('Actions'),
      'help' => $this
        ->t('Clickable links to actions a user may perform on an order.'),
      'field' => [
        'id' => 'uc_order_actions',
        'real field' => 'order_id',
        'click sortable' => FALSE,
      ],
    ];
    $data['uc_orders']['billing_country']['filter']['id'] = 'in_operator';
    $data['uc_orders']['billing_country']['filter']['options callback'] = 'Drupal\\uc_country\\Controller\\CountryController::countryOptionsCallback';
    $data['uc_orders']['delivery_country']['filter']['id'] = 'in_operator';
    $data['uc_orders']['delivery_country']['filter']['options callback'] = 'Drupal\\uc_country\\Controller\\CountryController::countryOptionsCallback';
    $data['uc_orders']['billing_country_name'] = [
      'title' => $this
        ->t('Billing country name'),
      'help' => $this
        ->t('The country name where the bill will be sent.'),
      'field' => [
        'id' => 'uc_country',
        'real field' => 'billing_country',
      ],
    ];
    $data['uc_orders']['delivery_country_name'] = [
      'title' => $this
        ->t('Delivery country name'),
      'help' => $this
        ->t('The country name of the delivery location.'),
      'field' => [
        'id' => 'uc_country',
        'real field' => 'delivery_country',
      ],
    ];
    $data['uc_orders']['billing_zone']['filter']['id'] = 'in_operator';
    $data['uc_orders']['billing_zone']['filter']['options callback'] = 'Drupal\\uc_country\\Controller\\CountryController::zoneOptionsCallback';
    $data['uc_orders']['delivery_zone']['filter']['id'] = 'in_operator';
    $data['uc_orders']['delivery_zone']['filter']['options callback'] = 'Drupal\\uc_country\\Controller\\CountryController::zoneOptionsCallback';
    $data['uc_orders']['billing_zone_name'] = [
      'title' => $this
        ->t('Billing state/province name'),
      'help' => $this
        ->t('The state/zone/province ID where the bill will be sent.'),
      'field' => [
        'id' => 'uc_zone',
        'real field' => 'billing_zone',
        'additional fields' => [
          'country' => [
            'field' => 'billing_country',
          ],
        ],
      ],
    ];
    $data['uc_orders']['delivery_zone_name'] = [
      'title' => $this
        ->t('Delivery state/province name'),
      'help' => $this
        ->t('The state/zone/province ID of the delivery location.'),
      'field' => [
        'id' => 'uc_zone',
        'real field' => 'delivery_zone',
        'additional fields' => [
          'country' => [
            'field' => 'delivery_country',
          ],
        ],
      ],
    ];
    $data['uc_orders']['billing_full_name'] = [
      'title' => $this
        ->t('Billing full name'),
      'help' => $this
        ->t('The full name of the person paying for the order.'),
      'field' => [
        'id' => 'uc_order_full_name',
        'real field' => 'billing_first_name',
        'additional fields' => [
          'last_name' => [
            'field' => 'billing_last_name',
          ],
        ],
      ],
    ];
    $data['uc_orders']['delivery_full_name'] = [
      'title' => $this
        ->t('Delivery full name'),
      'help' => $this
        ->t('The full name of the person receiving shipment.'),
      'field' => [
        'id' => 'uc_order_full_name',
        'real field' => 'delivery_first_name',
        'additional fields' => [
          'last_name' => [
            'field' => 'delivery_last_name',
          ],
        ],
      ],
    ];
    $data['uc_orders']['total_weight'] = [
      'title' => $this
        ->t('Total weight'),
      'help' => $this
        ->t('The physical weight of all the products (weight * quantity) in the order.'),
      'real field' => 'weight',
      'field' => [
        'handler' => 'uc_order_handler_field_order_weight_total',
        'additional fields' => [
          'order_id' => 'order_id',
        ],
      ],
    ];

    // Expose the uid as a relationship to users.
    $data['users_field_data']['uc_orders'] = [
      'title' => $this
        ->t('Orders'),
      'help' => $this
        ->t('Relate a user to the orders they have placed. This relationship will create one record for each order placed by the user.'),
      'relationship' => [
        'title' => $this
          ->t('Order'),
        'label' => $this
          ->t('Order'),
        'base' => 'uc_orders',
        'base field' => 'uid',
        'relationship field' => 'uid',
        'id' => 'standard',
      ],
    ];

    // Ordered products.
    // Get the standard EntityAPI Views data table.
    // $data['uc_order_products'] =  entity_views_table_definition('uc_order_product');
    // // Remove undesirable fields
    // foreach (['data'] as $bad_field) {
    //   if (isset($data['uc_order_products'][$bad_field])) {
    //     unset($data['uc_order_products'][$bad_field]);
    //   }
    // }
    // // Fix incomplete fields.
    // $data['uc_order_products']['weight_units']['title'] = $this->t('Weight units');
    $data['uc_order_products']['table']['group'] = $this
      ->t('Ordered product');
    $data['uc_order_products']['table']['base'] = [
      'field' => 'order_product_id',
      'title' => $this
        ->t('Ordered products'),
      'help' => $this
        ->t('Products that have been ordered in your Ubercart store.'),
    ];

    // Expose products to their orders as a relationship.
    $data['uc_orders']['products'] = [
      'relationship' => [
        'title' => $this
          ->t('Products'),
        'help' => $this
          ->t('Relate products to an order. This relationship will create one record for each product ordered.'),
        'id' => 'standard',
        'base' => 'uc_order_products',
        'base field' => 'order_id',
        'relationship field' => 'order_id',
        'label' => $this
          ->t('products'),
      ],
    ];

    // Expose nodes to ordered products as a relationship.
    $data['uc_order_products']['nid'] = [
      'title' => $this
        ->t('Nid'),
      'help' => $this
        ->t('The nid of the ordered product. If you need more fields than the nid: Node relationship'),
      'relationship' => [
        'title' => $this
          ->t('Node'),
        'help' => $this
          ->t('Relate product to node.'),
        'id' => 'standard',
        'base' => 'node',
        'field' => 'nid',
        'label' => $this
          ->t('node'),
      ],
      'filter' => [
        'id' => 'numeric',
      ],
      'argument' => [
        'id' => 'node_nid',
      ],
      'field' => [
        'id' => 'node',
      ],
    ];

    // Expose orders to ordered products as a relationship.
    $data['uc_order_products']['order_id'] = [
      'title' => $this
        ->t('Order ID'),
      'help' => $this
        ->t('The order ID of the ordered product. If you need more fields than the order ID: Order relationship'),
      'relationship' => [
        'title' => $this
          ->t('Order'),
        'help' => $this
          ->t('Relate product to order.'),
        'id' => 'standard',
        'base' => 'uc_orders',
        'field' => 'order_id',
        'label' => $this
          ->t('order'),
      ],
      'filter' => [
        'id' => 'numeric',
      ],
      'argument' => [
        'id' => 'numeric',
      ],
      'field' => [
        'id' => 'uc_order',
      ],
    ];
    $data['uc_order_products']['model'] = [
      'title' => $this
        ->t('SKU'),
      'help' => $this
        ->t('The product model/SKU.'),
      'field' => [
        'id' => 'standard',
        'click sortable' => TRUE,
      ],
      'sort' => [
        'id' => 'standard',
      ],
      'filter' => [
        'id' => 'string',
      ],
      'argument' => [
        'id' => 'string',
      ],
    ];
    $data['uc_order_products']['qty'] = [
      'title' => $this
        ->t('Quantity'),
      'help' => $this
        ->t('The quantity ordered.'),
      'field' => [
        'id' => 'standard',
        'click sortable' => TRUE,
      ],
      'sort' => [
        'id' => 'standard',
      ],
      'filter' => [
        'id' => 'numeric',
      ],
    ];
    $data['uc_order_products']['price'] = [
      'title' => $this
        ->t('Price'),
      'help' => $this
        ->t('The price paid for one product.'),
      'field' => [
        'id' => 'uc_price',
        'click sortable' => TRUE,
      ],
      'sort' => [
        'id' => 'standard',
      ],
      'filter' => [
        'id' => 'numeric',
      ],
    ];
    $data['uc_order_products']['total_price'] = [
      'title' => $this
        ->t('Total price'),
      'help' => $this
        ->t('The price paid for all the products (price * quantity).'),
      'real field' => 'price',
      'field' => [
        'handler' => 'uc_order_handler_field_money_total',
        'click sortable' => TRUE,
      ],
      'sort' => [
        'handler' => 'uc_order_handler_sort_total',
      ],
      'filter' => [
        'handler' => 'uc_order_handler_filter_total',
      ],
    ];
    $data['uc_order_products']['cost'] = [
      'title' => $this
        ->t('Cost'),
      'help' => $this
        ->t('The cost to the store for one product.'),
      'field' => [
        'id' => 'uc_price',
        'click sortable' => TRUE,
      ],
      'sort' => [
        'id' => 'standard',
      ],
      'filter' => [
        'id' => 'numeric',
      ],
    ];
    $data['uc_order_products']['total_cost'] = [
      'title' => $this
        ->t('Total cost'),
      'help' => $this
        ->t('The cost to the store for all the products (cost * quantity).'),
      'real field' => 'cost',
      'field' => [
        'handler' => 'uc_order_handler_field_money_total',
        'click sortable' => TRUE,
      ],
      'sort' => [
        'handler' => 'uc_order_handler_sort_total',
      ],
      'filter' => [
        'handler' => 'uc_order_handler_filter_total',
      ],
    ];
    $data['uc_order_products']['weight'] = [
      'title' => $this
        ->t('Weight'),
      'help' => $this
        ->t('The physical weight of one product.'),
      'field' => [
        'additional fields' => [
          'weight_units' => [
            'field' => 'weight_units',
          ],
        ],
        'id' => 'uc_weight',
      ],
    ];
    $data['uc_order_products']['total_weight'] = [
      'title' => $this
        ->t('Total weight'),
      'help' => $this
        ->t('The physical weight of all the products (weight * quantity).'),
      'real field' => 'weight',
      'field' => [
        'additional fields' => [
          'weight_units' => [
            'field' => 'weight_units',
          ],
        ],
        'handler' => 'uc_order_handler_field_weight_total',
      ],
    ];
    $data['uc_order_products']['title'] = [
      'title' => $this
        ->t('Title'),
      'help' => $this
        ->t('The title of the product.'),
      'field' => [
        'id' => 'standard',
        'click sortable' => TRUE,
      ],
      'sort' => [
        'id' => 'standard',
      ],
      'filter' => [
        'id' => 'string',
      ],
      'argument' => [
        'id' => 'string',
      ],
    ];

    // Order comments table.
    // @todo Refactor this into a groupwise max relationship.
    $data['uc_order_comments']['table']['group'] = $this
      ->t('Order comments');
    $data['uc_order_comments']['table']['join'] = [
      'uc_orders' => [
        'left_field' => 'order_id',
        'field' => 'order_id',
      ],
      'uc_order_products' => [
        'left_table' => 'uc_orders',
        'left_field' => 'order_id',
        'field' => 'order_id',
      ],
    ];
    $data['uc_order_comments']['message'] = [
      'title' => $this
        ->t('Comment'),
      'help' => $this
        ->t('The comment body.'),
      'field' => [
        'id' => 'standard',
        'click sortable' => TRUE,
      ],
    ];

    // Support for any module's line item, if new modules defines other line
    // items the views cache will have to be rebuilt.
    // Although new line items views support should be defined on each module,
    // I don't think this wider apporach would harm. At most, it will duplicate
    // line items.
    $line_items = [];
    $definitions = \Drupal::service('plugin.manager.uc_order.line_item')
      ->getDefinitions();
    foreach ($definitions as $line_item) {
      if (!in_array($line_item['id'], [
        'subtotal',
        'tax_subtotal',
        'total',
        'generic',
      ]) && $line_item['stored']) {
        $line_items[$line_item['id']] = $line_item['title'];
      }
    }
    foreach ($line_items as $line_item_id => $line_item_desc) {
      $data['uc_order_line_items_' . $line_item_id]['table']['join']['uc_orders'] = [
        'table' => 'uc_order_line_items',
        'left_field' => 'order_id',
        'field' => 'order_id',
        'extra' => [
          [
            'field' => 'type',
            'value' => $line_item_id,
          ],
        ],
      ];
      $data['uc_order_line_items_' . $line_item_id]['table']['join']['uc_order_products'] = $data['uc_order_line_items_' . $line_item_id]['table']['join']['uc_orders'];
      $data['uc_order_line_items_' . $line_item_id]['table']['join']['uc_order_products']['left_table'] = 'uc_orders';
      $data['uc_order_line_items_' . $line_item_id]['table']['group'] = $this
        ->t('Order: Line item');
      $data['uc_order_line_items_' . $line_item_id]['title'] = [
        'title' => $this
          ->t('@line_item title', [
          '@line_item' => $line_item_desc,
        ]),
        'help' => $this
          ->t('@line_item order line item', [
          '@line_item' => $line_item_desc,
        ]),
        'field' => [
          'id' => 'standard',
          'click sortable' => TRUE,
        ],
        'filter' => [
          'id' => 'string',
        ],
      ];
      $data['uc_order_line_items_' . $line_item_id]['amount'] = [
        'title' => $this
          ->t('@line_item amount', [
          '@line_item' => $line_item_desc,
        ]),
        'help' => $this
          ->t('@line_item order line item', [
          '@line_item' => $line_item_desc,
        ]),
        'field' => [
          'id' => 'uc_price',
          'click sortable' => TRUE,
        ],
        'filter' => [
          'id' => 'numeric',
        ],
      ];
    }
    return $data;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeprecatedServicePropertyTrait::__get public function Allows to access deprecated/removed properties.
EntityViewsData::$deprecatedProperties protected property
EntityViewsData::$entityFieldManager protected property The entity field manager.
EntityViewsData::$entityType protected property Entity type for this views data handler instance.
EntityViewsData::$entityTypeManager protected property The entity type manager.
EntityViewsData::$fieldStorageDefinitions protected property The field storage definitions for all base fields of the entity type.
EntityViewsData::$moduleHandler protected property The module handler.
EntityViewsData::$storage protected property The storage used for this entity type.
EntityViewsData::$translationManager protected property The translation manager.
EntityViewsData::addEntityLinks protected function Sets the entity links in case corresponding link templates exist.
EntityViewsData::createInstance public static function Instantiates a new instance of this entity handler. Overrides EntityHandlerInterface::createInstance
EntityViewsData::getFieldStorageDefinitions protected function Gets the field storage definitions.
EntityViewsData::getViewsTableForEntityType public function Gets the table of an entity type to be used as base table in views. Overrides EntityViewsDataInterface::getViewsTableForEntityType
EntityViewsData::mapFieldDefinition protected function Puts the views data for a single field onto the views data.
EntityViewsData::mapSingleFieldViewsData protected function Provides the views data for a given data type and schema field.
EntityViewsData::processViewsDataForEntityReference protected function Processes the views data for an entity reference field.
EntityViewsData::processViewsDataForLanguage protected function Processes the views data for a language field.
EntityViewsData::processViewsDataForTextLong protected function Processes the views data for a text field with formatting.
EntityViewsData::processViewsDataForUuid protected function Processes the views data for a UUID field.
EntityViewsData::__construct public function Constructs an EntityViewsData object.
OrderViewsData::getViewsData public function Returns views data for the entity type. Overrides EntityViewsData::getViewsData
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.