/** * {@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(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; }
/** * Builds and processes an order pane defined by hook_uc_order_pane(). * * @param $op * The operation the pane is performing. Possible values are "view", * "customer", "edit-form", "edit-theme" or "edit-process". * @param $order * The order being viewed or edited. * @param $form * The order's edit form. NULL for non-edit ops. * @param &$form_state * The form state array of the edit form. NULL for non-edit ops. * * @return * Varies according to the value of $op: * - view: A render array showing admin-visible order data. * - customer: A render array showing customer-visible order data. * - edit-form: $form with the pane grafted in. * - edit-theme: The rendered portion of the $form that the pane added. * - edit-process: An array of values to be modified on the order object, * keyed by the object's property, or NULL to signify no change on the order * object. */ function uc_order_pane_callback($op, $order, &$form = NULL, &$form_state = NULL) { global $user; switch ($op) { case 'view': $comments = uc_order_comments_load($order->order_id, TRUE); return tapir_get_table('uc_op_admin_comments_view_table', $comments); case 'edit-form': $form['admin_comment_field'] = array('#type' => 'fieldset', '#title' => t('Add an admin comment'), '#collapsible' => TRUE, '#collapsed' => TRUE); $form['admin_comment_field']['admin_comment'] = array('#type' => 'textarea', '#description' => t('Admin comments are only seen by store administrators.')); return $form; case 'edit-theme': $comments = uc_order_comments_load($form['order_id']['#value'], TRUE); if (is_array($comments) && count($comments) > 0) { foreach ($comments as $comment) { $items[] = '[' . theme('uc_uid', array('uid' => $comment->uid)) . '] ' . filter_xss_admin($comment->message); } } else { $items = array(t('No admin comments have been entered for this order.')); } $output = theme('item_list', array('items' => $items)) . drupal_render($form['admin_comment_field']); return $output; case 'edit-process': if (!empty($order['admin_comment'])) { uc_order_comment_save($order['order_id'], $user->uid, $order['admin_comment']); } return; } }
function moysklad_uc_checkout_complete($order, $account) { // dpm($order); // dpm($account); // dpm(array_keys(get_defined_vars())); $comment = uc_order_comments_load($order->order_id); $description = "Оформлен заказ номер: " . $order->order_id . "\n"; // немного хардкода if (function_exists('uc_extra_fields_pane_value_load') && function_exists('_delivery_type_description')) { $dd = uc_extra_fields_pane_value_load($order->order_id, 12, 1); $description .= "Предпочтительный способ доставки: " . _delivery_type_description($dd->value) . "\n"; } $description .= "Адрес доставки: " . $order->delivery_city . " " . $order->delivery_street1 . " " . $order->delivery_street2 . "\n"; $description .= "Комментарий клиента к заказу: " . $comment[0]->message; // если нет возможности получить auuid из почты пользователя, например новый // анонимный пользователь, то присваиваем дефолтное значение и пытаемся создать // нового пользователя в моем складе $mail = $order->primary_email; if (!($auuid = _moysklad_email_to_auuid($mail))) { $auuid = variable_get('default_auuid', ''); $body = _moysklad_user_to_xml(array("first_name" => $order->delivery_first_name, "last_name" => $order->delivery_last_name, "company" => $order->delivery_company, "phone" => $order->delivery_phone, "email" => $order->primary_email, "street1" => $order->delivery_street1, "street2" => $order->delivery_street2, "city" => $order->delivery_city), variable_get('moysklad_login')); $respond = _moysklad_company_send($body) or die("Мой склад не отвечает"); $respondXML = simplexml_load_string($respond); // если пользователь создался используем его auuid // и обновляем кеш пользователей с моего склада if ($respondXML->uuid) { $auuid = $respondXML->uuid; moysklad_users_cache(); drupal_set_message(t('New user created successfully.')); drupal_set_message(t('User cache was renewed.')); } else { drupal_set_message(t('Can`t create new user, use default user auuid instead'), 'error'); } } $items = $order->products; $coupons = false; if (isset($order->data['coupons'])) { $coupons = $order->data['coupons']; } $body = _moysklad_user_order_to_xml($auuid, $items, $coupons, $description); _moysklad_order_send($body); }