|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Lc\CaracoleBundle\Resolver; |
|
|
namespace Lc\CaracoleBundle\Resolver; |
|
|
|
|
|
|
|
|
|
|
|
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; |
|
|
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; |
|
|
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; |
|
|
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel; |
|
|
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel; |
|
|
|
|
|
use Lc\CaracoleBundle\Solver\Order\OrderShopSolver; |
|
|
use Lc\CaracoleBundle\Solver\Price\PriceSolver; |
|
|
use Lc\CaracoleBundle\Solver\Price\PriceSolver; |
|
|
use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver; |
|
|
use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
protected PriceSolver $priceSolver; |
|
|
protected PriceSolver $priceSolver; |
|
|
protected ProductFamilySolver $productFamilySolver; |
|
|
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->priceSolver = $priceSolver; |
|
|
$this->productFamilySolver = $productFamilySolver; |
|
|
$this->productFamilySolver = $productFamilySolver; |
|
|
|
|
|
$this->orderShopSolver = $orderShopSolver; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getMultiplyingFactor(ProductFamilyInterface $productFamily) |
|
|
public function getMultiplyingFactor(ProductFamilyInterface $productFamily) |
|
|
|
|
|
|
|
|
if ($productFamily->getBehaviorPrice() == ProductFamilyModel::BEHAVIOR_PRICE_BY_PIECE) { |
|
|
if ($productFamily->getBehaviorPrice() == ProductFamilyModel::BEHAVIOR_PRICE_BY_PIECE) { |
|
|
if ($productFamily->getBuyingPrice() > 0) { |
|
|
if ($productFamily->getBuyingPrice() > 0) { |
|
|
return number_format( |
|
|
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) { |
|
|
} elseif ($productFamily->getBehaviorPrice() == ProductFamilyModel::BEHAVIOR_PRICE_BY_REFERENCE_UNIT) { |
|
|
if ($productFamily->getBuyingPriceByRefUnit() > 0) { |
|
|
if ($productFamily->getBuyingPriceByRefUnit() > 0) { |
|
|
return number_format( |
|
|
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; |
|
|
$priceSolver = $this->priceSolver; |
|
|
|
|
|
|
|
|
return $this->getCheapestOrMostExpensiveProduct( |
|
|
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; |
|
|
$priceSolver = $this->priceSolver; |
|
|
|
|
|
|
|
|
return $this->getCheapestOrMostExpensiveProduct( |
|
|
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; |
|
|
$priceSolver = $this->priceSolver; |
|
|
|
|
|
|
|
|
return $this->getCheapestOrMostExpensiveProduct( |
|
|
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( |
|
|
private function getCheapestOrMostExpensiveProduct( |
|
|
ProductFamilyInterface $productFamily, |
|
|
|
|
|
$comparisonFunction, |
|
|
|
|
|
$returnSelfIfNotActiveProducts |
|
|
|
|
|
) { |
|
|
|
|
|
|
|
|
ProductFamilyInterface $productFamily, |
|
|
|
|
|
$comparisonFunction, |
|
|
|
|
|
$returnSelfIfNotActiveProducts, |
|
|
|
|
|
OrderShopInterface $orderShop |
|
|
|
|
|
) |
|
|
|
|
|
{ |
|
|
if ($productFamily->getActiveProducts()) { |
|
|
if ($productFamily->getActiveProducts()) { |
|
|
$products = $this->productFamilySolver->getProductsOnline($productFamily)->getValues(); |
|
|
$products = $this->productFamilySolver->getProductsOnline($productFamily)->getValues(); |
|
|
|
|
|
|
|
|
if (count($products) > 0) { |
|
|
if (count($products) > 0) { |
|
|
usort($products, $comparisonFunction); |
|
|
usort($products, $comparisonFunction); |
|
|
|
|
|
|
|
|
|
|
|
foreach ($products as $product) { |
|
|
|
|
|
if ($this->orderShopSolver->isProductAvailable($orderShop->getSection(), $orderShop, $product, 1, true)) { |
|
|
|
|
|
return $product; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return $products[0]; |
|
|
return $products[0]; |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |