Plugin Directory

Changeset 1370301


Ignore:
Timestamp:
03/13/2016 10:05:01 PM (10 years ago)
Author:
opentools
Message:

V1.2.1: Fix warning when a rule line contains only spaces

Location:
shipping-by-rules-for-woocommerce
Files:
5 edited
22 copied

Legend:

Unmodified
Added
Removed
  • shipping-by-rules-for-woocommerce/tags/1.2.1/includes/rules_shipping_framework_woocommerce.php

    r1339835 r1370301  
    2323            "products"      => 'products',
    2424            "skus"          => 'products',
     25            "vendors"       => 'vendors',
    2526        ));
    2627    }
     
    210211        $tags = array_unique($tags);
    211212        $shipping_classes = array_unique($shipping_classes);
    212 
    213         return array (
     213       
     214
     215        $data = array (
    214216            'skus'       => $skus,
    215217            'categories' => $categories,
     
    217219            'shippingclasses' => $shipping_classes,
    218220        );
     221       
     222        // THIRD-PARTY SUPPORT
     223       
     224        // "WC Vendors"  support (vendors stored as post author)
     225        if (class_exists("WC_Vendors")) {
     226            $vendorids = array();
     227            foreach ($products as $product) {
     228                $vendorids[] = $product['data']->post->post_author;
     229            }
     230            $data['vendorids'] = array_unique($vendorids);
     231           
     232            $vendors = array(); // Requires "WC Vendors" or "WooThemes Product Vendors" plugin
     233            $vendornames = array();
     234            foreach ($data['vendorids'] as $v) {
     235                $vnd = get_user_by('id', $v);  // Get user name by user id
     236                $vendornames[] = $vnd->display_name;
     237                $vendors[] = $vnd->user_login;
     238            }
     239            $data['vendornames'] = array_unique($vendornames);
     240            $data['vendors'] = array_unique($vendors);
     241        }
     242       
     243        // "WooThemes Vendor Products" support (vendors stored in its own taxonomy)
     244        if (class_exists("WooCommerce_Product_Vendors") && function_exists("get_product_vendors")) {
     245            $vendors = array();
     246            $vendornames = array();
     247            $vendorids = array();
     248            // The plugin provides its own function to retrieve the vendor for a product
     249            foreach ($products as $product) {
     250                foreach (get_product_vendors($product['data']->id) as $vendor) {
     251// $this->printWarning("<pre>vendor: ".print_r($vendor,1)."</pre>");
     252                    $vendors[] = $vendor->slug;
     253                    $vendornames[] = $vendor->title;
     254                    $vendorids[] = $vendor->ID;
     255                }
     256            }
     257            $data['vendors'] = array_unique($vendors);
     258            $data['vendornames'] = array_unique($vendornames);
     259            $data['vendorids'] = array_unique($vendorids);
     260        }
     261       
     262        // "YITH WooCommerce Multi Vendor" support (vendors stored in its own taxonomy)
     263        if (function_exists("yith_get_vendor")) {
     264            $vendors = array();
     265            $vendornames = array();
     266            $vendorids = array();
     267            // The plugin provides its own function to retrieve the vendor for a product
     268            foreach ($products as $product) {
     269                $vendor = yith_get_vendor($product['data']->id, 'product');
     270// $this->printWarning("<pre>vendor: ".print_r($vendor,1)."</pre>");
     271                if ($vendor->is_valid()) {
     272                    $vendors[] = $vendor->slug;
     273                    $vendornames[] = $vendor->name;
     274                    $vendorids[] = $vendor->term_id;
     275                }
     276            }
     277            $data['vendors'] = array_unique($vendors);
     278            $data['vendornames'] = array_unique($vendornames);
     279            $data['vendorids'] = array_unique($vendorids);
     280        }
     281       
     282       
     283        // END THIRD-PARTY SUPPORT
     284       
     285       
     286        return $data;
    219287    }
    220288   
     
    324392            if (!empty($filter_conditions['subcategories']) && count(array_intersect($subcategories, $prodcategories))==0)
    325393                continue;
     394           
     395            if (!empty($filter_conditions['vendors'])) {
     396                // Collect all vendors (ids and slug/login_name - PLUGIN-specific!)
     397                // for the current product. If any of them is in the vendor conditions
     398                // list, this product should not be filtered out!
     399                $vnd_props = array();
     400               
     401                // THIRD-PARTY SUPPORT
     402                // "WC Vendors"  support (vendors stored as post author)
     403                if (class_exists("WC_Vendors")) {
     404                    $vendor = $p['data']->post->post_author;
     405                    $vnd = get_user_by('id', $vendor);  // Get user name by user id
     406                    $vnd_props[] = $vendor;
     407                    $vnd_props[] = $vnd->user_login;
     408                }
     409
     410                // "WooThemes Vendor Products" support (vendors stored in its own taxonomy)
     411                if (class_exists("WooCommerce_Product_Vendors") && function_exists("get_product_vendors")) {
     412                    foreach (get_product_vendors($p['data']->id) as $vendor) {
     413                        $vnd_props[] = $vendor->slug;
     414                    }
     415                }
     416
     417                // "YITH WooCommerce Multi Vendor" support (vendors stored in its own taxonomy)
     418                if (function_exists("yith_get_vendor")) {
     419                    $vendor = yith_get_vendor($p['data']->id, 'product');
     420                    if ($vendor->is_valid()) {
     421                        $vnd_props[] = $vendor->slug;
     422                    }
     423                }
     424       
     425                // END THIRD-PARTY SUPPORT
     426
     427                // Check if any of the vendor properties is matched by the conditions; If not => skip product
     428                if (count(array_intersect($vnd_props, $filter_conditions['vendors']))==0)
     429                    continue;
     430            }
    326431            $result[] = $p;
    327432        }
  • shipping-by-rules-for-woocommerce/tags/1.2.1/includes/rules_shipping_framework_woocommerce_advanced.php

    r1338825 r1370301  
    3030    protected function getOrderAddress ($cart, $method) {
    3131        $data = parent::getOrderAddress($cart, $method);
     32        $address = $cart['destination'];
    3233        $zip = isset($address['postcode'])?trim($address['postcode']):'';
    3334        if (isset($zip) && $zip!='') {
  • shipping-by-rules-for-woocommerce/tags/1.2.1/library/rules_shipping_framework.php

    r1338825 r1370301  
    5252class RulesShippingFramework {
    5353    static $_version = "0.1";
    54     protected $_callbacks = array();
     54    protected $callbacks = array();
    5555    // Store the parsed and possibly evaluated rules for each method (method ID is used as key)
    5656    protected $rules = array();
     
    168168    }
    169169   
     170    function getCustomFunctionDefinitions() {
     171        return $this->custom_functions;
     172    }
     173   
    170174    /** @tag system-specific
    171175     *  @function printWarning()
     
    204208    public function setup() {
    205209        $custfuncdefs = $this->getCustomFunctions();
    206         // Loop through the return values of all plugins:
    207         foreach ($custfuncdefs as $custfuncs) {
    208             if (empty($custfuncs))
    209                 continue;
    210             if (!is_array($custfuncs)) {
    211                 $this->warning('OTSHIPMENT_RULES_CUSTOMFUNCTIONS_NOARRAY');
    212             }
    213             // Now loop through all custom function definitions of this plugin
    214             // If a function was registered before, print a warning and use the first definition
    215             foreach ($custfuncs as $fname => $func) {
    216                 if (isset($this->custom_functions[$fname])) {
    217                     $this->warning('OTSHIPMENT_RULES_CUSTOMFUNCTIONS_ALREADY_DEFINED', $fname);
    218                 } else {
    219                     $this->debug("Defining custom function $fname");
    220                     $this->custom_functions[strtolower($fname)] = $func;
    221                 }
     210        // Now loop through all custom function definitions of this plugin
     211        // If a function was registered before, print a warning and use the first definition
     212        foreach ($custfuncdefs as $fname => $func) {
     213            if (isset($this->custom_functions[$fname]) && $this->custom_functions[$fname]!=$custfuncs[$fname]) {
     214                $this->warning('OTSHIPMENT_RULES_CUSTOMFUNCTIONS_ALREADY_DEFINED', $fname);
     215            } else {
     216                $this->debug("Defining custom function $fname");
     217                $this->custom_functions[strtolower($fname)] = $func;
    222218            }
    223219        }
     
    288284    }
    289285   
     286    protected function getDebugVariables ($cart, $products, $method) {
     287       
     288        return array(
     289            'debug_cart'=> print_r($cart,1),
     290            'debug_products' => print_r($products, 1),
     291        );
     292    }
     293   
    290294    /**
    291295     * Extract information about non-numerical zip codes (UK and Canada) from the postal code
    292296     */
    293     protected function getAddressZIP ($zip) {
     297    public function getAddressZIP ($zip) {
    294298        $values = array();
    295299
     
    331335     */
    332336    protected function addCustomCartValues ($cart, $products, $method, &$values) {
     337        // Pass all args through to the callback, if it exists
    333338        if (isset($this->callbacks['addCustomCartValues'])) {
    334             return $this->callbacks['addCustomCartValues']($cart, $products, $method, $values);
    335         }
     339            return call_user_func_array($this->callbacks['addCustomCartValues'], array($cart, $products, $method, &$values)/*func_get_args()*/);
     340        }
     341        return $values;
    336342    }
    337343    protected function addPluginCartValues($cart, $products, $method, &$values) {
     344        return $values;
    338345    }
    339346   
     
    350357            // Add Total/Min/Max weight and dimension variables:
    351358            $this->getOrderWeights ($cart, $products, $method),
    352             $this->getOrderDimensions ($cart, $products, $method)
     359            $this->getOrderDimensions ($cart, $products, $method),
     360            $this->getDebugVariables ($cart, $products, $method)
    353361        );
    354362        // Let child classes update the $cartvals array, or add new variables
     
    531539    protected function createMethodRule ($r, $countries, $ruleinfo) {
    532540        if (isset($this->callbacks['initRule'])) {
    533             return $this->callbacks['initRule']($this, $r, $countries, $ruleinfo);
     541            return call_user_func_array($this->callbacks['initRule'],
     542                                        array($this, $r, $countries, $ruleinfo));
    534543        } else {
    535544            return new ShippingRule($this, $r, $countries, $ruleinfo);
     
    550559        foreach ($rules1 as $r) {
    551560            // Ignore empty lines
    552             if (empty($r)) continue;
     561            if (empty($r) || trim($r)=='') continue;
    553562            $result[] = $this->createMethodRule ($r, $countries, $ruleinfo);
    554563        }
     
    636645        /* Both versions create an expression tree, which can be easily evaluated in evaluateTerm */
    637646        $rulepart = trim($rulepart);
    638         if (empty($rulepart)) return;
     647        if (!isset($rulepart) || $rulepart==='') return;
    639648
    640649       
     
    823832        // Check if we have a custom function definition and use that if so.
    824833        // This is done first to allow plugins to override even built-in functions!
    825         if (isset($this->plugin->custom_functions[$func])) {
     834        $customfunctions = $this->framework->getCustomFunctionDefinitions();
     835        if (isset($customfunctions[$func])) {
    826836            $this->framework->debug("Evaluating custom function $function, defined by a plugin");
    827             return call_user_func_array($this->plugin->custom_functions[$func], $args, $this);
     837            return call_user_func($customfunctions[$func], $args, $this);
    828838        }
    829839
     
    907917        } elseif ($varname=='values') {
    908918            return $vals;
    909         } elseif ($varname=='values_debug') {
    910             return print_r($vals,1);
     919        } elseif ($varname=='values_debug' || $varname='debug_values') {
     920            $tmpvals = $vals;
     921            unset($tmpvals['debug_cart']);
     922            unset($tmpvals['debug_products']);
     923            return print_r($tmpvals,1);
    911924        } else {
    912925            $this->framework->warning('OTSHIPMENT_RULES_EVALUATE_UNKNOWN_VALUE', $expr, $this->rulestring);
  • shipping-by-rules-for-woocommerce/tags/1.2.1/readme.txt

    r1338829 r1370301  
    33Tags: WooCommerce, Shipment, Shipping, Rules shipping
    44Requires at least: 4.0
    5 Tested up to: 4.4.1
    6 Stable tag: 1.1.1
     5Tested up to: 4.4.2
     6Stable tag: 1.2.1
    77License: GPLv3 or later
    88License URI: http://www.gnu.org/licenses/gpl.html
     
    7070== Changelog ==
    7171
     72= 1.2.1 =
     73* Fix for warning when a rule contained only spaces
     74
     75= 1.2 =
     76* Add support for "WC Vendors" and for "WooThemes Product Vendors" (new variable "Vendors", new function "evaluate_for_vendors")
     77
    7278= 1.1.1 =
    7379* Fix for PHP 5.3
  • shipping-by-rules-for-woocommerce/tags/1.2.1/woocommerce-shipping-by-rules.php

    r1338825 r1370301  
    44 * Plugin URI: http://open-tools.net/woocommerce/advanced-shipping-by-rules-for-woocommerce.html
    55 * Description: Define Shipping cost by very general and flexible (text-based) rules.
    6  * Version: 1.1.1
     6 * Version: 1.2.1
    77 * Author: Open Tools, Reinhold Kainhofer
    88 * Author URI: http://open-tools.net
     
    1111 * License: GPL2+
    1212 * WC requires at least: 2.2
    13  * WC tested up to: 2.4
     13 * WC tested up to: 2.5
    1414 
    1515
     
    4040 *
    4141 * @class       WooCommerce_Shipping_By_Rules
    42  * @version     1.1.1
    4342 * @author      Reinhold Kainhofer
    4443 */
     
    5049     * @var string $version Plugin version number.
    5150     */
    52     public $version = '1.1.1';
     51    public $version = '1.2.1';
    5352
    5453
  • shipping-by-rules-for-woocommerce/tags/1.2/includes/rules_shipping_framework_woocommerce.php

    r1339835 r1370301  
    2323            "products"      => 'products',
    2424            "skus"          => 'products',
     25            "vendors"       => 'vendors',
    2526        ));
    2627    }
     
    210211        $tags = array_unique($tags);
    211212        $shipping_classes = array_unique($shipping_classes);
    212 
    213         return array (
     213       
     214
     215        $data = array (
    214216            'skus'       => $skus,
    215217            'categories' => $categories,
     
    217219            'shippingclasses' => $shipping_classes,
    218220        );
     221       
     222        // THIRD-PARTY SUPPORT
     223       
     224        // "WC Vendors"  support (vendors stored as post author)
     225        if (class_exists("WC_Vendors")) {
     226            $vendorids = array();
     227            foreach ($products as $product) {
     228                $vendorids[] = $product['data']->post->post_author;
     229            }
     230            $data['vendorids'] = array_unique($vendorids);
     231           
     232            $vendors = array(); // Requires "WC Vendors" or "WooThemes Product Vendors" plugin
     233            $vendornames = array();
     234            foreach ($data['vendorids'] as $v) {
     235                $vnd = get_user_by('id', $v);  // Get user name by user id
     236                $vendornames[] = $vnd->display_name;
     237                $vendors[] = $vnd->user_login;
     238            }
     239            $data['vendornames'] = array_unique($vendornames);
     240            $data['vendors'] = array_unique($vendors);
     241        }
     242       
     243        // "WooThemes Vendor Products" support (vendors stored in its own taxonomy)
     244        if (class_exists("WooCommerce_Product_Vendors") && function_exists("get_product_vendors")) {
     245            $vendors = array();
     246            $vendornames = array();
     247            $vendorids = array();
     248            // The plugin provides its own function to retrieve the vendor for a product
     249            foreach ($products as $product) {
     250                foreach (get_product_vendors($product['data']->id) as $vendor) {
     251// $this->printWarning("<pre>vendor: ".print_r($vendor,1)."</pre>");
     252                    $vendors[] = $vendor->slug;
     253                    $vendornames[] = $vendor->title;
     254                    $vendorids[] = $vendor->ID;
     255                }
     256            }
     257            $data['vendors'] = array_unique($vendors);
     258            $data['vendornames'] = array_unique($vendornames);
     259            $data['vendorids'] = array_unique($vendorids);
     260        }
     261       
     262        // END THIRD-PARTY SUPPORT
     263       
     264       
     265        return $data;
    219266    }
    220267   
     
    324371            if (!empty($filter_conditions['subcategories']) && count(array_intersect($subcategories, $prodcategories))==0)
    325372                continue;
     373           
     374            if (!empty($filter_conditions['vendors'])) {
     375                // Collect all vendors (ids and slug/login_name - PLUGIN-specific!)
     376                // for the current product. If any of them is in the vendor conditions
     377                // list, this product should not be filtered out!
     378                $vnd_props = array();
     379               
     380                // THIRD-PARTY SUPPORT
     381                // "WC Vendors"  support (vendors stored as post author)
     382                if (class_exists("WC_Vendors")) {
     383                    $vendor = $p['data']->post->post_author;
     384                    $vnd = get_user_by('id', $vendor);  // Get user name by user id
     385                    $vnd_props[] = $vendor;
     386                    $vnd_props[] = $vnd->user_login;
     387                }
     388
     389                // "WooThemes Vendor Products" support (vendors stored in its own taxonomy)
     390                if (class_exists("WooCommerce_Product_Vendors") && function_exists("get_product_vendors")) {
     391                    foreach (get_product_vendors($p['data']->id) as $vendor) {
     392                        $vnd_props[] = $vendor->slug;
     393                    }
     394                }
     395                // END THIRD-PARTY SUPPORT
     396
     397                // Check if any of the vendor properties is matched by the conditions; If not => skip product
     398                if (count(array_intersect($vnd_props, $filter_conditions['vendors']))==0)
     399                    continue;
     400            }
    326401            $result[] = $p;
    327402        }
  • shipping-by-rules-for-woocommerce/tags/1.2/includes/rules_shipping_framework_woocommerce_advanced.php

    r1338825 r1370301  
    3030    protected function getOrderAddress ($cart, $method) {
    3131        $data = parent::getOrderAddress($cart, $method);
     32        $address = $cart['destination'];
    3233        $zip = isset($address['postcode'])?trim($address['postcode']):'';
    3334        if (isset($zip) && $zip!='') {
  • shipping-by-rules-for-woocommerce/tags/1.2/library/rules_shipping_framework.php

    r1338825 r1370301  
    168168    }
    169169   
     170    function getCustomFunctionDefinitions() {
     171        return $this->custom_functions;
     172    }
     173   
    170174    /** @tag system-specific
    171175     *  @function printWarning()
     
    204208    public function setup() {
    205209        $custfuncdefs = $this->getCustomFunctions();
    206         // Loop through the return values of all plugins:
    207         foreach ($custfuncdefs as $custfuncs) {
    208             if (empty($custfuncs))
    209                 continue;
    210             if (!is_array($custfuncs)) {
    211                 $this->warning('OTSHIPMENT_RULES_CUSTOMFUNCTIONS_NOARRAY');
    212             }
    213             // Now loop through all custom function definitions of this plugin
    214             // If a function was registered before, print a warning and use the first definition
    215             foreach ($custfuncs as $fname => $func) {
    216                 if (isset($this->custom_functions[$fname])) {
    217                     $this->warning('OTSHIPMENT_RULES_CUSTOMFUNCTIONS_ALREADY_DEFINED', $fname);
    218                 } else {
    219                     $this->debug("Defining custom function $fname");
    220                     $this->custom_functions[strtolower($fname)] = $func;
    221                 }
     210        // Now loop through all custom function definitions of this plugin
     211        // If a function was registered before, print a warning and use the first definition
     212        foreach ($custfuncdefs as $fname => $func) {
     213            if (isset($this->custom_functions[$fname]) && $this->custom_functions[$fname]!=$custfuncs[$fname]) {
     214                $this->warning('OTSHIPMENT_RULES_CUSTOMFUNCTIONS_ALREADY_DEFINED', $fname);
     215            } else {
     216                $this->debug("Defining custom function $fname");
     217                $this->custom_functions[strtolower($fname)] = $func;
    222218            }
    223219        }
     
    288284    }
    289285   
     286    protected function getDebugVariables ($cart, $products, $method) {
     287       
     288        return array(
     289            'debug_cart'=> print_r($cart,1),
     290            'debug_products' => print_r($products, 1),
     291        );
     292    }
     293   
    290294    /**
    291295     * Extract information about non-numerical zip codes (UK and Canada) from the postal code
     
    350354            // Add Total/Min/Max weight and dimension variables:
    351355            $this->getOrderWeights ($cart, $products, $method),
    352             $this->getOrderDimensions ($cart, $products, $method)
     356            $this->getOrderDimensions ($cart, $products, $method),
     357            $this->getDebugVariables ($cart, $products, $method)
    353358        );
    354359        // Let child classes update the $cartvals array, or add new variables
     
    636641        /* Both versions create an expression tree, which can be easily evaluated in evaluateTerm */
    637642        $rulepart = trim($rulepart);
    638         if (empty($rulepart)) return;
     643        if (!isset($rulepart) || $rulepart==='') return;
    639644
    640645       
     
    823828        // Check if we have a custom function definition and use that if so.
    824829        // This is done first to allow plugins to override even built-in functions!
    825         if (isset($this->plugin->custom_functions[$func])) {
     830        $customfunctions = $this->framework->getCustomFunctionDefinitions();
     831        if (isset($customfunctions[$func])) {
    826832            $this->framework->debug("Evaluating custom function $function, defined by a plugin");
    827             return call_user_func_array($this->plugin->custom_functions[$func], $args, $this);
     833            return call_user_func($customfunctions[$func], $args, $this);
    828834        }
    829835
     
    907913        } elseif ($varname=='values') {
    908914            return $vals;
    909         } elseif ($varname=='values_debug') {
    910             return print_r($vals,1);
     915        } elseif ($varname=='values_debug' || $varname='debug_values') {
     916            $tmpvals = $vals;
     917            unset($tmpvals['debug_cart']);
     918            unset($tmpvals['debug_products']);
     919            return print_r($tmpvals,1);
    911920        } else {
    912921            $this->framework->warning('OTSHIPMENT_RULES_EVALUATE_UNKNOWN_VALUE', $expr, $this->rulestring);
  • shipping-by-rules-for-woocommerce/tags/1.2/readme.txt

    r1338829 r1370301  
    33Tags: WooCommerce, Shipment, Shipping, Rules shipping
    44Requires at least: 4.0
    5 Tested up to: 4.4.1
    6 Stable tag: 1.1.1
     5Tested up to: 4.4.2
     6Stable tag: 1.2
    77License: GPLv3 or later
    88License URI: http://www.gnu.org/licenses/gpl.html
     
    7070== Changelog ==
    7171
     72= 1.2 =
     73* Add support for "WC Vendors" and for "WooThemes Product Vendors" (new variable "Vendors", new function "evaluate_for_vendors")
     74
    7275= 1.1.1 =
    7376* Fix for PHP 5.3
  • shipping-by-rules-for-woocommerce/tags/1.2/woocommerce-shipping-by-rules.php

    r1338825 r1370301  
    44 * Plugin URI: http://open-tools.net/woocommerce/advanced-shipping-by-rules-for-woocommerce.html
    55 * Description: Define Shipping cost by very general and flexible (text-based) rules.
    6  * Version: 1.1.1
     6 * Version: 1.2
    77 * Author: Open Tools, Reinhold Kainhofer
    88 * Author URI: http://open-tools.net
     
    1111 * License: GPL2+
    1212 * WC requires at least: 2.2
    13  * WC tested up to: 2.4
     13 * WC tested up to: 2.5
    1414 
    1515
     
    4040 *
    4141 * @class       WooCommerce_Shipping_By_Rules
    42  * @version     1.1.1
    4342 * @author      Reinhold Kainhofer
    4443 */
     
    5049     * @var string $version Plugin version number.
    5150     */
    52     public $version = '1.1.1';
     51    public $version = '1.2';
    5352
    5453
  • shipping-by-rules-for-woocommerce/trunk/includes/rules_shipping_framework_woocommerce.php

    r1339835 r1370301  
    2323            "products"      => 'products',
    2424            "skus"          => 'products',
     25            "vendors"       => 'vendors',
    2526        ));
    2627    }
     
    210211        $tags = array_unique($tags);
    211212        $shipping_classes = array_unique($shipping_classes);
    212 
    213         return array (
     213       
     214
     215        $data = array (
    214216            'skus'       => $skus,
    215217            'categories' => $categories,
     
    217219            'shippingclasses' => $shipping_classes,
    218220        );
     221       
     222        // THIRD-PARTY SUPPORT
     223       
     224        // "WC Vendors"  support (vendors stored as post author)
     225        if (class_exists("WC_Vendors")) {
     226            $vendorids = array();
     227            foreach ($products as $product) {
     228                $vendorids[] = $product['data']->post->post_author;
     229            }
     230            $data['vendorids'] = array_unique($vendorids);
     231           
     232            $vendors = array(); // Requires "WC Vendors" or "WooThemes Product Vendors" plugin
     233            $vendornames = array();
     234            foreach ($data['vendorids'] as $v) {
     235                $vnd = get_user_by('id', $v);  // Get user name by user id
     236                $vendornames[] = $vnd->display_name;
     237                $vendors[] = $vnd->user_login;
     238            }
     239            $data['vendornames'] = array_unique($vendornames);
     240            $data['vendors'] = array_unique($vendors);
     241        }
     242       
     243        // "WooThemes Vendor Products" support (vendors stored in its own taxonomy)
     244        if (class_exists("WooCommerce_Product_Vendors") && function_exists("get_product_vendors")) {
     245            $vendors = array();
     246            $vendornames = array();
     247            $vendorids = array();
     248            // The plugin provides its own function to retrieve the vendor for a product
     249            foreach ($products as $product) {
     250                foreach (get_product_vendors($product['data']->id) as $vendor) {
     251// $this->printWarning("<pre>vendor: ".print_r($vendor,1)."</pre>");
     252                    $vendors[] = $vendor->slug;
     253                    $vendornames[] = $vendor->title;
     254                    $vendorids[] = $vendor->ID;
     255                }
     256            }
     257            $data['vendors'] = array_unique($vendors);
     258            $data['vendornames'] = array_unique($vendornames);
     259            $data['vendorids'] = array_unique($vendorids);
     260        }
     261       
     262        // "YITH WooCommerce Multi Vendor" support (vendors stored in its own taxonomy)
     263        if (function_exists("yith_get_vendor")) {
     264            $vendors = array();
     265            $vendornames = array();
     266            $vendorids = array();
     267            // The plugin provides its own function to retrieve the vendor for a product
     268            foreach ($products as $product) {
     269                $vendor = yith_get_vendor($product['data']->id, 'product');
     270// $this->printWarning("<pre>vendor: ".print_r($vendor,1)."</pre>");
     271                if ($vendor->is_valid()) {
     272                    $vendors[] = $vendor->slug;
     273                    $vendornames[] = $vendor->name;
     274                    $vendorids[] = $vendor->term_id;
     275                }
     276            }
     277            $data['vendors'] = array_unique($vendors);
     278            $data['vendornames'] = array_unique($vendornames);
     279            $data['vendorids'] = array_unique($vendorids);
     280        }
     281       
     282       
     283        // END THIRD-PARTY SUPPORT
     284       
     285       
     286        return $data;
    219287    }
    220288   
     
    324392            if (!empty($filter_conditions['subcategories']) && count(array_intersect($subcategories, $prodcategories))==0)
    325393                continue;
     394           
     395            if (!empty($filter_conditions['vendors'])) {
     396                // Collect all vendors (ids and slug/login_name - PLUGIN-specific!)
     397                // for the current product. If any of them is in the vendor conditions
     398                // list, this product should not be filtered out!
     399                $vnd_props = array();
     400               
     401                // THIRD-PARTY SUPPORT
     402                // "WC Vendors"  support (vendors stored as post author)
     403                if (class_exists("WC_Vendors")) {
     404                    $vendor = $p['data']->post->post_author;
     405                    $vnd = get_user_by('id', $vendor);  // Get user name by user id
     406                    $vnd_props[] = $vendor;
     407                    $vnd_props[] = $vnd->user_login;
     408                }
     409
     410                // "WooThemes Vendor Products" support (vendors stored in its own taxonomy)
     411                if (class_exists("WooCommerce_Product_Vendors") && function_exists("get_product_vendors")) {
     412                    foreach (get_product_vendors($p['data']->id) as $vendor) {
     413                        $vnd_props[] = $vendor->slug;
     414                    }
     415                }
     416
     417                // "YITH WooCommerce Multi Vendor" support (vendors stored in its own taxonomy)
     418                if (function_exists("yith_get_vendor")) {
     419                    $vendor = yith_get_vendor($p['data']->id, 'product');
     420                    if ($vendor->is_valid()) {
     421                        $vnd_props[] = $vendor->slug;
     422                    }
     423                }
     424       
     425                // END THIRD-PARTY SUPPORT
     426
     427                // Check if any of the vendor properties is matched by the conditions; If not => skip product
     428                if (count(array_intersect($vnd_props, $filter_conditions['vendors']))==0)
     429                    continue;
     430            }
    326431            $result[] = $p;
    327432        }
  • shipping-by-rules-for-woocommerce/trunk/includes/rules_shipping_framework_woocommerce_advanced.php

    r1338825 r1370301  
    3030    protected function getOrderAddress ($cart, $method) {
    3131        $data = parent::getOrderAddress($cart, $method);
     32        $address = $cart['destination'];
    3233        $zip = isset($address['postcode'])?trim($address['postcode']):'';
    3334        if (isset($zip) && $zip!='') {
  • shipping-by-rules-for-woocommerce/trunk/library/rules_shipping_framework.php

    r1338825 r1370301  
    5252class RulesShippingFramework {
    5353    static $_version = "0.1";
    54     protected $_callbacks = array();
     54    protected $callbacks = array();
    5555    // Store the parsed and possibly evaluated rules for each method (method ID is used as key)
    5656    protected $rules = array();
     
    168168    }
    169169   
     170    function getCustomFunctionDefinitions() {
     171        return $this->custom_functions;
     172    }
     173   
    170174    /** @tag system-specific
    171175     *  @function printWarning()
     
    204208    public function setup() {
    205209        $custfuncdefs = $this->getCustomFunctions();
    206         // Loop through the return values of all plugins:
    207         foreach ($custfuncdefs as $custfuncs) {
    208             if (empty($custfuncs))
    209                 continue;
    210             if (!is_array($custfuncs)) {
    211                 $this->warning('OTSHIPMENT_RULES_CUSTOMFUNCTIONS_NOARRAY');
    212             }
    213             // Now loop through all custom function definitions of this plugin
    214             // If a function was registered before, print a warning and use the first definition
    215             foreach ($custfuncs as $fname => $func) {
    216                 if (isset($this->custom_functions[$fname])) {
    217                     $this->warning('OTSHIPMENT_RULES_CUSTOMFUNCTIONS_ALREADY_DEFINED', $fname);
    218                 } else {
    219                     $this->debug("Defining custom function $fname");
    220                     $this->custom_functions[strtolower($fname)] = $func;
    221                 }
     210        // Now loop through all custom function definitions of this plugin
     211        // If a function was registered before, print a warning and use the first definition
     212        foreach ($custfuncdefs as $fname => $func) {
     213            if (isset($this->custom_functions[$fname]) && $this->custom_functions[$fname]!=$custfuncs[$fname]) {
     214                $this->warning('OTSHIPMENT_RULES_CUSTOMFUNCTIONS_ALREADY_DEFINED', $fname);
     215            } else {
     216                $this->debug("Defining custom function $fname");
     217                $this->custom_functions[strtolower($fname)] = $func;
    222218            }
    223219        }
     
    288284    }
    289285   
     286    protected function getDebugVariables ($cart, $products, $method) {
     287       
     288        return array(
     289            'debug_cart'=> print_r($cart,1),
     290            'debug_products' => print_r($products, 1),
     291        );
     292    }
     293   
    290294    /**
    291295     * Extract information about non-numerical zip codes (UK and Canada) from the postal code
    292296     */
    293     protected function getAddressZIP ($zip) {
     297    public function getAddressZIP ($zip) {
    294298        $values = array();
    295299
     
    331335     */
    332336    protected function addCustomCartValues ($cart, $products, $method, &$values) {
     337        // Pass all args through to the callback, if it exists
    333338        if (isset($this->callbacks['addCustomCartValues'])) {
    334             return $this->callbacks['addCustomCartValues']($cart, $products, $method, $values);
    335         }
     339            return call_user_func_array($this->callbacks['addCustomCartValues'], array($cart, $products, $method, &$values)/*func_get_args()*/);
     340        }
     341        return $values;
    336342    }
    337343    protected function addPluginCartValues($cart, $products, $method, &$values) {
     344        return $values;
    338345    }
    339346   
     
    350357            // Add Total/Min/Max weight and dimension variables:
    351358            $this->getOrderWeights ($cart, $products, $method),
    352             $this->getOrderDimensions ($cart, $products, $method)
     359            $this->getOrderDimensions ($cart, $products, $method),
     360            $this->getDebugVariables ($cart, $products, $method)
    353361        );
    354362        // Let child classes update the $cartvals array, or add new variables
     
    531539    protected function createMethodRule ($r, $countries, $ruleinfo) {
    532540        if (isset($this->callbacks['initRule'])) {
    533             return $this->callbacks['initRule']($this, $r, $countries, $ruleinfo);
     541            return call_user_func_array($this->callbacks['initRule'],
     542                                        array($this, $r, $countries, $ruleinfo));
    534543        } else {
    535544            return new ShippingRule($this, $r, $countries, $ruleinfo);
     
    550559        foreach ($rules1 as $r) {
    551560            // Ignore empty lines
    552             if (empty($r)) continue;
     561            if (empty($r) || trim($r)=='') continue;
    553562            $result[] = $this->createMethodRule ($r, $countries, $ruleinfo);
    554563        }
     
    636645        /* Both versions create an expression tree, which can be easily evaluated in evaluateTerm */
    637646        $rulepart = trim($rulepart);
    638         if (empty($rulepart)) return;
     647        if (!isset($rulepart) || $rulepart==='') return;
    639648
    640649       
     
    823832        // Check if we have a custom function definition and use that if so.
    824833        // This is done first to allow plugins to override even built-in functions!
    825         if (isset($this->plugin->custom_functions[$func])) {
     834        $customfunctions = $this->framework->getCustomFunctionDefinitions();
     835        if (isset($customfunctions[$func])) {
    826836            $this->framework->debug("Evaluating custom function $function, defined by a plugin");
    827             return call_user_func_array($this->plugin->custom_functions[$func], $args, $this);
     837            return call_user_func($customfunctions[$func], $args, $this);
    828838        }
    829839
     
    907917        } elseif ($varname=='values') {
    908918            return $vals;
    909         } elseif ($varname=='values_debug') {
    910             return print_r($vals,1);
     919        } elseif ($varname=='values_debug' || $varname='debug_values') {
     920            $tmpvals = $vals;
     921            unset($tmpvals['debug_cart']);
     922            unset($tmpvals['debug_products']);
     923            return print_r($tmpvals,1);
    911924        } else {
    912925            $this->framework->warning('OTSHIPMENT_RULES_EVALUATE_UNKNOWN_VALUE', $expr, $this->rulestring);
  • shipping-by-rules-for-woocommerce/trunk/readme.txt

    r1338829 r1370301  
    33Tags: WooCommerce, Shipment, Shipping, Rules shipping
    44Requires at least: 4.0
    5 Tested up to: 4.4.1
    6 Stable tag: 1.1.1
     5Tested up to: 4.4.2
     6Stable tag: 1.2.1
    77License: GPLv3 or later
    88License URI: http://www.gnu.org/licenses/gpl.html
     
    7070== Changelog ==
    7171
     72= 1.2.1 =
     73* Fix for warning when a rule contained only spaces
     74
     75= 1.2 =
     76* Add support for "WC Vendors" and for "WooThemes Product Vendors" (new variable "Vendors", new function "evaluate_for_vendors")
     77
    7278= 1.1.1 =
    7379* Fix for PHP 5.3
  • shipping-by-rules-for-woocommerce/trunk/woocommerce-shipping-by-rules.php

    r1338825 r1370301  
    44 * Plugin URI: http://open-tools.net/woocommerce/advanced-shipping-by-rules-for-woocommerce.html
    55 * Description: Define Shipping cost by very general and flexible (text-based) rules.
    6  * Version: 1.1.1
     6 * Version: 1.2.1
    77 * Author: Open Tools, Reinhold Kainhofer
    88 * Author URI: http://open-tools.net
     
    1111 * License: GPL2+
    1212 * WC requires at least: 2.2
    13  * WC tested up to: 2.4
     13 * WC tested up to: 2.5
    1414 
    1515
     
    4040 *
    4141 * @class       WooCommerce_Shipping_By_Rules
    42  * @version     1.1.1
    4342 * @author      Reinhold Kainhofer
    4443 */
     
    5049     * @var string $version Plugin version number.
    5150     */
    52     public $version = '1.1.1';
     51    public $version = '1.2.1';
    5352
    5453
Note: See TracChangeset for help on using the changeset viewer.