Skip to content

Commit 325d139

Browse files
authored
Merge pull request #43 from pronamic/40-fatal-error-on-non-numerical-quantity
Add support for `3 stuks` product field quanity
2 parents ce10c79 + c356de0 commit 325d139

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/Processor.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use GFCommon;
1414
use Pronamic\WordPress\Number\Number;
15+
use Pronamic\WordPress\Number\Parser as NumberParser;
1516
use Pronamic\WordPress\Money\Currency;
1617
use Pronamic\WordPress\Money\Money;
1718
use Pronamic\WordPress\Pay\AbstractGatewayIntegration;
@@ -356,9 +357,24 @@ public function entry_post_save( $lead, $form ) {
356357
$line->set_unit_price( new Money( $value, $currency ) );
357358

358359
if ( array_key_exists( 'quantity', $product ) ) {
359-
$quantity = Number::from_mixed( $product['quantity'] );
360-
361-
$value = $value->multiply( $quantity );
360+
try {
361+
$parser = new NumberParser();
362+
363+
$quantity = $parser->parse( $product['quantity'] );
364+
365+
$value = $value->multiply( $quantity );
366+
} catch ( \Exception $exception ) {
367+
$exception = new \Exception(
368+
\sprintf(
369+
'Couldn’t parse Gravity Forms product field `%s` quantity to a number.',
370+
\esc_html( $key )
371+
),
372+
0,
373+
$exception
374+
);
375+
376+
throw $exception;
377+
}
362378
}
363379

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

0 commit comments

Comments
 (0)