Skip to content

Commit

Permalink
Updates to 3.6.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Woo committed Jul 18, 2024
1 parent 9c614ae commit 3e486aa
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 21 deletions.
1 change: 0 additions & 1 deletion assets/js/gravityforms-product-addons.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ function gform_product_total(formId, total) {
} else {
return update_dynamic_price(total, formId);
}

}

function get_gravity_forms_price(formId) {
Expand Down
7 changes: 7 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
*** Gravity Forms Product Add-Ons Changelog ***
2024.06.26 - version 3.6.3
* Fix: Fix issue with reordering products with file upload fields and required fields.
* Fix: Fix issue where variable products could not be added to a Wishlist properly.
* Update: Respect the woocommerce_gforms_use_label_as_value setting for fields that do not have entry inputs.
* 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.

2024.06.04 - version 3.6.2
* Update: Update the display for checkbox type fields (regular and product options) to display better in checkout blocks.
* Internal: Update package dependencies and include a version check script.

2024.05.24 - version 3.6.1
* Fix: Fix issue with the mutation observer causing an infinate loop on some sites where gform is not available.
Expand Down
19 changes: 17 additions & 2 deletions gravityforms-product-addons-main.php
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,10 @@ public function get_gravity_form_reorder_data( int $post_id, array $working_data
}
}

$working_data['reorder_processing'] = $current_data['reorder_processing'] ?? 'revalidate';

// Return the data, filtered.
return apply_filters( 'woocommerce_gforms_get_product_reorder_form_data', $working_data, $post_id );
return apply_filters( 'woocommerce_gforms_get_product_reorder_form_data', $working_data, $current_data, $post_id );
}

public function has_gravity_form( int $product_id ): bool {
Expand Down Expand Up @@ -595,7 +597,7 @@ public function get_gravity_form_data( $post_id, $context = 'single' ) {
$data = wp_parse_args(
$data,
array(
'reorder_processing' => 'resubmit', // 'resubmit', 'revalidate', 'none'
'reorder_processing' => 'revalidate', // 'resubmit', 'revalidate', 'none'
'reorder_hydrate_defaults' => 'yes',
'use_ajax' => 'no',
'is_ajax' => false,
Expand Down Expand Up @@ -640,6 +642,19 @@ public function get_form_field_hash( int $form_id ): string {
// Loading main form object (supports serialized strings as well as JSON strings)
$form = GFFormsModel::unserialize( rgar( $form_row, 'display_meta' ) );
$fields = $form['fields'] = is_array( rgar( $form, 'fields' ) ) ? array_values( $form['fields'] ) : array();

// Remove any properties from the fields that are not simple values.
$fields = array_map(function($field) {
return array_filter($field, function($value) {
return !is_array($value) && !is_object($value);
});
}, $fields);

// Remove the fields that are not visible.
$fields = array_filter( $fields, function ( $field ) {
return ! rgar( $field, 'adminOnly' );
} );

$hash = md5( wp_json_encode( $fields ) );
}

Expand Down
4 changes: 2 additions & 2 deletions gravityforms-product-addons.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: WooCommerce Gravity Forms Product Add-Ons
* Plugin URI: http://woothemes.com/products/gravity-forms-add-ons/
* Description: Allows you to use Gravity Forms on individual WooCommerce products. Requires the Gravity Forms plugin to work.
* Version: 3.6.2
* Version: 3.6.3
* Author: Element Stark
* Author URI: https://www.elementstark.com/
* Developer: Lucas Stark
Expand All @@ -17,7 +17,7 @@
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
* WC requires at least: 7.0
* WC tested up to: 8.9
* WC tested up to: 9.0
* Woo: 18633:a6ac0ab1a1536e3a357ccf24c0650ed0
*
* @package WooCommerce Gravity Forms Product Add-Ons
Expand Down
8 changes: 4 additions & 4 deletions i18n/languages/woocommerce-gravityforms-product-addons.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# This file is distributed under the GNU General Public License v3.0.
msgid ""
msgstr ""
"Project-Id-Version: WooCommerce Gravity Forms Product Add-Ons 3.6.2\n"
"Project-Id-Version: WooCommerce Gravity Forms Product Add-Ons 3.6.3\n"
"Report-Msgid-Bugs-To: "
"https://wordpress.org/support/plugin/woocommerce-gravityforms-product-"
"addons\n"
"POT-Creation-Date: 2024-06-04 09:41:15+00:00\n"
"POT-Creation-Date: 2024-07-17 12:25:38+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down Expand Up @@ -556,8 +556,8 @@ msgstr ""
msgid "Overwrite the price(s) completely"
msgstr ""

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

Expand Down
2 changes: 1 addition & 1 deletion inc/gravityforms-product-addons-cart-validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function check_cart_items() {
// The _gravity_form_hash is set in the WC_GFPA_Product_Addons::add_cart_item_data() method.
$cart_item_form_field_hash = $cart_item['_gravity_form_hash'];

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

// Use the submission helper to revalidate the data.
Expand Down
65 changes: 58 additions & 7 deletions inc/gravityforms-product-addons-cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static function instance() {
private function __construct() {
// Filters for cart actions

add_filter( 'woocommerce_cart_id', array( $this, 'cart_id' ), 10, 5 );
add_filter( 'woocommerce_add_cart_item_data', array( $this, 'add_cart_item_data' ), 10, 3 );
add_filter( 'woocommerce_get_cart_item_from_session', array( $this, 'get_cart_item_from_session' ), 10, 2 );
add_filter( 'woocommerce_get_item_data', array( $this, 'get_item_data' ), 10, 2 );
Expand All @@ -47,6 +48,57 @@ private function __construct() {
);
}

/**
* Remove fields that cause the cart item key to be different even though the actual submitted data is the same.
* This is necessary because the cart item key is used to determine if the item is already in the cart.
*/
public function cart_id( $cart_id, $product_id, $variation_id, $variation, $cart_item_data ): string {

if ( isset( $cart_item_data['_gravity_form_data'] ) ) {
unset( $cart_item_data['_gravity_form_data'] );
}

if ( isset( $cart_item_data['_gravity_form_lead'] ) ) {
unset( $cart_item_data['_gravity_form_lead']['id'] );
unset( $cart_item_data['_gravity_form_lead']['source_url'] );
unset( $cart_item_data['_gravity_form_lead']['ip'] );
unset( $cart_item_data['_gravity_form_lead']['original_lead_id'] );
}

if ( isset( $cart_item_data['_gravity_form_hash'] ) ) {
unset( $cart_item_data['_gravity_form_hash'] );
}

$id_parts = array( $product_id );

if ( $variation_id && 0 !== $variation_id ) {
$id_parts[] = $variation_id;
}

if ( is_array( $variation ) && ! empty( $variation ) ) {
$variation_key = '';
foreach ( $variation as $key => $value ) {
$variation_key .= trim( $key ) . trim( $value );
}
$id_parts[] = $variation_key;
}

if ( is_array( $cart_item_data ) && ! empty( $cart_item_data ) ) {
$cart_item_data_key = '';
foreach ( $cart_item_data as $key => $value ) {
if ( is_array( $value ) || is_object( $value ) ) {
$value = http_build_query( $value );
}
$cart_item_data_key .= trim( $key ) . trim( $value );

}
$id_parts[] = $cart_item_data_key;
}

$cart_id = md5( implode( '_', $id_parts ) );
return $cart_id;
}

/**
* Performs the validation of the gravity form.
* Processes the form and saves the lead for later use during the cart_item_data filter.
Expand Down Expand Up @@ -473,12 +525,12 @@ public function get_item_data( $other_data, $cart_item ) {
// Controls the use_text option for the field
$use_label_as_value = apply_filters( 'woocommerce_gforms_use_label_as_value', true, $value, $field, $lead, $form_meta );

$display_value = GFCommon::get_lead_field_display( $field, $value, $currency, $use_label_as_value );
$price_adjustment = false;
$display_value = GFCommon::get_lead_field_display( $field, $value, $currency, false );
$display_value = apply_filters( 'gform_entry_field_value', $display_value, $field, $lead, $form_meta );

$display_text = GFCommon::get_lead_field_display( $field, $value, $currency, );
$display_text = GFCommon::get_lead_field_display( $field, $value, $currency, $use_label_as_value );
$display_text = apply_filters( 'woocommerce_gforms_field_display_text', $display_text, $display_value, $field, $lead, $form_meta );
$display_text = apply_filters( 'woocommerce_gforms_field_display_text_' . $field_id, $display_text, $display_value, $field, $lead, $form_meta );

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

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


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

$cart_item_data = apply_filters(
'woocommerce_gforms_get_item_data',
[
array(
'name' => $field_wrapper_prefix . $input_label,
'display' => $input_value_for_cart,
'value' => $input_value,
'hidden' => $field_wrapper_hidden,
],
),
$field,
$lead,
$form_meta
Expand Down
4 changes: 2 additions & 2 deletions inc/gravityforms-product-addons-reorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function on_get_order_again_cart_item_data( array $data, WC_Order_Item $i
$data['_gravity_form_data'] = $gravity_form_data;
$data['_gravity_form_hash'] = $form_fields_hash;

if ( $reorder_processing_type == 'resubmit' ) {
if ( $reorder_processing_type === 'resubmit' ) {

try {
// Disable notifications, confirmations and other processing.
Expand Down Expand Up @@ -196,7 +196,7 @@ public function on_get_order_again_cart_item_data( array $data, WC_Order_Item $i
$entry = $previous_entry_data;
}

} else if ( $reorder_processing_type == 'revalidate' ) {
} else if ( $reorder_processing_type === 'revalidate' ) {

try {
// Revalidate the entry to get make sure it is still valid.
Expand Down
5 changes: 3 additions & 2 deletions inc/gravityforms-product-addons-submission-helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public static function revalidate_entry( $form_id, $entry_data ) {

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

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

Expand Down

0 comments on commit 3e486aa

Please sign in to comment.