diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..836e2ed
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+/.idea
+node_modules
+.DS_Store
diff --git a/commerce_sos.module b/commerce_sos.module
index b78ae01..849f9ca 100644
--- a/commerce_sos.module
+++ b/commerce_sos.module
@@ -5,6 +5,9 @@
  * Contains code for commerce_sos.module.
  */
 
+define('COMMERCE_SOS_LINE_ITEM_DISCOUNT_NAME', 'sos_line_item_discount');
+define('COMMERCE_SOS_ORDER_DISCOUNT_NAME', 'sos_order_discount');
+
 /**
  * Implements hook_menu().
  */
@@ -45,10 +48,10 @@ function commerce_sos_menu() {
     'access arguments' => ['administer commerce simple order system'],
   ];
 
-  $items['admin/commerce/edit-customer-profile/%ctools_js/%commerce_customer_profile'] = [
+  $items['admin/commerce/sos/orders/%commerce_order/edit-customer-profile/%ctools_js/%commerce_customer_profile'] = [
     'title' => 'Edit Customer Profile',
     'page callback' => 'commerce_sos_edit_customer_profile_modal_callback',
-    'page arguments' => [3, 4],
+    'page arguments' => [4, 6, 7],
     'access arguments' => ['administer commerce simple order system'],
     'file' => 'includes/commerce_sos.form.inc',
   ];
@@ -132,6 +135,7 @@ function commerce_sos_order_form_wrapper($order = NULL, $uid = NULL) {
   }
 
   // Order edit form.
+  $form_state['build_info']['args'][] = $uid;
   return drupal_build_form('commerce_sos_order_form', $form_state);
 }
 
@@ -146,11 +150,30 @@ function commerce_sos_theme($existing, $type, $theme, $path) {
       'path' => $path . '/theme',
       'variables' => [
         'product' => NULL,
+        'product_search' => FALSE,
       ],
     ],
     'commerce_sos_products_table' => [
       'render element' => 'form',
     ],
+    'commerce_sos_existing_users_table' => [
+      'render element' => 'form',
+    ],
+    'commerce_sos_price_formatted_components' => [
+      'variables' => [
+        'order_wrapper' => NULL,
+        'components' => [],
+        'price' => [],
+        'number_of_line_item_products' => 0,
+      ],
+    ],
+    'commerce_sos_order_total_summary' => [
+      'variables' => [
+        'order_wrapper' => NULL,
+        'components' => [],
+        'price' => [],
+      ],
+    ],
   ];
 }
 
@@ -159,18 +182,23 @@ function commerce_sos_theme($existing, $type, $theme, $path) {
  *
  * @param int $product_id
  *   Product id of the product to build.
+ * @param bool $product_search
+ *   If we're building the array of product data for the product search.
  *
  * @return array|bool
  *   Array of product data for the autocomplete, or false if product couldn't be
  *   loaded.
  */
-function commerce_sos_product_autocomplete_build($product_id) {
+function commerce_sos_product_autocomplete_build($product_id, $product_search = FALSE) {
   $data = FALSE;
   $product = commerce_product_load($product_id);
 
   if (!empty($product)) {
     $data = [
-      'markup' => theme('commerce_sos_product_result', ['product' => $product]),
+      'markup' => theme('commerce_sos_product_result', [
+        'product' => $product,
+        'product_search' => $product_search,
+      ]),
       'title' => $product->title,
     ];
   }
@@ -192,7 +220,7 @@ function commerce_sos_product_thumbnail($product) {
 
   if ($image_fields = variable_get('commerce_sos_image_field_' . $product->type, FALSE)) {
     if (!($uri = commerce_sos_image_uri('commerce_product', $product, $image_fields))
-      && $nid = commerce_sos_get_product_display_nid($product->product_id)
+      && $nid = commerce_sos_get_product_display_nid($product->product_id)['nid']
     ) {
 
       // Try looking for images on the product display node.
@@ -243,41 +271,64 @@ function commerce_sos_image_uri($entity_type, $entity, $fields) {
  *
  * @param int $product_id
  *   The product ID to retrieve the display node for.
+ * @param bool $product_search
+ *   True if we're displaying the nid for the product search.
  *
- * @return int
- *   The nid of the display node, or 0 if none was found.
+ * @return array
+ *   The display node details, or 0 if none was found.
  */
-function commerce_sos_get_product_display_nid($product_id) {
+function commerce_sos_get_product_display_nid($product_id, $product_search) {
   global $language;
 
   // Iterate through fields which refer to products.
+  // If we're grabbing the display node for the product search, get the display
+  // node types the user selected in the admin settings page.
+  if ($product_search) {
+    $display_bundles_to_use_in_search = array_filter(variable_get('commerce_sos_product_displays_for_product_search', []));
+  }
   foreach (commerce_info_fields('commerce_product_reference', 'node') as $field) {
-    $query = 'SELECT entity_id, language FROM {field_data_' . $field['field_name'] . '}
+
+    // We only search the fields in the display nodes that the user selected in
+    // the admin settings.
+    $field_in_display_bundle_for_search = FALSE;
+    if ($display_bundles_to_use_in_search) {
+      foreach ($field['bundles']['node'] as $index => $bundle) {
+        if (isset($display_bundles_to_use_in_search[$bundle])) {
+          $field_in_display_bundle_for_search = TRUE;
+          break;
+        }
+      }
+    }
+
+    if ($field_in_display_bundle_for_search) {
+      $query = 'SELECT entity_type, entity_id, language FROM {field_data_' . $field['field_name'] . '}
       WHERE entity_type = :node
       AND ' . $field['field_name'] . '_product_id = :product_id
       AND (language = :language OR language = :language_none)';
 
-    $result = db_query($query, [
-      ':node' => 'node',
-      ':product_id' => $product_id,
-      ':language' => $language->language,
-      ':language_none' => LANGUAGE_NONE,
-    ]);
-
-    $no_lang_id = 0;
-
-    foreach ($result as $row) {
-      if ($row->language == $language->language) {
-        return $row->entity_id;
-      }
-      elseif ($row->language == LANGUAGE_NONE) {
-        $no_lang_id = $row->entity_id;
+      $result = db_query($query, [
+        ':node' => 'node',
+        ':product_id' => $product_id,
+        ':language' => $language->language,
+        ':language_none' => LANGUAGE_NONE,
+      ]);
+
+      foreach ($result as $row) {
+        if ($row->language == $language->language || $row->language == LANGUAGE_NONE) {
+          $display_node = [
+            'nid' => $row->entity_id,
+            'product_reference_field_name' => $field['field_name'],
+            'entity_type' => $row->entity_type,
+          ];
+        }
       }
     }
+  }
+
+  drupal_alter('commerce_sos_get_product_display_nid', $product_id, $display_nid);
 
-    // If we made it this far, there were either no matches or the only match
-    // was one without a language set.
-    return $no_lang_id;
+  if ($display_node) {
+    return $display_node;
   }
 
   return 0;
@@ -367,10 +418,17 @@ function _commerce_sos_fetch_product_details($product) {
 
   // Get the view link for the product.
   $view_url = '';
-  if ($display_nid = commerce_sos_get_product_display_nid($product->product_id)) {
+  $display_nid_info = commerce_sos_get_product_display_nid($product->product_id);
+
+  if ($display_nid = $display_nid_info['nid']) {
     $view_url = 'node/' . $display_nid;
   }
-  $view_link = isset($view_url) ? l(t('view'), $view_url, ['attributes' => ['class' => ['button'], 'target' => '_blank']]) : '';
+  $view_link = isset($view_url) ? l(t('view'), $view_url, [
+    'attributes' => [
+      'class' => ['button'],
+      'target' => '_blank',
+    ],
+  ]) : '';
 
   $product_info = [
     'product' => $product,
@@ -380,6 +438,9 @@ function _commerce_sos_fetch_product_details($product) {
     'order_quantity' => 0,
     'view_url' => $view_url,
     'view_link' => $view_link,
+    'entity_type' => !empty($display_nid_info) ? $display_nid_info['entity_type'] : NULL,
+    'product_reference_field_name' => !empty($display_nid_info) ? $display_nid_info['product_reference_field_name'] : NULL,
+    'display_nid' => !empty($display_nid_info) ? $display_nid : NULL,
   ];
 
   return $product_info;
@@ -433,10 +494,10 @@ function commerce_sos_form_views_exposed_form_alter(&$form, &$form_state, $form_
  */
 function commerce_sos_preprocess_views_view_field(&$vars) {
   $view = $vars['view'];
+  $row = $vars['row'];
 
+  // Our SOS order manager view.
   if ($view->name == 'commerce_sos_order_manager') {
-    $row = $vars['row'];
-
     // If the order hasn't completed, add links to process the order.
     if ($vars['field']->real_field == 'nothing') {
       if ($row->commerce_order_status != 'completed') {
@@ -462,7 +523,7 @@ function commerce_sos_preprocess_views_view_field(&$vars) {
 }
 
 /**
- * Implementation of hook_views_pre_view.
+ * Implements hook_views_pre_view().
  */
 function commerce_sos_views_pre_view(&$view, &$display_id, &$args) {
   // If the 'Inject Order ID' checkbox was checked in the config page, let's
@@ -499,6 +560,9 @@ function commerce_sos_form_commerce_checkout_form_checkout_alter(&$form, &$form_
   // If the 'Inject Order ID' checkbox was checked in the config page, let's
   // add the order id into the checkout form header.
   if (variable_get('commerce_sos_inject_order_id', 0) == 1) {
+    // Attach our CSS.
+    $form['#attached']['css'][] = drupal_get_path('module', 'commerce_sos') . '/css/commerce_sos_style.css';
+
     form_load_include($form_state, 'inc', 'commerce_sos', 'includes/commerce_sos.common');
     $content = commerce_sos_fetch_order_header_content($form_state['order']->order_id);
 
@@ -545,10 +609,18 @@ function theme_commerce_sos_products_table(array $variables) {
     t('Operation'),
   ];
 
+  // Remove the discount header if it isn't enabled.
+  if (!module_exists('commerce_discount')) {
+    unset($header[6]);
+  }
+
   $elements = $variables['form'];
+  $header_count = count($header);
 
   // Setup the structure to be rendered and returned.
   $rows = [];
+  $attributes = '';
+  $options = '';
   // Traverse each row.
   foreach (element_children($elements) as $row_index) {
     $row = [];
@@ -561,12 +633,111 @@ function theme_commerce_sos_products_table(array $variables) {
           $row[] = $elements[$row_index][$col_index]['#value'];
         }
         else {
-          $row[] = drupal_render($elements[$row_index][$col_index]);
+          // Add the add/remove quantity elements next to the quantity field.
+          if ($col_index == 'quantity') {
+            $row[] = [
+              'data' => drupal_render($elements[$row_index]['remove_quantity']) . ' ' . drupal_render($elements[$row_index][$col_index]) . ' ' . drupal_render($elements[$row_index]['add_quantity']),
+              'class' => ['sos-quantity'],
+            ];
+          }
+          elseif ($col_index == 'stock' && isset($elements[$row_index]['not_enough_stock'])) {
+            $row[] = [
+              'data' => drupal_render($elements[$row_index]['stock']),
+              'class' => ['sos-not-enough-stock'],
+            ];
+          }
+          else {
+            // Combine the remove and edit buttons in the operation column.
+            if ($col_index == 'remove') {
+              $row[] = drupal_render($elements[$row_index]['remove']) . ' ' . drupal_render($elements[$row_index]['edit']);
+            }
+            // Don't add the add/remove quantity fields and edit fields again.
+            else {
+              if ($col_index != 'add_quantity' && $col_index != 'remove_quantity' && $col_index != 'edit') {
+                // Now, add our product attributes and options in another row.
+                if ($col_index == 'attributes' || $col_index == 'options') {
+                  // Add the attributes first.
+                  if ($col_index == 'attributes') {
+                    $attributes = '';
+                    foreach (element_children($elements[$row_index][$col_index]) as $sub_col_index) {
+                      $attributes .= drupal_render($elements[$row_index][$col_index][$sub_col_index]);
+                    }
+                  }
+                  // Add the options now.
+                  else {
+                    $options = '';
+                    foreach (element_children($elements[$row_index][$col_index]) as $sub_col_index) {
+                      $options .= drupal_render($elements[$row_index][$col_index][$sub_col_index]);
+                    }
+                  }
+                }
+                else {
+                  $row[] = drupal_render($elements[$row_index][$col_index]);
+                }
+              }
+            }
+          }
         }
       }
     }
 
-    $rows[] = $row;
+    // Combine our attributes and options in another row, before we render the
+    // new rows.
+    if (isset($last_product_id) && $last_product_id != $row_index) {
+      // Add the previous line item details row before we add the
+      // options and attributes.
+      if (!isset($rows[$row_index . '-line-item-details'])) {
+        // Now, combine and add the attributes and options in a
+        // new row.
+        $rows[$row_index . '-line-item-details'] = [
+          'data' => $row,
+          'class' => ['sos-line-item-details'],
+        ];
+        $row = [];
+      }
+
+      $row[] = [
+        'data' => $attributes . $options,
+        'colspan' => $header_count,
+        'class' => empty($attributes) && empty($options) ? ['element-invisible'] : [],
+      ];
+      $rows[$row_index . '-line-item-attributes'] = [
+        'data' => $row,
+        'class' => ['sos-line-item-attributes']
+      ];
+
+      $attributes = '';
+      $options = '';
+    }
+    // Else, if this is the first row.
+    elseif (!isset($last_product_id)) {
+      // Add the previous line item details row before we add the
+      // options and attributes.
+      if (!isset($rows[$row_index . '-line-item-details'])) {
+        // Now, combine and add the attributes and options in a
+        // new row.
+        $rows[$row_index . '-line-item-details'] = [
+          'data' => $row,
+          'class' => ['sos-line-item-details'],
+        ];
+        $row = [];
+      }
+
+      $row[] = [
+        'data' => $attributes . $options,
+        'colspan' => $header_count,
+        'class' => empty($attributes) && empty($options) ? ['element-invisible'] : [],
+      ];
+      $rows[$row_index . '-line-item-attributes'] = [
+        'data' => $row,
+        'class' => ['sos-line-item-attributes']
+      ];
+
+      $attributes = '';
+      $options = '';
+    }
+
+    $last_product_id = $row_index;
   }
 
   // Theme the above table and add to $output.
@@ -584,3 +755,81 @@ function theme_commerce_sos_products_table(array $variables) {
 
   return $output;
 }
+
+/**
+ * Implements hook_commerce_line_item_rebase_unit_price().
+ */
+function commerce_sos_commerce_line_item_rebase_unit_price(&$price, $old_components, $line_item) {
+  // Check if any discounts have been applied to a line item and recalculate
+  // them as needed.
+  foreach ($old_components as $component) {
+    if (isset($component['price']['data']['sos_discount_type'])) {
+      $discount_type = $component['price']['data']['sos_discount_type'];
+      $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
+
+      switch ($discount_type) {
+        case 'percent':
+          $discount_amount = $component['price']['data']['sos_discount_rate'];
+          break;
+
+        case 'fixed':
+          $discount_amount = $component['price']['amount'] * -1;
+          break;
+      }
+
+      commerce_sos_apply_discount($line_item_wrapper, $discount_type, $discount_amount);
+
+      if ($component = commerce_sos_get_discount_component($line_item_wrapper->commerce_unit_price, $component['price']['data']['discount_name'])) {
+        $component_name = 'discount|' . COMMERCE_SOS_LINE_ITEM_DISCOUNT_NAME;
+        $price['data'] = commerce_price_component_add($price, $component_name, $component['price'], TRUE);
+        $price['amount'] += $component['price']['amount'];
+      }
+    }
+  }
+}
+
+/**
+ * Implements hook_commerce_price_formatted_components_alter().
+ */
+function commerce_sos_commerce_price_formatted_components_alter(&$components, $price, $entity) {
+  if (isset($price['data']['components'])) {
+    // Loop into price components and alter the component title if the discount
+    // component label is found.
+    foreach ($price['data']['components'] as $component) {
+      if (!isset($component['price']['data']['sos_discount_component_title'])) {
+        continue;
+      }
+
+      $components[$component['name']]['title'] = $component['price']['data']['sos_discount_component_title'];
+    }
+  }
+}
+
+/**
+ * After build function for the advanced settings field elements.
+ */
+function _commerce_sos_disable_after_build($element, &$form_state) {
+  // Disable the field.
+  _commerce_sos_disable_fields($element);
+
+  return $element;
+}
+
+/**
+ * Function which disables a form element including its children.
+ *
+ * @param array $elements
+ *   The form element.
+ */
+function _commerce_sos_disable_fields(array &$elements) {
+  foreach (element_children($elements) as $key) {
+    if (isset($elements[$key]) && $elements[$key]) {
+      // Recurse through all children elements.
+      _commerce_sos_disable_fields($elements[$key]);
+    }
+  }
+  if (!isset($elements['#attributes'])) {
+    $elements['#attributes'] = [];
+  }
+  $elements['#attributes']['disabled'] = 'disabled';
+}
\ No newline at end of file
diff --git a/includes/commerce_sos.admin.inc b/includes/commerce_sos.admin.inc
index b391863..b76876b 100644
--- a/includes/commerce_sos.admin.inc
+++ b/includes/commerce_sos.admin.inc
@@ -72,6 +72,20 @@ function commerce_sos_admin_form($form, &$form_state) {
     '#required' => TRUE,
   ];
 
+  // Select product types that should be in the product search.
+  $options = [];
+  foreach (commerce_product_types() as $key => $type) {
+    $options[$key] = $type['name'];
+  }
+  $form['commerce_sos_product_types_in_search'] = [
+    '#type' => 'select',
+    '#multiple' => TRUE,
+    '#options' => $options,
+    '#title' => t('Product Types Included in Product Search'),
+    '#description' => t('Select the product types that should be part of the product search.'),
+    '#default_value' => variable_get('commerce_sos_product_types_in_search', []),
+  ];
+
   // Select image field to be used in product searches and order details.
   $form['field_settings'] = [
     '#type' => 'fieldset',
@@ -173,6 +187,7 @@ function commerce_sos_admin_form_submit($form, &$form_state) {
   variable_set('commerce_sos_override_path_order_editing', $form_state['values']['commerce_sos_override_path_order_editing']);
   variable_set('commerce_sos_inject_order_id', $form_state['values']['commerce_sos_inject_order_id']);
   variable_set('commerce_sos_product_displays_for_product_search', $form_state['values']['commerce_sos_product_displays_for_product_search']);
+  variable_set('commerce_sos_product_types_in_search', $form_state['values']['commerce_sos_product_types_in_search']);
   variable_set('commerce_sos_billing_profile_type', $form_state['values']['commerce_sos_billing_profile_type']);
   variable_set('commerce_sos_shipping_profile_type', $form_state['values']['commerce_sos_shipping_profile_type']);
 
diff --git a/includes/commerce_sos.api.php b/includes/commerce_sos.api.php
index 125857f..e03ba70 100644
--- a/includes/commerce_sos.api.php
+++ b/includes/commerce_sos.api.php
@@ -55,7 +55,7 @@ function hook_commerce_sos_print_address_details_alter(array $address_info, &$ou
  * @param object $order
  *   The commerce order entity.
  * @param string $save_type
- *   The type of saving we're about to do. ie. 'void_order'
+ *   The type of saving we're about to do ie. 'void_order'.
  * @param string $status
  *   The status we're going to change the order to.
  */
@@ -64,3 +64,48 @@ function hook_commerce_sos_order_save_alter($order, $save_type, &$status) {
     $status = 'canceled';
   }
 }
+
+/**
+ * Allows altering the display path if a line item.
+ *
+ * @param object $line_item
+ *   The commerce order line item entity.
+ * @param object $product
+ *   The commerce product entity.
+ * @param string $display_path
+ *   The product display path url.
+ */
+function hook_commerce_sos_line_item_display_path_alter($line_item, $product, &$display_path) {
+  if ($product->type == 'something') {
+    $display_path = 'new/url';
+  }
+}
+
+/**
+ * Allows modules to act upon the main SOS order form AJAX submission.
+ *
+ * While this is technically possible already through the use of hook_form_alter,
+ * this hook allows other modules to set $form_state['order_updated'] to
+ * TRUE to force the form to reload the transaction and recalculate order
+ * totals.
+ *
+ * @param array $triggering_element
+ *   The element that triggered the AJAX submission. Available directly in the
+ *   $form_state variable, but provided for ease-of-use.
+ * @param array $form_state
+ *   The Drupal form API form state variable.
+ */
+function hook_commerce_sos_form_ajax_check_alter($triggering_element, &$form_state) {
+}
+
+/**
+ * Allows modules to alter the display node that references a product.
+ *
+ * @param int $product_id
+ *   The product ID to retrieve the display node for.
+ *
+ * @param array
+ *   The display node details, or 0 if none was found.
+ */
+function hook_commerce_sos_get_product_display_nid_alter($product_id, array &$display_node) {
+}
diff --git a/includes/commerce_sos.common.inc b/includes/commerce_sos.common.inc
index 9bfdd93..abd9b91 100644
--- a/includes/commerce_sos.common.inc
+++ b/includes/commerce_sos.common.inc
@@ -14,9 +14,6 @@
  *   The name of the customer.
  * @param string $address
  *   The street address of the customer.
- * @param bool $latest_profile
- *   If TRUE, returns a single record for the user with the latest
- *   shipping/billing profile ids.
  *
  * @return array
  *   An array of users keyed by the uid.
@@ -25,7 +22,8 @@ function commerce_sos_find_existing_customer($email = NULL, $name = NULL, $addre
   $results = [];
 
   $query = db_select('users', 'u');
-  $query->fields('u', ['uid', 'mail']);
+  $query = $query->extend('PagerDefault')->limit(5);
+  $query = $query->fields('u', ['uid', 'mail']);
   $query->fields('f', [
     'commerce_customer_address_first_name',
     'commerce_customer_address_last_name',
@@ -58,7 +56,10 @@ function commerce_sos_find_existing_customer($email = NULL, $name = NULL, $addre
   $query->condition('c.uid', 0, '!=');
   $query->orderBy('c.profile_id', 'DESC');
   $query->groupBy('u.uid');
-  $query->condition('c.type', [variable_get('commerce_sos_billing_profile_type', ''), variable_get('commerce_sos_shipping_profile_type')], 'IN');
+  $query->condition('c.type', [
+    variable_get('commerce_sos_billing_profile_type', ''),
+    variable_get('commerce_sos_shipping_profile_type'),
+  ], 'IN');
   $results = $query->execute()->fetchAllAssoc('uid');
 
   return $results;
@@ -67,7 +68,7 @@ function commerce_sos_find_existing_customer($email = NULL, $name = NULL, $addre
 /**
  * Function to clean up username.
  *
- * e.g.
+ * E.g.
  *     Replace two or more spaces with a single underscore
  *     Strip illegal characters.
  *
@@ -132,10 +133,13 @@ function commerce_sos_unique_username($name, $uid = NULL) {
   do {
     $new_name = empty($i) ? $name : $name . '_' . $i;
     if ($uid) {
-      $found = db_query_range("SELECT uid from {users} WHERE uid <> :uid AND name = :name", 0, 1, array(':uid' => $uid, ':name' => $new_name))->fetchAssoc();
+      $found = db_query_range("SELECT uid from {users} WHERE uid <> :uid AND name = :name", 0, 1, [
+        ':uid' => $uid,
+        ':name' => $new_name,
+      ])->fetchAssoc();
     }
     else {
-      $found = db_query_range("SELECT uid from {users} WHERE name = :name", 0, 1, array(':name' => $new_name))->fetchAssoc();
+      $found = db_query_range("SELECT uid from {users} WHERE name = :name", 0, 1, [':name' => $new_name])->fetchAssoc();
     }
 
     $i++;
@@ -178,7 +182,7 @@ function commerce_sos_save_profile($customer_profile, $type) {
     'postal_code',
     'thoroughfare',
     'premise',
-    'sub_premise'
+    'sub_premise',
   ];
   foreach ($address_array as $address_element) {
     $profile->commerce_customer_address[LANGUAGE_NONE][0][$address_element] = $customer_profile->commerce_customer_address[LANGUAGE_NONE][0][$address_element];
@@ -192,27 +196,31 @@ function commerce_sos_save_profile($customer_profile, $type) {
 /**
  * Outputs html with the address details for a billing/shipping profile.
  *
+ * @param object $order
+ *   The order entity we're displaying this address for.
  * @param array $address_info
  *   The billing/shipping profile along with the user details.
  *
  * @return string
  *   The html output.
  */
-function commerce_sos_print_address_details($address_info) {
+function commerce_sos_print_address_details($order, array $address_info) {
   $output = '';
 
-  $output .= '<div class="sos-address-header">' . t('@type Address', ['@type' => $address_info['profile']->type]) . '</div>';
-  $output .= '<div class="sos-address-email">' . $address_info['customer']->mail . '</div>';
-  $output .= '<div class="sos-address-details">';
-  $address_field = field_view_field('commerce_customer_profile', $address_info['profile'], 'commerce_customer_address', ['label' => 'hidden']);
-  $output .= drupal_render($address_field);
-  $output .= '</div>';
-
-  ctools_include('modal');
-  ctools_modal_add_js();
-  $output .= '<div class="sos-address-edit">' . l(t('Edit @type address', ['@type' => $address_info['profile']->type]), 'admin/commerce/edit-customer-profile/nojs/' . $address_info['profile']->profile_id, [
-    'attributes' => ['class' => ['ctools-use-modal']]
+  if (isset($address_info['profile']->type)) {
+    $output .= '<div class="sos-address-header">' . t('@type Address', ['@type' => $address_info['profile']->type]) . '</div>';
+    $output .= '<div class="sos-address-email">' . $address_info['customer']->mail . '</div>';
+    $output .= '<div class="sos-address-details">';
+    $address_field = field_view_field('commerce_customer_profile', $address_info['profile'], 'commerce_customer_address', ['label' => 'hidden']);
+    $output .= drupal_render($address_field);
+    $output .= '</div>';
+
+    ctools_include('modal');
+    ctools_modal_add_js();
+    $output .= '<div class="sos-address-edit">' . l(t('Edit @type address', ['@type' => $address_info['profile']->type]), 'admin/commerce/sos/orders/' . $order->order_id . '/edit-customer-profile/nojs/' . $address_info['profile']->profile_id, [
+      'attributes' => ['class' => ['ctools-use-modal']],
     ]) . '</div>';
+  }
 
   // Allow users to alter the address output.
   drupal_alter('commerce_sos_print_address_details', $address_info, $output);
@@ -270,7 +278,7 @@ function commerce_sos_product_autocomplete() {
     // Else, if we have results, add the themed markup to the products array.
     else {
       foreach ($results as $product_id) {
-        if ($data = commerce_sos_product_autocomplete_build($product_id)) {
+        if ($data = commerce_sos_product_autocomplete_build($product_id, TRUE)) {
           $products[$product_id] = $data;
         }
       }
@@ -305,7 +313,10 @@ function commerce_sos_product_search_api_search($keywords) {
     if ($index_id != 'default') {
       $index = search_api_index_load($index_id);
       $query = new SearchApiQuery($index);
-      $query->condition("status", 1);
+      $query->condition('status', 1);
+      if (!empty(variable_get('commerce_sos_product_types_in_search', []))) {
+        $query->condition('type', variable_get('commerce_sos_product_types_in_search', []), 'IN');
+      }
       $query->keys($keywords);
       $query->range(0, variable_get('commerce_sos_search_results_count', 5));
       $query_results = $query->execute();
@@ -328,6 +339,9 @@ function commerce_sos_product_search_basic($keywords) {
   $query = db_select('commerce_product', 'cp');
   $query->fields('cp', ['product_id', 'title', 'type']);
   $query->condition("status", 1);
+  if (!empty(variable_get('commerce_sos_product_types_in_search', []))) {
+    $query->condition('type', variable_get('commerce_sos_product_types_in_search', []), 'IN');
+  }
   $or = db_or();
   $or->condition('title', '%' . db_like($keywords) . '%', 'LIKE')
     ->condition('sku', $keywords, '=');
@@ -352,8 +366,8 @@ function commerce_sos_product_search_basic($keywords) {
 function commerce_sos_product_get_empty_results_message() {
   return [
     'markup' => '<div id="commerce-sos-product-no-results-message">'
-      . t('There are no products that match this search.')
-      . '</div>',
+    . t('There are no products that match this search.')
+    . '</div>',
     'title' => t('No Results'),
   ];
 }
@@ -363,8 +377,8 @@ function commerce_sos_product_get_empty_results_message() {
  *
  * @param object $order
  *   The order entity.
- * @param object $product
- *   The product entity.
+ * @param array $product_info
+ *   An array of product info including the display_path and product entity.
  * @param int $quantity
  *   The number of quantity to add.
  * @param bool $combine
@@ -375,12 +389,29 @@ function commerce_sos_product_get_empty_results_message() {
  * @return object
  *   The full saved and referenced line item.
  */
-function commerce_sos_add_product($order, $product, $quantity = 1, $combine = TRUE, $price = NULL) {
+function commerce_sos_add_product($order, array $product_info, $quantity = 1, $combine = TRUE, $price = NULL) {
   // If the specified product exists...
   // Create a new product line item for it.
+  $product = $product_info['product'];
+  $view_url = $product_info['view_url'];
   $line_item = commerce_product_line_item_new($product, $quantity, $order->order_id);
   $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
 
+  // Add the necessary data to the line item if we've got a display nid.
+  if (!empty($product_info['display_nid'])) {
+    $line_item->data['context'] = [
+      'product_ids' => 'entity',
+      'add_to_cart_combine' => $combine,
+      'show_single_product_attributes' => TRUE,
+      'display_path' => $view_url,
+      'entity' => [
+        'entity_type' => $product_info['entity_type'],
+        'entity_id' => $product_info['display_nid'],
+        'product_reference_field_name' => $product_info['product_reference_field_name'],
+      ],
+    ];
+  }
+
   rules_invoke_event('commerce_product_calculate_sell_price', $line_item);
 
   if (!empty($price)) {
@@ -389,16 +420,16 @@ function commerce_sos_add_product($order, $product, $quantity = 1, $combine = TR
 
     // We "snapshot" the calculated sell price and use it as the line item's
     // base price.
-    $unit_price = array(
+    $unit_price = [
       'amount' => $amount,
       'currency_code' => $currency,
-    );
+    ];
 
-    $unit_price['data'] = commerce_price_component_add($unit_price, 'base_price', array(
+    $unit_price['data'] = commerce_price_component_add($unit_price, 'base_price', [
       'amount' => $amount,
       'currency_code' => $currency,
-      'data' => array(),
-    ), TRUE, FALSE);
+      'data' => [],
+    ], TRUE, FALSE);
 
     $line_item_wrapper->commerce_unit_price->set($unit_price);
   }
@@ -407,7 +438,7 @@ function commerce_sos_add_product($order, $product, $quantity = 1, $combine = TR
     // Hack to prevent the combine logic in addLineItem() from incorrectly
     // thinking that the newly-added line item is different than
     // previously-added line items.
-    $line_item->commerce_pricing_attributes = serialize(array());
+    $line_item->commerce_pricing_attributes = serialize([]);
   }
 
   if (module_exists('commerce_tax')) {
@@ -416,6 +447,14 @@ function commerce_sos_add_product($order, $product, $quantity = 1, $combine = TR
     }
   }
 
+  // Set the display path for this product.
+  if (!empty($view_url)) {
+    // Let others alter the display path.
+    drupal_alter('commerce_sos_line_item_display_path', $line_item, $product, $view_url);
+
+    $line_item_wrapper->commerce_display_path->set($view_url);
+  }
+
   return commerce_sos_add_line_item($order, $line_item, $combine);
 }
 
@@ -433,7 +472,6 @@ function commerce_sos_add_product($order, $product, $quantity = 1, $combine = TR
  *   Returns the full saved line item.
  */
 function commerce_sos_add_line_item($order, $line_item, $combine) {
-  // Do not add the line item if it doesn't have a unit price.
   $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
 
   // Set the incoming line item's order_id.
@@ -456,7 +494,7 @@ function commerce_sos_add_line_item($order, $line_item, $combine) {
   // If we are supposed to look for a line item to combine into...
   if ($combine) {
     // Generate an array of properties and fields to compare.
-    $comparison_properties = array('type', 'commerce_product');
+    $comparison_properties = ['type', 'commerce_product'];
 
     // Add any field that was exposed on the Add to Cart form to the array.
     foreach (field_info_instances('commerce_line_item', $line_item->type) as $info) {
@@ -514,7 +552,7 @@ function commerce_sos_add_line_item($order, $line_item, $combine) {
 
     // Clear the line item cache so the updated quantity will be available to
     // the ensuing load instead of the original quantity as loaded above.
-    entity_get_controller('commerce_line_item')->resetCache(array($matching_line_item->line_item_id));
+    entity_get_controller('commerce_line_item')->resetCache([$matching_line_item->line_item_id]);
 
     // Update the line item variable for use in the invocation and return value.
     $line_item = $matching_line_item;
@@ -528,9 +566,83 @@ function commerce_sos_add_line_item($order, $line_item, $combine) {
 }
 
 /**
+ * Removes a line item from an order.
+ *
+ * @param object $order
+ *   The order entity.
+ * @param int $line_item_id
+ *   The line item id.
+ *
+ * @throws \Exception
+ */
+function commerce_sos_remove_line_item($order, $line_item_id) {
+  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
+
+  if ($order_wrapper) {
+    $line_item_found = FALSE;
+
+    foreach ($order_wrapper->commerce_line_items as $delta => $line_item_wrapper) {
+      if ($line_item_wrapper->line_item_id->raw() == $line_item_id) {
+        $order_wrapper->commerce_line_items->offsetUnset($delta);
+        $line_item_found = TRUE;
+        break;
+      }
+    }
+
+    if ($line_item_found) {
+      if (commerce_line_item_delete($line_item_id)) {
+        commerce_order_save($order);
+      }
+    }
+    else {
+      throw new Exception(t('Cannot remove line item, the order does not have a line item with ID @id', [
+        '@id' => $line_item_id,
+      ]));
+    }
+  }
+  else {
+    throw new Exception(t('Cannot remove line item, transaction does not have an order created for it.'));
+  }
+}
+
+/**
+ * Updates the quantity of a line item in the transactions' order.
+ *
+ * @param object $order
+ *   The commerce order entity.
+ * @param int $line_item_id
+ *   The line item id.
+ * @param int $quantity
+ *   The number to update the line item by.
+ * @param string $method
+ *   Whether to update or replace the entire quantity.
+ */
+function commerce_sos_update_line_item_quantity($order, $line_item_id, $quantity, $method = 'replace') {
+  $line_item = commerce_line_item_load($line_item_id);
+  $existing_qty = $line_item->quantity;
+
+  if ($method == 'update') {
+    $new_qty = $existing_qty + $quantity;
+  }
+  else {
+    $new_qty = $quantity;
+  }
+
+  // Make sure the line item actually belongs to the order.
+  if ($new_qty > 0 && ($line_item->order_id == $order->order_id) && ((int) $existing_qty != $new_qty)) {
+    $line_item->quantity = $new_qty;
+    commerce_line_item_save($line_item);
+  }
+  elseif ($new_qty == 0) {
+    commerce_sos_remove_line_item($order, $line_item_id);
+  }
+}
+
+/**
  * Returns the header content that is attached to the /cart & checkout forms.
  *
  * @param int $order_id
+ *   The order id.
  *
  * @return string
  *   Returns the html content.
@@ -539,7 +651,7 @@ function commerce_sos_fetch_order_header_content($order_id) {
   $content = '<div class="commerce-sos order-id">
     <span class="label">Order ID:</span>
     <span class="field id-number">' . $order_id
-  . '</span></div>';
+    . '</span></div>';
 
   // Allow users to alter the content.
   drupal_alter('commerce_sos_order_header_content', $order_id, $content);
diff --git a/includes/commerce_sos.discount.inc b/includes/commerce_sos.discount.inc
new file mode 100644
index 0000000..160365d
--- /dev/null
+++ b/includes/commerce_sos.discount.inc
@@ -0,0 +1,539 @@
+<?php
+
+/**
+ * @file
+ * Contains discount related code for the commerce_sos module.
+ */
+
+/**
+ * Retrieves the existing amount for a discount on a line item, if one exists.
+ */
+function commerce_sos_get_existing_line_item_discount_amount($line_item_id, $discount_name = COMMERCE_SOS_LINE_ITEM_DISCOUNT_NAME) {
+  if ($line_item = commerce_line_item_load($line_item_id)) {
+    $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
+    return commerce_sos_get_line_item_discount_data($line_item_wrapper, $discount_name);
+  }
+
+  return FALSE;
+}
+
+/**
+ * Fetches the existing amount for a discount on a line item.
+ */
+function commerce_sos_get_line_item_discount_data($line_item_wrapper, $discount_name) {
+  $data = [
+    'type' => '',
+    'amount' => 0,
+  ];
+
+  if ($component = commerce_sos_get_discount_component($line_item_wrapper->commerce_unit_price, $discount_name)) {
+    $data['type'] = $component['price']['data']['sos_discount_type'];
+    $data['currency_code'] = $component['price']['currency_code'];
+
+    // Found our discount, return its amount.
+    if ($component['price']['data']['sos_discount_type'] == 'percent') {
+      $data['amount'] = $component['price']['data']['sos_discount_rate'] * 100;
+    }
+    else {
+      $data['amount'] = number_format(abs($component['price']['amount'] / 100), 2);
+    }
+  }
+
+  return $data;
+}
+
+/**
+ * Retrieves the price component relating to SOS discount from a price field.
+ *
+ * @param EntityMetadataWrapper $price_wrapper
+ *   A metadata wrapper around a commerce price field.
+ *
+ * @return array|bool
+ *   The price component, or FALSE if none was found.
+ */
+function commerce_sos_get_discount_component(EntityMetadataWrapper $price_wrapper, $discount_name) {
+  $data = (array) $price_wrapper->data->value() + ['components' => []];
+
+  // Look for our discount in each of the price components.
+  foreach ($data['components'] as $key => $component) {
+    if (!empty($component['price']['data']['discount_name'])) {
+      if ($component['price']['data']['discount_name'] == $discount_name) {
+        return $component;
+      }
+    }
+  }
+
+  return FALSE;
+}
+
+/**
+ * Adds a discount to a specific line item in the order.
+ */
+function commerce_sos_add_line_item_discount($type, $line_item_id, $amount) {
+  if ($line_item = commerce_line_item_load($line_item_id)) {
+    $wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
+
+    // Remove any existing discount components on the line item.
+    commerce_sos_remove_discount_components($wrapper->commerce_unit_price, COMMERCE_SOS_LINE_ITEM_DISCOUNT_NAME);
+    $pre_discount_amount = $wrapper->commerce_unit_price->amount->raw();
+
+    commerce_sos_apply_discount($wrapper, $type, $amount);
+
+    $wrapper->commerce_unit_price->amount->set($pre_discount_amount);
+    $wrapper_value = $wrapper->value();
+    commerce_line_item_rebase_unit_price($wrapper_value);
+
+    $wrapper->save();
+  }
+}
+
+/**
+ * Remove discount components from a given price and recalculate the total.
+ *
+ * @param object $price_wrapper
+ *   Wrapped commerce price.
+ */
+function commerce_sos_remove_discount_components($price_wrapper, $discount_name_to_remove) {
+  $discount_amounts = 0;
+
+  $data = (array) $price_wrapper->data->value() + ['components' => []];
+  $component_removed = FALSE;
+  // Remove price components belonging to order discounts.
+  foreach ($data['components'] as $key => $component) {
+    $remove = FALSE;
+
+    // Remove all discount components.
+    if (!empty($component['price']['data']['discount_name'])) {
+      $discount_name = $component['price']['data']['discount_name'];
+
+      if ($discount_name_to_remove == $discount_name) {
+        $remove = TRUE;
+      }
+    }
+
+    if ($remove) {
+      $discount_amounts += $component['price']['amount'];
+
+      unset($data['components'][$key]);
+      $component_removed = TRUE;
+    }
+  }
+  // Don't alter the price components if no components were removed.
+  if (!$component_removed) {
+    return;
+  }
+
+  // Re-save the price without the discounts (if existed).
+  $price_wrapper->data->set($data);
+
+  // Re-set the total price.
+  $new_total = $price_wrapper->amount->raw() - $discount_amounts;
+  $price_wrapper->amount->set($new_total);
+}
+
+/**
+ * Apply a specific type of discount.
+ *
+ * This simply services as a centralized function to control which discount
+ * method(s) to call, rather than each individual piece of coding having to
+ * determine where to call applyPercentDiscount or applyFixedDiscount.
+ */
+function commerce_sos_apply_discount($wrapper, $type, $rate) {
+  switch ($type) {
+    case 'percent':
+      commerce_sos_apply_percent_discount($wrapper, $rate);
+
+      break;
+
+    case 'fixed':
+      commerce_sos_apply_fixed_discount($wrapper, $rate);
+
+      break;
+  }
+}
+
+/**
+ * A modified version of commerce_discount_percentage().
+ */
+function commerce_sos_apply_percent_discount($wrapper, $rate) {
+  if ($rate > 1) {
+    $rate = $rate / 100;
+  }
+
+  $component_data = [
+    'sos_discount_type' => 'percent',
+    'sos_discount_rate' => $rate,
+  ];
+
+  switch ($wrapper->type()) {
+    case 'commerce_order':
+
+      $discount_name = COMMERCE_SOS_ORDER_DISCOUNT_NAME;
+
+      $calculated_discount = 0;
+      // Loop the line items of the order and calculate the total discount.
+      foreach ($wrapper->commerce_line_items as $line_item_wrapper) {
+        $line_item_total = commerce_price_wrapper_value($line_item_wrapper, 'commerce_total', TRUE);
+        $calculated_discount += $line_item_total['amount'] * $rate;
+      }
+
+      if ($calculated_discount) {
+        $discount_amount = [
+          'amount' => $calculated_discount * -1,
+          'currency_code' => $wrapper->commerce_order_total->currency_code->value(),
+        ];
+
+        // Modify the existing discount line item or add a new line item
+        // if that fails.
+        if (!commerce_sos_set_existing_line_item_price($wrapper, $discount_name, $discount_amount, $component_data)) {
+          commerce_sos_discount_add_line_item($wrapper, $discount_name, $discount_amount, $component_data);
+        }
+      }
+      else {
+        commerce_sos_remove_order_discount_line_items($wrapper);
+      }
+
+      break;
+
+    case 'commerce_line_item':
+
+      $discount_name = COMMERCE_SOS_LINE_ITEM_DISCOUNT_NAME;
+
+      $unit_price = commerce_price_wrapper_value($wrapper, 'commerce_unit_price', TRUE);
+      $calculated_discount = $unit_price['amount'] * $rate * -1;
+
+      if ($calculated_discount) {
+        $discount_amount = [
+          'amount' => $calculated_discount,
+          'currency_code' => $unit_price['currency_code'],
+        ];
+
+        commerce_sos_add_price_component($wrapper, $discount_name, $discount_amount, $component_data);
+      }
+      break;
+  }
+}
+
+/**
+ * A modified version of commerce_discount_fixed_amount().
+ */
+function commerce_sos_apply_fixed_discount(EntityMetadataWrapper $wrapper, $discount_amount) {
+  $discount_price['amount'] = -$discount_amount;
+
+  $component_data = [
+    'sos_discount_type' => 'fixed',
+  ];
+
+  switch ($wrapper->type()) {
+    case 'commerce_order':
+
+      $discount_name = COMMERCE_SOS_ORDER_DISCOUNT_NAME;
+
+      if ($discount_amount) {
+        $discount_price['currency_code'] = $wrapper->commerce_order_total->currency_code->value();
+
+        // If the discount will bring the order to less than zero, set the
+        // discount amount so that it stops at zero.
+        // Loop the line items of the order and calculate the total discount.
+        $order_amount = 0;
+
+        foreach ($wrapper->commerce_line_items as $line_item_wrapper) {
+          $line_item_total = commerce_price_wrapper_value($line_item_wrapper, 'commerce_total', TRUE);
+          $order_amount += $line_item_total['amount'];
+        }
+
+        if (-$discount_price['amount'] > $order_amount) {
+          $discount_price['amount'] = -$order_amount;
+        }
+
+        // Modify the existing discount line item or add a new one if that
+        // fails.
+        if (!commerce_sos_set_existing_line_item_price($wrapper, $discount_name, $discount_price, $component_data)) {
+          commerce_sos_discount_add_line_item($wrapper, $discount_name, $discount_price, $component_data);
+        }
+      }
+      else {
+        commerce_sos_remove_order_discount_line_items($wrapper);
+      }
+
+      break;
+
+    case 'commerce_line_item':
+
+      $discount_name = COMMERCE_SOS_LINE_ITEM_DISCOUNT_NAME;
+
+      if ($discount_amount) {
+
+        // Do not allow negative line item totals.
+        $line_item_amount = $wrapper->commerce_unit_price->amount->value();
+        if (-$discount_price['amount'] > $line_item_amount) {
+          $discount_price['amount'] = -$line_item_amount;
+        }
+
+        $discount_price['currency_code'] = $wrapper->commerce_unit_price->currency_code->value();
+
+        commerce_sos_add_price_component($wrapper, $discount_name, $discount_price, $component_data);
+      }
+      break;
+  }
+}
+
+/**
+ * Updates the unit price of an existing discount line item.
+ *
+ * Non-discount line items are ignored.
+ *
+ * @param EntityDrupalWrapper $order_wrapper
+ *   The wrapped order entity.
+ * @param string $discount_name
+ *   The name of the discount being applied.
+ * @param array $discount_price
+ *   The discount amount price array (amount, currency_code).
+ * @param array $component_data
+ *   Any price data to merge into the component.
+ *
+ * @return bool
+ *   TRUE if an existing line item was successfully modified, FALSE otherwise.
+ */
+function commerce_sos_set_existing_line_item_price(EntityDrupalWrapper $order_wrapper, $discount_name, array $discount_price, array $component_data = []) {
+  $modified_existing = FALSE;
+  foreach ($order_wrapper->commerce_line_items as $line_item_wrapper) {
+    if ($line_item_wrapper->getBundle() == 'commerce_sos_discount') {
+      // Add the discount component price if the line item was originally
+      // added by discount module.
+      $line_item = $line_item_wrapper->value();
+      if (isset($line_item->data['discount_name']) && $line_item->data['discount_name'] == $discount_name) {
+        commerce_sos_set_price_component($line_item_wrapper, $discount_name, $discount_price, $component_data);
+        $modified_existing = TRUE;
+        $line_item_wrapper->save();
+      }
+    }
+  }
+
+  return $modified_existing;
+}
+
+/**
+ * Sets a discount price component to the provided line item.
+ *
+ * @param EntityDrupalWrapper $line_item_wrapper
+ *   The wrapped line item entity.
+ * @param string $discount_name
+ *   The name of the discount being applied.
+ * @param array $discount_amount
+ *   The discount amount price array (amount, currency_code).
+ * @param array $component_data
+ *   Any price data to merge into the component.
+ */
+function commerce_sos_set_price_component(EntityDrupalWrapper $line_item_wrapper, $discount_name, array $discount_amount, array $component_data = []) {
+  $unit_price = commerce_price_wrapper_value($line_item_wrapper, 'commerce_unit_price', TRUE);
+  // Currencies don't match, abort.
+  if ($discount_amount['currency_code'] != $unit_price['currency_code']) {
+    return;
+  }
+
+  $discount_amount['data'] = [
+    'discount_name' => $discount_name,
+    'sos_discount_component_title' => commerce_sos_get_discount_component_title($discount_name),
+  ];
+
+  $discount_amount['data'] += $component_data;
+
+  // Set the new unit price.
+  $line_item_wrapper->commerce_unit_price->amount = $discount_amount['amount'];
+  $line_item_wrapper->commerce_unit_price->data = commerce_price_component_delete($line_item_wrapper->commerce_unit_price->value(), 'discount|sos_order_discount');
+
+  // Add the discount amount as a price component.
+  $price = $line_item_wrapper->commerce_unit_price->value();
+  $type = check_plain('discount|' . $discount_name);
+  $line_item_wrapper->commerce_unit_price->data = commerce_price_component_add($price, $type, $discount_amount, TRUE, TRUE);
+
+  commerce_sos_calculate_taxes($line_item_wrapper);
+
+  // Update the line item total.
+  commerce_sos_update_line_item_total($line_item_wrapper);
+}
+
+/**
+ * Creates a discount line item on the provided order.
+ *
+ * @param EntityDrupalWrapper $order_wrapper
+ *   The wrapped order entity.
+ * @param string $discount_name
+ *   The name of the discount being applied.
+ * @param array $discount_amount
+ *   The discount amount price array (amount, currency_code).
+ * @param array $data
+ *   Any additional data to be added to the price component.
+ */
+function commerce_sos_discount_add_line_item(EntityDrupalWrapper $order_wrapper, $discount_name, array $discount_amount, array $data) {
+  // Create a new line item.
+  $values = [
+    'type' => 'commerce_sos_discount',
+    'order_id' => $order_wrapper->order_id->value(),
+    'quantity' => 1,
+    // Flag the line item.
+    'data' => ['discount_name' => $discount_name],
+  ];
+  $discount_line_item = entity_create('commerce_line_item', $values);
+  $discount_line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $discount_line_item);
+
+  // Initialize the line item unit price.
+  $discount_line_item_wrapper->commerce_unit_price->amount = 0;
+  $discount_line_item_wrapper->commerce_unit_price->currency_code = $discount_amount['currency_code'];
+
+  // Reset the data array of the line item total field to only include a
+  // base price component, set the currency code from the order.
+  $base_price = [
+    'amount' => 0,
+    'currency_code' => $discount_amount['currency_code'],
+    'data' => [],
+  ];
+
+  $discount_line_item_wrapper->commerce_unit_price->data = commerce_price_component_add($base_price, 'base_price', $base_price, TRUE);
+
+  // Add the discount price component.
+  commerce_sos_add_price_component($discount_line_item_wrapper, $discount_name, $discount_amount, $data);
+
+  commerce_sos_calculate_taxes($discount_line_item_wrapper);
+
+  // Save the line item and add it to the order.
+  $discount_line_item_wrapper->save();
+  $order_wrapper->commerce_line_items[] = $discount_line_item_wrapper;
+}
+
+/**
+ * Adds a discount price component to the provided line item.
+ *
+ * @param EntityDrupalWrapper $line_item_wrapper
+ *   The wrapped line item entity.
+ * @param string $discount_name
+ *   The name of the discount being applied.
+ * @param array $discount_amount
+ *   The discount amount price array (amount, currency_code).
+ * @param array $data
+ *   Any additional data to be merged into the new price component's data
+ *   array.
+ */
+function commerce_sos_add_price_component(EntityDrupalWrapper $line_item_wrapper, $discount_name, array $discount_amount, array $data) {
+  $unit_price = commerce_price_wrapper_value($line_item_wrapper, 'commerce_unit_price', TRUE);
+  $current_amount = $unit_price['amount'];
+  // Currencies don't match, abort.
+  if ($discount_amount['currency_code'] != $unit_price['currency_code']) {
+    return;
+  }
+
+  // Calculate the updated amount and create a price array representing the
+  // difference between it and the current amount.
+  $updated_amount = commerce_round(COMMERCE_ROUND_HALF_UP, $current_amount + $discount_amount['amount']);
+
+  $difference = [
+    'amount' => commerce_round(COMMERCE_ROUND_HALF_UP, $discount_amount['amount']),
+    'currency_code' => $discount_amount['currency_code'],
+    'data' => [
+      'discount_name' => $discount_name,
+      'sos_discount_component_title' => commerce_sos_get_discount_component_title($discount_name),
+    ],
+  ];
+
+  $difference['data'] += $data;
+
+  // Set the new unit price.
+  $line_item_wrapper->commerce_unit_price->amount = $updated_amount;
+
+  // Add the discount amount as a price component.
+  $price = $line_item_wrapper->commerce_unit_price->value();
+  $type = check_plain('discount|' . $discount_name);
+  $line_item_wrapper->commerce_unit_price->data = commerce_price_component_add($price, $type, $difference, TRUE, TRUE);
+
+  // Update the line item total.
+  commerce_sos_update_line_item_total($line_item_wrapper);
+}
+
+/**
+ * Retrieves a display name for a specific discount type.
+ */
+function commerce_sos_get_discount_component_title($discount_name) {
+  switch ($discount_name) {
+    case COMMERCE_SOS_LINE_ITEM_DISCOUNT_NAME:
+      return t('Product Discount');
+
+    case COMMERCE_SOS_ORDER_DISCOUNT_NAME:
+      return t('Order Discount');
+
+    default:
+      return FALSE;
+  }
+}
+
+/**
+ * Update commerce_total without saving line item.
+ *
+ * To have the order total refreshed without saving the line item.
+ * Taken from CommerceLineItemEntityController::save().
+ */
+function commerce_sos_update_line_item_total($line_item_wrapper) {
+  $quantity = $line_item_wrapper->quantity->value();
+
+  // Update the total of the line item based on the quantity and unit price.
+  $unit_price = commerce_price_wrapper_value($line_item_wrapper, 'commerce_unit_price', TRUE);
+
+  $line_item_wrapper->commerce_total->amount = $quantity * $unit_price['amount'];
+  $line_item_wrapper->commerce_total->currency_code = $unit_price['currency_code'];
+
+  // Add the components multiplied by the quantity to the data array.
+  if (empty($unit_price['data']['components'])) {
+    $unit_price['data']['components'] = [];
+  }
+  else {
+    foreach ($unit_price['data']['components'] as $key => &$component) {
+      $component['price']['amount'] *= $quantity;
+    }
+  }
+
+  // Set the updated data array to the total price.
+  $line_item_wrapper->commerce_total->data = $unit_price['data'];
+  // Reset the cache because we aren't saving it.
+  entity_get_controller('commerce_line_item')->resetCache([$line_item_wrapper->getIdentifier()]);
+}
+
+/**
+ * Calculate the taxes on a given line item.
+ *
+ * @param EntityMetadataWrapper $line_item_wrapper
+ *   A metadata wrapper representing the line item.
+ */
+function commerce_sos_calculate_taxes(EntityMetadataWrapper $line_item_wrapper) {
+  if (module_exists('commerce_tax')) {
+    module_load_include('inc', 'commerce_tax', 'commerce_tax.rules');
+
+    // First remove all existing tax components from the line item if any
+    // exist.
+    commerce_tax_remove_taxes($line_item_wrapper, FALSE, array_keys(commerce_tax_rates()));
+
+    foreach (commerce_tax_types() as $name => $type) {
+      commerce_tax_calculate_by_type($line_item_wrapper->value(), $name);
+    }
+  }
+}
+
+/**
+ * Removes all SOS discount line items from an order.
+ *
+ * @param EntityMetadataWrapper $order_wrapper
+ *   The order entity.
+ */
+function commerce_sos_remove_order_discount_line_items(EntityMetadataWrapper $order_wrapper) {
+  $line_items_to_delete = [];
+
+  foreach ($order_wrapper->commerce_line_items as $delta => $line_item_wrapper) {
+    if ($line_item_wrapper->type->value() == 'commerce_sos_discount') {
+      $order_wrapper->commerce_line_items->offsetUnset($delta);
+      $line_items_to_delete[] = $line_item_wrapper->line_item_id;
+    }
+  }
+
+  if ($line_items_to_delete) {
+    commerce_line_item_delete_multiple($line_items_to_delete);
+  }
+}
\ No newline at end of file
diff --git a/includes/commerce_sos.form.inc b/includes/commerce_sos.form.inc
index 604fa3d..e6d4d77 100644
--- a/includes/commerce_sos.form.inc
+++ b/includes/commerce_sos.form.inc
@@ -9,31 +9,36 @@
  * The create a new order form.
  */
 function commerce_sos_create_new_order_form($form, &$form_state, $order) {
+  form_load_include($form_state, 'inc', 'commerce_sos', 'includes/commerce_sos.common');
+
+  // Attach our CSS.
+  $form['#attached']['css'][] = drupal_get_path('module', 'commerce_sos') . '/css/commerce_sos_style.css';
+
   $options = [
     'new_customer' => t('New Customer')
     . '<p>'
-    . t('You\'ll create an account for the customer, including billing/shipping details')
+    . t('You\'ll create an account for the customer, including billing/shipping details.')
     . '</p>',
     'existing_customer' => t('Existing Customer')
     . '<p>'
-    . t('Find the customer by email, name or other account details')
+    . t('Find the customer by email, name or other account details.')
     . '</p>',
   ];
 
-  // Get the query params to see if existing customer value exists.
+  // Get the query params to see if existing customer values exist.
   $query_parameters = drupal_get_query_parameters();
   $form['customer'] = [
     '#type' => 'radios',
     '#title' => t('Customer'),
     '#required' => TRUE,
     '#options' => $options,
-    '#default_value' => isset($query_parameters['existing_customer']) ? 'existing_customer' : 'new_customer',
+    '#default_value' => isset($query_parameters['existing_customer_email']) || isset($query_parameters['existing_customer']) ? 'existing_customer' : 'new_customer',
   ];
 
   $form['existing_customer_email'] = [
     '#type' => 'textfield',
     '#title' => t('Customer Email'),
-    '#default_value' => isset($form_state['values']['existing_customer_email']) ? $form_state['values']['existing_customer_email'] : '',
+    '#default_value' => isset($query_parameters['existing_customer_email']) ? $query_parameters['existing_customer_email'] : (isset($form_state['values']['existing_customer_email']) ? $form_state['values']['existing_customer_email'] : ''),
     '#states' => [
       'visible' => [
         ':input[name="customer"]' => ['value' => 'existing_customer'],
@@ -44,7 +49,7 @@ function commerce_sos_create_new_order_form($form, &$form_state, $order) {
   $form['existing_customer_name'] = [
     '#type' => 'textfield',
     '#title' => t('Name'),
-    '#default_value' => isset($form_state['values']['existing_customer_name']) ? $form_state['values']['existing_customer_name'] : '',
+    '#default_value' => isset($query_parameters['existing_customer_name']) ? $query_parameters['existing_customer_name'] : (isset($form_state['values']['existing_customer_name']) ? $form_state['values']['existing_customer_name'] : ''),
     '#states' => [
       'visible' => [
         ':input[name="customer"]' => ['value' => 'existing_customer'],
@@ -55,7 +60,7 @@ function commerce_sos_create_new_order_form($form, &$form_state, $order) {
   $form['existing_customer_address'] = [
     '#type' => 'textfield',
     '#title' => t('Street Address'),
-    '#default_value' => isset($form_state['values']['existing_customer_address']) ? $form_state['values']['existing_customer_address'] : '',
+    '#default_value' => isset($query_parameters['existing_customer_address']) ? $query_parameters['existing_customer_address'] : (isset($form_state['values']['existing_customer_address']) ? $form_state['values']['existing_customer_address'] : ''),
     '#states' => [
       'visible' => [
         ':input[name="customer"]' => ['value' => 'existing_customer'],
@@ -80,42 +85,44 @@ function commerce_sos_create_new_order_form($form, &$form_state, $order) {
     '#element_key' => 'find-existing-customer',
   ];
 
-  // The existing customers table.
-  $markup = '';
-  if (isset($form_state['existing_customers'])) {
-    $rows = $form_state['existing_customers']['rows'];
-
-    // Create a 'Use' button element for each row.
-    foreach ($rows as $key => &$row) {
-      $element = $form['use_customer'][$key] = [
-        '#type' => 'submit',
-        '#value' => t('Use'),
-        '#uid' => $key,
-        '#submit' => ['commerce_sos_use_customer_submit'],
-        '#name' => 'use-customer-' . $key,
-        '#element_key' => 'use-customer-' . $key,
-      ];
-      $row[] = drupal_render($element);
-    }
-    $form_state['existing_customers']['rows'] = $rows;
-    $markup = theme('table', [
-      'header' => $form_state['existing_customers']['header'],
-      'rows' => $form_state['existing_customers']['rows'],
-      'empty' => t('We couldn\'t find customers that match the search criteria.'),
-    ]);
-  }
-  $form['existing_customers_table'] = [
-    '#type' => 'item',
-    '#markup' => $markup,
+  // Our existing customers fieldset, which will hold the table.
+  $form['existing_customers_fieldset'] = [
+    '#type' => 'fieldset',
+    '#theme' => 'commerce_sos_existing_users_table',
+    '#prefix' => '<div id="sos-existing-customers-table">',
+    '#suffix' => '</div>',
+    '#attributes' => ['class' => ['element-invisible']],
     '#states' => [
       'visible' => [
         ':input[name="customer"]' => ['value' => 'existing_customer'],
       ],
     ],
-    '#prefix' => '<div id="sos-existing-customers-table">',
-    '#suffix' => '</div>',
   ];
 
+  // The existing customers table.
+  // If we're paginating, we'll have the page number and the query filters in
+  // the paramaters, so let's run the query with those filters.
+  if (!isset($form_state['existing_customers']) && isset($query_parameters['existing_customer_email'])) {
+    $results = commerce_sos_find_existing_customer($query_parameters['existing_customer_email'], $query_parameters['existing_customer_name'], $query_parameters['existing_customer_address']);
+    $form_state['existing_customers'] = $results;
+  }
+
+  // If we've got existing customers, generate the elements for the table.
+  if (isset($form_state['existing_customers'])) {
+    // Pager fix as we're displaying the table via ajax.
+    $_GET['q'] = 'admin/commerce/sos/orders/add';
+    $form['existing_customers_fieldset']['#query_parameters'] = [
+      'existing_customer_email' => isset($form_state['values']['existing_customer_email']) ? $form_state['values']['existing_customer_email'] : $query_parameters['existing_customer_email'],
+      'existing_customer_name' => isset($form_state['values']['existing_customer_name']) ? $form_state['values']['existing_customer_name'] : $query_parameters['existing_customer_name'],
+      'existing_customer_address' => isset($form_state['values']['existing_customer_address']) ? $form_state['values']['existing_customer_address'] : $query_parameters['existing_customer_address'],
+    ];
+
+    // Make the fieldset visible now.
+    $form['existing_customers_fieldset']['#attributes'] = [];
+
+    _commerce_sos_create_existing_customers_table_elements($form['existing_customers_fieldset'], $form_state, $form_state['existing_customers']);
+  }
+
   $form['submit'] = [
     '#type' => 'submit',
     '#value' => t('Next'),
@@ -138,68 +145,56 @@ function commerce_sos_find_existing_customer_validate($form, &$form_state) {
   if (empty($form_state['values']['existing_customer_email']) && empty($form_state['values']['existing_customer_name']) && empty($form_state['values']['existing_customer_address'])) {
     form_set_error('existing_customer_email', t('At least one field must be filled out.'));
   }
-
-  // Validate email address.
-  if (!empty($form_state['values']['existing_customer_email']) && !valid_email_address($form_state['values']['existing_customer_email'])) {
-    form_set_error('existing_customer_email', t('Please enter a valid email address.'));
-  }
 }
 
 /**
  * Validate function for the find existing customer button.
  */
 function commerce_sos_find_existing_customer_submit($form, &$form_state) {
-  form_load_include($form_state, 'inc', 'commerce_sos', 'includes/commerce_sos.common');
+  // Get the results based on the filters entered.
   $results = commerce_sos_find_existing_customer($form_state['values']['existing_customer_email'], $form_state['values']['existing_customer_name'], $form_state['values']['existing_customer_address']);
 
-  $form_state['existing_customers'] = _commerce_sos_create_existing_customers_table_elements($results);
+  $form_state['existing_customers'] = $results;
   $form_state['rebuild'] = TRUE;
 }
 
 /**
- * Creates and returns the headers and rows for the existing customers table.
+ * Generates the existing customers table elements.
  *
+ * @param array $element
+ *   The $form['exisiting_users_fieldset'] element.
  * @param array $existing_customers
  *   An array of existing customers fetched from the db.
- * @param int $order_id
- *   The order id, if it exists, for creating the 'use' link.
- *
- * @return array
- *   Returns an array with the headers and rows.
  */
-function _commerce_sos_create_existing_customers_table_elements(array $existing_customers) {
-  $profiles = [];
-
-  $header = [
-    t('Name'),
-    t('Email'),
-    t('Address'),
-    t('City'),
-    t('Operation'),
-  ];
-
-  $rows = [];
+function _commerce_sos_create_existing_customers_table_elements(array &$element, array &$form_state, array $existing_customers) {
   if (!empty($existing_customers)) {
     foreach ($existing_customers as $key => $customer) {
-      $row = [];
-      $row[] = $customer->commerce_customer_address_first_name . ' ' . $customer->commerce_customer_address_last_name;
-      $row[] = $customer->mail;
-      $row[] = $customer->commerce_customer_address_thoroughfare;
-      $row[] = $customer->commerce_customer_address_locality;
-
-      $rows[$customer->uid] = $row;
-      $profiles[$customer->uid] = [
-        'billing_profile_id' => $customer->billing,
-        'shipping_profile_id' => $customer->shipping,
+      $element[$key]['customer_name'] = [
+        '#markup' => $customer->commerce_customer_address_first_name . ' ' . $customer->commerce_customer_address_last_name,
+      ];
+      $element[$key]['mail'] = [
+        '#markup' => $customer->mail,
+      ];
+      $element[$key]['address'] = [
+        '#markup' => $customer->commerce_customer_address_thoroughfare,
+      ];
+      $element[$key]['city'] = [
+        '#markup' => $customer->commerce_customer_address_locality,
       ];
+      $element[$key]['use'] = [
+        '#type' => 'submit',
+        '#value' => t('Use'),
+        '#uid' => $key,
+        '#submit' => ['commerce_sos_use_customer_submit'],
+        '#name' => 'use-customer-' . $key,
+        '#element_key' => 'use-customer-' . $key,
+      ];
+
+      // Save the profile ids in the form state.
+      $form_state['existing_customers']['profiles'][$key]['billing_profile_id'] = $customer->billing;
+      $form_state['existing_customers']['profiles'][$key]['shipping_profile_id'] = $customer->shipping;
     }
   }
-
-  return [
-    'header' => $header,
-    'rows' => $rows,
-    'profiles' => $profiles,
-  ];
 }
 
 /**
@@ -211,7 +206,7 @@ function commerce_sos_use_customer_submit($form, &$form_state) {
   $profiles['billing_information'] = commerce_customer_profile_load($form_state['existing_customers']['profiles'][$form_state['triggering_element']['#uid']]['billing_profile_id']);
   $profiles['shipping_information'] = commerce_customer_profile_load($form_state['existing_customers']['profiles'][$form_state['triggering_element']['#uid']]['shipping_profile_id']);
   $customer = user_load($form_state['triggering_element']['#uid']);
-  $order = commerce_sos_save_commerce_order($order, $customer, 'pending', $profiles);
+  $order = commerce_sos_save_commerce_order($order, $customer, 'checkout_checkout', $profiles);
 
   $form_state['redirect'] = [
     'admin/commerce/sos/orders/' . $order->order_id . '/edit',
@@ -222,7 +217,7 @@ function commerce_sos_use_customer_submit($form, &$form_state) {
  * Ajax callback for the find existing customer button.
  */
 function commerce_sos_find_existing_customers_callback($form, &$form_state) {
-  return $form['existing_customers_table'];
+  return $form['existing_customers_fieldset'];
 }
 
 /**
@@ -234,7 +229,7 @@ function commerce_sos_create_new_order_form_submit($form, &$form_state) {
   // If we don't have an order id, save this order.
   if (empty($order->order_id)) {
     form_load_include($form_state, 'inc', 'commerce_sos', 'includes/commerce_sos.common');
-    $order = commerce_sos_save_commerce_order($form_state['build_info']['args'][0], NULL, 'pending', []);
+    $order = commerce_sos_save_commerce_order($form_state['build_info']['args'][0], NULL, 'checkout_checkout', []);
   }
   $form_state['redirect'] = 'admin/commerce/sos/orders/' . $order->order_id . '/new';
 }
@@ -245,6 +240,9 @@ function commerce_sos_create_new_order_form_submit($form, &$form_state) {
 function commerce_sos_create_new_customer_form($form, &$form_state) {
   $form['#tree'] = TRUE;
 
+  // Attach our CSS.
+  $form['#attached']['css'][] = drupal_get_path('module', 'commerce_sos') . '/css/commerce_sos_style.css';
+
   drupal_set_title(t('New Customer'));
 
   // If email field ajax was triggered, check if we have an email that is
@@ -483,9 +481,9 @@ function commerce_sos_create_new_customer_form_submit($form, &$form_state) {
 
       $uri = entity_uri('user', $account);
       drupal_set_message(t('A welcome message with further instructions has been e-mailed to the new user <a href="@url">%name</a>.', [
-          '@url' => url($uri['path'], $uri['options']),
-          '%name' => $account->name
-        ]
+        '@url' => url($uri['path'], $uri['options']),
+        '%name' => $account->name,
+      ]
       ));
     }
   }
@@ -522,7 +520,7 @@ function commerce_sos_create_new_customer_form_submit($form, &$form_state) {
   drupal_set_message(t('Successfully saved billing and shipping profiles.'));
 
   // Now save our new order with the billing and shipping profiles.
-  $order = commerce_sos_save_commerce_order($form_state['build_info']['args'][0], $form_state['customer'], 'pending', [
+  $order = commerce_sos_save_commerce_order($form_state['build_info']['args'][0], $form_state['customer'], 'checkout_checkout', [
     'billing_information' => $form_state['customer']->billing_information,
     'shipping_information' => $form_state['customer']->shipping_information,
   ]);
@@ -537,9 +535,12 @@ function commerce_sos_create_new_customer_form_submit($form, &$form_state) {
  */
 function commerce_sos_order_form($form, &$form_state) {
   form_load_include($form_state, 'inc', 'commerce_sos', 'includes/commerce_sos.common');
+  form_load_include($form_state, 'inc', 'commerce_sos', 'includes/commerce_sos.discount');
+  form_load_include($form_state, 'inc', 'commerce_sos', 'includes/commerce_sos.vertical_tabs');
 
   // Load the order.
   $order = $form_state['build_info']['args'][0];
+  $form_state['edit_order'] = $form_state['build_info']['args'][1] == 'edit' ? TRUE : FALSE;
 
   if (empty($order)) {
     drupal_set_message(t('Invalid order.'), 'error');
@@ -550,9 +551,45 @@ function commerce_sos_order_form($form, &$form_state) {
   $form_state['commerce_order'] = $order;
   $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
 
+  if ($form_state['edit_order']) {
+    if ($order_wrapper->status->value() != 'checkout_checkout') {
+      drupal_set_title(t('Edit Order'));
+    }
+  }
+  else {
+    drupal_set_title(t('Order @order_id', ['@order_id' => $order_wrapper->order_id->value()]));
+  }
+
   // Load the billing/shipping profiles.
-  $form_state['billing_profile'] = commerce_customer_profile_load($order_wrapper->commerce_customer_billing->value()->profile_id);
-  $form_state['shipping_profile'] = commerce_customer_profile_load($order_wrapper->commerce_customer_shipping->value()->profile_id);
+  // If it doesn't exist and we're editing the order, create one.
+  if (!isset($order_wrapper->commerce_customer_billing->value()->profile_id) && $form_state['edit_order']) {
+    $new_profile = new stdClass();
+    $new_profile->type = 'billing';
+    $new_profile->uid = $order->uid;
+    $new_profile->status = 1;
+    commerce_customer_profile_save($new_profile);
+    $form_state['billing_profile'] = $new_profile;
+    $order_wrapper->commerce_customer_billing->set($form_state['billing_profile']->profile_id);
+    $order_wrapper->save();
+  }
+  else {
+    $form_state['billing_profile'] = commerce_customer_profile_load($order_wrapper->commerce_customer_billing->value()->profile_id);
+  }
+
+  // If the shipping doesn't exist and we're editing the order, create one.
+  if (!isset($order_wrapper->commerce_customer_shipping->value()->profile_id) && $form_state['edit_order']) {
+    $new_profile = new stdClass();
+    $new_profile->type = 'shipping';
+    $new_profile->uid = $order->uid;
+    $new_profile->status = 1;
+    commerce_customer_profile_save($new_profile);
+    $form_state['shipping_profile'] = $new_profile;
+    $order_wrapper->commerce_customer_shipping->set($form_state['shipping_profile']->profile_id);
+    $order_wrapper->save();
+  }
+  else {
+    $form_state['shipping_profile'] = commerce_customer_profile_load($order_wrapper->commerce_customer_shipping->value()->profile_id);
+  }
 
   // Load the customer of this order.
   $customer = user_load($order->uid);
@@ -572,7 +609,10 @@ function commerce_sos_order_form($form, &$form_state) {
 
   // Set the form title.
   if (!empty($order->order_id)) {
-    $title = '<h2>' . t('Order: @order_id', ['@order_id' => $order->order_id]) . '</h2>';
+    $title = '<h2>' . t('Order: @order_id', ['@order_id' => $order_wrapper->order_id->value()]) . '</h2>';
+    if (!$form_state['edit_order']) {
+      $title .= '<h3>' . t('Status: @status', ['@status' => $order_wrapper->status->value()]) . '</h3>';
+    }
   }
   else {
     $title = '<h2>' . t('New Order') . '</h2>';
@@ -584,44 +624,68 @@ function commerce_sos_order_form($form, &$form_state) {
 
   $form['customer_info'] = [
     '#type' => 'fieldset',
+    '#title' => $form_state['edit_order'] ? '<h3>' . t('Customer Information') . '</h3>' : '',
     '#tree' => FALSE,
-    '#prefix' => '<div id="sos-customer-information"><h3>' . t('Customer Information') . '</h3>',
+    '#prefix' => '<div id="sos-customer-information">',
     '#suffix' => '</div>',
   ];
 
-  $address_info = ['profile' => $form_state['billing_profile'], 'customer' => $customer];
+  $address_info = [
+    'profile' => $form_state['billing_profile'],
+    'customer' => $customer,
+  ];
   $form['customer_info']['billing_address'] = [
-    '#markup' => '<div id="sos-order-billing-address">' . commerce_sos_print_address_details($address_info) . '</div>',
+    '#markup' => '<div id="sos-order-billing-address">' . commerce_sos_print_address_details($order, $address_info) . '</div>',
 
   ];
 
-  $address_info = ['profile' => $form_state['shipping_profile'], 'customer' => $customer];
+  $address_info = [
+    'profile' => $form_state['shipping_profile'],
+    'customer' => $customer,
+  ];
   $form['customer_info']['shipping_address'] = [
-    '#markup' => '<div id="sos-order-shipping-address">' . commerce_sos_print_address_details($address_info) . '</div>',
+    '#markup' => '<div id="sos-order-shipping-address">' . commerce_sos_print_address_details($order, $address_info) . '</div>',
   ];
 
   // Check if we've got any ajax clicks.
   _commerce_sos_ajax_check($form, $form_state);
 
+  // Load and update the order again if we've got any updated fields.
+  if (isset($form_state['order_updated']) && $form_state['order_updated'] == TRUE) {
+    $order = commerce_order_load($order->order_id);
+    commerce_order_calculate_total($order_wrapper->value());
+    $order_wrapper->save();
+    $form_state['commerce_order'] = $order_wrapper->value();
+  }
+
+  // Add existing line items to the form state.
+  _commerce_sos_add_existing_line_items($form, $form_state);
+
   // Add product search fields.
-  $form += _commerce_sos_generate_product_search_fields($form, $form_state);
+  if ($form_state['edit_order']) {
+    $form += _commerce_sos_generate_product_search_fields($form, $form_state);
+  }
 
   // Add products table fields.
   $form += _commerce_sos_add_products_table_fields($form, $form_state);
 
-  $form['save_order'] = [
-    '#type' => 'submit',
-    '#value' => t('Save Order for Later Payment'),
-    '#submit' => ['commerce_sos_save_order_for_later_submit'],
-  ];
+  if ($form_state['edit_order']) {
+    // Save order button.
+    $form['save_order'] = [
+      '#type' => 'submit',
+      '#value' => t('Save Order for Later Payment'),
+      '#submit' => ['commerce_sos_save_order_for_later_submit'],
+    ];
 
-  $form['void_order'] = [
-    '#type' => 'submit',
-    '#value' => t('Void Order'),
-    '#submit' => ['commerce_sos_void_order_submit'],
-  ];
+    // Void order button.
+    $form['void_order'] = [
+      '#type' => 'submit',
+      '#value' => t('Void Order'),
+      '#submit' => ['commerce_sos_void_order_submit'],
+    ];
+  }
 
-  // Settings for our product search autocomplete.
+  // Settings for our order form.
   $js_settings = [
     'productAutoCompleteUrl' => url('admin/commerce/sos/product/autocomplete'),
   ];
@@ -655,7 +719,7 @@ function _commerce_sos_generate_product_search_fields(array $form, array &$form_
   // The product autocomplete search field.
   $form['product_search'] = [
     '#type' => 'textfield',
-    '#title' => '<h3>' . t('Find Products') . '</h3>',
+    '#title' => '<h3>' . t('Find Products') . '</h3>' . t('Product Search'),
     '#description' => t('Add items to the order, select options & quantities below.'),
     '#size' => 60,
     '#attributes' => [
@@ -666,7 +730,7 @@ function _commerce_sos_generate_product_search_fields(array $form, array &$form_
       'placeholder' => t('SKU, Product Title, Keywords'),
     ],
     '#element_validate' => ['commerce_sos_validate_product_input'],
-    '#prefix' => '<h2>' . t('Order Details') . '</h2>',
+    '#prefix' => '<h3>' . t('Order Details') . '</h3>',
   ];
 
   // A hidden field which will grab the product sku added in the product search.
@@ -675,7 +739,7 @@ function _commerce_sos_generate_product_search_fields(array $form, array &$form_
     '#title' => NULL,
     '#ajax' => [
       'callback' => 'commerce_sos_add_products_ajax_callback',
-      'wrapper' => 'sos-products-table',
+      'wrapper' => 'sos-products-table-wrapper',
     ],
     '#attributes' => [
       'class' => ['commerce-sos-product-sku-input'],
@@ -702,9 +766,11 @@ function commerce_sos_validate_product_input($element, &$form_state, $form) {
  */
 function commerce_sos_add_products_ajax_callback($form, &$form_state) {
   $commands = [];
-  $commands[] = ajax_command_replace('#sos-products-table', drupal_render($form['products']));
+  $commands[] = ajax_command_replace('#sos-products-table-wrapper', drupal_render($form['products']));
   $commands[] = ajax_command_remove('div.messages');
-  $commands[] = ajax_command_prepend('#commerce-sos-order-form', theme('status_messages'));
+  $commands[] = ajax_command_prepend('#sos-products-table-wrapper', theme('status_messages'));
+  $commands[] = ajax_command_replace('#sos-vertical-tabs-wrapper', drupal_render($form['additional_settings']));
+  $commands[] = ajax_command_replace('#sos-order-total-summary', drupal_render($form['order_total_summary']));
 
   return ['#type' => 'ajax', '#commands' => $commands];
 }
@@ -714,20 +780,92 @@ function commerce_sos_add_products_ajax_callback($form, &$form_state) {
  */
 function _commerce_sos_ajax_check(&$form, &$form_state) {
   if (isset($form_state['triggering_element'])) {
-    form_load_include($form_state, 'inc', 'commerce_sos', 'includes/commerce_sos.common');
-    $order = $form_state['build_info']['args'][0];
-
-    switch ($form_state['triggering_element']['#element_key']) {
-      case 'product-sku':
-        // Add the new product to our form_state array.
-        $product_info = commerce_sos_get_product_details($form_state['values']['product_sku']);
-        $line_item = commerce_sos_add_product($order, $product_info['product']);
-        $form_state['added_products'][$line_item->line_item_id] = [
-          'line_item' => $line_item,
-          'product_info' => $product_info,
-        ];
+    if (!empty($form_state['triggering_element']['#element_key'])) {
+      $order = $form_state['commerce_order'];
+      $form_state['order_updated'] = TRUE;
+
+      // FIX: Something is happening where the order discount disappears when a
+      // coupon or a line item discount is added. So we need to do this ugly fix
+      // for it. Need to find a permanent solution.
+      // First check for existing order discounts.
+      if (module_exists('commerce_discount')) {
+        _commerce_sos_remove_all_discounts($form, $form_state, $order);
+      }
+
+      switch ($form_state['triggering_element']['#element_key']) {
+        // A line item has been added to the order.
+        case 'product-sku':
+          // Add the new product to our form_state array.
+          $product_info = commerce_sos_get_product_details($form_state['values']['product_sku']);
+          $line_item = commerce_sos_add_product($order, $product_info);
+
+          $form_state['added_products'][$line_item->line_item_id] = [
+            'line_item' => $line_item,
+            'product_info' => $product_info,
+          ];
+
+          break;
+
+        // Line item quantity has been updated manually.
+        case 'line-item-qty':
+          commerce_sos_update_line_item_quantity($order, $form_state['triggering_element']['#line_item_id'], $form_state['input']['products'][$form_state['triggering_element']['#line_item_id']]['quantity']);
+
+          break;
+
+        // Line item quantity has been incremented by 1.
+        case 'line-item-add-qty':
+          commerce_sos_update_line_item_quantity($order, $form_state['triggering_element']['#line_item_id'], 1, 'update');
+
+          break;
+
+        // Line item quantity has been decremented by 1.
+        case 'line-item-remove-qty':
+          commerce_sos_update_line_item_quantity($order, $form_state['triggering_element']['#line_item_id'], -1, 'update');
+
+          break;
+
+        // Remove an entire line item.
+        case 'remove-line-item':
+          commerce_sos_remove_line_item($order, $form_state['triggering_element']['#line_item_id']);
+
+          break;
+
+        // A line item discount needs to be added.
+        case 'add-percent-discount':
+        case 'add-fixed-discount':
+          $discount_amount = $form_state['values']['products'][$form_state['triggering_element']['#line_item_id']]['discounts']['add_discount']['amount'];
+
+          if ($form_state['triggering_element']['#element_key'] == 'add-percent-discount') {
+            $discount_type = 'percent';
+            // Convert percent 100% style to 1.0 style.
+            $discount_amount /= 100;
+          }
+          else {
+            $discount_type = 'fixed';
+            // Convert the amount into cents, as we expected it to be provided
+            // in dollars.
+            $discount_amount *= 100;
+          }
 
-        break;
+          commerce_sos_add_line_item_discount($discount_type, $form_state['triggering_element']['#line_item_id'], $discount_amount);
+
+          break;
+
+        // A line item discount needs to be removed.
+        case 'remove-discount':
+          $discount_amount = 0;
+          $discount_type = 'fixed';
+
+          commerce_sos_add_line_item_discount($discount_type, $form_state['triggering_element']['#line_item_id'], $discount_amount);
+
+          break;
+      }
+
+      // See API documentation for an explanation of this hook.
+      drupal_alter('commerce_sos_form_ajax_check', $form_state['triggering_element'], $form_state);
+    }
+    else {
+      $form_state['order_updated'] = FALSE;
     }
   }
 }
@@ -744,12 +882,20 @@ function _commerce_sos_ajax_check(&$form, &$form_state) {
  *   The form array.
  */
 function _commerce_sos_add_products_table_fields(array $form, array &$form_state) {
+  $form['#tree'] = TRUE;
+
   // Our main products table.
   $form['products'] = [
     '#type' => 'fieldset',
-    '#prefix' => '<div id="sos-products-table">',
+    '#prefix' => '<div id="sos-products-table-wrapper">',
     '#suffix' => '</div>',
     '#theme' => 'commerce_sos_products_table',
+    '#attributes' => ['id' => ['products-fieldset']],
+  ];
+
+  $wrapper_ajax = [
+    'callback' => 'commerce_sos_add_products_ajax_callback',
+    'wrapper' => 'sos-products-table-wrapper',
   ];
 
   // Now add the products to the table.
@@ -761,12 +907,12 @@ function _commerce_sos_add_products_table_fields(array $form, array &$form_state
 
       $form['products'][$line_item_id]['line_item_id'] = [
         '#type' => 'value',
-        '#value' => $line_item->line_item_id,
+        '#value' => $line_item_id,
         '#hidden' => TRUE,
       ];
 
       $form['products'][$line_item_id]['sku'] = [
-        '#markup' => l(t($product_info['sku']), $product['view_url']),
+        '#markup' => l($product_info['sku'], $product_info['view_url']),
       ];
 
       $thumbnail = commerce_sos_product_thumbnail($line_item_wrapper->commerce_product->value());
@@ -775,49 +921,77 @@ function _commerce_sos_add_products_table_fields(array $form, array &$form_state
       ];
 
       $form['products'][$line_item_id]['product'] = [
-        '#markup' => $product_info['title'],
+        '#markup' => '<div class="sos-product-title">' . $product_info['title'] . '</div>',
       ];
 
+      if ((int) $line_item_wrapper->quantity->value() > $product_info['in_stock']) {
+        $form['products'][$line_item_id]['not_enough_stock'] = [
+          '#type' => 'value',
+          '#value' => TRUE,
+          '#hidden' => TRUE,
+        ];
+      }
       $form['products'][$line_item_id]['stock'] = [
         '#markup' => $product_info['in_stock'],
       ];
 
-      $base_price = commerce_price_component_load($line_item_wrapper->commerce_unit_price->value(), 'base_price');
-      $currency = commerce_currency_load();
+      $line_item_total = $line_item_wrapper->commerce_total->value();
       $form['products'][$line_item_id]['unit_price'] = [
-        '#markup' => commerce_currency_format($base_price[0]['price']['amount'] / 100, $base_price[0]['price']['currency_code'], NULL, FALSE),
+        '#markup' => commerce_currency_format($line_item_total['amount'] / $line_item_wrapper->quantity->value(), $line_item_total['currency_code']),
       ];
 
-      $form['products'][$line_item_id]['quantity'] = [
-        '#title' => '',
-        '#type' => 'textfield',
-        '#default_value' => (int) $line_item_wrapper->quantity->value(),
-        '#size' => 4,
-        '#maxlength' => 4,
-        '#element_key' => 'line-item-qty',
-        '#line_item_id' => $line_item_id,
-        '#attributes' => [
-          'class' => ['commerce-pos-hidden-element'],
-        ],
-        '#limit_validation_errors' => FALSE,
-      ];
+      if ($form_state['edit_order']) {
+        $form['products'][$line_item_id]['quantity'] = [
+          '#title' => '',
+          '#type' => 'textfield',
+          '#value' => (int) $line_item_wrapper->quantity->value(),
+          '#size' => 4,
+          '#maxlength' => 4,
+          '#ajax' => $wrapper_ajax,
+          '#element_key' => 'line-item-qty',
+          '#line_item_id' => $line_item_id,
+          '#element_validate' => ['_commerce_sos_validate_qty'],
+          '#attributes' => [
+            'class' => ['commerce-sos-hidden-element'],
+          ],
+        ];
 
-      $form['products'][$line_item_id]['discount'] = [
-        '#markup' => 'discount',
-      ];
+        $form['products'][$line_item_id]['add_quantity'] = [
+          '#type' => 'button',
+          '#value' => '+',
+          '#name' => 'line-item-' . $line_item_id . '-plus',
+          '#element_key' => 'line-item-add-qty',
+          '#line_item_id' => $line_item_id,
+          '#ajax' => $wrapper_ajax,
+          '#attributes' => [
+            'tabindex' => 0,
+          ],
+        ];
+
+        $form['products'][$line_item_id]['remove_quantity'] = [
+          '#type' => 'button',
+          '#value' => '-',
+          '#name' => 'line-item-' . $line_item_id . '-minus',
+          '#element_key' => 'line-item-remove-qty',
+          '#line_item_id' => $line_item_id,
+          '#ajax' => $wrapper_ajax,
+        ];
+      }
+      else {
+        $form['products'][$line_item_id]['quantity'] = [
+          '#type' => 'item',
+          '#markup' => (int) $line_item_wrapper->quantity->value(),
+        ];
+      }
+
+      // Add our discount fields here.
+      if (module_exists('commerce_discount')) {
+        commerce_sos_add_discount_fields($form, $form_state, $product_info, $line_item);
+      }
 
-      $line_item_total = $line_item_wrapper->commerce_total->value();
       $form['products'][$line_item_id]['total'] = [
         '#markup' => '<strong>' . commerce_currency_format($line_item_total['amount'], $line_item_total['currency_code']) . '</strong>',
       ];
-
-      $form['products'][$line_item_id]['remove'] = [
-        '#type' => 'submit',
-        '#value' => 'Remove',
-        '#name' => 'line-item-' . $line_item_id . '-remove',
-        '#submit' => ['commerce_pos_transaction_line_item_remove_submit'],
-        '#line_item_id' => $line_item_id,
-      ];
     }
   }
 
@@ -828,7 +1002,7 @@ function _commerce_sos_add_products_table_fields(array $form, array &$form_state
  * Submit function for the 'Save order for later' button.
  */
 function commerce_sos_save_order_for_later_submit($form, &$form_state) {
-  $status = 'pending';
+  $status = 'checkout_checkout';
   $save_type = 'save_order_for_later';
 
   // Allow users to alter the status.
@@ -836,6 +1010,10 @@ function commerce_sos_save_order_for_later_submit($form, &$form_state) {
 
   // Finally, save the order.
   commerce_sos_save_commerce_order($form_state['commerce_order'], NULL, $status);
+
+  drupal_set_message(t('Successfully saved order for later payment.'));
+
+  drupal_goto('admin/commerce/sos/orders');
 }
 
 /**
@@ -850,11 +1028,17 @@ function commerce_sos_void_order_submit($form, &$form_state) {
 
   // Finally, save the order.
   commerce_sos_save_commerce_order($form_state['commerce_order'], NULL, $status);
+
+  drupal_set_message(t('Successfully cancelled order.'));
+
+  drupal_goto('admin/commerce/sos/orders');
 }
 
 /**
  * Modal callback for editing a customer profile.
  *
+ * @param object $order
+ *   The order entity.
  * @param bool $ajax
  *   TRUE if javascript is enabled.
  * @param object $customer_profile
@@ -863,33 +1047,43 @@ function commerce_sos_void_order_submit($form, &$form_state) {
  * @return array|mixed
  *   Returns the customer profile form.
  */
-function commerce_sos_edit_customer_profile_modal_callback($ajax, $customer_profile) {
+function commerce_sos_edit_customer_profile_modal_callback($order, $ajax, $customer_profile) {
   module_load_include('inc', 'commerce_customer', 'includes/commerce_customer_profile.forms');
 
   if ($ajax) {
     ctools_include('ajax');
     ctools_include('modal');
 
-    $form_state = array(
+    $form_state = [
       'ajax' => TRUE,
       'module' => 'commerce_sos',
-      'title' => t('Edit Customer @type Profile', ['@type' => $customer_profile->type]),
+      'title' => t('Edit Customer @type Profile', ['@type' => ucwords($customer_profile->type)]),
       'build_info' => ['args' => [$customer_profile]],
-    );
+    ];
 
     $output = ctools_modal_form_wrapper('commerce_customer_ui_customer_profile_form', $form_state);
 
-    if(!empty($form_state['executed'])) {
-      // Replace the profile address with the new one.
-      $address_field = field_view_field('commerce_customer_profile', $form_state['build_info']['args'][0], 'commerce_customer_address', ['label' => 'hidden']);
-      $new_address = drupal_render($address_field);
+    if (!empty($form_state['executed'])) {
+      // Now, save the new address profile to the order.
+      $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
+      if ($customer_profile->type == 'shipping') {
+        $order_wrapper->commerce_customer_shipping->set($form_state['build_info']['args'][0]);
+      }
+      else {
+        $order_wrapper->commerce_customer_billing->set($form_state['build_info']['args'][0]);
+      }
+      $order_wrapper->save();
+
+      // Set the new profile as the default profile.
+      commerce_addressbook_set_default_profile($form_state['build_info']['args'][0]);
+      drupal_set_message(t('Set this profile as the new default @profile_type address.', ['@profile_type' => $customer_profile->type]));
 
-      $output = array();
-      $selector = '#sos-order-' . $customer_profile->type . '-address';
+      // Reload the page so that the new taxes and shipping take affect.
+      $output = [];
+      $output[] = ctools_modal_command_dismiss();
       $output[] = ajax_command_remove('div.messages');
       $output[] = ajax_command_prepend('#commerce-sos-order-form', theme('status_messages'));
-      $output[] = ajax_command_html($selector . ' .sos-address-details', $new_address);
-      $output[] = ctools_modal_command_dismiss();
+      $output[] = ctools_ajax_command_reload();
     }
 
     print ajax_render($output);
@@ -899,3 +1093,215 @@ function commerce_sos_edit_customer_profile_modal_callback($ajax, $customer_prof
     return drupal_get_form('commerce_customer_ui_customer_profile_form', $customer_profile);
   }
 }
+
+/**
+ * Validation handler for the line item quantity fields.
+ */
+function _commerce_sos_validate_qty($element, &$form_state, $form) {
+  if (isset($form_state['triggering_element']) && isset($form_state['triggering_element']['#line_item_id'])
+    && $form_state['triggering_element']['#line_item_id'] == $element['#line_item_id']
+  ) {
+    $requested_qty = drupal_array_get_nested_value($form_state['input'], $element['#parents']);
+
+    // If the increment or decrement buttons were used, we need to add/subtract
+    // from the requested_qty.
+    if (isset($form_state['triggering_element']['#element_key'])) {
+      if ($form_state['triggering_element']['#element_key'] == 'line-item-remove-qty') {
+        $requested_qty -= 1;
+      }
+      if ($form_state['triggering_element']['#element_key'] == 'line-item-add-qty') {
+        $requested_qty += 1;
+      }
+    }
+
+    if (is_numeric($requested_qty) && $requested_qty > 0) {
+      form_set_value($element, $requested_qty, $form_state);
+    }
+    else {
+      form_error($element, t('Quantity must be a number and greater than zero.'));
+    }
+  }
+}
+
+/**
+ * Fetch and add the existing line items in the order to the form state.
+ */
+function _commerce_sos_add_existing_line_items($form, &$form_state) {
+  $form_state['shipping_line_items_exist'] = FALSE;
+  $form_state['total_product_quantity'] = 0;
+  $form_state['added_products'] = [];
+  $order_wrapper = entity_metadata_wrapper('commerce_order', $form_state['commerce_order']);
+
+  foreach ($order_wrapper->commerce_line_items as $line_item_wrapper) {
+    if ($line_item_wrapper->type->value() != 'shipping' && isset($line_item_wrapper->commerce_product)) {
+      $line_item_id = $line_item_wrapper->line_item_id->value();
+
+      $product_info = _commerce_sos_fetch_product_details($line_item_wrapper->commerce_product->value());
+
+      $form_state['added_products'][$line_item_id] = [
+        'line_item' => $line_item_wrapper->value(),
+        'product_info' => $product_info,
+      ];
+
+      // Add the products to the form state for easier fetching.
+      $form_state['all_products'][$product_info['product']->product_id] = $product_info['product'];
+
+      // Increment total product quantity count.
+      $form_state['total_product_quantity'] += $line_item_wrapper->quantity->value();
+    }
+    // If we have shipping line items, denote that in the form state.
+    elseif ($line_item_wrapper->type->value() == 'shipping') {
+      $form_state['shipping_line_items_exist'] = TRUE;
+    }
+  }
+}
+
+/**
+ * Add the discount fields to each line item.
+ */
+function commerce_sos_add_discount_fields(&$form, &$form_state, $product_info, $line_item) {
+  $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
+  $line_item_id = $line_item_wrapper->line_item_id->value();
+  $current_product = $product_info['product'];
+  $wrapper_ajax = [
+    'callback' => 'commerce_sos_add_products_ajax_callback',
+    'wrapper' => 'sos-products-table-wrapper',
+  ];
+
+  $form['products'][$line_item_id]['discounts'] = [
+    '#type' => 'container',
+    '#id' => 'commerce-sos-discount-wrapper-' . $line_item_id,
+    '#attributes' => [
+      'class' => [
+        'commerce-sos-discount-wrapper',
+      ],
+    ],
+  ];
+
+  $discount_data = commerce_sos_get_existing_line_item_discount_amount($line_item_id);
+  if ($form_state['edit_order']) {
+    $form['products'][$line_item_id]['discounts']['toggle_discount'] = [
+      '#type' => 'button',
+      '#value' => t('Discount'),
+      '#line_item_id' => $line_item_id,
+      '#element_key' => 'toggle-discount',
+      '#name' => 'commerce-sos-discount-toggle-discount-' . $line_item_id,
+      '#ajax' => [
+        'wrapper' => 'commerce-sos-discount-wrapper-' . $line_item_id,
+        'callback' => 'commerce_sos_add_products_ajax_callback',
+      ],
+    ];
+
+    if (!empty($form_state['triggering_element']['#element_key']) && $form_state['triggering_element']['#element_key'] == 'toggle-discount' &&
+      $form_state['triggering_element']['#line_item_id'] == $line_item_id
+    ) {
+      $form['products'][$line_item_id]['discounts']['toggle_discount']['#element_key'] = 'toggle-discount-hide';
+
+      $form['products'][$line_item_id]['discounts']['add_discount'] = [
+        '#type' => 'container',
+        '#size' => 2,
+      ];
+
+      $form['products'][$line_item_id]['discounts']['add_discount']['#attached']['js'][] = [
+        'type' => 'setting',
+        'data' => [
+          'commerceSOSDiscount' => [
+            'focusInput' => TRUE,
+            'lineItemId' => $line_item_id,
+          ],
+        ],
+      ];
+
+      $discount_default_value = NULL;
+      if ($discount_data && !empty($discount_data['amount'])) {
+        $discount_default_value = $discount_data['amount'];
+      }
+
+      $form['products'][$line_item_id]['discounts']['add_discount']['amount'] = [
+        '#type' => 'textfield',
+        '#title' => NULL,
+        '#size' => 2,
+        '#default_value' => $discount_default_value,
+      ];
+
+      $form['products'][$line_item_id]['discounts']['add_discount']['percent'] = [
+        '#type' => 'button',
+        '#value' => '%',
+        '#element_key' => 'add-percent-discount',
+        '#line_item_id' => $line_item_id,
+        '#name' => 'commerce-sos-discount-percent-discount-' . $line_item_id,
+        '#ajax' => $wrapper_ajax,
+        '#attributes' => [
+          'class' => ['sos-blue'],
+        ],
+      ];
+
+      $form['products'][$line_item_id]['discounts']['add_discount']['fixed'] = [
+        '#type' => 'button',
+        '#value' => '$',
+        '#element_key' => 'add-fixed-discount',
+        '#line_item_id' => $line_item_id,
+        '#name' => 'commerce-sos-discount-fixed-discount-' . $line_item_id,
+        '#ajax' => $wrapper_ajax,
+        '#attributes' => [
+          'class' => ['sos-blue'],
+        ],
+      ];
+
+      if ($discount_data) {
+        $form['products'][$line_item_id]['discounts']['add_discount'][$discount_data['type']]['#attributes']['class'][] = 'sos-active';
+      }
+    }
+    else {
+      if (!empty($discount_data) && isset($discount_data['amount']) & !empty($discount_data['amount'])) {
+        $discount_price = '';
+        if (isset($discount_data['type']) && $discount_data['type'] == 'percent') {
+          $discount_price = $discount_data['amount'] . '%';
+        }
+        else {
+          $discount_price = commerce_currency_format(($discount_data['amount'] * 100), $discount_data['currency_code']);
+        }
+
+        $form['products'][$line_item_id]['discounts']['discount_description'] = [
+          '#markup' => $discount_price,
+          '#prefix' => '<span class="discount-description">',
+          '#suffix' => '</span>',
+          '#line_item_id' => $line_item_id,
+          '#element_key' => 'discount-description',
+        ];
+
+        $form['products'][$line_item_id]['discounts']['remove_discount'] = [
+          '#type' => 'button',
+          '#value' => 'Remove',
+          '#prefix' => ' - ',
+          '#element_key' => 'remove-discount',
+          '#line_item_id' => $line_item_id,
+          '#name' => 'commerce-sos-discount-remove-discount-' . $line_item_id,
+          '#ajax' => $wrapper_ajax,
+          '#attributes' => [
+            'class' => ['sos-remove-discount-link', 'sos-small'],
+          ],
+        ];
+      }
+      else {
+        $form['products'][$line_item_id]['discounts']['#attributes']['class'][] = 'sos-no-background';
+      }
+    }
+  }
+  else {
+    if (!empty($discount_data) && isset($discount_data['amount']) & !empty($discount_data['amount'])) {
+      $discount_price = '';
+      if (isset($discount_data['type']) && $discount_data['type'] == 'percent') {
+        $discount_price = $discount_data['amount'] . '%';
+      }
+      else {
+        $discount_price = commerce_currency_format(($discount_data['amount'] * 100), $discount_data['currency_code']);
+      }
+
+      $form['products'][$line_item_id]['discounts']['discount_description'] = [
+        '#type' => 'item',
+        '#markup' => '-' . $discount_price,
+      ];
+    }
+  }
+}
diff --git a/includes/views/order_manager_view.inc b/includes/views/order_manager_view.inc
index 5f2fb33..96e9e3b 100644
--- a/includes/views/order_manager_view.inc
+++ b/includes/views/order_manager_view.inc
@@ -109,6 +109,10 @@ $handler->display->display_options['empty']['area']['field'] = 'area';
 $handler->display->display_options['empty']['area']['empty'] = TRUE;
 $handler->display->display_options['empty']['area']['content'] = 'There are no orders that match the search criteria.';
 $handler->display->display_options['empty']['area']['format'] = 'filtered_html';
+/* Relationship: Commerce Order: Referenced line items */
+$handler->display->display_options['relationships']['commerce_line_items_line_item_id']['id'] = 'commerce_line_items_line_item_id';
+$handler->display->display_options['relationships']['commerce_line_items_line_item_id']['table'] = 'field_data_commerce_line_items';
+$handler->display->display_options['relationships']['commerce_line_items_line_item_id']['field'] = 'commerce_line_items_line_item_id';
 /* Field: Commerce Order: Order ID */
 $handler->display->display_options['fields']['order_id']['id'] = 'order_id';
 $handler->display->display_options['fields']['order_id']['table'] = 'commerce_order';
@@ -162,7 +166,7 @@ $handler->display->display_options['fields']['view_order']['field'] = 'view_orde
 $handler->display->display_options['fields']['view_order']['alter']['alter_text'] = TRUE;
 $handler->display->display_options['fields']['view_order']['alter']['text'] = 'View';
 $handler->display->display_options['fields']['view_order']['alter']['make_link'] = TRUE;
-$handler->display->display_options['fields']['view_order']['alter']['path'] = 'admin/commerce/sos/orders/[order_id]';
+$handler->display->display_options['fields']['view_order']['alter']['path'] = 'admin/commerce/sos/orders/[order_id]/view';
 $handler->display->display_options['fields']['view_order']['alter']['target'] = '_blank';
 $handler->display->display_options['fields']['view_order']['text'] = 'View';
 /* Sort criterion: Commerce Order: Created date */
@@ -237,6 +241,14 @@ $handler->display->display_options['filters']['mail']['expose']['remember_roles'
   7 => 0,
   8 => 0,
 );
+/* Filter criterion: Commerce Line Item: Type */
+$handler->display->display_options['filters']['type']['id'] = 'type';
+$handler->display->display_options['filters']['type']['table'] = 'commerce_line_item';
+$handler->display->display_options['filters']['type']['field'] = 'type';
+$handler->display->display_options['filters']['type']['relationship'] = 'commerce_line_items_line_item_id';
+$handler->display->display_options['filters']['type']['value'] = array(
+  'product' => 'product',
+);
 
 /* Display: Page */
 $handler = $view->new_display('page', 'Page', 'page');
diff --git a/js/commerce_sos.js b/js/commerce_sos.js
old mode 100644
new mode 100755
index ee0aac5..dd2de94
--- a/js/commerce_sos.js
+++ b/js/commerce_sos.js
@@ -111,6 +111,29 @@
           .val(sku)
           .trigger('blur');
       }
+
+      $('a.sos-show-line-item-attributes').click(function(event) {
+        event.preventDefault();
+        event.stopImmediatePropagation();
+
+        $(this).parent('td').parent('tr').next('tr').slideToggle("slow");
+        if ($(this).hasClass('edit-clicked')) {
+          $(this).removeClass('edit-clicked');
+        }
+        else {
+          $(this).addClass('edit-clicked');
+        }
+      });
+
+      /**
+       * Display the line item attributes only when the 'Edit' link in the order
+       * is clicked.
+       */
+      $('a.sos-show-line-item-attributes').each(function() {
+        if (!$(this).hasClass('edit-clicked')) {
+          $(this).parent('td').parent('tr').next('tr').hide();
+        }
+      });
     }
   }
 }(jQuery));
diff --git a/js/keynavigator.js b/js/keynavigator.js
index 0e0b77c..f346e83 100755
--- a/js/keynavigator.js
+++ b/js/keynavigator.js
@@ -1,7 +1,7 @@
 /*
  * Key navigator plugin for jQuery / Zepto.
  *
- * https://github.com/nekman/keynavigator (included in repo).
+ * https://github.com/nekman/keynavigator
  */
 
 (function (root, factory) {
diff --git a/theme/commerce-sos-product-result.tpl.php b/theme/commerce-sos-product-result.tpl.php
old mode 100644
new mode 100755
diff --git a/theme/commerce_sos.theme.inc b/theme/commerce_sos.theme.inc
old mode 100644
new mode 100755
index 38c995a..905ae54
--- a/theme/commerce_sos.theme.inc
+++ b/theme/commerce_sos.theme.inc
@@ -28,7 +28,7 @@ function commerce_sos_preprocess_commerce_sos_product_result(&$variables) {
     $variables['image'] = $image;
   }
 
-  if ($display_nid = commerce_sos_get_product_display_nid($product->product_id)) {
+  if ($display_nid = commerce_sos_get_product_display_nid($product->product_id, $variables['product_search'])['nid']) {
     $variables['product_display'] = 'node/' . $display_nid;
   }
   else {
