|
|
|
|
|
|
|
|
public function getCheapestProduct($productFamily) |
|
|
public function getCheapestProduct($productFamily) |
|
|
{ |
|
|
{ |
|
|
$priceUtils = $this->priceUtils ; |
|
|
$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) ; |
|
|
return $priceUtils->getPriceWithTaxAndReduction($a) > $priceUtils->getPriceWithTaxAndReduction($b) ; |
|
|
}, true); |
|
|
}, true); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getCheapestProductByRefUnit($productFamily) |
|
|
public function getCheapestProductByRefUnit($productFamily) |
|
|
{ |
|
|
{ |
|
|
$priceUtils = $this->priceUtils ; |
|
|
$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) ; |
|
|
return $priceUtils->getPriceByRefUnitWithTaxAndReduction($a) > $priceUtils->getPriceByRefUnitWithTaxAndReduction($b) ; |
|
|
}, false); |
|
|
}, false); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getMostExpensiveProductByRefUnit($productFamily) |
|
|
public function getMostExpensiveProductByRefUnit($productFamily) |
|
|
{ |
|
|
{ |
|
|
$priceUtils = $this->priceUtils ; |
|
|
$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) ; |
|
|
return $priceUtils->getPriceByRefUnitWithTaxAndReduction($a) < $priceUtils->getPriceByRefUnitWithTaxAndReduction($b) ; |
|
|
}, false); |
|
|
}, false); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private function getCheapestOrMostExpensiveProduct($products, $comparisonFunction, $returnSelfIfNotActiveProducts) |
|
|
|
|
|
|
|
|
private function getCheapestOrMostExpensiveProduct($productFamily, $comparisonFunction, $returnSelfIfNotActiveProducts) |
|
|
{ |
|
|
{ |
|
|
|
|
|
$products = $productFamily->getProducts()->getValues() ; |
|
|
if (count($products) > 0) { |
|
|
if (count($products) > 0) { |
|
|
usort($products, $comparisonFunction); |
|
|
usort($products, $comparisonFunction); |
|
|
return $products[0]; |
|
|
return $products[0]; |
|
|
} |
|
|
} |
|
|
if ($returnSelfIfNotActiveProducts) { |
|
|
if ($returnSelfIfNotActiveProducts) { |
|
|
return $this; |
|
|
|
|
|
|
|
|
return $productFamily; |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
return false; |
|
|
return false; |