Browse Source

Correctif ProductFamilyUtils

feature/export_comptable
Guillaume 4 years ago
parent
commit
398fec4382
1 changed files with 6 additions and 5 deletions
  1. +6
    -5
      ShopBundle/Services/ProductFamilyUtils.php

+ 6
- 5
ShopBundle/Services/ProductFamilyUtils.php View File

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;

Loading…
Cancel
Save