Skip to content

Improved handling of posted field values for clones#564

Merged
Soare-Robert-Daniel merged 2 commits intodevelopmentfrom
bugfix/pro/504
Apr 14, 2026
Merged

Improved handling of posted field values for clones#564
Soare-Robert-Daniel merged 2 commits intodevelopmentfrom
bugfix/pro/504

Conversation

@girishpanchal30
Copy link
Copy Markdown
Contributor

Summary

Checked the value for all the clone fields to validate them while adding the product to the cart.

Check before Pull Request is ready:

Closes https://github.com/Codeinwp/ppom-pro/issues/504

@girishpanchal30 girishpanchal30 requested a review from Copilot April 6, 2026 12:56
@girishpanchal30 girishpanchal30 added the pr-checklist-skip Allow this Pull Request to skip checklist. label Apr 6, 2026
@pirate-bot pirate-bot added the pr-checklist-complete The Pull Request checklist is complete. (automatic label) label Apr 6, 2026
@pirate-bot
Copy link
Copy Markdown
Contributor

pirate-bot commented Apr 6, 2026

Plugin build for 9a3a75b is ready 🛎️!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates server-side validation to better account for repeated (“cloned”) field instances when adding products to the cart, addressing issue #504.

Changes:

  • Update ppom_has_posted_field_value() to evaluate posted values across cloned field instances rather than stopping at the first match.
  • Align clone key parsing in max/min checked validation by switching the split token to __clone_.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread inc/functions.php Outdated
Comment thread inc/functions.php
Comment on lines +980 to 1016
// Every instance (the original field AND every clone) must have a value.
$has_value = true;
foreach ( $matching_keys as $instance_value ) {

if ( $quantity > 0 ) {
$has_value = true;
}
$instance_has_value = false;

break;

case 'fonts':
if ( isset( $value['font'] ) && $value['font'] != '' ) {
$has_value = true;
}
switch ( $type ) {

break;
case 'quantities':
$quantity = 0;
foreach ( (array) $instance_value as $qty ) {
$quantity += intval( $qty );
}
if ( $quantity > 0 ) {
$instance_has_value = true;
}
break;

default:
if ( $value != '' ) {
$has_value = true;
}
break;
case 'fonts':
if ( isset( $instance_value['font'] ) && '' !== $instance_value['font'] ) {
$instance_has_value = true;
}
break;

default:
if ( '' !== $instance_value ) {
$instance_has_value = true;
}
break;

}

if ( $has_value ) {
break;
}
}
if ( ! $instance_has_value ) {
$has_value = false;
break;
}
}
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change alters required-field validation semantics for cloned fields (now requiring all instances to have values). Given validation is a core path, please add/update PHPUnit coverage for ppom_has_posted_field_value() with at least one cloned-field case (including a failing clone instance) to prevent regressions.

Copilot uses AI. Check for mistakes.
@Soare-Robert-Daniel Soare-Robert-Daniel merged commit 5639e36 into development Apr 14, 2026
9 checks passed
@Soare-Robert-Daniel Soare-Robert-Daniel deleted the bugfix/pro/504 branch April 14, 2026 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-checklist-complete The Pull Request checklist is complete. (automatic label) pr-checklist-skip Allow this Pull Request to skip checklist.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants