/**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form = parent::buildForm($form, $form_state);
     $rate = $this->entity;
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#description' => $this->t('This name will appear to the customer when this tax is applied to an order.'), '#default_value' => $rate->label(), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#title' => $this->t('Machine name'), '#default_value' => $rate->id(), '#machine_name' => array('exists' => array($this, 'exists'), 'replace_pattern' => '([^a-z0-9_]+)|(^custom$)', 'error' => 'The machine-readable name must be unique, and can only contain lowercase letters, numbers, and underscores. Additionally, it can not be the reserved word "custom".'));
     $form['rate'] = array('#type' => 'textfield', '#title' => $this->t('Rate'), '#description' => $this->t('The tax rate as a percent or decimal. Examples: 6%, .06'), '#size' => 15, '#default_value' => (double) $rate->getRate() * 100.0 . '%', '#required' => TRUE);
     $form['jurisdiction'] = array('#type' => 'textfield', '#title' => $this->t('Jurisdiction'), '#description' => $this->t('Administrative label for the taxing authority, used to prepare reports of collected taxes.'), '#default_value' => $rate->getJurisdiction(), '#required' => FALSE);
     $form['shippable'] = array('#type' => 'radios', '#title' => $this->t('Taxed products'), '#options' => array(0 => $this->t('Apply tax to any product regardless of its shippability.'), 1 => $this->t('Apply tax to shippable products only.')), '#default_value' => (int) $rate->isForShippable());
     // TODO: Remove the need for a special case for product kit module.
     $options = array();
     foreach (node_type_get_names() as $type => $name) {
         if ($type != 'product_kit' && uc_product_is_product($type)) {
             $options[$type] = $name;
         }
     }
     $options['blank-line'] = $this->t('"Blank line" product');
     $form['product_types'] = array('#type' => 'checkboxes', '#title' => $this->t('Taxed product types'), '#description' => $this->t('Apply taxes to the specified product types/classes.'), '#default_value' => $rate->getProductTypes(), '#options' => $options);
     $options = array();
     foreach (_uc_line_item_list() as $id => $line_item) {
         if (!in_array($id, ['subtotal', 'tax_subtotal', 'total', 'tax_display'])) {
             $options[$id] = $line_item['title'];
         }
     }
     $form['line_item_types'] = array('#type' => 'checkboxes', '#title' => $this->t('Taxed line items'), '#description' => $this->t('Adds the checked line item types to the total before applying this tax.'), '#default_value' => $rate->getLineItemTypes(), '#options' => $options);
     $form['weight'] = array('#type' => 'weight', '#title' => $this->t('Weight'), '#description' => $this->t('Taxes are sorted by weight and then applied to the order sequentially. This value is important when taxes need to include other tax line items.'), '#default_value' => $rate->getWeight());
     $form['display_include'] = array('#type' => 'checkbox', '#title' => $this->t('Include this tax when displaying product prices.'), '#default_value' => $rate->isIncludedInPrice());
     $form['inclusion_text'] = array('#type' => 'textfield', '#title' => $this->t('Tax inclusion text'), '#description' => $this->t('This text will be displayed near the price to indicate that it includes tax.'), '#default_value' => $rate->getInclusionText());
     return $form;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(OrderInterface $order, array $form, FormStateInterface $form_state)
 {
     $options = array();
     $items = _uc_line_item_list();
     $line_items = $order->line_items;
     foreach ($items as $item) {
         if (isset($item['add_list']) && $item['add_list'] === TRUE) {
             $options[$item['id']] = SafeMarkup::checkPlain($item['title']);
         }
         if (isset($item['display_only']) && $item['display_only'] == TRUE) {
             $result = $item['callback']('display', $order);
             if (is_array($result)) {
                 foreach ($result as $line) {
                     $line_items[] = array('line_item_id' => $line['id'], 'title' => $line['title'], 'amount' => $line['amount'], 'weight' => $item['weight']);
                 }
             }
         }
     }
     usort($line_items, 'Drupal\\Component\\Utility\\SortArray::sortByWeightElement');
     $form['add_line_item'] = array('#type' => 'container');
     $form['add_line_item']['li_type_select'] = array('#type' => 'select', '#title' => $this->t('Add a line item'), '#options' => $options);
     $form['add_line_item']['submit'] = array('#type' => 'submit', '#value' => $this->t('Add line'), '#submit' => array(array($this, 'submitForm'), array($this, 'addLineItem')), '#ajax' => array('callback' => array($this, 'ajaxCallback')));
     $form['line_items'] = array('#type' => 'table', '#tree' => TRUE, '#attributes' => array('class' => array('line-item-table')), '#prefix' => '<div id="order-line-items">', '#suffix' => '</div>');
     foreach ($line_items as $item) {
         $form['line_items'][$item['line_item_id']]['li_id'] = array('#type' => 'hidden', '#value' => $item['line_item_id']);
         if (isset($item['type']) && _uc_line_item_data($item['type'], 'stored') == TRUE) {
             $form['line_items'][$item['line_item_id']]['remove'] = array('#type' => 'image_button', '#title' => $this->t('Remove line item.'), '#src' => drupal_get_path('module', 'uc_store') . '/images/error.gif', '#button_type' => 'remove', '#submit' => array(array($this, 'submitForm'), array($this, 'removeLineItem')), '#ajax' => array('callback' => array($this, 'ajaxCallback')), '#return_value' => $item['line_item_id']);
             $form['line_items'][$item['line_item_id']]['title'] = array('#type' => 'textfield', '#title' => $this->t('Title'), '#title_display' => 'invisible', '#default_value' => $item['title'], '#size' => 40, '#maxlength' => 128);
             $form['line_items'][$item['line_item_id']]['amount'] = array('#type' => 'uc_price', '#title' => $this->t('Amount'), '#title_display' => 'invisible', '#default_value' => $item['amount'], '#size' => 6, '#allow_negative' => TRUE, '#wrapper_attributes' => array('class' => array('li-amount')));
         } else {
             $form['line_items'][$item['line_item_id']]['remove'] = array('#markup' => '');
             $form['line_items'][$item['line_item_id']]['title'] = array('#plain_text' => $item['title']);
             $form['line_items'][$item['line_item_id']]['amount'] = array('#theme' => 'uc_price', '#price' => $item['amount'], '#wrapper_attributes' => array('class' => array('li-amount')));
         }
     }
     return $form;
 }
 /**
  * {@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'] = array('title' => $this->t('Actions'), 'help' => $this->t('Clickable links to actions a user may perform on an order.'), 'field' => array('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'] = array('title' => $this->t('Billing country name'), 'help' => $this->t('The country name where the bill will be sent.'), 'field' => array('id' => 'uc_country', 'real field' => 'billing_country'));
     $data['uc_orders']['delivery_country_name'] = array('title' => $this->t('Delivery country name'), 'help' => $this->t('The country name of the delivery location.'), 'field' => array('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'] = array('title' => $this->t('Billing state/province name'), 'help' => $this->t('The state/zone/province ID where the bill will be sent.'), 'field' => array('id' => 'uc_zone', 'real field' => 'billing_zone', 'additional fields' => array('country' => array('field' => 'billing_country'))));
     $data['uc_orders']['delivery_zone_name'] = array('title' => $this->t('Delivery state/province name'), 'help' => $this->t('The state/zone/province ID of the delivery location.'), 'field' => array('id' => 'uc_zone', 'real field' => 'delivery_zone', 'additional fields' => array('country' => array('field' => 'delivery_country'))));
     $data['uc_orders']['billing_full_name'] = array('title' => $this->t('Billing full name'), 'help' => $this->t('The full name of the person paying for the order.'), 'field' => array('id' => 'uc_order_full_name', 'real field' => 'billing_first_name', 'additional fields' => array('last_name' => array('field' => 'billing_last_name'))));
     $data['uc_orders']['delivery_full_name'] = array('title' => $this->t('Delivery full name'), 'help' => $this->t('The full name of the person receiving shipment.'), 'field' => array('id' => 'uc_order_full_name', 'real field' => 'delivery_first_name', 'additional fields' => array('last_name' => array('field' => 'delivery_last_name'))));
     $data['uc_orders']['total_weight'] = array('title' => $this->t('Total weight'), 'help' => $this->t('The physical weight of all the products (weight * quantity) in the order.'), 'real field' => 'weight', 'field' => array('handler' => 'uc_order_handler_field_order_weight_total', 'additional fields' => array('order_id' => 'order_id')));
     // Expose the uid as a relationship to users.
     $data['users_field_data']['uc_orders'] = array('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' => array('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(array('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'] = array('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'] = array('relationship' => array('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'] = array('title' => $this->t('Nid'), 'help' => $this->t('The nid of the ordered product. If you need more fields than the nid: Node relationship'), 'relationship' => array('title' => $this->t('Node'), 'help' => $this->t('Relate product to node.'), 'id' => 'standard', 'base' => 'node', 'field' => 'nid', 'label' => $this->t('node')), 'filter' => array('id' => 'numeric'), 'argument' => array('id' => 'node_nid'), 'field' => array('id' => 'node'));
     // Expose orders to ordered products as a relationship.
     $data['uc_order_products']['order_id'] = array('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' => array('title' => $this->t('Order'), 'help' => $this->t('Relate product to order.'), 'id' => 'standard', 'base' => 'uc_orders', 'field' => 'order_id', 'label' => $this->t('order')), 'filter' => array('id' => 'numeric'), 'argument' => array('id' => 'numeric'), 'field' => array('id' => 'uc_order'));
     $data['uc_order_products']['model'] = array('title' => $this->t('SKU'), 'help' => $this->t('The product model/SKU.'), 'field' => array('id' => 'standard', 'click sortable' => TRUE), 'sort' => array('id' => 'standard'), 'filter' => array('id' => 'string'), 'argument' => array('id' => 'string'));
     $data['uc_order_products']['qty'] = array('title' => $this->t('Quantity'), 'help' => $this->t('The quantity ordered.'), 'field' => array('id' => 'standard', 'click sortable' => TRUE), 'sort' => array('id' => 'standard'), 'filter' => array('id' => 'numeric'));
     $data['uc_order_products']['price'] = array('title' => $this->t('Price'), 'help' => $this->t('The price paid for one product.'), 'field' => array('id' => 'uc_price', 'click sortable' => TRUE), 'sort' => array('id' => 'standard'), 'filter' => array('id' => 'numeric'));
     $data['uc_order_products']['total_price'] = array('title' => $this->t('Total price'), 'help' => $this->t('The price paid for all the products (price * quantity).'), 'real field' => 'price', 'field' => array('handler' => 'uc_order_handler_field_money_total', 'click sortable' => TRUE), 'sort' => array('handler' => 'uc_order_handler_sort_total'), 'filter' => array('handler' => 'uc_order_handler_filter_total'));
     $data['uc_order_products']['cost'] = array('title' => $this->t('Cost'), 'help' => $this->t('The cost to the store for one product.'), 'field' => array('id' => 'uc_price', 'click sortable' => TRUE), 'sort' => array('id' => 'standard'), 'filter' => array('id' => 'numeric'));
     $data['uc_order_products']['total_cost'] = array('title' => $this->t('Total cost'), 'help' => $this->t('The cost to the store for all the products (cost * quantity).'), 'real field' => 'cost', 'field' => array('handler' => 'uc_order_handler_field_money_total', 'click sortable' => TRUE), 'sort' => array('handler' => 'uc_order_handler_sort_total'), 'filter' => array('handler' => 'uc_order_handler_filter_total'));
     $data['uc_order_products']['weight'] = array('title' => $this->t('Weight'), 'help' => $this->t('The physical weight of one product.'), 'field' => array('additional fields' => array('weight_units' => array('field' => 'weight_units')), 'id' => 'uc_weight'));
     $data['uc_order_products']['total_weight'] = array('title' => $this->t('Total weight'), 'help' => $this->t('The physical weight of all the products (weight * quantity).'), 'real field' => 'weight', 'field' => array('additional fields' => array('weight_units' => array('field' => 'weight_units')), 'handler' => 'uc_order_handler_field_weight_total'));
     $data['uc_order_products']['title'] = array('title' => $this->t('Title'), 'help' => $this->t('The title of the product.'), 'field' => array('id' => 'standard', 'click sortable' => TRUE), 'sort' => array('id' => 'standard'), 'filter' => array('id' => 'string'), 'argument' => array('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'] = array('uc_orders' => array('left_field' => 'order_id', 'field' => 'order_id'), 'uc_order_products' => array('left_table' => 'uc_orders', 'left_field' => 'order_id', 'field' => 'order_id'));
     $data['uc_order_comments']['message'] = array('title' => $this->t('Comment'), 'help' => $this->t('The comment body.'), 'field' => array('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 = array();
     foreach (_uc_line_item_list() as $line_item) {
         if (!in_array($line_item['id'], array('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'] = array('table' => 'uc_order_line_items', 'left_field' => 'order_id', 'field' => 'order_id', 'extra' => array(array('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'] = array('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' => array('id' => 'standard', 'click sortable' => TRUE), 'filter' => array('id' => 'string'));
         $data['uc_order_line_items_' . $line_item_id]['amount'] = array('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' => array('id' => 'uc_price', 'click sortable' => TRUE), 'filter' => array('id' => 'numeric'));
     }
     return $data;
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function getViewsData()
 {
     parent::getViewsData();
     // Orders table.
     $data['uc_orders']['table']['group'] = t('Order');
     $data['uc_orders']['table']['base'] = array('field' => 'order_id', 'title' => t('Orders'), 'help' => t('Orders placed in your Ubercart store.'));
     // Order ID field.
     $data['uc_orders']['order_id'] = array('title' => t('Order ID'), 'help' => t('The order ID.'), 'field' => array('id' => 'uc_order_id', 'click sortable' => TRUE), 'sort' => array('id' => 'standard'), 'filter' => array('id' => 'numeric'), 'argument' => array('id' => 'numeric', 'name field' => 'title', 'numeric' => TRUE, 'validate type' => 'order_id'));
     // Order status field.
     $data['uc_orders']['order_status'] = array('title' => t('Order status'), 'help' => t('The order status.'), 'field' => array('id' => 'uc_order_status', 'click sortable' => TRUE), 'sort' => array('id' => 'standard'), 'filter' => array('id' => 'uc_order_status'));
     $data['uc_orders']['uid'] = array('title' => t('Uid'), 'help' => t('The user ID that the order belongs to.'), 'field' => array('id' => 'user', 'click sortable' => TRUE), 'argument' => array('id' => 'user_uid', 'name field' => 'name'), 'filter' => array('title' => t('Name'), 'id' => 'user_name'), 'sort' => array('id' => 'standard'), 'relationship' => array('title' => t('Customer'), 'help' => t('Relate an order to the user who placed it.'), 'base' => 'users', 'field' => 'uid', 'id' => 'standard', 'label' => t('customer')));
     // Expose the uid as a relationship to users.
     $data['users']['uc_orders'] = array('title' => t('Orders'), 'help' => t('Relate a user to the orders they have placed. This relationship will create one record for each order placed by the user.'), 'relationship' => array('base' => 'uc_orders', 'base field' => 'uid', 'relationship field' => 'uid', 'id' => 'standard', 'label' => t('orders')));
     // Changed field handler to display as a price
     $data['uc_orders']['order_total'] = array('title' => t('Order total'), 'help' => t('The total amount to be paid for the order.'), 'field' => array('id' => 'uc_price', 'click sortable' => TRUE), 'sort' => array('id' => 'standard'), 'filter' => array('id' => 'numeric'));
     $data['uc_orders']['product_count'] = array('title' => t('Product count'), 'help' => t('The total number of products in the order.'), 'field' => array('id' => 'numeric', 'click sortable' => TRUE), 'sort' => array('id' => 'standard'), 'filter' => array('id' => 'numeric'));
     $data['uc_orders']['created'] = array('title' => t('Creation date'), 'help' => t('The date and time the order was created.'), 'field' => array('id' => 'date', 'click sortable' => TRUE), 'sort' => array('id' => 'date'), 'filter' => array('id' => 'date'));
     $data['uc_orders']['modified'] = array('title' => t('Last modified'), 'help' => t('The time the order was last modified.'), 'field' => array('id' => 'date', 'click sortable' => TRUE), 'sort' => array('id' => 'date'), 'filter' => array('id' => 'date'));
     $data['uc_orders']['actions'] = array('title' => t('Actions'), 'help' => t('Clickable links to actions a user may perform on an order.'), 'field' => array('id' => 'uc_order_actions', 'real field' => 'order_id', 'click sortable' => FALSE));
     $data['uc_orders']['primary_email'] = array('title' => t('Email address'), 'help' => t('The email address of the customer.'), 'field' => array('id' => 'user_mail', 'click sortable' => TRUE), 'sort' => array('id' => 'standard'), 'filter' => array('id' => 'string'));
     $addresses = array('billing' => t('Billing address'), 'delivery' => t('Delivery address'));
     $fields = array('first_name' => t('First name'), 'last_name' => t('Last name'), 'phone' => t('Phone number'), 'company' => t('Company'), 'street1' => t('Street address 1'), 'street2' => t('Street address 2'), 'city' => t('City'), 'postal_code' => t('Postal code'));
     foreach ($addresses as $prefix => $address) {
         $group = t('Order') . ': ' . $address;
         foreach ($fields as $field => $label) {
             $data['uc_orders'][$prefix . '_' . $field] = array('group' => $group, 'title' => $label, 'help' => t('The @field of the @address of the order.', ['@field' => Unicode::strtolower($label), '@address' => Unicode::strtolower($address)]), 'field' => array('id' => 'standard', 'click sortable' => TRUE), 'sort' => array('id' => 'standard'), 'filter' => array('id' => 'string'));
         }
         $data['uc_orders'][$prefix . '_full_name'] = array('group' => $group, 'title' => t('Full name'), 'help' => t('The @field of the @address of the order.', ['@field' => t('full name'), '@address' => Unicode::strtolower($address)]), 'field' => array('id' => 'uc_order_full_name', 'real field' => $prefix . '_first_name', 'additional fields' => array('last_name' => array('field' => $prefix . '_last_name'))));
         $data[$prefix . '_countries']['table']['group'] = $group;
         $data[$prefix . '_countries']['table']['join']['uc_orders'] = array('table' => 'uc_countries', 'left_field' => $prefix . '_country', 'field' => 'country_id');
         $data[$prefix . '_countries']['country_id'] = array('title' => t('ISO country code (numeric)'), 'help' => t('The @field of the @address of the order.', ['@field' => t('numeric ISO country code'), '@address' => Unicode::strtolower($address)]), 'argument' => array('id' => 'numeric', 'name field' => 'country_iso_code_2', 'numeric' => TRUE, 'validate type' => 'country_id'), 'filter' => array('id' => 'numeric'));
         $data[$prefix . '_countries']['country_name'] = array('title' => t('Country'), 'help' => t('The @field of the @address of the order.', ['@field' => t('country name'), '@address' => Unicode::strtolower($address)]), 'field' => array('id' => 'standard', 'click sortable' => TRUE), 'sort' => array('id' => 'standard'), 'filter' => array('id' => 'in_operator', 'real field' => 'country_id', 'options callback' => 'Drupal\\uc_country\\Controller\\CountryController::countryOptionsCallback'));
         $data[$prefix . '_countries']['country_iso_code_2'] = array('title' => t('ISO country code (2 characters)'), 'help' => t('The @field of the @address of the order.', ['@field' => t('ISO country code'), '@address' => Unicode::strtolower($address)]), 'field' => array('id' => 'standard', 'click sortable' => TRUE), 'sort' => array('id' => 'standard'), 'filter' => array('id' => 'string'));
         $data[$prefix . '_countries']['country_iso_code_3'] = array('title' => t('ISO country code (3 characters)'), 'help' => t('The @field of the @address of the order.', ['@field' => t('ISO country code'), '@address' => Unicode::strtolower($address)]), 'field' => array('id' => 'standard', 'click sortable' => TRUE), 'sort' => array('id' => 'standard'), 'filter' => array('id' => 'string'));
         $data[$prefix . '_zones']['table']['group'] = $group;
         $data[$prefix . '_zones']['table']['join']['uc_orders'] = array('table' => 'uc_countries_zones', 'left_field' => $prefix . '_zone', 'field' => 'zone_id');
         $data[$prefix . '_zones']['zone_name'] = array('title' => t('State/Province'), 'help' => t('The @field of the @address of the order.', ['@field' => t('state or province'), '@address' => Unicode::strtolower($address)]), 'field' => array('id' => 'standard', 'click sortable' => TRUE), 'sort' => array('id' => 'standard'), 'filter' => array('id' => 'in_operator', 'real field' => 'zone_code', 'options callback' => 'Drupal\\uc_country\\Controller\\CountryController::zoneOptionsCallback'));
         $data[$prefix . '_zones']['zone_code'] = array('title' => t('State/Province code'), 'help' => t('The @field of the @address of the order.', ['@field' => t('state or province code'), '@address' => Unicode::strtolower($address)]), 'field' => array('id' => 'standard', 'click sortable' => TRUE), 'sort' => array('id' => 'standard'), 'filter' => array('id' => 'string'));
     }
     $data['uc_orders']['total_weight'] = array('title' => t('Total weight'), 'help' => t('The physical weight of all the products (weight * quantity) in the order.'), 'real field' => 'weight', 'field' => array('handler' => 'uc_order_handler_field_order_weight_total', 'additional fields' => array('order_id' => 'order_id')));
     // Ordered products.
     // Get the standard EntityAPI Views data table.
     // $data['uc_order_products'] =  entity_views_table_definition('uc_order_product');
     // // Remove undesirable fields
     // foreach(array('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'] = t('Weight units');
     $data['uc_order_products']['table']['group'] = t('Ordered product');
     $data['uc_order_products']['table']['base'] = array('field' => 'order_product_id', 'title' => t('Ordered products'), 'help' => t('Products that have been ordered in your Ubercart store.'));
     // Expose products to their orders as a relationship.
     $data['uc_orders']['products'] = array('relationship' => array('title' => t('Products'), 'help' => 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' => t('products')));
     // Expose nodes to ordered products as a relationship.
     $data['uc_order_products']['nid'] = array('title' => t('Nid'), 'help' => t('The nid of the ordered product. If you need more fields than the nid: Node relationship'), 'relationship' => array('title' => t('Node'), 'help' => t('Relate product to node.'), 'id' => 'standard', 'base' => 'node', 'field' => 'nid', 'label' => t('node')), 'filter' => array('id' => 'numeric'), 'argument' => array('id' => 'node_nid'), 'field' => array('id' => 'node'));
     // Expose orders to ordered products as a relationship.
     $data['uc_order_products']['order_id'] = array('title' => t('Order ID'), 'help' => t('The order ID of the ordered product. If you need more fields than the order ID: Order relationship'), 'relationship' => array('title' => t('Order'), 'help' => t('Relate product to order.'), 'id' => 'standard', 'base' => 'uc_orders', 'field' => 'order_id', 'label' => t('order')), 'filter' => array('id' => 'numeric'), 'argument' => array('id' => 'numeric'), 'field' => array('id' => 'uc_order'));
     $data['uc_order_products']['model'] = array('title' => t('SKU'), 'help' => t('The product model/SKU.'), 'field' => array('id' => 'standard', 'click sortable' => TRUE), 'sort' => array('id' => 'standard'), 'filter' => array('id' => 'string'), 'argument' => array('id' => 'string'));
     $data['uc_order_products']['qty'] = array('title' => t('Quantity'), 'help' => t('The quantity ordered.'), 'field' => array('id' => 'standard', 'click sortable' => TRUE), 'sort' => array('id' => 'standard'), 'filter' => array('id' => 'numeric'));
     $data['uc_order_products']['price'] = array('title' => t('Price'), 'help' => t('The price paid for one product.'), 'field' => array('id' => 'uc_price', 'click sortable' => TRUE), 'sort' => array('id' => 'standard'), 'filter' => array('id' => 'numeric'));
     $data['uc_order_products']['total_price'] = array('title' => t('Total price'), 'help' => t('The price paid for all the products (price * quantity).'), 'real field' => 'price', 'field' => array('handler' => 'uc_order_handler_field_money_total', 'click sortable' => TRUE), 'sort' => array('handler' => 'uc_order_handler_sort_total'), 'filter' => array('handler' => 'uc_order_handler_filter_total'));
     $data['uc_order_products']['cost'] = array('title' => t('Cost'), 'help' => t('The cost to the store for one product.'), 'field' => array('id' => 'uc_price', 'click sortable' => TRUE), 'sort' => array('id' => 'standard'), 'filter' => array('id' => 'numeric'));
     $data['uc_order_products']['total_cost'] = array('title' => t('Total cost'), 'help' => t('The cost to the store for all the products (cost * quantity).'), 'real field' => 'cost', 'field' => array('handler' => 'uc_order_handler_field_money_total', 'click sortable' => TRUE), 'sort' => array('handler' => 'uc_order_handler_sort_total'), 'filter' => array('handler' => 'uc_order_handler_filter_total'));
     $data['uc_order_products']['weight'] = array('title' => t('Weight'), 'help' => t('The physical weight of one product.'), 'field' => array('additional fields' => array('weight_units' => array('field' => 'weight_units')), 'id' => 'uc_weight'));
     $data['uc_order_products']['total_weight'] = array('title' => t('Total weight'), 'help' => t('The physical weight of all the products (weight * quantity).'), 'real field' => 'weight', 'field' => array('additional fields' => array('weight_units' => array('field' => 'weight_units')), 'handler' => 'uc_order_handler_field_weight_total'));
     $data['uc_order_products']['title'] = array('title' => t('Title'), 'help' => t('The title of the product.'), 'field' => array('id' => 'standard', 'click sortable' => TRUE), 'sort' => array('id' => 'standard'), 'filter' => array('id' => 'string'), 'argument' => array('id' => 'string'));
     // Order comments table.
     // TODO: refactor this into a groupwise max relationship.
     $data['uc_order_comments']['table']['group'] = t('Order comments');
     $data['uc_order_comments']['table']['join'] = array('uc_orders' => array('left_field' => 'order_id', 'field' => 'order_id'), 'uc_order_products' => array('left_table' => 'uc_orders', 'left_field' => 'order_id', 'field' => 'order_id'));
     $data['uc_order_comments']['message'] = array('title' => t('Comment'), 'help' => t('The comment body.'), 'field' => array('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 = array();
     foreach (_uc_line_item_list() as $line_item) {
         if (!in_array($line_item['id'], array('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'] = array('table' => 'uc_order_line_items', 'left_field' => 'order_id', 'field' => 'order_id', 'extra' => array(array('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'] = t('Order: Line item');
         $data['uc_order_line_items_' . $line_item_id]['title'] = array('title' => t('@line_item title', ['@line_item' => $line_item_desc]), 'help' => t('@line_item order line item', ['@line_item' => $line_item_desc]), 'field' => array('id' => 'standard', 'click sortable' => TRUE), 'filter' => array('id' => 'string'));
         $data['uc_order_line_items_' . $line_item_id]['amount'] = array('title' => t('@line_item amount', ['@line_item' => $line_item_desc]), 'help' => t('@line_item order line item', ['@line_item' => $line_item_desc]), 'field' => array('id' => 'uc_price', 'click sortable' => TRUE), 'filter' => array('id' => 'numeric'));
     }
     return $data;
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function getDisplayLineItems()
 {
     $temp = clone $this;
     $line_items = $this->getLineItems();
     $items = _uc_line_item_list();
     foreach ($items as $item) {
         if (!empty($item['display_only'])) {
             $result = $item['callback']('display', $temp);
             if (is_array($result)) {
                 foreach ($result as $line) {
                     $line_items[] = array('type' => $item['id'], 'title' => $line['title'], 'amount' => $line['amount'], 'weight' => isset($line['weight']) ? $line['weight'] : $item['weight'], 'data' => isset($line['data']) ? $line['data'] : array());
                 }
             }
         }
     }
     foreach ($line_items as &$item) {
         $item['formatted_amount'] = uc_currency_format($item['amount']);
     }
     usort($line_items, 'Drupal\\Component\\Utility\\SortArray::sortByWeightElement');
     return $line_items;
 }