Plugin Directory

Changeset 2282505


Ignore:
Timestamp:
04/13/2020 03:47:58 PM (6 years ago)
Author:
invisibledragonltd
Message:

Update to version 1.0 from GitLab (https://gitlab.com/invisibledragon/id-delivery; https://gitlab.com/invisibledragon/id-delivery/-/jobs/508794186)

Location:
deliveryplus-by-invisible-dragon
Files:
28 added
14 edited
1 copied

Legend:

Unmodified
Added
Removed
  • deliveryplus-by-invisible-dragon/tags/1.0/admin.js

    r2251671 r2282505  
    88        $(".id-filtering").each(function () {
    99
     10            // When category is picked, load next option down
    1011            $(this).on("change", ".id-filter-category", function () {
    1112                var nextDrop = $(".id-filter-condition", $(this).closest("tr"));
     
    1415                    nextDrop.html('');
    1516                    for(let key in data) {
    16                         $("<option>").attr("value", key).text(data[key]).appendTo(nextDrop);
     17                        var nVal = data[key];
     18
     19                        $("<option>").attr("value", key).text(nVal['label']).attr("data-type", nVal['type']).appendTo(nextDrop);
    1720                    }
    1821                    if(nextDrop.attr("data-value")) {
     22                        // If we need to pre-set, pre-set
    1923                        nextDrop.val(nextDrop.attr("data-value"));
    2024                        nextDrop.removeAttr("data-value");
    2125                    }
     26                    // Load default values
    2227                    nextDrop.trigger('change');
    2328                });
    2429            });
    2530
     31            // When condition type is changed, update dropdown
    2632            $(this).on("change", ".id-filter-condition", function () {
     33                // Get the type of the condition value
     34                var category = $(".id-filter-category", $(this).closest("tr")).val();
     35                var nextType = $("option:selected", $(this)).attr("data-type");
     36
    2737                var nextDrop = $(".id-filter-value", $(this).closest("tr"));
    28                 nextDrop.html('<option>...</option>');
    29                 var category =  $(".id-filter-category", $(this).closest("tr")).val();
    30                 $.getJSON(window.ajaxurl + "?action=deliveryplus_get_values&category=" + category +"&condition=" + $(this).val(), function (data) {
    31                     nextDrop.html('');
    32                     for(let key in data) {
    33                         $("<option>").attr("value", key).text(data[key]).appendTo(nextDrop);
     38                var n = $("<div>").addClass("id-filter-value").text("...");
     39                nextDrop.replaceWith(n);
     40                nextDrop = n;
     41
     42                if(nextType == 'pick'){
     43
     44                    $.getJSON(window.ajaxurl + "?action=deliveryplus_get_values&category=" + category +"&condition=" + $(this).val(), function (data) {
     45                        var n = $("<select>").addClass("id-filter-value");
     46                        nextDrop.replaceWith(n);
     47                        nextDrop = n;
     48                        for(let key in data) {
     49                            $("<option>").attr("value", key).text(data[key]).appendTo(nextDrop);
     50                        }
     51                        if(nextDrop.parent().attr("data-value")) {
     52                            nextDrop.val(nextDrop.parent().attr("data-value"));
     53                            nextDrop.parent().removeAttr("data-value");
     54                        }
     55                        nextDrop.trigger('change');
     56                    });
     57
     58                } else if(nextType == 'value'){
     59
     60                    let n = $("<input>").addClass("id-filter-value input-text").attr("type", "text");
     61                    nextDrop.replaceWith(n);
     62                    nextDrop = n;
     63                    if(nextDrop.parent().attr("data-value")) {
     64                        nextDrop.val(nextDrop.parent().attr("data-value"));
     65                        nextDrop.parent().removeAttr("data-value");
    3466                    }
    35                     if(nextDrop.attr("data-value")) {
    36                         nextDrop.val(nextDrop.attr("data-value"));
    37                         nextDrop.removeAttr("data-value");
    38                     }
    39                     nextDrop.trigger('change');
    40                 });
     67
     68                }else {
     69                    nextDrop.text("! " + nextType);
     70                }
    4171            });
    4272
     73            // Delete Row
     74            $(this).on("click", ".id-remove-row", function(e){
     75                e.preventDefault();
     76                $(this).closest("tr").remove();
     77            });
     78
     79            // Delete Block
     80            $(this).on("click", ".id-remove-block", function(e){
     81                e.preventDefault();
     82                $(this).closest(".id-filter-set").remove();
     83            });
     84
     85            // New Row
    4386            $(this).on("click", ".id-add-new-and", function() {
    4487                newAndCondition($(this).closest("table"));
    4588            });
    4689
     90            // New Block
    4791            $(this).on("click", ".id-add-new-or", function(){
    4892                newOrCondition();
     
    56100                    $(".id-filter-category", n).val(row['category']);
    57101                    $(".id-filter-condition", n).attr("data-value", row['condition']);
    58                     $(".id-filter-value", n).attr("data-value", row['value']);
     102                    $(".id-filter-value", n).parent().attr("data-value", row['value']);
    59103                }
    60104
     
    75119            }
    76120
    77             let items = JSON.parse($("input", $(".id-filtering").closest('fieldset')).val() || '[]');
     121            // Parse input from saved
     122            let items = JSON.parse($("input[type='hidden']", $(".id-filtering").closest('fieldset')).val() || '[]');
    78123
    79124            if(items.length > 0) {
     
    99144                });
    100145
    101                 $("input", $(".id-filtering").closest('fieldset')).val(JSON.stringify(ret));
     146                $("input[type='hidden']", $(".id-filtering").closest('fieldset')).val(JSON.stringify(ret));
    102147
    103148            }
    104149
    105             $(this).on("change", "select", function(){
     150            $(this).on("change", "select, input[type='text']", function(){
    106151                renderJSON();
    107152            });
  • deliveryplus-by-invisible-dragon/tags/1.0/class.DeliveryPlus_Filter_Category.php

    r2251671 r2282505  
    11<?php
    22
    3 class DeliveryPlus_Filter_Category {
     3class DeliveryPlus_Filter_Category extends DeliveryPlus_Filter_Set {
     4
     5    public static $category = 'Category';
     6
     7    public static function category_label(){ return __('Category'); }
    48
    59    public static function activate() {
     10        parent::activate();
    611        add_filter( 'deliveryplus_filter_Category_1', array( static::class, 'at_least_one' ), 10, 3 );
    712        add_filter( 'deliveryplus_filter_Category_!', array( static::class, 'none' ), 10, 3 );
    813        add_filter( 'deliveryplus_filter_Category_!a', array( static::class, 'not_all' ), 10, 3 );
    914        add_filter( 'deliveryplus_filter_Category_a', array( static::class, 'all' ), 10, 3 );
     15    }
     16
     17    public static function get_conditions($conditions) {
     18        $ret['1'] = new DPF_Pick_Value(__('at least one in'));
     19        $ret['a'] = new DPF_Pick_Value(__('all must be in'));
     20        $ret['!'] = new DPF_Pick_Value(__('none must be in'));
     21        $ret['!a'] = new DPF_Pick_Value(__('not all in'));
     22        return $ret;
     23    }
     24
     25    public static function get_values($ret, $condition) {
     26        $raw = get_categories(array('taxonomy' => 'product_cat', 'hide_empty' => false));
     27        foreach($raw as $cat) {
     28            $ret[$cat->term_id] = wp_specialchars_decode( $cat->name );
     29        }
     30        return $ret;
    1031    }
    1132
  • deliveryplus-by-invisible-dragon/tags/1.0/class.DeliveryPlus_Filters.php

    r2251671 r2282505  
    11<?php
    22
    3 require_once "class.DeliveryPlus_Filter_Category.php";
     3/**
     4 * This is a standard DeliveryPlus condition, specifying the value for this
     5 * condition should be entered into a textbox
     6 */
     7class DPF_Value {
     8
     9    public $type = 'value';
     10
     11    public function __construct($label) {
     12        $this->label = $label;
     13    }
     14
     15    public function toJSON() {
     16        return array(
     17            'type' => $this->type,
     18            'label' => $this->label
     19        );
     20    }
     21
     22}
     23
     24/**
     25 * This is a variation of a DeliveryPlus conditon, whereby the value
     26 * needs to be picked from a dropdown list.
     27 */
     28class DPF_Pick_Value extends DPF_Value {
     29
     30    public $type = 'pick';
     31
     32}
     33
     34abstract class DeliveryPlus_Filter_Set {
     35
     36    public static $category = 'Unknown';
     37    public static function category_label(){ return __('Unknown'); }
     38
     39    public static function activate() {
     40
     41        add_filter( 'deliveryplus_categories', array( static::class, 'add_category' ) );
     42        add_filter( 'deliveryplus_values_' . static::$category, array( static::class, 'get_values' ), 10, 2 );
     43        add_filter( 'deliveryplus_conditions_' . static::$category, array( static::class, 'get_conditions' ) );
     44
     45        // Now associate a filter function for each condition
     46        $conditions = static::get_conditions(array());
     47        foreach($conditions as $key => $val) {
     48            add_filter( 'deliveryplus_filter_' . static::$category . '_' . $key, array( static::class, 'do_' . $key ), 10, 3 );
     49        }
     50
     51    }
     52
     53    abstract public static function get_conditions($conditions);
     54
     55    public static function get_values($ret, $condition){
     56        // TODO by sub-function
     57        return $ret;
     58    }
     59
     60    public static function add_category($filters) {
     61        $filters[static::$category] = static::category_label();
     62        return $filters;
     63    }
     64}
     65
    466
    567class DeliveryPlus_Filters {
     
    971        add_action( 'wp_ajax_deliveryplus_get_values', array( static::class, 'get_values_ajax' ) );
    1072
     73        // Activate default filters
     74        require_once "class.DeliveryPlus_Filter_Number.php";
     75        require_once "class.DeliveryPlus_Filter_Weight.php";
     76        require_once "class.DeliveryPlus_Filter_Category.php";
     77        require_once "class.DeliveryPlus_Filter_SubTotal.php";
     78
    1179        DeliveryPlus_Filter_Category::activate();
     80        DeliveryPlus_Filter_SubTotal::activate();
     81        DeliveryPlus_Filter_Weight::activate();
    1282    }
    1383
     
    2696    public static function get_categories() {
    2797
    28         $categories[] = 'Category';
    29 
    30         $categories = apply_filters( 'deliveryplus_categories', $categories );
     98        $categories = apply_filters( 'deliveryplus_categories', array() );
    3199
    32100        return $categories;
     
    37105
    38106        $ret = [];
    39 
    40         if($category == 'Category') {
    41             $raw = get_categories(array('taxonomy' => 'product_cat', 'hide_empty' => false));
    42             foreach($raw as $cat) {
    43                 $ret[$cat->term_id] = wp_specialchars_decode( $cat->name );
    44             }
    45         }
    46 
    47         $ret = apply_filters( 'deliveryplus_values_' . $category, $ret );
     107        $ret = apply_filters( 'deliveryplus_values_' . $category, $ret, $condition );
    48108
    49109        return $ret;
     
    64124
    65125        $ret = [];
    66 
    67         if($category == 'Category') {
    68             $ret['1'] = 'at least one in';
    69             $ret['a'] = 'all must be in';
    70             $ret['!'] = 'none must be in';
    71             $ret['!a'] = 'not all in';
    72         }
    73 
    74126        $ret = apply_filters( 'deliveryplus_conditions_' . $category, $ret );
    75127
     
    84136    public static function filter_block_package( $block, $package ) {
    85137
     138        if(empty($block)) {
     139            return true;
     140        }
     141
    86142        foreach( $block as $rule ) {
    87143
    88144            $filter = 'deliveryplus_filter_' . $rule['category'] . '_' . $rule['condition'];
    89145            if(!apply_filters($filter, false, $package, $rule)) {
    90                 var_dump($filter);
    91146                return false;
    92147            }
     
    99154
    100155    public static function filter_package( $filters, $package ) {
     156
     157        if(empty($filters)) {
     158            return true;
     159        }
    101160
    102161        foreach($filters as $block) {
  • deliveryplus-by-invisible-dragon/tags/1.0/class.DeliveryPlus_Shipping_Method.php

    r2251671 r2282505  
    3131                'default'       => __( 'DeliveryPlus' )
    3232            ),
     33            'tax_status' => array(
     34                'title'         => __( 'Tax status', 'woocommerce' ),
     35                'type'          => 'select',
     36                'class'         => 'wc-enhanced-select',
     37                'default'       => 'taxable',
     38                'options'       => array(
     39                    'taxable' => __( 'Taxable', 'woocommerce' ),
     40                    'none'    => _x( 'None', 'Tax status', 'woocommerce' ),
     41                ),
     42            ),
    3343            'rate' => array(
    3444                'title'         => __( 'Rate' ),
     
    247257                // Now we can do some area calculations
    248258                if($width && $length){
    249                     $total_flat_area = ( $width * $length ) * $values['quantity'];
     259                    $total_flat_area += ( $width * $length ) * $values['quantity'];
    250260                }
    251261
     
    269279                    '[length]',
    270280                    '[flat_area]',
     281                    '[weight]',
    271282                    '[cost]',
    272283                ),
     
    277288                    $total_length,
    278289                    $total_flat_area,
     290                    $total_weight,
    279291                    $package['contents_cost'],
    280292                ),
  • deliveryplus-by-invisible-dragon/tags/1.0/id-delivery.php

    r2251671 r2282505  
    77Author URI: https://invisibledragonltd.com/
    88License: Private
    9 Version: 1.0.0
     9Version: 1.1.0
     10
     11WC requires at least: 3.9
     12WC tested up to: 4.0
    1013*/
    1114
    12 define('ID_DELIVERY_VERSION', '1.0');
     15define('ID_DELIVERY_VERSION', '1.1');
    1316
    1417add_action( 'plugins_loaded', array( 'DeliveryPlusPlugin', 'get_instance' ) );
     
    3841
    3942        return have_rows($key, 'woo_ship_' . $rate->get_instance_id());
     43
     44    }
     45
     46    public static function methods_for_item($product, $destination = null) {
     47
     48        $package = [
     49            'contents' => [
     50                'single' => [
     51                    'quantity' => 1,
     52                    'data' => $product
     53                ]
     54            ],
     55            'destination' => $destination
     56        ];
     57
     58        $results = WC()->shipping()->calculate_shipping_for_package($package, time());
     59
     60        return $results['rates'];
    4061
    4162    }
  • deliveryplus-by-invisible-dragon/tags/1.0/includes/filters.php

    r2251671 r2282505  
    66    .id-filter-ui .footer { padding-top: 1.5rem; }
    77    .id-filter-ui .template { display: none; }
     8    .id-filter-ui .id-remove { color: #a00; }
     9    .id-filter-ui .id-remove:hover{ color: #c30000; }
    810</style>
    911<div class="id-filter-ui">
     
    1517            <thead>
    1618                <tr>
    17                     <th colspan="3">
     19                    <th colspan="4">
    1820                        <?= __('All of the following conditions match:'); ?>
    1921                    </th>
     
    2426                    <td>
    2527                        <select class="id-filter-category">
    26                             <?php $categories = DeliveryPlus_Filters::get_categories(); foreach($categories as $cat): ?>
    27                             <option value="<?= $cat; ?>"><?= $cat; ?></option>
     28                            <?php $categories = DeliveryPlus_Filters::get_categories(); foreach($categories as $key => $label): ?>
     29                            <option value="<?= $key; ?>"><?= $label; ?></option>
    2830                            <?php endforeach; ?>
    2931                        </select>
     
    3335                    </td>
    3436                    <td>
    35                         <select class="id-filter-value"></select>
     37                        <span class="id-filter-value">...</span>
     38                    </td>
     39                    <td>
     40                        <a href="#" class="id-remove id-remove-row" title="<?= __('Remove this row'); ?>">
     41                            <span class="dashicons dashicons-trash"></span>
     42                        </a>
    3643                    </td>
    3744                </tr>
     
    4249                        <a class="button button-primary id-add-new-and"><?= __('Add new'); ?></a>
    4350                    </th>
     51                    <td>
     52                        <a href="#" class="id-remove id-remove-block" title="<?= __('Remove this block'); ?>">
     53                            <span class="dashicons dashicons-trash"></span>
     54                        </a>
     55                    </td>
    4456                </tr>
    4557            </tfoot>
  • deliveryplus-by-invisible-dragon/tags/1.0/readme.txt

    r2251671 r2282505  
    44Tags: woocommerce, delivery, gravityforms, acf, advancedcustomfields
    55Requires at least: 5.1
    6 Tested up to: 5.3.2
     6Tested up to: 5.4
    77Requires PHP: 7.2
    88Stable tag: 4.3
     
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
    1111 
    12 DeliveryPlus provides a delivery option with rate calculation and filter rules. Also integrates with Gravity
    13 Forms and Advanced Custom Fields.
     12DeliveryPlus provides a delivery option with rate calculation and filter rules. Also integrates with Gravity Forms and Advanced Custom Fields.
    1413 
    1514== Description ==
    1615 
    17 DeliveryPlus was born out of a need for a clean, easy to use and native delivery method for WooCommerce. This
    18 plugin doesn't add any additional tabs to the WordPress menu bar, instead sitting neatly inside of WooCommerce's
    19 shipping options as it should, appearing like any other.
     16DeliveryPlus was born out of a need for a clean, easy to use and native delivery method for WooCommerce. This plugin doesn't add any additional tabs to the WordPress menu bar, instead sitting neatly inside of WooCommerce's shipping options as it should, appearing like any other.
    2017
    21 Each delivery option can opt to provide a method of calculation, with the available tools displayed on screen,
    22 and the ability to filter if the delivery option appears in the checkout under certain conditions.
     18Each delivery option can opt to provide a method of calculation, with the available tools displayed on screen, and the ability to filter if the delivery option appears in the checkout under certain conditions.
    2319
    24 The functionality can be extended if the plugin detects Gravity Forms installed, and allows you to pick a
    25 form to be displayed on the checkout if your delivery option is selected. Upon order submit, the details
    26 are saved and are visible inside of the order view of the WooCommerce admin.
     20The functionality can be extended if the plugin detects Gravity Forms installed, and allows you to pick a form to be displayed on the checkout if your delivery option is selected. Upon order submit, the details are saved and are visible inside of the order view of the WooCommerce admin.
    2721
    28 Again, if you have Advanced Custom Fields installed, you can create custom fields which appear inside of
    29 the shipping admin area and, with custom code, can be used to create an advanced shipping section on
    30 a custom theme.
     22Again, if you have Advanced Custom Fields installed, you can create custom fields which appear inside of the shipping admin area and, with custom code, can be used to create an advanced shipping section on a custom theme.
    3123 
    3224== Installation ==
    3325 
    34 The plugin installs in the standard WordPress fashion. Typically use the Plugins and then Add New and
    35 search for the plugin. Or, the manual way:
     26The plugin installs in the standard WordPress fashion. Typically use the Plugins and then Add New and search for the plugin. Or, the manual way:
    3627 
    37281. Upload the plugin directory to the `/wp-content/plugins/` directory
     
    6152= 1.0 =
    6253* Initial Release
     54
     55= 1.1 =
     56* Ability to remove conditions if added by mistake
     57* SubTotal condition added
     58* Bugs fixed
     59* Test Suite added
    6360 
    6461== Upgrade Notice ==
  • deliveryplus-by-invisible-dragon/trunk/admin.js

    r2251671 r2282505  
    88        $(".id-filtering").each(function () {
    99
     10            // When category is picked, load next option down
    1011            $(this).on("change", ".id-filter-category", function () {
    1112                var nextDrop = $(".id-filter-condition", $(this).closest("tr"));
     
    1415                    nextDrop.html('');
    1516                    for(let key in data) {
    16                         $("<option>").attr("value", key).text(data[key]).appendTo(nextDrop);
     17                        var nVal = data[key];
     18
     19                        $("<option>").attr("value", key).text(nVal['label']).attr("data-type", nVal['type']).appendTo(nextDrop);
    1720                    }
    1821                    if(nextDrop.attr("data-value")) {
     22                        // If we need to pre-set, pre-set
    1923                        nextDrop.val(nextDrop.attr("data-value"));
    2024                        nextDrop.removeAttr("data-value");
    2125                    }
     26                    // Load default values
    2227                    nextDrop.trigger('change');
    2328                });
    2429            });
    2530
     31            // When condition type is changed, update dropdown
    2632            $(this).on("change", ".id-filter-condition", function () {
     33                // Get the type of the condition value
     34                var category = $(".id-filter-category", $(this).closest("tr")).val();
     35                var nextType = $("option:selected", $(this)).attr("data-type");
     36
    2737                var nextDrop = $(".id-filter-value", $(this).closest("tr"));
    28                 nextDrop.html('<option>...</option>');
    29                 var category =  $(".id-filter-category", $(this).closest("tr")).val();
    30                 $.getJSON(window.ajaxurl + "?action=deliveryplus_get_values&category=" + category +"&condition=" + $(this).val(), function (data) {
    31                     nextDrop.html('');
    32                     for(let key in data) {
    33                         $("<option>").attr("value", key).text(data[key]).appendTo(nextDrop);
     38                var n = $("<div>").addClass("id-filter-value").text("...");
     39                nextDrop.replaceWith(n);
     40                nextDrop = n;
     41
     42                if(nextType == 'pick'){
     43
     44                    $.getJSON(window.ajaxurl + "?action=deliveryplus_get_values&category=" + category +"&condition=" + $(this).val(), function (data) {
     45                        var n = $("<select>").addClass("id-filter-value");
     46                        nextDrop.replaceWith(n);
     47                        nextDrop = n;
     48                        for(let key in data) {
     49                            $("<option>").attr("value", key).text(data[key]).appendTo(nextDrop);
     50                        }
     51                        if(nextDrop.parent().attr("data-value")) {
     52                            nextDrop.val(nextDrop.parent().attr("data-value"));
     53                            nextDrop.parent().removeAttr("data-value");
     54                        }
     55                        nextDrop.trigger('change');
     56                    });
     57
     58                } else if(nextType == 'value'){
     59
     60                    let n = $("<input>").addClass("id-filter-value input-text").attr("type", "text");
     61                    nextDrop.replaceWith(n);
     62                    nextDrop = n;
     63                    if(nextDrop.parent().attr("data-value")) {
     64                        nextDrop.val(nextDrop.parent().attr("data-value"));
     65                        nextDrop.parent().removeAttr("data-value");
    3466                    }
    35                     if(nextDrop.attr("data-value")) {
    36                         nextDrop.val(nextDrop.attr("data-value"));
    37                         nextDrop.removeAttr("data-value");
    38                     }
    39                     nextDrop.trigger('change');
    40                 });
     67
     68                }else {
     69                    nextDrop.text("! " + nextType);
     70                }
    4171            });
    4272
     73            // Delete Row
     74            $(this).on("click", ".id-remove-row", function(e){
     75                e.preventDefault();
     76                $(this).closest("tr").remove();
     77            });
     78
     79            // Delete Block
     80            $(this).on("click", ".id-remove-block", function(e){
     81                e.preventDefault();
     82                $(this).closest(".id-filter-set").remove();
     83            });
     84
     85            // New Row
    4386            $(this).on("click", ".id-add-new-and", function() {
    4487                newAndCondition($(this).closest("table"));
    4588            });
    4689
     90            // New Block
    4791            $(this).on("click", ".id-add-new-or", function(){
    4892                newOrCondition();
     
    56100                    $(".id-filter-category", n).val(row['category']);
    57101                    $(".id-filter-condition", n).attr("data-value", row['condition']);
    58                     $(".id-filter-value", n).attr("data-value", row['value']);
     102                    $(".id-filter-value", n).parent().attr("data-value", row['value']);
    59103                }
    60104
     
    75119            }
    76120
    77             let items = JSON.parse($("input", $(".id-filtering").closest('fieldset')).val() || '[]');
     121            // Parse input from saved
     122            let items = JSON.parse($("input[type='hidden']", $(".id-filtering").closest('fieldset')).val() || '[]');
    78123
    79124            if(items.length > 0) {
     
    99144                });
    100145
    101                 $("input", $(".id-filtering").closest('fieldset')).val(JSON.stringify(ret));
     146                $("input[type='hidden']", $(".id-filtering").closest('fieldset')).val(JSON.stringify(ret));
    102147
    103148            }
    104149
    105             $(this).on("change", "select", function(){
     150            $(this).on("change", "select, input[type='text']", function(){
    106151                renderJSON();
    107152            });
  • deliveryplus-by-invisible-dragon/trunk/class.DeliveryPlus_Filter_Category.php

    r2251671 r2282505  
    11<?php
    22
    3 class DeliveryPlus_Filter_Category {
     3class DeliveryPlus_Filter_Category extends DeliveryPlus_Filter_Set {
     4
     5    public static $category = 'Category';
     6
     7    public static function category_label(){ return __('Category'); }
    48
    59    public static function activate() {
     10        parent::activate();
    611        add_filter( 'deliveryplus_filter_Category_1', array( static::class, 'at_least_one' ), 10, 3 );
    712        add_filter( 'deliveryplus_filter_Category_!', array( static::class, 'none' ), 10, 3 );
    813        add_filter( 'deliveryplus_filter_Category_!a', array( static::class, 'not_all' ), 10, 3 );
    914        add_filter( 'deliveryplus_filter_Category_a', array( static::class, 'all' ), 10, 3 );
     15    }
     16
     17    public static function get_conditions($conditions) {
     18        $ret['1'] = new DPF_Pick_Value(__('at least one in'));
     19        $ret['a'] = new DPF_Pick_Value(__('all must be in'));
     20        $ret['!'] = new DPF_Pick_Value(__('none must be in'));
     21        $ret['!a'] = new DPF_Pick_Value(__('not all in'));
     22        return $ret;
     23    }
     24
     25    public static function get_values($ret, $condition) {
     26        $raw = get_categories(array('taxonomy' => 'product_cat', 'hide_empty' => false));
     27        foreach($raw as $cat) {
     28            $ret[$cat->term_id] = wp_specialchars_decode( $cat->name );
     29        }
     30        return $ret;
    1031    }
    1132
  • deliveryplus-by-invisible-dragon/trunk/class.DeliveryPlus_Filters.php

    r2251671 r2282505  
    11<?php
    22
    3 require_once "class.DeliveryPlus_Filter_Category.php";
     3/**
     4 * This is a standard DeliveryPlus condition, specifying the value for this
     5 * condition should be entered into a textbox
     6 */
     7class DPF_Value {
     8
     9    public $type = 'value';
     10
     11    public function __construct($label) {
     12        $this->label = $label;
     13    }
     14
     15    public function toJSON() {
     16        return array(
     17            'type' => $this->type,
     18            'label' => $this->label
     19        );
     20    }
     21
     22}
     23
     24/**
     25 * This is a variation of a DeliveryPlus conditon, whereby the value
     26 * needs to be picked from a dropdown list.
     27 */
     28class DPF_Pick_Value extends DPF_Value {
     29
     30    public $type = 'pick';
     31
     32}
     33
     34abstract class DeliveryPlus_Filter_Set {
     35
     36    public static $category = 'Unknown';
     37    public static function category_label(){ return __('Unknown'); }
     38
     39    public static function activate() {
     40
     41        add_filter( 'deliveryplus_categories', array( static::class, 'add_category' ) );
     42        add_filter( 'deliveryplus_values_' . static::$category, array( static::class, 'get_values' ), 10, 2 );
     43        add_filter( 'deliveryplus_conditions_' . static::$category, array( static::class, 'get_conditions' ) );
     44
     45        // Now associate a filter function for each condition
     46        $conditions = static::get_conditions(array());
     47        foreach($conditions as $key => $val) {
     48            add_filter( 'deliveryplus_filter_' . static::$category . '_' . $key, array( static::class, 'do_' . $key ), 10, 3 );
     49        }
     50
     51    }
     52
     53    abstract public static function get_conditions($conditions);
     54
     55    public static function get_values($ret, $condition){
     56        // TODO by sub-function
     57        return $ret;
     58    }
     59
     60    public static function add_category($filters) {
     61        $filters[static::$category] = static::category_label();
     62        return $filters;
     63    }
     64}
     65
    466
    567class DeliveryPlus_Filters {
     
    971        add_action( 'wp_ajax_deliveryplus_get_values', array( static::class, 'get_values_ajax' ) );
    1072
     73        // Activate default filters
     74        require_once "class.DeliveryPlus_Filter_Number.php";
     75        require_once "class.DeliveryPlus_Filter_Weight.php";
     76        require_once "class.DeliveryPlus_Filter_Category.php";
     77        require_once "class.DeliveryPlus_Filter_SubTotal.php";
     78
    1179        DeliveryPlus_Filter_Category::activate();
     80        DeliveryPlus_Filter_SubTotal::activate();
     81        DeliveryPlus_Filter_Weight::activate();
    1282    }
    1383
     
    2696    public static function get_categories() {
    2797
    28         $categories[] = 'Category';
    29 
    30         $categories = apply_filters( 'deliveryplus_categories', $categories );
     98        $categories = apply_filters( 'deliveryplus_categories', array() );
    3199
    32100        return $categories;
     
    37105
    38106        $ret = [];
    39 
    40         if($category == 'Category') {
    41             $raw = get_categories(array('taxonomy' => 'product_cat', 'hide_empty' => false));
    42             foreach($raw as $cat) {
    43                 $ret[$cat->term_id] = wp_specialchars_decode( $cat->name );
    44             }
    45         }
    46 
    47         $ret = apply_filters( 'deliveryplus_values_' . $category, $ret );
     107        $ret = apply_filters( 'deliveryplus_values_' . $category, $ret, $condition );
    48108
    49109        return $ret;
     
    64124
    65125        $ret = [];
    66 
    67         if($category == 'Category') {
    68             $ret['1'] = 'at least one in';
    69             $ret['a'] = 'all must be in';
    70             $ret['!'] = 'none must be in';
    71             $ret['!a'] = 'not all in';
    72         }
    73 
    74126        $ret = apply_filters( 'deliveryplus_conditions_' . $category, $ret );
    75127
     
    84136    public static function filter_block_package( $block, $package ) {
    85137
     138        if(empty($block)) {
     139            return true;
     140        }
     141
    86142        foreach( $block as $rule ) {
    87143
    88144            $filter = 'deliveryplus_filter_' . $rule['category'] . '_' . $rule['condition'];
    89145            if(!apply_filters($filter, false, $package, $rule)) {
    90                 var_dump($filter);
    91146                return false;
    92147            }
     
    99154
    100155    public static function filter_package( $filters, $package ) {
     156
     157        if(empty($filters)) {
     158            return true;
     159        }
    101160
    102161        foreach($filters as $block) {
  • deliveryplus-by-invisible-dragon/trunk/class.DeliveryPlus_Shipping_Method.php

    r2251671 r2282505  
    3131                'default'       => __( 'DeliveryPlus' )
    3232            ),
     33            'tax_status' => array(
     34                'title'         => __( 'Tax status', 'woocommerce' ),
     35                'type'          => 'select',
     36                'class'         => 'wc-enhanced-select',
     37                'default'       => 'taxable',
     38                'options'       => array(
     39                    'taxable' => __( 'Taxable', 'woocommerce' ),
     40                    'none'    => _x( 'None', 'Tax status', 'woocommerce' ),
     41                ),
     42            ),
    3343            'rate' => array(
    3444                'title'         => __( 'Rate' ),
     
    247257                // Now we can do some area calculations
    248258                if($width && $length){
    249                     $total_flat_area = ( $width * $length ) * $values['quantity'];
     259                    $total_flat_area += ( $width * $length ) * $values['quantity'];
    250260                }
    251261
     
    269279                    '[length]',
    270280                    '[flat_area]',
     281                    '[weight]',
    271282                    '[cost]',
    272283                ),
     
    277288                    $total_length,
    278289                    $total_flat_area,
     290                    $total_weight,
    279291                    $package['contents_cost'],
    280292                ),
  • deliveryplus-by-invisible-dragon/trunk/id-delivery.php

    r2251671 r2282505  
    77Author URI: https://invisibledragonltd.com/
    88License: Private
    9 Version: 1.0.0
     9Version: 1.1.0
     10
     11WC requires at least: 3.9
     12WC tested up to: 4.0
    1013*/
    1114
    12 define('ID_DELIVERY_VERSION', '1.0');
     15define('ID_DELIVERY_VERSION', '1.1');
    1316
    1417add_action( 'plugins_loaded', array( 'DeliveryPlusPlugin', 'get_instance' ) );
     
    3841
    3942        return have_rows($key, 'woo_ship_' . $rate->get_instance_id());
     43
     44    }
     45
     46    public static function methods_for_item($product, $destination = null) {
     47
     48        $package = [
     49            'contents' => [
     50                'single' => [
     51                    'quantity' => 1,
     52                    'data' => $product
     53                ]
     54            ],
     55            'destination' => $destination
     56        ];
     57
     58        $results = WC()->shipping()->calculate_shipping_for_package($package, time());
     59
     60        return $results['rates'];
    4061
    4162    }
  • deliveryplus-by-invisible-dragon/trunk/includes/filters.php

    r2251671 r2282505  
    66    .id-filter-ui .footer { padding-top: 1.5rem; }
    77    .id-filter-ui .template { display: none; }
     8    .id-filter-ui .id-remove { color: #a00; }
     9    .id-filter-ui .id-remove:hover{ color: #c30000; }
    810</style>
    911<div class="id-filter-ui">
     
    1517            <thead>
    1618                <tr>
    17                     <th colspan="3">
     19                    <th colspan="4">
    1820                        <?= __('All of the following conditions match:'); ?>
    1921                    </th>
     
    2426                    <td>
    2527                        <select class="id-filter-category">
    26                             <?php $categories = DeliveryPlus_Filters::get_categories(); foreach($categories as $cat): ?>
    27                             <option value="<?= $cat; ?>"><?= $cat; ?></option>
     28                            <?php $categories = DeliveryPlus_Filters::get_categories(); foreach($categories as $key => $label): ?>
     29                            <option value="<?= $key; ?>"><?= $label; ?></option>
    2830                            <?php endforeach; ?>
    2931                        </select>
     
    3335                    </td>
    3436                    <td>
    35                         <select class="id-filter-value"></select>
     37                        <span class="id-filter-value">...</span>
     38                    </td>
     39                    <td>
     40                        <a href="#" class="id-remove id-remove-row" title="<?= __('Remove this row'); ?>">
     41                            <span class="dashicons dashicons-trash"></span>
     42                        </a>
    3643                    </td>
    3744                </tr>
     
    4249                        <a class="button button-primary id-add-new-and"><?= __('Add new'); ?></a>
    4350                    </th>
     51                    <td>
     52                        <a href="#" class="id-remove id-remove-block" title="<?= __('Remove this block'); ?>">
     53                            <span class="dashicons dashicons-trash"></span>
     54                        </a>
     55                    </td>
    4456                </tr>
    4557            </tfoot>
  • deliveryplus-by-invisible-dragon/trunk/readme.txt

    r2251671 r2282505  
    44Tags: woocommerce, delivery, gravityforms, acf, advancedcustomfields
    55Requires at least: 5.1
    6 Tested up to: 5.3.2
     6Tested up to: 5.4
    77Requires PHP: 7.2
    88Stable tag: 4.3
     
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
    1111 
    12 DeliveryPlus provides a delivery option with rate calculation and filter rules. Also integrates with Gravity
    13 Forms and Advanced Custom Fields.
     12DeliveryPlus provides a delivery option with rate calculation and filter rules. Also integrates with Gravity Forms and Advanced Custom Fields.
    1413 
    1514== Description ==
    1615 
    17 DeliveryPlus was born out of a need for a clean, easy to use and native delivery method for WooCommerce. This
    18 plugin doesn't add any additional tabs to the WordPress menu bar, instead sitting neatly inside of WooCommerce's
    19 shipping options as it should, appearing like any other.
     16DeliveryPlus was born out of a need for a clean, easy to use and native delivery method for WooCommerce. This plugin doesn't add any additional tabs to the WordPress menu bar, instead sitting neatly inside of WooCommerce's shipping options as it should, appearing like any other.
    2017
    21 Each delivery option can opt to provide a method of calculation, with the available tools displayed on screen,
    22 and the ability to filter if the delivery option appears in the checkout under certain conditions.
     18Each delivery option can opt to provide a method of calculation, with the available tools displayed on screen, and the ability to filter if the delivery option appears in the checkout under certain conditions.
    2319
    24 The functionality can be extended if the plugin detects Gravity Forms installed, and allows you to pick a
    25 form to be displayed on the checkout if your delivery option is selected. Upon order submit, the details
    26 are saved and are visible inside of the order view of the WooCommerce admin.
     20The functionality can be extended if the plugin detects Gravity Forms installed, and allows you to pick a form to be displayed on the checkout if your delivery option is selected. Upon order submit, the details are saved and are visible inside of the order view of the WooCommerce admin.
    2721
    28 Again, if you have Advanced Custom Fields installed, you can create custom fields which appear inside of
    29 the shipping admin area and, with custom code, can be used to create an advanced shipping section on
    30 a custom theme.
     22Again, if you have Advanced Custom Fields installed, you can create custom fields which appear inside of the shipping admin area and, with custom code, can be used to create an advanced shipping section on a custom theme.
    3123 
    3224== Installation ==
    3325 
    34 The plugin installs in the standard WordPress fashion. Typically use the Plugins and then Add New and
    35 search for the plugin. Or, the manual way:
     26The plugin installs in the standard WordPress fashion. Typically use the Plugins and then Add New and search for the plugin. Or, the manual way:
    3627 
    37281. Upload the plugin directory to the `/wp-content/plugins/` directory
     
    6152= 1.0 =
    6253* Initial Release
     54
     55= 1.1 =
     56* Ability to remove conditions if added by mistake
     57* SubTotal condition added
     58* Bugs fixed
     59* Test Suite added
    6360 
    6461== Upgrade Notice ==
Note: See TracChangeset for help on using the changeset viewer.