|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
$smallestQuantity = null; |
|
|
$smallestQuantity = null; |
|
|
|
|
|
|
|
|
if($this->featureChecker->isEnabled(Feature::ALIAS_PRODUCT_ACCESSORY)) { |
|
|
|
|
|
foreach ($product->getProductAccessories() as $productAccessory) { |
|
|
|
|
|
$quantityAccessory = $productAccessory->getAccessory()->getQuantity(); |
|
|
|
|
|
$smallestQuantity = is_null($smallestQuantity) ? $quantityAccessory |
|
|
|
|
|
: min($smallestQuantity, $quantityAccessory); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
foreach ($product->getProductAccessories() as $productAccessory) { |
|
|
|
|
|
$quantityAccessory = $productAccessory->getAccessory()->getQuantity(); |
|
|
|
|
|
$smallestQuantity = is_null($smallestQuantity) ? $quantityAccessory |
|
|
|
|
|
: min($smallestQuantity, $quantityAccessory); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $smallestQuantity; |
|
|
return $smallestQuantity; |
|
|
|
|
|
|
|
|
public function getProductQuantityMax(Product $product, Distribution $distribution): ?float |
|
|
public function getProductQuantityMax(Product $product, Distribution $distribution): ?float |
|
|
{ |
|
|
{ |
|
|
$productDistribution = $this->productDistributionRepository->findOneProductDistribution($distribution, $product); |
|
|
$productDistribution = $this->productDistributionRepository->findOneProductDistribution($distribution, $product); |
|
|
|
|
|
// @TODO : gérer via une exception |
|
|
if(!$productDistribution) { |
|
|
if(!$productDistribution) { |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$quantityMax = $productDistribution->quantity_max; |
|
|
$quantityMax = $productDistribution->quantity_max; |
|
|
$smallestQuantityAccessory = $this->getSmallestQuantityAccessory($product); |
|
|
|
|
|
|
|
|
|
|
|
if(!is_null($smallestQuantityAccessory)) { |
|
|
|
|
|
$quantityMax = is_null($quantityMax) ? $smallestQuantityAccessory : min($quantityMax, $smallestQuantityAccessory); |
|
|
|
|
|
|
|
|
if($this->featureChecker->isEnabled(Feature::ALIAS_PRODUCT_ACCESSORY)) { |
|
|
|
|
|
$smallestQuantityAccessory = $this->getSmallestQuantityAccessory($product); |
|
|
|
|
|
if (!is_null($smallestQuantityAccessory)) { |
|
|
|
|
|
$quantityMax = is_null($quantityMax) ? $smallestQuantityAccessory : min($quantityMax, $smallestQuantityAccessory); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $quantityMax; |
|
|
return $quantityMax; |
|
|
|
|
|
|
|
|
: ($productDistribution->quantity_max - $quantityOrder); |
|
|
: ($productDistribution->quantity_max - $quantityOrder); |
|
|
|
|
|
|
|
|
// Limitation par nombre d'accessoires disponibles |
|
|
// Limitation par nombre d'accessoires disponibles |
|
|
$smallestQuantityAccessoryAvailable = $this->getSmallestQuantityAccessoryAvailable($product, $distribution); |
|
|
|
|
|
if(!is_null($smallestQuantityAccessoryAvailable)) { |
|
|
|
|
|
$quantityRemaining = is_null($quantityRemaining) ? $smallestQuantityAccessoryAvailable |
|
|
|
|
|
: min($quantityRemaining, $smallestQuantityAccessoryAvailable); |
|
|
|
|
|
|
|
|
if($this->featureChecker->isEnabled(Feature::ALIAS_PRODUCT_ACCESSORY)) { |
|
|
|
|
|
$smallestQuantityAccessoryAvailable = $this->getSmallestQuantityAccessoryAvailable($product, $distribution); |
|
|
|
|
|
if (!is_null($smallestQuantityAccessoryAvailable)) { |
|
|
|
|
|
$quantityRemaining = is_null($quantityRemaining) ? $smallestQuantityAccessoryAvailable |
|
|
|
|
|
: min($quantityRemaining, $smallestQuantityAccessoryAvailable); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $quantityRemaining; |
|
|
return $quantityRemaining; |