Skip to content

Commit

Permalink
Merge pull request #15 from piatkowski/dev
Browse files Browse the repository at this point in the history
Bug fixes
  • Loading branch information
piatkowski authored Jul 23, 2022
2 parents b4f41a1 + 8ee0dbd commit b07e635
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 11 deletions.
12 changes: 9 additions & 3 deletions assets/js/wckalkulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
var _form = wck_ajax_object.form;

var shouldCalculatePrice = wck_ajax_object._wck_has_expression === "1";
console.log(shouldCalculatePrice);
var CV = {};

if (wck_ajax_object.hasOwnProperty("_wck_visibility_rules") && wck_ajax_object._wck_visibility_rules !== null) {
Expand Down Expand Up @@ -36,13 +35,20 @@
});
}

function getFieldValue(field) {
if (field.prop("type") === "checkbox" || field.prop("type") === "radio") {
return field.is(":checked") ? field.val() : "";
}
return field.val();
}

function toggleField(fieldName, rules) {
var state = null;
$.each(rules, function (i, or_rule) {
$.each(or_rule, function (j, and_rule) {
var field = $("#wck_" + and_rule.field);
if(field.length) {
state = compare(field.val(), and_rule.comp, and_rule.value);
if (field.length) {
state = compare(getFieldValue(field), and_rule.comp, and_rule.value);
}
return state !== false;
});
Expand Down
2 changes: 1 addition & 1 deletion assets/js/wckalkulator.min.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Tags: woocommerce custom fields, woocommerce product price, woocommerce product fields, woocommerce custom price field, woocommerce personalized product, woocommerce custom product fields, product fields, custom product price, price calculation, price formula
Requires at least: 5.0
Tested up to: 6.0.1
Stable tag: 1.4.3
Stable tag: 1.4.4
Requires PHP: 5.6
License: GNU GPLv2
Donate link: https://www.paypal.com/donate/?hosted_button_id=5DNZK72H5YCBY
Expand Down Expand Up @@ -141,6 +141,9 @@ The customer can edit product options after adding to cart.
Full documentation at: [www.wckalkulator.com](https://wckalkulator.com)

== Changelog ==
2022-07-23 v.1.4.4
- bug fixes

2022-07-23 v.1.4.3
- bug fixes

Expand Down
3 changes: 3 additions & 0 deletions src/Fields/NumberField.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public function render_for_cart($value = '')
*/
public function validate($value)
{
if (!$this->is_required() && empty($value)) {
return true;
}
$is_greater_than_min = $value >= $this->data["min"];
$is_less_than_max = $value <= $this->data["max"];
$is_numeric = is_numeric($value);
Expand Down
4 changes: 4 additions & 0 deletions src/Fields/SelectField.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public function get_option_title($value)
*/
public function validate($value)
{
if (!$this->is_required() && empty($value)) {
return true;
}

return in_array($value, $this->data["options_name"]);
}

Expand Down
6 changes: 5 additions & 1 deletion views/admin/fields_editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@
</div>


<ul id="f-field-list"></ul>
<ul id="f-field-list">
<li class="welcome">
<?php _e('Add your first field. Select the field type from the dropdown list on the toolbar and click "Add field".', 'wc-kalkulator'); ?>
</li>
</ul>
<div class="clearfix"></div>
<input type="hidden" name="_wck_fieldset" value="">

17 changes: 14 additions & 3 deletions views/fields/admin/number.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,33 @@
use WCKalkulator\Helper;

?>
<div class="third first">
<div class="half first">
<label>* <?php _e('Min. value', 'wc-kalkulator'); ?>
<?php echo Helper::html_help_tip(__('The minimum value of the field.', 'wc-kalkulator')); ?>
</label>
<input type="number" class="param fn-min-value" step="any" required>
</div>
<div class="third">
<div class="half second">
<label>* <?php _e('Max. value', 'wc-kalkulator'); ?>
<?php echo Helper::html_help_tip(__('The maximum value of the field.', 'wc-kalkulator')); ?>
</label>
<input type="number" class="param fn-max-value" step="any" required>
</div>
<div class="third last">
<div class="clear"></div>
<div class="half first">
<label><?php _e('Default value', 'wc-kalkulator'); ?>
<?php echo Helper::html_help_tip(__('The default value of the field.', 'wc-kalkulator')); ?>
</label>
<input type="number" name="default_value_{id}" step="any" class="param f-default-value">
</div>
<div class="half second">
<label>
<?php _e('Is this field required?', 'wc-kalkulator'); ?>
</label>
<select class="param f-required">
<option value="off"><?php _e('No'); ?></option>
<option value="on"><?php _e('Yes'); ?></option>
</select>
</div>

<div class="clear"></div>
8 changes: 8 additions & 0 deletions views/fields/admin/select.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
}
use WCKalkulator\Helper;
?>
<label>
<?php _e('Is this field required?', 'wc-kalkulator'); ?>
</label>
<select class="param f-required">
<option value="off"><?php _e('No'); ?></option>
<option value="on"><?php _e('Yes'); ?></option>
</select>

<label>* <?php _e('Option Items', 'wc-kalkulator'); ?></label>
<div class="pairs fs-options">
<div class="pair fs-option">
Expand Down
4 changes: 2 additions & 2 deletions wc-kalkulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Plugin Name: WC Kalkulator
* Description: Description: Store Manager can add fieldsets to Products and Orders. WC Kalkulator allows to order and calculate the price of the product based on the values of the fields selected by the Customer.
* Version: 1.4.3
* Version: 1.4.4
* Author: Krzysztof Piątkowski
* Author URI: https://wckalkulator.com
* Text Domain: wc-kalkulator
Expand Down Expand Up @@ -31,7 +31,7 @@
*/
class Plugin
{
const VERSION = "1.4.3";
const VERSION = "1.4.4";

const NAME = "wc-kalkulator";

Expand Down

0 comments on commit b07e635

Please sign in to comment.