Plugin Directory

Changeset 1197796


Ignore:
Timestamp:
07/13/2015 09:43:35 AM (10 years ago)
Author:
crunnells
Message:

Updating to 1.3.4 after fixing two bugs

Location:
shopp-minimum-order-amount
Files:
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • shopp-minimum-order-amount/tags/1.3.4/readme.txt

    r1160833 r1197796  
    55Requires at least: 3.0
    66Tested up to: 4.0.1
    7 Stable tag: 1.3.3
     7Stable tag: 1.3.4
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4747== Changelog ==
    4848
     49= 1.3.4 =
     50* Squashed a couple of sneaky (but dumb) bugs. One was hiding the quantity select box on product pages, and the other was just silly.
     51
    4952= 1.3.3 =
    5053* Squashed a bug preventing minimums from being saved in 1.3.x (at the expense of 1.2.x compatibility). Thanks Thomas Bisshop
  • shopp-minimum-order-amount/tags/1.3.4/shopp-minimum-order.php

    r1160833 r1197796  
    55Description: Set a minimum order amount (total items or order total) for Shopp checkout.
    66Author: Chris Runnells
    7 Version: 1.3.3
     7Version: 1.3.4
    88Author URI: http://www.chrisrunnells.com
    99
     
    3737
    3838// admin stuff
    39 add_action('admin_menu', 'smo_menu', 90);
    40 add_action('admin_menu', 'smo_meta', 20);
    41 add_filter('plugin_action_links', 'smo_plugin_action_links', 10, 2);
    42 
    43 
    44 function smo_menu() {
    45     // Shopp 1.2 menu position
    46     // add_submenu_page('shopp-settings',__('Minimum Order'),__('Minimum Order'),'manage_options','shopp-minimum-order','smo_actions');
    47 
     39add_action( 'admin_menu', 'smo_menu', 90 );
     40add_action( 'admin_menu', 'smo_meta', 20 );
     41add_filter( 'plugin_action_links', 'smo_plugin_action_links', 10, 2 );
     42
     43
     44function smo_menu () {
    4845    // Shopp 1.3
    49     // shopp_admin_add_submenu ( string $label, string $page, string $menu = null, $handler = false, string $access = null )
    50     // shopp_admin_add_submenu( 'Minimum Order', 'shopp-setup-minimum', 'shopp-setup', 'smo_actions', 'shopp_settings' );
    51 
    5246    add_submenu_page( 'shopp-orders', 'Minimum Order', 'Minimum Order', 'manage_options', 'shopp-minimum-order', 'smo_actions' );
    5347}
    5448
    55 function smo_meta() {
     49function smo_meta () {
    5650    add_meta_box( 'smo_metabox', 'Set Minimum', 'smo_sidebar', 'shopp_product', 'side', 'default' );
    5751}
    5852
    59 function smo_plugin_action_links($links, $file) {
     53function smo_plugin_action_links ( $links, $file ) {
    6054    static $this_plugin;
    6155
    62     if (!$this_plugin) {
    63         $this_plugin = plugin_basename(__FILE__);
     56    if ( ! $this_plugin )
     57        $this_plugin = plugin_basename( __FILE__ );
     58
     59    if ( $file == $this_plugin ) {
     60        // The "page" query string value must be equal to the slug of the Settings admin page
     61        $settings_link = '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=shopp-minimum-order">Settings</a>';
     62        array_unshift( $links, $settings_link );
    6463    }
    6564
    66     if ($file == $this_plugin) {
    67         // The "page" query string value must be equal to the slug
    68         // of the Settings admin page we defined earlier, which in
    69         // this case equals "myplugin-settings".
    70         $settings_link = '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=shopp-minimum-order">Settings</a>';
    71         array_unshift($links, $settings_link);
    72     }
    73 
    7465    return $links;
    7566}
    7667
    77 function smo_actions() {
    78     if($_POST['action'] == 'update'){
     68function smo_actions () {
     69    if ( $_POST['action'] == 'update' ) {
    7970        smo_save();
    8071    } else {
     
    8374}
    8475
    85 function smo_form( $response = false ) {
    86 
    87     $type = get_option('smo_type');
    88     $minimum = get_option('smo_minimum');
    89 
    90     $selected[0] = "";
    91     $selected[1] = "";
    92     $selected[2] = "";
    93 
    94     if(isset($type)){
     76function smo_form ( $response = false ) {
     77
     78    $type = get_option( 'smo_type' );
     79    $minimum = get_option( 'smo_minimum' );
     80
     81    $selected = array( '', '', '' );
     82
     83    if ( isset( $type ) ) {
    9584        if($type == "quantity") $selected[0] = ' checked="checked"';
    9685        if($type == "total") $selected[1] = ' checked="checked"';
     
    10089    }
    10190
    102     if($response){
     91    if ( $response )
    10392        $response = '<div id="message" class="updated fade"><p>'.$response.'</p></div>';
    104     }
    105 
    106     if ('SHOPP_VERSION' < '1.2'){
    107         $response .= '<div id="message" class="updated fade"><p>'. sprintf(__('This plugin has only been tested in Shopp version 1.3 and greater. Your current version is %d and we recommend upgrading.'), SHOPP_VERSION) .'</p></div>';
    108     }
     93
     94    if ( defined('SHOPP_VERSION') && version_compare(SHOPP_VERSION, "1.3", "<") ) // 1.2
     95        $response .= '<div id="message" class="updated fade"><p>'. sprintf(__('This plugin has only been tested in Shopp version 1.3 and greater. Your current version is %d and we recommend upgrading to the latest version of Shopp.'), SHOPP_VERSION) .'</p></div>';
     96
    10997?>
    11098<style type="text/css">
     
    153141
    154142
    155 function smo_save(){
     143function smo_save () {
    156144    // sanitize user input
    157145    $type = sanitize_text_field($_POST['smo_type']);
     
    165153
    166154/* Meta box sidebar on the product page */
    167 function smo_sidebar(){
     155function smo_sidebar () {
    168156    global $post;
    169157
     
    180168
    181169/* Save data from product page meta box */
    182 function smo_save_postdata( $Product ) {
     170function smo_save_postdata ( $Product ) {
    183171    $minimum = (float) $_POST['smo_min'];
    184172    if ( ! $minimum ) return;
     
    186174}
    187175
    188 function smo_filter_quantity( $result, $options, $Product ){
     176function smo_filter_quantity ( $result, $options, $Product ) {
    189177    // check if this product has a minimum
    190178    $minimum = smo_get_minimum($Product->id);
    191     shopp_debug("Check catalog product: " . print_r($minimum, true));
     179    shopp_debug("Check catalog product: " . print_r($minimum, true));
    192180
    193181    // if it does, try to set the minimum in the dropdown OR text area input (soon)
    194 
     182    return $result;
    195183}
    196184
     
    198186    // check if this item has minimums
    199187    $minimum = smo_get_minimum($Item->product);
    200     shopp_debug("Check added item minimum: " . print_r($minimum, true));
    201 
    202     // if it does, set the quantity to minimum if it's less
    203     if ($Item->quantity < $minimum) $Item->quantity = $minimum;
    204 
    205     // drop a cart error to let the customer know what happened
    206     // new ShoppError(__('The minimum quantity for this product is:','Shopp'),false,SHOPP_ERR);
     188    if ( empty( $minimum ) ) return;
     189
     190    shopp_debug( "Check added item minimum: " . print_r($minimum, true) );
     191    // set the quantity to the minimum if it's less
     192    if ( $Item->quantity < $minimum ) {
     193        $Item->quantity = $minimum;
     194        // drop a cart error to let the customer know what happened
     195        shopp_add_notice('The minimum quantity for ' . $Item->name . ' is ' . $minimum . '. Your cart has been updated.');
     196    }
    207197}
    208198
     
    220210
    221211            // drop a cart error to let the customer know what happened
    222             new ShoppError(__('The minimum quantity for ' . $Item->name . ' is ' . $minimum . '. Your cart has been updated.', 'Shopp'), false, SHOPP_ERR);
     212            // new ShoppError(__('The minimum quantity for ' . $Item->name . ' is ' . $minimum . '. Your cart has been updated.', 'Shopp'), false, SHOPP_ERR);
     213            shopp_add_notice('The minimum quantity for ' . $Item->name . ' is ' . $minimum . '. Your cart has been updated.');
    223214        }
    224215
     
    227218}
    228219
    229 function smo_check_minimums ($valid) {
     220function smo_check_minimums ( $valid ) {
    230221    global $Shopp;
    231222
     
    234225
    235226    // if type is "total", check against the order subtotal
    236     if ( isset($type) && !empty($type) && shopp_cart_items_count() > 0){
    237         if ( $type == "total" ){
     227    if ( isset($type) && !empty($type) && shopp_cart_items_count() > 0 ) {
     228        if ( $type == "total" ) {
    238229            $Cart = ShoppOrder()->Cart;
    239230            $subtotal = $Cart->total('order');
     
    241232
    242233            if ( $subtotal < $minimum ){
    243                 if (SHOPP_DEBUG) new ShoppError('Total minimum: '. $minimum . ' sub-total: '. $subtotal, false, SHOPP_DEBUG_ERR);
     234                shopp_debug('Total minimum: '. $minimum . ' sub-total: '. $subtotal );
    244235
    245236                new ShoppError('The minimum order amount is ' . money($minimum) . '. Please add more items to complete your order.','cart_validation');
     
    247238                return false;
    248239            }
    249         } else if ($type == "quantity"){
     240        } else if ( $type == "quantity" ) {
    250241
    251242            $total_items = shopp('cart', 'get-total-quantity');
    252243
    253             if($total_items < $minimum){
    254                 if (SHOPP_DEBUG) new ShoppError('Quantity minimum: '. $minimum . ' total items: '. $total_items, false, SHOPP_DEBUG_ERR);
     244            if ( $total_items < $minimum ) {
     245                shopp_debug('Quantity minimum: '. $minimum . ' total items: '. $total_items);
    255246                new ShoppError('You must have at least '. $minimum .' items in your cart to check out. You currently have '. $total_items .' items.', 'cart_validation');
    256247                return false;
     
    264255}
    265256
    266 // Checks during checkout if minimum ahas been met
    267 function smo_cart_minimums (){
    268     global $Shopp;
     257// Checks during checkout if minimum has been met
     258function smo_cart_minimums () {
    269259
    270260    $minimum = get_option('smo_minimum');
    271261
    272     if (SHOPP_DEBUG) new ShoppError('minimum: '. $minimum . ' total: '. shopp('cart','get-total'),false,SHOPP_DEBUG_ERR);
    273 
    274     if ( floatval( shopp('cart','get-total') ) < $minimum ){
    275 
    276         if (SHOPP_DEBUG) new ShoppError("Minimum is " . money($minimum) . ", total is " . shopp('cart','get-total'),false,SHOPP_DEBUG_ERR);
    277 
    278         new ShoppError(__("Cart total does not exceed minimum order amount.","Shopp"));
     262    shopp_debug('minimum: '. $minimum . ' total: ' . shopp('cart.get-total'));
     263
     264    if ( floatval( shopp('cart.get-total') ) < $minimum ){
     265
     266        shopp_debug("Minimum is " . money($minimum) . ", total is " . shopp('cart.get-total'));
     267
     268        // new ShoppError(__("Cart total does not exceed minimum order amount.","Shopp"));
     269        shopp_add_error("Cart total does not exceed minimum order amount.");
    279270    }
    280271}
  • shopp-minimum-order-amount/trunk/readme.txt

    r1160833 r1197796  
    55Requires at least: 3.0
    66Tested up to: 4.0.1
    7 Stable tag: 1.3.3
     7Stable tag: 1.3.4
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4747== Changelog ==
    4848
     49= 1.3.4 =
     50* Squashed a couple of sneaky (but dumb) bugs. One was hiding the quantity select box on product pages, and the other was just silly.
     51
    4952= 1.3.3 =
    5053* Squashed a bug preventing minimums from being saved in 1.3.x (at the expense of 1.2.x compatibility). Thanks Thomas Bisshop
  • shopp-minimum-order-amount/trunk/shopp-minimum-order.php

    r1160833 r1197796  
    55Description: Set a minimum order amount (total items or order total) for Shopp checkout.
    66Author: Chris Runnells
    7 Version: 1.3.3
     7Version: 1.3.4
    88Author URI: http://www.chrisrunnells.com
    99
     
    3737
    3838// admin stuff
    39 add_action('admin_menu', 'smo_menu', 90);
    40 add_action('admin_menu', 'smo_meta', 20);
    41 add_filter('plugin_action_links', 'smo_plugin_action_links', 10, 2);
    42 
    43 
    44 function smo_menu() {
    45     // Shopp 1.2 menu position
    46     // add_submenu_page('shopp-settings',__('Minimum Order'),__('Minimum Order'),'manage_options','shopp-minimum-order','smo_actions');
    47 
     39add_action( 'admin_menu', 'smo_menu', 90 );
     40add_action( 'admin_menu', 'smo_meta', 20 );
     41add_filter( 'plugin_action_links', 'smo_plugin_action_links', 10, 2 );
     42
     43
     44function smo_menu () {
    4845    // Shopp 1.3
    49     // shopp_admin_add_submenu ( string $label, string $page, string $menu = null, $handler = false, string $access = null )
    50     // shopp_admin_add_submenu( 'Minimum Order', 'shopp-setup-minimum', 'shopp-setup', 'smo_actions', 'shopp_settings' );
    51 
    5246    add_submenu_page( 'shopp-orders', 'Minimum Order', 'Minimum Order', 'manage_options', 'shopp-minimum-order', 'smo_actions' );
    5347}
    5448
    55 function smo_meta() {
     49function smo_meta () {
    5650    add_meta_box( 'smo_metabox', 'Set Minimum', 'smo_sidebar', 'shopp_product', 'side', 'default' );
    5751}
    5852
    59 function smo_plugin_action_links($links, $file) {
     53function smo_plugin_action_links ( $links, $file ) {
    6054    static $this_plugin;
    6155
    62     if (!$this_plugin) {
    63         $this_plugin = plugin_basename(__FILE__);
     56    if ( ! $this_plugin )
     57        $this_plugin = plugin_basename( __FILE__ );
     58
     59    if ( $file == $this_plugin ) {
     60        // The "page" query string value must be equal to the slug of the Settings admin page
     61        $settings_link = '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=shopp-minimum-order">Settings</a>';
     62        array_unshift( $links, $settings_link );
    6463    }
    6564
    66     if ($file == $this_plugin) {
    67         // The "page" query string value must be equal to the slug
    68         // of the Settings admin page we defined earlier, which in
    69         // this case equals "myplugin-settings".
    70         $settings_link = '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=shopp-minimum-order">Settings</a>';
    71         array_unshift($links, $settings_link);
    72     }
    73 
    7465    return $links;
    7566}
    7667
    77 function smo_actions() {
    78     if($_POST['action'] == 'update'){
     68function smo_actions () {
     69    if ( $_POST['action'] == 'update' ) {
    7970        smo_save();
    8071    } else {
     
    8374}
    8475
    85 function smo_form( $response = false ) {
    86 
    87     $type = get_option('smo_type');
    88     $minimum = get_option('smo_minimum');
    89 
    90     $selected[0] = "";
    91     $selected[1] = "";
    92     $selected[2] = "";
    93 
    94     if(isset($type)){
     76function smo_form ( $response = false ) {
     77
     78    $type = get_option( 'smo_type' );
     79    $minimum = get_option( 'smo_minimum' );
     80
     81    $selected = array( '', '', '' );
     82
     83    if ( isset( $type ) ) {
    9584        if($type == "quantity") $selected[0] = ' checked="checked"';
    9685        if($type == "total") $selected[1] = ' checked="checked"';
     
    10089    }
    10190
    102     if($response){
     91    if ( $response )
    10392        $response = '<div id="message" class="updated fade"><p>'.$response.'</p></div>';
    104     }
    105 
    106     if ('SHOPP_VERSION' < '1.2'){
    107         $response .= '<div id="message" class="updated fade"><p>'. sprintf(__('This plugin has only been tested in Shopp version 1.3 and greater. Your current version is %d and we recommend upgrading.'), SHOPP_VERSION) .'</p></div>';
    108     }
     93
     94    if ( defined('SHOPP_VERSION') && version_compare(SHOPP_VERSION, "1.3", "<") ) // 1.2
     95        $response .= '<div id="message" class="updated fade"><p>'. sprintf(__('This plugin has only been tested in Shopp version 1.3 and greater. Your current version is %d and we recommend upgrading to the latest version of Shopp.'), SHOPP_VERSION) .'</p></div>';
     96
    10997?>
    11098<style type="text/css">
     
    153141
    154142
    155 function smo_save(){
     143function smo_save () {
    156144    // sanitize user input
    157145    $type = sanitize_text_field($_POST['smo_type']);
     
    165153
    166154/* Meta box sidebar on the product page */
    167 function smo_sidebar(){
     155function smo_sidebar () {
    168156    global $post;
    169157
     
    180168
    181169/* Save data from product page meta box */
    182 function smo_save_postdata( $Product ) {
     170function smo_save_postdata ( $Product ) {
    183171    $minimum = (float) $_POST['smo_min'];
    184172    if ( ! $minimum ) return;
     
    186174}
    187175
    188 function smo_filter_quantity( $result, $options, $Product ){
     176function smo_filter_quantity ( $result, $options, $Product ) {
    189177    // check if this product has a minimum
    190178    $minimum = smo_get_minimum($Product->id);
    191     shopp_debug("Check catalog product: " . print_r($minimum, true));
     179    shopp_debug("Check catalog product: " . print_r($minimum, true));
    192180
    193181    // if it does, try to set the minimum in the dropdown OR text area input (soon)
    194 
     182    return $result;
    195183}
    196184
     
    198186    // check if this item has minimums
    199187    $minimum = smo_get_minimum($Item->product);
    200     shopp_debug("Check added item minimum: " . print_r($minimum, true));
    201 
    202     // if it does, set the quantity to minimum if it's less
    203     if ($Item->quantity < $minimum) $Item->quantity = $minimum;
    204 
    205     // drop a cart error to let the customer know what happened
    206     // new ShoppError(__('The minimum quantity for this product is:','Shopp'),false,SHOPP_ERR);
     188    if ( empty( $minimum ) ) return;
     189
     190    shopp_debug( "Check added item minimum: " . print_r($minimum, true) );
     191    // set the quantity to the minimum if it's less
     192    if ( $Item->quantity < $minimum ) {
     193        $Item->quantity = $minimum;
     194        // drop a cart error to let the customer know what happened
     195        shopp_add_notice('The minimum quantity for ' . $Item->name . ' is ' . $minimum . '. Your cart has been updated.');
     196    }
    207197}
    208198
     
    220210
    221211            // drop a cart error to let the customer know what happened
    222             new ShoppError(__('The minimum quantity for ' . $Item->name . ' is ' . $minimum . '. Your cart has been updated.', 'Shopp'), false, SHOPP_ERR);
     212            // new ShoppError(__('The minimum quantity for ' . $Item->name . ' is ' . $minimum . '. Your cart has been updated.', 'Shopp'), false, SHOPP_ERR);
     213            shopp_add_notice('The minimum quantity for ' . $Item->name . ' is ' . $minimum . '. Your cart has been updated.');
    223214        }
    224215
     
    227218}
    228219
    229 function smo_check_minimums ($valid) {
     220function smo_check_minimums ( $valid ) {
    230221    global $Shopp;
    231222
     
    234225
    235226    // if type is "total", check against the order subtotal
    236     if ( isset($type) && !empty($type) && shopp_cart_items_count() > 0){
    237         if ( $type == "total" ){
     227    if ( isset($type) && !empty($type) && shopp_cart_items_count() > 0 ) {
     228        if ( $type == "total" ) {
    238229            $Cart = ShoppOrder()->Cart;
    239230            $subtotal = $Cart->total('order');
     
    241232
    242233            if ( $subtotal < $minimum ){
    243                 if (SHOPP_DEBUG) new ShoppError('Total minimum: '. $minimum . ' sub-total: '. $subtotal, false, SHOPP_DEBUG_ERR);
     234                shopp_debug('Total minimum: '. $minimum . ' sub-total: '. $subtotal );
    244235
    245236                new ShoppError('The minimum order amount is ' . money($minimum) . '. Please add more items to complete your order.','cart_validation');
     
    247238                return false;
    248239            }
    249         } else if ($type == "quantity"){
     240        } else if ( $type == "quantity" ) {
    250241
    251242            $total_items = shopp('cart', 'get-total-quantity');
    252243
    253             if($total_items < $minimum){
    254                 if (SHOPP_DEBUG) new ShoppError('Quantity minimum: '. $minimum . ' total items: '. $total_items, false, SHOPP_DEBUG_ERR);
     244            if ( $total_items < $minimum ) {
     245                shopp_debug('Quantity minimum: '. $minimum . ' total items: '. $total_items);
    255246                new ShoppError('You must have at least '. $minimum .' items in your cart to check out. You currently have '. $total_items .' items.', 'cart_validation');
    256247                return false;
     
    264255}
    265256
    266 // Checks during checkout if minimum ahas been met
    267 function smo_cart_minimums (){
    268     global $Shopp;
     257// Checks during checkout if minimum has been met
     258function smo_cart_minimums () {
    269259
    270260    $minimum = get_option('smo_minimum');
    271261
    272     if (SHOPP_DEBUG) new ShoppError('minimum: '. $minimum . ' total: '. shopp('cart','get-total'),false,SHOPP_DEBUG_ERR);
    273 
    274     if ( floatval( shopp('cart','get-total') ) < $minimum ){
    275 
    276         if (SHOPP_DEBUG) new ShoppError("Minimum is " . money($minimum) . ", total is " . shopp('cart','get-total'),false,SHOPP_DEBUG_ERR);
    277 
    278         new ShoppError(__("Cart total does not exceed minimum order amount.","Shopp"));
     262    shopp_debug('minimum: '. $minimum . ' total: ' . shopp('cart.get-total'));
     263
     264    if ( floatval( shopp('cart.get-total') ) < $minimum ){
     265
     266        shopp_debug("Minimum is " . money($minimum) . ", total is " . shopp('cart.get-total'));
     267
     268        // new ShoppError(__("Cart total does not exceed minimum order amount.","Shopp"));
     269        shopp_add_error("Cart total does not exceed minimum order amount.");
    279270    }
    280271}
Note: See TracChangeset for help on using the changeset viewer.