-
Notifications
You must be signed in to change notification settings - Fork 91
gpi-waiting-list.php
: Added waiting list message on order summary page.
#1117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -66,6 +66,8 @@ public function add_hooks() { | |||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
// Allow negative stock to be used for conditional logic validation. | ||||||||||||||||||||||||||||||||||||||||||||
add_filter( 'gpi_allow_negative_stock', array( $this, 'allow_negative_stock_for_conditional_logic' ), 10, 3 ); | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
add_filter( 'gform_order_summary', array( $this, 'add_waiting_list_to_order_summary' ), 11, 3 ); | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
public function is_applicable_form( $form ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
@@ -270,6 +272,39 @@ public function allow_negative_stock_for_conditional_logic( $allow_negative_stoc | |||||||||||||||||||||||||||||||||||||||||||
return true; | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
public function add_waiting_list_to_order_summary( $markup, $form, $entry ) { | ||||||||||||||||||||||||||||||||||||||||||||
if ( empty( $entry ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
return $markup; | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
$products = GFCommon::get_product_fields( $form, $entry ); | ||||||||||||||||||||||||||||||||||||||||||||
if ( empty( $products['products'] ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
return $markup; | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
libxml_use_internal_errors( true ); | ||||||||||||||||||||||||||||||||||||||||||||
$dom = new DOMDocument(); | ||||||||||||||||||||||||||||||||||||||||||||
$dom->loadHTML( mb_convert_encoding( $markup, 'HTML-ENTITIES', 'UTF-8' ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
$xpath = new DOMXPath( $dom ); | ||||||||||||||||||||||||||||||||||||||||||||
$productNodes = $xpath->query( "//div[contains(@class, 'product_name')]" ); | ||||||||||||||||||||||||||||||||||||||||||||
foreach ( $productNodes as $node ) { | ||||||||||||||||||||||||||||||||||||||||||||
foreach ( $products['products'] as $product_id => $product ) { | ||||||||||||||||||||||||||||||||||||||||||||
if ( $product['name'] == $node->nodeValue ) { | ||||||||||||||||||||||||||||||||||||||||||||
$field = GFAPI::get_field( $form, $product_id ); | ||||||||||||||||||||||||||||||||||||||||||||
$gpi_instance = gp_inventory_type_simple()::$type === rgar( $field, 'gpiInventory' ) ? gp_inventory_type_simple() : gp_inventory_type_advanced(); | ||||||||||||||||||||||||||||||||||||||||||||
$available = (int) $gpi_instance->get_available_stock( $field ); | ||||||||||||||||||||||||||||||||||||||||||||
if ( $available <= 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||
$node->nodeValue .= $this->waitlist_message; | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+294
to
+299
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add validation for inventory field compatibility. The code assumes the field is an inventory field but doesn't validate this before calling inventory methods, which could cause errors. $field = GFAPI::get_field( $form, $product_id );
+
+// Validate that this is an inventory field
+if ( ! gp_inventory_type_simple()->is_applicable_field( $field ) &&
+ ! gp_inventory_type_advanced()->is_applicable_field( $field ) ) {
+ continue;
+}
+
$gpi_instance = gp_inventory_type_simple()::$type === rgar( $field, 'gpiInventory' ) ? gp_inventory_type_simple() : gp_inventory_type_advanced(); 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||
break; | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
$markup = $dom->saveHTML(); | ||||||||||||||||||||||||||||||||||||||||||||
return $markup; | ||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+305
to
+306
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Preserve original markup structure when returning modified HTML. The -$markup = $dom->saveHTML();
-return $markup;
+// Get only the body content to preserve original structure
+$body = $dom->getElementsByTagName( 'body' )->item( 0 );
+if ( $body ) {
+ $markup = '';
+ foreach ( $body->childNodes as $child ) {
+ $markup .= $dom->saveHTML( $child );
+ }
+} else {
+ $markup = $dom->saveHTML();
+}
+return $markup; 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
new GPI_Waiting_List(); | ||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Handle DOM parsing errors and consider markup preservation.
The DOMDocument parsing could fail or alter the original markup structure. Consider adding error handling and preserving the original markup format.
📝 Committable suggestion
🤖 Prompt for AI Agents