/** * {@inheritdoc} */ public function getPrice(array $weightables) { $totalWeight = $this->strategy->getTotalWeight($weightables); // Sort tresholds ascending $tresholds = $this->tresholdProvider->getTresholds(); usort($tresholds, function (WeightTresholdInterface $a, WeightTresholdInterface $b) { return $a->getWeight() < $b->getWeight() ? -1 : 1; }); /** @var WeightTresholdInterface $treshold */ foreach ($tresholds as $treshold) { if ($totalWeight <= $treshold->getWeight()) { return (double) $treshold->getPrice(); } } return (double) (!count($tresholds)) ? 0 : $tresholds[count($tresholds) - 1]->getPrice(); }
/** * {@inheritdoc} */ public function getWeight($weightables) { return $this->weightCalculatorStrategy->getTotalWeight(is_array($weightables) ? $weightables : array($weightables)); }