Browse Source

Gestion des accessoires

feature/rotating_product
Guillaume Bourgeois 6 months ago
parent
commit
a191eae5b0
3 changed files with 20 additions and 18 deletions
  1. +4
    -0
      backend/views/distribution/index.php
  2. +0
    -5
      backend/web/js/vuejs/distribution-index.js
  3. +16
    -13
      domain/Order/Order/OrderResolver.php

+ 4
- 0
backend/views/distribution/index.php View File

@@ -151,6 +151,10 @@ $this->setPageTitle('Distributions') ;
<input type="text" class="form-control quantity-max" placeholder="&infin;" :data-id-product="product.id" v-model="getProductDistribution(product).quantity_max" @keyup="productQuantityMaxChange" />
<span class="input-group-addon">{{ (product.unit == 'piece') ? 'p.' : ' '+((product.unit == 'g' || product.unit == 'kg') ? 'kg' : 'litre(s)') }}</span>
</div>
<div v-if=" false && getProductDistribution(product).quantity_max != product.quantity_max">
Limitation accessoires : <br />
{{ product.quantity_max }}
</div>
</td>
</tr>
</tbody>

+ 0
- 5
backend/web/js/vuejs/distribution-index.js View File

@@ -1235,11 +1235,6 @@ if($(selector).length) {
}
},
getProductQuantityMax: function(product) {
//var quantityMax = this.getProductDistribution(product).quantity_max;

// Gestion quantité max accessoires
// ...

return product.quantity_max;
},
getProductQuantityOrder: function(product) {

+ 16
- 13
domain/Order/Order/OrderResolver.php View File

@@ -36,12 +36,10 @@ class OrderResolver extends AbstractResolver
{
$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;
@@ -50,15 +48,18 @@ class OrderResolver extends AbstractResolver
public function getProductQuantityMax(Product $product, Distribution $distribution): ?float
{
$productDistribution = $this->productDistributionRepository->findOneProductDistribution($distribution, $product);
// @TODO : gérer via une exception
if(!$productDistribution) {
return null;
}

$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;
@@ -105,10 +106,12 @@ class OrderResolver extends AbstractResolver
: ($productDistribution->quantity_max - $quantityOrder);

// 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;

Loading…
Cancel
Save