Skip to content

Commit

Permalink
Use provided weight.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsegura committed Jan 29, 2025
1 parent bcd356b commit b698bc2
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Action/Woopit/PackagesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use AppBundle\Entity\PackageSet;
use AppBundle\Entity\Task;
use AppBundle\Entity\Woopit\QuoteRequest as WoopitQuoteRequest;
use PhpUnitsOfMeasure\PhysicalQuantity\Mass;

trait PackagesTrait
{
Expand Down Expand Up @@ -47,8 +48,8 @@ protected function parseAndApplyPackages(WoopitQuoteRequest $data, Task $task)
$p->setAverageVolumeUnits(1);
$p->setMaxVolumeUnits(1);
$p->setColor('#FFFFFF');
$p->setAverageWeight(1000);
$p->setMaxWeight(1000);
$p->setAverageWeight($this->convertWeight($package['weight']));
$p->setMaxWeight($this->convertWeight($package['weight']));
$p->setShortCode(strtoupper(substr($packageName, 0 ,2)));

$this->entityManager->persist($p);
Expand All @@ -69,4 +70,11 @@ private function generatePackageName(array $data): string

return sprintf('%s x %s x %s, %s', ...$params);
}

private function convertWeight(array $data): int|float
{
$mass = new Mass($data['value'], $data['unit']);

return $mass->toUnit('g');
}
}

0 comments on commit b698bc2

Please sign in to comment.