|
- <?php
-
- namespace Lc\ShopBundle\Price\Services;
-
- use Lc\ShopBundle\Context\OrderShopInterface;
- use Lc\ShopBundle\Context\OrderShopPriceUtilsInterface;
-
- class OrderShopPriceUtils implements OrderShopPriceUtilsInterface
- {
- use PriceUtilsTrait ;
-
- protected $orderProductPriceUtils ;
-
- public function __construct(OrderProductPriceUtils $orderProductPriceUtils)
- {
- $this->orderProductPriceUtils = $orderProductPriceUtils ;
- }
-
- //Inclus les ReductionCatalog des OrderProducts
- public function getTotalOrderProducts(OrderShopInterface $orderShop):float
- {
- // A tester calculer ce montant en faisant TotalOrderWithTax - TotalOrderTaxes
-
- $total = 0;
- foreach ($orderShop->getOrderProducts() as $orderProduct) {
- $total += $this->orderProductPriceUtils->getTotalWithReduction($orderProduct);
- }
- return $total;
- }
-
- public function getTotalOrderProductsWithTax(OrderShopInterface $orderShop):float
- {
- $total = 0;
- foreach ($orderShop->getOrderProducts() as $orderProduct) {
- $total += $this->orderProductPriceUtils->getTotalWithTaxAndReduction($orderProduct);
- }
- return $total;
-
- }
-
-
- public function getTotalOrderProductsTaxes(OrderShopInterface $orderShop):float {
- }
-
- public function getOrderProductsTaxesAsArray(OrderShopInterface $orderShop):array
- {
- $orderProductsTaxes = [];
- foreach ($orderShop->getOrderProducts() as $orderProduct) {
-
- $idTaxRate = $orderProduct->getTaxRate()->getId() ;
-
- if(!isset($orderProductsTaxes[$idTaxRate])) {
- $orderProductsTaxes[$idTaxRate] = [
- 'label' => $orderProduct->getTaxRate()->getValue() . '%',
- 'totalOrderProducts' => 0,
- 'totalTaxes' => 0,
- ];
- }
-
- $orderProductsTaxes[$idTaxRate]['totalOrderProducts'] += $this->orderProductPriceUtils->getTotalWithReduction($orderProduct) * $this->getReductionsCoef($orderShop);
- $orderProductsTaxes[$idTaxRate]['totalTaxes'] += $this->orderProductPriceUtils->getTotalTaxes($orderProduct) * $this->getReductionsCoef($orderShop) ;
- }
-
- return $orderProductsTaxes ;
- }
-
- private function getReductionsCoef(OrderShopInterface $orderShop) :float
- {
- return $this->getTotalOrderProducts($orderShop) / $this->getTotalOrderProductsWithReductions($orderShop);
- }
-
-
-
- public function getTotalOrderProductsWithReductions(OrderShopInterface $orderShop)
- {
-
- }
-
-
- public function getTotalWithTaxAndReductions(OrderShopInterface $orderShop)
- {
-
- }
- }
|