Skip to content

Commit

Permalink
fix: mailbox works with kilo setting on php 8.1 (#744)
Browse files Browse the repository at this point in the history
  • Loading branch information
joerivanveen authored and EdieLemoine committed Feb 2, 2023
1 parent 8d33bd9 commit 721259a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Model/Sales/Repository/PackageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,20 @@ public function setMailboxSettings(string $carrierPath = self::XML_PATH_POSTNL_S

$this->setMailboxActive('1' === $settings['active']);
if (true === $this->isMailboxActive()) {
$weight = str_replace(',', '.', $settings['weight']);
$this->setMaxMailboxWeight($weight ?: self::DEFAULT_MAXIMUM_MAILBOX_WEIGHT);
$weight = abs((float) str_replace(',', '.', $settings['weight'] ?? ''));
$unit = $this->getGeneralConfig('print/weight_indication');

if ('kilo' === $unit) {
$epsilon = 0.00001;
$default = self::DEFAULT_MAXIMUM_MAILBOX_WEIGHT / 1000.0;
if ($weight < $epsilon) {
$weight = $default;
}
$this->setMaxMailboxWeight($weight);
} else {
$weight = (int)$weight;
$this->setMaxMailboxWeight($weight ?: self::DEFAULT_MAXIMUM_MAILBOX_WEIGHT);
}

$pickupMailbox = (bool) $this->getConfigValue("{$carrierPath}mailbox/pickup_mailbox");
$this->setPickupMailboxActive($pickupMailbox);
Expand Down

0 comments on commit 721259a

Please sign in to comment.