/**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $recipient = $form_state->getValue('email');
     $params = array('order' => $this->order);
     \Drupal::service('plugin.manager.mail')->mail('uc_order', 'invoice', $recipient, uc_store_mail_recipient_langcode($recipient), $params, uc_store_email_from());
     $message = t('Invoice e-mailed to @email.', ['@email' => $recipient]);
     drupal_set_message($message);
     $this->order->logChanges(array($message));
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     switch ($form_state->getValue('customer_type')) {
         case 'search':
             $uid = $form_state->getValue(['customer', 'uid']);
             break;
         case 'create':
             // Create new account.
             $email = trim($form_state->getValue(['customer', 'email']));
             $fields = array('name' => uc_store_email_to_username($email), 'mail' => $email, 'pass' => user_password(), 'status' => $this->config('uc_cart.settings')->get('new_customer_status_active') ? 1 : 0);
             $account = \Drupal\user\Entity\User::create($fields);
             $account->save();
             $uid = $account->id();
             if ($form_state->getValue(['customer', 'sendmail'])) {
                 // Manually set the password so it appears in the e-mail.
                 $account->password = $fields['pass'];
                 \Drupal::service('plugin.manager.mail')->mail('user', 'register_admin_created', $email, uc_store_mail_recipient_langcode($email), array('account' => $account), uc_store_email_from());
                 drupal_set_message(t('A welcome message has been e-mailed to the new user.'));
             }
             break;
         default:
             $uid = 0;
     }
     $order = \Drupal\uc_order\Entity\Order::create(array('uid' => $uid, 'order_status' => uc_order_state_default('post_checkout')));
     $order->save();
     uc_order_comment_save($order->id(), \Drupal::currentUser()->id(), t('Order created by the administration.'), 'admin');
     $form_state->setRedirect('entity.uc_order.edit_form', ['uc_order' => $order->id()]);
 }
示例#3
0
/**
 * Allows modules to take action when a stock level is changed.
 *
 * @param $sku
 *   The SKU whose stock level is being changed.
 * @param $stock
 *   The stock level before the adjustment.
 * @param $qty
 *   The amount by which the stock level was changed.
 */
function hook_uc_stock_adjusted($sku, $stock, $qty)
{
    $params = array('sku' => $sku, 'stock' => $stock, 'qty' => $qty);
    $to = "*****@*****.**";
    \Drupal::service('plugin.manager.mail')->mail('uc_stock_notify', 'stock-adjusted', $to, uc_store_mail_recipient_langcode($to), $params, uc_store_email_from());
}
示例#4
0
 /**
  * Link a completed sale to a user.
  *
  * @param \Drupal\uc_order\Entity\Order $order
  *   The order entity that has just been completed.
  */
 protected function completeSaleAccount($order)
 {
     // Order already has a user ID, so the user was logged in during checkout.
     if ($order->getOwnerId()) {
         $order->data->complete_sale = 'logged_in';
         return;
     }
     // Email address matches an existing account.
     if ($account = user_load_by_mail($order->getEmail())) {
         $order->setOwner($account);
         $order->data->complete_sale = 'existing_user';
         return;
     }
     // Set up a new user.
     $cart_config = \Drupal::config('uc_cart.settings');
     $fields = array('name' => uc_store_email_to_username($order->getEmail()), 'mail' => $order->getEmail(), 'init' => $order->getEmail(), 'pass' => user_password(), 'roles' => array(), 'status' => $cart_config->get('new_customer_status_active') ? 1 : 0);
     // Override the username, if specified.
     if (isset($order->data->new_user_name)) {
         $fields['name'] = $order->data->new_user_name;
     }
     // Create the account.
     $account = User::create($fields);
     $account->save();
     // Override the password, if specified.
     if (isset($order->data->new_user_hash)) {
         db_query('UPDATE {users_field_data} SET pass = :hash WHERE uid = :uid', [':hash' => $order->data->new_user_hash, ':uid' => $account->id()]);
         $account->password = t('Your password');
     } else {
         $account->password = $fields['pass'];
         $order->password = $fields['pass'];
     }
     // Send the customer their account details if enabled.
     if ($cart_config->get('new_customer_email')) {
         $type = $cart_config->get('new_customer_status_active') ? 'register_no_approval_required' : 'register_pending_approval';
         \Drupal::service('plugin.manager.mail')->mail('user', $type, $order->getEmail(), uc_store_mail_recipient_langcode($order->getEmail()), array('account' => $account), uc_store_email_from());
     }
     $order->setOwner($account);
     $order->data->new_user_name = $fields['name'];
     $order->data->complete_sale = 'new_user';
 }
 /**
  * Presents the customer search results and let one of them be chosen.
  */
 public function selectCustomer(Request $request, $email = NULL, $operation = NULL)
 {
     $build = array();
     $options = NULL;
     // Return the search results and let them pick one!
     switch ($operation) {
         case 'search':
             $first_name = str_replace('*', '%', db_like($request->request->get('first_name')));
             $last_name = str_replace('*', '%', db_like($request->request->get('last_name')));
             $email = str_replace('*', '%', db_like($request->request->get('email')));
             $query = db_select('users_field_data', 'u')->distinct();
             $query->leftJoin('uc_orders', 'o', 'u.uid = o.uid');
             $query->fields('u', array('uid', 'mail'))->fields('o', array('billing_first_name', 'billing_last_name'))->condition('u.uid', 0, '>')->orderBy('o.billing_last_name');
             if ($first_name && $first_name !== '%') {
                 $query->condition('o.billing_first_name', $first_name, 'LIKE');
             }
             if ($last_name && $last_name !== '%') {
                 $query->condition('o.billing_last_name', $last_name, 'LIKE');
             }
             if ($email && $email !== '%') {
                 $query->condition(db_or()->condition('o.primary_email', $email, 'LIKE')->condition('u.mail', $email, 'LIKE'));
             }
             $result = $query->execute();
             $options = array();
             foreach ($result as $user) {
                 if (empty($user->billing_first_name) && empty($user->billing_last_name)) {
                     $name = '';
                 } else {
                     $name = $user->billing_last_name . ', ' . $user->billing_first_name . ' ';
                 }
                 $options[$user->uid . ':' . $user->mail] = $name . '(' . $user->mail . ')';
             }
             if (count($options) == 0) {
                 $build['description'] = array('#prefix' => '<p>', '#markup' => $this->t('Search returned no results.'), '#suffix' => '</p>');
                 $options = NULL;
             } else {
                 $build['description'] = array('#prefix' => '<p>', '#markup' => $this->t('Search returned the following:'), '#suffix' => '</p>');
             }
             break;
         case 'new':
             if ($request->request->get('check') == TRUE) {
                 // Check to see if the e-mail address for a new user is unique.
                 $email = SafeMarkup::checkPlain($request->request->get('email'));
                 $build['email'] = array('#markup' => '');
                 $result = db_query("SELECT uid, mail FROM {users_field_data} WHERE mail = :mail", [':mail' => $email]);
                 if ($user_field_data = $result->fetchObject()) {
                     $build['#attached']['drupalSettings'] = array('userId' => $user_field_data->uid, 'userEmail' => $user_field_data->mail);
                     $build['email']['#markup'] .= $this->t('An account already exists for that e-mail.') . '<br /><br />';
                     $build['email']['#markup'] .= '<b>' . $this->t('Use this account now?') . '</b><br />' . $this->t('User @uid - @mail', ['@uid' => $user_field_data->uid, '@mail' => $user_field_data->mail]) . ' <input type="button" id="select-existing-customer" value="' . $this->t('Apply') . '" /><br /><br /><hr /><br/>';
                 } else {
                     $name = uc_store_email_to_username($email);
                     $fields = array('name' => $name, 'mail' => $email, 'pass' => user_password(6), 'status' => \Drupal::config('uc_cart.settings')->get('new_customer_status_active') ? 1 : 0);
                     $account = \Drupal\user\Entity\User::create($fields);
                     $account->save();
                     if ($request->request->get('sendmail') == 'true') {
                         // Manually set the password so it appears in the e-mail.
                         $account->password = $fields['pass'];
                         // Send the e-mail through the user module.
                         \Drupal::service('plugin.manager.mail')->mail('user', 'register_admin_created', $email, uc_store_mail_recipient_langcode($email), array('account' => $account), uc_store_email_from());
                         $build['email']['#markup'] .= $this->t('Account details sent to e-mail provided.<br /><br /><strong>Username:</strong> @username<br /><strong>Password:</strong> @password', array('@username' => $fields['name'], '@password' => $fields['pass'])) . '<br /><br />';
                     }
                     $build['#attached']['drupalSettings'] = array('userId' => $account->id(), 'userEmail' => $account->getEmail());
                     $build['result'] = array('#markup' => '<strong>' . $this->t('Use this account now?') . '</strong><br />' . $this->t('User @uid - @mail', array('@uid' => $account->id(), '@mail' => $account->getEmail())) . ' <input type="button" ' . 'id="select-existing-customer" value="' . $this->t('Apply') . '" /><br /><br /><hr /><br/>');
                 }
             }
             break;
         default:
             break;
     }
     $build['customer_select_form'] = \Drupal::formBuilder()->getForm('\\Drupal\\uc_order\\Form\\SelectCustomerForm', $operation, $options);
     return new Response(drupal_render($build));
 }