/**
  * {@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;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function orderSave(OrderInterface $order)
 {
     if (empty($order->payment_details['description'])) {
         db_delete('uc_payment_other')->condition('order_id', $order->id())->execute();
     } else {
         db_merge('uc_payment_other')->key(array('order_id' => $order->id()))->fields(array('description' => $order->payment_details['description']))->execute();
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, OrderInterface $order = NULL, $line_item_id = '')
 {
     $func = _uc_line_item_data($line_item_id, 'callback');
     if (!function_exists($func) || ($form = $func('form', $order->id())) == NULL) {
         $form['title'] = array('#type' => 'textfield', '#title' => $this->t('Line item title'), '#description' => $this->t('Display title of the line item.'), '#size' => 32, '#maxlength' => 128, '#default_value' => _uc_line_item_data($line_item_id, 'title'));
         $form['amount'] = array('#type' => 'uc_price', '#title' => $this->t('Line item amount'), '#allow_negative' => TRUE);
     }
     $form['order_id'] = array('#type' => 'hidden', '#value' => $order->id());
     $form['line_item_id'] = array('#type' => 'hidden', '#value' => $line_item_id);
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Add line item'), '#suffix' => Link::createFromRoute($this->t('Cancel'), 'entity.uc_order.edit_form', ['uc_order' => $order->id()])->toString());
     return $form;
 }
 /**
  * {@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;
 }
 /**
  * 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;
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 public function orderSubmit(OrderInterface $order)
 {
     if ($order->getTotal() >= 0.01) {
         return array(array('pass' => FALSE, 'message' => t('We cannot process your order without payment.')));
     }
     uc_payment_enter($order->id(), 'free_order', 0, 0, NULL, t('Checkout completed for a free order.'));
 }
 /**
  * {@inheritdoc}
  */
 public function view(OrderInterface $order, $view_mode)
 {
     if ($view_mode == 'customer' && $order->access('invoice')) {
         $build = array('#type' => 'link', '#title' => $this->t('Click to open a window with a printable invoice.'), '#url' => Url::fromRoute('uc_order.user_invoice_print', ['user' => $order->getOwnerId(), 'uc_order' => $order->id()], array('attributes' => array('onclick' => "window.open(this.href, '" . $this->t('Invoice') . "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=480,left=50,top=50'); return false;"))));
         return $build;
     }
 }
Example #8
0
 /**
  * {@inheritdoc}
  */
 public function view(OrderInterface $order, $view_mode)
 {
     if ($view_mode == 'customer' || $view_mode == 'view') {
         $tracking = array();
         $result = db_query('SELECT sid FROM {uc_shipments} WHERE order_id = :id', [':id' => $order->id()]);
         foreach ($result as $shipment) {
             $shipment = Shipment::load($shipment->sid);
             if ($shipment->tracking_number) {
                 $tracking[$shipment->carrier]['data'] = $shipment->carrier;
                 $tracking[$shipment->carrier]['children'][] = $shipment->tracking_number;
             } else {
                 foreach ($shipment->packages as $package) {
                     if ($package->tracking_number) {
                         $tracking[$shipment->carrier]['data'] = $shipment->carrier;
                         $tracking[$shipment->carrier]['children'][] = $package->tracking_number;
                     }
                 }
             }
         }
         // Do not show an empty pane to customers.
         if ($view_mode == 'view' || !empty($tracking)) {
             $build['tracking'] = array('#theme' => 'item_list', '#items' => $tracking);
             return $build;
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, OrderInterface $uc_order = NULL, $payment = NULL)
 {
     $this->payment = uc_payment_load($payment);
     // Make sure the payment is for the specified order.
     if ($this->payment->order_id != $uc_order->id()) {
         throw new NotFoundHttpException();
     }
     return parent::buildForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function review(OrderInterface $order)
 {
     $review = NULL;
     $result = db_query('SELECT message FROM {uc_order_comments} WHERE order_id = :id', [':id' => $order->id()]);
     if ($comment = $result->fetchObject()) {
         $review[] = array('title' => $this->t('Comment'), 'data' => array('#markup' => $comment->message));
     }
     return $review;
 }
 /**
  * {@inheritdoc}
  */
 public function orderView(OrderInterface $order)
 {
     $txn_id = db_query("SELECT txn_id FROM {uc_payment_paypal_ipn} WHERE order_id = :id ORDER BY received ASC", [':id' => $order->id()])->fetchField();
     if (empty($txn_id)) {
         $txn_id = $this->t('Unknown');
     }
     $build['#markup'] = $this->t('Transaction ID:<br />@txn_id', ['@txn_id' => $txn_id]);
     return $build;
 }
 /**
  * {@inheritdoc}
  */
 public function review(OrderInterface $order)
 {
     $review = NULL;
     $result = db_query("SELECT message FROM {uc_order_comments} WHERE order_id = :id", array(':id' => $order->id()));
     if ($comment = $result->fetchObject()) {
         $review[] = array('title' => t('Comment'), 'data' => SafeMarkup::checkPlain($comment->message));
     }
     return $review;
 }
 /**
  * Displays a log of changes made to an order.
  *
  * @param \Drupal\uc_order\OrderInterface $uc_order
  *   The order entity.
  *
  * @return array
  *   A render array.
  */
 public function log(OrderInterface $uc_order)
 {
     $result = db_query('SELECT order_log_id, uid, changes, created FROM {uc_order_log} WHERE order_id = :id ORDER BY order_log_id DESC', [':id' => $uc_order->id()]);
     $header = array($this->t('Time'), $this->t('User'), $this->t('Changes'));
     $rows = array();
     foreach ($result as $change) {
         $rows[] = array(\Drupal::service('date.formatter')->format($change->created, 'short'), array('data' => array('#theme' => 'uc_uid', '#uid' => $change->uid)), array('data' => array('#markup' => $change->changes)));
     }
     $build['log'] = array('#theme' => 'table', '#header' => $header, '#rows' => $rows, '#empty' => $this->t('No changes have been logged for this order.'));
     return $build;
 }
Example #14
0
 /**
  * {@inheritdoc}
  */
 public function fulfillOrder(OrderInterface $order, array $package_ids)
 {
     $shipment = new \stdClass();
     $shipment->order_id = $order->id();
     $shipment->packages = array();
     foreach ($package_ids as $id) {
         $package = Package::load($id);
         $shipment->packages[$id] = $package;
     }
     return \Drupal::formBuilder()->getForm('\\Drupal\\uc_fulfillment\\Form\\ShipmentEditForm', $order, $shipment);
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $payment = $form_state->getValue(['payments', 'new']);
     $received = strtotime($payment['received']['year'] . '-' . $payment['received']['month'] . '-' . $payment['received']['day'] . ' 00:00:00');
     // If the value entered is today, use the exact timestamp instead
     $startofday = mktime(0, 0, 0);
     if ($received == $startofday) {
         $received = REQUEST_TIME;
     }
     uc_payment_enter($this->order->id(), $payment['method'], $payment['amount'], \Drupal::currentUser()->id(), '', $payment['comment'], $received);
     drupal_set_message($this->t('Payment entered.'));
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(OrderInterface $order, array $form, FormStateInterface $form_state)
 {
     $items = array();
     $comments = uc_order_comments_load($order->id(), TRUE);
     foreach ($comments as $comment) {
         $items[] = ['username' => ['#theme' => 'uc_uid', '#uid' => $comment->uid, '#prefix' => '[', '#suffix' => '] '], 'message' => ['#markup' => $comment->message]];
     }
     $form['comments'] = array('#theme' => 'item_list', '#items' => $items, '#empty' => $this->t('No admin comments have been entered for this order.'));
     $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.'));
     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, 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;
 }
 /**
  * Handles a complete Website Payments Standard sale.
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  *   A redirect to the cart or checkout complete page.
  */
 public function wpsComplete(OrderInterface $uc_order)
 {
     // If the order ID specified in the return URL is not the same as the one in
     // the user's session, we need to assume this is either a spoof or that the
     // user tried to adjust the order on this side while at PayPal. If it was a
     // legitimate checkout, the IPN will still come in from PayPal so the order
     // gets processed correctly. We'll leave an ambiguous message just in case.
     $session = \Drupal::service('session');
     if (!$session->has('cart_order') || intval($session->get('cart_order')) != $uc_order->id()) {
         drupal_set_message($this->t('Thank you for your order! PayPal will notify us once your payment has been processed.'));
         return $this->redirect('uc_cart.cart');
     }
     // Ensure the payment method is PayPal WPS.
     $method = \Drupal::service('plugin.manager.uc_payment.method')->createFromOrder($uc_order);
     if (!$method instanceof PayPalWebsitePaymentsStandard) {
         return $this->redirect('uc_cart.cart');
     }
     // This lets us know it's a legitimate access of the complete page.
     $session = \Drupal::service('session');
     $session->set('uc_checkout_complete_' . $uc_order->id(), TRUE);
     return $this->redirect('uc_cart.checkout_complete');
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, OrderInterface $uc_order = NULL, $package_id = NULL)
 {
     $this->order_id = $uc_order->id();
     $form['package_id'] = array('#type' => 'value', '#value' => $package_id);
     return parent::buildForm($form, $form_state);
 }
 /**
  * Displays a list of shipments for an order.
  *
  * @param \Drupal\uc_order\OrderInterface $uc_order
  *   The order object.
  *
  * @return array|\Symfony\Component\HttpFoundation\RedirectResponse
  *   A render array, or redirect response if there are no shipments.
  */
 public function listOrderShipments(OrderInterface $uc_order)
 {
     $result = db_query('SELECT * FROM {uc_shipments} WHERE order_id = :id', [':id' => $uc_order->id()]);
     $header = array($this->t('Shipment ID'), $this->t('Name'), $this->t('Company'), $this->t('Destination'), $this->t('Ship date'), $this->t('Estimated delivery'), $this->t('Tracking number'), $this->t('Actions'));
     $rows = array();
     foreach ($result as $shipment) {
         $row = array();
         // Shipment ID.
         $row[] = array('data' => array('#plain_text' => $shipment->sid));
         // Name.
         $row[] = array('data' => array('#plain_text' => $shipment->d_first_name . ' ' . $shipment->d_last_name));
         // Company.
         $row[] = array('data' => array('#plain_text' => $shipment->d_company));
         // Destination.
         $row[] = array('data' => array('#plain_text' => $shipment->d_city . ', ' . $shipment->d_zone . ' ' . $shipment->d_postal_code));
         // Ship date.
         $row[] = \Drupal::service('date.formatter')->format($shipment->ship_date, 'uc_store');
         // Estimated delivery.
         $row[] = \Drupal::service('date.formatter')->format($shipment->expected_delivery, 'uc_store');
         // Tracking number.
         $row[] = is_null($shipment->tracking_number) ? $this->t('n/a') : array('data' => array('#plain_text' => $shipment->tracking_number));
         // Actions.
         $ops[] = array('#type' => 'operations', '#links' => array('view' => array('title' => $this->t('View'), 'url' => Url::fromRoute('uc_fulfillment.view_shipment', ['uc_order' => $uc_order->id(), 'shipment_id' => $shipment->sid])), 'edit' => array('title' => $this->t('Edit'), 'url' => Url::fromRoute('uc_fulfillment.edit_shipment', ['uc_order' => $uc_order->id(), 'shipment_id' => $shipment->sid])), 'print' => array('title' => $this->t('Print'), 'url' => Url::fromRoute('uc_fulfillment.print_shipment', ['uc_order' => $uc_order->id(), 'shipment_id' => $shipment->sid])), 'packing_slip' => array('title' => $this->t('Packing slip'), 'url' => Url::fromRoute('uc_fulfillment.packing_slip', ['uc_order' => $uc_order->id(), 'shipment_id' => $shipment->sid])), 'delete' => array('title' => $this->t('Delete'), 'url' => Url::fromRoute('uc_fulfillment.delete_shipment', ['uc_order' => $uc_order->id(), 'shipment_id' => $shipment->sid]))));
         $row[] = array('data' => $ops);
         $rows[] = $row;
     }
     if (empty($rows)) {
         if (!db_query('SELECT COUNT(*) FROM {uc_packages} WHERE order_id = :id', [':id' => $uc_order->id()])->fetchField()) {
             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()]);
         } else {
             drupal_set_message($this->t('No shipments have been made for this order.'), 'warning');
             return $this->redirect('uc_fulfillment.new_shipment', ['uc_order' => $uc_order->id()]);
         }
     }
     $build['shipments'] = array('#theme' => 'table', '#header' => $header, '#rows' => $rows);
     return $build;
 }
Example #22
0
 /**
  * {@inheritdoc}
  */
 public function orderView(OrderInterface $order)
 {
     $build = array();
     // Add the hidden span for the CC details if possible.
     $account = \Drupal::currentUser();
     if ($account->hasPermission('view cc details')) {
         $rows = array();
         if (!empty($order->payment_details['cc_type'])) {
             $rows[] = t('Card type') . ': ' . SafeMarkup::checkPlain($order->payment_details['cc_type']);
         }
         if (!empty($order->payment_details['cc_owner'])) {
             $rows[] = t('Card owner') . ': ' . SafeMarkup::checkPlain($order->payment_details['cc_owner']);
         }
         if (!empty($order->payment_details['cc_number'])) {
             $rows[] = t('Card number') . ': ' . uc_credit_display_number($order->payment_details['cc_number']);
         }
         if (!empty($order->payment_details['cc_start_month']) && !empty($order->payment_details['cc_start_year'])) {
             $rows[] = t('Start date') . ': ' . $order->payment_details['cc_start_month'] . '/' . $order->payment_details['cc_start_year'];
         }
         if (!empty($order->payment_details['cc_exp_month']) && !empty($order->payment_details['cc_exp_year'])) {
             $rows[] = t('Expiration') . ': ' . $order->payment_details['cc_exp_month'] . '/' . $order->payment_details['cc_exp_year'];
         }
         if (!empty($order->payment_details['cc_issue'])) {
             $rows[] = t('Issue number') . ': ' . SafeMarkup::checkPlain($order->payment_details['cc_issue']);
         }
         if (!empty($order->payment_details['cc_bank'])) {
             $rows[] = t('Issuing bank') . ': ' . SafeMarkup::checkPlain($order->payment_details['cc_bank']);
         }
         $build['cc_info'] = array('#prefix' => '<a href="#" onclick="jQuery(this).hide().next().show();">' . t('Show card details') . '</a><div style="display: none;">', '#markup' => implode('<br />', $rows), '#suffix' => '</div>');
         // Add the form to process the card if applicable.
         if ($account->hasPermission('process credit cards')) {
             $build['terminal'] = \Drupal::formBuilder()->getForm('uc_credit_order_view_form', $order->id());
         }
     }
     return $build;
 }
Example #23
0
 /**
  * {@inheritdoc}
  */
 public function customerView(OrderInterface $order)
 {
     $build = array();
     $result = db_query('SELECT clear_date FROM {uc_payment_check} WHERE order_id = :id ', [':id' => $order->id()]);
     if ($clear_date = $result->fetchField()) {
         $build['#markup'] = t('Check received') . '<br />' . t('Expected clear date:') . '<br />' . \Drupal::service('date.formatter')->format($clear_date, 'uc_store');
     }
     return $build;
 }
Example #24
0
 /**
  * {@inheritdoc}
  */
 public function review(OrderInterface $order)
 {
     $review = array();
     $result = db_query("SELECT * FROM {uc_order_line_items} WHERE order_id = :id AND type = :type", [':id' => $order->id(), ':type' => 'shipping']);
     if ($line_item = $result->fetchAssoc()) {
         $review[] = array('title' => $line_item['title'], 'data' => array('#theme' => 'uc_price', '#price' => $line_item['amount']));
     }
     return $review;
 }
Example #25
0
 /**
  * Get payment details stored within table {uc_payment_icepay}
  *
  * @param OrderInterface $order
  * @return mixed
  */
 public function getPaymentDetails(OrderInterface $order)
 {
     $result = Database::getConnection()->select('uc_payment_icepay', 'i')->fields('i')->condition("i.order_id", $order->id())->range(0, 1)->execute()->fetchObject();
     if (isset($result)) {
         return $result;
     }
     return false;
 }
Example #26
0
 /**
  * {@inheritdoc}
  */
 public function orderDelete(OrderInterface $order)
 {
     // delete payment transaction recorded in table {uc_payment_icepay}
     Database::getConnection()->delete('uc_payment_icepay')->condition('order_id', $order->id())->execute();
 }
 /**
  * {@inheritdoc}
  */
 public function orderDelete(OrderInterface $order)
 {
     db_delete('uc_payment_cod')->condition('order_id', $order->id())->execute();
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, OrderInterface $uc_order = NULL, $shipment = NULL)
 {
     // Sometimes $shipment is an ID, sometimes it's an object. FIX THIS! @todo
     if (!is_object($shipment)) {
         // Then $shipment is an ID.
         $shipment = Shipment::load($shipment);
     } elseif (isset($shipment->sid)) {
         $form['sid'] = array('#type' => 'value', '#value' => $shipment->sid);
         $shipment = Shipment::load($shipment->sid);
         $methods = \Drupal::moduleHandler()->invokeAll('uc_fulfillment_method');
         if (isset($methods[$shipment->shipping_method])) {
             $method = $methods[$shipment->shipping_method];
         }
     }
     $form['order_id'] = array('#type' => 'value', '#value' => $uc_order->id());
     $addresses = array();
     $form['packages'] = array('#type' => 'fieldset', '#title' => $this->t('Packages'), '#tree' => TRUE);
     if (isset($shipment->o_street1)) {
         $o_address = new \stdClass();
         foreach ($shipment as $field => $value) {
             if (substr($field, 0, 2) == 'o_') {
                 $o_address->{substr($field, 2)} = $value;
             }
         }
         $addresses[] = (object) $o_address;
     }
     foreach ($shipment->packages as $id => $package) {
         foreach ($package->addresses as $address) {
             if (!in_array($address, $addresses)) {
                 $addresses[] = (object) $address;
             }
         }
         // Create list of products and get a representative product (last one in
         // the loop) to use for some default values
         $product_list = array();
         $declared_value = 0;
         foreach ($package->products as $product) {
             $product_list[] = $product->qty . ' x ' . $product->model;
             $declared_value += $product->qty * $product->price;
         }
         $pkg_form = array('#type' => 'fieldset', '#title' => $this->t('Package @id', ['@id' => $id]));
         $pkg_form['products'] = array('#theme' => 'item_list', '#items' => $product_list);
         $pkg_form['pkg_type'] = array('#type' => 'textfield', '#title' => $this->t('Package type'), '#default_value' => $package->pkg_type, '#description' => $this->t('For example: Box, pallet, tube, envelope, etc.'));
         if (isset($method) && is_array($method['ship']['pkg_types'])) {
             $pkg_form['pkg_type']['#type'] = 'select';
             $pkg_form['pkg_type']['#options'] = $method['ship']['pkg_types'];
             $pkg_form['pkg_type']['#description'] = '';
         }
         $pkg_form['declared_value'] = array('#type' => 'uc_price', '#title' => $this->t('Declared value'), '#default_value' => isset($package->value) ? $package->value : $declared_value);
         $pkg_form['weight'] = array('#type' => 'container', '#attributes' => array('class' => array('uc-inline-form', 'clearfix')), '#description' => $this->t('Weight of the package. Default value is sum of product weights in the package.'), '#weight' => 15);
         $pkg_form['weight']['weight'] = array('#type' => 'number', '#title' => $this->t('Weight'), '#min' => 0, '#step' => 'any', '#default_value' => isset($package->weight) ? $package->weight : 0, '#size' => 10);
         $pkg_form['weight']['units'] = array('#type' => 'select', '#title' => $this->t('Units'), '#options' => array('lb' => $this->t('Pounds'), 'kg' => $this->t('Kilograms'), 'oz' => $this->t('Ounces'), 'g' => $this->t('Grams')), '#default_value' => isset($package->weight_units) ? $package->weight_units : \Drupal::config('uc_store.settings')->get('weight.units'));
         $pkg_form['dimensions'] = array('#type' => 'container', '#attributes' => array('class' => array('uc-inline-form', 'clearfix')), '#title' => $this->t('Dimensions'), '#description' => $this->t('Physical dimensions of the packaged product.'), '#weight' => 20);
         $pkg_form['dimensions']['length'] = array('#type' => 'number', '#title' => $this->t('Length'), '#min' => 0, '#step' => 'any', '#default_value' => isset($package->length) ? $package->length : 1, '#size' => 8);
         $pkg_form['dimensions']['width'] = array('#type' => 'number', '#title' => $this->t('Width'), '#min' => 0, '#step' => 'any', '#default_value' => isset($package->width) ? $package->width : 1, '#size' => 8);
         $pkg_form['dimensions']['height'] = array('#type' => 'number', '#title' => $this->t('Height'), '#min' => 0, '#step' => 'any', '#default_value' => isset($package->height) ? $package->height : 1, '#size' => 8);
         $pkg_form['dimensions']['units'] = array('#type' => 'select', '#title' => $this->t('Units of measurement'), '#options' => array('in' => $this->t('Inches'), 'ft' => $this->t('Feet'), 'cm' => $this->t('Centimeters'), 'mm' => $this->t('Millimeters')), '#default_value' => isset($package->length_units) ? $package->length_units : \Drupal::config('uc_store.settings')->get('length.units'));
         $pkg_form['tracking_number'] = array('#type' => 'textfield', '#title' => $this->t('Tracking number'), '#default_value' => isset($package->tracking_number) ? $package->tracking_number : '');
         $form['packages'][$id] = $pkg_form;
     }
     if (!empty($shipment->d_street1)) {
         foreach ($shipment as $field => $value) {
             if (substr($field, 0, 2) == 'd_') {
                 $uc_order->{'delivery_' . substr($field, 2)} = $value;
             }
         }
     }
     $form += \Drupal::formBuilder()->getForm('\\Drupal\\uc_fulfillment\\Form\\AddressForm', $addresses, $uc_order);
     $form['shipment'] = array('#type' => 'fieldset', '#title' => $this->t('Shipment data'));
     // Determine shipping option chosen by the customer.
     $message = '';
     if (isset($uc_order->quote['method'])) {
         // Order has a quote attached.
         $method = $uc_order->quote['method'];
         $methods = \Drupal::moduleHandler()->invokeAll('uc_fulfillment_method');
         if (isset($methods[$method])) {
             // Quote is from a currently-active shipping method.
             $services = $methods[$method]['quote']['accessorials'];
             $method = $services[$uc_order->quote['accessorials']];
         }
         $message = $this->t('Customer selected "@method" as the shipping method and paid @rate', ['@method' => $method, '@rate' => uc_currency_format($uc_order->quote['rate'])]);
     } else {
         // No quotes for this order.
         $message = $this->t('There are no shipping quotes attached to this order. Customer was not charged for shipping.');
     }
     // Inform administrator of customer's shipping choice.
     $form['shipment']['shipping_choice'] = array('#type' => 'container', '#markup' => $message);
     $form['shipment']['shipping_method'] = array('#type' => 'hidden', '#value' => isset($shipment->shipping_method) ? $shipment->shipping_method : 'manual');
     $form['shipment']['carrier'] = array('#type' => 'textfield', '#title' => $this->t('Carrier'), '#default_value' => isset($shipment->carrier) ? $shipment->carrier : '');
     $form['shipment']['accessorials'] = array('#type' => 'textfield', '#title' => $this->t('Shipment options'), '#default_value' => isset($shipment->accessorials) ? $shipment->accessorials : '', '#description' => $this->t('Short notes about the shipment, e.g. residential, overnight, etc.'));
     $form['shipment']['transaction_id'] = array('#type' => 'textfield', '#title' => $this->t('Transaction ID'), '#default_value' => isset($shipment->transaction_id) ? $shipment->transaction_id : '');
     $form['shipment']['tracking_number'] = array('#type' => 'textfield', '#title' => $this->t('Tracking number'), '#default_value' => isset($shipment->tracking_number) ? $shipment->tracking_number : '');
     $ship_date = REQUEST_TIME;
     if (isset($shipment->ship_date)) {
         $ship_date = $shipment->ship_date;
     }
     $exp_delivery = REQUEST_TIME;
     if (isset($shipment->expected_delivery)) {
         $exp_delivery = $shipment->expected_delivery;
     }
     $form['shipment']['ship_date'] = array('#type' => 'datetime', '#title' => $this->t('Ship date'), '#date_date_element' => 'date', '#date_time_element' => 'none', '#default_value' => DrupalDateTime::createFromTimestamp($ship_date));
     $form['shipment']['expected_delivery'] = array('#type' => 'datetime', '#title' => $this->t('Expected delivery'), '#date_date_element' => 'date', '#date_time_element' => 'none', '#default_value' => DrupalDateTime::createFromTimestamp($exp_delivery));
     $form['shipment']['cost'] = array('#type' => 'uc_price', '#title' => $this->t('Shipping cost'), '#default_value' => isset($shipment->cost) ? $shipment->cost : 0);
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save shipment'), '#weight' => 10);
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, OrderInterface $uc_order = NULL, Request $request = NULL)
 {
     $checked_pkgs = $request->query->has('pkgs') ? (array) $request->query->get('pkgs') : array();
     $form['#tree'] = TRUE;
     $form['#attached']['library'][] = 'uc_fulfillment/uc_fulfillment.scripts';
     $units = \Drupal::config('uc_store.settings')->get('weight.units');
     $result = db_query('SELECT * FROM {uc_packages} WHERE order_id = :id AND sid IS NULL', [':id' => $uc_order->id()]);
     $header = array(array('data' => '', 'class' => array('select-all')), 'package' => $this->t('Package'), 'product' => $this->t('Products'), 'weight' => $this->t('Weight'));
     $packages_by_type = array();
     foreach ($result as $package) {
         $products = array();
         $weight = 0;
         $result2 = db_query('SELECT pp.order_product_id, pp.qty, pp.qty * op.weight__value AS weight, op.weight__units, 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) {
             $units_conversion = uc_weight_conversion($product->weight__units, $units);
             $weight += $product->weight * $units_conversion;
             $products[$product->order_product_id] = $product;
         }
         $package->weight = $weight;
         $package->products = $products;
         $packages_by_type[$package->shipping_type][$package->package_id] = $package;
     }
     // Find FulfillmentMethod plugins.
     $methods = FulfillmentMethod::loadMultiple();
     uasort($methods, 'Drupal\\uc_fulfillment\\Entity\\FulfillmentMethod::sort');
     foreach ($methods as $method) {
         // Available fulfillment methods indexed by package type.
         $shipping_methods_by_type[$method->getPackageType()][] = $method;
     }
     $pkgs_exist = FALSE;
     $option_methods = array();
     $shipping_types = uc_quote_get_shipping_types();
     foreach ($packages_by_type as $shipping_type => $packages) {
         $form['shipping_types'][$shipping_type] = array('#type' => 'fieldset', '#title' => $shipping_types[$shipping_type]['title']);
         $rows = array();
         $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 ($packages as $package) {
             $pkgs_exist = TRUE;
             $row = array();
             $row['checked'] = array('#type' => 'checkbox', '#default_value' => in_array($package->package_id, $checked_pkgs) ? 1 : 0);
             $row['package_id'] = array('#markup' => $package->package_id);
             $product_list = array();
             foreach ($package->products as $product) {
                 $product_list[] = $product->qty . ' x ' . $product->model;
             }
             $row['products'] = array('#theme' => 'item_list', '#items' => $product_list);
             $row['weight'] = array('#markup' => uc_weight_format($package->weight, $units));
             $form['shipping_types'][$shipping_type]['table'][$package->package_id] = $row;
         }
         if (isset($shipping_methods_by_type[$shipping_type])) {
             foreach ($shipping_methods_by_type[$shipping_type] as $method) {
                 $option_methods += array($method->id() => $method->label());
             }
         }
     }
     $form['order_id'] = array('#type' => 'hidden', '#value' => $uc_order->id());
     if ($pkgs_exist) {
         // uc_fulfillment has a default plugin to provide the "Manual" method.
         $form['method'] = array('#type' => 'select', '#title' => $this->t('Shipping method'), '#options' => $option_methods, '#default_value' => 'manual');
         $form['actions'] = array('#type' => 'actions');
         $form['actions']['ship'] = array('#type' => 'submit', '#value' => $this->t('Ship packages'));
     }
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function orderSave(OrderInterface $order)
 {
     _uc_credit_save_cc_data_to_order($order->payment_details, $order->id());
 }