Browse Source

Gestion des accessoires

feature/rotating_product
Guillaume Bourgeois 6 months ago
parent
commit
8e1106e05e
1 changed files with 32 additions and 32 deletions
  1. +32
    -32
      domain/Order/Order/OrderResolver.php

+ 32
- 32
domain/Order/Order/OrderResolver.php View File

@@ -32,6 +32,38 @@ class OrderResolver extends AbstractResolver
return $this->orderSolver->getProductQuantity($product, $ordersArray);
}

public function getSmallestQuantityAccessory(Product $product): ?int
{
$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);
}
}

return $smallestQuantity;
}

public function getProductQuantityMax(Product $product, Distribution $distribution): ?float
{
$productDistribution = $this->productDistributionRepository->findOneProductDistribution($distribution, $product);
if(!$productDistribution) {
return null;
}

$quantityMax = $productDistribution->quantity_max;
$smallestQuantityAccessory = $this->getSmallestQuantityAccessory($product);

if(!is_null($smallestQuantityAccessory)) {
$quantityMax = is_null($quantityMax) ? $smallestQuantityAccessory : min($quantityMax, $smallestQuantityAccessory);
}

return $quantityMax;
}

public function getQuantityOfAccessoryAvailableInDistribution(Accessory $accessory, Distribution $distribution): int
{
$quantityOfAccessoryUsed = 0;
@@ -61,21 +93,6 @@ class OrderResolver extends AbstractResolver
return $smallestQuantity;
}

public function getSmallestQuantityAccessory(Product $product, Distribution $distribution): ?int
{
$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);
}
}

return $smallestQuantity;
}

public function getProductQuantityRemaining(Product $product, Distribution $distribution): ?float
{
$productDistribution = $this->productDistributionRepository->findOneProductDistribution($distribution, $product);
@@ -96,21 +113,4 @@ class OrderResolver extends AbstractResolver

return $quantityRemaining;
}

public function getProductQuantityMax(Product $product, Distribution $distribution): ?float
{
$productDistribution = $this->productDistributionRepository->findOneProductDistribution($distribution, $product);
if(!$productDistribution) {
return null;
}

$quantityMax = $productDistribution->quantity_max;
$smallestQuantityAccessory = $this->getSmallestQuantityAccessory($product, $distribution);

if(!is_null($smallestQuantityAccessory)) {
$quantityMax = is_null($quantityMax) ? $smallestQuantityAccessory : min($quantityMax, $smallestQuantityAccessory);
}

return $quantityMax;
}
}

Loading…
Cancel
Save