/**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $quote_config = $this->config('uc_quote.settings');
     $address = $quote_config->get('store_default_address');
     $form['uc_quote_display_debug'] = array('#type' => 'checkbox', '#title' => $this->t('Display debug information to administrators.'), '#default_value' => $quote_config->get('display_debug'));
     $form['uc_quote_require_quote'] = array('#type' => 'checkbox', '#title' => $this->t('Prevent the customer from completing an order if a shipping quote is not selected.'), '#default_value' => $quote_config->get('require_quote'));
     $form['default_address'] = array('#type' => 'details', '#title' => $this->t('Default pickup address'), '#description' => $this->t("When delivering products to customers, the original location of the product must be known in order to accurately quote the shipping cost and set up a delivery. This form provides the default location for all products in the store. If a product's individual pickup address is blank, Ubercart uses the store's default pickup address specified here."));
     $form['default_address']['address'] = array('#type' => 'uc_address', '#default_value' => $form_state->getValues() ?: $address, '#required' => FALSE);
     $shipping_types = uc_quote_shipping_type_options();
     if (is_array($shipping_types)) {
         $form['uc_quote_type_weight'] = array('#type' => 'details', '#title' => $this->t('List position'), '#description' => $this->t('Determines which shipping methods are quoted at checkout when products of different shipping types are ordered. Larger values take precedence.'), '#tree' => TRUE);
         $weight = $quote_config->get('type_weight');
         $shipping_methods = \Drupal::moduleHandler()->invokeAll('uc_shipping_method');
         $method_types = array();
         foreach ($shipping_methods as $method) {
             // Get shipping method types from shipping methods that provide quotes
             if (isset($method['quote'])) {
                 $method_types[$method['quote']['type']][] = $method['title'];
             }
         }
         if (isset($method_types['order']) && is_array($method_types['order'])) {
             $count = count($method_types['order']);
             $form['uc_quote_type_weight']['#description'] .= $this->formatPlural($count, '<br />The %list method is compatible with any shipping type.', '<br />The %list methods are compatible with any shipping type.', ['%list' => implode(', ', $method_types['order'])]);
         }
         foreach ($shipping_types as $id => $title) {
             $form['uc_quote_type_weight'][$id] = array('#type' => 'weight', '#title' => $title . (isset($method_types[$id]) && is_array($method_types[$id]) ? ' (' . implode(', ', $method_types[$id]) . ')' : ''), '#delta' => 5, '#default_value' => isset($weight[$id]) ? $weight[$id] : 0);
         }
     }
     $form['uc_store_shipping_type'] = array('#type' => 'select', '#title' => $this->t('Default order fulfillment type for products'), '#options' => $shipping_types, '#default_value' => $quote_config->get('shipping_type'));
     return parent::buildForm($form, $form_state);
 }
 /**
  * Displays a list of an order's packaged products.
  *
  * @param \Drupal\uc_order\OrderInterface $uc_order
  *   The order.
  *
  * @return array|\Symfony\Component\HttpFoundation\RedirectResponse
  *   A render array, or a redirect response if there are no packaged products.
  */
 public function listOrderPackages(OrderInterface $uc_order)
 {
     $shipping_type_options = uc_quote_shipping_type_options();
     $header = array($this->t('Package ID'), $this->t('Products'), $this->t('Shipping type'), $this->t('Package type'), $this->t('Shipment ID'), $this->t('Tracking number'), $this->t('Labels'), $this->t('Actions'));
     $rows = array();
     $result = db_query('SELECT package_id FROM {uc_packages} WHERE order_id = :id', [':id' => $uc_order->id()]);
     while ($package_id = $result->fetchField()) {
         $package = Package::load($package_id);
         $row = array();
         // Package ID.
         $row[] = array('data' => array('#plain_text' => $package->package_id));
         $product_list = array();
         $result2 = db_query('SELECT op.order_product_id, pp.qty, op.title, op.model FROM {uc_packaged_products} pp LEFT JOIN {uc_order_products} op ON op.order_product_id = pp.order_product_id WHERE pp.package_id = :id', [':id' => $package->package_id]);
         foreach ($result2 as $product) {
             $product_list[] = $product->qty . ' x ' . $product->model;
         }
         // Products.
         $row[] = array('data' => array('#theme' => 'item_list', '#items' => $product_list));
         // Shipping type.
         $row[] = isset($shipping_type_options[$package->shipping_type]) ? $shipping_type_options[$package->shipping_type] : strtr($package->shipping_type, '_', ' ');
         // Package type.
         $row[] = array('data' => array('#plain_text' => $package->pkg_type));
         // Shipment ID.
         $row[] = isset($package->sid) ? Link::createFromRoute($package->sid, 'uc_fulfillment.view_shipment', ['uc_order' => $uc_order->id(), 'shipment_id' => $package->sid])->toString() : '';
         // Tracking number.
         $row[] = isset($package->tracking_number) ? array('data' => array('#plain_text' => $package->tracking_number)) : '';
         if ($package->label_image && ($image = file_load($package->label_image))) {
             $package->label_image = $image;
         } else {
             unset($package->label_image);
         }
         // Shipping label.
         if (isset($package->sid) && isset($package->label_image)) {
             $method = db_query('SELECT shipping_method FROM {uc_shipments} WHERE sid = :sid', [':sid' => $package->sid])->fetchField();
             $row[] = Link::fromTextAndUrl("image goes here", Url::fromUri('base:admin/store/orders/' . $uc_order->id() . '/shipments/labels/' . $method . '/' . $package->label_image->uri, ['uc_order' => $uc_order->id(), 'method' => $method, 'image_uri' => $package->label_image->uri]))->toString();
         } else {
             $row[] = '';
         }
         // Operations.
         $ops = array('#type' => 'operations', '#links' => array('edit' => array('title' => $this->t('Edit'), 'url' => Url::fromRoute('uc_fulfillment.edit_package', ['uc_order' => $uc_order->id(), 'package_id' => $package->package_id])), 'ship' => array('title' => $this->t('Ship'), 'url' => Url::fromRoute('uc_fulfillment.new_shipment', ['uc_order' => $uc_order->id()], ['query' => ['pkgs' => $package->package_id]])), 'delete' => array('title' => $this->t('Delete'), 'url' => Url::fromRoute('uc_fulfillment.delete_package', ['uc_order' => $uc_order->id(), 'package_id' => $package->package_id]))));
         if ($package->sid) {
             $ops['#links']['cancel'] = array('title' => $this->t('Cancel'), 'url' => Url::fromRoute('uc_fulfillment.cancel_package', ['uc_order' => $uc_order->id(), 'package_id' => $package->package_id]));
         }
         $row[] = array('data' => $ops);
         $rows[] = $row;
     }
     if (empty($rows)) {
         drupal_set_message($this->t("This order's products have not been organized into packages."), 'warning');
         return $this->redirect('uc_fulfillment.new_package', ['uc_order' => $uc_order->id()]);
     }
     $build['packages'] = array('#theme' => 'table', '#header' => $header, '#rows' => $rows);
     return $build;
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $quote_config = $this->config('uc_quote.settings');
     $form['methods'] = array('#type' => 'table', '#header' => array(t('Shipping method'), t('Details'), t('List position'), t('Operations')), '#tabledrag' => array(array('action' => 'order', 'relationship' => 'sibling', 'group' => 'uc-quote-method-weight')), '#empty' => t('No shipping quotes have been configured yet.'));
     foreach (uc_quote_methods(TRUE) as $method) {
         if (isset($method['quote'])) {
             $id = $method['id'];
             // Build a list of operations links.
             $operations = isset($method['operations']) ? $method['operations'] : array();
             //        $operations += array('conditions' => array(
             //          'title' => t('conditions'),
             //          'url' => Url::fromRoute('admin/store/config/quotes/manage/get_quote_from_', ['id' => $id]),
             //          'weight' => 5,
             //        ));
             // Ensure "delete" comes towards the end of the list.
             if (isset($operations['delete'])) {
                 $operations['delete']['weight'] = 10;
             }
             uasort($operations, 'Drupal\\Component\\Utility\\SortArray::sortByWeightElement');
             $form['methods'][$id]['status'] = array('#type' => 'checkbox', '#title' => SafeMarkup::checkPlain($method['title']), '#default_value' => $method['enabled']);
             $form['methods'][$id]['description'] = array('#markup' => isset($method['description']) ? $method['description'] : '');
             $form['methods'][$id]['weight'] = array('#type' => 'weight', '#default_value' => $method['weight'], '#attributes' => array('class' => array('uc-quote-method-weight')));
             $form['methods'][$id]['operations'] = array('#type' => 'operations', '#links' => $operations);
         }
     }
     $shipping_types = uc_quote_shipping_type_options();
     if (is_array($shipping_types)) {
         $form['uc_quote_type_weight'] = array('#type' => 'details', '#title' => t('List position'), '#description' => t('Determines which shipping methods are quoted at checkout when products of different shipping types are ordered. Larger values take precedence.'), '#tree' => TRUE);
         $weight = $quote_config->get('type_weight');
         $shipping_methods = \Drupal::moduleHandler()->invokeAll('uc_shipping_method');
         $method_types = array();
         foreach ($shipping_methods as $method) {
             // Get shipping method types from shipping methods that provide quotes
             if (isset($method['quote'])) {
                 $method_types[$method['quote']['type']][] = $method['title'];
             }
         }
         if (isset($method_types['order']) && is_array($method_types['order'])) {
             $count = count($method_types['order']);
             $form['uc_quote_type_weight']['#description'] .= $this->formatPlural($count, '<br />The %list method is compatible with any shipping type.', '<br />The %list methods are compatible with any shipping type.', array('%list' => implode(', ', $method_types['order'])));
         }
         foreach ($shipping_types as $id => $title) {
             $form['uc_quote_type_weight'][$id] = array('#type' => 'weight', '#title' => $title . (isset($method_types[$id]) && is_array($method_types[$id]) ? ' (' . implode(', ', $method_types[$id]) . ')' : ''), '#delta' => 5, '#default_value' => isset($weight[$id]) ? $weight[$id] : 0);
         }
     }
     $form['uc_store_shipping_type'] = array('#type' => 'select', '#title' => t('Default order fulfillment type for products'), '#options' => $shipping_types, '#default_value' => $quote_config->get('shipping_type'));
     return parent::buildForm($form, $form_state);
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, OrderInterface $uc_order = NULL)
 {
     $form['#tree'] = TRUE;
     $form['#attached']['library'][] = 'uc_fulfillment/uc_fulfillment.scripts';
     $shipping_types_products = array();
     foreach ($uc_order->products as $product) {
         if (uc_order_product_is_shippable($product)) {
             $product->shipping_type = uc_product_get_shipping_type($product);
             $shipping_types_products[$product->shipping_type][] = $product;
         }
     }
     $quote_config = \Drupal::config('uc_quote.settings');
     $shipping_type_weights = $quote_config->get('type_weight');
     $result = db_query('SELECT op.order_product_id, SUM(pp.qty) AS quantity FROM {uc_packaged_products} pp LEFT JOIN {uc_packages} p ON pp.package_id = p.package_id LEFT JOIN {uc_order_products} op ON op.order_product_id = pp.order_product_id WHERE p.order_id = :id GROUP BY op.order_product_id', [':id' => $uc_order->id()]);
     $packaged_products = $result->fetchAllKeyed();
     $form['shipping_types'] = array();
     $header = array(array('data' => '', 'class' => array('select-all')), 'model' => $this->t('SKU'), 'name' => $this->t('Title'), 'qty' => $this->t('Quantity'), 'package' => $this->t('Package'));
     $shipping_type_options = uc_quote_shipping_type_options();
     foreach ($shipping_types_products as $shipping_type => $products) {
         $form['shipping_types'][$shipping_type] = array('#type' => 'fieldset', '#title' => isset($shipping_type_options[$shipping_type]) ? $shipping_type_options[$shipping_type] : Unicode::ucwords(str_replace('_', ' ', $shipping_type)), '#weight' => isset($shipping_type_weights[$shipping_type]) ? $shipping_type_weights[$shipping_type] : 0);
         $form['shipping_types'][$shipping_type]['table'] = array('#type' => 'table', '#header' => $header, '#empty' => $this->t('There are no products available for this type of package.'));
         foreach ($products as $product) {
             $unboxed_qty = $product->qty->value;
             if (isset($packaged_products[$product->order_product_id->value])) {
                 $unboxed_qty -= $packaged_products[$product->order_product_id->value];
             }
             if ($unboxed_qty > 0) {
                 $row = array();
                 $row['checked'] = array('#type' => 'checkbox', '#default_value' => 0);
                 $row['model'] = array('#plain_text' => $product->model->value);
                 $row['name'] = array('#markup' => $product->title->value);
                 $range = range(1, $unboxed_qty);
                 $row['qty'] = array('#type' => 'select', '#title' => $this->t('Quantity'), '#title_display' => 'invisible', '#options' => array_combine($range, $range), '#default_value' => $unboxed_qty);
                 $range = range(0, count($uc_order->products));
                 $options = array_combine($range, $range);
                 $options[0] = $this->t('Sep.');
                 $row['package'] = array('#type' => 'select', '#title' => $this->t('Package'), '#title_display' => 'invisible', '#options' => $options, '#default_value' => 0);
                 $form['shipping_types'][$shipping_type]['table'][$product->order_product_id->value] = $row;
             }
         }
     }
     $form['order_id'] = array('#type' => 'hidden', '#value' => $uc_order->id());
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['create'] = array('#type' => 'submit', '#value' => $this->t('Make packages'));
     $form['actions']['combine'] = array('#type' => 'submit', '#value' => $this->t('Create one package'));
     $form['actions']['cancel'] = array('#type' => 'submit', '#value' => $this->t('Cancel'));
     return $form;
 }
Ejemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, OrderInterface $uc_order = NULL, $package_id = NULL)
 {
     $this->package = Package::load($package_id);
     $form['#tree'] = TRUE;
     $form['#attached']['library'][] = 'uc_fulfillment/uc_fulfillment.scripts';
     $products = array();
     $shipping_types_products = array();
     foreach ($uc_order->products as $product) {
         if (uc_order_product_is_shippable($product)) {
             $product->shipping_type = uc_product_get_shipping_type($product);
             $shipping_types_products[$product->shipping_type][$product->order_product_id->value] = $product;
             $products[$product->order_product_id->value] = $product;
         }
     }
     $header = array(array('data' => '', 'class' => array('select-all')), 'model' => $this->t('SKU'), 'name' => $this->t('Title'), 'qty' => $this->t('Quantity'));
     $result = db_query('SELECT order_product_id, SUM(qty) AS quantity FROM {uc_packaged_products} pp LEFT JOIN {uc_packages} p ON pp.package_id = p.package_id WHERE p.order_id = :id GROUP BY order_product_id', [':id' => $uc_order->id()]);
     foreach ($result as $packaged_product) {
         // Make already packaged products unavailable, except those in this package.
         $products[$packaged_product->order_product_id]->qty->value -= $packaged_product->quantity;
         if (isset($this->package->products[$packaged_product->order_product_id])) {
             $products[$packaged_product->order_product_id]->qty->value += $this->package->products[$packaged_product->order_product_id]->qty;
         }
     }
     $form['products'] = array('#type' => 'table', '#header' => $header, '#empty' => $this->t('There are no products available for this type of package.'));
     foreach ($products as $product) {
         if ($product->qty->value > 0) {
             $row = array();
             $row['checked'] = array('#type' => 'checkbox', '#default_value' => isset($this->package->products[$product->order_product_id->value]));
             $row['model'] = array('#markup' => $product->model->value);
             $row['name'] = array('#markup' => $product->title->value);
             $range = range(1, $product->qty->value);
             $row['qty'] = array('#type' => 'select', '#options' => array_combine($range, $range), '#default_value' => isset($this->package->products[$product->order_product_id->value]) ? $this->package->products[$product->order_product_id->value]->qty : 1);
             $form['products'][$product->order_product_id->value] = $row;
         }
     }
     $options = array();
     $shipping_type_options = uc_quote_shipping_type_options();
     foreach (array_keys($shipping_types_products) as $type) {
         $options[$type] = isset($shipping_type_options[$type]) ? $shipping_type_options[$type] : Unicode::ucwords(str_replace('_', ' ', $type));
     }
     $form['shipping_type'] = array('#type' => 'select', '#title' => $this->t('Shipping type'), '#options' => $options, '#default_value' => isset($this->package->shipping_type) ? $this->package->shipping_type : 'small_package');
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save'));
     return $form;
 }