Plugin Directory

Changeset 2415322


Ignore:
Timestamp:
11/09/2020 04:54:07 PM (5 years ago)
Author:
UsusIpse
Message:

Update to current core with better use of JSON data

Location:
attribute-calculator/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • attribute-calculator/trunk/AttributeCalculator_OptionsManager.php

    r2196073 r2415322  
    282282        ?>
    283283        <div class="wrap">
    284             <h2><?php _e('System Settings', 'attribute-calculator'); ?></h2>
     284            <h2><?php
     285            _e('System Settings', 'attribute-calculator'); ?></h2>
    285286            <table cellspacing="1" cellpadding="2"><tbody>
    286287            <tr><td><?php _e('System', 'attribute-calculator'); ?></td><td><?php echo php_uname(); ?></td></tr>
     
    359360        if (is_array($aOptionMeta) && count($aOptionMeta) >= 2) { // Drop-down list
    360361            $choices = array_slice($aOptionMeta, 1);
    361             ?>
    362             <p><select name="<?php echo $aOptionKey ?>" id="<?php echo $aOptionKey ?>">
    363             <?php
    364                             foreach ($choices as $aChoice) {
    365                 $selected = ($aChoice == $savedOptionValue) ? 'selected' : '';
    366                 ?>
    367                     <option value="<?php echo $aChoice ?>" <?php echo $selected ?>><?php echo $this->getOptionValueI18nString($aChoice) ?></option>
    368                 <?php
    369             }
    370             ?>
    371             </select></p>
    372             <?php
    373 
    374         }
    375         else { // Simple input field
    376             ?>
    377             <p><input type="text" name="<?php echo $aOptionKey ?>" id="<?php echo $aOptionKey ?>"
    378                       value="<?php echo esc_attr($savedOptionValue) ?>" size="50"/></p>
    379             <?php
    380 
     362           
     363            ?>
     364            <p><select name="<?php echo $aOptionKey ?>" id="<?php echo $aOptionKey ?>">
     365            <?php
     366            foreach ($choices as $aChoice) {
     367                $selected = ($aChoice == $savedOptionValue) ? 'selected' : '';
     368                ?>
     369                    <option value="<?php echo $aChoice ?>" <?php echo $selected ?>><?php echo $this->getOptionValueI18nString($aChoice) ?></option>
     370                <?php
     371            }
     372            ?>
     373            </select></p>
     374            <?php
     375       
     376        }
     377        else { // Simple input field or checkbox
     378            if($savedOptionValue=="1" || $savedOptionValue=="0"){                               
     379                ($savedOptionValue==1)?$check="checked":$check="";                 
     380                ?><input type="hidden" name="<?php echo $aOptionKey ?>" value="0"/>
     381                <p><input type="checkbox" name="<?php echo $aOptionKey ?>" id="<?php echo $aOptionKey ?>"
     382                  value="1" <?php echo $check; ?>/></p>                 
     383                <?php
     384                   
     385            }else{
     386            ?>
     387            <p><input type="text" name="<?php echo $aOptionKey ?>" id="<?php echo $aOptionKey ?>"
     388                      value="<?php echo esc_attr($savedOptionValue) ?>" size="50"/></p>
     389            <?php
     390            }
    381391        }
    382392    }
  • attribute-calculator/trunk/AttributeCalculator_Plugin.php

    r2196073 r2415322  
    1515            //'_version' => array('Installed Version'), // Leave this one commented-out. Uncomment to test upgrades.
    1616            'multiplyBy' => array(__('Slug of the attribute to multiply by. (typically length)', 'uwcpc')),
    17             'isEnabled' => array(__('Enable calculator globally', 'uwcpc'), 'true', 'false')
     17            'isEnabled' => array(__('1', 'uwcpc'))
    1818        );
    1919    }
     
    6969        add_action('wp_enqueue_scripts', array(&$this, 'calculate_length_change_script'));
    7070       
    71        
     71        add_action('admin_enqueue_scripts', array(&$this, 'attcalc_admin_scripts'));
     72       
     73        add_action('add_meta_boxes', [&$this, 'attcalc_create_metabox']);
    7274
    7375    }   
     76    public function attcalc_admin_scripts(){
     77        wp_register_script('attcalc-admin', plugin_dir_url(__FILE__) . '/js/calcadmin.js', array('jquery'), '', true );
     78    }
     79    public function attcalc_create_metabox(){
     80        if(is_admin()){     
     81            add_meta_box('attcalc-control-panel', 'Attribute Calculator Settings', [&$this, 'attcalc_control_panel'], 'product', 'normal', 'high');
     82        }       
     83    }
     84    public function attcalc_control_panel(){
     85        echo 'raaaaaaaaaaaaaaaaaaaaaaawr';
     86    }
    7487    public function calculate_length_change_script(){
    7588        global $post_type;
    7689        wp_register_script('frontcalc', plugin_dir_url(__FILE__) . '/js/calculate.js', array('jquery'), '', true );
    7790       
    78         if($this->getOption('isEnabled') == 'true' && $post_type == 'product'){
     91        if($this->getOption('isEnabled') == '1' && $post_type == 'product'){
    7992            global $woocommerce;
    8093            $multiplyBy = $this->getOption('multiplyBy');
     
    124137        if (isset($_POST[$theMulti]) ) {
    125138       
    126                 $cPrice = substr($_POST[$theMulti], 0, strpos($_POST[$theMulti], '-'));
    127                
     139                //$cPrice = substr($_POST[$theMulti], 0, strpos($_POST[$theMulti], '-'));
     140                $cPrice = $_POST[$theMulti];
    128141                $_product_id = $variation_id > 0 ? $variation_id : $product_id;
    129142
    130143                $product = wc_get_product($_product_id); // The WC_Product Object
    131144                $base_price = (float) $product->get_regular_price(); // Get the product regular price
     145               
     146                echo 'post:'. $_POST[$theMulti];
     147                echo '</br>cprice:'.$cPrice;
     148                echo '</br>baseprice:'.$base_price;
    132149
    133150                $cart_item_data['custom_data']['base_price'] = $base_price;
     
    142159        return $cart_item_data;
    143160    }
     161   
     162        public function settingsPage() {
     163        if (!current_user_can('manage_options')) {
     164            wp_die(__('You do not have sufficient permissions to access this page.', 'attribute-calculator'));
     165        }
     166        wp_enqueue_script('attcalc-admin');
     167        wp_enqueue_style('attcalc-admin-style', plugins_url('/css/admin-style.css', __FILE__));
     168        $optionMetaData = $this->getOptionMetaData();
     169
     170        // Save Posted Options
     171        if ($optionMetaData != null) {
     172            foreach ($optionMetaData as $aOptionKey => $aOptionMeta) {
     173                if (isset($_POST[$aOptionKey])) {
     174                    $this->updateOption($aOptionKey, $_POST[$aOptionKey]);
     175                }
     176            }
     177        }
     178
     179        // HTML for the page
     180        $settingsGroup = get_class($this) . '-settings-group';
     181        ?>
     182        <div class="wrap">
     183            <h2><?php _e('System Settings', 'attribute-calculator'); ?></h2>
     184            <table cellspacing="1" cellpadding="2"><tbody>
     185            <tr><td><?php _e('System', 'attribute-calculator'); ?></td><td><?php echo php_uname(); ?></td></tr>
     186            <tr><td><?php _e('PHP Version', 'attribute-calculator'); ?></td>
     187                <td><?php echo phpversion(); ?>
     188                <?php
     189                if (version_compare('5.2', phpversion()) > 0) {
     190                    echo '&nbsp;&nbsp;&nbsp;<span style="background-color: #ffcc00;">';
     191                    _e('(WARNING: This plugin may not work properly with versions earlier than PHP 5.2)', 'attribute-calculator');
     192                    echo '</span>';
     193                }
     194                ?>
     195                </td>
     196            </tr>
     197            <tr><td><?php _e('MySQL Version', 'attribute-calculator'); ?></td>
     198                <td><?php echo $this->getMySqlVersion() ?>
     199                    <?php
     200                    echo '&nbsp;&nbsp;&nbsp;<span style="background-color: #ffcc00;">';
     201                    if (version_compare('5.0', $this->getMySqlVersion()) > 0) {
     202                        _e('(WARNING: This plugin may not work properly with versions earlier than MySQL 5.0)', 'attribute-calculator');
     203                    }
     204                    echo '</span>';
     205                    ?>
     206                </td>
     207            </tr>
     208            </tbody></table>
     209
     210            <h2><?php echo $this->getPluginDisplayName(); echo ' '; _e('Settings', 'attribute-calculator'); ?></h2>
     211
     212            <form method="post" action="">
     213            <?php settings_fields($settingsGroup); ?>
     214             
     215                <table class="plugin-options-table"><tbody>
     216                <?php
     217                if ($optionMetaData != null) {
     218                    foreach ($optionMetaData as $aOptionKey => $aOptionMeta) {
     219                        $displayText = is_array($aOptionMeta) ? $aOptionMeta[0] : $aOptionMeta;
     220                        ($displayText==1 || $displayText==2) ? $displayText = "Enable Globally" : null ;
     221                        ?>
     222                            <tr valign="top">
     223                                <th scope="row"><p>--<label for="<?php echo $aOptionKey ?>"><?php echo $displayText ?></label></p></th>
     224                                <td>
     225                                <?php $this->createFormControl($aOptionKey, $aOptionMeta, $this->getOption($aOptionKey)); ?>
     226                                </td>
     227                            </tr>
     228                        <?php
     229                       
     230                    }
     231                }
     232                ?>
     233                </tbody></table>
     234                <p class="submit">
     235                    <input type="submit" class="button-primary"
     236                           value="<?php _e('Save Changes', 'attribute-calculator') ?>"/>
     237                </p>
     238            </form>
     239        </div>
     240        <?php
     241
     242    }
    144243
    145244
  • attribute-calculator/trunk/attribute-calculator.php

    r2196073 r2415322  
    33   Plugin Name: Attribute Calculator
    44   Plugin URI: http://wordpress.org/extend/plugins/attribute-calculator/
    5    Version: 1.0
     5   Version: 1.2
    66   Author: Chris Butler
    77   Description: Allows you to define an attribute to multiply your product's price in WooCommerce
  • attribute-calculator/trunk/js/calculate.js

    r2196073 r2415322  
    1616           
    1717        }else{
    18             //console.log('nope');
     18            console.log('nope');
    1919            //$('table.variations').append(theVal.theError);
    2020        }
  • attribute-calculator/trunk/readme.txt

    r2196087 r2415322  
    22Contributors:UsusIpse
    33Donate link:https://ususipse.com/
    4 Tags:calculator, attribute, attribute-calculator, woocommerce, length, length-calculator, product, product-attribute-calculator, product-length-calculator
     4Tags:calculator, attribute, attribute-calculator, woocommerce, length, length-calculator, product, product-attribute-calculator, product-length-calculator, woocommerce
    55License: GPLv3
    66License URI: http://www.gnu.org/licenses/gpl-3.0.html
    77Requires at least: 3.5
    8 Tested up to: 5.2.4
    9 Stable tag: 1.0
     8Tested up to: 5.5.3
     9Requires WooCommerce at least: 2.3.6
     10Tested WooCommerce up to: 4.6.2
     11Stable tag: 1.2
    1012
    1113Multiply price by definable product attribute
     
    1315== Description ==
    1416
    15 Expands the functionality of WooCommerce to multiply product price by a definable product attribute.
     17Multiply price by definable product attribute
    1618
    1719== Installation ==
    1820
    1921After activation you will have a new submenu under Plugins. Follow that to enable and set your attribute name.
    20 Make sure you have an attribute with a number and you are good to go.
    21 This is designed to work with the attribute slug from Woo. So if you call your attribute 1 Foot, then the slug:
    22 1-foot will equal 1
    23 but
    24 1foot will return a non value, so don't mess with the slugs unless you know what you are doing
    25 
     22Make sure you have an attribute terms with a number. ex: 1 Foot, 2 Feet, 4 Feet, ect
     23This is designed to work with the attribute term's slug and will multiply by that number.
     24You then need to add this attribute to your variable products along with it's terms, click use for variations and then you can avoid making variations for products that are sold in length, ect.
    2625
    2726== Frequently Asked Questions ==
    2827
     28
     29==To Do ==
     30
     31Use attribute term description or other field to hold the multiplier.
    2932
    3033== Screenshots ==
     
    3639== Changelog ==
    3740
    38 = 0.1 = - addded front end Js function to update the price as the variations are updated. No changes are made to the actual price and theme support may vary.
     41= 1.2 = - Better use of JSON object
     42
    3943- Initial Revision
    4044= 1.0 = - Push to GitHub and Automatic
     45= 0.1 = - addded front end Js function to update the price as the variations are updated. No changes are made to the actual price and theme support may vary.
Note: See TracChangeset for help on using the changeset viewer.