Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.66 KB | None | 0 0
  1. /**
  2.  * Implementation of hook_form_alter().
  3.  */
  4. function internetdevels_form_alter(&$form, &$form_state, $form_id) {
  5. //  drupal_set_message('<pre>' . print_r(unserialize($form_state['post']['cart_contents']), 1) . '</pre>');
  6.   if ($form_id == 'uc_cart_checkout_form') {
  7.     if (isset($_SESSION['mail_msg'])) {
  8.       unset($_SESSION['mail_msg']);
  9.     }
  10.  
  11. //    $sku = unserialize($form_state['post']['cart_contents']);
  12. //    drupal_set_message('<pre>' . print_r($sku, 1) . '</pre>');
  13. //    $email = $form['account']['mail']['#default_value'];
  14.  
  15.     $default = unserialize(variable_get('ID_ZONE_EDIT_RESULT', ''));
  16.     $form['panes']['billing']['billing_address_select']['#access'] = FALSE;
  17.     foreach($form['panes']['billing']['billing_zone']['#options'] as $key => $elements) {
  18.       if (!in_array($key, $default) && is_numeric($key)) {
  19.         unset($form['panes']['billing']['billing_zone']['#options'][$key]);
  20.       }
  21.     }
  22.     if ($form_state['post']['op'] == t('Review order')) {
  23.       if (isset($form_state['post']['cart_contents']) && !empty($form_state['post']['cart_contents'])) {
  24.         $items = unserialize($form_state['post']['cart_contents']);
  25.         if (!empty($items) && is_array($items)) {
  26.           $price    = 0;
  27.           $products = '';
  28.           foreach ($items as $item) {
  29.             $products .= $item->title . ', ';
  30.             $price    += $item->price;
  31.           }
  32.  
  33.           if (!empty($form_state['post']['panes']['billing'])) {
  34.             $billing = $form_state['post']['panes']['billing'];
  35.             if (!empty($billing['billing_first_name']) && !empty($billing['billing_last_name']) && !empty($billing['billing_phone'])) {
  36.               $first_name = $billing['billing_first_name'];
  37.               $last_name  = $billing['billing_last_name'];
  38.               $phone  = $billing['billing_phone'];
  39.  
  40. //              drupal_set_message('<pre>' . print_r($email, 1) . '</pre>');
  41. //              drupal_set_message('<pre>' . print_r($phone, 1) . '</pre>');
  42.               $message = t('The customer !first_name !last_name buy products: !products worth !price grn, phone: !phone. email: !email, sku: !sku',
  43.                 array(
  44.                   '!first_name' => $first_name,
  45.                   '!last_name'  => $last_name,
  46.                   '!phone'      => $phone,
  47.                   '!email'      => $email,
  48.                   '!sku'        => $sku,
  49.                   '!products'   => $products,
  50.                   '!price'      => $price,
  51.                 )
  52.               );
  53.               $mail_message = array(
  54.                 'to'      => EDITOR_EMAIL,
  55.                 'subject' => t('New order buyer !first_name !last_name',
  56.                   array(
  57.                     '!first_name' => $first_name,
  58.                     '!last_name'  => $last_name,
  59.                     '!phone'      => $phone,
  60.                     '!email'      => $email,
  61.                     '!sku'        => $sku,
  62.                   )
  63.                 ),
  64.                 'body'    => $message,
  65.                 'headers' => array(),
  66.               );
  67.               $_SESSION['mail_msg'] = $mail_message;
  68.  
  69.             }
  70.           }
  71.         }
  72.       }
  73.     }
  74.   }
  75.   if ($form_id == 'uc_cart_checkout_review_form' && $form_state['post']['op'] == t('Submit order')) {
  76.     $message = $_SESSION['mail_msg'];
  77.     unset($_SESSION['mail_msg']);
  78.     drupal_mail_send($message);
  79.   }
  80.   if (strstr($form_id, 'webform_client_form_')) {
  81.     if (!empty($form['captcha']['#description'])) {
  82.       $form['captcha']['#description'] = t($form['captcha']['#description']);
  83.     }
  84.   }
  85.   if ($form_id == 'product_node_form') {
  86.     $form['#validate'][] = 'internetdevels_validate_sku';
  87.   }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement