protected function tfoot_append()
    {
        $prev = isset($_REQUEST['prev']) ? esc_attr($_REQUEST['prev']) : '';
        $clear_cart_url = add_query_arg(array('prev' => $prev, '_wp_nonce' => wp_create_nonce('wpsc-clear-cart')), wpsc_get_cart_url('clear'));
        ?>
		<tr class="wpsc-cart-item-table-actions">
			<td></td>
			<td colspan="<?php 
        echo count($this->columns) - 1;
        ?>
">
				<a class="wpsc-button wpsc-button-small wpsc-clear-cart" href="<?php 
        echo esc_url($clear_cart_url);
        ?>
"><?php 
        esc_html_e('Clear Cart', 'wp-e-commerce');
        ?>
</a>
				<input type="hidden" name="action" value="update_quantity" />
				<input type="hidden" name="prev" value="<?php 
        echo $prev;
        ?>
">
			</td>
		</tr>
		<?php 
    }
 /**
  * Generate the form configuration array for this tab
  *
  * @since  0.1
  * @access private
  */
 private function populate_form_array()
 {
     // define the sections
     $this->sections = array('locations' => array('title' => _x('Page Slugs', 'page locations section title', 'wpsc'), 'fields' => array('store_slug', 'store_as_front_page', 'category_base_slug', 'product_base_slug', 'cart_page_slug', 'checkout_page_slug', 'customer_account_page_slug', 'login_page_slug', 'password_reminder_page_slug', 'register_page_slug', 'prefix_product_slug', 'hierarchical_product_category_url')), 'titles' => array('title' => _x('Page Titles', 'page titles section title', 'wpsc'), 'fields' => array('store_title', 'cart_page_title', 'checkout_page_title', 'customer_account_page_title', 'login_page_title', 'password_reminder_page_title', 'register_page_title')));
     // Shortcut variables for buttons and messages
     $view_button = '<a class="button button-secondary button-view-page" href="%1$s">%2$s</a>';
     $view_message = _x('View', 'view page', 'wpsc');
     $view_category_message = _x('Sample Category', 'view page', 'wpsc');
     $view_product_message = _x('Sample Product', 'view page', 'wpsc');
     // generate sample URLs for single product and product category
     $base_shop_url = '<small>' . esc_url(wpsc_get_store_url('/')) . '</small>';
     $sample_category = get_terms('wpsc_product_category', array('number' => 1));
     $sample_product = get_posts(array('post_type' => 'wpsc-product', 'numberposts' => 1));
     // generate form fields
     $this->form_array = array('store_slug' => array('type' => 'textfield', 'prepend' => '<small>' . esc_url(home_url('/')) . '</small>', 'title' => _x('Main store', 'page slug setting', 'wpsc'), 'append' => sprintf($view_button, wpsc_get_store_url(), $view_message), 'validation' => 'required', 'class' => 'regular-text'), 'store_as_front_page' => array('type' => 'radios', 'title' => _x('Display main store on front page', 'page settings', 'wpsc'), 'options' => array(1 => _x('Yes', 'settings', 'wpsc'), 0 => _x('No', 'settings', 'wpsc'))), 'store_title' => array('type' => 'textfield', 'title' => _x('Main store title', 'page slug title', 'wpsc'), 'validation' => 'required'), 'category_base_slug' => array('type' => 'textfield', 'prepend' => $base_shop_url, 'append' => empty($sample_category) ? '' : sprintf($view_button, get_term_link($sample_category[0]), $view_category_message), 'title' => _x('Product category base slug', 'permalinks setting', 'wpsc'), 'validation' => 'required', 'class' => 'regular-text'), 'product_base_slug' => array('type' => 'textfield', 'prepend' => $base_shop_url, 'append' => empty($sample_product) ? '' : sprintf($view_button, get_permalink($sample_product[0]), $view_product_message), 'title' => _x('Single product base slug', 'permalinks setting', 'wpsc'), 'validation' => 'required', 'class' => 'regular-text'), 'prefix_product_slug' => array('type' => 'checkboxes', 'title' => _x('Product prefix', 'permalinks setting', 'wpsc'), 'options' => array(1 => __('Include category slug in product URL.', 'wpsc'))), 'hierarchical_product_category_url' => array('type' => 'radios', 'title' => _x('Hierarchical product category URL', 'permalinks setting', 'wpsc'), 'options' => array(1 => _x('Yes', 'settings', 'wpsc'), 0 => _x('No', 'settings', 'wpsc')), 'description' => __('When hierarchical product category URL is enabled, parent product categories are also included in the product URL.', 'wpsc')), 'cart_page_slug' => array('type' => 'textfield', 'prepend' => $base_shop_url, 'append' => sprintf($view_button, wpsc_get_cart_url(), $view_message), 'title' => _x('Cart page', 'page settings', 'wpsc'), 'validation' => 'required', 'class' => 'regular-text'), 'cart_page_title' => array('type' => 'textfield', 'title' => _x('Cart page', 'page settings', 'wpsc'), 'validation' => 'required'), 'checkout_page_slug' => array('type' => 'textfield', 'prepend' => $base_shop_url, 'title' => _x('Checkout page', 'page setting', 'wpsc'), 'validation' => 'required', 'class' => 'regular-text'), 'checkout_page_title' => array('type' => 'textfield', 'title' => _x('Checkout page', 'page settings', 'wpsc'), 'validation' => 'required'), 'customer_account_page_slug' => array('type' => 'textfield', 'prepend' => $base_shop_url, 'append' => sprintf($view_button, wpsc_get_customer_account_url(), $view_message), 'title' => _x('Customer account page', 'permalinks setting', 'wpsc'), 'validation' => 'required|slug_not_conflicted', 'class' => 'regular-text'), 'customer_account_page_title' => array('type' => 'textfield', 'title' => _x('Customer account page', 'page settings', 'wpsc'), 'validation' => 'required'), 'login_page_slug' => array('type' => 'textfield', 'prepend' => $base_shop_url, 'title' => _x('Login page', 'permalinks setting', 'wpsc'), 'description' => __('Leaving this field blank will disable the page.', 'wpsc'), 'validation' => 'slug_not_conflicted', 'class' => 'regular-text'), 'login_page_title' => array('type' => 'textfield', 'title' => _x('Login page', 'page settings', 'wpsc'), 'validation' => 'required'), 'password_reminder_page_slug' => array('type' => 'textfield', 'prepend' => $base_shop_url, 'title' => _x('Password reminder page', 'permalinks setting', 'wpsc'), 'description' => __("Leaving this field blank will disable the page.", 'wpsc'), 'validation' => 'slug_not_conflicted', 'class' => 'regular-text'), 'password_reminder_page_title' => array('type' => 'textfield', 'title' => _x('Password reminder page', 'page settings', 'wpsc'), 'validation' => 'required'), 'register_page_slug' => array('type' => 'textfield', 'prepend' => $base_shop_url, 'title' => _x('Register page', 'permalinks setting', 'wpsc'), 'description' => __("Leaving this field blank will disable the page.", 'wpsc'), 'validation' => 'slug_not_conflicted', 'class' => 'regular-text'), 'register_page_title' => array('type' => 'textfield', 'title' => _x('Register page', 'page settings', 'wpsc'), 'validation' => 'required'));
     // display warnings for login, register and password reminder pages when
     // "Anyone can register" is disabled.
     if (!get_option('users_can_register')) {
         $additional_description = '<br /> ' . __('<strong>Note:</strong> Enable "Anyone can register" in <a href="%s">Settings -> General</a> first if you want to use this page.', 'wpsc');
         $additional_description = sprintf($additional_description, admin_url('options-general.php'));
         $this->form_array['login_page_slug']['description'] .= $additional_description;
         $this->form_array['password_reminder_page_slug']['description'] .= $additional_description;
         $this->form_array['register_page_slug']['description'] .= $additional_description;
     }
 }
 private function check_cart_items()
 {
     global $wpsc_cart;
     if (count($wpsc_cart->cart_items) > 0) {
         return;
     }
     wp_redirect(wpsc_get_cart_url());
     exit;
 }
Exemple #4
0
/**
 * Return the array containing arguments to generate the "Add to cart" form.
 *
 * The returned array can then be used with {@link wpsc_get_form_output()} to
 * generate the HTML output.
 *
 * @since  0.1
 * @uses   apply_filters() Applies 'wpsc_add_to_cart_button_icon' filter. Set the value to an empty value to disable the icon
 * @uses   apply_filters() Applies 'wpsc_add_to_cart_button_title' filter. The return value must be escaped already.
 * @uses   apply_filters() Applies 'wpsc_get_add_to_cart_form_args' filter. Use this filter to add more fields
 * @uses   wpsc_get_product_id() Get current product ID in the loop
 * @uses   wpsc_get_cart_url() Get cart URL for the form action
 * @uses   WPSC_Product::get_instance() get the WPSC_Product object to fetch variation sets and terms
 *
 * @param  int   $id Optional. Product ID. Defaults to the current product in the loop.
 * @return array     Form argument array
 */
function wpsc_get_add_to_cart_form_args($id = null)
{
    if (!$id) {
        $id = wpsc_get_product_id();
    }
    $args = array('class' => 'wpsc-form wpsc-form-horizontal wpsc-add-to-cart-form', 'action' => wpsc_get_cart_url("add/{$id}"), 'id' => "wpsc-add-to-cart-form-{$id}", 'fields' => array(array('name' => 'quantity', 'type' => 'textfield', 'title' => __('Quantity', 'wpsc'), 'value' => 1)));
    // generate the variation dropdown menus
    $product = WPSC_Product::get_instance($id);
    foreach ($product->variation_sets as $variation_set_id => $title) {
        $variation_terms = $product->variation_terms[$variation_set_id];
        $args['fields'][] = array('name' => "wpsc_product_variations[{$variation_set_id}]", 'type' => 'select', 'options' => $variation_terms, 'title' => $title);
    }
    // form action section contains the button and hidden values
    $args['form_actions'] = array(array('type' => 'button', 'primary' => true, 'icon' => apply_filters('wpsc_add_to_cart_button_icon', array('shopping-cart', 'white')), 'title' => apply_filters('wpsc_add_to_cart_button_title', __('Add to Cart', 'wpsc'))), array('type' => 'hidden', 'name' => '_wp_http_referer', 'value' => home_url($_SERVER['REQUEST_URI'])), array('type' => 'hidden', 'name' => '_wp_nonce', 'value' => wp_create_nonce("wpsc-add-to-cart-{$id}")));
    $args = apply_filters('wpsc_get_add_to_cart_form_args', $args);
    return $args;
}
    protected function cart_item_description($item, $key)
    {
        $remove_url = add_query_arg('_wp_nonce', wp_create_nonce("wpsc-remove-cart-item-{$key}"), wpsc_get_cart_url('remove/' . absint($key)));
        ?>
		<div class="wpsc-cart-item-row-actions">
			<a alt="<?php 
        esc_attr_e('Remove from cart', 'wp-e-commerce');
        ?>
" class="wpsc-button wpsc-button-mini" href="<?php 
        echo esc_url($remove_url);
        ?>
"><i class="wpsc-icon-trash"></i> <?php 
        esc_html_e('Remove', 'wp-e-commerce');
        ?>
</a>
		</div>
		<?php 
        parent::cart_item_description($item, $key);
    }
 /**
  * Handles declined transactions from Amazon.
  *
  * On the front-end, if a transaction is declined due to an invalid payment method, the user needs
  * to be returned to the payment page to select a different method.
  *
  * If it is declined for any other reason, they're basically out of luck.
  *
  * @since  4.0
  *
  * @param  WPSC_Purchase_Log $order Current purchase log for transaction.
  * @return void
  */
 private function handle_declined_transaction($order)
 {
     $reason_code = $order->get('amazon-reason-code');
     if ('InvalidPaymentMethod' == $reason_code) {
         $message = __('Selected payment method was not valid.  Please select a valid payment method.', 'wpsc');
         $url = add_query_arg($_GET, wpsc_get_checkout_url('shipping-and-billing'));
     } else {
         $message = __('It is not currently possible to complete this transaction with Amazon Payments. Please contact the store administrator or try again later.', 'wpsc');
         $url = wpsc_get_cart_url();
     }
     WPSC_Message_Collection::get_instance()->add($message, 'error', 'main', 'flash');
     wp_safe_redirect($url);
     exit;
 }
Exemple #7
0
 public function add($product_id)
 {
     global $wpsc_cart;
     if (!wp_verify_nonce($_REQUEST['_wp_nonce'], "wpsc-add-to-cart-{$product_id}")) {
         wp_die(__('Request expired. Please try adding the item to your cart again.', 'wpsc'));
     }
     extract($_REQUEST, EXTR_SKIP);
     $defaults = array('variation_values' => array(), 'quantity' => 1, 'provided_price' => null, 'comment' => null, 'time_requested' => null, 'custom_message' => null, 'file_data' => null, 'is_customisable' => false, 'meta' => null);
     $provided_parameters = array();
     $product_id = apply_filters('wpsc_add_to_cart_product_id', (int) $product_id);
     if (!empty($wpsc_product_variations)) {
         foreach ($wpsc_product_variations as $key => $variation) {
             $provided_parameters['variation_values'][(int) $key] = (int) $variation;
         }
         $variation_product_id = wpsc_get_child_object_in_terms($product_id, $provided_parameters['variation_values'], 'wpsc-variation');
         if ($variation_product_id > 0) {
             $product_id = $variation_product_id;
         }
     }
     if (!empty($quantity)) {
         $provided_parameters['quantity'] = (int) $quantity;
     }
     if (!empty($is_customisable)) {
         $provided_parameters['is_customisable'] = true;
         if (isset($custom_text)) {
             $provided_parameters['custom_message'] = $custom_text;
         }
         if (isset($_FILES['custom_file'])) {
             $provided_parameters['file_data'] = $_FILES['custom_file'];
         }
     }
     if (isset($donation_price) && (double) $donation_price > 0) {
         $provided_parameters['provided_price'] = (double) $donation_price;
     }
     $parameters = array_merge($defaults, $provided_parameters);
     if ($parameters['quantity'] <= 0) {
         $this->message_collection->add(__('Sorry, but the quantity you just entered is not valid. Please try again.', 'wpsc'), 'error', 'main', 'flash');
         return;
     }
     $product = apply_filters('wpsc_add_to_cart_product_object', get_post($product_id, OBJECT, 'display'));
     $stock = get_post_meta($product_id, '_wpsc_stock', true);
     $remaining_quantity = $wpsc_cart->get_remaining_quantity($product_id, $parameters['variation_values']);
     if ($stock !== '' && $remaining_quantity !== true) {
         if ($remaining_quantity <= 0) {
             $message = apply_filters('wpsc_add_to_cart_out_of_stock_message', __('Sorry, the product "%s" is out of stock.', 'wpsc'));
             $this->message_collection->add(sprintf($message, $product->post_title), 'error', 'main', 'flash');
             wp_safe_redirect(wp_get_referer());
             exit;
         } elseif ($remaining_quantity < $parameters['quantity']) {
             $message = __('Sorry, but the quantity you just specified is larger than the available stock. There are only %d of the item in stock.', 'wpsc');
             $this->message_collection->add(sprintf($message, $remaining_quantity), 'error', 'main', 'flash');
             wp_safe_redirect(wp_get_referer());
             exit;
         }
     }
     if (wpsc_product_has_variations($product_id) && is_null($parameters['variation_values'])) {
         $message = apply_filters('wpsc_add_to_cart_variation_missing_message', sprintf(__('This product has several options to choose from.<br /><br /><a href="%s" style="display:inline; float:none; margin: 0; padding: 0;">Visit the product page</a> to select options.', 'wpsc'), esc_url(get_permalink($product_id))), $product_id);
         $this->message_collection->add(sprintf($message, $product->post_title), 'error', 'main', 'flash');
         wp_safe_redirect(wp_get_referer());
         exit;
     }
     if ($wpsc_cart->set_item($product_id, $parameters)) {
         $message = sprintf(__('You just added %s to your cart.', 'wpsc'), $product->post_title);
         $this->message_collection->add($message, 'success', 'main', 'flash');
         wp_safe_redirect(wpsc_get_cart_url());
         exit;
     } else {
         $this->message_collection->add(__('An unknown error just occured. Please contact the shop administrator.', 'wpsc'), 'error', 'main', 'flash');
         wp_safe_redirect(wp_get_referer());
         exit;
     }
 }
Exemple #8
0
function wpsc_cart_url($slug = '')
{
    echo esc_url(wpsc_get_cart_url($slug));
}