-
Notifications
You must be signed in to change notification settings - Fork 64
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
Fix the pricing issue with woo product add-ons ext #780
base: trunk
Are you sure you want to change the base?
Conversation
Before ppec only picked up the last checked add-on in the total price calculation. Now it picks up all the checked add-ons in the final price.
This commit updates generate_cart function, replaces serialized data with FormData object. Using FormData fixes all the price related issues between PPEC and Woo Product Add-ons plugin. Tested for simple and variable products with Woo Product add-on plugin.
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.
Based on the bug report, there are 2 problems that needs to be fixed.
- Multi-option check boxes uses only the last checked option value when passed to PayPal
- File field type values not passed to PayPal
Problem 1
I've tried applying the PR and noticed that the problem with check boxes are solved. However, explicit renaming of add-on fields caused problems the other field types and values for the same are not passed to PayPal.
Steps to recreate
- Apply PR
- Add different field types to products (Short Text, Quantity, Custom Defined Price etc.) including check boxes with multiple values.
- From Single Product page, submit to PayPal and notice that only the values for check boxes along with the base product price are passed to PayPal.
Problem 2
However, the second problem related to file field type value not passed to PayPal is still not solved. I've managed to figure out from where the problem happens (Line 92).
var field_pairs = form.serializeArray();
jQuery serializeArray()
skips the file
input field and hence the values are not added to the data
array - https://api.jquery.com/serializeArray/
Revisionscb0a78e fixes both these issues:
Manual Tests
DebuggingTo debug, insert the code below on line 118:
The MagicThis fixes all the issues because each key is unique in formData: |
// Save attributes in a nested array, | ||
// so that `attributes` can be used later on when adding a variable product to cart. | ||
if ( -1 !== formParams[ i ].name.indexOf( 'attribute_' ) ) { | ||
formData.append( "attributes[" + formParams[ i ].name + "]" , formParams[ i ].value ); |
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.
We need to do this because formData
does not support nested values!
$.each( $( tag )[ 0 ].files, function( i, file ) { | ||
formData.append( tag.name, file ); | ||
} ); | ||
} ); |
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.
This helps us include the file upload field prices from Woo Product add-on in the final calculation.
Summary
Closes #606.
Before PPEC only picked up the price of the last checked add-on in the total price calculation. Now it picks up the prices of all the checked add-ons in the total price.
Steps to test:
Documentation
This doesn't need documentation. The customer does not see any change.
Tests for PPEC
Screenshot
Screenshot-1
Questions
Previously the data sent to PayPal only contained one add-on item (example:
c
) even when the checked items were more (example:b
andc
).In this PR, I have made the field name's unique, such that each checked item is included in the data sent to PayPal. Is this the correct approach?
Closes #606.