From b8970410287beb06c5c1f4f695349fdcd7a3c24c Mon Sep 17 00:00:00 2001 From: Reinhold Kainhofer <reinhold@kainhofer.com> Date: Thu, 6 Apr 2017 00:46:22 +0200 Subject: [PATCH] More work on transition to shipping zones; help box is shown in methods; Work on issue #8 --- assets/css/admin-styles.css | 65 ++++++++++++++++--- assets/js/shipping-by-rules-config.js | 10 +++ includes/admin/html/html-upgrade-nag.php | 14 ++-- includes/admin/settings/meta-box-help.php | 29 ++++++++- includes/rules-shipping-method.php | 59 ++++++++++------- .../rules_shipping_framework_woocommerce.php | 4 +- ...hipping_framework_woocommerce_advanced.php | 4 ++ woocommerce-advanced-shipping-by-rules.php | 3 +- woocommerce-shipping-by-rules.php | 13 +++- 9 files changed, 153 insertions(+), 48 deletions(-) create mode 100644 assets/js/shipping-by-rules-config.js diff --git a/assets/css/admin-styles.css b/assets/css/admin-styles.css index 233e6f4..39c091c 100644 --- a/assets/css/admin-styles.css +++ b/assets/css/admin-styles.css @@ -1,29 +1,36 @@ /*******************************/ /* CSS for the Upgrade NAG Box */ /*******************************/ -div#opentools-shippingbyrules-upgrade { +div#opentools-shippingbyrules-upgrade, +div#opentools-shippingbyrules-help { padding: 5px 10px; + width: 100%; } -div#opentools-shippingbyrules-upgrade.postbox { - display: inline-block; +div#opentools-shippingbyrules-upgrade.postbox, +div#opentools-shippingbyrules-help.postbox { +/* display: inline-block; */ } -#opentools-shippingbyrules-upgrade h3 { +#opentools-shippingbyrules-upgrade h3, +#opentools-shippingbyrules-help h3 { margin: 0; border-bottom: #800000 solid 1px; margin-top: 3px; padding-bottom: 3px; } -div#opentools-shippingbyrules-upgrade ul { +div#opentools-shippingbyrules-upgrade ul, +div#opentools-shippingbyrules-help ul { list-style: disc; /* list-style-position: inside; */ margin-left: 5px; padding-left: 5px; margin-top: 5px; } -div#opentools-shippingbyrules-upgrade li { +div#opentools-shippingbyrules-upgrade li, +div#opentools-shippingbyrules-help li { margin-left: 2em; } -div#opentools-shippingbyrules-upgrade .column1, div#opentools-shippingbyrules-upgrade .column2 { +div#opentools-shippingbyrules-upgrade .column1, div#opentools-shippingbyrules-upgrade .column2, +div#opentools-shippingbyrules-help .column1, div#opentools-shippingbyrules-help .column2 { float: left; } @@ -39,6 +46,8 @@ div#opentools-shippingbyrules-upgrade .contents { + + /*******************************/ /* CSS for the rules help Box */ /*******************************/ @@ -59,6 +68,46 @@ ul.otsr_list blockquote { } +#opentools-shippingbyrules-help .opentools_shippingbyrules_title { + cursor: pointer; +} +#opentools-shippingbyrules-help .opentools_shippingbyrules_title h3 { + padding-right: 30px; +} + +#opentools-shippingbyrules-help .openclose { + cursor: pointer; + float: right; + width: 20px; + height: 20px; +} +#opentools-shippingbyrules-help.closed .content { + display: none; +} + +#opentools-shippingbyrules-help.closed .openclose:before { + content: '\f140'; +} +#opentools-shippingbyrules-help .openclose:before { + content: '\f142'; +} +#opentools-shippingbyrules-help .openclose:before { +/* right: 12px; */ + font: 400 20px/1 dashicons; + speak: none; + display: inline-block; + padding: 1px; + top: 0; + position: relative; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + text-decoration: none!important; + width: 100%; + height: 100%; +} + + + /************************************/ /* CSS for the Shipping methods box */ /************************************/ @@ -69,4 +118,4 @@ table.rules_shipping_methods.wc-shipping-zones td, table.rules_shipping_methods. line-height: 1.15em; padding-top: 5px; padding-bottom: 5px; -} \ No newline at end of file +} diff --git a/assets/js/shipping-by-rules-config.js b/assets/js/shipping-by-rules-config.js new file mode 100644 index 0000000..6c2cc34 --- /dev/null +++ b/assets/js/shipping-by-rules-config.js @@ -0,0 +1,10 @@ +/** + * Ordernumber Admin JS + */ +jQuery( function ( $ ) { + // Open/Close the help boxes + $( '#opentools-shippingbyrules-help' ).on( 'click', '.opentools_shippingbyrules_title', function (event) { + $( this ).closest( '#opentools-shippingbyrules-help' ).toggleClass('closed'); + }); + +}); diff --git a/includes/admin/html/html-upgrade-nag.php b/includes/admin/html/html-upgrade-nag.php index c917f31..3896fdf 100644 --- a/includes/admin/html/html-upgrade-nag.php +++ b/includes/admin/html/html-upgrade-nag.php @@ -5,20 +5,16 @@ if ( ! defined( 'ABSPATH' ) ) { } ?> - <div id="opentools-shippingbyrules-upgrade" class="rules_shipping rules_shipping_upgrade rules_shipping_meta_box rules_shipping_settings_meta_box postbox"> + <div id="opentools-shippingbyrules-upgrade" class="postbox"> <?php if (isset($settings['title'])) { ?><h3><?php echo esc_html($settings['title']); ?></h3><?php } ?> <div class="contents"> <div class="logoleft"><a href="<?php echo esc_html($settings['link']); ?>"><img src="<?php echo plugins_url('../../../assets/images/advlogo100.png', __FILE__); ?>"></a></div> <!--p>Advanced features not included in the free plugin include:</p--> <ul> - <li><b>Mathematical expressions</b> for shipping costs (depending on weight, dimensions, amount, etc.): - <ul style="font-size: smaller"> - <li>Shipping costs per kg</li> - <li>Percentage shipping cost on the amount, etc.</li> - </ul> - <li><b>Conditions for product subsets</b>: Conditions / costs depending on particular products, categories, tags or shipping classes - <li><b>Alphanumeric Postcodes</b>: Conditions on UK and Canadian postcodes</li> - <li><b>Coupon Codes</b>: conditions on coupon codes</li> + <li><b>Mathematical expressions</b> (depending on weight, dimensions, amount, etc.): <span style="font-size: smaller">shipping costs per kg, percentage shipping cost on the amount, etc.</span></li> + <li>Conditions on <b>certain products, categories, tags or shipping classes</b></li> + <li><b>Calculations for product subsets</b>: values (weight, quantity, amount, ...) only for particular products, categories, tags or shipping classes</li> + <li>Support <b>UK and Canadian postcodes</b>, <b>coupon codes</b>, and many more features...</li> </ul> <p>More information and purchase: <a class="button-primary" href="<?php echo esc_html($settings['link']); ?>" target="_blank">Get Support and advanced features</a></p> </div> diff --git a/includes/admin/settings/meta-box-help.php b/includes/admin/settings/meta-box-help.php index 80e53fa..cb9e922 100644 --- a/includes/admin/settings/meta-box-help.php +++ b/includes/admin/settings/meta-box-help.php @@ -10,8 +10,14 @@ */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly - -?><div class='rules_shipping rules_shipping_help rules_shipping_meta_box rules_shipping_help_meta_box'> +?><div id="opentools-shippingbyrules-help" class='closed postbox'> + <?php if (isset($settings['title'])) { ?> + <div class="opentools_shippingbyrules_title"> + <div class="openclose" title="Click to toggle"><br></div> + <h3><?php echo esc_html($settings['title']); ?> <span style="font-size: smaller; font-weight: normal;">(click to open/close this section)</span></h3> + </div><?php + } ?> + <div class="content opentools_shippingbyrules_contents"> <p>See also the the <a href='http://open-tools.net/documentation/advanced-shipping-by-rules-for-woocommerce.html'>Plugin's documentation</a> and <a href='http://open-tools.net/documentation/shipping-by-rules-plugins-for-virtuemart/rules-examples.html'>Rules Examples</a>.</p> <ul class='otsr_list'> <li>One rule per line, rule parts separated by Semicolon (;)</li> @@ -46,6 +52,23 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly <p>EXAMPLE: A rule named 'Europe' that sets shipping costs of 5€ for orders weighing less than 5kg, 10€ for heavier orders, and free shipping from 100€ on would be:</p> <blockquote><tt>Name=Free Shipping; 100<= Amount; 0<br/>Name=Europe; Weight<5; Shipping=5<br/>Name=Europe; Weight>=5; Shipping=10</tt></blockquote> + <?php if (!isset($settings['isAdvanced']) || !$settings['isAdvanced']) { ?> + <div id='opentools-shippingbyrules-upgrade'> + <h3><?php echo esc_html(__( 'Upgrade to the ADVANCED VERSION of the OpenTools Shipping by Rules plugin', 'opentools-shippingrules')); ?></h3> + <div class="contents"> + <div class="logoleft"><a href="<?php echo esc_html($settings['link']); ?>"><img src="<?php echo plugins_url('../../../assets/images/advlogo100.png', __FILE__); ?>"></a></div> + <!--p>Advanced features not included in the free plugin include:</p--> + <ul> + <li><b>Mathematical expressions</b> (depending on weight, dimensions, amount, etc.): <span style="font-size: smaller">shipping costs per kg, percentage shipping cost on the amount, etc.</span></li> + <li>Conditions on <b>certain products, categories, tags or shipping classes</b></li> + <li><b>Calculations for product subsets</b>: values (weight, quantity, amount, ...) only for particular products, categories, tags or shipping classes</li> + <li>Support <b>UK and Canadian postcodes</b>, <b>coupon codes</b>, and many more features...</li> + </ul> + <p>More information and purchase: <a class="button-primary" href="<?php echo esc_html($settings['link']); ?>" target="_blank">Get Support and advanced features</a></p> + </div> + </div> + <?php } ?> + </div> </div> -<?php \ No newline at end of file +<?php diff --git a/includes/rules-shipping-method.php b/includes/rules-shipping-method.php index e9a1f48..f038ab4 100644 --- a/includes/rules-shipping-method.php +++ b/includes/rules-shipping-method.php @@ -65,6 +65,7 @@ class Shipping_by_Rules extends WC_Shipping_Method { // Save settings in admin if you have any defined add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) ); + add_filter( 'woocommerce_admin_field_opentools_shippingbyrules_help', array( &$this, 'admin_field_opentools_shippingbyrules_help') ); } function define_global_form_fields() { @@ -88,13 +89,16 @@ class Shipping_by_Rules extends WC_Shipping_Method { 'methods' => array( 'type' => 'rules_shipping_methods', ), + + ) ); } function define_instance_form_fields() { + return array_merge( - $this->helper->getUpgradeNagSettings(), +// $this->helper->getUpgradeNagSettings(), array( 'title' => array( @@ -115,13 +119,20 @@ class Shipping_by_Rules extends WC_Shipping_Method { ) ), 'rules' => array( - 'title' => __('Rules:', 'opentools-shippingrules'), + 'title' => $this->helper->__('Rules:'), 'type' => 'textarea', 'css' => '', 'class' => 'shipping_rules_rule_textarea', - 'placeholder' => __('Rules of the form: Name="Rule name"; Amount>100; [...Conditions...]; Shipping=3', 'opentools-shippingrules'), + 'placeholder' => $this->helper->__('Rules of the form: Name="Rule name"; Amount>100; [...Conditions...]; Shipping=3'), + ), + 'ruleshelp' => array( + 'name' => $this->helper->__('Help on rules syntax'), + 'type' => 'opentools_shippingbyrules_help', + 'link' => 'http://open-tools.net/woocommerce/advanced-shipping-by-rules-for-woocommerce.html', + 'isAdvanced' => $this->helper->isAdvanced(), ), ) +// $this->helper->getUpgradeNagSettings() ); } @@ -150,27 +161,9 @@ class Shipping_by_Rules extends WC_Shipping_Method { return false; } - - public function getUpgradeNagSettings() { - $settings = array(); - if (!$this->isAdvanced()) { - add_filter( 'woocommerce_admin_field_opentools_shippingbyrules_upgrade', array( &$this, 'admin_field_opentools_shippingbyrules_upgrade') ); - $settings['opentools_shippingbyrules_upgrade'] = array( - 'name' => $this->__( 'Upgrade to the ADVANCED VERSION of the OpenTools Shipping by Rules plugin'), - 'type' => 'opentools_shippingbyrules_upgrade', - 'link' => 'http://open-tools.net/woocommerce/advanced-shipping-by-rules-for-woocommerce.html', - ); - } - return $settings; - } - - public function printUpgradeNagBox($settings) { - include plugin_dir_path( __FILE__ ) . 'admin/html/html-upgrade-nag.php'; - } - /** - * generate_rules_shipping_methods_html function. + * generate_opentools_shippingbyrules_upgrade_html function. * * @access public * @return string @@ -191,6 +184,28 @@ class Shipping_by_Rules extends WC_Shipping_Method { } + /** + * generate_opentools_shippingbyrules_help_html function. + * + * @access public + * @return string + */ + public function generate_opentools_shippingbyrules_help_html($id, $settings) { + if (isset($settings['name'])) { + $settings['title'] = $settings['name']; + } + ob_start(); + ?> + <tr valign="top"> + <td colspan="2"> + <?php include plugin_dir_path( __FILE__ ) . 'admin/settings/meta-box-help.php'; ?> + </td> + </tr> + <?php + return ob_get_clean(); + } + + /** * calculate_shipping function. * diff --git a/includes/rules_shipping_framework_woocommerce.php b/includes/rules_shipping_framework_woocommerce.php index ea13b4a..4499c3e 100644 --- a/includes/rules_shipping_framework_woocommerce.php +++ b/includes/rules_shipping_framework_woocommerce.php @@ -458,13 +458,13 @@ class RulesShippingFrameworkWooCommerce extends RulesShippingFramework { public function getUpgradeNagSettings() { $settings = array(); - if (!$this->isAdvanced()) { +// if (!$this->isAdvanced()) { $settings['opentools_shippingbyrules_upgrade'] = array( 'name' => $this->__( 'Upgrade to the ADVANCED VERSION of the OpenTools Shipping by Rules plugin'), 'type' => 'opentools_shippingbyrules_upgrade', 'link' => 'http://open-tools.net/woocommerce/advanced-shipping-by-rules-for-woocommerce.html', ); - } +// } return $settings; } diff --git a/includes/rules_shipping_framework_woocommerce_advanced.php b/includes/rules_shipping_framework_woocommerce_advanced.php index 0174224..5e3b237 100644 --- a/includes/rules_shipping_framework_woocommerce_advanced.php +++ b/includes/rules_shipping_framework_woocommerce_advanced.php @@ -47,6 +47,10 @@ class RulesShippingFrameworkWooCommerceAdvanced extends RulesShippingFrameworkWo $values['coupons'] = $cart['applied_coupons']; return $values; } + + public function getUpgradeNagSettings() { + return array(); + } } diff --git a/woocommerce-advanced-shipping-by-rules.php b/woocommerce-advanced-shipping-by-rules.php index 2874e6d..ecca61a 100644 --- a/woocommerce-advanced-shipping-by-rules.php +++ b/woocommerce-advanced-shipping-by-rules.php @@ -275,9 +275,8 @@ class WooCommerce_Shipping_By_Rules_Advanced { $assets_path = str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/'; wp_enqueue_style( 'select2', $assets_path . 'css/select2.css' ); - wp_enqueue_style( 'legacy_shipping_by_rules-style', plugins_url( 'assets/css/legacy-admin-styles.css', __FILE__ ), array('select2'), $this->version ); wp_enqueue_style( 'shipping_by_rules-style', plugins_url( 'assets/css/admin-styles.css', __FILE__ ), array('select2'), $this->version ); - wp_enqueue_script( 'legacy-shipping-by-rules-config', plugins_url( 'assets/js/legacy-shipping-by-rules-config.js', __FILE__ ), array( 'jquery', 'jquery-ui-sortable', 'select2', 'wc-enhanced-select' ), $this->version, true ); + wp_enqueue_script( 'shipping-by-rules-config', plugins_url( 'assets/js/shipping-by-rules-config.js', __FILE__ ), array( 'jquery', 'jquery-ui-sortable', 'select2', 'wc-enhanced-select' ), $this->version, true ); } diff --git a/woocommerce-shipping-by-rules.php b/woocommerce-shipping-by-rules.php index 0b79cf6..ebce79c 100644 --- a/woocommerce-shipping-by-rules.php +++ b/woocommerce-shipping-by-rules.php @@ -74,6 +74,7 @@ class WooCommerce_Shipping_By_Rules { // Check if WooCommerce is active if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) : if ( ! is_plugin_active_for_network( 'woocommerce/woocommerce.php' ) ) : + add_action( 'admin_notices', array('WooCommerce_Shipping_By_Rules', 'otsr_woocommerce_inactive_admin_notice') ); return; endif; endif; @@ -82,6 +83,15 @@ class WooCommerce_Shipping_By_Rules { } + public static function otsr_woocommerce_inactive_admin_notice() { + ?> + <div class="error"> + <p><?php _e( 'Open Tools <b>Advanced Shipping by Rules</b> for WooCommerce is enabled, but <b>WooCommerce</b> is not installed or enabled.', 'opentools-shippingrules' ); ?></p> + </div> + <?php + } + + /** * Instance. * @@ -273,9 +283,8 @@ class WooCommerce_Shipping_By_Rules { $assets_path = str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/'; wp_enqueue_style( 'select2', $assets_path . 'css/select2.css' ); - wp_enqueue_style( 'legacy_shipping_by_rules-style', plugins_url( 'assets/css/legacy-admin-styles.css', __FILE__ ), array('select2'), $this->version ); wp_enqueue_style( 'shipping_by_rules-style', plugins_url( 'assets/css/admin-styles.css', __FILE__ ), array('select2'), $this->version ); - wp_enqueue_script( 'legacy-shipping-by-rules-config', plugins_url( 'assets/js/legacy-shipping-by-rules-config.js', __FILE__ ), array( 'jquery', 'jquery-ui-sortable', 'select2', 'wc-enhanced-select' ), $this->version, true ); + wp_enqueue_script( 'shipping-by-rules-config', plugins_url( 'assets/js/shipping-by-rules-config.js', __FILE__ ), array( 'jquery', 'jquery-ui-sortable', 'select2', 'wc-enhanced-select' ), $this->version, true ); } -- GitLab