Permalink
Browse files

Merge pull request #25 from loxK/master

Shortcode fixes and more.
  • Loading branch information...
2 parents 7e2c42a + 07463ff commit 42ef3196ee2f7a0e87c1537f212218936ece1d67 @mikejolley mikejolley committed Jul 18, 2011
@@ -254,7 +254,7 @@ function update_checkout() {
jQuery(form).block({ message: null, overlayCSS: { background: '#fff url(<?php echo jigoshop::plugin_url(); ?>/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
jQuery.ajax({
type: 'POST',
- url: jQuery(form).attr('action'),
+ url: '<?php echo admin_url('admin-ajax.php?action=jigoshop-checkout') ?>',
data: jQuery(form).serialize(),
success: function( code ) {
jQuery('.jigoshop_error, .jigoshop_message').remove();
@@ -11,6 +11,7 @@
class jigoshop {
private static $_instance;
+ private static $_cache;
public static $errors = array();
public static $messages = array();
@@ -217,4 +218,34 @@ function redirect( $location, $status ) {
return $location;
}
+ static public function shortcode_wrapper ($function, $atts=array()) {
+ if( $content = jigoshop::cache_get( $function . '-shortcode', $atts ) ) return $content;
+
+ ob_start();
+ call_user_func($function, $atts);
+ return jigoshop::cache( $function . '-shortcode', ob_get_clean(), $atts);
+ }
+
+ /**
+ * Cache API
+ */
+
+ public static function cache ( $id, $data, $args=array() ) {
+
+ if( ! isset(self::$_cache[ $id ]) ) self::$_cache[ $id ] = array();
+
+ if( empty($args) ) self::$_cache[ $id ][0] = $data;
+ else self::$_cache[ $id ][ serialize($args) ] = $data;
+
+ return $data;
+
+ }
+ public static function cache_get ( $id, $args=array() ) {
+
+ if( ! isset(self::$_cache[ $id ]) ) return null;
+
+ if( empty($args) && isset(self::$_cache[ $id ][0]) ) return self::$_cache[ $id ][0];
+ elseif ( isset(self::$_cache[ $id ][ serialize($args) ] ) ) return self::$_cache[ $id ][ serialize($args) ];
+
+ }
}
@@ -31,11 +31,7 @@ class jigoshop_cart {
/** constructor */
function __construct() {
- self::$applied_coupons = array();
-
- self::get_cart_from_session();
-
- if ( isset($_SESSION['coupons']) ) self::$applied_coupons = $_SESSION['coupons'];
+ add_action('init', array($this, 'init'), 1);
}
@@ -47,6 +43,14 @@ public static function get() {
}
return self::$_instance;
}
+
+ public function init () {
+ self::$applied_coupons = array();
+
+ self::get_cart_from_session();
+
+ if ( isset($_SESSION['coupons']) ) self::$applied_coupons = $_SESSION['coupons'];
+ }
/** Gets the cart data from the PHP session */
function get_cart_from_session() {
@@ -17,8 +17,10 @@ class jigoshop_checkout {
var $must_create_account;
var $creating_account;
+ protected static $instance;
+
/** constructor */
- function __construct () {
+ protected function __construct () {
add_action('jigoshop_checkout_billing',array(&$this,'checkout_form_billing'));
add_action('jigoshop_checkout_shipping',array(&$this,'checkout_form_shipping'));
@@ -54,6 +56,15 @@ function __construct () {
);
}
+ public static function instance () {
+ if(!self::$instance) {
+ $class = __CLASS__;
+ self::$instance = new $class;
+ }
+
+ return self::$instance;
+ }
+
/** Output the billing information form */
function checkout_form_billing() {
@@ -170,7 +170,7 @@ function email_order_items_list( $show_download_links = false, $show_sku = false
foreach($this->items as $item) :
$_product = &new jigoshop_product( $item['id'] );
- $return .= $item['qty'] . ' x ' . $item['name'];
+ $return .= $item['qty'] . ' x ' . apply_filters('jigoshop_order_product_title', $item['name'], $_product);
if ($show_sku) :
@@ -113,6 +113,11 @@ function is_type( $type ) {
return false;
}
+ /** Returns whether or not the product has any child product */
+ function has_child () {
+ return sizeof($this->children) ? true : false;
+ }
+
/** Returns whether or not the product post exists */
function exists() {
if ($this->exists) return true;
@@ -141,14 +146,14 @@ function get_post_data() {
}
/** Get the title of the post */
- function get_title() {
+ function get_title () {
$this->get_post_data();
- return $this->post->post_title;
+ return apply_filters('jigoshop_product_title', $this->post->post_title, $this);
}
/** Get the add to url */
function add_to_cart_url() {
- if ($this->is_type('grouped')) :
+ if ( $this->has_child() ) :
$url = add_query_arg('add-to-cart', 'group');
$url = add_query_arg('product', $this->id, $url);
else :
@@ -359,7 +364,7 @@ function get_price_excluding_tax() {
/** Returns the price in html format */
function get_price_html() {
$price = '';
- if ($this->is_type('grouped')) :
+ if ( $this->has_child() ) :
$min_price = '';
$max_price = '';
View
@@ -169,6 +169,20 @@ function jigoshop_process_login() {
endif;
}
+/**
+ * Process ajax checkout form
+ */
+add_action('wp_ajax_jigoshop-checkout', 'jigoshop_process_checkout');
+add_action('wp_ajax_nopriv_jigoshop-checkout', 'jigoshop_process_checkout');
+
+function jigoshop_process_checkout () {
+ include_once jigoshop::plugin_path() . '/classes/jigoshop_checkout.class.php';
+
+ jigoshop_checkout::instance()->process_checkout();
+
+ die(0);
+}
+
/**
* Cancel a pending order - hook into init function
@@ -41,17 +41,17 @@ function jigoshop_recent_products( $atts ) {
### Multiple Products #########################################################
function jigoshop_products($atts){
- global $columns;
+ global $columns;
- if (empty($atts)) return;
+ if (empty($atts)) return;
extract(shortcode_atts(array(
'columns' => '4',
- 'orderby' => 'title',
- 'order' => 'asc'
- ), $atts));
+ 'orderby' => 'title',
+ 'order' => 'asc'
+ ), $atts));
- $args = array(
+ $args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
@@ -67,64 +67,64 @@ function jigoshop_products($atts){
);
if(isset($atts['skus'])){
- $skus = explode(',', $atts['skus']);
- array_walk($skus, create_function('&$val', '$val = trim($val);'));
- $args['meta_query'][] = array(
- 'key' => 'sku',
- 'value' => $skus,
- 'compare' => 'IN'
- );
- }
+ $skus = explode(',', $atts['skus']);
+ array_walk($skus, create_function('&$val', '$val = trim($val);'));
+ $args['meta_query'][] = array(
+ 'key' => 'sku',
+ 'value' => $skus,
+ 'compare' => 'IN'
+ );
+ }
if(isset($atts['ids'])){
- $ids = explode(',', $atts['ids']);
- array_walk($ids, create_function('&$val', '$val = trim($val);'));
- $args['post__in'] = $ids;
+ $ids = explode(',', $atts['ids']);
+ array_walk($ids, create_function('&$val', '$val = trim($val);'));
+ $args['post__in'] = $ids;
}
- query_posts($args);
- ob_start();
+ query_posts($args);
+
+ ob_start();
jigoshop_get_template_part( 'loop', 'shop' );
wp_reset_query();
-
return ob_get_clean();
}
### Single Product ############################################################
function jigoshop_product($atts){
- if (empty($atts)) return;
+ if (empty($atts)) return;
- $args = array(
- 'post_type' => 'product',
- 'posts_per_page' => 1,
- 'post_status' => 'publish',
- 'meta_query' => array(
+ $args = array(
+ 'post_type' => 'product',
+ 'posts_per_page' => 1,
+ 'post_status' => 'publish',
+ 'meta_query' => array(
array(
'key' => 'visibility',
'value' => array('catalog', 'visible'),
'compare' => 'IN'
)
)
- );
+ );
- if(isset($atts['sku'])){
- $args['meta_query'][] = array(
- 'key' => 'sku',
- 'value' => $atts['sku'],
- 'compare' => '='
- );
- }
+ if(isset($atts['sku'])){
+ $args['meta_query'][] = array(
+ 'key' => 'sku',
+ 'value' => $atts['sku'],
+ 'compare' => '='
+ );
+ }
- if(isset($atts['id'])){
- $args['p'] = $atts['id'];
- }
+ if(isset($atts['id'])){
+ $args['p'] = $atts['id'];
+ }
- query_posts($args);
- ob_start();
+ query_posts($args);
+
+ ob_start();
jigoshop_get_template_part( 'loop', 'shop' );
wp_reset_query();
-
return ob_get_clean();
}
@@ -172,14 +172,16 @@ function jigoshop_featured_products( $atts ) {
add_shortcode('product', 'jigoshop_product');
add_shortcode('products', 'jigoshop_products');
+
add_shortcode('recent_products', 'jigoshop_recent_products');
add_shortcode('featured_products', 'jigoshop_featured_products');
-add_shortcode('jigoshop_cart', 'jigoshop_cart');
-add_shortcode('jigoshop_checkout', 'jigoshop_checkout');
-add_shortcode('jigoshop_order_tracking', 'jigoshop_order_tracking');
-add_shortcode('jigoshop_my_account', 'jigoshop_my_account');
-add_shortcode('jigoshop_edit_address', 'jigoshop_edit_address');
-add_shortcode('jigoshop_change_password', 'jigoshop_change_password');
-add_shortcode('jigoshop_view_order', 'jigoshop_view_order');
-add_shortcode('jigoshop_pay', 'jigoshop_pay');
-add_shortcode('jigoshop_thankyou', 'jigoshop_thankyou');
+
+add_shortcode('jigoshop_cart', 'get_jigoshop_cart');
+add_shortcode('jigoshop_checkout', 'get_jigoshop_checkout');
+add_shortcode('jigoshop_order_tracking', 'get_jigoshop_order_tracking');
+add_shortcode('jigoshop_my_account', 'get_jigoshop_my_account');
+add_shortcode('jigoshop_edit_address', 'get_jigoshop_edit_address');
+add_shortcode('jigoshop_change_password', 'get_jigoshop_change_password');
+add_shortcode('jigoshop_view_order', 'get_jigoshop_view_order');
+add_shortcode('jigoshop_pay', 'get_jigoshop_pay');
+add_shortcode('jigoshop_thankyou', 'get_jigoshop_thankyou');
@@ -3,7 +3,7 @@
* Custom Post Types
**/
function jigoshop_post_type() {
-
+do_action('lox');
global $wpdb;
$shop_page_id = get_option('jigoshop_shop_page_id');
@@ -56,7 +56,7 @@ function jigoshop_template_loader( $template ) {
function jigoshop_get_template_part( $slug, $name = '' ) {
if ($name=='shop') :
if (!locate_template(array( 'loop-shop.php', JIGOSHOP_TEMPLATE_URL . 'loop-shop.php' ))) :
- load_template( jigoshop::plugin_path() . '/templates/loop-shop.php' );
+ load_template( jigoshop::plugin_path() . '/templates/loop-shop.php',false );
return;
endif;
endif;
@@ -84,10 +84,10 @@ function jigoshop_comments_template($template) {
// Get other templates (e.g. product attributes)
################################################################################
-function jigoshop_get_template($template_name) {
- if (file_exists( STYLESHEETPATH . '/' . JIGOSHOP_TEMPLATE_URL . $template_name )) load_template( STYLESHEETPATH . '/' . JIGOSHOP_TEMPLATE_URL . $template_name );
- elseif (file_exists( STYLESHEETPATH . '/' . $template_name )) load_template( STYLESHEETPATH . '/' . $template_name );
- else load_template( jigoshop::plugin_path() . '/templates/' . $template_name );
+function jigoshop_get_template($template_name, $require_once = true) {
+ if (file_exists( STYLESHEETPATH . '/' . JIGOSHOP_TEMPLATE_URL . $template_name )) load_template( STYLESHEETPATH . '/' . JIGOSHOP_TEMPLATE_URL . $template_name, $require_once );
+ elseif (file_exists( STYLESHEETPATH . '/' . $template_name )) load_template( STYLESHEETPATH . '/' . $template_name , $require_once);
+ else load_template( jigoshop::plugin_path() . '/templates/' . $template_name , $require_once);
}
################################################################################
View
@@ -1,4 +1,9 @@
<?php
+
+function get_jigoshop_cart( $atts ) {
+ return jigoshop::shortcode_wrapper('jigoshop_cart', $atts);
+}
+
function jigoshop_cart( $atts ) {
$errors = array();
@@ -108,7 +113,7 @@ function jigoshop_cart( $atts ) {
else echo '<img src="'.jigoshop::plugin_url(). '/assets/images/placeholder.png" alt="Placeholder" width="'.jigoshop::get_var('shop_tiny_w').'" height="'.jigoshop::get_var('shop_tiny_h').'" />';
echo ' </a></td>
- <td class="product-name"><a href="'.get_permalink($item_id).'">'.$_product->get_title().'</a></td>
+ <td class="product-name"><a href="'.get_permalink($item_id).'">' . apply_filters('jigoshop_cart_product_title', $_product->get_title(), $_product) . '</a></td>
<td class="product-price">'.jigoshop_price($_product->get_price()).'</td>
<td class="product-quantity"><div class="quantity"><input name="cart['.$item_id.'][qty]" value="'.$values['quantity'].'" size="4" title="Qty" class="input-text qty text" maxlength="12" /></div></td>
<td class="product-subtotal">'.jigoshop_price($_product->get_price()*$values['quantity']).'</td>
Oops, something went wrong.

0 comments on commit 42ef319

Please sign in to comment.