示例#1
0
 /**
  * Widget
  * Display the widget in the sidebar
  * Save output to the cache if empty
  *
  * @param  array  sidebar arguments
  * @param  array  instance
  */
 public function widget($args, $instance)
 {
     // Hide widget if page is the cart or checkout
     if (is_cart() || is_checkout()) {
         return false;
     }
     extract($args);
     // Set the widget title
     $title = apply_filters('widget_title', $instance['title'] ? $instance['title'] : __('Cart', 'fflcommerce'), $instance, $this->id_base);
     // Print the widget wrapper & title
     echo $before_widget;
     if ($title) {
         echo $before_title . $title . $after_title;
     }
     // Get the contents of the cart
     $cart_contents = fflcommerce_cart::$cart_contents;
     // If there are items in the cart print out a list of products
     if (!empty($cart_contents)) {
         // Open the list
         echo '<ul class="cart_list">';
         foreach ($cart_contents as $key => $value) {
             // Get product instance
             $_product = $value['data'];
             if ($_product->exists() && $value['quantity'] > 0) {
                 echo '<li>';
                 // Print the product image & title with a link to the permalink
                 echo '<a href="' . esc_attr(get_permalink($_product->id)) . '" title="' . esc_attr($_product->get_title()) . '">';
                 // Print the product thumbnail image if exists else display placeholder
                 echo has_post_thumbnail($_product->id) ? get_the_post_thumbnail($_product->id, 'shop_tiny') : fflcommerce_get_image_placeholder('shop_tiny');
                 // Print the product title
                 echo '<span class="js_widget_product_title">' . $_product->get_title() . '</span>';
                 echo '</a>';
                 // Displays variations and cart item meta
                 echo fflcommerce_cart::get_item_data($value);
                 // Print the quantity & price per product
                 echo '<span class="js_widget_product_price">' . $value['quantity'] . ' &times; ' . $_product->get_price_html() . '</span>';
                 echo '</li>';
             }
         }
         echo '</ul>';
         // Close the list
         // Print the cart total
         echo '<p class="total"><strong>';
         echo __('Subtotal', 'fflcommerce');
         echo ':</strong> ' . fflcommerce_price($this->total_cart_items());
         echo '</p>';
         do_action('fflcommerce_widget_cart_before_buttons');
         // Print view cart & checkout buttons
         $view_cart_button_label = isset($instance['view_cart_button']) ? $instance['view_cart_button'] : __('View Cart &rarr;', 'fflcommerce');
         $checkout_button_label = isset($instance['checkout_button']) ? $instance['checkout_button'] : __('Checkout &rarr;', 'fflcommerce');
         echo '<p class="buttons">';
         echo '<a href="' . esc_attr(fflcommerce_cart::get_cart_url()) . '" class="button">' . __($view_cart_button_label, 'fflcommerce') . '</a>';
         echo '<a href="' . esc_attr(fflcommerce_cart::get_checkout_url()) . '" class="button checkout">' . __($checkout_button_label, 'fflcommerce') . '</a>';
         echo '</p>';
     } else {
         echo '<span class="empty">' . __('No products in the cart.', 'fflcommerce') . '</span>';
     }
     // Print closing widget wrapper
     echo $after_widget;
 }
 function fflcommerce_add_to_cart_action($url = false)
 {
     if (empty($_REQUEST['add-to-cart']) || !fflcommerce::verify_nonce('add_to_cart')) {
         return false;
     }
     $options = FFLCommerce_Base::get_options();
     $product_added = false;
     switch ($_REQUEST['add-to-cart']) {
         case 'variation':
             // ensure we have a valid quantity, product and variation id, that is numeric, without any SQL injection attempts.
             $product_id = isset($_REQUEST['product_id']) && is_numeric($_REQUEST['product_id']) ? (int) $_REQUEST['product_id'] : -1;
             if ($product_id < 0) {
                 break;
                 // drop out and put up message, unable to add product.
             }
             if (empty($_REQUEST['variation_id']) || !is_numeric($_REQUEST['variation_id'])) {
                 break;
                 // drop out and put up message, unable to add product.
             }
             $quantity = isset($_REQUEST['quantity']) && is_numeric($_REQUEST['quantity']) ? (int) $_REQUEST['quantity'] : 1;
             $product_id = apply_filters('fflcommerce_product_id_add_to_cart_filter', $product_id);
             $variation_id = apply_filters('fflcommerce_variation_id_add_to_cart_filter', (int) $_REQUEST['variation_id']);
             $attributes = (array) maybe_unserialize(get_post_meta($product_id, 'product_attributes', true));
             $variations = array();
             $all_variations_set = true;
             if (get_post_meta($product_id, 'customizable', true) == 'yes') {
                 // session personalization initially set to parent product until variation selected
                 $custom_products = (array) fflcommerce_session::instance()->customized_products;
                 // transfer it to the variation
                 $custom_products[$variation_id] = $custom_products[$product_id];
                 unset($custom_products[$product_id]);
                 fflcommerce_session::instance()->customized_products = $custom_products;
             }
             foreach ($attributes as $attribute) {
                 if (!$attribute['variation']) {
                     continue;
                 }
                 $attr_name = 'tax_' . sanitize_title($attribute['name']);
                 if (!empty($_REQUEST[$attr_name])) {
                     $variations[$attr_name] = esc_attr($_REQUEST[$attr_name]);
                 } else {
                     $all_variations_set = false;
                 }
             }
             // Add to cart validation
             $is_valid = apply_filters('fflcommerce_add_to_cart_validation', true, $product_id, $quantity);
             if ($all_variations_set && $is_valid) {
                 if (fflcommerce_cart::add_to_cart($product_id, $quantity, $variation_id, $variations)) {
                     $product_added = true;
                 }
             }
             break;
         case 'group':
             if (empty($_REQUEST['quantity']) || !is_array($_REQUEST['quantity'])) {
                 break;
             }
             // do nothing
             foreach ($_REQUEST['quantity'] as $product_id => $quantity) {
                 // Skip if no quantity
                 if (!$quantity) {
                     continue;
                 }
                 $quantity = (int) $quantity;
                 // Add to cart validation
                 $is_valid = apply_filters('fflcommerce_add_to_cart_validation', true, $product_id, $quantity);
                 // Add to the cart if passsed validation
                 if ($is_valid) {
                     if (fflcommerce_cart::add_to_cart($product_id, $quantity)) {
                         $product_added = true;
                     }
                 }
             }
             break;
         default:
             if (!is_numeric($_REQUEST['add-to-cart'])) {
                 // Handle silently for now
                 break;
             }
             // Get product ID & quantity
             $product_id = apply_filters('fflcommerce_product_id_add_to_cart_filter', (int) $_REQUEST['add-to-cart']);
             $quantity = isset($_REQUEST['quantity']) ? (int) $_REQUEST['quantity'] : 1;
             // Add to cart validation
             $is_valid = apply_filters('fflcommerce_add_to_cart_validation', true, $product_id, $quantity);
             // Add to the cart if passed validation
             if ($is_valid) {
                 if (fflcommerce_cart::add_to_cart($product_id, $quantity)) {
                     $product_added = true;
                 }
             }
             break;
     }
     if (!$product_added) {
         fflcommerce::add_error(__('The Product could not be added to the cart.  Please try again.', 'fflcommerce'));
         wp_safe_redirect(remove_query_arg(array('add-to-cart', 'quantity', 'product_id', '_n'), wp_get_referer()), 301);
         exit;
     } else {
         switch ($options->get('fflcommerce_redirect_add_to_cart', 'same_page')) {
             case 'same_page':
                 $message = __('Product successfully added to your cart.', 'fflcommerce');
                 $button = __('View Cart &rarr;', 'fflcommerce');
                 $message = '<a href="%s" class="button">' . $button . '</a> ' . $message;
                 fflcommerce::add_message(sprintf($message, fflcommerce_cart::get_cart_url()));
                 break;
             case 'to_checkout':
                 // Do nothing
                 break;
             default:
                 fflcommerce::add_message(__('Product successfully added to your cart.', 'fflcommerce'));
                 break;
         }
         $url = apply_filters('add_to_cart_redirect', $url);
         if ($url) {
             wp_safe_redirect($url, 301);
             exit;
         } else {
             if ($options->get('fflcommerce_redirect_add_to_cart', 'same_page') == 'to_checkout' && !fflcommerce::has_errors()) {
                 wp_safe_redirect(fflcommerce_cart::get_checkout_url(), 301);
                 exit;
             } else {
                 if ($options->get('fflcommerce_redirect_add_to_cart', 'to_cart') == 'to_cart' && !fflcommerce::has_errors()) {
                     wp_safe_redirect(fflcommerce_cart::get_cart_url(), 301);
                     exit;
                 } else {
                     if (wp_get_referer()) {
                         wp_safe_redirect(remove_query_arg(array('add-to-cart', 'quantity', 'product_id'), wp_get_referer()), 301);
                         exit;
                     } else {
                         wp_safe_redirect(home_url(), 301);
                         exit;
                     }
                 }
             }
         }
     }
 }
示例#3
0
    }
    ?>
		<?php 
    if ($options->get('fflcommerce_cart_shows_shop_button') == 'yes') {
        ?>
			<tr>
				<td colspan="6" class="actions">
					<a href="<?php 
        echo esc_url(fflcommerce_cart::get_shop_url());
        ?>
" class="checkout-button button-alt" style="float:left;"><?php 
        _e('&larr; Return to Shop', 'fflcommerce');
        ?>
</a>
					<a href="<?php 
        echo esc_url(fflcommerce_cart::get_checkout_url());
        ?>
" class="checkout-button button-alt"><?php 
        _e('Proceed to Checkout &rarr;', 'fflcommerce');
        ?>
</a>
				</td>
			</tr>
		<?php 
    }
    do_action('fflcommerce_shop_table_cart_foot');
    ?>
		</tfoot>
		<?php 
    do_action('fflcommerce_shop_table_cart');
    ?>
示例#4
0
 * versions in the future. If you wish to customise FFL Commerce core for your needs,
 * please use our GitHub repository to publish essential changes for consideration.
 *
 * @package             FFLCommerce
 * @category            Checkout
 * @author              Tampa Bay Tactical Supply, Inc.
 * @copyright           Copyright © 2011-2014 Tampa Bay Tactical Supply, Inc. & Jigoshop.
 * @license             GNU General Public License v3
 * 
 */
?>

<?php 
do_action('before_checkout_form');
// filter hook for include new pages inside the payment method
$get_checkout_url = apply_filters('fflcommerce_get_checkout_url', fflcommerce_cart::get_checkout_url());
?>

<form name="checkout" method="post" class="checkout" action="<?php 
echo esc_url($get_checkout_url);
?>
">

	<h3 id="order_review_heading"><?php 
_e('Your Order', 'fflcommerce');
?>
</h3>

	<?php 
do_action('fflcommerce_checkout_order_review');
?>