query = $query; $this->priceResolver = $priceResolver; } public function isOneProductAvailableAddCart(array $products): bool { foreach ($products as $product) { if ($product->isAvailable(1, true)) { return true; } } return false; } public function getMultiplyingFactor($productFamily) { if ($productFamily->getBehaviorPrice() == ProductFamilyModel::BEHAVIOR_PRICE_BY_PIECE) { if ($productFamily->getBuyingPrice() > 0) { return number_format( $this->priceResolver->getPriceWithTax($productFamily) / $productFamily->getBuyingPrice(), 3 ); } } elseif ($productFamily->getBehaviorPrice() == ProductFamilyModel::BEHAVIOR_PRICE_BY_REFERENCE_UNIT) { if ($productFamily->getBuyingPriceByRefUnit() > 0) { return number_format( $this->priceResolver->getPriceByRefUnitWithTax( $productFamily ) / $productFamily->getBuyingPriceByRefUnit(), 3 ); } } } public function getCheapestProduct(ProductFamilyInterface $productFamily) { $priceResolver = $this->priceResolver; return $this->getCheapestOrMostExpensiveProduct( $productFamily, function ($a, $b) use ($priceResolver) { return $priceResolver->getPriceWithTaxAndReduction( $a ) > $priceResolver->getPriceWithTaxAndReduction($b); }, true ); } public function getCheapestProductByRefUnit(ProductFamilyInterface $productFamily) { $priceResolver = $this->priceResolver; return $this->getCheapestOrMostExpensiveProduct( $productFamily, function ($a, $b) use ($priceResolver) { return $priceResolver->getPriceByRefUnitWithTaxAndReduction( $a ) > $priceResolver->getPriceByRefUnitWithTaxAndReduction($b); }, false ); } public function getMostExpensiveProductByRefUnit(ProductFamilyInterface $productFamily) { $priceResolver = $this->priceResolver; return $this->getCheapestOrMostExpensiveProduct( $productFamily, function ($a, $b) use ($priceResolver) { return $priceResolver->getPriceByRefUnitWithTaxAndReduction( $a ) < $priceResolver->getPriceByRefUnitWithTaxAndReduction($b); }, false ); } private function getCheapestOrMostExpensiveProduct( ProductFamilyInterface $productFamily, $comparisonFunction, $returnSelfIfNotActiveProducts ) { if ($productFamily->getActiveProducts()) { $products = $productFamily->getProductsOnline()->getValues(); if (count($products) > 0) { usort($products, $comparisonFunction); return $products[0]; } } else { return $productFamily->getOriginProduct(); } if ($returnSelfIfNotActiveProducts) { return $productFamily; } else { return false; } } }