Skip to content

Commit 3e486aa

Browse files
author
Woo
committed
Updates to 3.6.3
1 parent 9c614ae commit 3e486aa

9 files changed

+94
-21
lines changed

assets/js/gravityforms-product-addons.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ function gform_product_total(formId, total) {
88
} else {
99
return update_dynamic_price(total, formId);
1010
}
11-
1211
}
1312

1413
function get_gravity_forms_price(formId) {

changelog.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
*** Gravity Forms Product Add-Ons Changelog ***
2+
2024.06.26 - version 3.6.3
3+
* Fix: Fix issue with reordering products with file upload fields and required fields.
4+
* Fix: Fix issue where variable products could not be added to a Wishlist properly.
5+
* Update: Respect the woocommerce_gforms_use_label_as_value setting for fields that do not have entry inputs.
6+
* Update: Better handling for Limit purchases to 1 item per order. Filter the cart_id to remove data that changes or could change between form submissions, but is not related to the actual data of the form.
7+
28
2024.06.04 - version 3.6.2
39
* Update: Update the display for checkbox type fields (regular and product options) to display better in checkout blocks.
10+
* Internal: Update package dependencies and include a version check script.
411

512
2024.05.24 - version 3.6.1
613
* Fix: Fix issue with the mutation observer causing an infinate loop on some sites where gform is not available.

gravityforms-product-addons-main.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,10 @@ public function get_gravity_form_reorder_data( int $post_id, array $working_data
556556
}
557557
}
558558

559+
$working_data['reorder_processing'] = $current_data['reorder_processing'] ?? 'revalidate';
560+
559561
// Return the data, filtered.
560-
return apply_filters( 'woocommerce_gforms_get_product_reorder_form_data', $working_data, $post_id );
562+
return apply_filters( 'woocommerce_gforms_get_product_reorder_form_data', $working_data, $current_data, $post_id );
561563
}
562564

563565
public function has_gravity_form( int $product_id ): bool {
@@ -595,7 +597,7 @@ public function get_gravity_form_data( $post_id, $context = 'single' ) {
595597
$data = wp_parse_args(
596598
$data,
597599
array(
598-
'reorder_processing' => 'resubmit', // 'resubmit', 'revalidate', 'none'
600+
'reorder_processing' => 'revalidate', // 'resubmit', 'revalidate', 'none'
599601
'reorder_hydrate_defaults' => 'yes',
600602
'use_ajax' => 'no',
601603
'is_ajax' => false,
@@ -640,6 +642,19 @@ public function get_form_field_hash( int $form_id ): string {
640642
// Loading main form object (supports serialized strings as well as JSON strings)
641643
$form = GFFormsModel::unserialize( rgar( $form_row, 'display_meta' ) );
642644
$fields = $form['fields'] = is_array( rgar( $form, 'fields' ) ) ? array_values( $form['fields'] ) : array();
645+
646+
// Remove any properties from the fields that are not simple values.
647+
$fields = array_map(function($field) {
648+
return array_filter($field, function($value) {
649+
return !is_array($value) && !is_object($value);
650+
});
651+
}, $fields);
652+
653+
// Remove the fields that are not visible.
654+
$fields = array_filter( $fields, function ( $field ) {
655+
return ! rgar( $field, 'adminOnly' );
656+
} );
657+
643658
$hash = md5( wp_json_encode( $fields ) );
644659
}
645660

gravityforms-product-addons.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: WooCommerce Gravity Forms Product Add-Ons
44
* Plugin URI: http://woothemes.com/products/gravity-forms-add-ons/
55
* Description: Allows you to use Gravity Forms on individual WooCommerce products. Requires the Gravity Forms plugin to work.
6-
* Version: 3.6.2
6+
* Version: 3.6.3
77
* Author: Element Stark
88
* Author URI: https://www.elementstark.com/
99
* Developer: Lucas Stark
@@ -17,7 +17,7 @@
1717
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
1818
1919
* WC requires at least: 7.0
20-
* WC tested up to: 8.9
20+
* WC tested up to: 9.0
2121
* Woo: 18633:a6ac0ab1a1536e3a357ccf24c0650ed0
2222
*
2323
* @package WooCommerce Gravity Forms Product Add-Ons

i18n/languages/woocommerce-gravityforms-product-addons.pot

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
# This file is distributed under the GNU General Public License v3.0.
33
msgid ""
44
msgstr ""
5-
"Project-Id-Version: WooCommerce Gravity Forms Product Add-Ons 3.6.2\n"
5+
"Project-Id-Version: WooCommerce Gravity Forms Product Add-Ons 3.6.3\n"
66
"Report-Msgid-Bugs-To: "
77
"https://wordpress.org/support/plugin/woocommerce-gravityforms-product-"
88
"addons\n"
9-
"POT-Creation-Date: 2024-06-04 09:41:15+00:00\n"
9+
"POT-Creation-Date: 2024-07-17 12:25:38+00:00\n"
1010
"MIME-Version: 1.0\n"
1111
"Content-Type: text/plain; charset=utf-8\n"
1212
"Content-Transfer-Encoding: 8bit\n"
@@ -556,8 +556,8 @@ msgstr ""
556556
msgid "Overwrite the price(s) completely"
557557
msgstr ""
558558

559-
#: dist/woocommerce-gravityforms-product-addons/gravityforms-product-addons-main.php:590
560-
#: gravityforms-product-addons-main.php:590
559+
#: dist/woocommerce-gravityforms-product-addons/gravityforms-product-addons-main.php:592
560+
#: gravityforms-product-addons-main.php:592
561561
msgid "There was a problem with your submission. Please review the fields below."
562562
msgstr ""
563563

inc/gravityforms-product-addons-cart-validation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function check_cart_items() {
5454
// The _gravity_form_hash is set in the WC_GFPA_Product_Addons::add_cart_item_data() method.
5555
$cart_item_form_field_hash = $cart_item['_gravity_form_hash'];
5656

57-
if ( $form_fields_hash !== $cart_item_form_field_hash ) {
57+
if ($cart_item_form_field_hash && $form_fields_hash !== $cart_item_form_field_hash ) {
5858
GFCommon::log_debug( __METHOD__ . '(): Form fields have changed for product ' . $cart_item['product_id'] . '. Revalidating.' );
5959

6060
// Use the submission helper to revalidate the data.

inc/gravityforms-product-addons-cart.php

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public static function instance() {
2727
private function __construct() {
2828
// Filters for cart actions
2929

30+
add_filter( 'woocommerce_cart_id', array( $this, 'cart_id' ), 10, 5 );
3031
add_filter( 'woocommerce_add_cart_item_data', array( $this, 'add_cart_item_data' ), 10, 3 );
3132
add_filter( 'woocommerce_get_cart_item_from_session', array( $this, 'get_cart_item_from_session' ), 10, 2 );
3233
add_filter( 'woocommerce_get_item_data', array( $this, 'get_item_data' ), 10, 2 );
@@ -47,6 +48,57 @@ private function __construct() {
4748
);
4849
}
4950

51+
/**
52+
* Remove fields that cause the cart item key to be different even though the actual submitted data is the same.
53+
* This is necessary because the cart item key is used to determine if the item is already in the cart.
54+
*/
55+
public function cart_id( $cart_id, $product_id, $variation_id, $variation, $cart_item_data ): string {
56+
57+
if ( isset( $cart_item_data['_gravity_form_data'] ) ) {
58+
unset( $cart_item_data['_gravity_form_data'] );
59+
}
60+
61+
if ( isset( $cart_item_data['_gravity_form_lead'] ) ) {
62+
unset( $cart_item_data['_gravity_form_lead']['id'] );
63+
unset( $cart_item_data['_gravity_form_lead']['source_url'] );
64+
unset( $cart_item_data['_gravity_form_lead']['ip'] );
65+
unset( $cart_item_data['_gravity_form_lead']['original_lead_id'] );
66+
}
67+
68+
if ( isset( $cart_item_data['_gravity_form_hash'] ) ) {
69+
unset( $cart_item_data['_gravity_form_hash'] );
70+
}
71+
72+
$id_parts = array( $product_id );
73+
74+
if ( $variation_id && 0 !== $variation_id ) {
75+
$id_parts[] = $variation_id;
76+
}
77+
78+
if ( is_array( $variation ) && ! empty( $variation ) ) {
79+
$variation_key = '';
80+
foreach ( $variation as $key => $value ) {
81+
$variation_key .= trim( $key ) . trim( $value );
82+
}
83+
$id_parts[] = $variation_key;
84+
}
85+
86+
if ( is_array( $cart_item_data ) && ! empty( $cart_item_data ) ) {
87+
$cart_item_data_key = '';
88+
foreach ( $cart_item_data as $key => $value ) {
89+
if ( is_array( $value ) || is_object( $value ) ) {
90+
$value = http_build_query( $value );
91+
}
92+
$cart_item_data_key .= trim( $key ) . trim( $value );
93+
94+
}
95+
$id_parts[] = $cart_item_data_key;
96+
}
97+
98+
$cart_id = md5( implode( '_', $id_parts ) );
99+
return $cart_id;
100+
}
101+
50102
/**
51103
* Performs the validation of the gravity form.
52104
* Processes the form and saves the lead for later use during the cart_item_data filter.
@@ -473,12 +525,12 @@ public function get_item_data( $other_data, $cart_item ) {
473525
// Controls the use_text option for the field
474526
$use_label_as_value = apply_filters( 'woocommerce_gforms_use_label_as_value', true, $value, $field, $lead, $form_meta );
475527

476-
$display_value = GFCommon::get_lead_field_display( $field, $value, $currency, $use_label_as_value );
477-
$price_adjustment = false;
528+
$display_value = GFCommon::get_lead_field_display( $field, $value, $currency, false );
478529
$display_value = apply_filters( 'gform_entry_field_value', $display_value, $field, $lead, $form_meta );
479530

480-
$display_text = GFCommon::get_lead_field_display( $field, $value, $currency, );
531+
$display_text = GFCommon::get_lead_field_display( $field, $value, $currency, $use_label_as_value );
481532
$display_text = apply_filters( 'woocommerce_gforms_field_display_text', $display_text, $display_value, $field, $lead, $form_meta );
533+
$display_text = apply_filters( 'woocommerce_gforms_field_display_text_' . $field_id, $display_text, $display_value, $field, $lead, $form_meta );
482534

483535
if ( $field['type'] == 'product' ) {
484536
$prefix = '';
@@ -540,12 +592,11 @@ public function get_item_data( $other_data, $cart_item ) {
540592
} else {
541593

542594
$_a_value = RGFormsModel::get_lead_field_value( $lead, $field );
543-
$_a_display_value = $field->get_value_entry_detail( $_a_value, $currency, $use_label_as_value, 'text');
595+
$_a_display_value = $field->get_value_entry_detail( $_a_value, $currency, $use_label_as_value, 'text' );
544596
if ( ( is_string( $_a_value ) && rgblank( $_a_value ) ) || ( is_array( $_a_value ) && empty( $_a_value ) ) || ( $_a_value === '[]' ) ) {
545597
continue;
546598
}
547599

548-
549600
$value = RGFormsModel::get_lead_field_value( $lead, $field );
550601
$display_value = $field->get_value_entry_detail( $value );
551602
if ( ( is_string( $value ) && rgblank( $value ) ) || ( is_array( $value ) && empty( $value ) ) || ( $value === '[]' ) ) {
@@ -606,12 +657,12 @@ function ( $value ) {
606657

607658
$cart_item_data = apply_filters(
608659
'woocommerce_gforms_get_item_data',
609-
[
660+
array(
610661
'name' => $field_wrapper_prefix . $input_label,
611662
'display' => $input_value_for_cart,
612663
'value' => $input_value,
613664
'hidden' => $field_wrapper_hidden,
614-
],
665+
),
615666
$field,
616667
$lead,
617668
$form_meta

inc/gravityforms-product-addons-reorder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function on_get_order_again_cart_item_data( array $data, WC_Order_Item $i
163163
$data['_gravity_form_data'] = $gravity_form_data;
164164
$data['_gravity_form_hash'] = $form_fields_hash;
165165

166-
if ( $reorder_processing_type == 'resubmit' ) {
166+
if ( $reorder_processing_type === 'resubmit' ) {
167167

168168
try {
169169
// Disable notifications, confirmations and other processing.
@@ -196,7 +196,7 @@ public function on_get_order_again_cart_item_data( array $data, WC_Order_Item $i
196196
$entry = $previous_entry_data;
197197
}
198198

199-
} else if ( $reorder_processing_type == 'revalidate' ) {
199+
} else if ( $reorder_processing_type === 'revalidate' ) {
200200

201201
try {
202202
// Revalidate the entry to get make sure it is still valid.

inc/gravityforms-product-addons-submission-helpers.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public static function revalidate_entry( $form_id, $entry_data ) {
2323

2424
//Find any upload fields in the form.
2525
$upload_fields = array_filter( $form['fields'], function ( $field ) {
26-
return $field->type === 'fileupload';
26+
// $field->type === 'fileupload';
27+
//TODO: See if we can enable file uploads for revalidation. It's not working as of 3.6.2
2728
} );
2829

2930
//If there are any upload_fields, hydrate the globals. This is necessary for the file upload field to work and validate properly.
@@ -136,7 +137,7 @@ public static function ignore_field_validation_rules( $result, $value, $form, $f
136137
'signature',
137138
'creditcard',
138139
'password',
139-
// 'fileupload',
140+
'fileupload',
140141
'captcha',
141142
] );
142143

0 commit comments

Comments
 (0)