/** * {@inheritdoc} */ public function getValueOptions() { if (!isset($this->valueOptions)) { $this->valueTitle = t('Order status'); $this->valueOptions = array_merge(['_active' => t('Active')], OrderStatus::getOptionsList()); } }
/** * {@inheritdoc} */ public function view(OrderInterface $order, $view_mode) { // @todo Simplify this or replace with Views if ($view_mode == 'customer') { $comments = uc_order_comments_load($order->id()); $statuses = OrderStatus::loadMultiple(); $header = array($this->t('Date'), $this->t('Status'), $this->t('Message')); $rows[] = array(array('data' => \Drupal::service('date.formatter')->format($order->created->value, 'uc_store'), 'class' => array('date')), array('data' => '-', 'class' => array('status')), array('data' => $this->t('Order created.'), 'class' => array('message'))); if (count($comments) > 0) { foreach ($comments as $comment) { $rows[] = array(array('data' => \Drupal::service('date.formatter')->format($comment->created, 'uc_store'), 'class' => array('date')), array('data' => array('#plain_text' => $statuses[$comment->order_status]->getName()), 'class' => array('status')), array('data' => array('#markup' => $comment->message), 'class' => array('message'))); } } $build = array('#theme' => 'table', '#header' => $header, '#rows' => $rows, '#attributes' => array('class' => array('uc-order-comments'))); } else { $build = array('#theme' => 'table', '#header' => array(array('data' => $this->t('Date'), 'class' => array('date')), array('data' => $this->t('User'), 'class' => array('user', RESPONSIVE_PRIORITY_LOW)), array('data' => $this->t('Notified'), 'class' => array('notified')), array('data' => $this->t('Status'), 'class' => array('status', RESPONSIVE_PRIORITY_LOW)), array('data' => $this->t('Comment'), 'class' => array('message'))), '#rows' => array(), '#attributes' => array('class' => array('order-pane-table uc-order-comments')), '#empty' => $this->t('This order has no comments associated with it.')); $comments = uc_order_comments_load($order->id()); $statuses = OrderStatus::loadMultiple(); foreach ($comments as $comment) { $icon = $comment->notified ? 'true-icon.gif' : 'false-icon.gif'; $build['#rows'][] = array(array('data' => \Drupal::service('date.formatter')->format($comment->created, 'short'), 'class' => array('date')), array('data' => array('#theme' => 'uc_uid', '#uid' => $comment->uid), 'class' => array('user')), array('data' => array('#theme' => 'image', '#uri' => drupal_get_path('module', 'uc_order') . '/images/' . $icon), 'class' => array('notified')), array('data' => array('#plain_text' => $statuses[$comment->order_status]->getName()), 'class' => array('status')), array('data' => array('#markup' => $comment->message), 'class' => array('message'))); } } return $build; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, $values) { $form['search'] = array('#type' => 'details', '#title' => t('Customize product report parameters'), '#description' => t('Adjust these values and update the report to build your custom product report. Once submitted, the report may be bookmarked for easy reference in the future.')); $form['search']['start_date'] = array('#type' => 'date', '#title' => t('Start date'), '#default_value' => array('month' => \Drupal::service('date.formatter')->format($values['start_date'], 'custom', 'n'), 'day' => \Drupal::service('date.formatter')->format($values['start_date'], 'custom', 'j'), 'year' => \Drupal::service('date.formatter')->format($values['start_date'], 'custom', 'Y'))); $form['search']['end_date'] = array('#type' => 'date', '#title' => t('End date'), '#default_value' => array('month' => \Drupal::service('date.formatter')->format($values['end_date'], 'custom', 'n'), 'day' => \Drupal::service('date.formatter')->format($values['end_date'], 'custom', 'j'), 'year' => \Drupal::service('date.formatter')->format($values['end_date'], 'custom', 'Y'))); $form['search']['status'] = array('#type' => 'checkboxes', '#title' => t('Order statuses'), '#description' => t('Only orders with selected statuses will be included in the report.'), '#options' => OrderStatus::getOptionsList(), '#default_value' => $values['status']); $form['search']['actions'] = array('#type' => 'actions'); $form['search']['actions']['submit'] = array('#type' => 'submit', '#value' => t('Update report')); return $form; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, $values = NULL) { $form['params'] = array('#type' => 'fieldset', '#title' => t('Customize tax report parameters'), '#description' => t('Adjust these values and update the report to build your sales tax report. Once submitted, the report may be bookmarked for easy reference in the future.')); $form['params']['start_date'] = array('#type' => 'date', '#title' => t('Start date'), '#default_value' => array('month' => \Drupal::service('date.formatter')->format($values['start_date'], 'custom', 'n'), 'day' => \Drupal::service('date.formatter')->format($values['start_date'], 'custom', 'j'), 'year' => \Drupal::service('date.formatter')->format($values['start_date'], 'custom', 'Y'))); $form['params']['end_date'] = array('#type' => 'date', '#title' => t('End date'), '#default_value' => array('month' => \Drupal::service('date.formatter')->format($values['end_date'], 'custom', 'n'), 'day' => \Drupal::service('date.formatter')->format($values['end_date'], 'custom', 'j'), 'year' => \Drupal::service('date.formatter')->format($values['end_date'], 'custom', 'Y'))); $stat = $values['status']; if ($stat === FALSE) { $stat = uc_report_order_statuses(); } $form['params']['status'] = array('#type' => 'select', '#title' => t('Order statuses'), '#description' => t('Only orders with selected statuses will be included in the report.') . '<br />' . t('Hold Ctrl + click to select multiple statuses.'), '#options' => OrderStatus::getOptionsList(), '#default_value' => $stat, '#multiple' => TRUE, '#size' => 5); $form['params']['actions'] = array('#type' => 'actions'); $form['params']['actions']['submit'] = array('#type' => 'submit', '#value' => t('Update report')); return $form; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, OrderInterface $order = NULL) { $form['order_comment_field'] = array('#type' => 'details', '#title' => $this->t('Add an order comment')); $form['order_comment_field']['order_comment'] = array('#type' => 'textarea', '#description' => $this->t('Order comments are used primarily to communicate with the customer.')); $form['admin_comment_field'] = array('#type' => 'details', '#title' => $this->t('Add an admin comment')); $form['admin_comment_field']['admin_comment'] = array('#type' => 'textarea', '#description' => $this->t('Admin comments are only seen by store administrators.')); $form['current_status'] = array('#type' => 'value', '#value' => $order->getStatusId()); $form['order_id'] = array('#type' => 'value', '#value' => $order->id()); $form['controls'] = array('#type' => 'container', '#attributes' => array('class' => array('uc-inline-form')), '#weight' => 10); $form['controls']['status'] = array('#type' => 'select', '#title' => $this->t('Order status'), '#default_value' => $order->getStatusId(), '#options' => OrderStatus::getOptionsList()); $form['controls']['notify'] = array('#type' => 'checkbox', '#title' => $this->t('Send e-mail notification on update.')); $form['controls']['actions'] = array('#type' => 'actions'); $form['controls']['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Update'), '#button_type' => 'primary'); return $form; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, $values, $statuses) { $form['search'] = array('#type' => 'details', '#title' => $this->t('Customize sales report parameters'), '#description' => $this->t('Adjust these values and update the report to build your custom sales summary. Once submitted, the report may be bookmarked for easy reference in the future.')); $form['search']['start_date'] = array('#type' => 'date', '#title' => $this->t('Start date'), '#default_value' => array('month' => \Drupal::service('date.formatter')->format($values['start_date'], 'custom', 'n'), 'day' => \Drupal::service('date.formatter')->format($values['start_date'], 'custom', 'j'), 'year' => \Drupal::service('date.formatter')->format($values['start_date'], 'custom', 'Y'))); $form['search']['end_date'] = array('#type' => 'date', '#title' => $this->t('End date'), '#default_value' => array('month' => \Drupal::service('date.formatter')->format($values['end_date'], 'custom', 'n'), 'day' => \Drupal::service('date.formatter')->format($values['end_date'], 'custom', 'j'), 'year' => \Drupal::service('date.formatter')->format($values['end_date'], 'custom', 'Y'))); $form['search']['length'] = array('#type' => 'select', '#title' => $this->t('Results breakdown'), '#description' => $this->t('Large daily reports may take a long time to display.'), '#options' => array('day' => $this->t('daily'), 'week' => $this->t('weekly'), 'month' => $this->t('monthly'), 'year' => $this->t('yearly')), '#default_value' => $values['length']); if ($statuses === FALSE) { $statuses = uc_report_order_statuses(); } $form['search']['status'] = array('#type' => 'checkboxes', '#title' => $this->t('Order statuses'), '#description' => $this->t('Only orders with selected statuses will be included in the report.'), '#options' => OrderStatus::getOptionsList(), '#default_value' => $statuses); $form['search']['detail'] = array('#type' => 'checkbox', '#title' => $this->t('Show a detailed list of products ordered.'), '#default_value' => $values['detail']); $form['search']['actions'] = array('#type' => 'actions'); $form['search']['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Update report')); return $form; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, $args = NULL) { if (!isset($args['start_date'])) { $args['start_date'] = REQUEST_TIME; } if (!isset($args['end_date'])) { $args['end_date'] = REQUEST_TIME; } if (!isset($args['statuses'])) { $args['statuses'] = uc_report_order_statuses(); } $form['params'] = array('#type' => 'fieldset', '#title' => $this->t('Customize tax report parameters'), '#description' => $this->t('Adjust these values and update the report to build your sales tax report. Once submitted, the report may be bookmarked for easy reference in the future.')); $form['params']['start_date'] = array('#type' => 'datetime', '#title' => $this->t('Start date'), '#date_date_element' => 'date', '#date_time_element' => 'none', '#default_value' => DrupalDateTime::createFromTimestamp($args['start_date'])); $form['params']['end_date'] = array('#type' => 'datetime', '#title' => $this->t('End date'), '#date_date_element' => 'date', '#date_time_element' => 'none', '#default_value' => DrupalDateTime::createFromTimestamp($args['end_date'])); $form['params']['statuses'] = array('#type' => 'select', '#title' => $this->t('Order statuses'), '#description' => $this->t('Only orders with selected statuses will be included in the report.') . '<br />' . $this->t('Hold Ctrl + click to select multiple statuses.'), '#options' => OrderStatus::getOptionsList(), '#default_value' => $args['statuses'], '#multiple' => TRUE, '#size' => 5); $form['params']['actions'] = array('#type' => 'actions'); $form['params']['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Update report')); return $form; }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $config = $this->config('uc_order.settings'); foreach ($form_state->getValue('order_states') as $key => $value) { $config->set("default_state.{$key}", $value['default']); } $config->save(); foreach ($form_state->getValue('order_statuses') as $id => $value) { $status = OrderStatus::load($id); if (!empty($value['remove'])) { $status->delete(); drupal_set_message(t('Order status %status removed.', ['%status' => $status->getName()])); } else { $status->setName($value['name']); $status->setWeight((int) $value['weight']); // The state cannot be changed if the status is locked. if (!$status->isLocked()) { $status->setState($value['state']); } $status->save(); } } parent::submitForm($form, $form_state); }
/** * Tests that delete() throws an exception when the status is locked. * * @covers ::delete * @expectedException \LogicException */ public function testDeleteWhenLocked() { $this->orderStatus->setLocked(TRUE); $this->orderStatus->delete(); }
/** * {@inheritdoc} */ public function render(ResultRow $values) { $status = OrderStatus::load($this->getValue($values)); return $this->sanitizeValue($status->getName()); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { OrderStatus::create(array('id' => strtolower(trim($form_state->getValue('id'))), 'name' => $form_state->getValue('name'), 'state' => $form_state->getValue('state'), 'weight' => (int) $form_state->getValue('weight')))->save(); drupal_set_message($this->t('Custom order status created.')); $form_state->setRedirect('uc_order.workflow'); }
/** * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form['status'] = array('#type' => 'select', '#title' => $this->t('Order status'), '#default_value' => $this->configuration['status'], '#options' => OrderStatus::getOptionsList()); $form['notify'] = array('#type' => 'checkbox', '#title' => $this->t('Send e-mail notification on update.'), '#default_value' => $this->configuration['notify']); return $form; }