TypeError: Argument 1 passed to Drupal\commerce_price\Calculator::multiply() must be of the type string, null given, called in /var/www/draft/drupal/modules/contrib/commerce_klarna_checkout/src/KlarnaManager.php on line 300 in Drupal\commerce_price\Calculator::multiply() (line 72 of modules/contrib/commerce/modules/price/src/Calculator.php).

Comments

ozin created an issue. See original summary.

ozin’s picture

Status: Needs work » Needs review
StatusFileSize
new670 bytes
jsacksick’s picture

Why do you have a NULL tax rate in the first place?

jsacksick’s picture

Did you define a custom tax type plugin? cause the LocalTaxTypeBase has this code:

        $order_item->addAdjustment(new Adjustment([
          'type' => 'tax',
          'label' => $zone->getDisplayLabel(),
          'amount' => $tax_amount,
          'percentage' => $percentage->getNumber(),
          'source_id' => $this->parentEntity->id() . '|' . $zone->getId() . '|' . $rate->getId(),
          'included' => $this->isDisplayInclusive(),
        ]));

Are you using the Avatax module by any chance? We should fix this, I realized we're not setting the "percentage" when adding the adjustment:

      $item->addAdjustment(new Adjustment([
        'type' => 'tax',
        'label' => $adjustments[$item->uuid()]['label'],
        'amount' => new Price((string) $adjustments[$item->uuid()]['amount'], $currency_code),
        'source_id' => $this->pluginId . '|' . $this->entityId,
      ]));
ozin’s picture

Hi

No, I do not use Avatax module. Probably I miss somewhere `percentage` when creating Tax, or maybe when it is should be Zero percent it set NULL, not sure. I will debug my case and back with more details.

ozin’s picture

StatusFileSize
new676 bytes

Updated patch according to lates changes

jsacksick’s picture

Shouldn't we try calculating the percentage? Klarna doesn't complain about a "0" tax rate? Is the tax amount 0 as well?

jsacksick’s picture

Status: Needs review » Needs work

I'm pretty sure Klarna will crash if we pass a 0 tax_rate (in case a tax amount is positive), so I believe the proper fix is to make sure the tax adjustment has a percentage set on the tax adjustment, or the percentage should be calculated, so not committing this.

ozin’s picture

I think this issue is more related to my project, so I have to debug more.

zaporylie’s picture

I've just stepped-into step-debugging mode to learn more about this issue and I believe this is related to how Adjustments are handled in general, meaning it may actually be an issue in commerce core.

from Drupal\commerce_order\Adjustment.php:

    if (!empty($definition['percentage'])) {
      if (is_float($definition['percentage'])) {
        throw new \InvalidArgumentException(sprintf('The provided percentage "%s" must be a string, not a float.', $definition['percentage']));
      }
      if (!is_numeric($definition['percentage'])) {
        throw new \InvalidArgumentException(sprintf('The provided percentage "%s" is not a numeric value.', $definition['percentage']));
      }
    }
...
    $this->percentage = !empty($definition['percentage']) ? $definition['percentage'] : NULL;

So if the tax rate resolves to "0" (which is valid tax rate in some tax zones) the code above will result in Adjustment::percentage member property set to NULL, causing the fatal error in question. However, IMHO this is to be solved in Commerce Core rather than here.