Esempio n. 1
0
 public static function get_instance()
 {
     if (is_null(self::$instance)) {
         self::$instance = new WPSC_Message_Collection();
     }
     return self::$instance;
 }
Esempio n. 2
0
 public function __construct()
 {
     require_once WPSC_TE_V2_CLASSES_PATH . '/message-collection.php';
     add_filter('template_include', array($this, '_filter_template_router'));
     add_action('wpsc_router_init', array($this, 'force_ssl'));
     $this->message_collection = WPSC_Message_Collection::get_instance();
 }
Esempio n. 3
0
function wpsc_get_inline_validation_error($field, $types = 'validation', $context = 'inline', $mode = 'all')
{
    static $cache = array();
    $cache_key = md5($types . ':' . $context . ':' . $mode);
    if (!array_key_exists($cache_key, $cache)) {
        $message_collection = WPSC_Message_Collection::get_instance();
        $cache[$cache_key] = $message_collection->query($types, $context, $mode);
    }
    $errors = array();
    foreach ($cache[$cache_key] as $type => $messages) {
        if (array_key_exists($field, $messages)) {
            $errors[] = $messages[$field];
        }
    }
    return $errors;
}
Esempio n. 4
0
/**
 * Register a customer to the store website.
 *
 * @since  4.0
 *
 * @param  string  $username Username
 * @param  string  $email    Email address
 * @param  boolean $redirect Whether or not to redirect to the login page.
 *
 * @return mixed Null if redirected or errors are present, User ID if created successfully.
 */
function wpsc_register_customer($username = '', $email = '', $redirect = true)
{
    $errors = new WP_Error();
    do_action('register_post', $username, $email, $errors);
    $errors = apply_filters('registration_errors', $errors, $username, $email);
    if ($errors->get_error_code()) {
        wpsc_set_validation_error($errors);
        return;
    }
    $password = wp_generate_password(12, false);
    $user_id = wp_insert_user(apply_filters('wpsc_register_customer_args', array('user_login' => $username, 'user_pass' => $password, 'user_email' => $email)));
    $message_collection = WPSC_Message_Collection::get_instance();
    if (is_wp_error($user_id)) {
        foreach ($user_id->get_error_messages() as $message) {
            $message_collection->add($message, 'error');
        }
        return;
    }
    if (!$user_id) {
        $message = apply_filters('wpsc_register_unknown_error_message', __('Sorry, but we could not process your registration information. Please <a href="mailto:%s">contact us</a>, or try again later.', 'wpsc'));
        $message_collection->add(sprintf($message, get_option('admin_email'), 'error'));
        return;
    }
    update_user_option($user_id, 'default_password_nag', true, true);
    //Set up the Password change nag.
    $notification = wpsc_send_registration_notification($user_id, $username, $email, $password);
    if (!$notification) {
        $message = apply_filters('wpsc_register_email_did_not_send', __('We were able to create your account, but our server was unable to send an email to you. Please <a href="mailto:%s">contact us</a>.', 'wpsc'));
        $message_collection->add(sprintf($message, get_option('admin_email'), 'error'));
        return;
    } else {
        $message_collection->add(__('We just sent you an email containing your generated password. Just follow the directions in that email to complete your registration.', 'wpsc'), 'success', 'main', 'flash');
    }
    if ($redirect) {
        wp_redirect(wpsc_get_login_url());
        exit;
    } else {
        return $user_id;
    }
}
function wpsc_has_user_messages($type = 'all', $context = 'main')
{
    $message_collection = WPSC_Message_Collection::get_instance();
    $messages = $message_collection->query($type, $context);
    return !empty($messages);
}
 public function set_customer_details()
 {
     $_POST['wpsc_checkout_details'] = array();
     $_GET['amazon_reference_id'] = sanitize_text_field($_POST['amazon_reference_id']);
     try {
         if (!$this->reference_id) {
             throw new Exception(__('An Amazon payment method was not chosen.', 'wpsc'));
         }
         if (is_null($this->purchase_log)) {
             $log = _wpsc_get_current_controller()->get_purchase_log();
             wpsc_update_customer_meta('current_purchase_log_id', $log->get('id'));
             $this->set_purchase_log($log);
         }
         global $wpsc_cart;
         // Update order reference with amounts
         $response = $this->api_request(array('Action' => 'SetOrderReferenceDetails', 'AmazonOrderReferenceId' => $this->reference_id, 'OrderReferenceAttributes.OrderTotal.Amount' => $wpsc_cart->calculate_total_price(), 'OrderReferenceAttributes.OrderTotal.CurrencyCode' => strtoupper($this->get_currency_code()), 'OrderReferenceAttributes.SellerNote' => sprintf(__('Order %s from %s.', 'wpsc'), $this->purchase_log->get('id'), urlencode(remove_accents(wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES)))), 'OrderReferenceAttributes.SellerOrderAttributes.SellerOrderId' => $this->purchase_log->get('id'), 'OrderReferenceAttributes.SellerOrderAttributes.StoreName' => remove_accents(wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES)), 'OrderReferenceAttributes.PlatformId' => 'A2Z8DY3R4G08IM'));
         if (is_wp_error($response)) {
             throw new Exception($response->get_error_message());
         }
         if (isset($response['Error']['Message'])) {
             throw new Exception($response['Error']['Message']);
         }
         $response = $this->api_request(array('Action' => 'GetOrderReferenceDetails', 'AmazonOrderReferenceId' => $this->reference_id));
         if (is_wp_error($response)) {
             throw new Exception($response->get_error_message());
         }
         if (!isset($response['GetOrderReferenceDetailsResult']['OrderReferenceDetails']['Destination']['PhysicalDestination'])) {
             return;
         }
         $address = $response['GetOrderReferenceDetailsResult']['OrderReferenceDetails']['Destination']['PhysicalDestination'];
         remove_action('wpsc_checkout_get_fields', '__return_empty_array');
         add_filter('wpsc_validate_form', '__return_true');
         $form = WPSC_Checkout_Form::get();
         $fields = $form->get_fields();
         foreach ($fields as $field) {
             switch ($field->unique_name) {
                 case 'shippingstate':
                     $_POST['wpsc_checkout_details'][$field->id] = WPSC_Countries::get_region_id($address['CountryCode'], $address['StateOrRegion']);
                     break;
                 case 'shippingcountry':
                     $_POST['wpsc_checkout_details'][$field->id] = $address['CountryCode'];
                     break;
                 case 'shippingpostcode':
                     $_POST['wpsc_checkout_details'][$field->id] = $address['PostalCode'];
                     break;
                 case 'shippingcity':
                     $_POST['wpsc_checkout_details'][$field->id] = $address['City'];
                     break;
             }
         }
     } catch (Exception $e) {
         WPSC_Message_Collection::get_instance()->add($e->getMessage(), 'error', 'main', 'flash');
         return;
     }
 }
Esempio n. 7
0
function wpsc_get_user_messages($args = '')
{
    $defaults = array('context' => 'main', 'types' => 'all', 'before_message_list' => '<div class="%s">', 'after_message_list' => '</div>', 'before_message_item' => '<p>', 'after_message_item' => '</p>');
    $r = wp_parse_args($args, $defaults);
    extract($r);
    $message_collection = WPSC_Message_Collection::get_instance();
    $messages = $message_collection->query($types, $context);
    $output = '';
    foreach ($messages as $type => $type_messages) {
        $classes = "wpsc-alert wpsc-alert-block wpsc-alert-{$type}";
        if ($type == 'validation') {
            $classes .= ' wpsc-alert-error';
        }
        $output .= sprintf($before_message_list, $classes);
        foreach ($type_messages as $message) {
            $output .= $before_message_item;
            $output .= apply_filters('wpsc_inline_validation_error_message', $message);
            $output .= $after_message_item;
        }
        $output .= $after_message_list;
    }
    return $output;
}