Skip to content

Commit

Permalink
Update Processor.php
Browse files Browse the repository at this point in the history
  • Loading branch information
remcotolsma committed May 28, 2024
1 parent ce10c79 commit 690e80e
Showing 1 changed file with 19 additions and 3 deletions.
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,
$e

Check failure on line 373 in src/Processor.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Undefined variable: $e
);

throw $exception;
}
}

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

0 comments on commit 690e80e

Please sign in to comment.