Browse Source

Refactor services

feature/export_comptable
Fab 4 years ago
parent
commit
aaa7980129
5 changed files with 68 additions and 20 deletions
  1. +2
    -2
      ShopBundle/Controller/ApiController.php
  2. +4
    -3
      ShopBundle/Services/Order/OrderUtils.php
  3. +47
    -0
      ShopBundle/Services/Price/PriceUtils.php
  4. +2
    -2
      ShopBundle/Services/Price/ProductPriceUtils.php
  5. +13
    -13
      ShopBundle/Services/ProductFamilyUtils.php

+ 2
- 2
ShopBundle/Controller/ApiController.php View File



use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\PriceUtilsInterface;
use Lc\ShopBundle\Context\ProductCategoryInterface; use Lc\ShopBundle\Context\ProductCategoryInterface;
use Lc\ShopBundle\Context\ProductInterface; use Lc\ShopBundle\Context\ProductInterface;
use Lc\ShopBundle\Services\PriceUtils;
use Lc\ShopBundle\Services\ProductFamilyUtils; use Lc\ShopBundle\Services\ProductFamilyUtils;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
protected $priceUtils ; protected $priceUtils ;
protected $productFamilyUtils; protected $productFamilyUtils;


public function __construct(EntityManagerInterface $entityManager, PriceUtils $priceUtils, ProductFamilyUtils $productFamilyUtils)
public function __construct(EntityManagerInterface $entityManager, PriceUtilsInterface $priceUtils, ProductFamilyUtils $productFamilyUtils)
{ {
$this->em = $entityManager; $this->em = $entityManager;
$this->priceUtils = $priceUtils; $this->priceUtils = $priceUtils;

+ 4
- 3
ShopBundle/Services/Order/OrderUtils.php View File

use Lc\ShopBundle\Context\OrderShopInterface; use Lc\ShopBundle\Context\OrderShopInterface;
use Lc\ShopBundle\Context\OrderStatusHistoryInterface; use Lc\ShopBundle\Context\OrderStatusHistoryInterface;
use Lc\ShopBundle\Context\OrderStatusInterface; use Lc\ShopBundle\Context\OrderStatusInterface;
use Lc\ShopBundle\Context\PriceUtilsInterface;
use Lc\ShopBundle\Context\ProductFamilyUtilsInterface; use Lc\ShopBundle\Context\ProductFamilyUtilsInterface;
use Lc\ShopBundle\Context\ReductionCartInterface; use Lc\ShopBundle\Context\ReductionCartInterface;
use Lc\ShopBundle\Context\ReductionCreditInterface; use Lc\ShopBundle\Context\ReductionCreditInterface;
protected $orderShopRepo; protected $orderShopRepo;
protected $reductionCreditRepo ; protected $reductionCreditRepo ;
protected $orderReductionCreditRepo ; protected $orderReductionCreditRepo ;
protected $orderShopPriceUtils;
protected $priceUtils;
protected $productFamilyUtils; protected $productFamilyUtils;
protected $documentUtils; protected $documentUtils;
protected $session; protected $session;


public function __construct(EntityManagerInterface $em, Security $security, UserUtils $userUtils, public function __construct(EntityManagerInterface $em, Security $security, UserUtils $userUtils,
MerchantUtilsInterface $merchantUtils, OrderShopPriceUtils $orderShopPriceUtils, ProductFamilyUtilsInterface $productFamilyUtils,
MerchantUtilsInterface $merchantUtils, PriceUtilsInterface $priceUtils, ProductFamilyUtilsInterface $productFamilyUtils,
DocumentUtils $documentUtils, SessionInterface $session) DocumentUtils $documentUtils, SessionInterface $session)
{ {
$this->em = $em; $this->em = $em;
$this->orderShopRepo = $this->em->getRepository($this->em->getClassMetadata(OrderShopInterface::class)->getName()); $this->orderShopRepo = $this->em->getRepository($this->em->getClassMetadata(OrderShopInterface::class)->getName());
$this->reductionCreditRepo = $this->em->getRepository($this->em->getClassMetadata(ReductionCreditInterface::class)->getName()); $this->reductionCreditRepo = $this->em->getRepository($this->em->getClassMetadata(ReductionCreditInterface::class)->getName());
$this->orderReductionCreditRepo = $this->em->getRepository($this->em->getClassMetadata(OrderReductionCreditInterface::class)->getName()); $this->orderReductionCreditRepo = $this->em->getRepository($this->em->getClassMetadata(OrderReductionCreditInterface::class)->getName());
$this->orderShopPriceUtils = $orderShopPriceUtils;
$this->priceUtils = $priceUtils;
$this->productFamilyUtils = $productFamilyUtils; $this->productFamilyUtils = $productFamilyUtils;
$this->documentUtils = $documentUtils; $this->documentUtils = $documentUtils;
$this->session = $session; $this->session = $session;

+ 47
- 0
ShopBundle/Services/Price/PriceUtils.php View File

<?php

namespace Lc\ShopBundle\Services\Price ;

use Lc\ShopBundle\Context\OrderProductInterface;
use Lc\ShopBundle\Context\OrderShopInterface;
use Lc\ShopBundle\Context\OrderShopPriceUtilsInterface;
use Lc\ShopBundle\Context\PriceUtilsInterface;
use Lc\ShopBundle\Context\ProductPropertyInterface;

class PriceUtils implements PriceUtilsInterface
{
protected $productPriceUtils ;
protected $orderProductPriceUtils ;
protected $orderShopPriceUtils ;

public function __construct(ProductPriceUtils $productPriceUtils, OrderProductPriceUtils $orderProductPriceUtils, OrderShopPriceUtilsInterface $orderShopPriceUtils)
{
$this->productPriceUtils = $productPriceUtils ;
$this->orderProductPriceUtils = $orderProductPriceUtils ;
$this->orderShopPriceUtils = $orderShopPriceUtils ;
}

public function __call($name, $arguments)
{
$entity = $arguments[0] ;
$service = '' ;

if($entity instanceof ProductPropertyInterface) {
$service = 'productPriceUtils' ;
}

if($entity instanceof OrderProductInterface) {
$service = 'orderProductPriceUtils' ;
}

if($entity instanceof OrderShopInterface) {
$service = 'orderShopPriceUtils' ;
}

if(strlen($service) && $entity && method_exists($this->$service, $name)) {
return $this->$service->$name($entity) ;
}

return false ;
}
}

+ 2
- 2
ShopBundle/Services/Price/ProductPriceUtils.php View File

{ {
return $this->applyReductionCatalog( return $this->applyReductionCatalog(
$product, $product,
$this->getTotal($product),
$this->getTotalWithTax($product)
$this->getPrice($product),
$this->getPriceWithTax($product)
); );
} }



+ 13
- 13
ShopBundle/Services/ProductFamilyUtils.php View File



namespace Lc\ShopBundle\Services ; namespace Lc\ShopBundle\Services ;


use Lc\ShopBundle\Services\Price\ProductPriceUtils;
use Lc\ShopBundle\Context\PriceUtilsInterface;


class ProductFamilyUtils class ProductFamilyUtils
{ {
protected $productPriceUtils ;
protected $priceUtils ;


public function __construct(ProductPriceUtils $productPriceUtils)
public function __construct(PriceUtilsInterface $priceUtils)
{ {
$this->productPriceUtils = $productPriceUtils ;
$this->priceUtils = $priceUtils ;
} }


public function getCheapestProduct($productFamily) public function getCheapestProduct($productFamily)
{ {
$productPriceUtils = $this->productPriceUtils ;
return $this->getCheapestOrMostExpensiveProduct($productFamily, function ($a, $b) use ($productPriceUtils) {
return $productPriceUtils->getPriceWithTaxAndReduction($a) > $productPriceUtils->getPriceWithTaxAndReduction($b) ;
$priceUtils = $this->priceUtils ;
return $this->getCheapestOrMostExpensiveProduct($productFamily, function ($a, $b) use ($priceUtils) {
return $priceUtils->getPriceWithTaxAndReduction($a) > $priceUtils->getPriceWithTaxAndReduction($b) ;
}, true); }, true);
} }


public function getCheapestProductByRefUnit($productFamily) public function getCheapestProductByRefUnit($productFamily)
{ {
$productPriceUtils = $this->productPriceUtils ;
return $this->getCheapestOrMostExpensiveProduct($productFamily, function ($a, $b) use ($productPriceUtils) {
return $productPriceUtils->getPriceByRefUnitWithTaxAndReduction($a) > $productPriceUtils->getPriceByRefUnitWithTaxAndReduction($b) ;
$priceUtils = $this->priceUtils ;
return $this->getCheapestOrMostExpensiveProduct($productFamily, function ($a, $b) use ($priceUtils) {
return $priceUtils->getPriceByRefUnitWithTaxAndReduction($a) > $priceUtils->getPriceByRefUnitWithTaxAndReduction($b) ;
}, false); }, false);
} }


public function getMostExpensiveProductByRefUnit($productFamily) public function getMostExpensiveProductByRefUnit($productFamily)
{ {
$productPriceUtils = $this->productPriceUtils ;
return $this->getCheapestOrMostExpensiveProduct($productFamily, function ($a, $b) use ($productPriceUtils) {
return $productPriceUtils->getPriceByRefUnitWithTaxAndReduction($a) < $productPriceUtils->getPriceByRefUnitWithTaxAndReduction($b) ;
$priceUtils = $this->priceUtils ;
return $this->getCheapestOrMostExpensiveProduct($productFamily, function ($a, $b) use ($priceUtils) {
return $priceUtils->getPriceByRefUnitWithTaxAndReduction($a) < $priceUtils->getPriceByRefUnitWithTaxAndReduction($b) ;
}, false); }, false);
} }



Loading…
Cancel
Save