|
|
@@ -14,7 +14,7 @@ class ProductFamilyUtils |
|
|
|
public function getCheapestProduct($productFamily) |
|
|
|
{ |
|
|
|
$priceUtils = $this->priceUtils ; |
|
|
|
return $this->getCheapestOrMostExpensiveProduct($productFamily->getProducts()->getValues(), function ($a, $b) use ($priceUtils) { |
|
|
|
return $this->getCheapestOrMostExpensiveProduct($productFamily, function ($a, $b) use ($priceUtils) { |
|
|
|
return $priceUtils->getPriceWithTaxAndReduction($a) > $priceUtils->getPriceWithTaxAndReduction($b) ; |
|
|
|
}, true); |
|
|
|
} |
|
|
@@ -22,7 +22,7 @@ class ProductFamilyUtils |
|
|
|
public function getCheapestProductByRefUnit($productFamily) |
|
|
|
{ |
|
|
|
$priceUtils = $this->priceUtils ; |
|
|
|
return $this->getCheapestOrMostExpensiveProduct($productFamily->getProducts()->getValues(), function ($a, $b) use ($priceUtils) { |
|
|
|
return $this->getCheapestOrMostExpensiveProduct($productFamily, function ($a, $b) use ($priceUtils) { |
|
|
|
return $priceUtils->getPriceByRefUnitWithTaxAndReduction($a) > $priceUtils->getPriceByRefUnitWithTaxAndReduction($b) ; |
|
|
|
}, false); |
|
|
|
} |
|
|
@@ -30,19 +30,20 @@ class ProductFamilyUtils |
|
|
|
public function getMostExpensiveProductByRefUnit($productFamily) |
|
|
|
{ |
|
|
|
$priceUtils = $this->priceUtils ; |
|
|
|
return $this->getCheapestOrMostExpensiveProduct($productFamily->getProducts()->getValues(), function ($a, $b) use ($priceUtils) { |
|
|
|
return $this->getCheapestOrMostExpensiveProduct($productFamily, function ($a, $b) use ($priceUtils) { |
|
|
|
return $priceUtils->getPriceByRefUnitWithTaxAndReduction($a) < $priceUtils->getPriceByRefUnitWithTaxAndReduction($b) ; |
|
|
|
}, false); |
|
|
|
} |
|
|
|
|
|
|
|
private function getCheapestOrMostExpensiveProduct($products, $comparisonFunction, $returnSelfIfNotActiveProducts) |
|
|
|
private function getCheapestOrMostExpensiveProduct($productFamily, $comparisonFunction, $returnSelfIfNotActiveProducts) |
|
|
|
{ |
|
|
|
$products = $productFamily->getProducts()->getValues() ; |
|
|
|
if (count($products) > 0) { |
|
|
|
usort($products, $comparisonFunction); |
|
|
|
return $products[0]; |
|
|
|
} |
|
|
|
if ($returnSelfIfNotActiveProducts) { |
|
|
|
return $this; |
|
|
|
return $productFamily; |
|
|
|
} |
|
|
|
else { |
|
|
|
return false; |