Przeglądaj źródła

[Frontend] Produits > liste : prendre en compte la disponibilité des produits pour le calcul du meilleur prix #636

develop
Guillaume Bourgeois 1 rok temu
rodzic
commit
a59b0a556f
1 zmienionych plików z 52 dodań i 35 usunięć
  1. +52
    -35
      Resolver/ProductFamilyResolver.php

+ 52
- 35
Resolver/ProductFamilyResolver.php Wyświetl plik

@@ -2,8 +2,10 @@

namespace Lc\CaracoleBundle\Resolver;

use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
use Lc\CaracoleBundle\Solver\Order\OrderShopSolver;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver;

@@ -11,11 +13,13 @@ class ProductFamilyResolver
{
protected PriceSolver $priceSolver;
protected ProductFamilySolver $productFamilySolver;
protected OrderShopSolver $orderShopSolver;

public function __construct(PriceSolver $priceSolver, ProductFamilySolver $productFamilySolver)
public function __construct(PriceSolver $priceSolver, ProductFamilySolver $productFamilySolver, OrderShopSolver $orderShopSolver)
{
$this->priceSolver = $priceSolver;
$this->productFamilySolver = $productFamilySolver;
$this->orderShopSolver = $orderShopSolver;
}

public function getMultiplyingFactor(ProductFamilyInterface $productFamily)
@@ -23,76 +27,89 @@ class ProductFamilyResolver
if ($productFamily->getBehaviorPrice() == ProductFamilyModel::BEHAVIOR_PRICE_BY_PIECE) {
if ($productFamily->getBuyingPrice() > 0) {
return number_format(
$this->priceSolver->getPriceWithTax($productFamily) / $productFamily->getBuyingPrice(),
3
$this->priceSolver->getPriceWithTax($productFamily) / $productFamily->getBuyingPrice(),
3
);
}
} elseif ($productFamily->getBehaviorPrice() == ProductFamilyModel::BEHAVIOR_PRICE_BY_REFERENCE_UNIT) {
if ($productFamily->getBuyingPriceByRefUnit() > 0) {
return number_format(
$this->priceSolver->getPriceByRefUnitWithTax(
$productFamily
) / $productFamily->getBuyingPriceByRefUnit(),
3
$this->priceSolver->getPriceByRefUnitWithTax(
$productFamily
) / $productFamily->getBuyingPriceByRefUnit(),
3
);
}
}
}

public function getCheapestProduct(ProductFamilyInterface $productFamily)
public function getCheapestProduct(ProductFamilyInterface $productFamily, OrderShopInterface $orderShop)
{
$priceSolver = $this->priceSolver;

return $this->getCheapestOrMostExpensiveProduct(
$productFamily,
function ($a, $b) use ($priceSolver) {
return $priceSolver->getPriceWithTaxAndReduction(
$a
) > $priceSolver->getPriceWithTaxAndReduction($b);
},
true
$productFamily,
function ($a, $b) use ($priceSolver) {
return $priceSolver->getPriceWithTaxAndReduction(
$a
) > $priceSolver->getPriceWithTaxAndReduction($b);
},
true,
$orderShop
);
}

public function getCheapestProductByRefUnit(ProductFamilyInterface $productFamily)
public function getCheapestProductByRefUnit(ProductFamilyInterface $productFamily, OrderShopInterface $orderShop)
{
$priceSolver = $this->priceSolver;

return $this->getCheapestOrMostExpensiveProduct(
$productFamily,
function ($a, $b) use ($priceSolver) {
return $priceSolver->getPriceByRefUnitWithTaxAndReduction(
$a
) > $priceSolver->getPriceByRefUnitWithTaxAndReduction($b);
},
false
$productFamily,
function ($a, $b) use ($priceSolver) {
return $priceSolver->getPriceByRefUnitWithTaxAndReduction(
$a
) > $priceSolver->getPriceByRefUnitWithTaxAndReduction($b);
},
false,
$orderShop
);
}

public function getMostExpensiveProductByRefUnit(ProductFamilyInterface $productFamily)
public function getMostExpensiveProductByRefUnit(ProductFamilyInterface $productFamily, OrderShopInterface $orderShop)
{
$priceSolver = $this->priceSolver;

return $this->getCheapestOrMostExpensiveProduct(
$productFamily,
function ($a, $b) use ($priceSolver) {
return $priceSolver->getPriceByRefUnitWithTaxAndReduction(
$a
) < $priceSolver->getPriceByRefUnitWithTaxAndReduction($b);
},
false
$productFamily,
function ($a, $b) use ($priceSolver) {
return $priceSolver->getPriceByRefUnitWithTaxAndReduction(
$a
) < $priceSolver->getPriceByRefUnitWithTaxAndReduction($b);
},
false,
$orderShop
);
}

private function getCheapestOrMostExpensiveProduct(
ProductFamilyInterface $productFamily,
$comparisonFunction,
$returnSelfIfNotActiveProducts
) {
ProductFamilyInterface $productFamily,
$comparisonFunction,
$returnSelfIfNotActiveProducts,
OrderShopInterface $orderShop
)
{
if ($productFamily->getActiveProducts()) {
$products = $this->productFamilySolver->getProductsOnline($productFamily)->getValues();

if (count($products) > 0) {
usort($products, $comparisonFunction);

foreach ($products as $product) {
if ($this->orderShopSolver->isProductAvailable($orderShop->getSection(), $orderShop, $product, 1, true)) {
return $product;
}
}

return $products[0];
}
} else {

Ładowanie…
Anuluj
Zapisz