/**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form['id'] = array('#type' => 'textfield', '#title' => $this->t('Order status ID'), '#description' => $this->t('Must be a unique ID with no spaces.'), '#size' => 32, '#maxlength' => 32, '#required' => TRUE);
     $form['name'] = array('#type' => 'textfield', '#title' => $this->t('Title'), '#description' => $this->t('The order status title displayed to users.'), '#size' => 32, '#maxlength' => 48, '#required' => TRUE);
     $form['state'] = array('#type' => 'select', '#title' => $this->t('Order state'), '#description' => $this->t('Set which order state this status is for.'), '#options' => uc_order_state_options_list(), '#default_value' => 'post_checkout');
     $form['weight'] = array('#type' => 'weight', '#title' => $this->t('List position'), '#delta' => 20, '#default_value' => 0);
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['create'] = array('#type' => 'submit', '#value' => $this->t('Create'));
     $form['actions']['cancel'] = array('#markup' => Link::createFromRoute($this->t('Cancel'), 'uc_order.status_add')->toString());
     return $form;
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $states = uc_order_state_options_list();
     $statuses = OrderStatus::loadMultiple();
     $form['order_states'] = array('#type' => 'details', '#title' => t('Order states'));
     $form['order_states']['order_states'] = array('#type' => 'table', '#header' => array(t('State'), t('Default order status')));
     foreach ($states as $state_id => $title) {
         $form['order_states']['order_states'][$state_id]['title'] = array('#markup' => $title);
         // Create the select box for specifying a default status per order state.
         $options = array();
         foreach ($statuses as $status) {
             if ($state_id == $status->getState()) {
                 $options[$status->id()] = $status->getName();
             }
         }
         if (empty($options)) {
             $form['order_states']['order_states'][$state_id]['default'] = array('#markup' => t('- N/A -'));
         } else {
             $form['order_states']['order_states'][$state_id]['default'] = array('#type' => 'select', '#options' => $options, '#default_value' => uc_order_state_default($state_id));
         }
     }
     $form['order_statuses'] = array('#type' => 'details', '#title' => t('Order statuses'), '#open' => TRUE);
     $form['order_statuses']['order_statuses'] = array('#type' => 'table', '#header' => array(t('ID'), t('Title'), t('List position'), t('State'), t('Remove')));
     foreach ($statuses as $status) {
         $form['order_statuses']['order_statuses'][$status->id()]['id'] = array('#markup' => $status->id());
         $form['order_statuses']['order_statuses'][$status->id()]['name'] = array('#type' => 'textfield', '#default_value' => $status->getName(), '#size' => 32, '#required' => TRUE);
         $form['order_statuses']['order_statuses'][$status->id()]['weight'] = array('#type' => 'weight', '#delta' => 20, '#default_value' => $status->getWeight());
         if ($status->isLocked()) {
             $form['order_statuses']['order_statuses'][$status->id()]['state'] = array('#markup' => $states[$status->getState()]);
         } else {
             $form['order_statuses']['order_statuses'][$status->id()]['state'] = array('#type' => 'select', '#options' => $states, '#default_value' => $status->getState());
             $form['order_statuses']['order_statuses'][$status->id()]['remove'] = array('#type' => 'checkbox');
         }
     }
     return parent::buildForm($form, $form_state);
 }
예제 #3
0
 public function testCustomOrderStatus()
 {
     $order = $this->ucCreateOrder($this->customer);
     $this->drupalLogin($this->adminUser);
     // Update an order status label.
     $this->drupalGet('admin/store/config/orders');
     $title = $this->randomMachineName();
     $edit = array('order_statuses[in_checkout][name]' => $title);
     $this->drupalPostForm(NULL, $edit, 'Save configuration');
     $this->assertFieldByName('order_statuses[in_checkout][name]', $title, 'Updated status title found.');
     // Confirm the updated label is displayed.
     $this->drupalGet('admin/store/orders/view');
     $this->assertText($title, 'Order displays updated status title.');
     // Create a custom order status.
     $this->drupalGet('admin/store/config/orders');
     $this->clickLink('Create custom order status');
     $edit = array('id' => strtolower($this->randomMachineName()), 'name' => $this->randomMachineName(), 'state' => array_rand(uc_order_state_options_list()), 'weight' => mt_rand(-10, 10));
     $this->drupalPostForm(NULL, $edit, 'Create');
     $this->assertText($edit['id'], 'Custom status ID found.');
     $this->assertFieldByName('order_statuses[' . $edit['id'] . '][name]', $edit['name'], 'Custom status title found.');
     $this->assertFieldByName('order_statuses[' . $edit['id'] . '][weight]', $edit['weight'], 'Custom status weight found.');
     // Set an order to the custom status.
     $this->drupalPostForm('admin/store/orders/' . $order->id(), array('status' => $edit['id']), 'Update');
     $this->drupalGet('admin/store/orders/view');
     $this->assertText($edit['name'], 'Order displays custom status title.');
     // Delete the custom order status.
     $this->drupalPostForm('admin/store/config/orders', ['order_statuses[' . $edit['id'] . '][remove]' => 1], 'Save configuration');
     $this->assertNoText($edit['id'], 'Deleted status ID not found.');
 }