Skip to content
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

Add support for 3 stuks product field quanity #43

Merged
merged 2 commits into from
May 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use GFCommon;
use Pronamic\WordPress\Number\Number;
use Pronamic\WordPress\Number\Parser as NumberParser;
use Pronamic\WordPress\Money\Currency;
use Pronamic\WordPress\Money\Money;
use Pronamic\WordPress\Pay\AbstractGatewayIntegration;
Expand Down Expand Up @@ -356,9 +357,24 @@ public function entry_post_save( $lead, $form ) {
$line->set_unit_price( new Money( $value, $currency ) );

if ( array_key_exists( 'quantity', $product ) ) {
$quantity = Number::from_mixed( $product['quantity'] );

$value = $value->multiply( $quantity );
try {
$parser = new NumberParser();

$quantity = $parser->parse( $product['quantity'] );

$value = $value->multiply( $quantity );
} catch ( \Exception $exception ) {
$exception = new \Exception(
\sprintf(
'Couldn’t parse Gravity Forms product field `%s` quantity to a number.',
\esc_html( $key )
),
0,
$exception
);

throw $exception;
}
}

$line->set_total_amount( new Money( $value, $currency ) );
Expand Down